Maven: do not populate system-scope dependency root entries on every import (IDEADEV-41396)

This commit is contained in:
Anton.Makeev
2009-11-17 15:48:02 +03:00
parent 4699fd4f8a
commit a27c3119fe
4 changed files with 113 additions and 7 deletions
@@ -240,13 +240,14 @@ public class MavenRootModelAdapter {
OrderRootType type,
MavenArtifact artifact,
String classifier) {
String newUrl = artifact.getUrlForClassifier(classifier);
for (String url : libraryModel.getUrls(type)) {
if (isRepositoryUrl(artifact, url, classifier)) {
if (newUrl.equals(url)) return;
if (MavenConstants.SCOPE_SYSTEM.equals(artifact.getScope()) || isRepositoryUrl(artifact, url, classifier)) {
libraryModel.removeRoot(url, type);
}
}
libraryModel.addRoot(artifact.getUrlForClassifier(classifier), type);
libraryModel.addRoot(newUrl, type);
}
private boolean isRepositoryUrl(MavenArtifact artifact, String url, String classifier) {
@@ -24,6 +24,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.embedder.CustomArtifact;
import static org.jetbrains.idea.maven.project.MavenId.append;
@@ -134,10 +135,10 @@ public class MavenArtifact implements Serializable {
}
public boolean isResolved() {
return myResolved && myFile != null && myFile.exists() && !myStubbed;
return myResolved && myFile.exists() && !myStubbed;
}
@Nullable
@NotNull
public File getFile() {
return myFile;
}
@@ -187,6 +187,8 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
private void assertModuleLibDepPath(LibraryOrderEntry lib, OrderRootType type, List<String> paths) {
if (paths == null) return;
assertUnorderedElementsAreEqual(lib.getUrls(type), ArrayUtil.toStringArray(paths));
// also check the library because it may contain slight different set of urls (e.g. with duplicates)
assertUnorderedElementsAreEqual(lib.getLibrary().getUrls(type), ArrayUtil.toStringArray(paths));
}
protected void assertModuleLibDepScope(String moduleName, String depName, DependencyScope scope) {
@@ -1221,9 +1221,8 @@ public class DependenciesImportingTest extends MavenImportingTestCase {
ModifiableRootModel rootModel = ModuleRootManager.getInstance(getModule("project")).getModifiableModel();
LibraryTable.ModifiableModel tableModel = rootModel.getModuleLibraryTable().getModifiableModel();
Library lib = tableModel.createLibrary("junit:junit:4.0");
tableModel.createLibrary("junit:junit:4.0");
tableModel.commit();
//rootModel.addLibraryEntry(lib);
rootModel.commit();
assertModuleLibDeps("project", "junit:junit:4.0");
@@ -1405,6 +1404,109 @@ public class DependenciesImportingTest extends MavenImportingTestCase {
"jar://" + getRepositoryPath() + "/org/testng/testng/5.8/testng-5.8-jdk15-javadoc.jar!/");
}
public void testDoNotPopulateSameRootEntriesOnEveryImport() throws Exception {
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<dependencies>" +
" <dependency>" +
" <groupId>junit</groupId>" +
" <artifactId>junit</artifactId>" +
" <version>4.0</version>" +
" </dependency>" +
"</dependencies>");
assertModuleLibDep("project", "Maven: junit:junit:4.0",
Arrays.asList("jar://" + getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar!/"),
Arrays.asList("jar://" + getRepositoryPath() + "/junit/junit/4.0/junit-4.0-sources.jar!/"),
Arrays.asList("jar://" + getRepositoryPath() + "/junit/junit/4.0/junit-4.0-javadoc.jar!/"));
scheduleResolveAll();
resolveDependenciesAndImport();
scheduleResolveAll();
resolveDependenciesAndImport();
assertModuleLibDep("project", "Maven: junit:junit:4.0",
Arrays.asList("jar://" + getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar!/"),
Arrays.asList("jar://" + getRepositoryPath() + "/junit/junit/4.0/junit-4.0-sources.jar!/"),
Arrays.asList("jar://" + getRepositoryPath() + "/junit/junit/4.0/junit-4.0-javadoc.jar!/"));
}
public void testDoNotPopulateSameRootEntriesOnEveryImportForSystemLibraries() throws Exception {
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<dependencies>" +
" <dependency>" +
" <groupId>xxx</groupId>" +
" <artifactId>yyy</artifactId>" +
" <version>1</version>" +
" <scope>system</scope>" +
" <systemPath>c:/foo/bar.jar</systemPath>" +
" </dependency>" +
"</dependencies>");
assertModuleLibDep("project", "Maven: xxx:yyy:1",
Arrays.asList("jar://c:/foo/bar.jar!/"),
Arrays.asList("jar://c:/foo/bar-sources.jar!/"),
Arrays.asList("jar://c:/foo/bar-javadoc.jar!/"));
scheduleResolveAll();
resolveDependenciesAndImport();
scheduleResolveAll();
resolveDependenciesAndImport();
assertModuleLibDep("project", "Maven: xxx:yyy:1",
Arrays.asList("jar://c:/foo/bar.jar!/"),
Arrays.asList("jar://c:/foo/bar-sources.jar!/"),
Arrays.asList("jar://c:/foo/bar-javadoc.jar!/"));
}
public void testRemovingPreviousSystemPathForForSystemLibraries() throws Exception {
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<dependencies>" +
" <dependency>" +
" <groupId>xxx</groupId>" +
" <artifactId>yyy</artifactId>" +
" <version>1</version>" +
" <scope>system</scope>" +
" <systemPath>c:/foo/bar.jar</systemPath>" +
" </dependency>" +
"</dependencies>");
assertModuleLibDep("project", "Maven: xxx:yyy:1",
Arrays.asList("jar://c:/foo/bar.jar!/"),
Arrays.asList("jar://c:/foo/bar-sources.jar!/"),
Arrays.asList("jar://c:/foo/bar-javadoc.jar!/"));
createProjectPom("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>" +
"<dependencies>" +
" <dependency>" +
" <groupId>xxx</groupId>" +
" <artifactId>yyy</artifactId>" +
" <version>1</version>" +
" <scope>system</scope>" +
" <systemPath>c:/foo/xxx.jar</systemPath>" +
" </dependency>" +
"</dependencies>");
scheduleResolveAll();
resolveDependenciesAndImport();
assertModuleLibDep("project", "Maven: xxx:yyy:1",
Arrays.asList("jar://c:/foo/xxx.jar!/"),
Arrays.asList("jar://c:/foo/xxx-sources.jar!/"),
Arrays.asList("jar://c:/foo/xxx-javadoc.jar!/"));
}
public void testRemovingUnusedLibraries() throws Exception {
createProjectPom("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +