Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Alexey Pegov
2010-02-05 16:49:13 +03:00
24 changed files with 323 additions and 186 deletions
@@ -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;
}
}
@@ -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;
@@ -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();
}
@@ -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();
@@ -95,7 +95,9 @@ public class ASTDiffBuilder implements DiffTreeChangeBuilder<ASTNode, ASTNode> {
((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<ASTNode, ASTNode> {
((TreeElement)node).clearCaches();
((CompositeElement)oldParent).subtreeChanged();
DebugUtil.checkTreeStructure(oldParent);
if (DEBUG) {
DebugUtil.checkTreeStructure(oldParent);
}
}
public TreeChangeEventImpl getEvent() {
@@ -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
refactoring.extract.method.dialog.empty=Empty
@@ -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() + '\'';
}
}
}
@@ -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;
}
@@ -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();
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -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());
}
+1 -39
View File
@@ -25,45 +25,7 @@
<root url="jar://$MODULE_DIR$/lib/maven-2.2.0-uber.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-artifact-test/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-plugin-parameter-documenter/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-reporting/maven-reporting-api/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-script/maven-script-ant/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-model/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-core/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-plugin-registry/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-model/target/generated-sources/modello" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-plugin-api/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-repository-metadata/target/generated-sources/modello" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-plugin-descriptor/target/generated-sources/modello" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-plugin-parameter-documenter/target/generated-sources/modello" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-project/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-toolchain/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-script/maven-script-ant/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-artifact/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-profile/target/generated-sources/modello" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-project/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-profile/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-monitor/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-plugin-registry/target/generated-sources/modello" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-core/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-settings/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/apache-maven/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-settings/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-artifact/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-toolchain/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-toolchain/target/generated-sources/modello" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-settings/target/generated-sources/modello" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-plugin-descriptor/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-core-it-runner/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-script/maven-script-beanshell/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-plugin-descriptor/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-artifact-manager/src/test/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-compat/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-artifact-manager/src/main/java" />
<root url="file://$MODULE_DIR$/../../../../maven/maven-2.2/components/maven-error-diagnostics/src/main/java" />
</SOURCES>
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
@@ -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<Artifact>() {
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<ArtifactRepository> 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<ArtifactRepository> convertRepositories(List<MavenRemoteRepository> repositories) {
List<ArtifactRepository> result = new ArrayList<ArtifactRepository>();
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<Boolean>() {
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<ComponentDependency>)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);
@@ -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,
@@ -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;
@@ -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;
}
@@ -448,6 +448,15 @@ public class MavenProject {
getActiveProfilesIds(),
locator);
MavenProjectChanges changes = set(result, false, result.readingProblems.isEmpty(), false);
List<MavenImporter> 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;
}
@@ -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<Pair<String, MavenProfileState>> getProfilesWithStates() {
Collection<Pair<String,MavenProfileState>> result = new ArrayListSet<Pair<String,MavenProfileState>>();
Collection<Pair<String, MavenProfileState>> result = new ArrayListSet<Pair<String, MavenProfileState>>();
Pair<Collection<String>, Collection<String>> profiles = getAvailableAndActiveProfiles(true, true);
Collection<String> 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<Boolean, MavenProjectChanges> resolveResult = mavenProject.resolveFolders(embedder,
generalSettings,
importingSettings,
new MavenProjectReader(),
console);
if (resolveResult.first) {
fireFoldersResolved(Pair.create(mavenProject, resolveResult.second), message);
}
}
});
Pair<Boolean, MavenProjectChanges> 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);
@@ -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";
@@ -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();
@@ -236,7 +236,6 @@ public abstract class MavenTestCase extends UsefulTestCase {
"<mirrors>" +
" <mirror>" +
" <id>Nexus</id>" +
" <name>Nexus Public Mirror</name>" +
" <url>" + mirror + "</url>" +
" <mirrorOf>*</mirrorOf>" +
" </mirror>" +
@@ -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 {
" <dependency>" +
" <groupId>com.adobe.flex.framework</groupId>" +
" <artifactId>framework</artifactId>" +
" <version>3.2.0.3959</version>" +
" <version>3.2.0.3958</version>" +
" <type>resource-bundle</type>" +
" <classifier>en_US</classifier>" +
" </dependency>" +
@@ -138,6 +143,7 @@ public class MavenEmbedderWrapperTest extends MavenImportingTestCase {
" <plugin>" +
" <groupId>org.sonatype.flexmojos</groupId>" +
" <artifactId>flexmojos-maven-plugin</artifactId>" +
" <version>3.5.0</version>" +
" <extensions>true</extensions>" +
" </plugin>" +
" </plugins>" +
@@ -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.<String>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");
@@ -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;
}
}