Search in sources :

Example 36 with MavenId

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

the class CustomRepositoryMetadataManager method resolve.

@Override
public void resolve(RepositoryMetadata metadata, List remoteRepositories, ArtifactRepository localRepository) throws RepositoryMetadataResolutionException {
    super.resolve(metadata, remoteRepositories, localRepository);
    MavenWorkspaceMap map = myWorkspaceMap;
    if (map == null)
        return;
    Metadata data = metadata.getMetadata();
    Versioning versioning = data.getVersioning();
    if (versioning == null) {
        data.setVersioning(versioning = new Versioning());
    }
    for (MavenId each : map.getAvailableIds()) {
        if (each.equals(data.getGroupId(), data.getArtifactId())) {
            versioning.addVersion(each.getVersion());
        }
    }
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) MavenWorkspaceMap(org.jetbrains.idea.maven.model.MavenWorkspaceMap)

Example 37 with MavenId

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

the class MavenResourceCompilerConfigurationGenerator method generateBuildConfiguration.

public void generateBuildConfiguration(boolean force) {
    if (!myMavenProjectsManager.isMavenizedProject()) {
        return;
    }
    final BuildManager buildManager = BuildManager.getInstance();
    final File projectSystemDir = buildManager.getProjectSystemDirectory(myProject);
    if (projectSystemDir == null) {
        return;
    }
    final File mavenConfigFile = new File(projectSystemDir, MavenProjectConfiguration.CONFIGURATION_FILE_RELATIVE_PATH);
    ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
    ProjectFileIndex fileIndex = projectRootManager.getFileIndex();
    final int projectRootModificationCount = (int) projectRootManager.getModificationCount();
    final int mavenConfigCrc = myProjectsTree.getFilterConfigCrc(fileIndex);
    final int crc = mavenConfigCrc + projectRootModificationCount;
    final File crcFile = new File(mavenConfigFile.getParent(), "configuration.crc");
    if (!force) {
        try {
            DataInputStream crcInput = new DataInputStream(new FileInputStream(crcFile));
            try {
                final int lastCrc = crcInput.readInt();
                // Project had not change since last config generation.
                if (lastCrc == crc)
                    return;
                LOG.debug(String.format("project configuration changed: lastCrc = %d, currentCrc = %d, projectRootModificationCount = %d, mavenConfigCrc = %d", lastCrc, crc, projectRootModificationCount, mavenConfigCrc));
            } finally {
                crcInput.close();
            }
        } catch (IOException ignored) {
            LOG.debug("Unable to read or find config file: " + ignored.getMessage());
        }
    }
    MavenProjectConfiguration projectConfig = new MavenProjectConfiguration();
    for (MavenProject mavenProject : myMavenProjectsManager.getProjects()) {
        VirtualFile pomXml = mavenProject.getFile();
        Module module = fileIndex.getModuleForFile(pomXml);
        if (module == null)
            continue;
        if (!Comparing.equal(mavenProject.getDirectoryFile(), fileIndex.getContentRootForFile(pomXml)))
            continue;
        MavenModuleResourceConfiguration resourceConfig = new MavenModuleResourceConfiguration();
        MavenId projectId = mavenProject.getMavenId();
        resourceConfig.id = new MavenIdBean(projectId.getGroupId(), projectId.getArtifactId(), projectId.getVersion());
        MavenId parentId = mavenProject.getParentId();
        if (parentId != null) {
            resourceConfig.parentId = new MavenIdBean(parentId.getGroupId(), parentId.getArtifactId(), parentId.getVersion());
        }
        resourceConfig.directory = FileUtil.toSystemIndependentName(mavenProject.getDirectory());
        resourceConfig.delimitersPattern = MavenFilteredPropertyPsiReferenceProvider.getDelimitersPattern(mavenProject).pattern();
        for (Map.Entry<String, String> entry : mavenProject.getModelMap().entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (value != null) {
                resourceConfig.modelMap.put(key, value);
            }
        }
        addEarModelMapEntries(mavenProject, resourceConfig.modelMap);
        Element pluginConfiguration = mavenProject.getPluginConfiguration("org.apache.maven.plugins", "maven-resources-plugin");
        resourceConfig.outputDirectory = getResourcesPluginGoalOutputDirectory(mavenProject, pluginConfiguration, "resources");
        resourceConfig.testOutputDirectory = getResourcesPluginGoalOutputDirectory(mavenProject, pluginConfiguration, "testResources");
        addResources(resourceConfig.resources, mavenProject.getResources());
        addResources(resourceConfig.testResources, mavenProject.getTestResources());
        addWebResources(module, projectConfig, mavenProject);
        addEjbClientArtifactConfiguration(module, projectConfig, mavenProject);
        resourceConfig.filteringExclusions.addAll(MavenProjectsTree.getFilterExclusions(mavenProject));
        final Properties properties = getFilteringProperties(mavenProject);
        for (Map.Entry<Object, Object> propEntry : properties.entrySet()) {
            resourceConfig.properties.put((String) propEntry.getKey(), (String) propEntry.getValue());
        }
        resourceConfig.escapeString = MavenJDOMUtil.findChildValueByPath(pluginConfiguration, "escapeString", null);
        String escapeWindowsPaths = MavenJDOMUtil.findChildValueByPath(pluginConfiguration, "escapeWindowsPaths");
        if (escapeWindowsPaths != null) {
            resourceConfig.escapeWindowsPaths = Boolean.parseBoolean(escapeWindowsPaths);
        }
        String overwrite = MavenJDOMUtil.findChildValueByPath(pluginConfiguration, "overwrite");
        if (overwrite != null) {
            resourceConfig.overwrite = Boolean.parseBoolean(overwrite);
        }
        projectConfig.moduleConfigurations.put(module.getName(), resourceConfig);
        generateManifest(mavenProject, module, resourceConfig);
    }
    addNonMavenResources(projectConfig);
    final Element element = new Element("maven-project-configuration");
    XmlSerializer.serializeInto(projectConfig, element);
    buildManager.runCommand(() -> {
        buildManager.clearState(myProject);
        FileUtil.createIfDoesntExist(mavenConfigFile);
        try {
            JdomKt.write(element, mavenConfigFile.toPath());
            DataOutputStream crcOutput = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(crcFile)));
            try {
                crcOutput.writeInt(crc);
            } finally {
                crcOutput.close();
            }
        } catch (IOException e) {
            LOG.debug("Unable to write config file", e);
            throw new RuntimeException(e);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Element(org.jdom.Element) MavenId(org.jetbrains.idea.maven.model.MavenId) BuildManager(com.intellij.compiler.server.BuildManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 38 with MavenId

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

the class MavenFrameworkSupportProvider method createConfigurable.

@NotNull
@Override
public FrameworkSupportConfigurable createConfigurable(@NotNull FrameworkSupportModel model) {
    return new FrameworkSupportConfigurable() {

        @Override
        public JComponent getComponent() {
            return new JPanel();
        }

        @Override
        public void addSupport(@NotNull Module module, @NotNull ModifiableRootModel model, @Nullable Library library) {
            VirtualFile[] roots = model.getContentRoots();
            VirtualFile root;
            if (roots.length == 0) {
                VirtualFile moduleFile = module.getModuleFile();
                if (moduleFile != null) {
                    root = moduleFile.getParent();
                    model.addContentEntry(root);
                } else {
                    return;
                }
            } else {
                root = roots[0];
            }
            VirtualFile existingPom = null;
            for (VirtualFile child : root.getChildren()) {
                if (child.getName().startsWith("pom.")) {
                    existingPom = child;
                }
            }
            if (existingPom != null) {
                MavenProjectsManager.getInstance(module.getProject()).addManagedFilesOrUnignore(Collections.singletonList(existingPom));
            } else {
                prepareProjectStructure(model, root);
                new MavenModuleBuilderHelper(new MavenId("groupId", module.getName(), "1.0-SNAPSHOT"), null, null, false, false, null, null, "Add Maven Support").configure(model.getProject(), root, true);
            }
        }
    };
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenId(org.jetbrains.idea.maven.model.MavenId) FrameworkSupportConfigurable(com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with MavenId

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

the class MavenModuleWizardStep method updateDataModel.

@Override
public void updateDataModel() {
    myContext.setProjectBuilder(myBuilder);
    myBuilder.setAggregatorProject(myAggregator);
    myBuilder.setParentProject(myParent);
    myBuilder.setProjectId(new MavenId(myGroupIdField.getText(), myArtifactIdField.getText(), myVersionField.getText()));
    myBuilder.setInheritedOptions(myInheritGroupIdCheckBox.isSelected(), myInheritVersionCheckBox.isSelected());
    if (myContext.getProjectName() == null) {
        myContext.setProjectName(myBuilder.getProjectId().getArtifactId());
    }
    if (myArchetypes != null) {
        myBuilder.setArchetype(myArchetypes.getSelectedArchetype());
    }
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId)

Example 40 with MavenId

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

the class AddMavenDependencyQuickFixTest method testAddDependencyInTest.

public void testAddDependencyInTest() throws IOException {
    VirtualFile f = createProjectSubFile("src/test/java/A.java", "import org.apache.commons.io.IOUtils;\n" + "\n" + "public class Aaa {\n" + "\n" + "  public void xxx() {\n" + "    IOUtil<caret>s u;\n" + "  }\n" + "\n" + "}");
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>");
    myFixture.configureFromExistingVirtualFile(f);
    IntentionAction intentionAction = findAddMavenIntention();
    MavenArtifactSearchDialog.ourResultForTest = Collections.singletonList(new MavenId("commons-io", "commons-io", "2.4"));
    intentionAction.invoke(myProject, myFixture.getEditor(), myFixture.getFile());
    String pomText = PsiManager.getInstance(myProject).findFile(myProjectPom).getText();
    assertTrue(pomText.matches("(?s).*<dependency>\\s*<groupId>commons-io</groupId>\\s*<artifactId>commons-io</artifactId>\\s*<version>2.4</version>\\s*<scope>test</scope>\\s*</dependency>.*"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenId(org.jetbrains.idea.maven.model.MavenId) IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

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