@@ -86,6 +86,8 @@ public class InstallableUnitGenerator {
8686
8787 private static final String KEY_UNITS = "InstallableUnitGenerator.units" ;
8888
89+ private static final String KEY_ARTIFACT_FILE = "InstallableUnitGenerator.artifactFile" ;
90+
8991 @ Requirement
9092 private IProvisioningAgent provisioningAgent ;
9193
@@ -165,28 +167,37 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
165167 Objects .requireNonNull (session );
166168 log .debug ("Computing installable units for " + project + ", force update = " + forceUpdate );
167169 synchronized (project ) {
168- if (!forceUpdate ) {
169- Object contextValue = project .getContextValue (KEY_UNITS );
170- if (contextValue instanceof Collection <?>) {
171- Collection <IInstallableUnit > collection = (Collection <IInstallableUnit >) contextValue ;
172- if (isCompatible (collection )) {
173- log .debug ("Using cached value for " + project );
174- return collection ;
175- } else {
176- log .debug ("Cannot use cached value for " + project
177- + " because of incompatible classloaders, update is forced" );
178- }
179- }
180- }
181170 File basedir = project .getBasedir ();
182171 if (basedir == null || !basedir .isDirectory ()) {
183172 log .warn ("No valid basedir for " + project + " found" );
184173 return Collections .emptyList ();
185174 }
175+ File projectArtifact = getProjectArtifact (project );
176+ if (!forceUpdate ) {
177+ // first check if the packed state might has changed...
178+ if (Objects .equals (project .getContextValue (KEY_ARTIFACT_FILE ), projectArtifact )) {
179+ Object contextValue = project .getContextValue (KEY_UNITS );
180+ if (contextValue instanceof Collection <?>) {
181+ // now check if we are classlaoder compatible...
182+ Collection <IInstallableUnit > collection = (Collection <IInstallableUnit >) contextValue ;
183+ if (isCompatible (collection )) {
184+ log .debug ("Using cached value for " + project );
185+ return collection ;
186+ } else {
187+ log .debug ("Cannot use cached value for " + project
188+ + " because of incompatible classloaders, update is forced" );
189+ }
190+ }
191+ } else {
192+ log .info ("Cannot use cached value for " + project
193+ + " because project artifact has changed, update is forced" );
194+ }
195+ }
186196 String packaging = project .getPackaging ();
187197 String version = project .getVersion ();
188198 String artifactId = project .getArtifactId ();
189- List <IPublisherAction > actions = getPublisherActions (packaging , basedir , version , artifactId );
199+ List <IPublisherAction > actions = getPublisherActions (packaging , basedir , projectArtifact , version ,
200+ artifactId );
190201 Collection <IInstallableUnit > publishedUnits = publisher .publishMetadata (actions );
191202 for (InstallableUnitProvider unitProvider : getProvider (project , session )) {
192203 log .debug ("Asking " + unitProvider + " for additional units for " + project );
@@ -207,24 +218,38 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
207218 log .debug ("Cannot generate any InstallableUnit for packaging type '" + packaging + "' for " + project );
208219 }
209220 project .setContextValue (KEY_UNITS , result );
221+ project .setContextValue (KEY_ARTIFACT_FILE , projectArtifact );
210222 return result ;
211223
212224 }
213225 }
214226
215- private List <IPublisherAction > getPublisherActions (String packaging , File basedir , String version ,
216- String artifactId ) throws CoreException {
227+ private static File getProjectArtifact (MavenProject project ) {
228+ Artifact artifact = project .getArtifact ();
229+ if (artifact != null ) {
230+ File file = artifact .getFile ();
231+ if (file != null && file .exists ()) {
232+ return file ;
233+ }
234+ }
235+ return null ;
236+ }
237+
238+ private List <IPublisherAction > getPublisherActions (String packaging , File basedir , File projectArtifact ,
239+ String version , String artifactId ) throws CoreException {
217240 List <IPublisherAction > actions = new ArrayList <>();
218241 switch (packaging ) {
219242 case PackagingType .TYPE_ECLIPSE_TEST_PLUGIN :
220243 case PackagingType .TYPE_ECLIPSE_PLUGIN : {
221- actions .add (new BundlesAction (new File [] { basedir }));
244+ File bundleFile = Objects .requireNonNullElse (projectArtifact , basedir );
245+ actions .add (new BundlesAction (new File [] { bundleFile }));
222246 break ;
223247 }
224248 case PackagingType .TYPE_ECLIPSE_FEATURE : {
225249 FeatureParser parser = new FeatureParser ();
226- Feature feature = parser .parse (basedir );
227- feature .setLocation (basedir .getAbsolutePath ());
250+ File featureFile = Objects .requireNonNullElse (projectArtifact , basedir );
251+ Feature feature = parser .parse (featureFile );
252+ feature .setLocation (featureFile .getAbsolutePath ());
228253 FeatureDependenciesAction action = new FeatureDependenciesAction (feature );
229254 actions .add (action );
230255 break ;
@@ -353,32 +378,31 @@ public synchronized Collection<IInstallableUnit> getUnits(Artifact artifact) {
353378 if (PackagingType .TYPE_ECLIPSE_PLUGIN .equals (type )
354379 || PackagingType .TYPE_ECLIPSE_TEST_PLUGIN .equals (type ) || "bundle" .equals (type )) {
355380 List <IPublisherAction > actions = getPublisherActions (PackagingType .TYPE_ECLIPSE_PLUGIN , file ,
356- artifact .getVersion (), artifact .getArtifactId ());
381+ file , artifact .getVersion (), artifact .getArtifactId ());
357382 return units = publisher .publishMetadata (actions );
358383 } else if (PackagingType .TYPE_ECLIPSE_FEATURE .equals (type )) {
359384 List <IPublisherAction > actions = getPublisherActions (PackagingType .TYPE_ECLIPSE_FEATURE , file ,
360- artifact .getVersion (), artifact .getArtifactId ());
385+ file , artifact .getVersion (), artifact .getArtifactId ());
361386 return units = publisher .publishMetadata (actions );
362387 } else {
363388 boolean isBundle = false ;
364389 boolean isFeature = false ;
365390 try (JarFile jarFile = new JarFile (file )) {
366391 Manifest manifest = jarFile .getManifest ();
367392 isBundle = manifest != null
368- && manifest .getMainAttributes ()
369- .getValue (Constants .BUNDLE_SYMBOLICNAME ) != null ;
393+ && manifest .getMainAttributes ().getValue (Constants .BUNDLE_SYMBOLICNAME ) != null ;
370394 isFeature = jarFile .getEntry ("feature.xml" ) != null ;
371395 } catch (IOException e ) {
372396 // can't determine the type then...
373397 }
374398 if (isBundle ) {
375399 List <IPublisherAction > actions = getPublisherActions (PackagingType .TYPE_ECLIPSE_PLUGIN ,
376- file , artifact .getVersion (), artifact .getArtifactId ());
400+ file , file , artifact .getVersion (), artifact .getArtifactId ());
377401 return units = publisher .publishMetadata (actions );
378402 }
379403 if (isFeature ) {
380404 List <IPublisherAction > actions = getPublisherActions (PackagingType .TYPE_ECLIPSE_FEATURE ,
381- file , artifact .getVersion (), artifact .getArtifactId ());
405+ file , file , artifact .getVersion (), artifact .getArtifactId ());
382406 return units = publisher .publishMetadata (actions );
383407 }
384408 }
0 commit comments