Search in sources :

Example 21 with MavenProjectsManager

use of org.jetbrains.idea.maven.project.MavenProjectsManager in project azure-tools-for-java by Microsoft.

the class MavenProjectGenerator method importMavenProject.

private void importMavenProject() throws ConfigurationException {
    Project project = this.module.getProject();
    String baseDirPath = project.getBasePath();
    MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    File pomFile = new File(baseDirPath + File.separator + "pom.xml");
    VirtualFile pom = VfsUtil.findFileByIoFile(pomFile, true);
    manager.addManagedFiles(Collections.singletonList(pom));
    manager.scheduleImportAndResolve();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 22 with MavenProjectsManager

use of org.jetbrains.idea.maven.project.MavenProjectsManager in project android by JetBrains.

the class AndroidMavenExecutor method generateResources.

public static Map<CompilerMessageCategory, List<String>> generateResources(final Module module) {
    MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
    final MavenRunnerParameters parameters = new MavenRunnerParameters(true, projectsManager.findProject(module).getDirectory(), Collections.singletonList("process-resources"), projectsManager.getExplicitProfiles());
    final Map<CompilerMessageCategory, List<String>> result = new HashMap<CompilerMessageCategory, List<String>>();
    result.put(CompilerMessageCategory.ERROR, new ArrayList<String>());
    try {
        JavaParameters javaParams = ApplicationManager.getApplication().runReadAction(new Computable<JavaParameters>() {

            @Nullable
            @Override
            public JavaParameters compute() {
                try {
                    return MavenExternalParameters.createJavaParameters(module.getProject(), parameters);
                } catch (ExecutionException e) {
                    LOG.info(e);
                    result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
                    return null;
                }
            }
        });
        if (javaParams == null) {
            return result;
        }
        GeneralCommandLine commandLine = javaParams.toCommandLine();
        final StringBuildingOutputProcessor processor = new StringBuildingOutputProcessor();
        boolean success = AndroidUtils.executeCommand(commandLine, processor, WaitingStrategies.WaitForever.getInstance()) == ExecutionStatus.SUCCESS;
        String message = processor.getMessage();
        if (!success) {
            LOG.info(message);
            String lcmessage = message.toLowerCase();
            int buildErrorIndex = lcmessage.indexOf(BUILD_ERROR_INDICATOR);
            if (buildErrorIndex >= 0) {
                result.get(CompilerMessageCategory.ERROR).add(message.substring(buildErrorIndex));
            }
        }
    } catch (ExecutionException e) {
        LOG.info(e);
        result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
    }
    return result;
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) HashMap(com.intellij.util.containers.HashMap) StringBuildingOutputProcessor(org.jetbrains.android.util.StringBuildingOutputProcessor) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Example 23 with MavenProjectsManager

use of org.jetbrains.idea.maven.project.MavenProjectsManager in project liferay-ide by liferay.

the class AbstractLiferayMavenGoalAction method checkOrPerform.

public boolean checkOrPerform(DataContext context, boolean perform) {
    Project project = MavenActionUtil.getProject(context);
    MavenProject mavenProject = MavenActionUtil.getMavenProject(context);
    if ((project == null) || (mavenProject == null)) {
        return false;
    }
    if (!perform) {
        return true;
    }
    String projectDir = mavenProject.getDirectory();
    MavenProjectsManager mavenProjectsManager = MavenActionUtil.getProjectsManager(context);
    MavenExplicitProfiles explicitProfiles = mavenProjectsManager.getExplicitProfiles();
    Collection<String> enabledProfiles = explicitProfiles.getEnabledProfiles();
    Collection<String> disabledProfiles = explicitProfiles.getDisabledProfiles();
    MavenRunnerParameters params = new MavenRunnerParameters(true, projectDir, goals, enabledProfiles, disabledProfiles);
    MavenRunConfigurationType.runConfiguration(project, params, null);
    return true;
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Example 24 with MavenProjectsManager

use of org.jetbrains.idea.maven.project.MavenProjectsManager in project liferay-ide by liferay.

the class LiferayWorkspaceUtil method isValidMavenWorkspaceLocation.

public static boolean isValidMavenWorkspaceLocation(Project project) {
    File pomFile = new File(project.getBasePath(), _BUILD_MAVEN_FILE_NAME);
    if (!pomFile.exists()) {
        return false;
    }
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    VirtualFile virtualPom = fileSystem.findFileByPath(pomFile.getPath());
    if (virtualPom.exists()) {
        boolean pom = MavenUtil.isPomFile(project, virtualPom);
        if (!pom) {
            return false;
        }
    }
    try {
        MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(project);
        MavenProject mavenWorkspaceProject = mavenProjectsManager.findProject(virtualPom);
        MavenPlugin liferayWorkspacePlugin = mavenWorkspaceProject.findPlugin("com.liferay", "com.liferay.portal.tools.bundle.support");
        if (liferayWorkspacePlugin != null) {
            return true;
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) MavenPlugin(org.jetbrains.idea.maven.model.MavenPlugin) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 25 with MavenProjectsManager

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

the class MOEMavenTask method runTask.

public boolean runTask() {
    String workDirectory = getWorkPath();
    MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
    File mavenHome = MavenUtil.resolveMavenHomeDirectory(projectsManager.getGeneralSettings().getMavenHome());
    if (mavenHome == null) {
        Notification notification = new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "Failed to execute goal", RunnerBundle.message("external.maven.home.no.default.with.fix"), NotificationType.ERROR, new NotificationListener.Adapter() {

            @Override
            protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                ShowSettingsUtil.getInstance().showSettingsDialog(module.getProject(), MavenSettings.DISPLAY_NAME);
            }
        });
        Notifications.Bus.notify(notification, module.getProject());
        return false;
    }
    StringBuilder goalBuilder = new StringBuilder();
    setGoalTarget(goalBuilder);
    addArguments(goalBuilder);
    MavenRunnerParameters parameters = new MavenRunnerParameters(true, workDirectory, Arrays.asList(ParametersList.parse(goalBuilder.toString())), Collections.<String>emptyList());
    MavenGeneralSettings generalSettings = new MavenGeneralSettings();
    generalSettings.setMavenHome(mavenHome.getPath());
    MavenRunnerSettings runnerSettings = MavenRunner.getInstance(module.getProject()).getSettings().clone();
    runnerSettings.setMavenProperties(new LinkedHashMap<String, String>());
    runnerSettings.setSkipTests(true);
    RunnerAndConfigurationSettings configSettings = createRunnerAndConfigurationSettings(generalSettings, runnerSettings, parameters, module.getProject());
    ProgramRunner runner = DefaultJavaProgramRunner.getInstance();
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    ExecutionEnvironment environment = new ExecutionEnvironment(executor, runner, configSettings, module.getProject());
    return executeTask(module.getProject(), getMavenProject(), environment, goalBuilder.toString());
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) HyperlinkEvent(javax.swing.event.HyperlinkEvent) MavenRunnerSettings(org.jetbrains.idea.maven.execution.MavenRunnerSettings) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Notification(com.intellij.notification.Notification) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) MavenRunConfigurationType.createRunnerAndConfigurationSettings(org.jetbrains.idea.maven.execution.MavenRunConfigurationType.createRunnerAndConfigurationSettings) DefaultJavaProgramRunner(com.intellij.execution.impl.DefaultJavaProgramRunner) ProgramRunner(com.intellij.execution.runners.ProgramRunner) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotificationListener(com.intellij.notification.NotificationListener) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Aggregations

MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)52 MavenProject (org.jetbrains.idea.maven.project.MavenProject)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)24 Project (com.intellij.openapi.project.Project)13 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 Nullable (org.jetbrains.annotations.Nullable)8 DataContext (com.intellij.openapi.actionSystem.DataContext)6 PsiFile (com.intellij.psi.PsiFile)6 Notification (com.intellij.notification.Notification)4 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)4 MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)4 NotificationListener (com.intellij.notification.NotificationListener)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 XmlElement (com.intellij.psi.xml.XmlElement)2 List (java.util.List)2