use of org.jboss.shrinkwrap.api.Archive 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.jboss.shrinkwrap.api.Archive in project wildfly-swarm by wildfly-swarm.
the class ConfigurableManagerTest method testDeploymentConfigurableUsingBoth.
@Test
public void testDeploymentConfigurableUsingBoth() throws Exception {
Properties props = new Properties();
Map<String, String> env = new HashMap<>();
ConfigViewFactory factory = new ConfigViewFactory(props, env);
factory.withProperty("swarm.deployment.[myapp.war].context", "/my-specific-app");
factory.withProperty("swarm.http.context", "/my-alias-app");
ConfigView configView = factory.get(true);
DeploymentContext context = new DeploymentContextImpl();
ConfigurableManager manager = new ConfigurableManager(configView, context);
Archive archive = ShrinkWrap.create(JavaArchive.class, "myapp.war");
try {
context.activate(archive, archive.getName(), false);
Component component = new Component();
manager.scan(component);
assertThat(component.context.get()).isEqualTo("/my-specific-app");
} finally {
context.deactivate();
}
Archive archiveToo = ShrinkWrap.create(JavaArchive.class, "otherapp.war");
try {
context.activate(archiveToo, archiveToo.getName(), false);
Component component = new Component();
manager.scan(component);
assertThat(component.context.get()).isEqualTo("/my-alias-app");
} finally {
context.deactivate();
}
}
use of org.jboss.shrinkwrap.api.Archive in project wildfly-swarm by wildfly-swarm.
the class HttpSecurityPreparer method process.
@SuppressWarnings("unchecked")
@Override
public void process() {
if (deploymentConfigs == null || deploymentConfigs.isEmpty()) {
return;
}
// find a matching archive declaration
Optional<String> match = deploymentConfigs.keySet().stream().filter(c -> archive.getName().equals(c)).findFirst();
if (!match.isPresent()) {
// no matching archive
return;
}
Map<String, Object> matchingConfig = (Map<String, Object>) deploymentConfigs.get(match.get());
if (!matchingConfig.containsKey("web")) {
// missing web configuration
return;
}
Map<String, Object> deploymentConfig = (Map<String, Object>) matchingConfig.get("web");
WARArchive war = archive.as(WARArchive.class);
WebXmlAsset webXml = war.findWebXmlAsset();
JBossWebAsset jbossWeb = war.findJbossWebAsset();
// login-config
Map<String, Object> loginConfig = (Map<String, Object>) deploymentConfig.get("login-config");
if (loginConfig != null) {
String authMethod = (String) loginConfig.getOrDefault("auth-method", "NONE");
// Setup login-config
webXml.setLoginConfig(authMethod, "ignored");
// security domain
if (loginConfig.containsKey("security-domain")) {
jbossWeb.setSecurityDomain((String) loginConfig.get("security-domain"));
}
// form login
if (loginConfig.containsKey("form-login-config")) {
Map<String, Object> formLoginConfig = (Map<String, Object>) loginConfig.get("form-login-config");
webXml.setFormLoginConfig("Security Realm", (String) formLoginConfig.get("form-login-page"), (String) formLoginConfig.get("form-error-page"));
}
}
// security constraints
List<Map<String, Object>> securityConstraints = (List<Map<String, Object>>) deploymentConfig.getOrDefault("security-constraints", Collections.EMPTY_LIST);
for (Map<String, Object> sc : securityConstraints) {
SecurityConstraint securityConstraint = webXml.protect((String) sc.getOrDefault("url-pattern", "/*"));
((List<String>) sc.getOrDefault("methods", Collections.emptyList())).forEach(securityConstraint::withMethod);
((List<String>) sc.getOrDefault("roles", Collections.emptyList())).forEach(securityConstraint::withRole);
}
}
use of org.jboss.shrinkwrap.api.Archive in project wildfly-swarm by wildfly-swarm.
the class JolokiaWarDeploymentProducer method jolokiaWar.
@Produces
public Archive jolokiaWar() throws Exception {
if (this.context == null) {
this.context = this.fraction.context();
}
Archive deployment = this.lookup.artifact(DEPLOYMENT_GAV, DEPLOYMENT_NAME);
deployment.as(WARArchive.class).setContextRoot(this.context);
Consumer<Archive> preparer = new ConfigurationValueAccessPreparer(this.jolokiaAccessXML);
if (this.fraction.jolokiaWarPreparer() != null) {
preparer = preparer.andThen(this.fraction.jolokiaWarPreparer());
}
preparer.accept(deployment);
return deployment;
}
use of org.jboss.shrinkwrap.api.Archive in project wildfly-swarm by wildfly-swarm.
the class JolokiaWarDeploymentProducerTest method testPreferConfigValueFile_vs_FractionSetting.
public void testPreferConfigValueFile_vs_FractionSetting() throws Exception {
URL resource = getClass().getClassLoader().getResource("my-jolokia-access2.xml");
URL fractionResource = getClass().getClassLoader().getResource("my-jolokia-access3.xml");
String path = resource.getPath();
File file = new File(path);
JolokiaWarDeploymentProducer producer = new JolokiaWarDeploymentProducer();
producer.fraction = new JolokiaFraction().prepareJolokiaWar(JolokiaFraction.jolokiaAccessXml(fractionResource));
producer.lookup = new MockArtifactLookup();
producer.jolokiaAccessXML = file.getAbsolutePath();
Archive war = producer.jolokiaWar();
Node xml = war.get("WEB-INF/classes/jolokia-access.xml");
assertThat(xml).isNotNull();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(xml.getAsset().openStream()))) {
List<String> lines = reader.lines().collect(Collectors.toList());
assertThat(lines).isNotEmpty();
assertThat(lines.get(0)).contains("This is my-jolokia-access2.xml");
}
}
Aggregations