Skip to content

Commit b1957c6

Browse files
committed
Do not fail the DS build if one dependency failed to add
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)
1 parent 9b5ff9b commit b1957c6

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

tycho-ds-plugin/src/main/java/org/eclipse/tycho/ds/DeclarativeServicesMojo.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.maven.plugin.AbstractMojo;
2424
import org.apache.maven.plugin.MojoExecutionException;
2525
import org.apache.maven.plugin.MojoFailureException;
26+
import org.apache.maven.plugin.logging.Log;
2627
import org.apache.maven.plugins.annotations.Component;
2728
import org.apache.maven.plugins.annotations.LifecyclePhase;
2829
import org.apache.maven.plugins.annotations.Mojo;
@@ -145,7 +146,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
145146
return;
146147
}
147148
Version dsVersion = configuration.getSpecificationVersion();
148-
getLog().info("Using Declarative Service specification version " + dsVersion + " to generate component definitions");
149+
Log log = getLog();
150+
log.info("Using Declarative Service specification version " + dsVersion
151+
+ " to generate component definitions");
149152
boolean isDs12 = dsVersion.getMajor() == 1 && dsVersion.getMinor() == 2;
150153
String childPath = configuration.getPath();
151154
File targetDirectory = new File(outputDirectory, childPath);
@@ -162,14 +165,18 @@ public void execute() throws MojoExecutionException, MojoFailureException {
162165
for (ClasspathEntry entry : classpath) {
163166
List<File> locations = entry.getLocations();
164167
for (File file : locations) {
165-
if (file.exists() && !file.equals(outputDirectory)) {
166-
analyzer.addClasspath(file);
168+
if (file.exists() && !file.equals(outputDirectory) && file.length() > 0) {
169+
try {
170+
analyzer.addClasspath(file);
171+
} catch (IOException e) {
172+
log.warn("Can't add file " + file + " as classpath entry to ds analyzer",
173+
log.isDebugEnabled() ? e : null);
174+
}
167175
}
168176
}
169177
}
170178
pluginRealmHelper.visitPluginExtensions(project, session, ClasspathContributor.class, cpc -> {
171-
List<ClasspathEntry> list = cpc.getAdditionalClasspathEntries(project,
172-
Artifact.SCOPE_COMPILE);
179+
List<ClasspathEntry> list = cpc.getAdditionalClasspathEntries(project, Artifact.SCOPE_COMPILE);
173180
if (list != null && !list.isEmpty()) {
174181
for (ClasspathEntry entry : list) {
175182
for (File file : entry.getLocations()) {
@@ -183,7 +190,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
183190
});
184191
if (isDs12) {
185192
// see https://github.com/bndtools/bnd/issues/5548
186-
getLog().warn(
193+
log.warn(
187194
"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");
188195
} else {
189196
// https://bnd.bndtools.org/instructions/dsannotations-options.html
@@ -193,13 +200,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
193200
analyzer.addBasicPlugin(new DSAnnotations());
194201
analyzer.analyze();
195202
for (String warning : analyzer.getWarnings()) {
196-
getLog().warn(warning);
203+
log.warn(warning);
197204
}
198205
for (String error : analyzer.getErrors()) {
199-
getLog().error(error);
206+
log.error(error);
200207
}
201208
if (!analyzer.getErrors().isEmpty()) {
202-
throw new MojoFailureException("Generation of Declarative Service components failed, see log for details");
209+
throw new MojoFailureException(
210+
"Generation of Declarative Service components failed, see log for details");
203211
}
204212
String components = analyzer.getProperty(SERVICE_COMPONENT_HEADER);
205213
if (components == null || components.isBlank()) {
@@ -219,7 +227,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
219227
keep++;
220228
continue;
221229
}
222-
getLog().info("\t" + name);
230+
log.info("\t" + name);
223231
generated++;
224232
Resource resource = analyzer.getJar().getResource(component);
225233
if (resource != null) {
@@ -229,9 +237,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
229237
}
230238
}
231239
if (keep > 0) {
232-
getLog().info(generated + " component(s) where generated, " + keep + " where kept.");
240+
log.info(generated + " component(s) where generated, " + keep + " where kept.");
233241
} else {
234-
getLog().info(generated + " component(s) where generated.");
242+
log.info(generated + " component(s) where generated.");
235243
}
236244
}
237245
} catch (Exception e) {

0 commit comments

Comments
 (0)