getLogger().info("watching directories {}", Arrays.asList(watchDirs)); connection = GradleConnector.newConnector() .useInstallation(project.getGradle().getGradleHomeDir()) .forProjectDirectory(project.getRootDir())
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; }
private static ProjectConnection openConnection(GradleArguments gradleArguments) { GradleConnector connector = GradleConnector.newConnector(); gradleArguments.applyTo(connector); return connector.connect(); }
@Override protected GradleConnector initialValue() { logger.info("Starting Gradle connector"); GradleConnector connector = GradleConnector.newConnector(); if (!Strings.isNullOrEmpty(gradleVersion)) { if (VERSION_NUMBER_PATTERN.matcher(gradleVersion).matches()) {
public synchronized ProjectConnection getConnection() { if (connection == null) { this.connection = GradleConnector.newConnector().forProjectDirectory(this.project.getRootDir()).connect(); } return this.connection; }
ProjectConnection getProjectConnection() { final String gradleVersion = Config.load().getGradleVersion(); GradleConnector connector; if (gradleVersion.isEmpty()) { connector = GradleConnector.newConnector().forProjectDirectory(this.rootProject); } else { log.debug("use gradle version:'{}'", gradleVersion); connector = GradleConnector.newConnector() .useGradleVersion(gradleVersion) .forProjectDirectory(this.rootProject); } if (connector instanceof DefaultGradleConnector) { final DefaultGradleConnector defaultGradleConnector = (DefaultGradleConnector) connector; defaultGradleConnector.daemonMaxIdleTime(1, TimeUnit.HOURS); } return connector.connect(); }
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(); }
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(); } }
/** * 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(); } }
private Archive<?> runBuild(GradleBuild conf) { .newConnector() .forProjectDirectory(new File(conf.path())) .connect();
@Override public CompileResult execute(Transport t) { GradleConnector c = GradleConnector.newConnector(); c.useGradleVersion(Optional.ofNullable(gradleVersion).orElse(GradleVersion.current().getVersion())) .forProjectDirectory(new File(projectDirectory));
ProjectConnection connection = GradleConnector.newConnector() .useGradleUserHomeDir(gradle.getGradleUserHomeDir()) .useInstallation(gradle.getGradleHomeDir())
public static ProjectConnection newInstance(CancellationTokenSource tokenSource, GradleArguments gradleArguments, IProgressMonitor monitor) { GradleConnector connector = GradleConnector.newConnector(); gradleArguments.applyTo(connector); ProjectConnection connection = connector.connect(); GradleProgressAttributes progressAttributes = GradleProgressAttributes.builder(tokenSource, monitor) .forBackgroundProcess() .withFullProgress() .build(); return new IdeAttachedProjectConnection(connection, gradleArguments, progressAttributes); }
ProjectConnection connection = GradleConnector.newConnector() .forProjectDirectory(new File(projectPath)) .connect();
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(); } }
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 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(); } }
out.flush(); connection = GradleConnector.newConnector() .useInstallation(project.getGradle().getGradleHomeDir()) .forProjectDirectory(project.getProjectDir())
GradleConnector c = GradleConnector.newConnector(); getLog().info("jvmArgs: " + args); getLog().info(
public <T> T getModel(File projectDir, Class<T> modelType) throws GradleException { ProjectConnection connection = null; try { GradleConnector gradleConnector = GradleConnector.newConnector().forProjectDirectory(projectDir); /* * Shut down Gradle daemons right away. Necessary project data is * queried once and then cached, hence no need need to have the * daemon running */ ((DefaultGradleConnector) gradleConnector).daemonMaxIdleTime(1, TimeUnit.SECONDS); configuration.configure(gradleConnector); // Use patched Gradle 4.4 distribution or higher as a workaround for https://github.com/gradle/gradle/issues/2483 gradleConnector.useGradleVersion("4.6"); connection = gradleConnector.connect(); return connection.getModel(modelType); } catch (GradleConnectionException e) { Log.log(e); throw new GradleException(e); } finally { if (connection != null) { connection.close(); } } }