Search in sources :

Example 6 with MavenExplicitProfiles

use of org.jetbrains.idea.maven.model.MavenExplicitProfiles in project moe-ide-integration by multi-os-engine.

the class MOEMavenTask method executeTask.

public boolean executeTask(final Project project, final MavenProject mavenProject, final ExecutionEnvironment env, final String goal) {
    final Semaphore targetDone = new Semaphore();
    final boolean[] result = new boolean[] { true };
    try {
        ApplicationManager.getApplication().invokeAndWait(new Runnable() {

            @Override
            public void run() {
                if (project == null || project.isDisposed() || mavenProject == null)
                    return;
                final MavenExplicitProfiles explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles();
                final MOEMavenRunner mavenRunner = MOEMavenRunner.getInstance(project);
                targetDone.down();
                new Task.Backgroundable(project, title, true) {

                    public void run(@NotNull ProgressIndicator indicator) {
                        try {
                            MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), ParametersListUtil.parse(goal), explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
                            result[0] = mavenRunner.runBatch(Collections.singletonList(params), null, null, title, indicator);
                        } finally {
                            targetDone.up();
                        }
                    }

                    @Override
                    public boolean shouldStartInBackground() {
                        return startInBackground;
                    }

                    @Override
                    public void processSentToBackground() {
                        MOEMavenRunner.getInstance(project).getSettings().setRunMavenInBackground(true);
                    }
                }.queue();
            }
        }, ModalityState.NON_MODAL);
    } catch (Exception e) {
        MavenLog.LOG.error(e);
        return false;
    }
    targetDone.waitFor();
    return result[0];
}
Also used : MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Semaphore(com.intellij.util.concurrency.Semaphore) NotNull(org.jetbrains.annotations.NotNull) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Example 7 with MavenExplicitProfiles

use of org.jetbrains.idea.maven.model.MavenExplicitProfiles in project intellij-plugins by JetBrains.

the class Flexmojos3GenerateConfigTask method perform.

public void perform(final Project project, final MavenEmbeddersManager embeddersManager, final MavenConsole console, final MavenProgressIndicator indicator) throws MavenProcessCanceledException {
    if (myModule.isDisposed())
        return;
    indicator.setText(FlexBundle.message("generating.flex.config.for", myMavenProject.getDisplayName()));
    final MavenProjectsTree.EmbedderTask task = new MavenProjectsTree.EmbedderTask() {

        public void run(MavenEmbedderWrapper embedder) throws MavenProcessCanceledException {
            List<VirtualFile> temporaryFiles = null;
            final IgnoredFileBean[] filesToIgnoreOriginal = ChangeListManager.getInstance(project).getFilesToIgnore();
            try {
                MavenWorkspaceMap workspaceMap = new MavenWorkspaceMap();
                temporaryFiles = mavenIdToOutputFileMapping(workspaceMap, project, myTree.getProjects());
                embedder.customizeForStrictResolve(workspaceMap, console, indicator);
                final String generateConfigGoal = FlexmojosImporter.FLEXMOJOS_GROUP_ID + ":" + FlexmojosImporter.FLEXMOJOS_ARTIFACT_ID + ":generate-config-" + myMavenProject.getPackaging();
                final MavenExplicitProfiles profilesIds = myMavenProject.getActivatedProfilesIds();
                MavenServerExecutionResult result = embedder.execute(myMavenProject.getFile(), profilesIds.getEnabledProfiles(), profilesIds.getDisabledProfiles(), Collections.singletonList(generateConfigGoal));
                if (result.projectData == null) {
                    myFlexConfigInformer.showFlexConfigWarningIfNeeded(project);
                }
                MavenUtil.invokeAndWaitWriteAction(project, () -> {
                    // need to refresh externally created file
                    final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(myConfigFilePath);
                    if (file != null) {
                        file.refresh(false, false);
                        updateMainClass(myModule, file);
                    }
                });
            } catch (MavenProcessCanceledException e) {
                throw e;
            } catch (Exception e) {
                myFlexConfigInformer.showFlexConfigWarningIfNeeded(project);
                console.printException(e);
                MavenLog.LOG.warn(e);
            } finally {
                ChangeListManager.getInstance(project).setFilesToIgnore(filesToIgnoreOriginal);
                if (temporaryFiles != null && !temporaryFiles.isEmpty()) {
                    removeTemporaryFiles(project, temporaryFiles);
                }
            }
        }
    };
    myTree.executeWithEmbedder(myMavenProject, embeddersManager, MavenEmbeddersManager.FOR_POST_PROCESSING, console, indicator, task);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) IgnoredFileBean(com.intellij.openapi.vcs.changes.IgnoredFileBean) MavenWorkspaceMap(org.jetbrains.idea.maven.model.MavenWorkspaceMap)

