Author: schor Date: Fri Apr 19 18:59:46 2019 New Revision: 1857826 URL: http://svn.apache.org/viewvc?rev=1857826&view=rev Log: [UIMA-6025] extend migration tool to work on 1 source file.
Modified: uima/uv3/uimaj-v3/trunk/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/MigrateJCas.java Modified: uima/uv3/uimaj-v3/trunk/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/MigrateJCas.java URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/MigrateJCas.java?rev=1857826&r1=1857825&r2=1857826&view=diff ============================================================================== --- uima/uv3/uimaj-v3/trunk/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/MigrateJCas.java (original) +++ uima/uv3/uimaj-v3/trunk/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/MigrateJCas.java Fri Apr 19 18:59:46 2019 @@ -127,6 +127,7 @@ import com.github.javaparser.printer.Pre * <ul><li>converts these to v3</li></ul></li></ul> * * <li>also can receive a list of individual class names</li> + * <li>also can do a single source file</li> * </ul> * * <p>Creates summary and detailed reports of its actions. @@ -206,7 +207,7 @@ import com.github.javaparser.printer.Pre * - compiles the results * - does reassembly for Jars and PEARs, replacing the JCas classes. * - * Mode 2: Given sources-roots + * Mode 2: Given sources-roots or a single source java file * scans the sources-routes looking for candidates * - migrates that decompiled source. * </pre> @@ -289,6 +290,7 @@ public class MigrateJCas extends VoidVis final List<V3CompiledPathAndContainerItemPath> v3CompiledPathAndContainerItemPath = new ArrayList<>(); final boolean isPear; final boolean isJar; + final boolean isSingleJavaSource; /** can't use Path as the type, because the equals for Path is object == */ final Set<String> _Types = new HashSet<>(); // has the non_Type path only if the _Type is found boolean haveDifferentCapitalizedNamesCollidingOnWindows = false; @@ -309,6 +311,7 @@ public class MigrateJCas extends VoidVis String s = root.toString().toLowerCase(); isJar = s.endsWith(".jar"); isPear = s.endsWith(".pear"); + isSingleJavaSource = s.endsWith(".java"); this.root = (isPear || isJar) ? installJarOrPear() : root; @@ -2205,13 +2208,16 @@ public class MigrateJCas extends VoidVis private void getAndProcessCandidatesInContainer(Container container) { // current_paths2RootIds = top_paths2RootIds; // don't do lower, that's called within Jars etc. - - try (Stream<Path> stream = Files.walk(container.root, FileVisitOption.FOLLOW_LINKS)) { // needed to release file handles - stream.forEachOrdered( - // only puts into the RootIds possible Fqcn (ending in either .class or .java) - p -> getCandidates_processFile2(p, container)); - } catch (IOException e) { - throw new RuntimeException(e); + if (container.isSingleJavaSource) { + getCandidates_processFile2(container.root, container); + } else { + try (Stream<Path> stream = Files.walk(container.root, FileVisitOption.FOLLOW_LINKS)) { // needed to release file handles + stream.forEachOrdered( + // only puts into the RootIds possible Fqcn (ending in either .class or .java) + p -> getCandidates_processFile2(p, container)); + } catch (IOException e) { + throw new RuntimeException(e); + } } // walk from root container, remove items not JCas candidates @@ -2310,7 +2316,7 @@ public class MigrateJCas extends VoidVis // System.out.println("debug container._Types did contain " + candidate); // } // } - if (!container._Types.contains(candidate)) { + if (!container.isSingleJavaSource && !container._Types.contains(candidate)) { it.remove(); } } @@ -2924,7 +2930,7 @@ public class MigrateJCas extends VoidVis private void printUsage() { System.out.println( "Usage: java org.apache.uima.migratev3.jcas.MigrateJCas \n" - + " [-sourcesRoots <One-or-more-directories-or-jars-separated-by-Path-separator>]\n" + + " [-sourcesRoots <One-or-more-directories-or-jars-separated-by-Path-separator, or a path to a single JCas source class>]\n" + " [-classesRoots <One-or-more-directories-or-jars-or-pears-separated-by-Path-separator>]\n" + " [-outputDirectory a-writable-directory-path (optional)\n" + " if omitted, a temporary directory is used\n"