maven alt-insert in pom.xml

This commit is contained in:
sergey.vasiliev
2010-02-11 13:30:53 +03:00
parent 413186de09
commit ee9de51471
20 changed files with 856 additions and 27 deletions
@@ -26,6 +26,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.util.ArrayUtil;
import com.intellij.util.xml.ConvertContext;
import com.intellij.util.xml.DomUtil;
import com.intellij.util.xml.ResolvingConverter;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NonNls;
@@ -64,7 +65,10 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert
public Collection<String> getVariants(ConvertContext context) {
MavenProjectIndicesManager manager = MavenProjectIndicesManager.getInstance(getProject(context));
MavenId id = MavenArtifactCoordinatesHelper.getId(context);
return selectStrategy(context).getVariants(id, manager);
MavenDomShortArtifactCoordinates coordinates = MavenArtifactCoordinatesHelper.getCoordinates(context);
return selectStrategy(context).getVariants(id, manager, coordinates);
}
protected abstract Set<String> doGetVariants(MavenId id, MavenProjectIndicesManager manager);
@@ -147,7 +151,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert
return doIsValid(id, manager, context) || resolveBySpecifiedPath() != null;
}
public Set<String> getVariants(MavenId id, MavenProjectIndicesManager manager) {
public Set<String> getVariants(MavenId id, MavenProjectIndicesManager manager, MavenDomShortArtifactCoordinates coordinates) {
return doGetVariants(id, manager);
}
@@ -240,6 +244,20 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert
public PsiFile resolveBySpecifiedPath() {
return myDependency.getSystemPath().getValue();
}
@Override
public Set<String> getVariants(MavenId id, MavenProjectIndicesManager manager, MavenDomShortArtifactCoordinates coordinates) {
if (StringUtil.isEmpty(id.getGroupId())) {
Set<String> result = new THashSet<String>();
if (DomUtil.hasXml(coordinates.getGroupId())) {
for (String each : manager.getGroupIds()) {
id = new MavenId(each, id.getArtifactId(), id.getVersion());
result.addAll(super.getVariants(id, manager, coordinates));
} }
return result;
}
return super.getVariants(id, manager, coordinates);
}
}
private class ExclusionStrategy extends ConverterStrategy {
@@ -278,16 +296,25 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert
}
@Override
public Set<String> getVariants(MavenId id, MavenProjectIndicesManager manager) {
public Set<String> getVariants(MavenId id, MavenProjectIndicesManager manager, MavenDomShortArtifactCoordinates coordinates) {
if (StringUtil.isEmpty(id.getGroupId())) {
Set<String> result = new THashSet<String>();
for (String each : MavenArtifactUtil.DEFAULT_GROUPS) {
for (String each : getGroupIdVariants(manager, coordinates)) {
id = new MavenId(each, id.getArtifactId(), id.getVersion());
result.addAll(super.getVariants(id, manager));
result.addAll(super.getVariants(id, manager, coordinates));
}
return result;
}
return super.getVariants(id, manager);
return super.getVariants(id, manager, coordinates);
}
private String[] getGroupIdVariants(MavenProjectIndicesManager manager, MavenDomShortArtifactCoordinates coordinates) {
if (DomUtil.hasXml(coordinates.getGroupId())) {
Set<String> strings = manager.getGroupIds();
return strings.toArray(new String[strings.size()]);
}
return MavenArtifactUtil.DEFAULT_GROUPS;
}
@Override
@@ -1,25 +1,15 @@
/*
* Copyright 2000-2009 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 org.jetbrains.idea.maven.dom.converters;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.hash.HashSet;
import com.intellij.util.xml.ConvertContext;
import com.intellij.util.xml.impl.ConvertContextImpl;
import org.jetbrains.idea.maven.dom.model.MavenDomShortArtifactCoordinates;
import org.jetbrains.idea.maven.indices.MavenProjectIndicesManager;
import org.jetbrains.idea.maven.project.MavenId;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
public class MavenArtifactCoordinatesGroupIdConverter extends MavenArtifactCoordinatesConverter {
@@ -33,4 +23,18 @@ public class MavenArtifactCoordinatesGroupIdConverter extends MavenArtifactCoord
protected Set<String> doGetVariants(MavenId id, MavenProjectIndicesManager manager) {
return manager.getGroupIds();
}
public Collection<String> getSmartVariants(ConvertContext convertContext) {
Set<String> groupIds = new HashSet<String>();
String artifactId = MavenArtifactCoordinatesHelper.getId(convertContext).getArtifactId();
if (!StringUtil.isEmptyOrSpaces(artifactId)) {
MavenProjectIndicesManager manager = MavenProjectIndicesManager.getInstance(convertContext.getFile().getProject());
for (String grouipId : manager.getGroupIds()) {
if (manager.getArtifactIds(grouipId).contains(artifactId)) {
groupIds.add(grouipId);
}
}
}
return groupIds;
}
}
@@ -16,14 +16,19 @@
package org.jetbrains.idea.maven.dom.converters;
import com.intellij.util.xml.ConvertContext;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.dom.model.MavenDomArtifactCoordinates;
import org.jetbrains.idea.maven.dom.model.MavenDomShortArtifactCoordinates;
import org.jetbrains.idea.maven.project.MavenId;
public class MavenArtifactCoordinatesHelper {
public static MavenId getId(ConvertContext context) {
MavenDomShortArtifactCoordinates coords = (MavenDomShortArtifactCoordinates)context.getInvocationElement().getParent();
return getId(coords);
return getId(getCoordinates(context));
}
@Nullable
public static MavenDomShortArtifactCoordinates getCoordinates(ConvertContext context) {
return (MavenDomShortArtifactCoordinates)context.getInvocationElement().getParent();
}
public static MavenId getId(MavenDomShortArtifactCoordinates coords) {
@@ -0,0 +1,75 @@
/*
* 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 org.jetbrains.idea.maven.dom.converters.repositories;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.util.containers.HashMap;
import com.intellij.util.xmlb.XmlSerializer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.dom.converters.repositories.beans.RepositoriesBean;
import org.jetbrains.idea.maven.dom.converters.repositories.beans.RepositoryBeanInfo;
import java.util.Map;
import java.util.Set;
/**
* @author Serega.Vasiliev
*/
public class MavenRepositoriesProvider {
public static MavenRepositoriesProvider getInstance() {
return ServiceManager.getService(MavenRepositoriesProvider.class);
}
Map<String, Pair<String, String>> myRepositoriesMap = new HashMap<String, Pair<String, String>>();
public MavenRepositoriesProvider() {
final RepositoriesBean repositoriesBean =
XmlSerializer.deserialize(MavenRepositoriesProvider.class.getResource("repositories.xml"), RepositoriesBean.class);
assert repositoriesBean != null;
RepositoryBeanInfo[] repositories = repositoriesBean.getRepositories();
assert repositories != null;
for (RepositoryBeanInfo repository : repositories) {
registerRepository(repository.getId(), repository.getName(), repository.getUrl());
}
}
public void registerRepository(@NotNull String id, @NotNull String name, @NotNull String url) {
myRepositoriesMap.put(id, Pair.create(name, url));
}
@NotNull
public Set<String> getRepositoryIds() {
return myRepositoriesMap.keySet();
}
@Nullable
public String getRepositoryName(@Nullable String id) {
Pair<String, String> pair = myRepositoriesMap.get(id);
return pair != null ? pair.getFirst() : null;
}
@Nullable
public String getRepositoryUrl(@Nullable String id) {
Pair<String, String> pair = myRepositoriesMap.get(id);
return pair != null ? pair.getSecond() : null;
}
}
@@ -0,0 +1,119 @@
/*
* 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 org.jetbrains.idea.maven.dom.converters.repositories;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementFactory;
import com.intellij.codeInsight.lookup.MutableLookupElement;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.ElementManipulators;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.util.xml.ConvertContext;
import com.intellij.util.xml.GenericDomValue;
import com.intellij.util.xml.ResolvingConverter;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.dom.converters.MavenUrlConverter;
import org.jetbrains.idea.maven.dom.model.MavenDomRepositoryBase;
import org.jetbrains.idea.maven.dom.references.MavenUrlPsiReference;
import org.jetbrains.idea.maven.utils.MavenIcons;
import java.util.Collection;
import java.util.Collections;
/**
* @author Serega.Vasiliev
*/
public abstract class MavenRepositoryConverter extends ResolvingConverter<String> {
public static class Id extends MavenRepositoryConverter {
@NotNull
public Collection<String> getVariants(final ConvertContext context) {
Module module = context.getModule();
if (module != null) {
return MavenRepositoriesProvider.getInstance().getRepositoryIds();
}
return Collections.emptySet();
}
@Override
public LookupElement createLookupElement(String s) {
MutableLookupElement<String> element = LookupElementFactory.getInstance().createLookupElement(s, s)
.setIcon(MavenIcons.REPOSITORY_ICON)
.setTailText(" (" + MavenRepositoriesProvider.getInstance().getRepositoryUrl(s) + ")", true);
return element;
}
}
public static class Name extends MavenRepositoryConverter {
@NotNull
public Collection<String> getVariants(final ConvertContext context) {
Module module = context.getModule();
if (module != null) {
String name = MavenRepositoriesProvider.getInstance().getRepositoryName(getRepositoryId(context));
if (!StringUtil.isEmptyOrSpaces(name)) return Collections.singleton(name);
}
return Collections.emptySet();
}
}
public static class Url extends MavenUrlConverter {
@NotNull
@Override
public PsiReference[] createReferences(GenericDomValue value, final PsiElement element, final ConvertContext context) {
String text = value.getStringValue();
TextRange range = ElementManipulators.getValueTextRange(element);
return new PsiReference[]{new MavenUrlPsiReference(element, text, range) {
@NotNull
@Override
public Object[] getVariants() {
Module module = context.getModule();
if (module != null) {
String name = MavenRepositoriesProvider.getInstance().getRepositoryUrl(getRepositoryId(context));
if (!StringUtil.isEmptyOrSpaces(name)) return new Object[]{name};
}
return super.getVariants();
}
}};
}
}
@Nullable
private static String getRepositoryId(ConvertContext context) {
MavenDomRepositoryBase repository = context.getInvocationElement().getParentOfType(MavenDomRepositoryBase.class, false);
if (repository != null) return repository.getId().getStringValue();
return null;
}
public String fromString(@Nullable @NonNls final String s, final ConvertContext context) {
return s;
}
@Override
public String toString(@Nullable String s, ConvertContext convertContext) {
return s;
}
}
@@ -0,0 +1,30 @@
/*
* 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 org.jetbrains.idea.maven.dom.converters.repositories.beans;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Tag;
public class RepositoriesBean {
@Tag("repositories")
@AbstractCollection(surroundWithTag = false)
public RepositoryBeanInfo[] myRepositories;
public RepositoryBeanInfo[] getRepositories() {
return myRepositories;
}
}
@@ -0,0 +1,46 @@
/*
* 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 org.jetbrains.idea.maven.dom.converters.repositories.beans;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
/**
* @author Serega.Vasiliev
*/
@Tag("repository")
public class RepositoryBeanInfo {
@Attribute("id")
public String myId;
@Attribute("name")
public String myName;
@Attribute("url")
public String myUrl;
public String getId() {
return myId;
}
public String getName() {
return myName;
}
public String getUrl() {
return myUrl;
}
}
@@ -0,0 +1,15 @@
<root>
<repositories>
<repository id="central" name="Maven Central" url="http://repo1.maven.org/maven2/"/>
<repository id="codehaus" name="Сodehaus" url="http://repository.codehaus.org"/>
<repository id="glassfish-repo-archive" name="Nexus repository collection for Glassfish" url="http://maven.glassfish.org/content/groups/glassfish"/>
<repository id="ibiblio.mirrors" name="ibiblio.mirrors" url="http://mirrors.ibiblio.org/pub/mirrors/maven2"/>
<repository id="java.net.m2" name="java.net m2 repo" url="http://download.java.net/maven/2"/>
<repository id="java.net2" name="Java.net" url="http://download.java.net/maven/2/"/>
<repository id="jboss-maven2-release-repository" name="JBoss" url="http://repository.jboss.org/maven2/"/>
<repository id="Open.iona.com Releases" name="FUSE" url="http://repo.open.iona.com/maven2/"/>
<repository id="terracotta" name="Terracotta" url="http://download.terracotta.org/maven2/"/>
<repository id="sonatype" name="Sonatype" url="http://repository.sonatype.org/content/groups/public/ "/>
</repositories>
</root>
@@ -0,0 +1,46 @@
package org.jetbrains.idea.maven.dom.generate;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.Function;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.ElementPresentationManager;
import com.intellij.util.xml.TypeNameManager;
import com.intellij.util.xml.ui.actions.generate.GenerateDomElementAction;
import com.intellij.util.xml.ui.actions.generate.GenerateDomElementProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.dom.MavenDomUtil;
import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel;
/**
* User: Sergey.Vasiliev
*/
public class MavenCodeInsightGenerateAction extends GenerateDomElementAction {
public MavenCodeInsightGenerateAction(@NotNull Class<? extends DomElement> childElementClass,
@Nullable final String mappingId,
@NotNull Function<MavenDomProjectModel, DomElement> parentFunction) {
this(TypeNameManager.getTypeName(childElementClass), childElementClass, mappingId, parentFunction);
}
public MavenCodeInsightGenerateAction(@NotNull final String description,
@NotNull final Class<? extends DomElement> childElementClass,
@Nullable final String mappingId,
@NotNull Function<MavenDomProjectModel, DomElement> parentFunction) {
super(new MavenGenerateDomElementProvider(description, childElementClass, mappingId, parentFunction));
getTemplatePresentation().setIcon(ElementPresentationManager.getIconForClass(childElementClass));
}
public MavenCodeInsightGenerateAction(final GenerateDomElementProvider generateProvider) {
super(generateProvider);
}
protected boolean isValidForFile(Project project, Editor editor, PsiFile file) {
return file instanceof XmlFile && MavenDomUtil.getMavenDomModel(file, MavenDomProjectModel.class) != null;
}
}
@@ -0,0 +1,75 @@
/*
* 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 org.jetbrains.idea.maven.dom.generate;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.util.Function;
import com.intellij.util.xml.DomElement;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.dom.MavenDomBundle;
import org.jetbrains.idea.maven.dom.model.MavenDomDependency;
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin;
import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel;
import org.jetbrains.idea.maven.dom.model.MavenDomRepository;
/**
* User: Sergey.Vasiliev
*/
public class MavenGenerateDomActionGroup extends DefaultActionGroup {
public MavenGenerateDomActionGroup() {
// generate dependencies
final Function<MavenDomProjectModel, DomElement> dependenciesFunction = new Function<MavenDomProjectModel, DomElement>() {
public DomElement fun(MavenDomProjectModel mavenDomProjectModel) {
return mavenDomProjectModel.getDependencies();
}
};
add(createAction(MavenDomBundle.message("generate.dependency.artifact"), MavenDomDependency.class, "maven-dependency-artifact", dependenciesFunction));
add(createAction(MavenDomBundle.message("generate.dependency.group"), MavenDomDependency.class, "maven-dependency", dependenciesFunction));
// generate plugins
Function<MavenDomProjectModel, DomElement> pluginFunction = new Function<MavenDomProjectModel, DomElement>() {
public DomElement fun(MavenDomProjectModel mavenDomProjectModel) {
return mavenDomProjectModel.getBuild().getPlugins();
}
};
add(createAction(MavenDomBundle.message("generate.plugin.artifact"), MavenDomPlugin.class, "maven-plugin-artifact-first", pluginFunction));
add(createAction(MavenDomBundle.message("generate.plugin.group"), MavenDomPlugin.class, "maven-plugin", pluginFunction));
// generate repository
add(createAction(MavenDomRepository.class, "maven-repository", new Function<MavenDomProjectModel, DomElement>() {
public DomElement fun(MavenDomProjectModel mavenDomProjectModel) {
return mavenDomProjectModel.getRepositories();
}
}));
}
private static MavenCodeInsightGenerateAction createAction(String actionDescription,
final Class<? extends DomElement> aClass,
@NonNls @Nullable String mappingId,
@NotNull Function<MavenDomProjectModel, DomElement> parentFunction) {
return new MavenCodeInsightGenerateAction(actionDescription, aClass, mappingId, parentFunction);
}
protected static AnAction createAction(final Class<? extends DomElement> aClass,
@NonNls @Nullable String mappingId,
@NotNull Function<MavenDomProjectModel, DomElement> parentFunction) {
return new MavenCodeInsightGenerateAction(aClass, mappingId, parentFunction);
}
}
@@ -0,0 +1,43 @@
/*
* 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 org.jetbrains.idea.maven.dom.generate;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.util.Function;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.actions.generate.AbstractDomGenerateProvider;
import org.jetbrains.idea.maven.dom.MavenDomUtil;
import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel;
/**
* User: Sergey.Vasiliev
*/
public class MavenGenerateDomElementProvider extends AbstractDomGenerateProvider{
private final Function<MavenDomProjectModel, DomElement> myParentFunction;
public MavenGenerateDomElementProvider(final String description, final Class<? extends DomElement> childElementClass, String mappingId, Function<MavenDomProjectModel, DomElement> parentFunction) {
super(description, childElementClass, mappingId);
myParentFunction = parentFunction;
}
protected DomElement getParentDomElement(final Project project, final Editor editor, final PsiFile file) {
MavenDomProjectModel domProjectModel = MavenDomUtil.getMavenDomModel(file, MavenDomProjectModel.class);
return domProjectModel == null ? null : myParentFunction.fun(domProjectModel);
}
}
@@ -26,17 +26,20 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.dom.MavenDomElement;
import org.jetbrains.idea.maven.dom.converters.MavenRepositoryLayoutConverter;
import org.jetbrains.idea.maven.dom.converters.MavenUrlConverter;
import org.jetbrains.idea.maven.dom.converters.repositories.MavenRepositoryConverter;
public interface MavenDomRepositoryBase extends MavenDomElement {
@NotNull
@Required
@Convert(MavenRepositoryConverter.Id.class)
GenericDomValue<String> getId();
@NotNull
@Convert(MavenRepositoryConverter.Name.class)
GenericDomValue<String> getName();
@NotNull
@Convert(MavenUrlConverter.class)
@Convert(MavenRepositoryConverter.Url.class)
GenericDomValue<String> getUrl();
@NotNull
@@ -0,0 +1,87 @@
/*
* 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 org.jetbrains.idea.maven.dom.model.completion;
import com.intellij.codeInsight.completion.CompletionContributor;
import com.intellij.codeInsight.completion.CompletionParameters;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.xml.XmlText;
import com.intellij.psi.xml.XmlToken;
import com.intellij.util.xml.Converter;
import com.intellij.util.xml.impl.GenericDomValueReference;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.dom.converters.MavenArtifactCoordinatesGroupIdConverter;
import java.util.Collection;
public class MavenGroupIdSmartCompletionContributor extends CompletionContributor {
@Override
public void fillCompletionVariants(final CompletionParameters parameters, final CompletionResultSet result) {
if (parameters.getCompletionType() != CompletionType.SMART) {
return;
}
ApplicationManager.getApplication().runReadAction(new Runnable() {
public void run() {
final GenericDomValueReference reference = getReference(parameters);
if (reference == null) {
return;
}
Collection<String> variants =
((MavenArtifactCoordinatesGroupIdConverter)reference.getConverter()).getSmartVariants(reference.getConvertContext());
for (String variant : variants) {
if (!StringUtil.isEmptyOrSpaces(variant)) {
result.addElement(LookupElementBuilder.create(variant));
}
}
}
});
}
@Nullable
private GenericDomValueReference getReference(CompletionParameters parameters) {
if (!(parameters.getPosition() instanceof XmlToken)) return null;
PsiReference[] references = getReferences(parameters);
for (final PsiReference psiReference : references) {
if (psiReference instanceof GenericDomValueReference) {
final Converter converter = ((GenericDomValueReference)psiReference).getConverter();
if (converter instanceof MavenArtifactCoordinatesGroupIdConverter) {
return (GenericDomValueReference)psiReference;
}
}
}
return null;
}
private static PsiReference[] getReferences(CompletionParameters parameters) {
PsiElement psiElement = parameters.getPosition().getParent();
return psiElement instanceof XmlText ? psiElement.getParent().getReferences() : psiElement.getReferences();
}
}
@@ -19,6 +19,7 @@ import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.FakePsiElement;
import org.jetbrains.annotations.NotNull;
public class MavenUrlPsiReference extends MavenPsiReference {
public MavenUrlPsiReference(PsiElement element, String text, TextRange range) {
@@ -43,6 +44,7 @@ public class MavenUrlPsiReference extends MavenPsiReference {
};
}
@NotNull
public Object[] getVariants() {
return EMPTY_ARRAY;
}
@@ -0,0 +1,82 @@
/*
* 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 org.jetbrains.idea.maven.utils;
import com.intellij.codeInsight.template.impl.TemplateSettings;
import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathMacros;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.util.xml.ElementPresentationManager;
import com.intellij.util.xml.TypeNameManager;
import org.jdom.Document;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.dom.MavenDomBundle;
import org.jetbrains.idea.maven.dom.model.MavenDomDependency;
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin;
import org.jetbrains.idea.maven.dom.model.MavenDomRepository;
import org.jetbrains.idea.maven.embedder.MavenEmbedderFactory;
import java.io.File;
public class MavenDomApplicationComponent implements ApplicationComponent {
private static final Logger LOG = Logger.getInstance(MavenDomApplicationComponent.class.getName());
@NonNls private static final String LIVE_TEMPLATES_DIR = "/liveTemplates/";
@NonNls private static final String[] LIVE_TEMPLATES_FILES = {"maven_generate_dom.xml"};
@NotNull
public String getComponentName() {
return MavenDomApplicationComponent.class.getName();
}
public void initComponent() {
registerLiveTemplates();
registerPresentations();
}
private static void registerPresentations() {
TypeNameManager.registerTypeName(MavenDomRepository.class, MavenDomBundle.message("maven.repository"));
TypeNameManager.registerTypeName(MavenDomPlugin.class, MavenDomBundle.message("maven.plugin"));
TypeNameManager.registerTypeName(MavenDomDependency.class, MavenDomBundle.message("maven.dependency"));
ElementPresentationManager.registerIcon(MavenDomRepository.class, MavenIcons.PLUGIN_ICON);
ElementPresentationManager.registerIcon(MavenDomDependency.class, MavenIcons.DEPENDENCY_ICON);
ElementPresentationManager.registerIcon(MavenDomPlugin.class, MavenIcons.PLUGIN_ICON);
}
private static void registerLiveTemplates() {
final TemplateSettings settings = TemplateSettings.getInstance();
for (String templatesFile : LIVE_TEMPLATES_FILES) {
try {
final Document document =
JDOMUtil.loadDocument(MavenDomApplicationComponent.class.getResourceAsStream(LIVE_TEMPLATES_DIR + templatesFile));
settings.readHiddenTemplateFile(document);
}
catch (Exception e) {
LOG.error("Can't load " + templatesFile, e);
}
}
}
public void disposeComponent() {
}
}
@@ -30,6 +30,7 @@ public class MavenIcons {
public static final Icon OPEN_PLUGINS_ICON = IconLoader.getIcon("/images/phasesOpen.png");
public static final Icon CLOSED_PLUGINS_ICON = IconLoader.getIcon("/images/phasesClosed.png");
public static final Icon PLUGIN_ICON = IconLoader.getIcon("/images/mavenPlugin.png");
public static final Icon REPOSITORY_ICON = IconLoader.getIcon("/images/mavenPlugin.png");
public static final Icon PLUGIN_GOAL_ICON = IconLoader.getIcon("/images/pluginGoal.png");
public static final Icon OPEN_DEPENDENCIES_ICON = IconLoader.getIcon("/nodes/ppLibOpen.png");
public static final Icon CLOSED_DEPENDENCIES_ICON = IconLoader.getIcon("/nodes/ppLibClosed.png");
@@ -6,3 +6,13 @@ fix.update.indices=Update Maven Indices
fix.parent.path=Fix relative path
fix.open.file=Open ''{0}''
intention.choose.file=Choose File
maven.repository=Repository
maven.dependency=Dependency
maven.plugin=Plugin
generate.dependency.artifact=Dependency (artifact)
generate.dependency.group=Dependency (group)
generate.plugin.artifact=Plugin (artifact)
generate.plugin.group=Plugin (group)
@@ -44,8 +44,10 @@
<dom.fileDescription implementation="org.jetbrains.idea.maven.dom.MavenDomSettingsModelDescription"/>
<dom.fileDescription implementation="org.jetbrains.idea.maven.dom.MavenDomPluginModelDescription"/>
<lang.documentationProvider language="XML" implementationClass="org.jetbrains.idea.maven.dom.MavenModelDocumentationProvider" order="first"/>
<lang.documentationProvider language="XML" implementationClass="org.jetbrains.idea.maven.dom.MavenPluginModelDocumentationProvider" order="first"/>
<lang.documentationProvider language="XML" implementationClass="org.jetbrains.idea.maven.dom.MavenModelDocumentationProvider"
order="first"/>
<lang.documentationProvider language="XML" implementationClass="org.jetbrains.idea.maven.dom.MavenPluginModelDocumentationProvider"
order="first"/>
<elementDescriptionProvider implementation="org.jetbrains.idea.maven.dom.MavenModelDocumentationProvider" order="first"/>
<inspectionToolProvider implementation="org.jetbrains.idea.maven.dom.MavenModelInspection"/>
@@ -54,7 +56,8 @@
<dom.extender domClass="org.jetbrains.idea.maven.dom.model.MavenDomConfigurationParameter"
extenderClass="org.jetbrains.idea.maven.dom.MavenPluginConfigurationParameterDomExtender"/>
<completion.contributor language="any" implementationClass="org.jetbrains.idea.maven.dom.references.MavenPropertyCompletionContributor" id="Maven"/>
<completion.contributor language="any" implementationClass="org.jetbrains.idea.maven.dom.references.MavenPropertyCompletionContributor"
id="Maven"/>
<psi.referenceContributor implementation="org.jetbrains.idea.maven.dom.references.MavenPropertyPsiReferenceContributor"/>
<usageTargetProvider implementation="org.jetbrains.idea.maven.dom.references.MavenUsageTargetProvider"/>
@@ -67,6 +70,9 @@
<projectService serviceInterface="org.jetbrains.idea.maven.dom.MavenDomElementDescriptorHolder"
serviceImplementation="org.jetbrains.idea.maven.dom.MavenDomElementDescriptorHolder"/>
<applicationService serviceInterface="org.jetbrains.idea.maven.dom.converters.repositories.MavenRepositoriesProvider"
serviceImplementation="org.jetbrains.idea.maven.dom.converters.repositories.MavenRepositoriesProvider"/>
<typedHandler implementation="org.jetbrains.idea.maven.dom.code.MavenTypedHandlerDelegate"/>
<backspaceHandlerDelegate implementation="org.jetbrains.idea.maven.dom.code.MavenBackspaceHandlerDelegate"/>
@@ -80,6 +86,8 @@
<gotoFileContributor implementation="org.jetbrains.idea.maven.vfs.MavenGotoPropertyFileContibutor"/>
<gotoFileContributor implementation="org.jetbrains.idea.maven.utils.MavenGotoSettingsFileContibutor"/>
<fileTemplateGroup implementation="org.jetbrains.idea.maven.utils.MavenFileTemplateGroupFactory"/>
<completion.contributor language="XML" implementationClass="org.jetbrains.idea.maven.dom.model.completion.MavenGroupIdSmartCompletionContributor"/>
</extensions>
<application-components>
@@ -92,6 +100,9 @@
<component>
<implementation-class>org.jetbrains.idea.maven.vfs.MavenPropertiesVirtualFileSystem</implementation-class>
</component>
<component>
<implementation-class>org.jetbrains.idea.maven.utils.MavenDomApplicationComponent</implementation-class>
</component>
</application-components>
<project-components>
@@ -275,6 +286,10 @@
class="org.jetbrains.idea.maven.tasks.actions.AssignShortcutAction" text="Assign Shortcut..."
description="Assign shortcutto selected phase/goal">
</action>
<action id="Generate.Dom.Elements" class="org.jetbrains.idea.maven.dom.generate.MavenGenerateDomActionGroup" text="Generate">
<add-to-group anchor="last" group-id="GenerateGroup"/>
</action>
</group>
<group id="Maven.NavigatorToolbar" description="Maven Projects Navigator Toolbar">
Binary file not shown.

After

Width:  |  Height:  |  Size: 797 B

@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<templateSet group="maven">
<template id="maven-repository" name="mavenrepository"
value="&lt;repository&gt;&#10; &lt;id&gt;$ID$&lt;/id&gt;&#10; &lt;name&gt;$NAME$&lt;/name&gt;&#10; &lt;url&gt;$URL$&lt;/url&gt;&#10;&lt;/repository&gt;"
description="" toReformat="false" toShortenFQNames="true">
<variable name="ID" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<variable name="NAME" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<variable name="URL" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<context>
<option name="JAVA_CODE" value="false"/>
<option name="JAVA_COMMENT" value="false"/>
<option name="JAVA_STRING" value="false"/>
<option name="COMPLETION" value="false"/>
<option name="HTML" value="false"/>
<option name="XML" value="false"/>
<option name="JSP" value="false"/>
<option name="CSS" value="false"/>
<option name="SQL" value="false"/>
<option name="JAVA_SCRIPT" value="false"/>
<option name="GROOVY" value="false"/>
<option name="PHP" value="false"/>
<option name="RUBY" value="false"/>
<option name="RHTML" value="false"/>
<option name="CUCUMBER_FEATURE_FILE" value="false"/>
<option name="Python" value="false"/>
<option name="GSP" value="false"/>
<option name="OTHER" value="false"/>
</context>
</template>
<template id="maven-plugin-artifact-first" name="mavenpluginфкешафсе"
value="&lt;plugin&gt;&#10; &lt;groupId&gt;$GROUP$&lt;/groupId&gt;&#10; &lt;artifactId&gt;$ARTIFACT$&lt;/artifactId&gt;&#10; &lt;version&gt;$VERSION$&lt;/version&gt;&#10;&lt;/plugin&gt;"
description="" toReformat="false" toShortenFQNames="false">
<variable name="ARTIFACT" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<variable name="GROUP" expression="completeSmart()" defaultValue="" alwaysStopAt="true"/>
<variable name="VERSION" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<context>
<option name="JAVA_CODE" value="false"/>
<option name="JAVA_COMMENT" value="false"/>
<option name="JAVA_STRING" value="false"/>
<option name="COMPLETION" value="false"/>
<option name="HTML" value="false"/>
<option name="XML" value="false"/>
<option name="Python" value="false"/>
<option name="JSP" value="false"/>
<option name="CSS" value="false"/>
<option name="PHP" value="false"/>
<option name="GROOVY" value="false"/>
<option name="RUBY" value="false"/>
<option name="RHTML" value="false"/>
<option name="CUCUMBER_FEATURE_FILE" value="false"/>
<option name="SQL" value="false"/>
<option name="JAVA_SCRIPT" value="false"/>
<option name="GSP" value="false"/>
<option name="OTHER" value="false"/>
</context>
</template>
<template id="maven-plugin" name="mavenplugin"
value="&lt;plugin&gt;&#10; &lt;groupId&gt;$GROUP$&lt;/groupId&gt;&#10; &lt;artifactId&gt;$ARTIFACT$&lt;/artifactId&gt;&#10; &lt;version&gt;$VERSION$&lt;/version&gt;&#10;&lt;/plugin&gt;"
description="" toReformat="false" toShortenFQNames="false">
<variable name="GROUP" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<variable name="ARTIFACT" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<variable name="VERSION" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<context>
<option name="JAVA_CODE" value="false"/>
<option name="JAVA_COMMENT" value="false"/>
<option name="JAVA_STRING" value="false"/>
<option name="COMPLETION" value="false"/>
<option name="HTML" value="false"/>
<option name="XML" value="false"/>
<option name="Python" value="false"/>
<option name="JSP" value="false"/>
<option name="CSS" value="false"/>
<option name="PHP" value="false"/>
<option name="GROOVY" value="false"/>
<option name="RUBY" value="false"/>
<option name="RHTML" value="false"/>
<option name="CUCUMBER_FEATURE_FILE" value="false"/>
<option name="SQL" value="false"/>
<option name="JAVA_SCRIPT" value="false"/>
<option name="GSP" value="false"/>
<option name="OTHER" value="false"/>
</context>
</template>
<template id="maven-dependency" name="mavendependency"
value="&lt;dependency&gt;&#10; &lt;groupId&gt;$GROUP$&lt;/groupId&gt;&#10; &lt;artifactId&gt;$ARTIFACT$&lt;/artifactId&gt;&#10; &lt;version&gt;$VERSION$&lt;/version&gt;&#10;&lt;/dependency&gt;"
description="" toReformat="false" toShortenFQNames="false">
<variable name="GROUP" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<variable name="ARTIFACT" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<variable name="VERSION" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<context>
<option name="JAVA_CODE" value="false"/>
<option name="JAVA_COMMENT" value="false"/>
<option name="JAVA_STRING" value="false"/>
<option name="COMPLETION" value="false"/>
<option name="HTML" value="false"/>
<option name="XML" value="false"/>
<option name="Python" value="false"/>
<option name="JSP" value="false"/>
<option name="CSS" value="false"/>
<option name="PHP" value="false"/>
<option name="GROOVY" value="false"/>
<option name="RUBY" value="false"/>
<option name="RHTML" value="false"/>
<option name="CUCUMBER_FEATURE_FILE" value="false"/>
<option name="SQL" value="false"/>
<option name="JAVA_SCRIPT" value="false"/>
<option name="GSP" value="false"/>
<option name="OTHER" value="false"/>
</context>
</template>
<template id="maven-dependency-artifact" name="mavendependencyart"
value="&lt;dependency&gt;&#10; &lt;groupId&gt;$GROUP$&lt;/groupId&gt;&#10; &lt;artifactId&gt;$ARTIFACT$&lt;/artifactId&gt;&#10; &lt;version&gt;$VERSION$&lt;/version&gt;&#10;&lt;/dependency&gt;"
description="" toReformat="false" toShortenFQNames="false">
<variable name="ARTIFACT" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<variable name="GROUP" expression="completeSmart()" defaultValue="" alwaysStopAt="true"/>
<variable name="VERSION" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<context>
<option name="JAVA_CODE" value="false"/>
<option name="JAVA_COMMENT" value="false"/>
<option name="JAVA_STRING" value="false"/>
<option name="COMPLETION" value="false"/>
<option name="HTML" value="false"/>
<option name="XML" value="false"/>
<option name="Python" value="false"/>
<option name="JSP" value="false"/>
<option name="CSS" value="false"/>
<option name="PHP" value="false"/>
<option name="GROOVY" value="false"/>
<option name="RUBY" value="false"/>
<option name="RHTML" value="false"/>
<option name="CUCUMBER_FEATURE_FILE" value="false"/>
<option name="SQL" value="false"/>
<option name="JAVA_SCRIPT" value="false"/>
<option name="GSP" value="false"/>
<option name="OTHER" value="false"/>
</context>
</template>
</templateSet>