use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.
the class ConfigurationsTest method testCreateInnerPackageLocalApplication.
public void testCreateInnerPackageLocalApplication() throws ExecutionException {
PsiClass psiClass = findClass(getModule1(), "test2.NotATest.InnerApplication");
assertNotNull(psiClass);
ApplicationConfiguration configuration = createConfiguration(psiClass);
assertEquals("test2.NotATest$InnerApplication", configuration.MAIN_CLASS_NAME);
checkCanRun(configuration);
}
use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.
the class ConfigurationsTest method testTestClassPathWhenRunningConfigurations.
public void testTestClassPathWhenRunningConfigurations() throws IOException, ExecutionException {
addModule("module4", false);
Module module4 = getModule4();
assignJdk(module4);
addSourcePath(module4, "testSrc", true);
addSourcePath(module4, "src", false);
String output = setCompilerOutput(module4, "classes", false);
String testOuput = setCompilerOutput(module4, "testClasses", true);
ApplicationConfiguration applicationConfiguration = createConfiguration(findClass(module4, "Application"));
JavaParameters parameters = checkCanRun(applicationConfiguration);
String classPath = parameters.getClassPath().getPathsString();
checkDoesNotContain(classPath, testOuput);
checkContains(classPath, output);
JUnitConfiguration junitConfiguration = createJUnitConfiguration(findClass(module4, "TestApplication"), TestInClassConfigurationProducer.class, new MapDataContext());
parameters = checkCanRun(junitConfiguration);
classPath = parameters.getClassPath().getPathsString();
checkContains(classPath, testOuput);
checkContains(classPath, output);
applicationConfiguration.MAIN_CLASS_NAME = junitConfiguration.getPersistentData().getMainClassName();
classPath = checkCanRun(applicationConfiguration).getClassPath().getPathsString();
checkContains(classPath, testOuput);
checkContains(classPath, output);
}
use of com.intellij.execution.application.ApplicationConfiguration 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;
}
}
use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.
the class SnapShooterConfigurationExtension method updateJavaParameters.
@Override
public void updateJavaParameters(RunConfigurationBase configuration, JavaParameters params, RunnerSettings runnerSettings) {
if (!isApplicableFor(configuration)) {
return;
}
ApplicationConfiguration appConfiguration = (ApplicationConfiguration) configuration;
SnapShooterConfigurationSettings settings = appConfiguration.getUserData(SnapShooterConfigurationSettings.SNAP_SHOOTER_KEY);
if (settings == null) {
settings = new SnapShooterConfigurationSettings();
appConfiguration.putUserData(SnapShooterConfigurationSettings.SNAP_SHOOTER_KEY, settings);
}
if (appConfiguration.ENABLE_SWING_INSPECTOR) {
settings.setLastPort(NetUtils.tryToFindAvailableSocketPort());
}
if (appConfiguration.ENABLE_SWING_INSPECTOR && settings.getLastPort() != -1) {
params.getProgramParametersList().prepend(appConfiguration.MAIN_CLASS_NAME);
params.getProgramParametersList().prepend(Integer.toString(settings.getLastPort()));
// add +1 because idea_rt.jar will be added as the last entry to the classpath
params.getProgramParametersList().prepend(Integer.toString(params.getClassPath().getPathList().size() + 1));
Set<String> paths = new TreeSet<>();
// ui-designer-impl
paths.add(PathUtil.getJarPathForClass(SnapShooter.class));
// appcore-api
paths.add(PathUtil.getJarPathForClass(BaseComponent.class));
// openapi
paths.add(PathUtil.getJarPathForClass(ProjectComponent.class));
// platform-impl
paths.add(PathUtil.getJarPathForClass(DesignerEditorPanelFacade.class));
// UIDesignerCore
paths.add(PathUtil.getJarPathForClass(LwComponent.class));
// forms_rt
paths.add(PathUtil.getJarPathForClass(GridConstraints.class));
// openapi
paths.add(PathUtil.getJarPathForClass(PaletteGroup.class));
// ui-impl
paths.add(PathUtil.getJarPathForClass(LafManagerListener.class));
// action-system-openapi
paths.add(PathUtil.getJarPathForClass(DataProvider.class));
// idea
paths.add(PathUtil.getJarPathForClass(XmlStringUtil.class));
// pom
paths.add(PathUtil.getJarPathForClass(Navigatable.class));
// extensions
paths.add(PathUtil.getJarPathForClass(AreaInstance.class));
// jgoodies
paths.add(PathUtil.getJarPathForClass(FormLayout.class));
paths.addAll(PathManager.getUtilClassPath());
for (String path : paths) {
params.getClassPath().addFirst(path);
}
params.setMainClass("com.intellij.uiDesigner.snapShooter.SnapShooter");
}
}
Aggregations