IDEA-108478 Do not use section pluginManagement

This commit is contained in:
Sergey Evdokimov
2013-06-26 20:56:20 +04:00
parent bc38292ec5
commit 0432530445
3 changed files with 85 additions and 9 deletions
@@ -49,8 +49,24 @@ public class DependencyConflictId {
return new DependencyConflictId(groupId, artifactId, type, classifier);
}
public boolean isValid() {
return StringUtil.isNotEmpty(groupId) && StringUtil.isNotEmpty(artifactId);
@NotNull
public String getGroupId() {
return groupId;
}
@NotNull
public String getArtifactId() {
return artifactId;
}
@NotNull
public String getType() {
return type;
}
@Nullable
public String getClassifier() {
return classifier;
}
@Override
@@ -41,6 +41,7 @@ import org.jetbrains.idea.maven.dom.model.*;
import org.jetbrains.idea.maven.indices.MavenProjectIndicesManager;
import org.jetbrains.idea.maven.model.MavenArtifact;
import org.jetbrains.idea.maven.model.MavenId;
import org.jetbrains.idea.maven.model.MavenPlugin;
import org.jetbrains.idea.maven.project.MavenProject;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
import org.jetbrains.idea.maven.utils.MavenArtifactUtil;
@@ -194,6 +195,15 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert
return null;
}
@Nullable
protected MavenProject findMavenProject(ConvertContext context) {
PsiFile psiFile = context.getFile().getOriginalFile();
VirtualFile file = psiFile.getVirtualFile();
if (file == null) return null;
return MavenProjectsManager.getInstance(psiFile.getProject()).findProject(file);
}
private PsiFile resolveInProjects(MavenId id, MavenProjectsManager projectsManager, PsiManager psiManager) {
MavenProject project = projectsManager.findProject(id);
return project == null ? null : psiManager.findFile(project.getFile());
@@ -209,7 +219,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert
return psiManager.findFile(virtualFile);
}
protected File makeLocalRepositoryFile(MavenId id, File localRepository) {
private File makeLocalRepositoryFile(MavenId id, File localRepository) {
String relPath = (StringUtil.notNullize(id.getGroupId(), "null")).replace(".", "/");
relPath += "/" + id.getArtifactId();
@@ -273,10 +283,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert
DependencyConflictId dependencyId = DependencyConflictId.create((MavenDomDependency)parent);
if (dependencyId == null) return null;
VirtualFile file = context.getFile().getOriginalFile().getVirtualFile();
if (file == null) return null;
MavenProject mavenProject = MavenProjectsManager.getInstance(context.getProject()).findProject(file);
MavenProject mavenProject = findMavenProject(context);
if (mavenProject != null) {
for (MavenArtifact artifact : mavenProject.getDependencies()) {
if (dependencyId.equals(DependencyConflictId.create(artifact))) {
@@ -381,8 +388,33 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert
}
@Override
protected File makeLocalRepositoryFile(MavenId id, File localRepository) {
return MavenArtifactUtil.getArtifactFile(localRepository, id.getGroupId(), id.getArtifactId(), id.getVersion(), "pom");
public PsiFile resolve(MavenId id, ConvertContext context) {
PsiFile res = super.resolve(id, context);
if (res != null) return res;
// Try to resolve to imported plugin
MavenProject mavenProject = findMavenProject(context);
if (mavenProject != null) {
for (MavenPlugin plugin : mavenProject.getPlugins()) {
if (MavenArtifactUtil.isPluginIdEquals(id.getGroupId(), id.getArtifactId(), plugin.getGroupId(), plugin.getArtifactId())) {
return super.resolve(plugin.getMavenId(), context);
}
}
}
// Try to resolve to plugin with latest version
PsiManager psiManager = context.getPsiManager();
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(psiManager.getProject());
File artifactFile = MavenArtifactUtil
.getArtifactFile(projectsManager.getLocalRepository(), id.getGroupId(), id.getArtifactId(), id.getVersion(), "pom");
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(artifactFile);
if (virtualFile != null) {
return psiManager.findFile(virtualFile);
}
return null;
}
}
}
@@ -15,6 +15,7 @@
*/
package org.jetbrains.idea.maven.utils;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import gnu.trove.THashMap;
@@ -70,6 +71,33 @@ public class MavenArtifactUtil {
return getArtifactFile(localRepository, id.getGroupId(), id.getArtifactId(), id.getVersion(), "pom");
}
public static boolean isPluginIdEquals(@Nullable String groupId1, @Nullable String artifactId1,
@Nullable String groupId2, @Nullable String artifactId2) {
if (artifactId1 == null) return false;
if (!artifactId1.equals(artifactId2)) return false;
if (groupId1 != null) {
for (String group : DEFAULT_GROUPS) {
if (groupId1.equals(group)) {
groupId1 = null;
break;
}
}
}
if (groupId2 != null) {
for (String group : DEFAULT_GROUPS) {
if (groupId2.equals(group)) {
groupId2 = null;
break;
}
}
}
return Comparing.equal(groupId1, groupId2);
}
@NotNull
public static File getArtifactFile(File localRepository, String groupId, String artifactId, String version, String type) {
File dir = null;