use of com.intellij.execution.configurations.JavaParameters in project android by JetBrains.
the class AndroidJunitPatcherWithTestArtifactTest method testRemoveAndroidTestClasspath.
public void testRemoveAndroidTestClasspath() throws Exception {
loadProject(SYNC_MULTIPROJECT);
JUnitPatcher myPatcher = new AndroidJunitPatcher();
Module module1 = ModuleManager.getInstance(myFixture.getProject()).findModuleByName("module1");
JavaParameters parameters = new JavaParameters();
parameters.configureByModule(module1, JavaParameters.CLASSES_AND_TESTS);
String classpath = parameters.getClassPath().getPathsString();
assertThat(classpath).contains("junit-4.12.jar");
assertThat(classpath).contains("gson-2.2.4.jar");
// JUnit is in test dependency, gson and guava are android test dependency
myPatcher.patchJavaParameters(module1, parameters);
classpath = parameters.getClassPath().getPathsString();
assertThat(classpath).contains("junit-4.12.jar");
assertThat(classpath).doesNotContain("gson-2.2.4.jar");
assertThat(classpath).doesNotContain("guava-18.0.jar");
assertThat(classpath).doesNotContain("module3");
}
use of com.intellij.execution.configurations.JavaParameters 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;
}
use of com.intellij.execution.configurations.JavaParameters in project intellij-community by JetBrains.
the class GradleScriptType method getRunner.
@Override
public GroovyScriptRunner getRunner() {
return new GroovyScriptRunner() {
@Override
public boolean shouldRefreshAfterFinish() {
return true;
}
@Override
public boolean isValidModule(@NotNull Module module) {
GradleInstallationManager libraryManager = ServiceManager.getService(GradleInstallationManager.class);
return libraryManager.isGradleSdk(OrderEnumerator.orderEntries(module).getAllLibrariesAndSdkClassesRoots());
}
@Override
public void ensureRunnerConfigured(@NotNull GroovyScriptRunConfiguration configuration) {
String parameters = configuration.getProgramParameters();
if (parameters != null) {
// TODO den implement
// GradleTasksList list = GradleUtil.getToolWindowElement(GradleTasksList.class, project, ExternalSystemDataKeys.RECENT_TASKS_LIST);
// if (list != null) {
// ExternalSystemTaskDescriptor descriptor = new ExternalSystemTaskDescriptor(parameters, null);
// descriptor.setExecutorId(executor.getId());
// list.setFirst(descriptor);
// GradleLocalSettings.getInstance(project).setRecentTasks(list.getModel().getTasks());
// }
}
final GradleInstallationManager libraryManager = ServiceManager.getService(GradleInstallationManager.class);
// TODO den implement
//if (libraryManager.getGradleHome(module, project) == null) {
// int result = 0;
// int result = Messages.showOkCancelDialog(
// ExternalSystemBundle.message("gradle.run.no.sdk.text"),
// ExternalSystemBundle.message("gradle.run.no.sdk.title"),
// GradleIcons.Gradle
// );
// if (result == 0) {
// ShowSettingsUtil.getInstance().editConfigurable(project, new AbstractExternalProjectConfigurable(project));
// }
// if (libraryManager.getGradleHome(module, project) == null) {
// return false;
// }
// }
}
@Override
public void configureCommandLine(JavaParameters params, @Nullable Module module, boolean tests, VirtualFile script, GroovyScriptRunConfiguration configuration) throws CantRunException {
final Project project = configuration.getProject();
final GradleInstallationManager libraryManager = ServiceManager.getService(GradleInstallationManager.class);
if (module == null) {
throw new CantRunException("Target module is undefined");
}
String rootProjectPath = module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
if (StringUtil.isEmpty(rootProjectPath)) {
throw new CantRunException(String.format("Module '%s' is not backed by gradle", module.getName()));
}
final VirtualFile gradleHome = libraryManager.getGradleHome(module, project, rootProjectPath);
if (gradleHome == null) {
throw new CantRunException("Gradle home can not be found");
}
params.setMainClass(findMainClass(gradleHome, script, project));
final File[] groovyJars = GroovyConfigUtils.getGroovyAllJars(gradleHome.getPath() + "/lib/");
if (groovyJars.length > 0) {
params.getClassPath().add(groovyJars[0].getAbsolutePath());
} else {
final VirtualFile groovyJar = findGroovyJar(module);
if (groovyJar != null) {
params.getClassPath().add(groovyJar);
}
}
final String userDefinedClasspath = System.getProperty("gradle.launcher.classpath");
if (StringUtil.isNotEmpty(userDefinedClasspath)) {
params.getClassPath().add(userDefinedClasspath);
} else {
final Collection<VirtualFile> roots = libraryManager.getClassRoots(project);
if (roots != null) {
params.getClassPath().addVirtualFiles(roots);
}
}
params.getVMParametersList().addParametersString(configuration.getVMParameters());
params.getVMParametersList().add("-Dgradle.home=" + FileUtil.toSystemDependentName(gradleHome.getPath()));
setToolsJar(params);
final String scriptPath = configuration.getScriptPath();
if (scriptPath == null) {
throw new CantRunException("Target script or gradle project path is undefined");
}
if (new File(scriptPath).isFile()) {
params.getProgramParametersList().add("--build-file");
} else {
params.getProgramParametersList().add("--project-dir");
}
params.getProgramParametersList().add(FileUtil.toSystemDependentName(scriptPath));
params.getProgramParametersList().addParametersString(configuration.getProgramParameters());
}
};
}
use of com.intellij.execution.configurations.JavaParameters in project intellij-plugins by JetBrains.
the class BndLaunchUtil method createJavaParameters.
@NotNull
public static JavaParameters createJavaParameters(@NotNull BndRunConfigurationBase configuration, @NotNull ProjectLauncher launcher) throws CantRunException {
Project project = configuration.getProject();
JavaParameters parameters = new JavaParameters();
File launcherDir = launcher.getCwd();
parameters.setWorkingDirectory(launcherDir != null ? launcherDir.getPath() : project.getBasePath());
String jreHome = configuration.useAlternativeJre ? configuration.alternativeJrePath : null;
JavaParametersUtil.configureProject(project, parameters, JavaParameters.JDK_ONLY, jreHome);
parameters.getEnv().putAll(launcher.getRunEnv());
parameters.getVMParametersList().addAll(asList(launcher.getRunVM()));
parameters.getClassPath().addAll(asList(launcher.getClasspath()));
parameters.setMainClass(launcher.getMainTypeName());
parameters.getProgramParametersList().addAll(asList(launcher.getRunProgramArgs()));
return parameters;
}
use of com.intellij.execution.configurations.JavaParameters in project intellij-community by JetBrains.
the class GradleApplicationEnvironmentProvider method createExecutionEnvironment.
@Nullable
public ExecutionEnvironment createExecutionEnvironment(@NotNull Project project, @NotNull ExecuteRunConfigurationTask executeRunConfigurationTask, @Nullable Executor executor) {
if (!isApplicable(executeRunConfigurationTask))
return null;
ApplicationConfiguration applicationConfiguration = (ApplicationConfiguration) executeRunConfigurationTask.getRunProfile();
PsiClass mainClass = applicationConfiguration.getMainClass();
if (mainClass == null)
return null;
VirtualFile virtualFile = mainClass.getContainingFile().getVirtualFile();
Module module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(virtualFile);
if (module == null)
return null;
final JavaParameters params = new JavaParameters();
JavaParametersUtil.configureConfiguration(params, applicationConfiguration);
params.getVMParametersList().addParametersString(applicationConfiguration.getVMParameters());
String javaExePath = null;
try {
final Sdk jdk = JavaParametersUtil.createProjectJdk(project, applicationConfiguration.getAlternativeJrePath());
if (jdk == null)
throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
final SdkTypeId type = jdk.getSdkType();
if (!(type instanceof JavaSdkType))
throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
javaExePath = ((JavaSdkType) type).getVMExecutablePath(jdk);
if (javaExePath == null)
throw new RuntimeException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable"));
javaExePath = FileUtil.toSystemIndependentName(javaExePath);
} catch (CantRunException e) {
ExecutionErrorDialog.show(e, "Cannot use specified JRE", project);
}
StringBuilder parametersString = new StringBuilder();
for (String parameter : params.getProgramParametersList().getParameters()) {
parametersString.append("args '").append(parameter).append("'\n");
}
StringBuilder vmParametersString = new StringBuilder();
for (String parameter : params.getVMParametersList().getParameters()) {
vmParametersString.append("jvmArgs '").append(parameter).append("'\n");
}
ExternalSystemTaskExecutionSettings taskSettings = new ExternalSystemTaskExecutionSettings();
taskSettings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
taskSettings.setExternalProjectPath(ExternalSystemApiUtil.getExternalProjectPath(module));
final String runAppTaskName = "run " + mainClass.getName();
taskSettings.setTaskNames(Collections.singletonList(runAppTaskName));
String executorId = executor == null ? DefaultRunExecutor.EXECUTOR_ID : executor.getId();
ExecutionEnvironment environment = ExternalSystemUtil.createExecutionEnvironment(project, GradleConstants.SYSTEM_ID, taskSettings, executorId);
if (environment != null) {
RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
assert runnerAndConfigurationSettings != null;
ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
final String gradlePath = GradleProjectResolverUtil.getGradlePath(module);
if (gradlePath == null)
return null;
final String sourceSetName;
if (GradleConstants.GRADLE_SOURCE_SET_MODULE_TYPE_KEY.equals(ExternalSystemApiUtil.getExternalModuleType(module))) {
sourceSetName = GradleProjectResolverUtil.getSourceSetName(module);
} else {
sourceSetName = ModuleRootManager.getInstance(module).getFileIndex().isInTestSourceContent(virtualFile) ? "test" : "main";
}
if (sourceSetName == null)
return null;
@Language("Groovy") String initScript = "projectsEvaluated {\n" + " rootProject.allprojects {\n" + " if(project.path == '" + gradlePath + "' && project.sourceSets) {\n" + " project.tasks.create(name: '" + runAppTaskName + "', overwrite: true, type: JavaExec) {\n" + (javaExePath != null ? " executable = '" + javaExePath + "'\n" : "") + " classpath = project.sourceSets.'" + sourceSetName + "'.runtimeClasspath\n" + " main = '" + mainClass.getQualifiedName() + "'\n" + parametersString.toString() + vmParametersString.toString() + " }\n" + " }\n" + " }\n" + "}\n";
runConfiguration.putUserData(GradleTaskManager.INIT_SCRIPT_KEY, initScript);
return environment;
} else {
return null;
}
}
Aggregations