use of com.intellij.execution.configurations.JavaParameters in project intellij-community by JetBrains.
the class MavenClasspathsAndSearchScopesTest method assertClasspath.
private void assertClasspath(String moduleName, Scope scope, Type type, String... expectedPaths) throws Exception {
createOutputDirectories();
PathsList actualPathsList;
Module module = getModule(moduleName);
if (scope == Scope.RUNTIME) {
JavaParameters params = new JavaParameters();
params.configureByModule(module, type == Type.TESTS ? JavaParameters.CLASSES_AND_TESTS : JavaParameters.CLASSES_ONLY);
actualPathsList = params.getClassPath();
} else {
OrderEnumerator en = OrderEnumerator.orderEntries(module).recursively().withoutSdk().compileOnly();
if (type == Type.PRODUCTION)
en.productionOnly();
actualPathsList = en.classes().getPathsList();
}
assertPaths(expectedPaths, actualPathsList.getPathList());
}
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;
}
}
use of com.intellij.execution.configurations.JavaParameters in project kotlin by JetBrains.
the class KotlinDebuggerTestCase method createJavaParameters.
@Override
protected JavaParameters createJavaParameters(String mainClass) {
JavaParameters parameters = super.createJavaParameters(mainClass);
parameters.getClassPath().add(ForTestCompileRuntime.runtimeJarForTests());
parameters.getClassPath().add(CUSTOM_LIBRARY_JAR);
return parameters;
}
use of com.intellij.execution.configurations.JavaParameters in project intellij-plugins by JetBrains.
the class AbstractFrameworkRunner method createJavaParameters.
@Override
public JavaParameters createJavaParameters(@NotNull OsgiRunConfiguration runConfiguration, @NotNull List<SelectedBundle> bundles) throws ExecutionException {
myRunConfiguration = runConfiguration;
myInstance = myRunConfiguration.getInstanceToUse();
assert myInstance != null : myRunConfiguration;
myIntegrator = FrameworkIntegratorRegistry.getInstance().findIntegratorByInstanceDefinition(myInstance);
assert myIntegrator != null : myInstance;
myInstanceManager = myIntegrator.getFrameworkInstanceManager();
myAdditionalProperties = myRunConfiguration.getAdditionalProperties();
myBundles = bundles;
JavaParameters params = new JavaParameters();
if (myRunConfiguration.isGenerateWorkingDir()) {
myWorkingDir = new File(PathManager.getSystemPath(), "osmorc/run." + System.currentTimeMillis());
} else {
myWorkingDir = new File(myRunConfiguration.getWorkingDir());
}
if (!myWorkingDir.isDirectory() && !myWorkingDir.mkdirs()) {
throw new CantRunException("Cannot create work directory '" + myWorkingDir.getPath() + "'");
}
params.setWorkingDirectory(myWorkingDir);
// only add JDK classes to the classpath, the rest is to be provided by bundles
String jreHome = myRunConfiguration.isUseAlternativeJre() ? myRunConfiguration.getAlternativeJrePath() : null;
JavaParametersUtil.configureProject(myRunConfiguration.getProject(), params, JavaParameters.JDK_ONLY, jreHome);
// class path
Collection<SelectedBundle> systemBundles = myInstanceManager.getFrameworkBundles(myInstance, FrameworkBundleType.SYSTEM);
if (systemBundles.isEmpty()) {
throw new CantRunException("Libraries required to start the framework not found - please check the installation");
}
for (SelectedBundle bundle : systemBundles) {
String path = bundle.getBundlePath();
assert path != null : bundle;
params.getClassPath().add(path);
}
if (GenericRunProperties.isStartConsole(myAdditionalProperties)) {
Collection<SelectedBundle> shellBundles = myInstanceManager.getFrameworkBundles(myInstance, FrameworkBundleType.SHELL);
if (shellBundles.isEmpty()) {
throw new CantRunException("Console requested but no shell bundles can be found - please check the installation");
}
List<SelectedBundle> allBundles = ContainerUtil.newArrayList(shellBundles);
allBundles.addAll(myBundles);
myBundles = allBundles;
}
if (myRunConfiguration.isIncludeAllBundlesInClassPath()) {
for (SelectedBundle bundle : myBundles) {
String path = bundle.getBundlePath();
if (path != null) {
params.getClassPath().add(path);
}
}
}
// runner options
params.setUseDynamicVMOptions(!myBundles.isEmpty());
params.setUseDynamicParameters(!myBundles.isEmpty());
HttpConfigurable.getInstance().getJvmProperties(false, null).forEach(p -> params.getVMParametersList().addProperty(p.first, p.second));
params.getVMParametersList().addParametersString(myRunConfiguration.getVmParameters());
String additionalProgramParams = myRunConfiguration.getProgramParameters();
if (!StringUtil.isEmptyOrSpaces(additionalProgramParams)) {
params.getProgramParametersList().addParametersString(additionalProgramParams);
}
String bootDelegation = GenericRunProperties.getBootDelegation(myAdditionalProperties);
if (!StringUtil.isEmptyOrSpaces(bootDelegation)) {
params.getVMParametersList().addProperty("org.osgi.framework.bootdelegation", bootDelegation);
}
String systemPackages = GenericRunProperties.getSystemPackages(myAdditionalProperties);
if (!StringUtil.isEmptyOrSpaces(systemPackages)) {
params.getVMParametersList().addProperty("org.osgi.framework.system.packages.extra", systemPackages);
}
// framework-specific options
setupParameters(params);
return params;
}
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;
}
Aggregations