Search in sources :

Example 41 with MavenProject

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

the class SelectMavenProjectDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    ComboBoxUtil.setModel(myMavenProjectsComboBox, new DefaultComboBoxModel(), myMavenDomProjectModels, model -> {
        String projectName = model.getName().getStringValue();
        MavenProject mavenProject = MavenDomUtil.findProject(model);
        if (mavenProject != null) {
            projectName = mavenProject.getDisplayName();
        }
        if (StringUtil.isEmptyOrSpaces(projectName)) {
            projectName = "pom.xml";
        }
        return Pair.create(projectName, model);
    });
    myReplaceAllListener = new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            updateControls();
        }
    };
    myMavenProjectsComboBox.addItemListener(myReplaceAllListener);
    myMavenProjectsComboBox.setSelectedItem(0);
    myReplaceAllCheckBox.setVisible(myHasUsagesInProjects);
    myExtractExclusions.setVisible(myHasExclusions);
    updateControls();
    return myMainPanel;
}
Also used : ItemEvent(java.awt.event.ItemEvent) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ItemListener(java.awt.event.ItemListener)

Example 42 with MavenProject

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

the class IntroducePropertyDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    myFieldNamePanel.setLayout(new BorderLayout());
    myNameField = new NameSuggestionsField(myProject);
    myNameChangedListener = new NameSuggestionsField.DataChanged() {

        public void dataChanged() {
            updateOkStatus();
        }
    };
    myNameField.addDataChangedListener(myNameChangedListener);
    myNameField.setSuggestions(getSuggestions());
    myFieldNamePanel.add(myNameField, BorderLayout.CENTER);
    List<MavenDomProjectModel> projects = getProjects();
    ComboBoxUtil.setModel(myMavenProjectsComboBox, new DefaultComboBoxModel(), projects, model -> {
        String projectName = model.getName().getStringValue();
        MavenProject mavenProject = MavenDomUtil.findProject(model);
        if (mavenProject != null) {
            projectName = mavenProject.getDisplayName();
        }
        if (StringUtil.isEmptyOrSpaces(projectName)) {
            projectName = "pom.xml";
        }
        return Pair.create(projectName, model);
    });
    myMavenProjectsComboBox.setSelectedItem(myMavenDomProjectModel);
    return myMainPanel;
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) MavenProject(org.jetbrains.idea.maven.project.MavenProject) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField)

Example 43 with MavenProject

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

the class MavenFilteredPropertyPsiReferenceProvider method getReferencesByElement.

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    if (!shouldAddReference(element)) {
        // Add reference to element with one child or leaf element only to avoid performance problem.
        return PsiReference.EMPTY_ARRAY;
    }
    if (!MavenDomUtil.isFilteredResourceFile(element))
        return PsiReference.EMPTY_ARRAY;
    String text = element.getText();
    if (StringUtil.isEmptyOrSpaces(text))
        return PsiReference.EMPTY_ARRAY;
    MavenProject mavenProject = MavenDomUtil.findContainingProject(element);
    if (mavenProject == null)
        return PsiReference.EMPTY_ARRAY;
    List<PsiReference> res = null;
    Pattern pattern = getDelimitersPattern(mavenProject);
    Matcher matcher = pattern.matcher(text);
    int groupCount = matcher.groupCount();
    while (matcher.find()) {
        String propertyName = null;
        int from = 0;
        for (int i = 0; i < groupCount; i++) {
            propertyName = matcher.group(i + 1);
            if (propertyName != null) {
                from = matcher.start(i + 1);
                break;
            }
        }
        assert propertyName != null;
        if (res == null) {
            res = new ArrayList<>();
        }
        TextRange range = TextRange.from(from, propertyName.length());
        res.add(new MavenFilteredPropertyPsiReference(mavenProject, element, propertyName, range));
    }
    return res == null ? PsiReference.EMPTY_ARRAY : res.toArray(new PsiReference[res.size()]);
}
Also used : Pattern(java.util.regex.Pattern) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Matcher(java.util.regex.Matcher) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 44 with MavenProject

use of org.jetbrains.idea.maven.project.MavenProject 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 45 with MavenProject

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

the class MavenPropertyResolver method doFilterText.

public static void doFilterText(Module module, String text, Properties additionalProperties, @Nullable String propertyEscapeString, Appendable out) throws IOException {
    MavenProjectsManager manager = MavenProjectsManager.getInstance(module.getProject());
    MavenProject mavenProject = manager.findProject(module);
    if (mavenProject == null) {
        out.append(text);
        return;
    }
    Element pluginConfiguration = mavenProject.getPluginConfiguration("org.apache.maven.plugins", "maven-resources-plugin");
    String escapeWindowsPathsStr = MavenJDOMUtil.findChildValueByPath(pluginConfiguration, "escapeWindowsPaths");
    boolean escapeWindowsPath = escapeWindowsPathsStr == null || Boolean.parseBoolean(escapeWindowsPathsStr);
    doFilterText(MavenFilteredPropertyPsiReferenceProvider.getDelimitersPattern(mavenProject), manager, mavenProject, text, additionalProperties, propertyEscapeString, escapeWindowsPath, null, out);
}
Also used : MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) XmlElement(com.intellij.psi.xml.XmlElement) Element(org.jdom.Element)

Aggregations

MavenProject (org.jetbrains.idea.maven.project.MavenProject)132 VirtualFile (com.intellij.openapi.vfs.VirtualFile)40 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)20 MavenId (org.jetbrains.idea.maven.model.MavenId)16 Project (com.intellij.openapi.project.Project)10 Nullable (org.jetbrains.annotations.Nullable)9 Bombed (com.intellij.idea.Bombed)8 Module (com.intellij.openapi.module.Module)6 DataContext (com.intellij.openapi.actionSystem.DataContext)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 Result (com.intellij.openapi.application.Result)4 MavenArtifact (org.jetbrains.idea.maven.model.MavenArtifact)4 MavenEmbeddersManager (org.jetbrains.idea.maven.project.MavenEmbeddersManager)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 TextRange (com.intellij.openapi.util.TextRange)3 NotNull (org.jetbrains.annotations.NotNull)3 MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)3 MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)3 MavenProjectsTree (org.jetbrains.idea.maven.project.MavenProjectsTree)3