.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; }
@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; }
@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; }
public void applyTo(GradleConnector connector) { connector.forProjectDirectory(this.rootDir); connector.useGradleUserHomeDir(this.gradleUserHome); this.gradleDistribution.apply(connector); }
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(); }
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(); }
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(); } }
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(); } }
.forProjectDirectory(new File(conf.path())) .connect();
GradleConnector c = GradleConnector.newConnector(); c.useGradleVersion(Optional.ofNullable(gradleVersion).orElse(GradleVersion.current().getVersion())) .forProjectDirectory(new File(projectDirectory));
/* * 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(); } }
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(); } }
.forProjectDirectory(project.getProjectDir()) .connect();
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(); } } }