use of org.jetbrains.plugins.groovy.runner.GroovyScriptRunner 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());
}
};
}
Aggregations