getLogger().info("watching directories {}", Arrays.asList(watchDirs)); connection = GradleConnector.newConnector() .useInstallation(project.getGradle().getGradleHomeDir()) .forProjectDirectory(project.getRootDir()) .connect();
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; }
GradleConnector c = GradleConnector.newConnector(); getLog().info("jvmArgs: " + args); getLog().info( "gradleProjectDirectory: " + getGradleProjectDirectory().getAbsolutePath()); c = c.useGradleVersion(gradleVersion).forProjectDirectory( getGradleProjectDirectory()); "gradleInstallation: " + gradleInstallationDir.getAbsolutePath()); c = c.useInstallation(gradleInstallationDir); "gradleUserHome: " + gradleUserHomeDir.getAbsolutePath()); c = c.useGradleUserHomeDir(gradleUserHomeDir); c = c.useDistribution(new URI(gradleDistribution)); connection = c.connect();
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(); } }
@Override protected GradleConnector initialValue() { logger.info("Starting Gradle connector"); GradleConnector connector = GradleConnector.newConnector(); if (!Strings.isNullOrEmpty(gradleVersion)) { if (VERSION_NUMBER_PATTERN.matcher(gradleVersion).matches()) { logger.debug("Using Gradle version {}", gradleVersion); connector.useGradleVersion(gradleVersion); } else { boolean validUri = false; validUri = true; logger.debug("Using Gradle distribution from {}", gradleDistribution); connector.useDistribution(gradleDistribution); File gradleInstallation = new File(gradleVersion); logger.debug("Using Gradle installation {}", gradleInstallation); connector.useInstallation(gradleInstallation); connector.useGradleUserHomeDir(gradleHome);
private static ProjectConnection openConnection(GradleArguments gradleArguments) { GradleConnector connector = GradleConnector.newConnector(); gradleArguments.applyTo(connector); return connector.connect(); }
public void applyTo(GradleConnector connector) { connector.forProjectDirectory(this.rootDir); connector.useGradleUserHomeDir(this.gradleUserHome); this.gradleDistribution.apply(connector); }
@Override public DistributionConfigurationStage forProjectDirectory(final File projectDir) { Validate.notNull(projectDir, "Project directory file can not be null!"); final File absoluteFile = projectDir.getAbsoluteFile(); if (!absoluteFile.exists()) { throw new IllegalArgumentException("Given project dir do not exist: " + absoluteFile); } else if (!absoluteFile.isDirectory()) { throw new IllegalArgumentException("Given project dir is not a directory" + absoluteFile); } projectName = absoluteFile.getName(); connector.forProjectDirectory(absoluteFile); return this; }
private BuildLauncher getBuildLauncher() { if (buildLauncher == null) { projectConnection = connector.connect(); buildLauncher = projectConnection.newBuild(); } return buildLauncher; }
@Override public ConfigurationStage useGradleVersion(final String version) { connector.useGradleVersion(version); return this; }
@Override public void apply(GradleConnector connector) { connector.useInstallation(this.location); }
@Override public ConfigurationStage useGradleUserHomeDir(final File gradleUserHomeDir) { connector.useGradleUserHomeDir(gradleUserHomeDir); return this; }
public synchronized ProjectConnection getConnection() { if (connection == null) { this.connection = GradleConnector.newConnector().forProjectDirectory(this.project.getRootDir()).connect(); } return this.connection; }
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 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); }
@Override public DistributionConfigurationStage forProjectDirectory(final File projectDir) { Validate.notNull(projectDir, "Project directory file can not be null!"); final File absoluteFile = projectDir.getAbsoluteFile(); if (!absoluteFile.exists()) { throw new IllegalArgumentException("Given project dir do not exist: " + absoluteFile); } else if (!absoluteFile.isDirectory()) { throw new IllegalArgumentException("Given project dir is not a directory" + absoluteFile); } projectName = absoluteFile.getName(); connector.forProjectDirectory(absoluteFile); return this; }
private BuildLauncher getBuildLauncher() { if (buildLauncher == null) { projectConnection = connector.connect(); buildLauncher = projectConnection.newBuild(); } return buildLauncher; }
@Override public ConfigurationStage useGradleVersion(final String version) { connector.useGradleVersion(version); return this; }
@Override public ConfigurationStage useInstallation(final File gradleHome) { connector.useInstallation(gradleHome); return this; }
@Override public ConfigurationStage useGradleUserHomeDir(final File gradleUserHomeDir) { connector.useGradleUserHomeDir(gradleUserHomeDir); return this; }