use of com.intellij.execution.RunnerAndConfigurationSettings 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.RunnerAndConfigurationSettings in project intellij-community by JetBrains.
the class GroovyScriptRunConfigurationProducer method createConfigurationByElement.
@Override
protected RunnerAndConfigurationSettings createConfigurationByElement(final Location location, final ConfigurationContext context) {
final PsiElement element = location.getPsiElement();
final PsiFile file = element.getContainingFile();
if (!(file instanceof GroovyFile)) {
return null;
}
GroovyFile groovyFile = (GroovyFile) file;
final PsiClass aClass = GroovyRunnerPsiUtil.getRunningClass(location.getPsiElement());
if (aClass instanceof GroovyScriptClass || GroovyRunnerPsiUtil.isRunnable(aClass)) {
final RunnerAndConfigurationSettings settings = createConfiguration(aClass);
if (settings != null) {
mySourceElement = element;
final GroovyScriptRunConfiguration configuration = (GroovyScriptRunConfiguration) settings.getConfiguration();
GroovyScriptUtil.getScriptType(groovyFile).tuneConfiguration(groovyFile, configuration, location);
return settings;
}
}
if (file.getText().contains("@Grab")) {
ApplicationConfigurationProducer producer = new ApplicationConfigurationProducer();
ConfigurationFromContext settings = producer.createConfigurationFromContext(context);
if (settings != null) {
PsiElement src = settings.getSourceElement();
mySourceElement = src;
return createConfiguration(src instanceof PsiMethod ? ((PsiMethod) src).getContainingClass() : (PsiClass) src);
}
return null;
} else {
return null;
}
}
use of com.intellij.execution.RunnerAndConfigurationSettings in project intellij-community by JetBrains.
the class GroovyScriptRunConfigurationProducer method findExistingByElement.
@Override
protected RunnerAndConfigurationSettings findExistingByElement(Location location, @NotNull List<RunnerAndConfigurationSettings> existingConfigurations, ConfigurationContext context) {
for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) {
final RunConfiguration configuration = existingConfiguration.getConfiguration();
final GroovyScriptRunConfiguration existing = (GroovyScriptRunConfiguration) configuration;
final String path = existing.getScriptPath();
if (path != null) {
final PsiFile file = location.getPsiElement().getContainingFile();
if (file instanceof GroovyFile) {
final VirtualFile vfile = file.getVirtualFile();
if (vfile != null && FileUtil.toSystemIndependentName(path).equals(ScriptFileUtil.getScriptFilePath(vfile))) {
if (!((GroovyFile) file).isScript() || GroovyScriptUtil.getScriptType((GroovyFile) file).isConfigurationByLocation(existing, location)) {
return existingConfiguration;
}
}
}
}
}
return null;
}
use of com.intellij.execution.RunnerAndConfigurationSettings in project intellij-community by JetBrains.
the class XsltConfigurationProducer method createConfigurationByElement.
@Override
protected RunnerAndConfigurationSettings createConfigurationByElement(Location location, ConfigurationContext context) {
final XmlFile file = PsiTreeUtil.getParentOfType(location.getPsiElement(), XmlFile.class, false);
if (file != null && file.isPhysical() && XsltSupport.isXsltFile(file)) {
myFile = file;
final Project project = myFile.getProject();
final RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createRunConfiguration(myFile.getName(), getConfigurationFactory());
((XsltRunConfiguration) settings.getConfiguration()).initFromFile(myFile);
return settings;
}
return null;
}
use of com.intellij.execution.RunnerAndConfigurationSettings in project intellij-community by JetBrains.
the class UploadApplicationAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
RunnerAndConfigurationSettings configurationToRun = getConfigurationToRun(project);
if (configurationToRun != null) {
ProgramRunnerUtil.executeConfiguration(project, configurationToRun, DefaultRunExecutor.getRunExecutorInstance());
} else {
AppEngineCloudType serverType = AppEngineCloudType.getInstance();
List<RemoteServer<AppEngineServerConfiguration>> servers = RemoteServersManager.getInstance().getServers(serverType);
DeploymentConfigurationManager.getInstance(project).createAndRunConfiguration(serverType, ContainerUtil.getFirstItem(servers));
}
}
Aggregations