Search in sources :

Example 1 with MavenId

use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.

the class MavenProjectModelModifier method addModuleDependency.

@Nullable
@Override
public Promise<Void> addModuleDependency(@NotNull Module from, @NotNull Module to, @NotNull final DependencyScope scope) {
    final MavenProject toProject = myProjectsManager.findProject(to);
    if (toProject == null)
        return null;
    MavenId mavenId = toProject.getMavenId();
    return addDependency(Collections.singletonList(from), mavenId, scope);
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with MavenId

use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.

the class MavenPropertyPsiReference method collectVariants.

protected void collectVariants(final List<Object> result, Set<String> variants) {
    int prefixLength = 0;
    if (myText.startsWith("pom.")) {
        prefixLength = "pom.".length();
    } else if (myText.startsWith("project.")) {
        prefixLength = "project.".length();
    }
    MavenProject mavenProject = myMavenProject;
    while (myText.startsWith("parent.", prefixLength)) {
        MavenId parentId = mavenProject.getParentId();
        if (parentId == null)
            return;
        mavenProject = myProjectsManager.findProject(parentId);
        if (mavenProject == null)
            return;
        prefixLength += "parent.".length();
    }
    final String prefix = prefixLength == 0 ? null : myText.substring(0, prefixLength);
    PsiDirectory baseDir = getBaseDir(mavenProject);
    addVariant(result, "basedir", baseDir, prefix, MavenIcons.MavenLogo);
    if (prefix == null) {
        result.add(createLookupElement(baseDir, "project.baseUri", MavenIcons.MavenLogo));
        result.add(createLookupElement(baseDir, "pom.baseUri", MavenIcons.MavenLogo));
        result.add(LookupElementBuilder.create(TIMESTAMP_PROP).withIcon(MavenIcons.MavenLogo));
    }
    processSchema(MavenSchemaProvider.MAVEN_PROJECT_SCHEMA_URL, new SchemaProcessor<Object>() {

        @Override
        public Object process(@NotNull String property, XmlElementDescriptor descriptor) {
            if (property.startsWith("project.")) {
                addVariant(result, property.substring("project.".length()), descriptor, prefix, MavenIcons.MavenLogo);
            }
            return null;
        }
    });
    processSchema(MavenSchemaProvider.MAVEN_SETTINGS_SCHEMA_URL, new SchemaProcessor<Object>() {

        @Override
        public Object process(@NotNull String property, XmlElementDescriptor descriptor) {
            result.add(createLookupElement(descriptor, property, MavenIcons.MavenLogo));
            return null;
        }
    });
    collectPropertiesVariants(result, variants);
    collectSystemEnvProperties(MavenPropertiesVirtualFileSystem.SYSTEM_PROPERTIES_FILE, null, result, variants);
    collectSystemEnvProperties(MavenPropertiesVirtualFileSystem.ENV_PROPERTIES_FILE, "env.", result, variants);
    MavenRunnerSettings runnerSettings = MavenRunner.getInstance(myProject).getSettings();
    for (String prop : runnerSettings.getMavenProperties().keySet()) {
        if (variants.add(prefix)) {
            result.add(LookupElementBuilder.create(prop).withIcon(PlatformIcons.PROPERTY_ICON));
        }
    }
    for (String prop : MavenUtil.getPropertiesFromMavenOpts().keySet()) {
        if (variants.add(prop)) {
            result.add(LookupElementBuilder.create(prop).withIcon(PlatformIcons.PROPERTY_ICON));
        }
    }
    for (Object key : myMavenProject.getProperties().keySet()) {
        if (key instanceof String) {
            String property = (String) key;
            if (variants.add(property)) {
                result.add(LookupElementBuilder.create(property).withIcon(PlatformIcons.PROPERTY_ICON));
            }
        }
    }
    MavenDomConfiguration pluginCfg = DomUtil.findDomElement(myElement, MavenDomConfiguration.class);
    if (pluginCfg != null) {
        MavenPluginDescriptor.processDescriptors(descriptor -> {
            if (descriptor.properties != null) {
                for (MavenPluginDescriptor.ModelProperty property : descriptor.properties) {
                    if (property.insideConfigurationOnly) {
                        result.add(LookupElementBuilder.create(property.name).withIcon(PlatformIcons.PROPERTY_ICON));
                    }
                }
            }
            return true;
        }, pluginCfg);
    }
}
Also used : MavenRunnerSettings(org.jetbrains.idea.maven.execution.MavenRunnerSettings) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenDomConfiguration(org.jetbrains.idea.maven.dom.model.MavenDomConfiguration) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenPluginDescriptor(org.jetbrains.idea.maven.plugins.api.MavenPluginDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 3 with MavenId

use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.

the class MavenDomProjectProcessorUtils method findParent.

@Nullable
public static MavenDomProjectModel findParent(@NotNull MavenDomParent mavenDomParent, Project project) {
    if (!DomUtil.hasXml(mavenDomParent))
        return null;
    MavenId id = new MavenId(mavenDomParent.getGroupId().getStringValue(), mavenDomParent.getArtifactId().getStringValue(), mavenDomParent.getVersion().getStringValue());
    MavenProject mavenProject = MavenProjectsManager.getInstance(project).findProject(id);
    return mavenProject != null ? MavenDomUtil.getMavenDomProjectModel(project, mavenProject.getFile()) : null;
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with MavenId

use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.

the class MavenDomUtil method updateMavenParent.

public static MavenDomParent updateMavenParent(MavenDomProjectModel mavenModel, MavenProject parentProject) {
    MavenDomParent result = mavenModel.getMavenParent();
    VirtualFile pomFile = DomUtil.getFile(mavenModel).getVirtualFile();
    Project project = mavenModel.getXmlElement().getProject();
    MavenId parentId = parentProject.getMavenId();
    result.getGroupId().setStringValue(parentId.getGroupId());
    result.getArtifactId().setStringValue(parentId.getArtifactId());
    result.getVersion().setStringValue(parentId.getVersion());
    if (!Comparing.equal(pomFile.getParent().getParent(), parentProject.getDirectoryFile())) {
        result.getRelativePath().setValue(PsiManager.getInstance(project).findFile(parentProject.getFile()));
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenId(org.jetbrains.idea.maven.model.MavenId)

Example 5 with MavenId

use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.

the class MavenArtifactCoordinatesConverter method getVariants.

@NotNull
public Collection<String> getVariants(ConvertContext context) {
    MavenProjectIndicesManager manager = MavenProjectIndicesManager.getInstance(context.getProject());
    MavenId id = MavenArtifactCoordinatesHelper.getId(context);
    MavenDomShortArtifactCoordinates coordinates = MavenArtifactCoordinatesHelper.getCoordinates(context);
    return selectStrategy(context).getVariants(id, manager, coordinates);
}
Also used : MavenProjectIndicesManager(org.jetbrains.idea.maven.indices.MavenProjectIndicesManager) MavenId(org.jetbrains.idea.maven.model.MavenId) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MavenId (org.jetbrains.idea.maven.model.MavenId)59 MavenProject (org.jetbrains.idea.maven.project.MavenProject)16 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Module (com.intellij.openapi.module.Module)5 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)5 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)4 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 RemoteException (java.rmi.RemoteException)4 ArchetypeDataSourceException (org.apache.maven.archetype.source.ArchetypeDataSourceException)4 SoutMavenConsole (org.jetbrains.idea.maven.execution.SoutMavenConsole)4 MavenArtifact (org.jetbrains.idea.maven.model.MavenArtifact)4 MavenServerExecutionResult (org.jetbrains.idea.maven.server.MavenServerExecutionResult)4 Project (com.intellij.openapi.project.Project)3 File (java.io.File)3 MavenArchetype (org.jetbrains.idea.maven.model.MavenArchetype)3 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2