.onComplete(() -> connection.close()) .throwException())); watcher.start();
public NbProjectInfo loadInfo(File project, String... extraArgs) { NbProjectInfo ret = null; GradleConnector gconn = GradleConnector.newConnector(); ProjectConnection pconn = gconn.forProjectDirectory(project).connect(); BuildActionExecuter<NbProjectInfo> action = pconn.action(new NbProjectInfoAction()); action.setJvmArguments( "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006", "-DNETBEANS_TOOLING_JAR=" + buildDir + "/libs/netbeans-gradle-tooling.jar" ); ArrayList<String> args = new ArrayList<>(); args.add("-I"); args.add(buildDir + "/resources/main/nb-tooling.gradle"); args.addAll(Arrays.asList(extraArgs)); action.withArguments(args.toArray(new String[args.size()])); try { ret = action.run(); } catch (GradleConnectionException | IllegalStateException ex) { System.err.println("Failed to retrieve project information for: " + project); ex.printStackTrace(); } finally { try { pconn.close(); } catch (NullPointerException ex) { } } return ret; }
@Override public void close() { this.delegate.close(); } }
@Override public void close() { this.delegate.close(); }
public void close() { connection.close(); }
@Override public void onComplete(final Void result) { try { outputStream.close(); inputStream.close(); } catch (IOException e) { log.error(e.getMessage(), e); } finally { projectConnection.close(); } }
@Override public void onFailure(final GradleConnectionException failure) { try { log.catching(failure.getCause()); outputStream.close(); inputStream.close(); } catch (IOException e) { log.error(e.getMessage(), e); } finally { projectConnection.close(); } } }
task run << { ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File("someProjectFolder")).connect(); try { BuildLauncher build = connection.newBuild(); build.setJvmArguments("-javaagent:/home/audrius/org.springframework.instrument-3.0.5.RELEASE.jar") build.forTasks("jettyRun").run(); } finally { connection.close(); } }
private void runPrepareCompileTask() throws IOException { if (!this.prepareCompileTask.isEmpty()) { final ProjectConnection connection = this.getProjectConnection(); try { final String[] tasks = prepareCompileTask.toArray(new String[0]); final BuildLauncher buildLauncher = connection.newBuild(); log.info("project {} run tasks:{}", this.name, tasks); GradleProject.setBuildJVMArgs(buildLauncher); buildLauncher.forTasks(tasks).run(); } finally { connection.close(); } } }
private void runPrepareTestCompileTask() throws IOException { if (!this.prepareTestCompileTask.isEmpty()) { final ProjectConnection connection = this.getProjectConnection(); try { final String[] tasks = prepareTestCompileTask.toArray(new String[0]); final BuildLauncher buildLauncher = connection.newBuild(); log.info("project {} run tasks:{}", this.name, tasks); GradleProject.setBuildJVMArgs(buildLauncher); buildLauncher.forTasks(tasks).run(); } finally { connection.close(); } } }
private void closeConnection() { this.connection.close(); if (ideFriendlyCustomActionClassLoader != null) { try { ideFriendlyCustomActionClassLoader.close(); } catch (IOException e) { CorePlugin.logger().error("Can't close URL class loader", e); } } }
GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(new File(".")); // project dir ProjectConnection connection = connector.connect(); try { // Load the model for the project GradleProject project = connection.getModel(GradleProject.class); System.out.println("Project: " + project.getName()); System.out.println("Tasks:"); for (Task task : project.getTasks()) { System.out.println(" " + task.getName()); } } finally { // Clean up connection.close(); }
public boolean build(String ...tasks) { ProjectConnection connection = connector.connect(); BuildLauncher build = connection.newBuild(); if (tasks.length > 0) { build.forTasks(tasks); } try { build.run(); }finally { connection.close(); } return true; }
@Override public void runInToolingApi(CancellationTokenSource tokenSource, IProgressMonitor monitor) throws Exception { // TODO (donat) use AutoCloseable once we update to Tooling API 5.0 ProjectConnection connection = IdeAttachedProjectConnection.newInstance(tokenSource, getGradleArguments(), monitor); if (isSynchronizing()) { connection = new CachingProjectConnection(connection, DefaultGradleBuild.this.projectConnectionCache); } try { this.result = this.action.apply(connection); } finally { connection.close(); } }
protected byte[] runTasks(String... tasks) { ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File(InputConfiguration.get().getAbsolutePathToProjectRoot())).connect(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LOGGER.info("Run gradle tasks: {}", String.join(" ", tasks)); try { BuildLauncher build = connection.newBuild(); build.forTasks(tasks); build.setStandardOutput(outputStream); build.setStandardError(outputStream); build.run(); } catch (Exception e) { throw new RuntimeException(e); } finally { connection.close(); } return outputStream.toByteArray(); }
public <T, E extends Exception> T executeInProject(File projectDirectory, GradleProjectExecution<T, E> execution) throws E { ProjectConnection connection = getConnector().forProjectDirectory(projectDirectory).connect(); try { return execution.execute(projectDirectory, connection); } finally { connection.close(); } }
/** * Proceeds Gradle actions on this project. * @param configurator the Gradle action configurator * @return this * @see #gradle(String...) */ public TSelf gradle(TryConsumer<? super GradleAdapter, IOException> configurator) { GradleConnector connector = GradleConnector.newConnector() .forProjectDirectory(getDirectory().toFile()); Optional.ofNullable(property(KEY_GRADLE_VERSION)) .ifPresent(it -> { LOG.debug("using Gradle: {}", it); connector.useGradleVersion(it); }); ProjectConnection connection = connector.connect(); try { return configure(new GradleAdapter(this, connection), configurator); } finally { connection.close(); } }
/* * perform Gradle tasks such as compile, build, test */ public static void performGradleTasks(String path, String ... tasks) { GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(new File(path)); ProjectConnection connection = connector.connect(); try { // Configure the build BuildLauncher launcher = connection.newBuild(); launcher.forTasks(tasks); launcher.setStandardOutput(System.out); launcher.setStandardError(System.err); // Run the build launcher.run(); } finally { // Clean up connection.close(); } }
public void run(final File projectFolder, final ResultHandler<? super Void> resultHandler, final Consumer<BuildLauncher> configClosure) { final ProjectConnection connector = GradleConnector.newConnector().useGradleVersion(GradleHelper.GRADLE_VERSION).forProjectDirectory(projectFolder).connect(); try { final BuildLauncher build = connector.newBuild(); final ProgressListener _function = (ProgressEvent event) -> { GradleHelper.logger.debug("Gradle build event=\'{}\'", event.getDisplayName()); }; build.addProgressListener(_function, OperationType.values()); configClosure.accept(build); if ((resultHandler != null)) { build.run(resultHandler); } else { build.run(); } } finally { connector.close(); } }
private static void runTestForProject( String gradleVersion, File projectDir, ProjectConnectionTask task) throws Exception { if (projectDir == null) throw new NullPointerException("projectDir"); if (task == null) throw new NullPointerException("task"); GradleConnector connector = GradleConnector.newConnector(); connector.useGradleVersion(gradleVersion); connector.forProjectDirectory(projectDir); if (connector instanceof DefaultGradleConnector) { ((DefaultGradleConnector)connector).daemonMaxIdleTime(60, TimeUnit.SECONDS); } ProjectConnection connection = connector.connect(); try { task.doTask(connection); } finally { connection.close(); } }