Example 8 with MavenExplicitProfiles

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

the class ToggleProfileAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    MavenProjectsManager manager = MavenActionUtil.getProjectsManager(e.getDataContext());
    if (manager == null)
        return;
    Map<String, MavenProfileKind> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
    if (selectedProfiles == null)
        return;
    Set<String> selectedProfileIds = selectedProfiles.keySet();
    MavenProfileKind targetState = getTargetState(manager, selectedProfiles);
    if (targetState == null)
        return;
    MavenExplicitProfiles newExplicitProfiles = manager.getExplicitProfiles().clone();
    switch(targetState) {
        case NONE:
            // disable explicitly
            newExplicitProfiles.getEnabledProfiles().removeAll(selectedProfileIds);
            newExplicitProfiles.getDisabledProfiles().addAll(selectedProfileIds);
            break;
        case EXPLICIT:
            // enable explicitly
            newExplicitProfiles.getDisabledProfiles().removeAll(selectedProfileIds);
            newExplicitProfiles.getEnabledProfiles().addAll(selectedProfileIds);
            break;
        case IMPLICIT:
        default:
            // reset to default state
            newExplicitProfiles.getEnabledProfiles().removeAll(selectedProfileIds);
            newExplicitProfiles.getDisabledProfiles().removeAll(selectedProfileIds);
            break;
    }
    manager.setExplicitProfiles(newExplicitProfiles);
}
Also used : MavenProfileKind(org.jetbrains.idea.maven.model.MavenProfileKind) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles)

Example 9 with MavenExplicitProfiles

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

the class MavenWorkspaceSettingsComponent method getState.

@Override
@NotNull
public MavenWorkspaceSettings getState() {
    MavenExplicitProfiles profiles = MavenProjectsManager.getInstance(myProject).getExplicitProfiles();
    mySettings.setEnabledProfiles(profiles.getEnabledProfiles());
    mySettings.setDisabledProfiles(profiles.getDisabledProfiles());
    return mySettings;
}
Also used : MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with MavenExplicitProfiles

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

the class MavenProjectBuilder method commit.

@Override
public List<Module> commit(Project project, ModifiableModuleModel model, ModulesProvider modulesProvider, ModifiableArtifactModel artifactModel) {
    MavenWorkspaceSettings settings = MavenWorkspaceSettingsComponent.getInstance(project).getSettings();
    settings.generalSettings = getGeneralSettings();
    settings.importingSettings = getImportingSettings();
    String settingsFile = System.getProperty("idea.maven.import.settings.file");
    if (!StringUtil.isEmptyOrSpaces(settingsFile)) {
        settings.generalSettings.setUserSettingsFile(settingsFile.trim());
    }
    MavenExplicitProfiles selectedProfiles = getSelectedProfiles();
    String enabledProfilesList = System.getProperty("idea.maven.import.enabled.profiles");
    String disabledProfilesList = System.getProperty("idea.maven.import.disabled.profiles");
    if (enabledProfilesList != null || disabledProfilesList != null) {
        selectedProfiles = selectedProfiles.clone();
        appendProfilesFromString(selectedProfiles.getEnabledProfiles(), enabledProfilesList);
        appendProfilesFromString(selectedProfiles.getDisabledProfiles(), disabledProfilesList);
    }
    MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    manager.setIgnoredState(getParameters().mySelectedProjects, false);
    manager.addManagedFilesWithProfiles(MavenUtil.collectFiles(getParameters().mySelectedProjects), selectedProfiles);
    manager.waitForReadingCompletion();
    boolean isFromUI = model != null;
    return manager.importProjects(isFromUI ? new IdeUIModifiableModelsProvider(project, model, (ModulesConfigurator) modulesProvider, artifactModel) : new IdeModifiableModelsProviderImpl(project));
}
Also used : IdeUIModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)

Aggregations

MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)20 MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)4 Project (com.intellij.openapi.project.Project)3 MavenProfileKind (org.jetbrains.idea.maven.model.MavenProfileKind)3 MavenProject (org.jetbrains.idea.maven.project.MavenProject)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Semaphore (com.intellij.util.concurrency.Semaphore)2 NotNull (org.jetbrains.annotations.NotNull)2 MavenEmbedderWrapper (org.jetbrains.idea.maven.server.MavenEmbedderWrapper)2 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)1 IdeUIModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Task (com.intellij.openapi.progress.Task)1 IgnoredFileBean (com.intellij.openapi.vcs.changes.IgnoredFileBean)1 PsiFile (com.intellij.psi.PsiFile)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Nullable (org.jetbrains.annotations.Nullable)1