.onComplete(() -> connection.close()) .throwException())); watcher.start();
private void runTask(final ProjectConnection connection, final Path path, final String task) { synchronized (LOCK) { Map<String, String> xml = new HashMap<>(); try { // clean jaxp XML_PROPS.forEach(p -> xml.put(p, (String) System.getProperties().remove(p))); try { connection.newBuild() .setStandardError(System.err) .setStandardOutput(System.out) .forTasks(task) .run(); } catch (Exception ex) { getLogger().debug("Execution of " + task + " resulted in exception", ex); } } finally { // restore jaxp xml.forEach((k, v) -> { if (v != null) { System.setProperty(k, v); } }); } } }
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; }
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(); } }
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 static BuildLauncher newBuildLauncher(GradleArguments gradleArguments, GradleProgressAttributes progressAttributes) { ProjectConnection connection = openConnection(gradleArguments); BuildEnvironment buildEnvironment = connection.getModel(BuildEnvironment.class); BuildLauncher launcher = connection.newBuild(); describeAndApplyConfiguration(launcher, gradleArguments, buildEnvironment, progressAttributes); return (BuildLauncher) newProxyInstance(connection, launcher); }
static AndroidProject getAndroidProject( final File root, final org.gradle.tooling.model.GradleProject gradleProject) { String path = gradleProject.getPath(); String name = path.substring(1); File childDir = new File(root, name); GradleConnector childConnector = GradleConnector.newConnector().forProjectDirectory(childDir); ProjectConnection childConnection = childConnector.connect(); try { ModelBuilder<AndroidProject> modelBuilder = childConnection .model(AndroidProject.class) .withArguments("-Pandroid.injected.build.model.only.versioned=3"); if (nonNull(modelBuilder)) { return modelBuilder.get(); } return null; } catch (Exception e) { log.debug("not android project", e); return null; } finally { childConnection.close(); } }
@Override public T call() throws Exception { return DefaultModelProvider.this.gradleBuild.withConnection(connection -> connection.getModel(model), monitor); } }, fetchStrategy, cacheKey);
public static TestLauncher newTestLauncher(GradleArguments gradleArguments, GradleProgressAttributes progressAttributes) { ProjectConnection connection = openConnection(gradleArguments); BuildEnvironment buildEnvironment = connection.getModel(BuildEnvironment.class); TestLauncher launcher = connection.newTestLauncher(); describeAndApplyConfiguration(launcher, gradleArguments, buildEnvironment, progressAttributes); return (TestLauncher) newProxyInstance(connection, launcher); }
@Override public Builder action() { // TODO (donat) use cache for this method too return this.delegate.action(); }
@Override public <T> ModelBuilder<T> model(Class<T> modelType) { return new CachingModelBuilder<>(this.delegate.model(modelType), this.cache, modelType); }
public static GradleEffectiveDependencies getEffectiveDependencies(final String projectDirectory) { final GradleEffectiveDependencies gradleEffectiveDependencies = new GradleEffectiveDependencies(); final GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(new File(projectDirectory)); ProjectConnection connection = null; try { connection = connector.connect(); final IdeaProject project = connection.getModel(IdeaProject.class); final DomainObjectSet<? extends IdeaModule> modules = project.getChildren(); for (IdeaModule ideaModule: modules) { final DomainObjectSet<? extends IdeaDependency> dependencies = ideaModule.getDependencies(); for (IdeaDependency ideaDependency : dependencies) { if (ideaDependency instanceof IdeaSingleEntryLibraryDependency) { gradleEffectiveDependencies.addDependency((IdeaSingleEntryLibraryDependency) ideaDependency); } } } } finally { if(connection != null) { connection.close(); } } return gradleEffectiveDependencies; }
private GradleProject findCurrentGradleProject() { final GradleProject rootGradleProject = projectConnection.getModel(GradleProject.class); if (!rootGradleProject.getName().equals(projectName)) { final GradleProject child = findChildProject(rootGradleProject, projectName); if (child != null) { return child; } } return rootGradleProject; }
@Override public <T> BuildActionExecuter<T> action(BuildAction<T> buildAction) { return configureOperation(this.delegate.action(buildAction)); }
@Override public <T> ModelBuilder<T> model(Class<T> modelType) { return configureOperation(this.delegate.model(modelType)); }
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(); } } }
@Override public BuildLauncher newBuild() { return this.delegate.newBuild(); }
@Override public void close() { this.delegate.close(); } }