Search in sources :

Example 16 with MavenDomProjectModel

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

the class MavenDuplicateDependenciesInspection method checkFileElement.

@Override
public void checkFileElement(DomFileElement<MavenDomProjectModel> domFileElement, DomElementAnnotationHolder holder) {
    MavenDomProjectModel projectModel = domFileElement.getRootElement();
    checkManagedDependencies(projectModel, holder);
    checkDependencies(projectModel, holder);
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)

Example 17 with MavenDomProjectModel

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

the class MavenDuplicateDependenciesInspection method addProblem.

private static void addProblem(@NotNull MavenDomDependency dependency, @NotNull Collection<MavenDomDependency> dependencies, @NotNull DomElementAnnotationHolder holder) {
    StringBuilder sb = new StringBuilder();
    Set<MavenDomProjectModel> processed = new HashSet<>();
    for (MavenDomDependency domDependency : dependencies) {
        if (dependency.equals(domDependency))
            continue;
        MavenDomProjectModel model = domDependency.getParentOfType(MavenDomProjectModel.class, false);
        if (model != null && !processed.contains(model)) {
            if (processed.size() > 0)
                sb.append(", ");
            sb.append(createLinkText(model, domDependency));
            processed.add(model);
        }
    }
    holder.createProblem(dependency, HighlightSeverity.WARNING, MavenDomBundle.message("MavenDuplicateDependenciesInspection.has.duplicates", sb.toString()));
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) HashSet(com.intellij.util.containers.hash.HashSet) MavenDomDependency(org.jetbrains.idea.maven.dom.model.MavenDomDependency)

Example 18 with MavenDomProjectModel

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

the class AddMavenDependencyQuickFix method invoke.

public void invoke(@NotNull final Project project, Editor editor, final PsiFile file) throws IncorrectOperationException {
    if (!myRef.isValid())
        return;
    MavenProject mavenProject = MavenDomUtil.findContainingProject(file);
    if (mavenProject == null)
        return;
    final List<MavenId> ids = MavenArtifactSearchDialog.searchForClass(project, getReferenceText());
    if (ids.isEmpty())
        return;
    final MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(project, mavenProject.getFile());
    if (model == null)
        return;
    new WriteCommandAction(project, "Add Maven Dependency", DomUtil.getFile(model)) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            boolean isTestSource = false;
            VirtualFile virtualFile = file.getOriginalFile().getVirtualFile();
            if (virtualFile != null) {
                isTestSource = ProjectRootManager.getInstance(project).getFileIndex().isInTestSourceContent(virtualFile);
            }
            for (MavenId each : ids) {
                MavenDomDependency dependency = MavenDomUtil.createDomDependency(model, null, each);
                if (isTestSource) {
                    dependency.getScope().setStringValue("test");
                }
            }
        }
    }.execute();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Result(com.intellij.openapi.application.Result) MavenDomDependency(org.jetbrains.idea.maven.dom.model.MavenDomDependency)

Example 19 with MavenDomProjectModel

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

the class MavenParentRelativePathConverter method getVariants.

@NotNull
@Override
public Collection<PsiFile> getVariants(ConvertContext context) {
    List<PsiFile> result = new ArrayList<>();
    PsiFile currentFile = context.getFile().getOriginalFile();
    for (DomFileElement<MavenDomProjectModel> each : MavenDomUtil.collectProjectModels(context.getFile().getProject())) {
        PsiFile file = each.getOriginalFile();
        if (file == currentFile)
            continue;
        result.add(file);
    }
    return result;
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with MavenDomProjectModel

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

the class MavenModuleBuilderHelper method configure.

public void configure(final Project project, final VirtualFile root, final boolean isInteractive) {
    PsiFile[] psiFiles = myAggregatorProject != null ? new PsiFile[] { getPsiFile(project, myAggregatorProject.getFile()) } : PsiFile.EMPTY_ARRAY;
    final VirtualFile pom = new WriteCommandAction<VirtualFile>(project, myCommandName, psiFiles) {

        @Override
        protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
            VirtualFile file;
            try {
                file = root.createChildData(this, MavenConstants.POM_XML);
                MavenUtil.runOrApplyMavenProjectFileTemplate(project, file, myProjectId, isInteractive);
                result.setResult(file);
            } catch (IOException e) {
                showError(project, e);
                return;
            }
            updateProjectPom(project, file);
            if (myAggregatorProject != null) {
                MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(project, myAggregatorProject.getFile());
                if (model != null) {
                    model.getPackaging().setStringValue("pom");
                    MavenDomModule module = model.getModules().addModule();
                    module.setValue(getPsiFile(project, file));
                }
            }
        }
    }.execute().getResultObject();
    if (pom == null)
        return;
    if (myAggregatorProject == null) {
        MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
        manager.addManagedFilesOrUnignore(Collections.singletonList(pom));
    }
    if (myArchetype == null) {
        try {
            VfsUtil.createDirectories(root.getPath() + "/src/main/java");
            VfsUtil.createDirectories(root.getPath() + "/src/main/resources");
            VfsUtil.createDirectories(root.getPath() + "/src/test/java");
        } catch (IOException e) {
            MavenLog.LOG.info(e);
        }
    }
    // execute when current dialog is closed (e.g. Project Structure)
    MavenUtil.invokeLater(project, ModalityState.NON_MODAL, () -> {
        if (!pom.isValid())
            return;
        EditorHelper.openInEditor(getPsiFile(project, pom));
        if (myArchetype != null)
            generateFromArchetype(project, pom);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) MavenDomModule(org.jetbrains.idea.maven.dom.model.MavenDomModule) Result(com.intellij.openapi.application.Result)

Aggregations

MavenDomProjectModel (org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)5 MavenDomDependency (org.jetbrains.idea.maven.dom.model.MavenDomDependency)5 Nullable (org.jetbrains.annotations.Nullable)4 PsiFile (com.intellij.psi.PsiFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 DomElement (com.intellij.util.xml.DomElement)3 MavenProject (org.jetbrains.idea.maven.project.MavenProject)3 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 MavenId (org.jetbrains.idea.maven.model.MavenId)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 IProperty (com.intellij.lang.properties.IProperty)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 Pair (com.intellij.openapi.util.Pair)1 TextRange (com.intellij.openapi.util.TextRange)1