You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by al...@apache.org on 2006/12/14 23:39:01 UTC
svn commit: r487377 - in /incubator/uima/uimaj/trunk/uimaj-tools/src/main:
java/org/apache/uima/tools/migration/
resources/org/apache/uima/tools/migration/
Author: alally
Date: Thu Dec 14 14:39:00 2006
New Revision: 487377
URL: http://svn.apache.org/viewvc?view=rev&rev=487377
Log:
More improvements to migration utility.
UIMA-49: https://issues.apache.org/jira/browse/UIMA-49
Modified:
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/migration/IbmUimaToApacheUima.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/migration/packageMapping.txt
incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/migration/stringReplacements.txt
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/migration/IbmUimaToApacheUima.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/migration/IbmUimaToApacheUima.java?view=diff&rev=487377&r1=487376&r2=487377
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/migration/IbmUimaToApacheUima.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/migration/IbmUimaToApacheUima.java Thu Dec 14 14:39:00 2006
@@ -24,8 +24,11 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.TreeMap;
import org.apache.uima.internal.util.FileUtils;
@@ -41,6 +44,7 @@
private static Map packageMapping = new TreeMap();
private static Map stringReplacements = new TreeMap();
private static int MAX_FILE_SIZE = 1000000; //don't update files bigger than this
+ private static Set extensions = new HashSet();
/**
* Main program. Expects one argument, the name of a directory containing files to
@@ -49,21 +53,70 @@
* @throws IOException if an I/O error occurs
*/
public static void main(String[] args) throws IOException{
- if (args.length < 1) {
- System.err.println("Usage: java " + IbmUimaToApacheUima.class.getName() + " <directory>");
- System.exit(1);
+ //parse command line
+ String dir = null;
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].startsWith("-")) {
+ if (args[i].equals("-ext")) {
+ if (i + 1 >= args.length) {
+ printUsageAndExit();
+ }
+ parseCommaSeparatedList(args[++i], extensions);
+ }
+ else {
+ System.err.println("Unknown switch " + args[i]);
+ printUsageAndExit();
+ }
+ }
+ else {
+ if (dir != null) {
+ printUsageAndExit();
+ }
+ else {
+ dir = args[i];
+ }
+ }
+ }
+ if (dir == null) {
+ printUsageAndExit();
}
+
//read resource files
- //mapp from IBM UIMA package names to Apache UIMA package names
+ //map from IBM UIMA package names to Apache UIMA package names
readMapping("packageMapping.txt", packageMapping);
//other string replacements
readMapping("stringReplacements.txt", stringReplacements);
+ //from system property, get list of file extensions to exclude
+
//do the replacements
replaceInAllFiles(new File(args[0]));
}
/**
+ * Parses a comma separated list, entering each value into the results Collection.
+ * Trailing empty strings are included in the results Collection.
+ * @param string string to parse
+ * @param results Collection to which each value will be added
+ */
+ private static void parseCommaSeparatedList(String string, Collection results) {
+ String[] components = string.split(",",-1);
+ for (int i = 0; i < components.length; i++) {
+ results.add(components[i]);
+ }
+ }
+
+ /**
+ *
+ */
+ private static void printUsageAndExit() {
+ System.err.println("Usage: java " + IbmUimaToApacheUima.class.getName() + " <directory> [-ext <fileExtensions>]");
+ System.err.println("<fileExtensions> is a comma separated list of file extensions to process, e.g.: java,xml,properties");
+ System.err.println("\tUse a trailing comma to include files with no extension (meaning their name contains no dot)");
+ System.exit(1);
+ }
+
+ /**
* Applies the necessary replacements to all files in the given directory.
* Subdirectories are processed recursively.
*
@@ -75,18 +128,31 @@
for (int i = 0; i < fileList.length; i++) {
File file = fileList[i];
if (file.isFile()) {
+ //skip files with extensions specified in the excludes list
+ if (!extensions.isEmpty()) {
+ String filename = file.getName();
+ String ext="";
+ int lastDot = filename.lastIndexOf('.');
+ if (lastDot > -1) {
+ ext = filename.substring(lastDot+1);
+ }
+ if (!extensions.contains(ext.toLowerCase())) {
+ continue;
+ }
+ }
+
//skip files that we can't read and write
if (!file.canRead()) {
- System.err.println("Skipping unreadable file: " + file.getPath());
+ System.err.println("Skipping unreadable file: " + file.getCanonicalPath());
continue;
}
if (!file.canWrite()) {
- System.err.println("Skipping unwritable file: " + file.getPath());
+ System.err.println("Skipping unwritable file: " + file.getCanonicalPath());
continue;
}
//skip files that are too big
if (file.length() > MAX_FILE_SIZE) {
- System.err.println("Skipping file " + file.getPath() + " with size: " + file.length() + " bytes");
+ System.out.println("Skipping file " + file.getCanonicalPath() + " with size: " + file.length() + " bytes");
continue;
}
@@ -121,23 +187,15 @@
//loop over packages to replace
//we do special processing for package names to try to handle the case where
//user code exists in a package prefixed by com.ibm.uima.
- //in .java files, we only replace imports
- //in other files, we only replace the package name when it appears on its own,
- //not as a prefix of another package.
+ //We only replace the package name when it appears as part of a fully-qualified
+ //class name in that package, not as a prefix of another package.
Iterator entries = packageMapping.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry)entries.next();
String ibmPkg = (String)entry.getKey();
String apachePkg = (String)entry.getValue();
- //apply replacement (depends on whether this is a .java file)
- if (file.getName().endsWith(".java")) {
- String regex = "import\\s*"+ibmPkg+"(\\.[^\\.]*;)";
- contents = contents.replaceAll(regex, "import " + apachePkg + "$1");
- }
- else {
- String regex = ibmPkg+"(\\.[^\\.]*[\\W&&[^\\.]])";
- contents = contents.replaceAll(regex, apachePkg + "$1");
- }
+ String regex = ibmPkg+"(\\.(\\*|[A-Z]\\w*))";
+ contents = contents.replaceAll(regex, apachePkg + "$1");
}
//now apply simple string replacements
entries = stringReplacements.entrySet().iterator();
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/migration/packageMapping.txt
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/migration/packageMapping.txt?view=diff&rev=487377&r1=487376&r2=487377
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/migration/packageMapping.txt (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/migration/packageMapping.txt Thu Dec 14 14:39:00 2006
@@ -89,7 +89,7 @@
com.ibm.uima.tutorial.ex6 org.apache.uima.tutorial.ex6
com.ibm.uima.uimacpp org.apache.uima.uimacpp
com.ibm.uima.util org.apache.uima.util
-com.ibm.uima.reference_impl.util org.apache.uima.util.impl
+com.ibm.uima.reference_impl.util org.apache.uima.internal.util
com.ibm.vinci.debug org.apache.vinci.debug
com.ibm.vinci.transport org.apache.vinci.transport
com.ibm.vinci.transport.context org.apache.vinci.transport.context
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/migration/stringReplacements.txt
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/migration/stringReplacements.txt?view=diff&rev=487377&r1=487376&r2=487377
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/migration/stringReplacements.txt (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/migration/stringReplacements.txt Thu Dec 14 14:39:00 2006
@@ -2,4 +2,10 @@
<frameworkImplementation>JEDII</frameworkImplementation> <frameworkImplementation>org.apache.uima.java</frameworkImplementation>
VinciCasObjectProcessorService_impl VinciAnalysisEngineService_impl
org.apache.uima.tools.DocumentAnalyzer org.apache.uima.tools.docanalyzer.DocumentAnalyzer
-http://uima.watson.ibm.com/resourceSpecifier http://uima.apache.org/resourceSpecifier
\ No newline at end of file
+http://uima.watson.ibm.com/resourceSpecifier http://uima.apache.org/resourceSpecifier
+org.apache.uima.internal.util.JSR47Logger_impl org.apache.uima.util.impl.JSR47Logger_impl
+org.apache.uima.internal.util.Logger_impl org.apache.uima.util.impl.Logger_impl
+org.apache.uima.internal.util.ProcessTrace_impl org.apache.uima.util.impl.ProcessTrace_impl
+org.apache.uima.internal.util.ProcessTraceEvent_impl org.apache.uima.util.impl.ProcessTraceEvent_impl
+org.apache.uima.internal.util.SaxDeserializer_impl org.apache.uima.util.impl.SaxDeserializer_impl
+org.apache.uima.internal.util.XMLParser_impl org.apache.uima.util.impl.XMLParser_impl