File sourceLocation = artifactSourceLocations.getSourceLocation(groupId, artifactId);
if (sourceLocation != null) {
fileToImport = sourceLocation.getCanonicalFile();
if (!fileToImport.exists()) {
throw new LilyRTException("Specified artifact source directory does not exist: "
+ fileToImport.getAbsolutePath(), importConf.getLocation());
}
sourceType = ModuleSourceType.SOURCE_DIRECTORY;
} else {
fileToImport = repository.resolve(groupId, artifactId, classifier, version);
sourceType = ModuleSourceType.JAR;
}
} else if (importConf.getName().equals("directory")) {
id = importConf.getAttribute("id");
String dirName = PropertyResolver.resolveProperties(importConf.getAttribute("path"));
// When basePath is specified, the directory specified in dirName will be resolved
// against basePath. Moreover, basePath can contain a list of paths,
// in which case each basePath will be combined with the path. (this is the only
// reason for having basePath as a separate attribute)
// (It would make sense to allow multiple values for path as well, but the
// need hasn't come up)
String basePath = importConf.getAttribute("basePath", null);
if (basePath != null) {
basePath = PropertyResolver.resolveProperties(basePath);
String[] basePaths = basePath.split(File.pathSeparator);
for (String path : basePaths) {
path = path.trim();
if (path.length() > 0) {
String subDirName = new File(new File(path), dirName).getAbsolutePath();
include(subDirName, id, modules, wiringFileStack, repository, artifactSourceLocations);
}
}
} else {
include(dirName, id, modules, wiringFileStack, repository, artifactSourceLocations);
}
} else {
throw new LilyRTException("Unexpected node: " + importConf.getName(), importConf.getLocation());
}
if (fileToImport != null) {
if (!fileToImport.exists()) {
throw new LilyRTException("Import does not exist: " + fileToImport.getAbsolutePath(),
importConf.getLocation());
}
ModuleDefinition moduleDefinition = new ModuleDefinition(id, fileToImport, sourceType);
moduleDefinition.setLocation(importConf.getLocation());