diff --git a/org.eclipse.m2e.tests/projects/549312-fallbackToLatestEE/pom.xml b/org.eclipse.m2e.tests/projects/549312-fallbackToLatestEE/pom.xml
index ae2995635..5307c0b89 100644
--- a/org.eclipse.m2e.tests/projects/549312-fallbackToLatestEE/pom.xml
+++ b/org.eclipse.m2e.tests/projects/549312-fallbackToLatestEE/pom.xml
@@ -6,11 +6,18 @@
m2e-test-parent
1.0.0
- 549312-fallbackToLatestEE
- 0.0.1-SNAPSHOT
-
-
- 9999
- 9999
-
+ 549312-fallbackToLatestEE
+ 0.0.1-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 9999
+
+
+
+
\ No newline at end of file
diff --git a/org.eclipse.m2e.tests/projects/downloadsources/p009/.classpath b/org.eclipse.m2e.tests/projects/downloadsources/p009/.classpath
new file mode 100644
index 000000000..464509f49
--- /dev/null
+++ b/org.eclipse.m2e.tests/projects/downloadsources/p009/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/org.eclipse.m2e.tests/projects/downloadsources/p009/.project b/org.eclipse.m2e.tests/projects/downloadsources/p009/.project
new file mode 100644
index 000000000..f126dfb9a
--- /dev/null
+++ b/org.eclipse.m2e.tests/projects/downloadsources/p009/.project
@@ -0,0 +1,23 @@
+
+
+ downloadsources-p009
+
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/org.eclipse.m2e.tests/projects/downloadsources/p009/pom.xml b/org.eclipse.m2e.tests/projects/downloadsources/p009/pom.xml
new file mode 100644
index 000000000..388f2ec05
--- /dev/null
+++ b/org.eclipse.m2e.tests/projects/downloadsources/p009/pom.xml
@@ -0,0 +1,15 @@
+
+ 4.0.0
+ downloadsources
+ downloadsources-p009
+ jar
+ 0.0.1-SNAPSHOT
+
+
+ downloadsources
+ downloadsources-t009
+ 0.0.1-SNAPSHOT
+
+
+
diff --git a/org.eclipse.m2e.tests/repositories/testrepo-src/downloadsources/downloadsources-t009/pom.xml b/org.eclipse.m2e.tests/repositories/testrepo-src/downloadsources/downloadsources-t009/pom.xml
new file mode 100644
index 000000000..c3f656e19
--- /dev/null
+++ b/org.eclipse.m2e.tests/repositories/testrepo-src/downloadsources/downloadsources-t009/pom.xml
@@ -0,0 +1,46 @@
+
+ 4.0.0
+
+
+ downloadsources
+ downloadsources-parent
+ 0.0.1
+
+
+ downloadsources
+ downloadsources-t009
+ 0.0.1-SNAPSHOT
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ attach-sources
+ verify
+
+ jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
+
+ attach-javadocs
+ verify
+
+ jar
+
+
+
+
+
+
+
diff --git a/org.eclipse.m2e.tests/repositories/testrepo-src/downloadsources/downloadsources-t009/src/main/java/a/A.java b/org.eclipse.m2e.tests/repositories/testrepo-src/downloadsources/downloadsources-t009/src/main/java/a/A.java
new file mode 100644
index 000000000..75102d142
--- /dev/null
+++ b/org.eclipse.m2e.tests/repositories/testrepo-src/downloadsources/downloadsources-t009/src/main/java/a/A.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2021 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package a;
+
+public class A {}
\ No newline at end of file
diff --git a/org.eclipse.m2e.tests/repositories/testrepo-src/downloadsources/pom.xml b/org.eclipse.m2e.tests/repositories/testrepo-src/downloadsources/pom.xml
index 5c8824286..162a6d3ef 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo-src/downloadsources/pom.xml
+++ b/org.eclipse.m2e.tests/repositories/testrepo-src/downloadsources/pom.xml
@@ -24,5 +24,6 @@
downloadsources-t006
downloadsources-t007
downloadsources-t008
+ downloadsources-t009
diff --git a/org.eclipse.m2e.tests/repositories/testrepo-src/m2e-test-parent/pom.xml b/org.eclipse.m2e.tests/repositories/testrepo-src/m2e-test-parent/pom.xml
index a7047a8f1..a9673f22c 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo-src/m2e-test-parent/pom.xml
+++ b/org.eclipse.m2e.tests/repositories/testrepo-src/m2e-test-parent/pom.xml
@@ -29,6 +29,10 @@
org.apache.maven.plugins
maven-compiler-plugin
2.0.2
+
+
+ 1.6
+
org.apache.maven.plugins
@@ -50,6 +54,11 @@
maven-plugin-plugin
2.5
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ 2.7
+
diff --git a/org.eclipse.m2e.tests/repositories/testrepo-src/pom.xml b/org.eclipse.m2e.tests/repositories/testrepo-src/pom.xml
index 9350f90a6..b05d79b1f 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo-src/pom.xml
+++ b/org.eclipse.m2e.tests/repositories/testrepo-src/pom.xml
@@ -30,7 +30,20 @@
m2e-test-parent
- test-packaging-plugin
+ 422106_legacyPlexusUtils-plugin
+ 438454_guicescopes-plugin
+ 441257_stalePluginRealms/parentWithBuildExtensions
+ downloadsources
mngeclipse-2110
+ mngeclipse-2126
+ mngeclipse-2149
+ mngeclipse-369
+ readparent
+ registrymanager
+ test-buildcontext-plugin
+ test-buildhelper-plugin
+ test-embeddedmapping-plugin
+ testLifecycleMappingMetadata
+ test-packaging-plugin
diff --git a/org.eclipse.m2e.tests/repositories/testrepo-src/test-buildhelper-plugin/pom.xml b/org.eclipse.m2e.tests/repositories/testrepo-src/test-buildhelper-plugin/pom.xml
index 114dd5100..b35c6bd69 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo-src/test-buildhelper-plugin/pom.xml
+++ b/org.eclipse.m2e.tests/repositories/testrepo-src/test-buildhelper-plugin/pom.xml
@@ -46,19 +46,4 @@
${maven-version}
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 2.0.2
-
-
- 1.5
-
-
-
-
-
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-parent/0.0.1/downloadsources-parent-0.0.1.pom b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-parent/0.0.1/downloadsources-parent-0.0.1.pom
index bcf9dc9c0..162a6d3ef 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-parent/0.0.1/downloadsources-parent-0.0.1.pom
+++ b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-parent/0.0.1/downloadsources-parent-0.0.1.pom
@@ -23,5 +23,7 @@
downloadsources-t005
downloadsources-t006
downloadsources-t007
+ downloadsources-t008
+ downloadsources-t009
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-parent/maven-metadata.xml b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-parent/maven-metadata.xml
index c270692a5..03603280c 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-parent/maven-metadata.xml
+++ b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-parent/maven-metadata.xml
@@ -7,6 +7,6 @@
0.0.1
- 20110212034910
+ 20210904071631
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t008/maven-metadata-local.xml b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t008/maven-metadata.xml
similarity index 100%
rename from org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t008/maven-metadata-local.xml
rename to org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t008/maven-metadata.xml
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1-javadoc.jar b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1-javadoc.jar
new file mode 100644
index 000000000..a3cea1ca7
Binary files /dev/null and b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1-javadoc.jar differ
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1-sources.jar b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1-sources.jar
new file mode 100644
index 000000000..306beaafc
Binary files /dev/null and b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1-sources.jar differ
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1.jar b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1.jar
new file mode 100644
index 000000000..712dd2cd9
Binary files /dev/null and b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1.jar differ
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1.pom b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1.pom
new file mode 100644
index 000000000..c3f656e19
--- /dev/null
+++ b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/downloadsources-t009-0.0.1-20210904.071644-1.pom
@@ -0,0 +1,46 @@
+
+ 4.0.0
+
+
+ downloadsources
+ downloadsources-parent
+ 0.0.1
+
+
+ downloadsources
+ downloadsources-t009
+ 0.0.1-SNAPSHOT
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ attach-sources
+ verify
+
+ jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
+
+ attach-javadocs
+ verify
+
+ jar
+
+
+
+
+
+
+
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/maven-metadata.xml b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/maven-metadata.xml
new file mode 100644
index 000000000..13fce8abb
--- /dev/null
+++ b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/maven-metadata.xml
@@ -0,0 +1,37 @@
+
+
+ downloadsources
+ downloadsources-t009
+ 0.0.1-SNAPSHOT
+
+
+ 20210904.071644
+ 1
+
+ 20210904071644
+
+
+ jar
+ 0.0.1-20210904.071644-1
+ 20210904071644
+
+
+ pom
+ 0.0.1-20210904.071644-1
+ 20210904071644
+
+
+ sources
+ jar
+ 0.0.1-20210904.071644-1
+ 20210904071644
+
+
+ javadoc
+ jar
+ 0.0.1-20210904.071644-1
+ 20210904071644
+
+
+
+
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/maven-metadata.xml b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/maven-metadata.xml
new file mode 100644
index 000000000..5f9c09eca
--- /dev/null
+++ b/org.eclipse.m2e.tests/repositories/testrepo/downloadsources/downloadsources-t009/maven-metadata.xml
@@ -0,0 +1,11 @@
+
+
+ downloadsources
+ downloadsources-t009
+
+
+ 0.0.1-SNAPSHOT
+
+ 20210904071644
+
+
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/1.0.0/test-buildhelper-plugin-1.0.0.jar b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/1.0.0/test-buildhelper-plugin-1.0.0.jar
index 83a42e81b..83dd6f2f6 100644
Binary files a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/1.0.0/test-buildhelper-plugin-1.0.0.jar and b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/1.0.0/test-buildhelper-plugin-1.0.0.jar differ
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/1.0.0/test-buildhelper-plugin-1.0.0.pom b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/1.0.0/test-buildhelper-plugin-1.0.0.pom
index 114dd5100..b35c6bd69 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/1.0.0/test-buildhelper-plugin-1.0.0.pom
+++ b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/1.0.0/test-buildhelper-plugin-1.0.0.pom
@@ -46,19 +46,4 @@
${maven-version}
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 2.0.2
-
-
- 1.5
-
-
-
-
-
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/maven-metadata.xml b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/maven-metadata.xml
index aaa64c62b..b70cf3522 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/maven-metadata.xml
+++ b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/lifecyclemapping/test-buildhelper-plugin/maven-metadata.xml
@@ -8,6 +8,6 @@
1.0.0
- 20151123092639
+ 20210903202951
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/m2e-test-parent/1.0.0/m2e-test-parent-1.0.0.pom b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/m2e-test-parent/1.0.0/m2e-test-parent-1.0.0.pom
index a7047a8f1..a9673f22c 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/m2e-test-parent/1.0.0/m2e-test-parent-1.0.0.pom
+++ b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/m2e-test-parent/1.0.0/m2e-test-parent-1.0.0.pom
@@ -29,6 +29,10 @@
org.apache.maven.plugins
maven-compiler-plugin
2.0.2
+
+
+ 1.6
+
org.apache.maven.plugins
@@ -50,6 +54,11 @@
maven-plugin-plugin
2.5
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ 2.7
+
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/m2e-test-parent/maven-metadata.xml b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/m2e-test-parent/maven-metadata.xml
index b2fc18eaf..30c952642 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/m2e-test-parent/maven-metadata.xml
+++ b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/m2e-test-parent/maven-metadata.xml
@@ -7,6 +7,6 @@
1.0.0
- 20131120141813
+ 20210903202930
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/testrepo-src/1.0.0/testrepo-src-1.0.0.pom b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/testrepo-src/1.0.0/testrepo-src-1.0.0.pom
index 9350f90a6..b05d79b1f 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/testrepo-src/1.0.0/testrepo-src-1.0.0.pom
+++ b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/testrepo-src/1.0.0/testrepo-src-1.0.0.pom
@@ -30,7 +30,20 @@
m2e-test-parent
- test-packaging-plugin
+ 422106_legacyPlexusUtils-plugin
+ 438454_guicescopes-plugin
+ 441257_stalePluginRealms/parentWithBuildExtensions
+ downloadsources
mngeclipse-2110
+ mngeclipse-2126
+ mngeclipse-2149
+ mngeclipse-369
+ readparent
+ registrymanager
+ test-buildcontext-plugin
+ test-buildhelper-plugin
+ test-embeddedmapping-plugin
+ testLifecycleMappingMetadata
+ test-packaging-plugin
diff --git a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/testrepo-src/maven-metadata.xml b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/testrepo-src/maven-metadata.xml
index 32f6275c6..8d2e136af 100644
--- a/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/testrepo-src/maven-metadata.xml
+++ b/org.eclipse.m2e.tests/repositories/testrepo/org/eclipse/m2e/test/testrepo-src/maven-metadata.xml
@@ -7,6 +7,6 @@
1.0.0
- 20110212011936
+ 20210903202953
diff --git a/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/BuildPathManagerTest.java b/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/BuildPathManagerTest.java
index 6a52641ef..7912c4921 100644
--- a/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/BuildPathManagerTest.java
+++ b/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/BuildPathManagerTest.java
@@ -23,6 +23,7 @@
import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@@ -55,8 +56,6 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.JavaRuntime;
-import org.codehaus.plexus.util.DirectoryScanner;
-
import org.apache.maven.archetype.catalog.Archetype;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Build;
@@ -223,9 +222,7 @@ public void testProjectImportWithProfile1() throws Exception {
waitForJobsToComplete();
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathEntry[] classpathEntries = BuildPathManager.getMaven2ClasspathContainer(javaProject)
- .getClasspathEntries();
+ IClasspathEntry[] classpathEntries = getClasspathEntries(project);
assertEquals("" + Arrays.asList(classpathEntries), 3, classpathEntries.length);
assertEquals("junit-4.13.1.jar", classpathEntries[0].getPath().lastSegment());
assertEquals("jaxb-api-1.5.jar", classpathEntries[2].getPath().lastSegment());
@@ -245,9 +242,7 @@ public void testProjectImportWithProfile2() throws Exception {
waitForJobsToComplete();
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathEntry[] classpathEntries = BuildPathManager.getMaven2ClasspathContainer(javaProject)
- .getClasspathEntries();
+ IClasspathEntry[] classpathEntries = getClasspathEntries(project);
assertEquals("" + Arrays.asList(classpathEntries), 5, classpathEntries.length);
assertEquals("junit-4.13.1.jar", classpathEntries[0].getPath().lastSegment());
assertEquals("jaxb-api-2.0.jar", classpathEntries[2].getPath().lastSegment());
@@ -316,9 +311,7 @@ public void testClasspathOrderWorkspace001() throws Exception {
// MavenPlugin.getBuildpathManager().updateClasspathContainer(p1, new NullProgressMonitor());
- IJavaProject javaProject = JavaCore.create(project1);
- IClasspathContainer maven2ClasspathContainer = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry[] cp = maven2ClasspathContainer.getClasspathEntries();
+ IClasspathEntry[] cp = getClasspathEntries(project1);
// order according to mvn -X
assertEquals(4, cp.length);
@@ -344,9 +337,7 @@ public void testClasspathOrderWorkspace003() throws Exception {
p3.build(IncrementalProjectBuilder.FULL_BUILD, null);
waitForJobsToComplete();
- IJavaProject javaProject = JavaCore.create(p3);
- IClasspathContainer maven2ClasspathContainer = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry[] cp = maven2ClasspathContainer.getClasspathEntries();
+ IClasspathEntry[] cp = getClasspathEntries(p3);
// order according to mvn -X. note that maven 2.0.7 and 2.1-SNAPSHOT produce different order
assertEquals(7, cp.length);
@@ -367,19 +358,15 @@ public void testDownloadSources_001_basic() throws Exception {
waitForJobsToComplete();
IJavaProject javaProject = JavaCore.create(project);
- IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
// sanity check
- IClasspathEntry[] cp = container.getClasspathEntries();
- assertEquals(2, cp.length);
- assertNull(cp[0].getSourceAttachmentPath());
- assertNull(cp[1].getSourceAttachmentPath());
+ IClasspathEntry[] cp = getClasspathEntries(project);
+ assertNullSourceAttachmentPaths(2, cp);
// test project
getBuildPathManager().scheduleDownload(project, true, false);
waitForJobsToComplete();
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
+ cp = getClasspathEntries(project);
assertEquals(2, cp.length);
assertEquals("downloadsources-t001-0.0.1-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
assertEquals("downloadsources-t002-0.0.1-sources.jar", cp[1].getSourceAttachmentPath().lastSegment());
@@ -395,8 +382,7 @@ public void testDownloadSources_001_basic() throws Exception {
// test one entry
getBuildPathManager().scheduleDownload(getPackageFragmentRoot(javaProject, cp[0]), true, false);
waitForJobsToComplete();
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
+ cp = getClasspathEntries(project);
assertEquals(2, cp.length);
assertEquals("downloadsources-t001-0.0.1-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
assertNull(cp[1].getSourceAttachmentPath());
@@ -414,13 +400,17 @@ public void testDownloadSources_001_basic() throws Exception {
getBuildPathManager().scheduleDownload(getPackageFragmentRoot(javaProject, cp[0]), true, false);
getBuildPathManager().scheduleDownload(getPackageFragmentRoot(javaProject, cp[1]), true, false);
waitForJobsToComplete();
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
+ cp = getClasspathEntries(project);
assertEquals(2, cp.length);
assertEquals("downloadsources-t001-0.0.1-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
assertEquals("downloadsources-t002-0.0.1-sources.jar", cp[1].getSourceAttachmentPath().lastSegment());
}
+ private IPackageFragmentRoot getPackageFragmentRoot(IJavaProject javaProject, IClasspathEntry cp)
+ throws JavaModelException {
+ return javaProject.findPackageFragmentRoot(cp.getPath());
+ }
+
@Test
public void testDownloadSources_001_workspaceRestart() throws Exception {
deleteSourcesAndJavadoc(new File(repo, "downloadsources/downloadsources-t001/0.0.1/"));
@@ -429,14 +419,9 @@ public void testDownloadSources_001_workspaceRestart() throws Exception {
IProject project = createExisting("downloadsources-p001", "projects/downloadsources/p001");
waitForJobsToComplete();
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
-
// sanity check
- IClasspathEntry[] cp = container.getClasspathEntries();
- assertEquals(2, cp.length);
- assertNull(cp[0].getSourceAttachmentPath());
- assertNull(cp[1].getSourceAttachmentPath());
+ IClasspathEntry[] cp = getClasspathEntries(project);
+ assertNullSourceAttachmentPaths(2, cp);
// purge MavenProject cache to simulate workspace restart
deserializeFromWorkspaceState(MavenPlugin.getMavenProjectRegistry().getProject(project));
@@ -444,32 +429,12 @@ public void testDownloadSources_001_workspaceRestart() throws Exception {
// test project
getBuildPathManager().scheduleDownload(project, true, false);
waitForJobsToComplete();
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
+ cp = getClasspathEntries(project);
assertEquals(2, cp.length);
assertEquals("downloadsources-t001-0.0.1-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
assertEquals("downloadsources-t002-0.0.1-sources.jar", cp[1].getSourceAttachmentPath().lastSegment());
}
- private IPackageFragmentRoot getPackageFragmentRoot(IJavaProject javaProject, IClasspathEntry cp)
- throws JavaModelException {
- return javaProject.findPackageFragmentRoot(cp.getPath());
- }
-
- private void deleteSourcesAndJavadoc(File basedir) {
- if(!basedir.exists()) {
- return;
- }
- DirectoryScanner ds = new DirectoryScanner();
- ds.setBasedir(basedir);
- ds.setIncludes(new String[] {"*-sources.jar", "*-javadoc.jar", "m2e-lastUpdated.properties"});
- ds.scan();
-
- for(String path : ds.getIncludedFiles()) {
- new File(basedir, path).delete();
- }
- }
-
@Test
public void testDownloadSources_001_sourceAttachment() throws Exception {
new File(repo, "downloadsources/downloadsources-t001/0.0.1/downloadsources-t001-0.0.1-sources.jar").delete();
@@ -478,10 +443,7 @@ public void testDownloadSources_001_sourceAttachment() throws Exception {
IProject project = createExisting("downloadsources-p001", "projects/downloadsources/p001");
waitForJobsToComplete();
- IJavaProject javaProject = JavaCore.create(project);
- final IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
-
- IPath entryPath = container.getClasspathEntries()[0].getPath();
+ IPath entryPath = getClasspathEntries(project)[0].getPath();
IPath srcPath = new Path("/a");
IPath srcRoot = new Path("/b");
@@ -495,35 +457,10 @@ public void testDownloadSources_001_sourceAttachment() throws Exception {
new IClasspathAttribute[] {attribute}, //
false /*not exported*/);
- BuildPathManager buildpathManager = getBuildPathManager();
-
- IClasspathContainer containerSuggestion = new IClasspathContainer() {
- @Override
- public IClasspathEntry[] getClasspathEntries() {
- return new IClasspathEntry[] {entry};
- }
-
- @Override
- public String getDescription() {
- return container.getDescription();
- }
-
- @Override
- public int getKind() {
- return container.getKind();
- }
-
- @Override
- public IPath getPath() {
- return container.getPath();
- }
- };
- buildpathManager.persistAttachedSourcesAndJavadoc(javaProject, containerSuggestion, monitor);
- waitForJobsToComplete();
+ BuildPathManager buildpathManager = persistAttachedSourcesAndJavadoc(project, entry);
// check custom source/javadoc
- IClasspathContainer container2 = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry entry2 = container2.getClasspathEntries()[0];
+ IClasspathEntry entry2 = getClasspathEntries(project)[0];
assertEquals(entryPath, entry2.getPath());
assertEquals(srcPath, entry2.getSourceAttachmentPath());
assertEquals(srcRoot, entry2.getSourceAttachmentRootPath());
@@ -538,6 +475,35 @@ public IPath getPath() {
assertEquals(false, file.canRead());
}
+ @Test
+ public void testDownloadSources_001_redownloadRelease() throws Exception {
+ deleteSourcesAndJavadoc(new File(repo, "downloadsources/downloadsources-t001/0.0.1/"));
+ deleteSourcesAndJavadoc(new File(repo, "downloadsources/downloadsources-t002/0.0.1/"));
+
+ IProject project = createExisting("downloadsources-p001", "projects/downloadsources/p001");
+ waitForJobsToComplete();
+
+ // sanity check
+ IClasspathEntry[] cp = getClasspathEntries(project);
+ assertNullSourceAttachmentPaths(2, cp);
+
+ // download sources the first time
+ getBuildPathManager().scheduleDownload(project, true, false);
+ waitForJobsToComplete();
+ cp = getClasspathEntries(project);
+ assertEquals(2, cp.length);
+ assertEquals("downloadsources-t001-0.0.1-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
+ assertEquals("downloadsources-t002-0.0.1-sources.jar", cp[1].getSourceAttachmentPath().lastSegment());
+
+ // download sources a second time time
+ getBuildPathManager().scheduleDownload(project, true, false);
+ waitForJobsToComplete();
+ cp = getClasspathEntries(project);
+ assertEquals(2, cp.length);
+ assertEquals("downloadsources-t001-0.0.1-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
+ assertEquals("downloadsources-t002-0.0.1-sources.jar", cp[1].getSourceAttachmentPath().lastSegment());
+ }
+
@Test
public void testDownloadSources_002_javadoconly() throws Exception {
deleteSourcesAndJavadoc(new File(repo, "downloadsources/downloadsources-t003/0.0.1"));
@@ -546,19 +512,14 @@ public void testDownloadSources_002_javadoconly() throws Exception {
waitForJobsToComplete();
// sanity check
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry[] cp = container.getClasspathEntries();
- assertEquals(1, cp.length);
- assertNull(cp[0].getSourceAttachmentPath());
+ IClasspathEntry[] cp = getClasspathEntries(project);
+ assertNullSourceAttachmentPaths(1, cp);
getBuildPathManager().scheduleDownload(project, false, true);
waitForJobsToComplete();
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
- assertEquals(1, cp.length);
- assertNull(cp[0].getSourceAttachmentPath()); // sanity check
+ cp = getClasspathEntries(project);
+ assertNullSourceAttachmentPaths(1, cp);
assertEquals("" + cp[0], 1, getAttributeCount(cp[0], IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME));
}
@@ -570,31 +531,20 @@ public void testDownloadSources_003_customRemoteRepository() throws Exception {
waitForJobsToComplete();
// sanity check
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry[] cp = container.getClasspathEntries();
- assertEquals(1, cp.length);
- assertNull(cp[0].getSourceAttachmentPath());
+ IClasspathEntry[] cp = getClasspathEntries(project);
+ assertNullSourceAttachmentPaths(1, cp);
getBuildPathManager().scheduleDownload(project, true, false);
waitForJobsToComplete();
- javaProject = JavaCore.create(project);
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
+ cp = getClasspathEntries(project);
assertEquals(1, cp.length);
assertEquals("downloadsources-t004-0.0.1-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
}
- private static int getAttributeCount(IClasspathEntry entry, String name) {
+ private static long getAttributeCount(IClasspathEntry entry, String name) {
IClasspathAttribute[] attrs = entry.getExtraAttributes();
- int count = 0;
- for(int i = 0; i < attrs.length; i++ ) {
- if(name.equals(attrs[i].getName())) {
- count++ ;
- }
- }
- return count;
+ return Arrays.stream(attrs).map(IClasspathAttribute::getName).filter(name::equals).count();
}
@Test
@@ -604,17 +554,14 @@ public void testDownloadSources_004_testsClassifier() throws Exception {
IProject project = createExisting("downloadsources-p004", "projects/downloadsources/p004");
waitForJobsToComplete();
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry[] cp = container.getClasspathEntries();
+ IClasspathEntry[] cp = getClasspathEntries(project);
// sanity check
assertEquals("downloadsources-t005-0.0.1-tests.jar", cp[1].getPath().lastSegment());
getBuildPathManager().scheduleDownload(project, true, false);
waitForJobsToComplete();
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
+ cp = getClasspathEntries(project);
assertEquals(2, cp.length);
assertEquals("downloadsources-t005-0.0.1-test-sources.jar", cp[1].getSourceAttachmentPath().lastSegment());
@@ -627,17 +574,14 @@ public void testDownloadSources_005_classifier() throws Exception {
IProject project = createExisting("downloadsources-p005", "projects/downloadsources/p005");
waitForJobsToComplete();
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry[] cp = container.getClasspathEntries();
+ IClasspathEntry[] cp = getClasspathEntries(project);
// sanity check
assertEquals("downloadsources-t006-0.0.1-jdk14.jar", cp[0].getPath().lastSegment());
getBuildPathManager().scheduleDownload(project, true, false);
waitForJobsToComplete();
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
+ cp = getClasspathEntries(project);
assertEquals(1, cp.length);
assertNotNull(cp[0].getSourceAttachmentPath());
@@ -706,14 +650,11 @@ public void testDownloadSources_007_missingTestsSources() throws Exception {
IProject project = createExisting("downloadsources-p007", "projects/downloadsources/p007");
waitForJobsToComplete();
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry[] cp = container.getClasspathEntries();
+ IClasspathEntry[] cp = getClasspathEntries(project);
// sanity check
- assertEquals(1, cp.length);
+ assertNullSourceAttachmentPaths(1, cp);
assertEquals("downloadsources-t007-0.0.1-tests.jar", cp[0].getPath().lastSegment());
- assertNull(cp[0].getSourceAttachmentPath());
boolean oldDownloadSources = mavenConfiguration.isDownloadSources();
try {
@@ -721,12 +662,10 @@ public void testDownloadSources_007_missingTestsSources() throws Exception {
MavenUpdateRequest request = new MavenUpdateRequest(project, false/*offline*/, false/*updateSnapshots*/);
MavenPlugin.getMavenProjectRegistry().refresh(request);
waitForJobsToComplete();
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
+ cp = getClasspathEntries(project);
- assertEquals(1, cp.length);
+ assertNullSourceAttachmentPaths(1, cp);
assertEquals("downloadsources-t007-0.0.1-tests.jar", cp[0].getPath().lastSegment());
- assertNull(cp[0].getSourceAttachmentPath());
} finally {
((MavenConfigurationImpl) mavenConfiguration).setDownloadSources(oldDownloadSources);
}
@@ -745,22 +684,17 @@ public void testDownloadSources_008_fallbackToJavadocWhenMissingSources() throws
waitForJobsToComplete();
// sanity check
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry[] cp = container.getClasspathEntries();
- assertEquals(1, cp.length);
- assertNull(cp[0].getSourceAttachmentPath());
+ IClasspathEntry[] cp = getClasspathEntries(project);
+ assertNullSourceAttachmentPaths(1, cp);
assertEquals("" + cp[0], 0, getAttributeCount(cp[0], IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME));
MavenUpdateRequest request = new MavenUpdateRequest(project, false/*offline*/, false/*updateSnapshots*/);
//when sources are missing, we expect the javadoc to be downloaded if available.
MavenPlugin.getMavenProjectRegistry().refresh(request);
waitForJobsToComplete();
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
+ cp = getClasspathEntries(project);
- assertEquals(1, cp.length);
- assertNull(cp[0].getSourceAttachmentPath()); // sanity check
+ assertNullSourceAttachmentPaths(1, cp);
assertEquals("" + cp[0], 1, getAttributeCount(cp[0], IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME));
} finally {
((MavenConfigurationImpl) mavenConfiguration).setDownloadSources(oldDownloadSources);
@@ -768,6 +702,89 @@ public void testDownloadSources_008_fallbackToJavadocWhenMissingSources() throws
}
}
+ @Test
+ public void testDownloadSources_009_downloadSnapshot() throws Exception {
+ deleteSourcesAndJavadoc(new File(repo, "downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/"));
+
+ IProject project = createExisting("downloadsources-t009", "projects/downloadsources/p009");
+ waitForJobsToComplete();
+
+ // sanity check
+ IClasspathEntry[] cp = getClasspathEntries(project);
+ assertNullSourceAttachmentPaths(1, cp);
+
+ // download sources the first time
+ getBuildPathManager().scheduleDownload(project, true, false);
+ waitForJobsToComplete();
+ cp = getClasspathEntries(project);
+ assertEquals(1, cp.length);
+ assertEquals("downloadsources-t009-0.0.1-SNAPSHOT-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
+ }
+
+ @Test
+ public void testDownloadSources_009_redownloadSnapshot() throws Exception {
+ deleteSourcesAndJavadoc(new File(repo, "downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/"));
+
+ IProject project = createExisting("downloadsources-t009", "projects/downloadsources/p009");
+ waitForJobsToComplete();
+
+ // sanity check
+ IClasspathEntry[] cp = getClasspathEntries(project);
+ assertNullSourceAttachmentPaths(1, cp);
+
+ // download sources the first time
+ getBuildPathManager().scheduleDownload(project, true, false);
+ waitForJobsToComplete();
+ cp = getClasspathEntries(project);
+ assertEquals(1, cp.length);
+ assertEquals("downloadsources-t009-0.0.1-SNAPSHOT-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
+
+ // download sources a second time time
+ getBuildPathManager().scheduleDownload(project, true, false);
+ waitForJobsToComplete();
+ cp = getClasspathEntries(project);
+ assertEquals(1, cp.length);
+ assertEquals("downloadsources-t009-0.0.1-SNAPSHOT-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
+ }
+
+ @Test
+ public void testDownloadSources_009_redownloadSnapshotWithOlderSources() throws Exception {
+ File localSnapshotRepoMirror = new File(repo, "downloadsources/downloadsources-t009/0.0.1-SNAPSHOT/");
+ deleteSourcesAndJavadoc(localSnapshotRepoMirror);
+
+ IProject project = createExisting("downloadsources-t009", "projects/downloadsources/p009");
+ waitForJobsToComplete();
+
+ // sanity check
+ IClasspathEntry[] cp = getClasspathEntries(project);
+ assertNullSourceAttachmentPaths(1, cp);
+
+ // download sources the first time
+ getBuildPathManager().scheduleDownload(project, true, false);
+ waitForJobsToComplete();
+ cp = getClasspathEntries(project);
+ assertEquals(1, cp.length);
+ assertEquals("downloadsources-t009-0.0.1-SNAPSHOT-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
+
+ // Pretend artifact was last-modified after its sources
+ // The sources artifact is (sometimes and sometimes not) touched during source download, so the main-artifact is touched.
+ File mainArtifact = new File(localSnapshotRepoMirror, "downloadsources-t009-0.0.1-SNAPSHOT.jar");
+ File mainArtifactSources = new File(localSnapshotRepoMirror, "downloadsources-t009-0.0.1-SNAPSHOT-sources.jar");
+ mainArtifact.setLastModified(mainArtifactSources.lastModified() + 10_000);
+
+ // download sources a second time time
+ getBuildPathManager().scheduleDownload(project, true, false);
+ waitForJobsToComplete();
+ cp = getClasspathEntries(project);
+ assertEquals(1, cp.length);
+ assertEquals("downloadsources-t009-0.0.1-SNAPSHOT-sources.jar", cp[0].getSourceAttachmentPath().lastSegment());
+
+ // Afterwards sanity check: For this test-case setup it is mandatory that the main-artifact is last-modified after its sources.
+ // Because the setup of this situation is a bit fragile, this afterwards check makes sure the test setup was not pointless.
+ assertTrue("Main artifact not last-modified after sources",
+ mainArtifactSources.lastModified() < mainArtifact.lastModified());
+ }
+
private BuildPathManager getBuildPathManager() {
return (BuildPathManager) MavenJdtPlugin.getDefault().getBuildpathManager();
}
@@ -777,9 +794,7 @@ public void testClassifiers() throws Exception {
IProject p1 = createExisting("classifiers-p1", "projects/classifiers/classifiers-p1");
waitForJobsToComplete();
- IJavaProject javaProject = JavaCore.create(p1);
- IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry[] cp = container.getClasspathEntries();
+ IClasspathEntry[] cp = getClasspathEntries(p1);
assertEquals(2, cp.length);
assertEquals("classifiers-p2-0.0.1.jar", cp[0].getPath().lastSegment());
@@ -788,8 +803,7 @@ public void testClassifiers() throws Exception {
IProject p2 = createExisting("classifiers-p2", "projects/classifiers/classifiers-p2");
waitForJobsToComplete();
- container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- cp = container.getClasspathEntries();
+ cp = getClasspathEntries(p1);
assertEquals(1, cp.length);
assertEquals("classifiers-p2", cp[0].getPath().lastSegment());
@@ -1389,9 +1403,7 @@ public void test388596_expandedSnapshotDependency() throws Exception {
new String[] {"a/pom.xml", "b/pom.xml"}, new ResolverConfiguration());
waitForJobsToComplete();
- IJavaProject javaProject = JavaCore.create(projects[1]);
- IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry[] cp = container.getClasspathEntries();
+ IClasspathEntry[] cp = getClasspathEntries(projects[1]);
assertEquals(1, cp.length);
ClasspathHelpers.assertClasspathEntry(cp, projects[0].getFullPath());
@@ -1401,17 +1413,13 @@ public void test388596_expandedSnapshotDependency() throws Exception {
public void test385391_keepCustomSourceEncoding() throws Exception {
IProject project = createSimpleProject("simple-project", null);
- IJavaProject javaProject = JavaCore.create(project);
-
IClasspathEntry[] entries = getMavenContainerEntries(project);
assertEquals(Arrays.toString(entries), 2, entries.length);
assertEquals(IClasspathEntry.CPE_LIBRARY, entries[0].getEntryKind());
assertEquals("junit-4.13.1.jar", entries[0].getPath().lastSegment());
assertNull(MavenClasspathHelpers.getAttribute(entries[0], IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING));
- final IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
-
- IPath entryPath = container.getClasspathEntries()[0].getPath();
+ IPath entryPath = getClasspathEntries(project)[0].getPath();
String encoding = "ISO-8859-1";
@@ -1423,8 +1431,55 @@ public void test385391_keepCustomSourceEncoding() throws Exception {
new IClasspathAttribute[] {attribute}, //
false /*not exported*/);
- BuildPathManager buildpathManager = getBuildPathManager();
+ persistAttachedSourcesAndJavadoc(project, entry);
+
+ // check custom source encoding
+ IClasspathEntry entry2 = getClasspathEntries(project)[0];
+ assertEquals(entryPath, entry2.getPath());
+ assertEquals(entry.getSourceAttachmentPath(), entry2.getSourceAttachmentPath());
+ assertEquals(entry.getSourceAttachmentRootPath(), entry2.getSourceAttachmentRootPath());
+ assertEquals(encoding, MavenClasspathHelpers.getAttribute(entry2, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING));
+ }
+
+ // --- utility methods ---
+
+ private Set getMavenProjectArtifacts(IProject p) throws CoreException {
+ MavenProject mavenProject = manager.create(p, monitor).getMavenProject(monitor);
+ return mavenProject.getArtifacts();
+ }
+
+ private void deleteSourcesAndJavadoc(File basedir) throws IOException {
+ if(!basedir.exists()) {
+ return;
+ }
+ try (var files = Files.newDirectoryStream(basedir.toPath());) {
+ for(java.nio.file.Path file : files) {
+ if(file.toString().endsWith("-sources.jar") || file.toString().endsWith("-javadoc.jar")
+ || file.endsWith("m2e-lastUpdated.properties")) {
+ Files.delete(file);
+ }
+ }
+ }
+ }
+
+ private static IClasspathEntry[] getClasspathEntries(IProject project) throws JavaModelException {
+ IJavaProject javaProject2 = JavaCore.create(project);
+ IClasspathContainer container2 = BuildPathManager.getMaven2ClasspathContainer(javaProject2);
+ return container2.getClasspathEntries();
+ }
+ private void assertNullSourceAttachmentPaths(int expectedLength, IClasspathEntry[] entries) {
+ assertEquals(expectedLength, entries.length);
+ for(IClasspathEntry entry : entries) {
+ assertNull(entry.getSourceAttachmentPath());
+ }
+ }
+
+ private BuildPathManager persistAttachedSourcesAndJavadoc(IProject project, final IClasspathEntry entry)
+ throws CoreException, InterruptedException {
+ IJavaProject javaProject = JavaCore.create(project);
+ BuildPathManager buildpathManager = getBuildPathManager();
+ final IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject);
IClasspathContainer containerSuggestion = new IClasspathContainer() {
@Override
public IClasspathEntry[] getClasspathEntries() {
@@ -1448,18 +1503,6 @@ public IPath getPath() {
};
buildpathManager.persistAttachedSourcesAndJavadoc(javaProject, containerSuggestion, monitor);
waitForJobsToComplete();
-
- // check custom source encoding
- IClasspathContainer container2 = BuildPathManager.getMaven2ClasspathContainer(javaProject);
- IClasspathEntry entry2 = container2.getClasspathEntries()[0];
- assertEquals(entryPath, entry2.getPath());
- assertEquals(entry.getSourceAttachmentPath(), entry2.getSourceAttachmentPath());
- assertEquals(entry.getSourceAttachmentRootPath(), entry2.getSourceAttachmentRootPath());
- assertEquals(encoding, MavenClasspathHelpers.getAttribute(entry2, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING));
- }
-
- private Set getMavenProjectArtifacts(IProject p) throws CoreException {
- MavenProject mavenProject = manager.create(p, monitor).getMavenProject(monitor);
- return mavenProject.getArtifacts();
+ return buildpathManager;
}
}