this.moduleDefinition = moduleDefinition;
this.runtime = runtime;
}
private ModuleConfig build() {
ModuleSource moduleSource = null;
VersionManager versionManager = new VersionManager(runtime);
try {
moduleSource = runtime.getModuleSourceManager().getModuleSource(moduleDefinition.getFile(), moduleDefinition.getSourceType());
// build classpath
ClassLoadingConfig classLoadingConfig;
InputStream is = moduleSource.getClassLoaderConfig();
if (is != null) {
try {
Document document = DocumentHelper.parse(is);
classLoadingConfig = XmlClassLoaderBuilder.build(document.getDocumentElement(), moduleSource, runtime.getArtifactRepository(), versionManager);
} finally {
IOUtils.closeQuietly(is);
}
} else {
ClasspathEntry selfEntry = new ClasspathEntry(new FileArtifactRef(moduleSource.getClassPathEntry()), ArtifactSharingMode.PROHIBITED, moduleSource);
classLoadingConfig = new ClassLoadingConfigImpl(Collections.singletonList(selfEntry), runtime.getArtifactRepository());
}
return new ModuleConfigImpl(moduleDefinition, classLoadingConfig, moduleSource);
} catch (Throwable e) {
if (moduleSource != null) {
try {
moduleSource.dispose();
} catch (Throwable e2) {
log.error("Error disposing module source for file " + moduleDefinition.getFile().getAbsolutePath(), e2);
}
}