Search in sources :

Example 36 with MavenProject

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

the class ToggleIgnoredProjectsAction method isAvailable.

@Override
protected boolean isAvailable(AnActionEvent e) {
    if (!super.isAvailable(e))
        return false;
    final DataContext context = e.getDataContext();
    MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
    if (projectsManager == null)
        return false;
    List<MavenProject> projects = MavenActionUtil.getMavenProjects(context);
    if (projects == null || projects.isEmpty())
        return false;
    int ignoredStatesCount = 0;
    int ignoredCount = 0;
    for (MavenProject each : projects) {
        if (projectsManager.getIgnoredState(each)) {
            ignoredStatesCount++;
        }
        if (projectsManager.isIgnored(each)) {
            ignoredCount++;
        }
    }
    return (ignoredCount == 0 || ignoredCount == projects.size()) && (ignoredStatesCount == 0 || ignoredStatesCount == projects.size());
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject)

Example 37 with MavenProject

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

the class MavenPropertyCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiFile psiFile = parameters.getOriginalFile();
    Project project = psiFile.getProject();
    MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    if (!manager.isMavenizedProject())
        return;
    MavenProject projectFile = MavenDomUtil.findContainingProject(psiFile);
    if (projectFile == null)
        return;
    if (!MavenDomUtil.isMavenFile(psiFile) && !MavenDomUtil.isFilteredResourceFile(psiFile))
        return;
    String text = psiFile.getText();
    int offset = parameters.getOffset();
    int braceOffset = findOpenBrace(text, offset);
    if (braceOffset == -1)
        return;
    TextRange range = TextRange.create(braceOffset, offset);
    String prefix = range.substring(text);
    MavenFilteredPropertyPsiReference ref = new MavenFilteredPropertyPsiReference(projectFile, psiFile, prefix, range);
    addVariants(Arrays.asList(ref.getVariants()), result.withPrefixMatcher(prefix));
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange)

Example 38 with MavenProject

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

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

the class MavenExternalParameters method dumpModulesPaths.

private static File dumpModulesPaths(@NotNull Project project) throws IOException {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    Properties res = new Properties();
    MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        if (manager.isMavenizedModule(module)) {
            MavenProject mavenProject = manager.findProject(module);
            if (mavenProject != null && !manager.isIgnored(mavenProject)) {
                res.setProperty(mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ":pom" + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getFile().getPath());
                res.setProperty(mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ':' + mavenProject.getPackaging() + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getOutputDirectory());
                res.setProperty(mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ":test-jar" + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getTestOutputDirectory());
                addArtifactFileMapping(res, mavenProject, "sources");
                addArtifactFileMapping(res, mavenProject, "test-sources");
                addArtifactFileMapping(res, mavenProject, "javadoc");
                addArtifactFileMapping(res, mavenProject, "test-javadoc");
            }
        }
    }
    File file = new File(PathManager.getSystemPath(), "Maven/idea-projects-state-" + project.getLocationHash() + ".properties");
    FileUtil.ensureExists(file.getParentFile());
    OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
    try {
        res.store(out, null);
    } finally {
        out.close();
    }
    return file;
}
Also used : MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ZipOutputStream(java.util.zip.ZipOutputStream) Module(com.intellij.openapi.module.Module)

Example 40 with MavenProject

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

the class MavenProjectConstantListConverter method getValues.

protected Collection<String> getValues(@NotNull ConvertContext context) {
    DomElement element = context.getInvocationElement();
    MavenProject project = MavenDomUtil.findContainingProject(element);
    if (project == null)
        return Collections.emptyList();
    return getValues(context, project);
}
Also used : DomElement(com.intellij.util.xml.DomElement) MavenProject(org.jetbrains.idea.maven.project.MavenProject)

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