in uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java [661:813]
public int main1(String[] arguments) {
boolean hadError = false;
try {
try {
if (null == progressMonitor) {
progressMonitor = new UimaLoggerProgressMonitor();
}
if (null == error)
error = new LogThrowErrorImpl();
String inputFile = null;
String outputDirectory = null;
TypeSystemDescription typeSystemDescription = null;
TypeDescription[] tds = null;
projectPathDir = ""; // init to default value
limitJCasGenToProjectScope = false;
for (int i = 0; i < arguments.length - 1; i++) {
if (arguments[i].equalsIgnoreCase("-jcasgeninput")) {
inputFile = arguments[++i];
continue;
}
if (arguments[i].equalsIgnoreCase("-jcasgenoutput")) {
outputDirectory = arguments[++i];
continue;
}
// This is used by the jcasgen maven plugin
if (arguments[i].equalsIgnoreCase("=jcasgenclasspath") || // https://issues.apache.org/jira/browse/UIMA-3044
arguments[i].equalsIgnoreCase("-jcasgenclasspath")) { // https://issues.apache.org/jira/browse/UIMA-3044
classPath = arguments[++i];
continue;
}
if (arguments[i].equalsIgnoreCase("-limitToDirectory")) {
projectPathDir = arguments[++i];
limitJCasGenToProjectScope = (projectPathDir.length() > 0);
continue;
}
}
xmlSourceFileName = inputFile.replaceAll("\\\\", "/");
URL url;
if (inputFile.substring(0, 4).equalsIgnoreCase("jar:")) {
// https://issues.apache.org/jira/browse/UIMA-1793 get things out of Jars
try {
url = new URL(inputFile);
// if (null == url) { // is never null from above line
// error.newError(IError.ERROR, getString("fileNotFound", new Object[] { inputFile }),
// null);
// }
if (null == outputDirectory || outputDirectory.equals("")) {
error.newError(IError.ERROR,
getString("sourceArgNeedsDirectory", new Object[] { inputFile }), null);
}
} catch (MalformedURLException e) {
error.newError(IError.ERROR, getString("fileNotFound", new Object[] { inputFile }),
null);
url = null; // never get here, the previous statement throws. Needed, though for java
// path analysis.
}
} else {
File file = new File(inputFile);
if (!file.exists()) {
error.newError(IError.ERROR, getString("fileNotFound", new Object[] { inputFile }),
null);
}
if (null == outputDirectory || outputDirectory.equals("")) {
File dir = file.getParentFile();
if (null == dir) {
error.newError(IError.ERROR,
getString("sourceArgNeedsDirectory", new Object[] { inputFile }), null);
}
outputDirectory = dir.getPath() + File.separator + "JCas"
+ ((null != merger) ? "" : "New");
}
url = file.toURI().toURL();
}
progressMonitor.beginTask("", 5);
progressMonitor.subTask("Output going to '" + outputDirectory + "'");
progressMonitor.subTask(
getString("ReadingDescriptorAndCreatingTypes", new Object[] { inputFile }));
// code to read xml and make cas type instance
CASImpl casLocal = null;
// handle classpath
try {
XMLInputSource in = new XMLInputSource(url);
XMLizable specifier = UIMAFramework.getXMLParser().parse(in);
mergedTypesAddingFeatures.clear();
if (specifier instanceof AnalysisEngineDescription) {
AnalysisEngineDescription aeSpecifier = (AnalysisEngineDescription) specifier;
if (!aeSpecifier.isPrimitive())
typeSystemDescription = CasCreationUtils.mergeDelegateAnalysisEngineTypeSystems(
aeSpecifier, createResourceManager(), mergedTypesAddingFeatures);
else
typeSystemDescription = mergeTypeSystemImports(
aeSpecifier.getAnalysisEngineMetaData().getTypeSystem());
} else if (specifier instanceof TypeSystemDescription)
typeSystemDescription = mergeTypeSystemImports(((TypeSystemDescription) specifier));
else {
error.newError(IError.ERROR, getString("fileDoesntParse", new Object[] { inputFile }),
null);
}
if (mergedTypesAddingFeatures.size() > 0) {
error.newError(IError.WARN, getString("typesHaveFeaturesAdded",
new Object[] { makeMergeMessage(mergedTypesAddingFeatures) }), null);
}
TypePriorities typePriorities = null;
FsIndexDescription[] fsIndexDescription = null;
try {
// no ResourceManager, since everything has been
// imported/merged by previous actions
casLocal = (CASImpl) CasCreationUtils.createCas(typeSystemDescription, typePriorities,
fsIndexDescription);
} catch (ResourceInitializationException e) {
error.newError(IError.WARN, getString("resourceInitializationException",
new Object[] { e.getLocalizedMessage() }), e);
casLocal = null; // continue with null cas, anyway
}
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidXMLException e) {
error.newError(IError.ERROR, getString("invalidXML", new Object[] { inputFile }), e);
} catch (ResourceInitializationException e) {
error.newError(IError.ERROR,
getString("resourceInitializationExceptionError", new Object[] {}), e);
}
progressMonitor.worked(1);
tds = typeSystemDescription.getTypes();
// Generate type classes from DEFAULT templates
generateAllTypesFromTemplates(outputDirectory, tds, casLocal, JCasTypeTemplate.class);
} catch (IOException e) {
error.newError(IError.ERROR, getString("IOException", new Object[] {}), e);
} catch (ErrorExit e) {
hadError = true;
} catch (InstantiationException e) {
error.newError(IError.ERROR, getString("InstantiationException", new Object[] {}), e);
} catch (IllegalAccessException e) {
error.newError(IError.ERROR, getString("IllegalAccessException", new Object[] {}), e);
}
} finally {
progressMonitor.done();
}
return (hadError) ? -1 : 0;
}