use of org.wildfly.swarm.bootstrap.env.ApplicationEnvironment in project wildfly-swarm by wildfly-swarm.
the class ApplicationModuleFinderTest method testDependency.
@Test
public void testDependency() {
// Mocks
ApplicationEnvironment env = mock(ApplicationEnvironment.class);
when(env.getDependencies()).thenReturn(Collections.singleton("org.jboss.forge.addon:ui-spi:jar:3.4.0.Final"));
ModuleSpec.Builder builder = mock(ModuleSpec.Builder.class);
ApplicationModuleFinder sut = new ApplicationModuleFinder();
sut.addDependencies(builder, env);
verify(builder, times(1)).addResourceRoot(any());
}
use of org.wildfly.swarm.bootstrap.env.ApplicationEnvironment in project wildfly-swarm by wildfly-swarm.
the class ApplicationModuleFinder method buildModule.
@Override
public void buildModule(ModuleSpec.Builder builder, ModuleLoader delegateLoader) throws ModuleLoadException {
ApplicationEnvironment env = ApplicationEnvironment.get();
env.bootstrapModules().forEach((module) -> {
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, module, false));
});
try {
addAsset(builder, env);
} catch (IOException e) {
throw new ModuleLoadException(e);
}
addDependencies(builder, env);
try {
addClasspathJars(builder);
} catch (IOException e) {
throw new ModuleLoadException(e);
}
builder.addDependency(DependencySpec.createModuleDependencySpec("org.jboss.modules"));
builder.addDependency(DependencySpec.createModuleDependencySpec("org.jboss.shrinkwrap"));
builder.addDependency(DependencySpec.createModuleDependencySpec("org.wildfly.swarm.configuration", false, true));
builder.addDependency(DependencySpec.createModuleDependencySpec("sun.jdk", false, true));
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, "org.wildfly.swarm.container:api", true));
builder.addDependency(DependencySpec.createLocalDependencySpec());
}
use of org.wildfly.swarm.bootstrap.env.ApplicationEnvironment in project wildfly-swarm by wildfly-swarm.
the class ContainerModuleFinder method buildModule.
@Override
public void buildModule(ModuleSpec.Builder builder, ModuleLoader delegateLoader) throws ModuleLoadException {
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, "org.wildfly.swarm.spi", false));
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, "org.wildfly.swarm.container:runtime", false));
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, "org.wildfly.swarm.bootstrap", false));
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, "org.jboss.jandex", false));
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, "org.jboss.weld.se", false));
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, "javax.enterprise.api", false));
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, "org.apache.xalan", true));
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, "org.apache.xerces", false));
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, "org.codehaus.woodstox", false));
ApplicationEnvironment environment = ApplicationEnvironment.get();
environment.bootstrapModules().forEach((module) -> {
builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), PathFilters.acceptAll(), ClassFilters.acceptAll(), ClassFilters.acceptAll(), null, module + ":" + RUNTIME_SLOT, false));
});
}
use of org.wildfly.swarm.bootstrap.env.ApplicationEnvironment in project wildfly-swarm by wildfly-swarm.
the class RuntimeDeployer method deploy.
public void deploy(Archive<?> deployment, String asName) throws DeploymentException {
if (deployment.getName().endsWith(".rar")) {
// Track any .rar deployments
this.rarDeploymentNames.add(deployment.getName());
} else if (!this.rarDeploymentNames.isEmpty()) {
// Add any previous .rar deployments as dependencies
// of any non-.rar deployments.
JARArchive mutable = deployment.as(JARArchive.class);
this.rarDeploymentNames.forEach(e -> {
mutable.addModule("deployment." + e);
});
}
try (AutoCloseable deploymentTimer = Performance.time("deployment: " + deployment.getName())) {
// see DependenciesContainer#addAllDependencies()
if (deployment instanceof DependenciesContainer) {
DependenciesContainer<?> depContainer = (DependenciesContainer) deployment;
if (depContainer.hasMarker(DependenciesContainer.ALL_DEPENDENCIES_MARKER)) {
if (!depContainer.hasMarker(ALL_DEPENDENCIES_ADDED_MARKER)) {
ApplicationEnvironment appEnv = ApplicationEnvironment.get();
if (ApplicationEnvironment.Mode.UBERJAR == appEnv.getMode()) {
ArtifactLookup artifactLookup = ArtifactLookup.get();
for (String gav : appEnv.getDependencies()) {
depContainer.addAsLibrary(artifactLookup.artifact(gav));
}
} else {
Set<String> paths = appEnv.resolveDependencies(Collections.emptyList());
for (String path : paths) {
final File pathFile = new File(path);
if (path.endsWith(".jar")) {
depContainer.addAsLibrary(pathFile);
} else if (pathFile.isDirectory()) {
depContainer.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class).importDirectory(pathFile).as(GenericArchive.class), "/WEB-INF/classes", Filters.includeAll());
}
}
}
depContainer.addMarker(ALL_DEPENDENCIES_ADDED_MARKER);
}
}
}
this.deploymentContext.activate(deployment, asName, !this.implicitDeploymentsComplete);
// 2. give fractions a chance to handle the deployment
for (DeploymentProcessor processor : this.deploymentProcessors) {
processor.process();
}
this.deploymentContext.deactivate();
if (DeployerMessages.MESSAGES.isDebugEnabled()) {
DeployerMessages.MESSAGES.deploying(deployment.getName());
Map<ArchivePath, Node> ctx = deployment.getContent();
for (Map.Entry<ArchivePath, Node> each : ctx.entrySet()) {
DeployerMessages.MESSAGES.deploymentContent(each.getKey().toString());
}
}
if (BootstrapProperties.flagIsSet(SwarmProperties.EXPORT_DEPLOYMENT)) {
String exportLocation = System.getProperty(SwarmProperties.EXPORT_DEPLOYMENT);
if (exportLocation != null) {
Path archivePath = null;
if (exportLocation.toLowerCase().equals("true")) {
archivePath = Paths.get(deployment.getName());
} else {
Path exportDir = Paths.get(exportLocation);
Files.createDirectories(exportDir);
archivePath = exportDir.resolve(deployment.getName());
}
final File out = archivePath.toFile();
DeployerMessages.MESSAGES.exportingDeployment(out.getAbsolutePath());
deployment.as(ZipExporter.class).exportTo(out, true);
}
}
byte[] hash = this.contentRepository.addContent(deployment);
final ModelNode deploymentAdd = new ModelNode();
deploymentAdd.get(OP).set(ADD);
deploymentAdd.get(OP_ADDR).set("deployment", deployment.getName());
deploymentAdd.get(RUNTIME_NAME).set(deployment.getName());
deploymentAdd.get(ENABLED).set(true);
deploymentAdd.get(PERSISTENT).set(true);
ModelNode content = deploymentAdd.get(CONTENT).add();
content.get(HASH).set(hash);
int deploymentTimeout = Integer.getInteger(SwarmProperties.DEPLOYMENT_TIMEOUT, 300);
final ModelNode opHeaders = new ModelNode();
opHeaders.get(BLOCKING_TIMEOUT).set(deploymentTimeout);
deploymentAdd.get(OPERATION_HEADERS).set(opHeaders);
BootstrapLogger.logger("org.wildfly.swarm.runtime.deployer").info("deploying " + deployment.getName());
System.setProperty(SwarmInternalProperties.CURRENT_DEPLOYMENT, deployment.getName());
try {
ModelNode result = client.execute(deploymentAdd);
ModelNode outcome = result.get("outcome");
if (outcome.asString().equals("success")) {
return;
}
ModelNode description = result.get("failure-description");
throw new DeploymentException(deployment, SwarmMessages.MESSAGES.deploymentFailed(description.asString()));
} catch (IOException e) {
throw SwarmMessages.MESSAGES.deploymentFailed(e, deployment);
}
} catch (Exception e) {
throw new DeploymentException(deployment, e);
}
}
use of org.wildfly.swarm.bootstrap.env.ApplicationEnvironment in project wildfly-swarm by wildfly-swarm.
the class ArtifactManager method allArtifacts.
@Override
public List<JavaArchive> allArtifacts(String... groupIdExclusions) throws IOException {
Map<String, JavaArchive> archives = new HashMap<>();
Set<String> archivesPaths;
final List<String> exclusions = Arrays.asList(groupIdExclusions);
ApplicationEnvironment env = ApplicationEnvironment.get();
archivesPaths = env.resolveDependencies(exclusions);
// package the shrinkwrap bits
for (final String element : archivesPaths) {
final File artifact = new File(element);
if (artifact.isFile()) {
archives.put(artifact.getName(), ShrinkWrap.create(ZipImporter.class, artifact.getName()).importFrom(artifact).as(JavaArchive.class));
} else {
final String archiveName = FileSystemLayout.archiveNameForClassesDir(artifact.toPath());
// pack resources and classes of the same project into one archive
if (archives.containsKey(archiveName)) {
archives.get(archiveName).as(ExplodedImporter.class).importDirectory(artifact);
} else {
archives.put(archiveName, ShrinkWrap.create(ExplodedImporter.class, archiveName).importDirectory(artifact).as(JavaArchive.class));
}
}
}
return new ArrayList<>(archives.values());
}
Aggregations