diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactAction.java index a3ab8d20e2ab..801bd4a41974 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactAction.java @@ -31,6 +31,7 @@ import com.intellij.packaging.impl.artifacts.ArtifactUtil; import com.intellij.packaging.impl.elements.ArtifactPackagingElement; import com.intellij.util.PathUtil; import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -65,11 +66,8 @@ public class ExtractArtifactAction extends LayoutTreeActionBase { if (selectedElements.size() == 1) { initialName = PathUtil.suggestFileName(ContainerUtil.getFirstItem(selectedElements, null).createPresentation(myArtifactEditor.getContext()).getPresentableName()); } - final ExtractArtifactDialog dialog = new ExtractArtifactDialog(myArtifactEditor.getContext(), treeComponent, initialName); - dialog.show(); - if (!dialog.isOK()) { - return; - } + IExtractArtifactDialog dialog = showDialog(treeComponent, initialName); + if (dialog == null) return; final Project project = myArtifactEditor.getContext().getProject(); final ModifiableArtifactModel model = myArtifactEditor.getContext().getOrCreateModifiableArtifactModel(); @@ -87,4 +85,14 @@ public class ExtractArtifactAction extends LayoutTreeActionBase { }); treeComponent.rebuildTree(); } + + @Nullable + protected IExtractArtifactDialog showDialog(LayoutTreeComponent treeComponent, String initialName) { + final ExtractArtifactDialog dialog = new ExtractArtifactDialog(myArtifactEditor.getContext(), treeComponent, initialName); + dialog.show(); + if (!dialog.isOK()) { + return null; + } + return dialog; + } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactDialog.java index 11752e635b15..46d56a8d355d 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactDialog.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactDialog.java @@ -33,7 +33,7 @@ import javax.swing.event.DocumentEvent; /** * @author nik */ -public class ExtractArtifactDialog extends DialogWrapper { +public class ExtractArtifactDialog extends DialogWrapper implements IExtractArtifactDialog { private JPanel myMainPanel; private JTextField myNameField; private JComboBox myTypeBox; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/IExtractArtifactDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/IExtractArtifactDialog.java new file mode 100644 index 000000000000..dd731778d02a --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/IExtractArtifactDialog.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.ui.configuration.artifacts.actions; + +import com.intellij.packaging.artifacts.ArtifactType; + +/** + * @author nik + */ +public interface IExtractArtifactDialog { + String getArtifactName(); + + ArtifactType getArtifactType(); +} diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java index 76bd57f475b7..0df9273abb14 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java @@ -219,7 +219,9 @@ public class ProjectJdkImpl implements JDOMExternalizable, Sdk, SdkModificator { final String name = getName(); dest.setName(name); dest.setHomePath(getHomePath()); - dest.setVersionString(getVersionString()); + if (myVersionDefined) { + dest.setVersionString(getVersionString()); + } dest.setSdkAdditionalData(getSdkAdditionalData()); dest.myRootContainer.startChange(); dest.myRootContainer.removeAllRoots(); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/text/ASTDiffBuilder.java b/platform/lang-impl/src/com/intellij/psi/impl/source/text/ASTDiffBuilder.java index e4781fc34314..0e896d2c666a 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/text/ASTDiffBuilder.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/text/ASTDiffBuilder.java @@ -95,7 +95,9 @@ public class ASTDiffBuilder implements DiffTreeChangeBuilder { ((TreeElement)child).rawRemove(); ((CompositeElement)parent).subtreeChanged(); - DebugUtil.checkTreeStructure(parent); + if (DEBUG) { + DebugUtil.checkTreeStructure(parent); + } } public void nodeInserted(@NotNull final ASTNode oldParent, @NotNull ASTNode node, final int pos) { @@ -121,7 +123,9 @@ public class ASTDiffBuilder implements DiffTreeChangeBuilder { ((TreeElement)node).clearCaches(); ((CompositeElement)oldParent).subtreeChanged(); - DebugUtil.checkTreeStructure(oldParent); + if (DEBUG) { + DebugUtil.checkTreeStructure(oldParent); + } } public TreeChangeEventImpl getEvent() { diff --git a/platform/platform-resources-en/src/messages/RefactoringBundle.properties b/platform/platform-resources-en/src/messages/RefactoringBundle.properties index 64a102a2a8d2..f20f16af35cc 100644 --- a/platform/platform-resources-en/src/messages/RefactoringBundle.properties +++ b/platform/platform-resources-en/src/messages/RefactoringBundle.properties @@ -711,7 +711,7 @@ inline.parameter.confirmation=Inline parameter ''{0}'' with initializer ''{1}''? inline.parameter.command.name=Inline Parameter {0} inline.parameter.error.hierarchy=Inline parameter is not supported when method is a part of inheritance hierarchy inline.parameter.error.varargs=Inline for varargs parameters is not supported -inline.parameter.replace.with.local.checkbox=&Replace with local variable +inline.parameter.replace.with.local.checkbox=R&eplace with local variable type.migration.rerun.button.text=&Rerun Type Migration type.migration.migrate.button.text=&Migrate type.migration.exclude.action.text=&Exclude @@ -730,4 +730,4 @@ refactoring.extract.method.dialog.method.name=Method name: refactoring.extract.method.dialog.parameters=Parameters: refactoring.extract.method.dialog.output.variables=Output variables: refactoring.extract.method.dialog.signature.preview=Signature preview: -refactoring.extract.method.dialog.empty=Empty \ No newline at end of file +refactoring.extract.method.dialog.empty=Empty diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspection.java index ccc88bab4cc6..987187862e95 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,90 +29,133 @@ import org.jetbrains.annotations.NotNull; public class CastConflictsWithInstanceofInspection extends BaseInspection { + @Override @NotNull public String getDisplayName() { return InspectionGadgetsBundle.message( "cast.conflicts.with.instanceof.display.name"); } + @Override @NotNull public String buildErrorString(Object... infos) { return InspectionGadgetsBundle.message( "cast.conflicts.with.instanceof.problem.descriptor"); } + @NotNull + @Override + protected InspectionGadgetsFix[] buildFixes(final Object... infos) { + final PsiType castExpressionType = (PsiType)infos[0]; + final PsiInstanceOfExpression conflictingInstanceof = + (PsiInstanceOfExpression)infos[1]; + final PsiTypeElement typeElement = conflictingInstanceof.getCheckType(); + return new InspectionGadgetsFix[] { + new ReplaceCastFix(typeElement, castExpressionType), + new ReplaceInstanceofFix(typeElement, castExpressionType) + }; + } + + @Override public BaseInspectionVisitor buildVisitor() { return new CastConflictsWithInstanceofVisitor(); } - - @NotNull - @Override - protected InspectionGadgetsFix[] buildFixes(final Object... infos) { - final PsiInstanceOfExpression conflictingInstanceof = (PsiInstanceOfExpression)infos[2]; - return new InspectionGadgetsFix[] {new ReplaceFix(conflictingInstanceof, (PsiType)infos[0]){ - protected void replace(PsiTypeElement castTypeElement, PsiTypeElement instanceofTypeElement, Project project) { - castTypeElement.replace(JavaPsiFacade.getElementFactory(project).createTypeElement(instanceofTypeElement.getType())); - } - - @NotNull - public String getName() { - return "Replace cast to \'" + myCastType.getPresentableText() + "\' with \'" + myConflictingInstanceof.getCheckType().getType().getPresentableText() + "\'"; - } - }, new ReplaceFix(conflictingInstanceof, (PsiType)infos[0]) { - protected void replace(PsiTypeElement castTypeElement, PsiTypeElement instanceofTypeElement, Project project) { - instanceofTypeElement.replace(JavaPsiFacade.getElementFactory(project).createTypeElement(castTypeElement.getType())); - } - - @NotNull - public String getName() { - return "Replace instanceof \'" + myConflictingInstanceof.getCheckType().getType().getPresentableText() + "\' with \'" + myCastType.getPresentableText() + "\'"; - } - }}; - } - - private static class CastConflictsWithInstanceofVisitor + private static class CastConflictsWithInstanceofVisitor extends BaseInspectionVisitor { - @Override public void visitTypeCastExpression( + @Override + public void visitTypeCastExpression( @NotNull PsiTypeCastExpression expression) { super.visitTypeCastExpression(expression); final PsiType castType = expression.getType(); - if (castType != null) { - final PsiExpression operand = expression.getOperand(); - final PsiInstanceOfExpression conflictingInstanceof = InstanceOfUtils.getConflictingInstanceof(expression); - if (conflictingInstanceof == null) { + if (castType == null) { return; - } - registerError(expression, castType, operand, conflictingInstanceof); } + final PsiInstanceOfExpression conflictingInstanceof = + InstanceOfUtils.getConflictingInstanceof(expression); + if (conflictingInstanceof == null) { + return; + } + registerError(expression, castType, conflictingInstanceof); } } - private static abstract class ReplaceFix extends InspectionGadgetsFix { - protected final PsiInstanceOfExpression myConflictingInstanceof; - protected final PsiType myCastType; + private static abstract class ReplaceFix extends InspectionGadgetsFix { + + protected final PsiTypeElement myInstanceofTypeElement; + protected final PsiType myCastType; + + protected ReplaceFix(@NotNull PsiTypeElement instanceofTypeElement, + @NotNull PsiType castType) { + myInstanceofTypeElement = instanceofTypeElement; + myCastType = castType; + } + + @Override + protected void doFix(Project project, ProblemDescriptor descriptor) + throws IncorrectOperationException { + final PsiTypeCastExpression typeCastExpression = + (PsiTypeCastExpression)descriptor.getPsiElement(); + final PsiTypeElement castTypeElement = + typeCastExpression.getCastType(); + if (castTypeElement == null) { + return; + } + final PsiElement newElement = + replace(castTypeElement, myInstanceofTypeElement, project); + final JavaCodeStyleManager codeStyleManager = + JavaCodeStyleManager.getInstance(project); + codeStyleManager.shortenClassReferences(newElement); + } + + protected abstract PsiElement replace(PsiTypeElement castTypeElement, + PsiTypeElement instanceofTypeElement, + Project project); - public ReplaceFix(PsiInstanceOfExpression conflictingInstanceof, PsiType castType) { - myConflictingInstanceof = conflictingInstanceof; - myCastType = castType; } - @Override - protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { - final PsiTypeCastExpression typeCastExpression = (PsiTypeCastExpression)descriptor.getPsiElement(); - final PsiTypeElement castTypeElement = typeCastExpression.getCastType(); - final PsiTypeElement typeElement = myConflictingInstanceof.getCheckType(); - if (castTypeElement != null && typeElement != null) { - replace(castTypeElement, typeElement, project); - JavaCodeStyleManager.getInstance(project).shortenClassReferences(myConflictingInstanceof); - } + private static class ReplaceCastFix extends ReplaceFix { + + public ReplaceCastFix(PsiTypeElement instanceofTypeElement, + PsiType castType) { + super(instanceofTypeElement, castType); + } + + @Override + protected PsiElement replace(PsiTypeElement castTypeElement, + PsiTypeElement instanceofTypeElement, + Project project) { + return castTypeElement.replace(instanceofTypeElement); + } + + @NotNull + public String getName() { + return "Replace cast to \'" + + myCastType.getPresentableText() + "\' with \'" + + myInstanceofTypeElement.getType().getPresentableText() + '\''; + } } - protected abstract void replace(PsiTypeElement castTypeElement, PsiTypeElement instanceofTypeElement, Project project); + private static class ReplaceInstanceofFix extends ReplaceFix { + public ReplaceInstanceofFix(PsiTypeElement instanceofTypeElement, + PsiType castExpressionType) { + super(instanceofTypeElement, castExpressionType); + } - } - + @Override + protected PsiElement replace(PsiTypeElement castTypeElement, + PsiTypeElement instanceofTypeElement, + Project project) { + return instanceofTypeElement.replace(castTypeElement); + } + @NotNull + public String getName() { + return "Replace instanceof \'" + + myInstanceofTypeElement.getType().getPresentableText() + + "\' with \'" + myCastType.getPresentableText() + '\''; + } + } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/InstanceOfUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/InstanceOfUtils.java index 458f40f99374..c3400bf86d72 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/InstanceOfUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/InstanceOfUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Bas Leijdekkers + * Copyright 2007-2010 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,13 +48,12 @@ public class InstanceOfUtils { PsiBinaryExpression.class, PsiIfStatement.class, PsiConditionalExpression.class); } + if (checker.hasAgreeingInstanceof()) { + return null; + } return checker.getConflictingInstanceof(); } - public static boolean hasConflictingInstanceof(@NotNull PsiTypeCastExpression expression) { - return getConflictingInstanceof(expression) != null; - } - public static boolean hasAgreeingInstanceof( @NotNull PsiTypeCastExpression expression) { final PsiType castType = expression.getType(); @@ -103,22 +102,29 @@ public class InstanceOfUtils { visitExpression(expression); } - @Override public void visitBinaryExpression(PsiBinaryExpression expression) { + @Override public void visitBinaryExpression( + PsiBinaryExpression expression) { final PsiJavaToken sign = expression.getOperationSign(); final IElementType tokenType = sign.getTokenType(); if (tokenType == JavaTokenType.ANDAND) { - checkExpression(expression.getLOperand()); - checkExpression(expression.getROperand()); - if (!inElse && conflictingInstanceof != null) { - agreeingInstanceof = false; - } + checkExpression(expression.getLOperand()); + if (agreeingInstanceof) { + return; + } + checkExpression(expression.getROperand()); + if (agreeingInstanceof) { + return; + } + if (!inElse && conflictingInstanceof != null) { + agreeingInstanceof = false; + } } else if (tokenType == JavaTokenType.OROR) { - checkExpression(expression.getLOperand()); - checkExpression(expression.getROperand()); - if (inElse && conflictingInstanceof != null) { - agreeingInstanceof = false; - } + checkExpression(expression.getLOperand()); + checkExpression(expression.getROperand()); + if (inElse && conflictingInstanceof != null) { + agreeingInstanceof = false; + } } } @@ -202,14 +208,15 @@ public class InstanceOfUtils { } private void checkInstanceOfExpression(PsiExpression expression) { - if (expression instanceof PsiInstanceOfExpression) { - final PsiInstanceOfExpression instanceOfExpression = - (PsiInstanceOfExpression)expression; - if (isAgreeing(instanceOfExpression)) { - agreeingInstanceof = true; - } else if (isConflicting(instanceOfExpression)) { - conflictingInstanceof = instanceOfExpression; - } + if (!(expression instanceof PsiInstanceOfExpression)) { + return; + } + final PsiInstanceOfExpression instanceOfExpression = + (PsiInstanceOfExpression)expression; + if (isAgreeing(instanceOfExpression)) { + agreeingInstanceof = true; + } else if (isConflicting(instanceOfExpression)) { + conflictingInstanceof = instanceOfExpression; } } @@ -253,10 +260,6 @@ public class InstanceOfUtils { return agreeingInstanceof; } - public boolean hasConflictingInstanceof() { - return conflictingInstanceof != null; - } - public PsiInstanceOfExpression getConflictingInstanceof() { return conflictingInstanceof; } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/andAnd/AndAnd.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/andAnd/AndAnd.java new file mode 100644 index 000000000000..fcdae5a8e380 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/andAnd/AndAnd.java @@ -0,0 +1,30 @@ +package com.siyeh.igtest.bugs.castConflictingInstanceof.andAnd; + +public class AndAnd { + + public String getCanonicalText(PsiElement resolved) { + if (resolved instanceof PsiMember || resolved instanceof PsiNamedElement) { + PsiClass clazz = ((PsiMember) resolved).getContainingClass(); + if (clazz != null) { + String qName = clazz.getQualifiedName(); + if (qName != null) { + return qName + "." + ((PsiNamedElement) resolved).getName(); + } + } + } + + return null; + } + + interface PsiElement {} + interface PsiMember { + + PsiClass getContainingClass(); + } + interface PsiNamedElement { + String getName(); + } + interface PsiClass extends PsiElement { + String getQualifiedName(); + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/andAnd/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/andAnd/expected.xml new file mode 100644 index 000000000000..e8f00e82629f --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/castConflictingInstanceof/andAnd/expected.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java index b64c12f9596b..31f26b7a981f 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CastConflictsWithInstanceofInspectionTest.java @@ -31,6 +31,10 @@ public class CastConflictsWithInstanceofInspectionTest extends IGInspectionTestC doTest(); } + public void testAndAnd() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest("com/siyeh/igtest/bugs/castConflictingInstanceof/" + getTestName(false), new CastConflictsWithInstanceofInspection()); } diff --git a/plugins/maven/maven.iml b/plugins/maven/maven.iml index d82b2612467b..8889960a8ff7 100644 --- a/plugins/maven/maven.iml +++ b/plugins/maven/maven.iml @@ -25,45 +25,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/embedder/MavenEmbedderWrapper.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/embedder/MavenEmbedderWrapper.java index 869e7cdc9b8f..793a5b9bd39e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/embedder/MavenEmbedderWrapper.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/embedder/MavenEmbedderWrapper.java @@ -49,6 +49,7 @@ import org.apache.maven.monitor.event.DefaultEventDispatcher; import org.apache.maven.monitor.event.DefaultEventMonitor; import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.plugin.PluginManager; +import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.ProfileManager; import org.apache.maven.project.*; @@ -66,6 +67,7 @@ import org.apache.maven.settings.Settings; import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainerException; +import org.codehaus.plexus.component.repository.ComponentDependency; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; @@ -299,23 +301,27 @@ public class MavenEmbedderWrapper { throws MavenProcessCanceledException { return doExecute(new Executor() { public Artifact execute() throws Exception { - Artifact artifact = getComponent(ArtifactFactory.class).createArtifactWithClassifier(id.getGroupId(), - id.getArtifactId(), - id.getVersion(), - type, - classifier); - try { - getComponent(ArtifactResolver.class).resolve(artifact, convertRepositories(remoteRepositories), myLocalRepository); - return artifact; - } - catch (Exception e) { - MavenLog.LOG.info(e); - } - return artifact; + return doResolve(id, type, classifier, convertRepositories(remoteRepositories)); } }); } + private Artifact doResolve(MavenId id, String type, String classifier, List remoteRepositories) { + Artifact artifact = getComponent(ArtifactFactory.class).createArtifactWithClassifier(id.getGroupId(), + id.getArtifactId(), + id.getVersion(), + type, + classifier); + try { + getComponent(ArtifactResolver.class).resolve(artifact, remoteRepositories, myLocalRepository); + return artifact; + } + catch (Exception e) { + MavenLog.LOG.info(e); + } + return artifact; + } + private List convertRepositories(List repositories) { List result = new ArrayList(); for (MavenRemoteRepository each : repositories) { @@ -330,7 +336,7 @@ public class MavenEmbedderWrapper { return result; } - public boolean resolvePlugin(@NotNull final MavenPlugin plugin, @NotNull final MavenProject nativeMavenProject) + public boolean resolvePlugin(@NotNull final MavenPlugin plugin, @NotNull final MavenProject nativeMavenProject, final boolean transitive) throws MavenProcessCanceledException { return doExecute(new Executor() { public Boolean execute() throws Exception { @@ -339,7 +345,15 @@ public class MavenEmbedderWrapper { mavenPlugin.setGroupId(plugin.getGroupId()); mavenPlugin.setArtifactId(plugin.getArtifactId()); mavenPlugin.setVersion(plugin.getVersion()); - getComponent(PluginManager.class).verifyPlugin(mavenPlugin, nativeMavenProject, mySettings, myLocalRepository); + PluginDescriptor result = + getComponent(PluginManager.class).verifyPlugin(mavenPlugin, nativeMavenProject, mySettings, myLocalRepository); + if (!transitive) return true; + + for (ComponentDependency each : (List)result.getDependencies()) { + List repos = nativeMavenProject.getRemoteArtifactRepositories(); + // todo try to use parallel downloading + doResolve(new MavenId(each.getGroupId(), each.getArtifactId(), each.getVersion()), each.getType(), null, repos); + } } catch (Exception e) { MavenLog.LOG.info(e); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImporter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImporter.java index 7c1b72de5412..a5c3f872504e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImporter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImporter.java @@ -53,6 +53,10 @@ public abstract class MavenImporter { public abstract boolean isSupportedDependency(MavenArtifact artifact); + public boolean requiresResolvedPlugin(MavenPlugin plugin) { + return false; + } + public abstract void preProcess(Module module, MavenProject mavenProject, MavenProjectChanges changes, diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenEmbeddersManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenEmbeddersManager.java index d7263e4dced5..9f184d4244e7 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenEmbeddersManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenEmbeddersManager.java @@ -31,7 +31,7 @@ public class MavenEmbeddersManager { FOR_PLUGINS_RESOLVE, FOR_FOLDERS_RESOLVE, FOR_DOWNLOAD, - FOR_FLEX_CONFIG_GENERATION, + FOR_POST_PROCESSING, } private final MavenGeneralSettings myGeneralSettings; diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenId.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenId.java index 929bcf1e5220..cb38c558d66f 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenId.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenId.java @@ -77,9 +77,14 @@ public class MavenId implements Serializable { return getDisplayString(); } - public boolean equals(String groupId, String artifactId, String version) { + public boolean equals(String groupId, String artifactId) { if (myGroupId != null ? !myGroupId.equals(groupId) : groupId != null) return false; if (myArtifactId != null ? !myArtifactId.equals(artifactId) : artifactId != null) return false; + return true; + } + + public boolean equals(String groupId, String artifactId, String version) { + if (!equals(groupId, artifactId)) return false; if (myVersion != null ? !myVersion.equals(version) : version != null) return false; return true; } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java index 422ec9ec3efc..7e8b89a67132 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java @@ -448,6 +448,15 @@ public class MavenProject { getActiveProfilesIds(), locator); MavenProjectChanges changes = set(result, false, result.readingProblems.isEmpty(), false); + + List importers = getSuitableImporters(); + for (MavenPlugin eachPlugin : getPlugins()) { + for (MavenImporter eachImporter : importers) { + if (eachImporter.requiresResolvedPlugin(eachPlugin)) { + embedder.resolvePlugin(eachPlugin, result.nativeMavenProject, true); + } + } + } return Pair.create(changes, result.nativeMavenProject); } @@ -759,7 +768,7 @@ public class MavenProject { @Nullable public MavenPlugin findPlugin(String groupId, String artifactId) { for (MavenPlugin each : getPlugins()) { - if (groupId.equals(each.getGroupId()) && artifactId.equals(each.getArtifactId())) return each; + if (each.getMavenId().equals(groupId, artifactId)) return each; } return null; } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java index 8da3ceb06aff..c3ee0c8afc6b 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java @@ -30,6 +30,7 @@ import org.apache.maven.artifact.Artifact; import org.jetbrains.annotations.TestOnly; import org.jetbrains.idea.maven.embedder.MavenConsole; import org.jetbrains.idea.maven.embedder.MavenEmbedderWrapper; +import org.jetbrains.idea.maven.importing.MavenImporter; import org.jetbrains.idea.maven.utils.*; import java.io.*; @@ -384,7 +385,7 @@ public class MavenProjectsTree { } public Collection> getProfilesWithStates() { - Collection> result = new ArrayListSet>(); + Collection> result = new ArrayListSet>(); Pair, Collection> profiles = getAvailableAndActiveProfiles(true, true); Collection available = profiles.first; @@ -393,7 +394,9 @@ public class MavenProjectsTree { for (String each : available) { MavenProfileState state = MavenProfileState.NONE; - if (explicitProfiles.contains(each)) state = MavenProfileState.EXPLICIT; + if (explicitProfiles.contains(each)) { + state = MavenProfileState.EXPLICIT; + } else if (active.contains(each)) state = MavenProfileState.IMPLICIT; result.add(Pair.create(each, state)); } @@ -1016,7 +1019,7 @@ public class MavenProjectsTree { for (MavenPlugin each : mavenProject.getDeclaredPlugins()) { process.checkCanceled(); process.setText(ProjectBundle.message("maven.downloading.pom.plugins", mavenProject.getDisplayName())); - embedder.resolvePlugin(each, nativeMavenProject); + embedder.resolvePlugin(each, nativeMavenProject, false); } firePluginsResolved(mavenProject); } @@ -1032,27 +1035,27 @@ public class MavenProjectsTree { final MavenConsole console, final MavenProgressIndicator process, final Object message) throws MavenProcessCanceledException { - doWithEmbedder(mavenProject, - embeddersManager, - MavenEmbeddersManager.EmbedderKind.FOR_FOLDERS_RESOLVE, - console, - process, - new EmbedderTask() { - public void run(MavenEmbedderWrapper embedder) throws MavenProcessCanceledException { - process.checkCanceled(); - process.setText(ProjectBundle.message("maven.updating.folders.pom", mavenProject.getDisplayName())); - process.setText2(""); + executeWithEmbedder(mavenProject, + embeddersManager, + MavenEmbeddersManager.EmbedderKind.FOR_FOLDERS_RESOLVE, + console, + process, + new EmbedderTask() { + public void run(MavenEmbedderWrapper embedder) throws MavenProcessCanceledException { + process.checkCanceled(); + process.setText(ProjectBundle.message("maven.updating.folders.pom", mavenProject.getDisplayName())); + process.setText2(""); - Pair resolveResult = mavenProject.resolveFolders(embedder, - generalSettings, - importingSettings, - new MavenProjectReader(), - console); - if (resolveResult.first) { - fireFoldersResolved(Pair.create(mavenProject, resolveResult.second), message); - } - } - }); + Pair resolveResult = mavenProject.resolveFolders(embedder, + generalSettings, + importingSettings, + new MavenProjectReader(), + console); + if (resolveResult.first) { + fireFoldersResolved(Pair.create(mavenProject, resolveResult.second), message); + } + } + }); } public void downloadArtifacts(MavenProject mavenProject, @@ -1091,12 +1094,12 @@ public class MavenProjectsTree { } } - public void doWithEmbedder(MavenProject mavenProject, - MavenEmbeddersManager embeddersManager, - MavenEmbeddersManager.EmbedderKind embedderKind, - MavenConsole console, - MavenProgressIndicator process, - EmbedderTask task) throws MavenProcessCanceledException { + public void executeWithEmbedder(MavenProject mavenProject, + MavenEmbeddersManager embeddersManager, + MavenEmbeddersManager.EmbedderKind embedderKind, + MavenConsole console, + MavenProgressIndicator process, + EmbedderTask task) throws MavenProcessCanceledException { MavenEmbedderWrapper embedder = embeddersManager.getEmbedder(embedderKind); embedder.customizeForStrictResolve(getProjectIdToFileMapping(), console, process); embedder.clearCachesFor(mavenProject); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenConstants.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenConstants.java index c1be345b500f..53cb6442d1c8 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenConstants.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenConstants.java @@ -22,6 +22,7 @@ public class MavenConstants { public static final String PROFILES_XML = "profiles.xml"; public static final String SETTINGS_XML = "settings.xml"; + public static final String TYPE_POM = "pom"; public static final String TYPE_JAR = "jar"; public static final String TYPE_TEST_JAR = "test-jar"; public static final String TYPE_WAR = "war"; diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilderHelper.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilderHelper.java index d91e2edf8c85..c7588478ec43 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilderHelper.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilderHelper.java @@ -171,7 +171,7 @@ public class MavenModuleBuilderHelper { } MavenRunnerParameters params = new MavenRunnerParameters( - false, workingDir.getPath(), Collections.singletonList("org.apache.maven.plugins:maven-archetype-plugin:generate"), null); + false, workingDir.getPath(), Collections.singletonList("org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate"), null); MavenRunner runner = MavenRunner.getInstance(project); MavenRunnerSettings settings = runner.getState().clone(); diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java index fe9cc18456ba..38997dc7005f 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java @@ -236,7 +236,6 @@ public abstract class MavenTestCase extends UsefulTestCase { "" + " " + " Nexus" + - " Nexus Public Mirror" + " " + mirror + "" + " *" + " " + diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/embedder/MavenEmbedderWrapperTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/embedder/MavenEmbedderWrapperTest.java index 683f927f8529..9ec9d9f6c735 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/embedder/MavenEmbedderWrapperTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/embedder/MavenEmbedderWrapperTest.java @@ -58,6 +58,11 @@ public class MavenEmbedderWrapperTest extends MavenImportingTestCase { assertEquals(getRepositoryFile(), myEmbedder.getLocalRepositoryFile()); } + public void testReleasingTwice() throws Exception { + myEmbedder.release(); + myEmbedder.release(); + } + public void testExecutionGoals() throws Exception { createProjectSubFile("src/main/java/A.java", "public class A {}"); @@ -127,7 +132,7 @@ public class MavenEmbedderWrapperTest extends MavenImportingTestCase { " " + " com.adobe.flex.framework" + " framework" + - " 3.2.0.3959" + + " 3.2.0.3958" + " resource-bundle" + " en_US" + " " + @@ -138,6 +143,7 @@ public class MavenEmbedderWrapperTest extends MavenImportingTestCase { " " + " org.sonatype.flexmojos" + " flexmojos-maven-plugin" + + " 3.5.0" + " true" + " " + " " + diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArchetypesTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArchetypesTest.java index 795174854eaa..6727fd5b1e3e 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArchetypesTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArchetypesTest.java @@ -18,10 +18,7 @@ package org.jetbrains.idea.maven.importing; import com.intellij.openapi.progress.EmptyProgressIndicator; import gnu.trove.THashMap; import org.jetbrains.idea.maven.MavenTestCase; -import org.jetbrains.idea.maven.execution.MavenExecutor; -import org.jetbrains.idea.maven.execution.MavenExternalExecutor; -import org.jetbrains.idea.maven.execution.MavenRunnerParameters; -import org.jetbrains.idea.maven.execution.MavenRunnerSettings; +import org.jetbrains.idea.maven.execution.*; import java.io.File; import java.util.Arrays; @@ -36,7 +33,7 @@ public class ArchetypesTest extends MavenTestCase { dir.mkdirs(); MavenRunnerParameters params = new MavenRunnerParameters(false, dir.getPath(), - Arrays.asList("archetype:create"), + Arrays.asList("org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate"), Collections.emptyList()); MavenRunnerSettings settings = new MavenRunnerSettings(); @@ -44,6 +41,8 @@ public class ArchetypesTest extends MavenTestCase { props.put("archetypeGroupId", "org.apache.maven.archetypes"); props.put("archetypeArtifactId", "maven-archetype-quickstart"); props.put("archetypeVersion", "1.0"); + props.put("interactiveMode", "false"); + props.put("groupId", "foo"); props.put("groupId", "foo"); props.put("artifactId", "bar"); diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java index dcf777d169b4..b4dbb4062e1e 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java @@ -15,6 +15,8 @@ */ package org.jetbrains.idea.maven.importing; +import junit.framework.Test; +import junit.framework.TestSuite; import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.indices.MavenCustomRepositoryHelper; @@ -123,4 +125,12 @@ public class ArtifactsDownloadingTest extends MavenImportingTestCase { assertTrue(f.exists()); } + + public static Test suite() { + TestSuite s = new TestSuite(); + s.addTestSuite(ArtifactsDownloadingTest.class); + s.addTestSuite(ArtifactsDownloadingTest.class); + s.addTestSuite(ArtifactsDownloadingTest.class); + return s; + } }