Example usage for org.apache.commons.io FilenameUtils separatorsToSystem

List of usage examples for org.apache.commons.io FilenameUtils separatorsToSystem

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils separatorsToSystem.

Prototype

public static String separatorsToSystem(String path) 

Source Link

Document

Converts all separators to the system separator.

Usage

From source file:org.ebayopensource.turmeric.tools.codegen.util.JavaToolsClassLoader.java

public static File findToolsJar() throws CodeGenFailedException {
    // Attempt to find the tools.jar near the java.home

    // The search paths for the tools.jar
    // @formatter:off
    String searchPaths[] = { "tools.jar", "lib/tools.jar", "../lib/tools.jar", "../Classes/classes.jar" };
    // @formatter:on

    // The search process
    File jdkHome = new File(System.getProperty("java.home"));
    File toolsJar = null;// ww w.  j  a va 2 s  . com
    for (String searchPath : searchPaths) {
        File possible = new File(jdkHome, FilenameUtils.separatorsToSystem(searchPath));
        if (possible.exists()) {
            toolsJar = possible;
            break;
        }
    }

    // Not found. can't codegen!
    if (toolsJar == null) {
        StringBuilder msg = new StringBuilder();
        msg.append("Failed(2) to load tools.jar: Are you running with a JDK?");
        msg.append("\nSystem.ENV(JAVA_HOME)=").append(System.getenv("JAVA_HOME"));
        msg.append("\nSystem.ENV(JDK_HOME)=").append(System.getenv("JDK_HOME"));
        msg.append("\nSystem.property(java.home)=").append(System.getProperty("java.home"));
        throw new CodeGenFailedException(msg.toString());
    }

    return toolsJar;
}

From source file:org.ebayopensource.turmeric.tools.errorlibrary.ErrorLibraryDataInputTest.java

private File createDomainPropertiesFile(File projRoot, String errorLibName) throws Exception {
    String dirname = FilenameUtils.separatorsToSystem("meta-src/META-INF/errorlibrary/" + errorLibName);
    File testDir = new File(projRoot, dirname);

    // Ensure that we don't accidentally benefit from past or other tests.
    MavenTestingUtils.ensureDirExists(testDir);

    // Create an empty properties file
    File testProp = new File(testDir, "error_library_project.properties");
    Assert.assertTrue("Creating empty file: " + testProp, testProp.createNewFile());

    // Create required support files.
    ErrorLibraryFileGenerationTest.copyErrorPropertiesToProjectRoot("QAErrors.properties", projRoot, "runtime");
    ErrorLibraryFileGenerationTest.copyErrorXmlToProjectRoot("ErrorData_QA.xml", projRoot, "runtime");

    return testProp;
}

From source file:org.ebayopensource.turmeric.tools.errorlibrary.ErrorLibraryFileGenerationTest.java

public static void copyErrorXmlToProjectRoot(String sourceFileName, File projectRoot, String domain)
        throws Exception {
    File sourceFile = TestResourceUtil
            .getResource("org/ebayopensource/turmeric/test/tools/codegen/data/" + sourceFileName);
    String path = "meta-src/META-INF/errorlibrary/" + domain + "/ErrorData.xml";
    File outputFile = new File(projectRoot, FilenameUtils.separatorsToSystem(path));
    MavenTestingUtils.ensureDirExists(outputFile.getParentFile());
    FileUtils.copyFile(sourceFile, outputFile);
}

From source file:org.ebayopensource.turmeric.tools.errorlibrary.ErrorLibraryFileGenerationTest.java

public static void copyErrorPropertiesToProjectRoot(String sourceFileName, File projectRoot, String domain)
        throws Exception {
    File sourceFile = TestResourceUtil
            .getResource("org/ebayopensource/turmeric/test/tools/codegen/data/" + sourceFileName);
    String path = "meta-src/META-INF/errorlibrary/" + domain + "/Errors_en_US.properties";
    File outputFile = new File(projectRoot, FilenameUtils.separatorsToSystem(path));
    MavenTestingUtils.ensureDirExists(outputFile.getParentFile());
    FileUtils.copyFile(sourceFile, outputFile);
}

