use of org.jboss.modules.ModuleLoadException in project wildfly-swarm by wildfly-swarm.
the class Swarm method initializeConfigView.
private void initializeConfigView(Properties props) throws IOException, ModuleLoadException {
try (AutoCloseable handle = Performance.time("Loading YAML")) {
if (System.getProperty(SwarmProperties.PROJECT_STAGE_FILE) != null) {
String file = System.getProperty(SwarmProperties.PROJECT_STAGE_FILE);
boolean loaded = false;
try {
Path path = Paths.get(file);
if (Files.exists(path)) {
this.configView.load("stages", path.toUri().toURL());
loaded = true;
}
} catch (InvalidPathException e) {
// ignore
}
if (!loaded) {
// try it as a URL
try {
URL url = new URL(file);
this.configView.load("stages", url);
} catch (MalformedURLException e) {
// oh well
}
}
}
// List<String> activatedNames = new ArrayList<>();
String projectStageProp = System.getProperty(SwarmProperties.PROJECT_STAGE);
if (projectStageProp == null && props != null) {
projectStageProp = props.getProperty(SwarmProperties.PROJECT_STAGE);
}
if (projectStageProp == null) {
projectStageProp = this.configView.get().resolve(SwarmProperties.PROJECT_STAGE).withDefault("NOT_FOUND").getValue();
if (projectStageProp != null && projectStageProp.equals("NOT_FOUND")) {
projectStageProp = null;
}
}
if (projectStageProp != null) {
String[] activated = projectStageProp.split(",");
for (String each : activated) {
this.configView.load(each);
this.configView.withProfile(each);
}
}
int counter = 0;
for (URL config : this.configs) {
String syntheticName = "cli-" + (++counter);
this.configView.load(syntheticName, config);
this.configView.withProfile(syntheticName);
}
this.configView.load("stages");
for (String profile : this.profiles) {
this.configView.load(profile);
this.configView.withProfile(profile);
}
this.configView.load("defaults");
initializeConfigFilters();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.jboss.modules.ModuleLoadException in project wildfly-swarm by wildfly-swarm.
the class CommandLine method resolveResource.
private static URL resolveResource(String path) {
Path candidate = Paths.get(path);
if (Files.exists(candidate)) {
try {
return candidate.toUri().toURL();
} catch (MalformedURLException e) {
// ignore
}
}
URL yml = null;
try {
Module appModule = Module.getBootModuleLoader().loadModule("swarm.application");
yml = appModule.getClassLoader().getResource(path);
if (yml != null) {
return yml;
}
} catch (ModuleLoadException e) {
// ignore;
}
yml = ClassLoader.getSystemClassLoader().getResource(path);
return yml;
}
use of org.jboss.modules.ModuleLoadException in project wildfly-swarm by wildfly-swarm.
the class MainInvoker method getMainClass.
public static Class<?> getMainClass(String mainClassName) throws IOException, URISyntaxException, ModuleLoadException, ClassNotFoundException {
Class<?> mainClass = null;
try {
Module module = Module.getBootModuleLoader().loadModule("swarm.application");
ClassLoader cl = module.getClassLoader();
mainClass = cl.loadClass(mainClassName);
} catch (ClassNotFoundException | ModuleLoadException e) {
ClassLoader cl = ClassLoader.getSystemClassLoader();
mainClass = cl.loadClass(mainClassName);
}
if (mainClass == null) {
throw new ClassNotFoundException(mainClassName);
}
return mainClass;
}
use of org.jboss.modules.ModuleLoadException in project wildfly-swarm by wildfly-swarm.
the class ApplicationEnvironment method loadFractionManifestsFromUberjar.
private void loadFractionManifestsFromUberjar() throws IOException, ModuleLoadException {
if (this.manifests != null) {
return;
}
this.manifests = new ArrayList<>();
Set<String> modulesManifests = new HashSet<>();
this.bootstrapModules.forEach(moduleName -> {
try {
Module module = Module.getBootModuleLoader().loadModule(moduleName);
ClassLoader cl = module.getClassLoader();
Enumeration<URL> results = cl.getResources(FractionManifest.CLASSPATH_LOCATION);
while (results.hasMoreElements()) {
URL each = results.nextElement();
FractionManifest manifest = new FractionManifest(each);
this.manifests.add(manifest);
modulesManifests.add(manifest.getGroupId() + manifest.getArtifactId());
}
} catch (ModuleLoadException | IOException e) {
throw new RuntimeException(e);
}
});
bootstrapArtifactsAsCoordinates().forEach((coords) -> {
try {
File artifactFile = MavenResolvers.get().resolveJarArtifact(coords);
if (artifactFile == null) {
throw new RuntimeException("Unable to resolve artifact from coordinates: " + coords);
}
try (ZipFile zip = new ZipFile(artifactFile)) {
ZipEntry manifestEntry = zip.getEntry(FractionManifest.CLASSPATH_LOCATION);
if (manifestEntry != null) {
FractionManifest manifest = new FractionManifest(zip.getInputStream(manifestEntry));
if (!modulesManifests.contains(manifest.getGroupId() + manifest.getArtifactId())) {
this.manifests.add(manifest);
}
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
use of org.jboss.modules.ModuleLoadException in project wildfly-swarm by wildfly-swarm.
the class BootstrapClasspathModuleFinder method findModule.
@Override
public ModuleSpec findModule(String identifier, ModuleLoader delegateLoader) throws ModuleLoadException {
String simpleIdentifier = identifier;
if (!identifier.contains(":")) {
identifier = identifier + ":main";
}
try (AutoCloseable handle = Performance.accumulate("module: BootstrapClassPath")) {
final String[] nameAndSlot = identifier.split("\\:", 2);
final String path = "modules/" + nameAndSlot[0].replace('.', MODULE_SEPARATOR) + MODULE_SEPARATOR + nameAndSlot[1] + "/module.xml";
ClassLoader cl = BootstrapClasspathModuleFinder.class.getClassLoader();
URL url = cl.getResource(path);
if (url == null) {
return null;
}
ModuleSpec moduleSpec = null;
InputStream in = null;
try {
final URL base = new URL(url, "./");
in = url.openStream();
moduleSpec = ModuleXmlParser.parseModuleXml((rootPath, loaderPath, loaderName) -> NestedJarResourceLoader.loaderFor(base, rootPath, loaderPath, loaderName), MavenResolvers.get(), "/", in, path.toString(), delegateLoader, simpleIdentifier);
} catch (IOException e) {
throw new ModuleLoadException(e);
} catch (Throwable t) {
throw t;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
throw new ModuleLoadException(e);
}
}
return moduleSpec;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations