use of org.jetbrains.idea.maven.execution.MavenRunnerParameters in project intellij-community by JetBrains.
the class MavenBeforeRunTasksProvider method executeTask.
public boolean executeTask(final DataContext context, RunConfiguration configuration, ExecutionEnvironment env, final MavenBeforeRunTask task) {
final Semaphore targetDone = new Semaphore();
final boolean[] result = new boolean[] { true };
try {
ApplicationManager.getApplication().invokeAndWait(() -> {
final Project project = CommonDataKeys.PROJECT.getData(context);
final MavenProject mavenProject = getMavenProject(task);
if (project == null || project.isDisposed() || mavenProject == null)
return;
FileDocumentManager.getInstance().saveAllDocuments();
final MavenExplicitProfiles explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles();
final MavenRunner mavenRunner = MavenRunner.getInstance(project);
targetDone.down();
new Task.Backgroundable(project, TasksBundle.message("maven.tasks.executing"), true) {
public void run(@NotNull ProgressIndicator indicator) {
try {
MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), ParametersListUtil.parse(task.getGoal()), explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
result[0] = mavenRunner.runBatch(Collections.singletonList(params), null, null, TasksBundle.message("maven.tasks.executing"), indicator);
} finally {
targetDone.up();
}
}
@Override
public boolean shouldStartInBackground() {
return MavenRunner.getInstance(project).getSettings().isRunMavenInBackground();
}
@Override
public void processSentToBackground() {
MavenRunner.getInstance(project).getSettings().setRunMavenInBackground(true);
}
}.queue();
}, ModalityState.NON_MODAL);
} catch (Exception e) {
MavenLog.LOG.error(e);
return false;
}
targetDone.waitFor();
return result[0];
}
use of org.jetbrains.idea.maven.execution.MavenRunnerParameters in project intellij-community by JetBrains.
the class MavenTasksManager method doExecute.
private boolean doExecute(boolean before, CompileContext context) {
List<MavenRunnerParameters> parametersList;
synchronized (this) {
parametersList = new ArrayList<>();
Set<MavenCompilerTask> tasks = before ? myState.beforeCompileTasks : myState.afterCompileTasks;
if (context.isRebuild()) {
tasks = Sets.union(before ? myState.beforeRebuildTask : myState.afterRebuildTask, tasks);
}
for (MavenCompilerTask each : tasks) {
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(each.getProjectPath());
if (file == null)
continue;
MavenExplicitProfiles explicitProfiles = myProjectsManager.getExplicitProfiles();
parametersList.add(new MavenRunnerParameters(true, file.getParent().getPath(), Arrays.asList(each.getGoal()), explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles()));
}
}
return myRunner.runBatch(parametersList, null, null, TasksBundle.message("maven.tasks.executing"), context.getProgressIndicator());
}
use of org.jetbrains.idea.maven.execution.MavenRunnerParameters in project intellij-community by JetBrains.
the class RunBuildAction method checkOrPerform.
private static boolean checkOrPerform(DataContext context, boolean perform) {
final List<String> goals = MavenDataKeys.MAVEN_GOALS.getData(context);
if (goals == null || goals.isEmpty())
return false;
final Project project = MavenActionUtil.getProject(context);
if (project == null)
return false;
final MavenProject mavenProject = MavenActionUtil.getMavenProject(context);
if (mavenProject == null)
return false;
if (!perform)
return true;
final MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
if (projectsManager == null)
return false;
MavenExplicitProfiles explicitProfiles = projectsManager.getExplicitProfiles();
final MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), goals, explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
MavenRunConfigurationType.runConfiguration(project, params, null);
return true;
}
use of org.jetbrains.idea.maven.execution.MavenRunnerParameters in project intellij-community by JetBrains.
the class MavenModuleBuilderHelper method generateFromArchetype.
private void generateFromArchetype(final Project project, final VirtualFile pom) {
final File workingDir;
try {
workingDir = FileUtil.createTempDirectory("archetype", "tmp");
workingDir.deleteOnExit();
} catch (IOException e) {
showError(project, e);
return;
}
MavenRunnerParameters params = new MavenRunnerParameters(false, workingDir.getPath(), Collections.singletonList("org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate"), Collections.emptyList());
MavenRunner runner = MavenRunner.getInstance(project);
MavenRunnerSettings settings = runner.getState().clone();
Map<String, String> props = settings.getMavenProperties();
props.put("interactiveMode", "false");
//props.put("archetypeGroupId", myArchetype.groupId);
//props.put("archetypeArtifactId", myArchetype.artifactId);
//props.put("archetypeVersion", myArchetype.version);
//if (myArchetype.repository != null) props.put("archetypeRepository", myArchetype.repository);
//props.put("groupId", myProjectId.getGroupId());
//props.put("artifactId", myProjectId.getArtifactId());
//props.put("version", myProjectId.getVersion());
props.putAll(myPropertiesToCreateByArtifact);
runner.run(params, settings, () -> copyGeneratedFiles(workingDir, pom, project));
}
use of org.jetbrains.idea.maven.execution.MavenRunnerParameters 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;
}
Aggregations