From source file:org.ebayopensource.turmeric.tools.GeneratedAssert.java

public static File assertFileExists(File outputDir, String path) {
    File expectedFile = new File(outputDir, FilenameUtils.separatorsToSystem(path));
    Assert.assertThat("Generated Path should exist: " + expectedFile.getAbsolutePath(), expectedFile.exists(),
            is(true));// w w  w. java 2  s . c om
    Assert.assertThat("Generated Path should be a file: " + expectedFile.getAbsolutePath(),
            expectedFile.isFile(), is(true));
    return expectedFile;
}

From source file:org.ebayopensource.turmeric.tools.GeneratedAssert.java

public static File assertDirExists(File outputDir, String path) {
    File expectedDir = new File(outputDir, FilenameUtils.separatorsToSystem(path));
    Assert.assertThat("Generated Path should exist: " + expectedDir.getAbsolutePath(), expectedDir.exists(),
            is(true));//from w  w w  . j a  va2  s. c o  m
    Assert.assertThat("Generated Path should be a directory: " + expectedDir.getAbsolutePath(),
            expectedDir.isDirectory(), is(true));
    return expectedDir;
}

From source file:org.ebayopensource.turmeric.tools.GeneratedAssert.java

public static void assertPathNotExists(File outputDir, String path) {
    File expectedFile = new File(outputDir, FilenameUtils.separatorsToSystem(path));
    Assert.assertThat("Generated Path should NOT exist: " + expectedFile.getAbsolutePath(),
            expectedFile.exists(), is(false));
}

From source file:org.ebayopensource.turmeric.tools.TestResourceUtil.java

/**
 * Gets a required resource file from the test resources dir.
 * //from   w ww  .j  av a2s .co  m
 * @param path
 *            the path to fetch (Note: use "/" always as this argument, the internal implementation will adjust the
 *            path accordingly on all systems)
 * @return the resource required (will throw an assertion failure if the resource does not exist)
 */
public static File getResource(String path) {
    String syspath = FilenameUtils.separatorsToSystem(path);
    File resource = new File(TestResourceUtil.getDir(), syspath);
    PathAssert.assertFileExists(resource);
    return resource;
}

From source file:org.ebayopensource.turmeric.tools.TestResourceUtil.java

/**
 * Gets a required resource dir from the test resources dir.
 * /*from   w ww  . j  av  a  2  s .c o  m*/
 * @param path
 *            the path to fetch (Note: use "/" always as this argument, the internal implementation will adjust the
 *            path accordingly on all systems)
 * @return the resource required (will throw an assertion failure if the resource does not exist)
 */
public static File getResourceDir(String path) {
    String syspath = FilenameUtils.separatorsToSystem(path);
    File resource = new File(TestResourceUtil.getDir(), syspath);
    PathAssert.assertDirExists(resource);
    return resource;
}

From source file:org.ebayopensource.turmeric.tools.TestResourceUtil.java

/**
 * Copy a test resource into the {@link TestingDir} managed location
 * //from   ww w  .ja  v a 2s.co  m
 * @param path
 *            the path to the resource (will be reused as the output path in the {@link TestingDir#getDir()} +
 *            testingDirPath)
 * @param testingdir
 *            the test specific testing dir
 * @param testingDirPath
 *            the path within the test specific testing dir to use
 * @return the destination file that was copied
 * @throws IOException
 */
public static File copyResource(String path, TestingDir testingdir, String testingDirPath) throws IOException {
    File destBaseDir = testingdir.getFile(FilenameUtils.separatorsToSystem(testingDirPath));
    MavenTestingUtils.ensureDirExists(destBaseDir);
    File resource = getResource(path);
    String filename = resource.getName();
    String destRelPath = path.substring(0, path.length() - filename.length());
    String destPath = FilenameUtils.normalize(destRelPath + "/" + filename);
    File destFile = new File(destBaseDir, FilenameUtils.separatorsToSystem(destPath));
    FileUtils.copyFile(resource, destFile);
    return destFile;
}