Search in sources :

Example 51 with MavenId

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

the class MavenModuleBuilderTest method testAddingParentWithInheritedProperties.

public void testAddingParentWithInheritedProperties() throws Exception {
    if (!hasMavenInstallation())
        return;
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>");
    setModuleNameAndRoot("module", getProjectPath() + "/module");
    setParentProject(myProjectPom);
    setInheritedOptions(true, true);
    createNewModule(new MavenId("org.foo", "module", "1.0"));
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" + "         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + "    <parent>\n" + "        <artifactId>project</artifactId>\n" + "        <groupId>test</groupId>\n" + "        <version>1</version>\n" + "    </parent>\n" + "    <modelVersion>4.0.0</modelVersion>\n" + "\n" + "    <artifactId>module</artifactId>\n" + "\n" + "\n" + "</project>", VfsUtil.loadText(myProjectRoot.findFileByRelativePath("module/pom.xml")));
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId)

Example 52 with MavenId

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

the class MavenModuleBuilderTest method testInheritJdkFromProject.

public void testInheritJdkFromProject() throws Exception {
    if (!hasMavenInstallation())
        return;
    createNewModule(new MavenId("org.foo", "module", "1.0"));
    ModuleRootManager manager = ModuleRootManager.getInstance(getModule("module"));
    assertTrue(manager.isSdkInherited());
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager)

Example 53 with MavenId

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

the class MavenModuleBuilderTest method testAddingManagedProjectIfNoArrgerator.

public void testAddingManagedProjectIfNoArrgerator() throws Exception {
    if (!hasMavenInstallation())
        return;
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>");
    assertEquals(1, myProjectsManager.getProjectsTreeForTests().getManagedFilesPaths().size());
    setModuleNameAndRoot("module", getProjectPath() + "/module");
    setAggregatorProject(null);
    createNewModule(new MavenId("org.foo", "module", "1.0"));
    myProjectRoot.findFileByRelativePath("module/pom.xml");
    assertEquals(2, myProjectsManager.getProjectsTreeForTests().getManagedFilesPaths().size());
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId)

Example 54 with MavenId

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

the class MavenModuleBuilderTest method testAddingParent.

public void testAddingParent() throws Exception {
    if (!hasMavenInstallation())
        return;
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>");
    setModuleNameAndRoot("module", getProjectPath() + "/module");
    setParentProject(myProjectPom);
    createNewModule(new MavenId("org.foo", "module", "1.0"));
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" + "         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + "    <parent>\n" + "        <artifactId>project</artifactId>\n" + "        <groupId>test</groupId>\n" + "        <version>1</version>\n" + "    </parent>\n" + "    <modelVersion>4.0.0</modelVersion>\n" + "\n" + "    <groupId>org.foo</groupId>\n" + "    <artifactId>module</artifactId>\n" + "    <version>1.0</version>\n" + "\n" + "\n" + "</project>", VfsUtil.loadText(myProjectRoot.findFileByRelativePath("module/pom.xml")));
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId)

Example 55 with MavenId

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

the class MavenPropertyResolver method doResolveProperty.

@Nullable
private static String doResolveProperty(String propName, MavenProjectsManager projectsManager, MavenProject mavenProject, Properties additionalProperties) {
    boolean hasPrefix = false;
    String unprefixed = propName;
    if (propName.startsWith("pom.")) {
        unprefixed = propName.substring("pom.".length());
        hasPrefix = true;
    } else if (propName.startsWith("project.")) {
        unprefixed = propName.substring("project.".length());
        hasPrefix = true;
    }
    MavenProject selectedProject = mavenProject;
    while (unprefixed.startsWith("parent.")) {
        MavenId parentId = selectedProject.getParentId();
        if (parentId == null)
            return null;
        unprefixed = unprefixed.substring("parent.".length());
        if (unprefixed.equals("groupId")) {
            return parentId.getGroupId();
        }
        if (unprefixed.equals("artifactId")) {
            return parentId.getArtifactId();
        }
        if (unprefixed.equals("version")) {
            return parentId.getVersion();
        }
        selectedProject = projectsManager.findProject(parentId);
        if (selectedProject == null)
            return null;
    }
    if (unprefixed.equals("basedir") || (hasPrefix && mavenProject == selectedProject && unprefixed.equals("baseUri"))) {
        return selectedProject.getDirectory();
    }
    if ("java.home".equals(propName)) {
        String jreDir = MavenUtil.getModuleJreHome(projectsManager, mavenProject);
        if (jreDir != null) {
            return jreDir;
        }
    }
    if ("java.version".equals(propName)) {
        String javaVersion = MavenUtil.getModuleJavaVersion(projectsManager, mavenProject);
        if (javaVersion != null) {
            return javaVersion;
        }
    }
    String result;
    result = MavenUtil.getPropertiesFromMavenOpts().get(propName);
    if (result != null)
        return result;
    result = MavenServerUtil.collectSystemProperties().getProperty(propName);
    if (result != null)
        return result;
    result = selectedProject.getModelMap().get(unprefixed);
    if (result != null)
        return result;
    result = additionalProperties.getProperty(propName);
    if (result != null)
        return result;
    result = mavenProject.getProperties().getProperty(propName);
    if (result != null)
        return result;
    if ("settings.localRepository".equals(propName)) {
        return mavenProject.getLocalRepository().getAbsolutePath();
    }
    return null;
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Nullable(org.jetbrains.annotations.Nullable)

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