List of usage examples for org.apache.commons.io FilenameUtils separatorsToSystem
public static String separatorsToSystem(String path)
From source file:org.ebayopensource.turmeric.plugins.maven.codegen.PathMustNotExistRule.java
@Override public List<String> verify() { LinkedList<String> failures = new LinkedList<String>(); for (Entry<String, String> entry : checks.entrySet()) { String checkPath = FilenameUtils.separatorsToSystem(entry.getKey()); File testPath = new File(baseDir, checkPath); if (testPath.exists()) { failures.add(String.format(" %s : Path should not exist (%s)", checkPath, entry.getValue())); }/*w ww .j a v a 2 s. c om*/ } if (failures.size() > 0) { failures.add(0, String.format("[%s: %s] Failures - %s", this.getClass().getSimpleName(), basePath, baseDir)); } return failures; }
From source file:org.ebayopensource.turmeric.plugins.maven.resources.ResourceLocator.java
private URI findFileResource(File path, String pathref) { if (path.isFile()) { // Assume its an archive. String extn = FilenameUtils.getExtension(path.getName()); if (StringUtils.isBlank(extn)) { log.debug("No extension found for file: " + path); return null; }//w ww . ja va 2s . c o m extn = extn.toLowerCase(); if ("jar".equals(extn)) { log.debug("looking inside of jar file: " + path); JarFile jar = null; try { jar = new JarFile(path); JarEntry entry = jar.getJarEntry(pathref); if (entry == null) { log.debug("JarEntry not found: " + pathref); return null; } String uripath = String.format("jar:%s!/%s", path.toURI(), entry.getName()); try { return new URI(uripath); } catch (URISyntaxException e) { log.debug("Unable to create URI reference: " + path, e); return null; } } catch (JarException e) { log.debug("Unable to open archive: " + path, e); return null; } catch (IOException e) { log.debug("Unable to open archive: " + path, e); return null; } finally { if (jar != null) { try { jar.close(); } catch (IOException e) { log.debug("Unable to close jar: " + path, e); } } } } log.debug("Unsupported archive file: " + path); return null; } if (path.isDirectory()) { File testFile = new File(path, FilenameUtils.separatorsToSystem(pathref)); if (testFile.exists() && testFile.isFile()) { return testFile.toURI(); } log.debug("Not found in directory: " + testFile); return null; } log.debug("Unable to handle non-file, non-directory " + File.class.getName() + " objects: " + path); return null; }
From source file:org.ebayopensource.turmeric.plugins.maven.resources.ResourceLocator.java
private String toOS(String path) { return FilenameUtils.separatorsToSystem(path); }
From source file:org.ebayopensource.turmeric.plugins.maven.stubs.TurmericProjectStub.java
private File toFile(URL url, String path) { if (url.getProtocol().equals("jar")) { String jarfilename = url.toExternalForm(); jarfilename = jarfilename.substring("jar:".length()); int idx = jarfilename.indexOf("!/"); if (idx > 0) { jarfilename = jarfilename.substring(0, idx); }//w ww .j a v a 2s . c o m System.out.printf("Project Dependency: %s%n", jarfilename); return new File(jarfilename); } if (url.getProtocol().equals("file")) { File file; try { file = new File(url.toURI()); } catch (URISyntaxException e) { file = new File(url.toExternalForm()); } String filename = file.getAbsolutePath(); String syspath = FilenameUtils.separatorsToSystem(path); if (filename.endsWith(syspath)) { filename = filename.substring(0, filename.length() - syspath.length()); } return new File(filename); } return null; }
From source file:org.ebayopensource.turmeric.runtime.config.validation.ConfigAsserts.java
private static String os(String path) { return FilenameUtils.separatorsToSystem(path); }
From source file:org.ebayopensource.turmeric.tools.codegen.AbstractServiceGeneratorTestCase.java
protected File getTestDestPath(String path) { String syspath = FilenameUtils.separatorsToSystem(path); return new File(getTestDestDir(), syspath); }
From source file:org.ebayopensource.turmeric.tools.codegen.CodeGenUtilTest.java
@Test public void normalizePath() throws Exception { String expectedPath = FilenameUtils.separatorsToSystem("com/ebay/"); String normalizedPath = CodeGenUtil.toOSFilePath("com\\ebay"); Assert.assertEquals(expectedPath, normalizedPath); }
From source file:org.ebayopensource.turmeric.tools.codegen.CodeGenUtilTest.java
@Test public void normalizePath2() throws Exception { String expectedPath = FilenameUtils.separatorsToSystem("com/ebay/"); String normalizedPath = CodeGenUtil.toOSFilePath("com/ebay/"); Assert.assertEquals(expectedPath, normalizedPath); }
From source file:org.ebayopensource.turmeric.tools.codegen.ServiceGeneratorWSDLTest.java
@Test public void testDefaultingInputTypeWSDL() throws Exception { // Initialize testing paths MavenTestingUtils.ensureEmpty(testingdir); File destDir = getTestDestDir(); File binDir = testingdir.getFile("bin"); File rootDir = testingdir.getDir(); String wsdlToBeCopied = "org/ebayopensource/turmeric/test/tools/codegen/data/CalcService.wsdl"; File wsdl = TestResourceUtil.copyResource(wsdlToBeCopied, testingdir, "meta-src"); // generate the service_metadata.properties // @formatter:off String args1[] = { // this is a WSDL based service "-servicename", "MyCalcService9031", "-wsdl", wsdl.getAbsolutePath(), "-gentype", "ServiceMetadataProps", "-pr", rootDir.getAbsolutePath(), "-scv", "1.2.0", "-slayer", "COMMON" }; // @formatter:on performDirectCodeGen(args1);//from w w w. j a v a 2 s . c om //Copying the WSDL to the required folder where codegen will pick it File destBaseDir = testingdir.getFile(FilenameUtils.separatorsToSystem( "meta-src/META-INF/soa/services/wsdl/MyCalcService9031/MyCalcService9031.wsdl")); TestResourceUtil.copyResource(wsdlToBeCopied, destBaseDir); // generate all the other artifacts // @formatter:off String args2[] = { // not providing the inputType, the code should default to WSDL based service as SMP would contain wsdluri "-servicename", "MyCalcService9031", "-gentype", "All", "-pr", rootDir.getAbsolutePath(), "-dest", destDir.getAbsolutePath(), "-bin", binDir.getAbsolutePath() }; // @formatter:on performDirectCodeGen(args2); }
From source file:org.ebayopensource.turmeric.tools.codegen.util.CodeGenClassLoader.java
/** * Returns a class loader that can load classes from JDK tools.jar. * //from w w w . j a va 2s . co m * @param parentClassLoader */ private static URL[] getToolsJar(ClassLoader parent) throws CodeGenFailedException { // @formatter:off String expectedClasses[] = { "com.sun.tools.javac.Main", "com.sun.tools.apt.Main", "com.sun.javadoc.Doclet" }; // @formatter:on // If all of the expected classes are present already // then just return the active classloader. boolean foundExpected = true; for (String expectedClass : expectedClasses) { try { Class.forName(expectedClass, false, parent); } catch (ClassNotFoundException e) { foundExpected = false; break; } } if (foundExpected) { // we can already load them in the parent class loader. // so no need to look for tools.jar. // this happens when we are run inside IDE/Ant, or // in Mac OS. return new URL[0]; } // 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" }; // @formatter:on // Start with the jdkHome File jdkHome = new File(System.getProperty("java.home")); if (!CodeGenUtil.isEmptyString(ServiceGenerator.s_JdkHome)) { jdkHome = new File(ServiceGenerator.s_JdkHome); s_logger.log(Level.INFO, "JdkHome being used for classloader is :" + jdkHome); } // The search process File toolsJar = null; 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()); } try { return new URL[] { toolsJar.toURI().toURL() }; } catch (MalformedURLException e) { throw new CodeGenFailedException( "MalformedURLException from the tools.jar location: " + toolsJar.getAbsolutePath(), e); } }