Skip to content

Commit

Permalink
Do not fail the DS build if one dependency failed to add
Browse files Browse the repository at this point in the history
Currently it can happen that if a project has a "bad" dependency that
the whole build fails due to DS generation as the analyzer can't read
it.

This adds instead a warning and proceed because DS components can often
be generated anyways.

(cherry picked from commit 0d58b9d)
  • Loading branch information
laeubi authored and akurtakov committed Mar 14, 2024
1 parent 10a46e5 commit 0daa2e3
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -145,7 +146,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
return;
}
Version dsVersion = configuration.getSpecificationVersion();
getLog().info("Using Declarative Service specification version " + dsVersion + " to generate component definitions");
Log log = getLog();
log.info("Using Declarative Service specification version " + dsVersion
+ " to generate component definitions");
boolean isDs12 = dsVersion.getMajor() == 1 && dsVersion.getMinor() == 2;
String childPath = configuration.getPath();
File targetDirectory = new File(outputDirectory, childPath);
Expand All @@ -162,14 +165,18 @@ public void execute() throws MojoExecutionException, MojoFailureException {
for (ClasspathEntry entry : classpath) {
List<File> locations = entry.getLocations();
for (File file : locations) {
if (file.exists() && !file.equals(outputDirectory)) {
analyzer.addClasspath(file);
if (file.exists() && !file.equals(outputDirectory) && file.length() > 0) {
try {
analyzer.addClasspath(file);
} catch (IOException e) {
log.warn("Can't add file " + file + " as classpath entry to ds analyzer",
log.isDebugEnabled() ? e : null);
}
}
}
}
pluginRealmHelper.visitPluginExtensions(project, session, ClasspathContributor.class, cpc -> {
List<ClasspathEntry> list = cpc.getAdditionalClasspathEntries(project,
Artifact.SCOPE_COMPILE);
List<ClasspathEntry> list = cpc.getAdditionalClasspathEntries(project, Artifact.SCOPE_COMPILE);
if (list != null && !list.isEmpty()) {
for (ClasspathEntry entry : list) {
for (File file : entry.getLocations()) {
Expand All @@ -183,7 +190,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
});
if (isDs12) {
// see https://github.com/bndtools/bnd/issues/5548
getLog().warn(
log.warn(
"Generating of XML DS 1.2 might be not fully supported and validation is disabled (see https://github.com/bndtools/bnd/issues/5548), please upgrade to at least 1.3");
} else {
// https://bnd.bndtools.org/instructions/dsannotations-options.html
Expand All @@ -193,13 +200,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
analyzer.addBasicPlugin(new DSAnnotations());
analyzer.analyze();
for (String warning : analyzer.getWarnings()) {
getLog().warn(warning);
log.warn(warning);
}
for (String error : analyzer.getErrors()) {
getLog().error(error);
log.error(error);
}
if (!analyzer.getErrors().isEmpty()) {
throw new MojoFailureException("Generation of Declarative Service components failed, see log for details");
throw new MojoFailureException(
"Generation of Declarative Service components failed, see log for details");
}
String components = analyzer.getProperty(SERVICE_COMPONENT_HEADER);
if (components == null || components.isBlank()) {
Expand All @@ -219,7 +227,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
keep++;
continue;
}
getLog().info("\t" + name);
log.info("\t" + name);
generated++;
Resource resource = analyzer.getJar().getResource(component);
if (resource != null) {
Expand All @@ -229,9 +237,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}
if (keep > 0) {
getLog().info(generated + " component(s) where generated, " + keep + " where kept.");
log.info(generated + " component(s) where generated, " + keep + " where kept.");
} else {
getLog().info(generated + " component(s) where generated.");
log.info(generated + " component(s) where generated.");
}
}
} catch (Exception e) {
Expand Down

0 comments on commit 0daa2e3

Please sign in to comment.