use of org.jetbrains.idea.maven.execution.MavenRunner 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.MavenRunner 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];
}
Aggregations