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

Fixes in the Arquillian Maven Plugin #39

Merged
merged 2 commits into from
Jan 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public static void main(String[] args) throws Exception {
boolean verbose = Boolean.parseBoolean(args[4]);
// ClassLoader to load the Scanner from the classpath (equivalent to application cp).
// Delegates to the application classpath to resolve Java API.
URLClassLoader cpLoader = buildClassLoader(cpArray, Thread.currentThread().getContextClassLoader(), verbose);
URLClassLoader cpLoader = buildClassLoader(cpArray, Thread.currentThread().getContextClassLoader());
// ClassLoader to load the test classes, delegate to cpLoader
URLClassLoader testLoader = buildClassLoader(urlsArray, cpLoader, verbose);
URLClassLoader testLoader = buildClassLoader(urlsArray, cpLoader);
Class<?> exporterClass = Class.forName("org.wildfly.glow.plugin.arquillian.GlowArquillianDeploymentExporter", true, cpLoader);
Constructor ctr = exporterClass.getConstructor(List.class, ClassLoader.class, Path.class, Boolean.TYPE);
Object obj = ctr.newInstance(classes, testLoader, outputFolder, verbose);
Expand All @@ -64,12 +64,9 @@ public static void main(String[] args) throws Exception {
System.exit(0);
}

private static URLClassLoader buildClassLoader(String[] cpUrls, ClassLoader parent, boolean verbose) throws Exception {
private static URLClassLoader buildClassLoader(String[] cpUrls, ClassLoader parent) throws Exception {
List<URL> urls = new ArrayList<>();
for (String s : cpUrls) {
if (verbose) {
System.out.println("URL " + s);
}
urls.add(new File(s).toURI().toURL());
}
URL[] cp = urls.toArray(new URL[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
Expand All @@ -73,6 +74,7 @@
import org.jboss.galleon.universe.FeaturePackLocation;
import org.jboss.galleon.universe.UniverseResolver;
import org.jboss.galleon.universe.maven.MavenChannel;
import org.wildfly.glow.ScanArguments;
import org.wildfly.glow.error.IdentifiedError;
import static org.wildfly.glow.plugin.arquillian.GlowArquillianDeploymentExporter.TEST_CLASSPATH;
import static org.wildfly.glow.plugin.arquillian.GlowArquillianDeploymentExporter.TEST_PATHS;
Expand Down Expand Up @@ -138,16 +140,11 @@ public void trace(Object s) {
/**
* List of feature-packs that are scanned and injected in the generated
* provisioning.xml.
* This option can't be used when {@code server-version} or {@code preview} or {@code context} are used.
*/
@Parameter(required = false, alias = "feature-packs")
List<GalleonFeaturePack> featurePacks = Collections.emptyList();

/**
* Enable verbose output (containing identified errors, suggestions, ...).
*/
@Parameter(alias = "enable-verbose-output", property = "org.wildfly.glow.enable-verbose-output")
boolean enableVerboseOutput = false;

/**
* GroupId:ArtifactId of dependencies that contain test classes to scan for
* Arquillian deployments.
Expand All @@ -156,10 +153,10 @@ public void trace(Object s) {
private List<String> dependenciesToScan = Collections.emptyList();

/**
* Execution profiles.
* Execution profile.
*/
@Parameter(alias = "profiles", required = false, property = "org.wildfly.glow.profiles")
Set<String> profiles = Collections.emptySet();
@Parameter(alias = "profile", required = false, property = "org.wildfly.glow.profile")
private String profile;

/**
* Do not lookup deployments to scan.
Expand Down Expand Up @@ -213,10 +210,13 @@ public void trace(Object s) {
@Parameter(alias = "expected-errors", property = "org.wildfly.glow.expected-errors")
private List<String> expectedErrors = Collections.emptyList();

/**
* Enable verbose output (containing identified errors, suggestions, ...).
*/
@Parameter(property = "org.wildfly.glow.verbose")
private boolean verbose = false;

/**
/**
* A list of channels used for resolving artifacts while provisioning.
* <p>
* Defining a channel:
Expand Down Expand Up @@ -253,8 +253,48 @@ public void trace(Object s) {
@Parameter(alias = "channels", property = "org.wildfly.glow.channels")
List<ChannelConfiguration> channels;

/**
* A WildFly server version. The latest version is the default, only usable if no {@code feature-packs} have been set.
*/
@Parameter(alias = "server-version", property = "org.wildfly.glow.server-version")
private String serverVersion;

/**
* Use WildFly Preview server, only usable if no {@code feature-packs} have been set.
*/
@Parameter(alias = "preview-server", property = "org.wildfly.glow.preview-server")
private boolean previewServer;

/**
* Execution context, can be {@code cloud} or {@code bare-metal}, default value is {@code bare-metal},
* only usable if no {@code feature-packs} have been set.
*/
@Parameter(alias = "context", property = "org.wildfly.glow.context")
private String context;

/**
* By default the execution is aborted when unknown errors are reported. You can disable the check done for errors by
* setting this option to true.
*/
@Parameter(alias = "check-errors", property = "org.wildfly.glow.check-errors")
private boolean checkErrors = true;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

// Check configuration
if (!featurePacks.isEmpty()) {
if (serverVersion != null) {
throw new MojoExecutionException("server-version can't be set when feature-packs have been set.");
}
if (context != null) {
throw new MojoExecutionException("context can't be set when feature-packs have been set.");
}
if (previewServer) {
throw new MojoExecutionException("preview-server can't be set when feature-packs have been set.");
}
}

// Make sure that the 'hidden' properties used by the Arguments class come from the Maven configuration
HiddenPropertiesAccessor.setOverrides(systemPropertyVariables);
try {
Expand Down Expand Up @@ -343,76 +383,110 @@ public void execute() throws MojoExecutionException, MojoFailureException {
throw new MojoExecutionException(ex.getLocalizedMessage(), ex);
}
}
Arguments arguments = Arguments.scanBuilder().
Set<String> profiles = new HashSet<>();
if (profile != null) {
profiles.add(profile);
}
ScanArguments.Builder argumentsBuilder = Arguments.scanBuilder().
setExecutionProfiles(profiles).
setBinaries(retrieveDeployments(paths, classesRootFolder, outputFolder)).
setProvisoningXML(buildInputConfig(outputFolder, artifactResolver)).
setUserEnabledAddOns(addOns).
setConfigName(configName).
setSuggest((enableVerboseOutput || getLog().isDebugEnabled())).
setSuggest((verbose || getLog().isDebugEnabled())).
setJndiLayers(layersForJndi).
setVerbose(verbose || getLog().isDebugEnabled()).
setOutput(OutputFormat.PROVISIONING_XML).build();
setOutput(OutputFormat.PROVISIONING_XML).
setTechPreview(previewServer).
setExecutionContext(context).setVersion(serverVersion);

if (!featurePacks.isEmpty()) {
argumentsBuilder.setProvisoningXML(buildInputConfig(outputFolder, artifactResolver));
}

Arguments arguments = argumentsBuilder.build();

try (ScanResults results = GlowSession.scan(artifactResolver,
arguments, writer)) {
boolean skipTests = Boolean.getBoolean("maven.test.skip") || Boolean.getBoolean("skipTests");
if (skipTests) {
getLog().warn("Tests are disabled, not checking for expected discovered layers.");
} else {
if (expectedDiscovery != null) {
String compact = results.getCompactInformation();
if (!expectedDiscovery.equals(compact)) {
throw new MojoExecutionException("Error in glow discovery.\n"
+ "-Expected: " + expectedDiscovery + "\n"
+ "-Found : " + compact);
}
}
if (results.getErrorSession().hasErrors()) {
if (expectedErrors.isEmpty()) {
results.outputInformation(writer);
throw new MojoExecutionException("An error has been reported and expected-errors has not been set.");
}
List<IdentifiedError> errors = new ArrayList<>();
for (IdentifiedError err : results.getErrorSession().getErrors()) {
if (!err.isFixed()) {
errors.add(err);
boolean skipTests = Boolean.getBoolean("maven.test.skip") || Boolean.getBoolean("skipTests");
if (skipTests) {
getLog().warn("Tests are disabled, not checking for expected discovered layers.");
} else {
if (expectedDiscovery != null) {
String compact = results.getCompactInformation();
if (!expectedDiscovery.equals(compact)) {
throw new MojoExecutionException("Error in glow discovery.\n"
+ "-Expected: " + expectedDiscovery + "\n"
+ "-Found : " + compact);
}
}
if (expectedErrors.size() != errors.size()) {
List<String> descriptions = new ArrayList<>();
for (IdentifiedError err : errors) {
descriptions.add(err.getDescription());
if (results.getErrorSession().hasErrors()) {
boolean errorsFound = false;
if (expectedErrors.isEmpty()) {
results.outputInformation(writer);
errorsFound = true;
String msg = "An error has been reported and expected-errors has not been set.";
if (checkErrors) {
throw new MojoExecutionException(msg);
} else {
getLog().warn(msg);
return;
}
}
throw new MojoExecutionException("Number of expected errors mismatch. Expected "
+ expectedErrors.size() + " reported " + errors.size() + ".\n"
+ "Reported Errors " + descriptions + "\n"
+ "Expected Errors " + expectedErrors);
}
Iterator<IdentifiedError> it = errors.iterator();
while (it.hasNext()) {
IdentifiedError err = it.next();
if (expectedErrors.contains(err.getDescription())) {
it.remove();
List<IdentifiedError> errors = new ArrayList<>();
for (IdentifiedError err : results.getErrorSession().getErrors()) {
if (!err.isFixed()) {
errors.add(err);
}
}
}
it = errors.iterator();
if (it.hasNext()) {
StringBuilder builder = new StringBuilder();
if (expectedErrors.size() != errors.size()) {
List<String> descriptions = new ArrayList<>();
for (IdentifiedError err : errors) {
descriptions.add(err.getDescription());
}
String msg = "Number of expected errors mismatch. Expected "
+ expectedErrors.size() + " reported " + errors.size() + ".\n"
+ "Reported Errors " + descriptions + "\n"
+ "Expected Errors " + expectedErrors;
errorsFound = true;
if (checkErrors) {
throw new MojoExecutionException(msg);
} else {
getLog().warn(msg);
}
}
Iterator<IdentifiedError> it = errors.iterator();
while (it.hasNext()) {
IdentifiedError err = it.next();
builder.append(err.getDescription()).append("\n");
if (expectedErrors.contains(err.getDescription())) {
it.remove();
}
}
it = errors.iterator();
if (it.hasNext()) {
StringBuilder builder = new StringBuilder();
while (it.hasNext()) {
IdentifiedError err = it.next();
builder.append(err.getDescription()).append("\n");
}
errorsFound = true;
String msg = "The following errors are unexpected:\n" + builder.toString();
if (checkErrors) {
throw new MojoExecutionException(msg);
} else {
getLog().warn(msg);
}
}
if(!errorsFound) {
getLog().info("Expected errors found in glow scanning results. "
+ " The test execution should fix them (eg: add missing datasources)");
}
} else {
if (!expectedErrors.isEmpty()) {
throw new MojoExecutionException("expected-errors contains errors but no error reported.");
}
throw new MojoExecutionException("The following errors are unexpected:\n" + builder.toString());
}
getLog().info("Expected errors found in glow scanning results. "
+ " The test execution should fix them (eg: add missing datasources)");
} else {
if (!expectedErrors.isEmpty()) {
throw new MojoExecutionException("expected-errors contains errors but no error reported.");
}
}
}
if (enableVerboseOutput || getLog().isDebugEnabled()) {
if (verbose || getLog().isDebugEnabled()) {
results.outputInformation(writer);
} else {
results.outputCompactInformation(writer);
Expand Down Expand Up @@ -478,7 +552,7 @@ private Process startScanner(Path outputFolder,
}
Path lst = outputFolder.resolve(TEST_PATHS);
Files.write(lst, pathList.toString().getBytes());
if (enableVerboseOutput) {
if (verbose) {
getLog().info("SCANNER: Test elements: " + pathList);
getLog().info("SCANNER: Classes: " + classesLst);
}
Expand All @@ -487,10 +561,10 @@ private Process startScanner(Path outputFolder,
collectCpPaths(System.getProperty("java.home"),
Thread.currentThread().getContextClassLoader(),
cp,
enableVerboseOutput,
verbose,
reducedCp,
getLog());
if (enableVerboseOutput) {
if (verbose) {
getLog().info("SCANNER: classpath: " + cp);
getLog().info("SCANNER: bootstrap classpath: " + reducedCp);
}
Expand All @@ -510,7 +584,7 @@ private Process startScanner(Path outputFolder,
cmd.add(lst.toAbsolutePath().toString());
cmd.add(classesLst.toString());
cmd.add(outputFolder.toAbsolutePath().toString());
cmd.add(enableVerboseOutput || getLog().isDebugEnabled() ? "true" : "false");
cmd.add(verbose || getLog().isDebugEnabled() ? "true" : "false");
final ProcessBuilder builder = new ProcessBuilder(cmd)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.redirectOutput(ProcessBuilder.Redirect.INHERIT);
Expand All @@ -528,9 +602,6 @@ private static void collectCpPaths(String javaHome, ClassLoader cl, StringBuilde
for (URL url : ((URLClassLoader) cl).getURLs()) {
final String filePath;
File file;
if (enableVerboseOutput) {
log.info("SCANNER: CP file url " + url);
}
try {
file = new File(url.toURI());
filePath = file.getAbsolutePath();
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/wildfly/glow/DeploymentScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private void scanAnnotations(DeploymentScanContext ctx) throws IOException {
if (l != null) {
ctx.layers.addAll(l);
//System.out.println("Find an annotation " + ai.name().packagePrefix() + " layer being " + l);
LayerMapping.addRule(LayerMapping.RULE.ANNOTATION, l, ai.name().packagePrefix());
LayerMapping.addRule(LayerMapping.RULE.ANNOTATION, l, ai.name().packagePrefix() + ".*");
} else {
// Pattern?
for (String s : ctx.mapping.getAnnotations().keySet()) {
Expand Down Expand Up @@ -578,7 +578,7 @@ private Set<Layer> lookup(String className, DeploymentScanContext ctx) {
String pkgPrefix = className.substring(0, index);
l = map.get(pkgPrefix);
if (l != null) {
LayerMapping.addRule(LayerMapping.RULE.JAVA_TYPE,l, pkgPrefix);
LayerMapping.addRule(LayerMapping.RULE.JAVA_TYPE,l, pkgPrefix + ".*");
}
}
if (l == null) {
Expand Down
Loading
Loading