CAS cas = CasCreationUtils.createCas(initialTypeSystem, null, new FsIndexDescription[0]);
fillTypeNameMap(typeNameMap, cas.getTypeSystem());
cas.release();
List<TypeSystemDescription> toInclude = new ArrayList<TypeSystemDescription>();
List<Import> importList = new ArrayList<Import>();
Import_impl import_impl = new Import_impl();
if (option.isImportByName()) {
String name = initialTypeSystem.getName();
import_impl.setName(name);
} else if (option.isResolveImports()) {
String absoluteLocation = initialTypeSystem.getSourceUrlString();
import_impl.setLocation(absoluteLocation);
} else {
String relativeLocation = getRelativeLocation(defaultTypeSystemFile.getAbsolutePath(),
typeSystemOutput);
import_impl.setLocation(relativeLocation);
}
importList.add(import_impl);
for (String eachName : desc.getImportedTypeSystems()) {
String locate = RutaEngine.locate(eachName, enginePaths, ".xml");
URL url = null;
boolean include = false;
if (locate != null) {
File file = new File(locate);
url = file.toURI().toURL();
}
if (url == null) {
url = checkImportExistence(eachName, "xml", classloader);
include = true;
if (url == null) {
throw new FileNotFoundException("Build process can't find " + eachName + " in "
+ mainScript);
}
}
TypeSystemDescription each = getTypeSystemDescriptor(url, option);
if (each != null) {
fillTypeNameMap(typeNameMap, each);
if (include) {
// need to include the complete type system because an import is not possible
each.resolveImports(rm);
toInclude.add(each);
} else {
import_impl = new Import_impl();
if (option.isImportByName()) {
import_impl.setName(eachName);
} else if (option.isResolveImports()) {
String absoluteLocation = each.getSourceUrlString();
import_impl.setLocation(absoluteLocation);
} else {
String path = url.getPath();
String relativeLocation = getRelativeLocation(path, typeSystemOutput);
File parentFile = new File(typeSystemOutput).getParentFile();
File targetFile = new File(parentFile, relativeLocation);
boolean ableToFindFile = targetFile.exists();
if (!ableToFindFile) {
// hotfix for different partitions making trouble for the relative path
import_impl.setName(eachName);
} else {
import_impl.setLocation(relativeLocation);
}
}
importList.add(import_impl);
}
} else {
throw new FileNotFoundException("Build process can't find " + eachName + " in "
+ mainScript);
}
}
for (String eachName : desc.getImportedScripts()) {
// TODO
String locate = RutaEngine.locate(eachName, enginePaths, "TypeSystem.xml");
File file = new File(locate);
URL url = file.toURI().toURL();
TypeSystemDescription each = getTypeSystemDescriptor(url, option);
if (each != null) {
fillTypeNameMap(typeNameMap, each);
import_impl = new Import_impl();
if (option.isImportByName()) {
import_impl.setName(eachName + "TypeSystem");
} else if (option.isResolveImports()) {
String absoluteLocation = each.getSourceUrlString();
import_impl.setLocation(absoluteLocation);
} else {
String relativeLocation = getRelativeLocation(file.getAbsolutePath(), typeSystemOutput);
import_impl.setLocation(relativeLocation);
}
importList.add(import_impl);
} else {
throw new FileNotFoundException("Build process can't find " + eachName + " in "
+ mainScript);
}
}
typeSystemDescription = CasCreationUtils.mergeTypeSystems(toInclude, rm);
Import[] newImports = importList.toArray(new Import[0]);
typeSystemDescription.setImports(newImports);
if (option.isResolveImports()) {
try {
typeSystemDescription.resolveImports(rm);
} catch (InvalidXMLException e) {
throw new RutaBuildException("Failed to resolve imported Type Systems", e);
}
}
// TODO hotfixes: where do I get the final types??
Set<String> finalTypes = new HashSet<String>();
finalTypes.addAll(Arrays.asList(new String[] { "uima.cas.Boolean", "uima.cas.Byte",
"uima.cas.Short", "uima.cas.Integer", "uima.cas.Long", "uima.cas.Float", "uima.cas.Double",
"uima.cas.BooleanArray", "uima.cas.ByteArray", "uima.cas.ShortArray",
"uima.cas.IntegerArray", "uima.cas.LongArray", "uima.cas.FloatArray",
"uima.cas.DoubleArray", "uima.cas.StringArray", "uima.cas.FSArray" }));
int typeIndex = 0;
for (String eachType : desc.getTypeShortNames()) {
StringTriple typeTriple = desc.getTypeTriples().get(typeIndex);
typeTriple = resolveType(typeTriple, typeNameMap, mainScript);
if (typeSystemDescription.getType(typeTriple.getName()) != null) {
continue;
}
if (!finalTypes.contains(typeTriple.getParent())) {
TypeDescription newType = typeSystemDescription.addType(typeTriple.getName(),
typeTriple.getDescription(), typeTriple.getParent());
capability.addInputType(typeTriple.getName(), false);
capability.addOutputType(typeTriple.getName(), false);
Collection<StringTriple> collection = desc.getFeatures().get(eachType);
if (collection != null) {
for (StringTriple eachFeature : collection) {
eachFeature = resolveFeature(eachFeature, typeNameMap);
newType.addFeature(eachFeature.getName(), eachFeature.getDescription(),
eachFeature.getParent());
// capability.addInputFeature(eachFeature.getName());
// capability.addOutputFeature(eachFeature.getName());
}
}
}
typeIndex++;
}
Set<String> names = new HashSet<String>();
List<TypeDescription> types = new ArrayList<TypeDescription>();
for (TypeDescription each : typeSystemDescription.getTypes()) {
String name = each.getName();
if (!names.contains(name)) {
names.add(name);
types.add(each);
}
}
File typeSystemFile = getFile(typeSystemOutput);
TypeDescription[] presentTypes = typeSystemDescription.getTypes();
types.addAll(Arrays.asList(presentTypes));
typeSystemDescription.setTypes(types.toArray(new TypeDescription[0]));
typeSystemDescription.setName(mainScript + "TypeSystem");
typeSystemDescription.setSourceUrl(typeSystemFile.toURI().toURL());
TypeSystemDescription aets = uimaFactory.createTypeSystemDescription();
import_impl = new Import_impl();
if (option.isImportByName()) {
import_impl.setName(typeSystemDescription.getName());
} else {
String relativeLocation = getRelativeLocation(engineOutput, typeSystemOutput);
import_impl.setLocation(relativeLocation);
}
File engineFile = configureEngine(desc, engineOutput, option, mainScript, scriptPaths,
enginePaths, capability, import_impl, aets);