private void addRunTask() { JavaExec run = project.getTasks().create(TASK_RUN_NAME, JavaExec.class); run.setDescription("Runs this project as a JVM application"); run.setGroup(APPLICATION_GROUP); JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class); run.setClasspath(javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath()); run.getConventionMapping().map("main", new Callable<Object>() { @Override public Object call() throws Exception { return pluginConvention.getMainClassName(); } }); run.getConventionMapping().map("jvmArgs", new Callable<Object>() { @Override public Object call() throws Exception { return pluginConvention.getApplicationDefaultJvmArgs(); } }); }
private void configureRunTask(final Project project) { final JavaExec run = (JavaExec) project.getTasks().findByName(ApplicationPlugin.TASK_RUN_NAME); final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME); run.getInputs().property("moduleName", module.geName()); run.doFirst(new Action<Task>() { @Override public void execute(Task task) { List<String> args = new ArrayList<>(); args.add("--module-path"); args.add(run.getClasspath().getAsPath()); args.add("--module"); args.add(module.geName() + "/" + run.getMain()); run.setJvmArgs(args); run.setClasspath(project.files()); } }); }
private void mainClassNameFinder(Project project) { FindMainClassTask findMainClassTask = project.getTasks() .create(FIND_MAIN_CLASS_TASK_NAME, FindMainClassTask.class); SourceSet mainSourceSet = SourceSets.findMainSourceSet(project); if (mainSourceSet != null) { findMainClassTask.setMainClassSourceSetOutput(mainSourceSet.getOutput()); } project.getTasks().all(new Action<Task>() { @Override public void execute(Task task) { if (task instanceof JavaExec || task instanceof CreateStartScripts) { task.dependsOn(FIND_MAIN_CLASS_TASK_NAME); } } }); }
static FileCollection fromLocalClassloader() { Set<File> files = new LinkedHashSet<>(); Consumer<Class<?>> addPeerClasses = clazz -> { URLClassLoader urlClassloader = (URLClassLoader) clazz.getClassLoader(); for (URL url : urlClassloader.getURLs()) { String name = url.getFile(); if (name != null) { files.add(new File(name)); } } }; // add the classes that goomph needs addPeerClasses.accept(JavaExecable.class); // add the gradle API addPeerClasses.accept(JavaExec.class); return new SimpleFileCollection(files); }
private void addAgent(Project project, JavaExec exec) { project.getLogger().debug("Attaching to: " + exec); if (this.agent != null) { project.getLogger().info("Attaching agent: " + this.agent); exec.jvmArgs("-javaagent:" + this.agent.getAbsolutePath()); if (this.noverify != null && this.noverify) { exec.jvmArgs("-noverify"); } Iterable<?> defaultJvmArgs = exec.getConventionMapping() .getConventionValue(null, "jvmArgs", false); if (defaultJvmArgs != null) { exec.jvmArgs(defaultJvmArgs); } } }
private JavaExec findRunTask(Project project) { Task runTask = project.getTasks().findByName("run"); if (runTask instanceof JavaExec) { return (JavaExec) runTask; } return null; }
private void configureAppPlugin() { final ApplicationPluginConvention convention = this.project.getConvention().findPlugin( ApplicationPluginConvention.class ); convention.setMainClassName( "io.purplejs.boot.MainApp" ); final JavaExec runTask = (JavaExec) this.project.getTasks().getByName( ApplicationPlugin.TASK_RUN_NAME ); runTask.systemProperty( "io.purplejs.runMode", "dev" ); final String devDirs = new File( this.project.getProjectDir(), "src/main/resources" ).getAbsolutePath(); runTask.systemProperty( "io.purplejs.devSourceDirs", devDirs ); }
public GradleJavaExec(Project project, String name, File executableJar) { javaExec = project.getTasks().create(name, JavaExec.class); javaExec.setWorkingDir(project.getProjectDir()); // Because JavaExec doesn't have proper support for exec'ing runnable jars, use this hack, // saying the main class is "-jar", to make it work javaExec.setMain("-jar"); javaExec.args(executableJar.getAbsolutePath()); }
@Override public JavaExec setArgs(Iterable<?> applicationArgs) { throw argsUnsupportOperationException(); }
private void addAgent(Project project, Task task) { if (task instanceof JavaExec) { addAgent(project, (JavaExec) task); } }
private String findMainClass() { Project project = getProject(); String mainClass = null; // Try the SpringBoot extension setting SpringBootPluginExtension bootExtension = project.getExtensions() .getByType(SpringBootPluginExtension.class); if (bootExtension.getMainClass() != null) { mainClass = bootExtension.getMainClass(); } ApplicationPluginConvention application = (ApplicationPluginConvention) project .getConvention().getPlugins().get("application"); if (mainClass == null && application != null) { // Try the Application extension setting mainClass = application.getMainClassName(); } JavaExec runTask = findRunTask(project); if (mainClass == null && runTask != null) { mainClass = runTask.getMain(); } if (mainClass == null) { Task bootRunTask = project.getTasks().findByName("bootRun"); if (bootRunTask != null) { mainClass = (String) bootRunTask.property("main"); } } if (mainClass == null) { // Search if (this.mainClassSourceSetOutput != null) { project.getLogger().debug("Looking for main in: " + this.mainClassSourceSetOutput.getClassesDir()); try { mainClass = MainClassFinder.findSingleMainClass( this.mainClassSourceSetOutput.getClassesDir()); project.getLogger().info("Computed main class: " + mainClass); } catch (IOException ex) { throw new IllegalStateException("Cannot find main class", ex); } } } project.getLogger().info("Found main: " + mainClass); if (bootExtension.getMainClass() == null) { bootExtension.setMainClass(mainClass); } if (application != null && application.getMainClassName() == null) { application.setMainClassName(mainClass); } if (runTask != null && !runTask.hasProperty("main")) { runTask.setMain(mainClass); } return mainClass; }