Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Add support for WildFly Glow #374

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@
<groupId>org.wildfly.prospero</groupId>
<artifactId>prospero-metadata</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.glow</groupId>
<artifactId>wildfly-glow-core</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.plugin.common;

import org.apache.maven.plugin.logging.Log;
import org.wildfly.glow.GlowMessageWriter;

/**
*
* @author jdenise
*/
public class GlowMavenMessageWriter implements GlowMessageWriter {

private final Log log;

GlowMavenMessageWriter(Log log) {
this.log = log;
}

@Override
public void info(Object s) {
log.info(s.toString());
}

@Override
public void warn(Object s) {
log.warn(s.toString());
}

@Override
public void error(Object s) {
log.error(s.toString());
}

@Override
public void trace(Object s) {
log.debug(s.toString());
}
}
79 changes: 79 additions & 0 deletions plugin/src/main/java/org/wildfly/plugin/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,29 @@

package org.wildfly.plugin.common;

import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.jboss.galleon.ProvisioningManager;
import org.jboss.galleon.config.ProvisioningConfig;
import org.jboss.galleon.universe.maven.repo.MavenRepoManager;
import org.jboss.galleon.xml.ProvisioningXmlWriter;
import org.wildfly.glow.Arguments;
import org.wildfly.glow.GlowSession;
import org.wildfly.glow.ScanResults;
import org.wildfly.plugin.core.FeaturePack;
import org.wildfly.plugin.core.GalleonUtils;
import org.wildfly.plugin.provision.GlowConfig;

/**
* A simple utility class.
*
Expand Down Expand Up @@ -101,4 +118,66 @@ public static List<String> splitArguments(final CharSequence arguments) {
}
return args;
}

public static ScanResults scanDeployment(GlowConfig discoverProvisioningInfo,
List<String> layers,
List<String> excludedLayers,
List<FeaturePack> featurePacks,
boolean dryRun,
Log log,
Path deploymentContent,
MavenRepoManager artifactResolver,
Path outputFolder,
ProvisioningManager pm,
Map<String, String> galleonOptions,
String layersConfigurationFileName) throws Exception {
if (!layers.isEmpty()) {
throw new MojoExecutionException("layers must be empty when enabling glow");
}
if (!excludedLayers.isEmpty()) {
throw new MojoExecutionException("excluded layers must be empty when enabling glow");
}
if (!Files.exists(deploymentContent)) {
throw new MojoExecutionException("A deployment is expected when enabling glow layer discovery");
}
Path inProvisioningFile = null;
Path glowOutputFolder = outputFolder.resolve("glow-scan");
Files.createDirectories(glowOutputFolder);
if (!featurePacks.isEmpty()) {
ProvisioningConfig in = GalleonUtils.buildConfig(pm, featurePacks, layers, excludedLayers, galleonOptions,
layersConfigurationFileName);
inProvisioningFile = glowOutputFolder.resolve("glow-in-provisioning.xml");
try (FileWriter fileWriter = new FileWriter(inProvisioningFile.toFile())) {
ProvisioningXmlWriter.getInstance().write(in, fileWriter);
}
}
Arguments arguments = discoverProvisioningInfo.toArguments(deploymentContent, inProvisioningFile);
log.info("Glow is scanning... ");
ScanResults results;
GlowMavenMessageWriter writer = new GlowMavenMessageWriter(log);
try {
results = GlowSession.scan(artifactResolver, arguments, writer);
} catch (Exception ex) {
throw new MojoExecutionException(ex.getLocalizedMessage(), ex);
}

log.info("Glow scanning DONE.");
try {
results.outputInformation(writer);
} catch (Exception ex) {
throw new MojoExecutionException(ex.getLocalizedMessage(), ex);
}
if (!dryRun) {
results.outputConfig(glowOutputFolder, false);
}
if (results.getErrorSession().hasErrors()) {
if (discoverProvisioningInfo.isFailsOnError()) {
throw new MojoExecutionException("Error detected by WildFly Glow. Aborting.");
} else {
log.warn("Some erros have been identified, check logs.");
}
}

return results;
}
}
Loading