2323import org .apache .maven .plugin .AbstractMojo ;
2424import org .apache .maven .plugin .MojoExecutionException ;
2525import org .apache .maven .plugin .MojoFailureException ;
26+ import org .apache .maven .plugin .logging .Log ;
2627import org .apache .maven .plugins .annotations .Component ;
2728import org .apache .maven .plugins .annotations .LifecyclePhase ;
2829import 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