IDEA generate maven libraries with incorrect classes URL. Url points to pom.xml inste... idea/132.106
authorSergey Evdokimov <sergey.evdokimov@jetbrains.com>
Wed, 4 Sep 2013 13:51:25 +0000 (17:51 +0400)
committerSergey Evdokimov <sergey.evdokimov@jetbrains.com>
Wed, 4 Sep 2013 13:51:50 +0000 (17:51 +0400)
plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenModuleImporter.java
plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java
plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java

index c628a6c01b2898e34700b697af086422c9e6c718..b53471de926b29237cd0297e12fe46d63b270934 100644 (file)
@@ -174,21 +174,11 @@ public class MavenModuleImporter {
 
       MavenProject depProject = myMavenTree.findProject(artifact.getMavenId());
 
-      if (depProject != null && !myMavenTree.isIgnored(depProject)) {
+      if (depProject != null) {
         if (depProject == myMavenProject) continue;
-        boolean isTestJar = MavenConstants.TYPE_TEST_JAR.equals(dependencyType) || "tests".equals(artifact.getClassifier());
-        myRootModelAdapter.addModuleDependency(myMavenProjectToModuleName.get(depProject), scope, isTestJar);
 
-        Element buildHelperCfg = depProject.getPluginGoalConfiguration("org.codehaus.mojo", "build-helper-maven-plugin", "attach-artifact");
-        if (buildHelperCfg != null) {
-          addAttachArtifactDependency(buildHelperCfg, scope, depProject, artifact);
-        }
-
-        if (artifact.getClassifier() != null
-            && !isTestJar
-            && !"system".equals(artifact.getScope())
-            && !"false".equals(System.getProperty("idea.maven.classifier.dep"))) {
-          MavenArtifact a = new MavenArtifact(
+        if (myMavenTree.isIgnored(depProject)) {
+          MavenArtifact projectsArtifactInRepository = new MavenArtifact(
             artifact.getGroupId(),
             artifact.getArtifactId(),
             artifact.getVersion(),
@@ -203,7 +193,38 @@ public class MavenModuleImporter {
             false, false
           );
 
-          myRootModelAdapter.addLibraryDependency(a, scope, myModifiableModelsProvider, myMavenProject);
+          myRootModelAdapter.addLibraryDependency(projectsArtifactInRepository, scope, myModifiableModelsProvider, myMavenProject);
+        }
+        else {
+          boolean isTestJar = MavenConstants.TYPE_TEST_JAR.equals(dependencyType) || "tests".equals(artifact.getClassifier());
+          myRootModelAdapter.addModuleDependency(myMavenProjectToModuleName.get(depProject), scope, isTestJar);
+
+          Element buildHelperCfg = depProject.getPluginGoalConfiguration("org.codehaus.mojo", "build-helper-maven-plugin", "attach-artifact");
+          if (buildHelperCfg != null) {
+            addAttachArtifactDependency(buildHelperCfg, scope, depProject, artifact);
+          }
+
+          if (artifact.getClassifier() != null
+              && !isTestJar
+              && !"system".equals(artifact.getScope())
+              && !"false".equals(System.getProperty("idea.maven.classifier.dep"))) {
+            MavenArtifact a = new MavenArtifact(
+              artifact.getGroupId(),
+              artifact.getArtifactId(),
+              artifact.getVersion(),
+              artifact.getBaseVersion(),
+              dependencyType,
+              artifact.getClassifier(),
+              artifact.getScope(),
+              artifact.isOptional(),
+              artifact.getExtension(),
+              null,
+              myMavenProject.getLocalRepository(),
+              false, false
+            );
+
+            myRootModelAdapter.addLibraryDependency(a, scope, myModifiableModelsProvider, myMavenProject);
+          }
         }
       }
       else if ("system".equals(artifact.getScope())) {
index ef8e43f78829d955ee096f6fcfbf1529dc1175cd..ed5438974062dff7d62472caf3e1f4b9d4f90d24 100644 (file)
@@ -38,6 +38,7 @@ import com.intellij.util.ui.UIUtil;
 import gnu.trove.THashSet;
 import org.intellij.lang.annotations.Language;
 import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.idea.maven.indices.MavenIndicesManager;
 import org.jetbrains.idea.maven.project.*;
 import org.jetbrains.idea.maven.utils.MavenProgressIndicator;
@@ -499,7 +500,8 @@ public abstract class MavenTestCase extends UsefulTestCase {
     assertEquals(new HashSet<T>(expected), new HashSet<T>(actual));
   }
   protected static void assertUnorderedPathsAreEqual(Collection<String> actual, Collection<String> expected) {
-    assertEquals(new THashSet<String>(expected, FileUtil.PATH_HASHING_STRATEGY), new THashSet<String>(actual, FileUtil.PATH_HASHING_STRATEGY));
+    assertEquals(new SetWithToString<String>(new THashSet<String>(expected, FileUtil.PATH_HASHING_STRATEGY)),
+                 new SetWithToString<String>(new THashSet<String>(actual, FileUtil.PATH_HASHING_STRATEGY)));
   }
 
   protected static <T> void assertUnorderedElementsAreEqual(T[] actual, T... expected) {
@@ -556,4 +558,45 @@ public abstract class MavenTestCase extends UsefulTestCase {
   private static String getTestMavenHome() {
     return System.getProperty("idea.maven.test.home");
   }
+
+  private static class SetWithToString<T> extends AbstractSet<T> {
+
+    private final Set<T> myDelegate;
+
+    public SetWithToString(@NotNull Set<T> delegate) {
+      myDelegate = delegate;
+    }
+
+    @Override
+    public int size() {
+      return myDelegate.size();
+    }
+
+    @Override
+    public boolean contains(Object o) {
+      return myDelegate.contains(o);
+    }
+
+    @NotNull
+    @Override
+    public Iterator<T> iterator() {
+      return myDelegate.iterator();
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c) {
+      return myDelegate.containsAll(c);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      return myDelegate.equals(o);
+    }
+
+    @Override
+    public int hashCode() {
+      return myDelegate.hashCode();
+    }
+  }
+
 }
index 390b8f817205c3689298f7826c58aa5f6e55ea36..3d1e3b709fe86b52db101e756e50b8a1528e8860 100644 (file)
@@ -2337,6 +2337,11 @@ public class DependenciesImportingTest extends MavenImportingTestCase {
 
     assertModules("project", "m1");
     assertModuleLibDeps("m1", "Maven: test:m2:2");
+
+    assertModuleLibDep("m1", "Maven: test:m2:2",
+                       "jar://" + getRepositoryPath() + "/test/m2/2/m2-2.jar!/",
+                       "jar://" + getRepositoryPath() + "/test/m2/2/m2-2-sources.jar!/",
+                       "jar://" + getRepositoryPath() + "/test/m2/2/m2-2-javadoc.jar!/");
   }
 
   public void testSaveJdkPosition() throws Exception {