9
9
* Sonatype Inc. - initial API and implementation
10
10
* Christoph Läubrich - [Bug 572416] Tycho does not understand "additional.bundles" directive in build.properties
11
11
* [Bug 572416] Compile all source folders contained in .classpath
12
+ * [Issue #460] Delay classpath resolution to the compile phase
12
13
*******************************************************************************/
13
14
package org .eclipse .tycho .core .osgitools ;
14
15
23
24
import java .util .LinkedHashSet ;
24
25
import java .util .List ;
25
26
import java .util .Map ;
27
+ import java .util .Objects ;
26
28
import java .util .Properties ;
27
29
import java .util .Set ;
28
30
import java .util .regex .Matcher ;
89
91
@ Component (role = TychoProject .class , hint = PackagingType .TYPE_ECLIPSE_PLUGIN )
90
92
public class OsgiBundleProject extends AbstractTychoProject implements BundleProject {
91
93
92
- private static final String CTX_ARTIFACT_KEY = TychoConstants .CTX_BASENAME + "/osgiBundle/artifactKey" ;
94
+ private static final String CTX_OSGI_BUNDLE_BASENAME = TychoConstants .CTX_BASENAME + "/osgiBundle" ;
95
+ private static final String CTX_ARTIFACT_KEY = CTX_OSGI_BUNDLE_BASENAME + "/artifactKey" ;
96
+ private static final String CTX_MAVEN_SESSION = CTX_OSGI_BUNDLE_BASENAME + "/mavenSession" ;
97
+ private static final String CTX_MAVEN_PROJECT = CTX_OSGI_BUNDLE_BASENAME + "/mavenProject" ;
98
+ private static final String CTX_CLASSPATH = CTX_OSGI_BUNDLE_BASENAME + "/classPath" ;
93
99
94
100
@ Requirement
95
101
private BundleReader bundleReader ;
@@ -171,7 +177,20 @@ public ArtifactKey getArtifactKey(ReactorProject project) {
171
177
@ Override
172
178
public void setupProject (MavenSession session , MavenProject project ) {
173
179
ArtifactKey key = readArtifactKey (project .getBasedir ());
174
- DefaultReactorProject .adapt (project ).setContextValue (CTX_ARTIFACT_KEY , key );
180
+ ReactorProject reactorProject = DefaultReactorProject .adapt (project );
181
+ reactorProject .setContextValue (CTX_ARTIFACT_KEY , key );
182
+ reactorProject .setContextValue (CTX_MAVEN_SESSION , session );
183
+ reactorProject .setContextValue (CTX_MAVEN_PROJECT , project );
184
+ }
185
+
186
+ private MavenSession getMavenSession (ReactorProject reactorProject ) {
187
+ return Objects .requireNonNull ((MavenSession ) reactorProject .getContextValue (CTX_MAVEN_SESSION ),
188
+ "Project not setup correctly" );
189
+ }
190
+
191
+ private MavenProject getMavenProject (ReactorProject reactorProject ) {
192
+ return Objects .requireNonNull ((MavenProject ) reactorProject .getContextValue (CTX_MAVEN_PROJECT ),
193
+ "Project not setup correctly" );
175
194
}
176
195
177
196
public ArtifactKey readArtifactKey (File location ) {
@@ -188,8 +207,8 @@ private OsgiManifest getManifest(ReactorProject project) {
188
207
return bundleReader .loadManifest (project .getBasedir ());
189
208
}
190
209
191
- @ Override
192
- public void resolveClassPath ( MavenSession session , MavenProject project ) {
210
+ private BundleClassPath resolveClassPath ( MavenSession session , MavenProject project ) {
211
+ logger . info ( "Resolving class path of " + project . getName () + "..." );
193
212
ReactorProject reactorProject = DefaultReactorProject .adapt (project );
194
213
DependencyArtifacts artifacts = getDependencyArtifacts (reactorProject );
195
214
@@ -247,13 +266,10 @@ public void resolveClassPath(MavenSession session, MavenProject project) {
247
266
List <File > projectClasspath = getThisProjectClasspath (artifact , reactorProject );
248
267
classpath .add (new DefaultClasspathEntry (reactorProject , artifact .getKey (), projectClasspath , null ));
249
268
250
- reactorProject .setContextValue (TychoConstants .CTX_ECLIPSE_PLUGIN_CLASSPATH , classpath );
251
- reactorProject .setContextValue (TychoConstants .CTX_ECLIPSE_PLUGIN_STRICT_BOOTCLASSPATH_ACCESSRULES ,
252
- strictBootClasspathAccessRules );
253
- reactorProject .setContextValue (TychoConstants .CTX_ECLIPSE_PLUGIN_BOOTCLASSPATH_EXTRA_ACCESSRULES ,
254
- dependencyComputer .computeBootClasspathExtraAccessRules (state ));
269
+ List <AccessRule > bootClasspathExtraAccessRules = dependencyComputer .computeBootClasspathExtraAccessRules (state );
255
270
256
271
addPDESourceRoots (project );
272
+ return new BundleClassPath (classpath , strictBootClasspathAccessRules , bootClasspathExtraAccessRules );
257
273
}
258
274
259
275
private Collection <ClasspathEntry > computeExtraTestClasspath (ReactorProject reactorProject ) {
@@ -365,24 +381,22 @@ private void populateProperties(Properties mavenProjectProperties, EclipsePlugin
365
381
366
382
@ Override
367
383
public List <ClasspathEntry > getClasspath (ReactorProject project ) {
368
- @ SuppressWarnings ("unchecked" )
369
- List <ClasspathEntry > classpath = (List <ClasspathEntry >) project
370
- .getContextValue (TychoConstants .CTX_ECLIPSE_PLUGIN_CLASSPATH );
371
- if (classpath == null ) {
372
- throw new IllegalStateException ();
373
- }
374
- return classpath ;
384
+ return getBundleClassPath (project ).getClasspathEntries ();
375
385
}
376
386
377
387
@ Override
378
388
public List <ClasspathEntry .AccessRule > getBootClasspathExtraAccessRules (ReactorProject project ) {
379
- @ SuppressWarnings ("unchecked" )
380
- List <ClasspathEntry .AccessRule > rules = (List <AccessRule >) project
381
- .getContextValue (TychoConstants .CTX_ECLIPSE_PLUGIN_BOOTCLASSPATH_EXTRA_ACCESSRULES );
382
- if (rules == null ) {
383
- throw new IllegalStateException ();
389
+ return getBundleClassPath (project ).getExtraBootClasspathAccessRules ();
390
+ }
391
+
392
+ public synchronized BundleClassPath getBundleClassPath (ReactorProject project ) {
393
+ Object contextValue = project .getContextValue (CTX_CLASSPATH );
394
+ if (contextValue instanceof BundleClassPath ) {
395
+ return (BundleClassPath ) contextValue ;
384
396
}
385
- return rules ;
397
+ BundleClassPath cp = resolveClassPath (getMavenSession (project ), getMavenProject (project ));
398
+ project .setContextValue (CTX_CLASSPATH , cp );
399
+ return cp ;
386
400
}
387
401
388
402
/**
@@ -485,7 +499,8 @@ private void addExtraClasspathEntries(List<ClasspathEntry> classpath, ReactorPro
485
499
if (entry instanceof LibraryClasspathEntry ) {
486
500
LibraryClasspathEntry libraryClasspathEntry = (LibraryClasspathEntry ) entry ;
487
501
ArtifactKey projectKey = getArtifactKey (project );
488
- classpath .add (new DefaultClasspathEntry (project , projectKey , Collections .singletonList (libraryClasspathEntry .getLibraryPath ()), null ));
502
+ classpath .add (new DefaultClasspathEntry (project , projectKey ,
503
+ Collections .singletonList (libraryClasspathEntry .getLibraryPath ()), null ));
489
504
}
490
505
}
491
506
}
0 commit comments