Java Code Examples for org.gradle.tooling.GradleConnector#useInstallation()
The following examples show how to use
org.gradle.tooling.GradleConnector#useInstallation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GradleBuildComparison.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private ProjectConnection createProjectConnection(ComparableGradleBuildExecuter executer) { GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(executer.getSpec().getProjectDir()); File gradleUserHomeDir = gradle.getStartParameter().getGradleUserHomeDir(); if (gradleUserHomeDir != null) { connector.useGradleUserHomeDir(gradleUserHomeDir); } GradleVersion gradleVersion = executer.getGradleVersion(); if (gradleVersion.equals(GradleVersion.current())) { connector.useInstallation(gradle.getGradleHomeDir()); } else { connector.useGradleVersion(gradleVersion.getVersion()); } return connector.connect(); }
Example 2
Source File: GradleBuildComparison.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private ProjectConnection createProjectConnection(ComparableGradleBuildExecuter executer) { GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(executer.getSpec().getProjectDir()); File gradleUserHomeDir = gradle.getStartParameter().getGradleUserHomeDir(); if (gradleUserHomeDir != null) { connector.useGradleUserHomeDir(gradleUserHomeDir); } GradleVersion gradleVersion = executer.getGradleVersion(); if (gradleVersion.equals(GradleVersion.current())) { connector.useInstallation(gradle.getGradleHomeDir()); } else { connector.useGradleVersion(gradleVersion.getVersion()); } return connector.connect(); }
Example 3
Source File: GradleBuildComparison.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private ProjectConnection createProjectConnection(ComparableGradleBuildExecuter executer) { GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(executer.getSpec().getProjectDir()); File gradleUserHomeDir = gradle.getStartParameter().getGradleUserHomeDir(); if (gradleUserHomeDir != null) { connector.useGradleUserHomeDir(gradleUserHomeDir); } GradleVersion gradleVersion = executer.getGradleVersion(); if (gradleVersion.equals(GradleVersion.current())) { connector.useInstallation(gradle.getGradleHomeDir()); } else { connector.useGradleVersion(gradleVersion.getVersion()); } return connector.connect(); }
Example 4
Source File: GradleBuildComparison.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private ProjectConnection createProjectConnection(ComparableGradleBuildExecuter executer) { GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(executer.getSpec().getProjectDir()); File gradleUserHomeDir = gradle.getStartParameter().getGradleUserHomeDir(); if (gradleUserHomeDir != null) { connector.useGradleUserHomeDir(gradleUserHomeDir); } GradleVersion gradleVersion = executer.getGradleVersion(); if (gradleVersion.equals(GradleVersion.current())) { connector.useInstallation(gradle.getGradleHomeDir()); } else { connector.useGradleVersion(gradleVersion.getVersion()); } return connector.connect(); }
Example 5
Source File: Main.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public static void main(String[] args) { // Configure the connector and create the connection GradleConnector connector = GradleConnector.newConnector(); if (args.length > 0) { connector.useInstallation(new File(args[0])); if (args.length > 1) { connector.useGradleUserHomeDir(new File(args[1])); } } connector.forProjectDirectory(new File(".")); ProjectConnection connection = connector.connect(); try { // Configure the build BuildLauncher launcher = connection.newBuild(); launcher.forTasks("help"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); launcher.setStandardOutput(outputStream); launcher.setStandardError(outputStream); // Run the build launcher.run(); } finally { // Clean up connection.close(); } }
Example 6
Source File: Main.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public static void main(String[] args) { // Configure the connector and create the connection GradleConnector connector = GradleConnector.newConnector(); if (args.length > 0) { connector.useInstallation(new File(args[0])); if (args.length > 1) { connector.useGradleUserHomeDir(new File(args[1])); } } connector.forProjectDirectory(new File(".")); ProjectConnection connection = connector.connect(); try { // Configure the build BuildLauncher launcher = connection.newBuild(); launcher.forTasks("help"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); launcher.setStandardOutput(outputStream); launcher.setStandardError(outputStream); // Run the build launcher.run(); } finally { // Clean up connection.close(); } }
Example 7
Source File: Main.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public static void main(String[] args) { // Configure the connector and create the connection GradleConnector connector = GradleConnector.newConnector(); if (args.length > 0) { connector.useInstallation(new File(args[0])); if (args.length > 1) { connector.useGradleUserHomeDir(new File(args[1])); } } connector.forProjectDirectory(new File(".")); ProjectConnection connection = connector.connect(); try { // Configure the build BuildLauncher launcher = connection.newBuild(); launcher.forTasks("help"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); launcher.setStandardOutput(outputStream); launcher.setStandardError(outputStream); // Run the build launcher.run(); } finally { // Clean up connection.close(); } }
Example 8
Source File: Main.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public static void main(String[] args) { // Configure the connector and create the connection GradleConnector connector = GradleConnector.newConnector(); if (args.length > 0) { connector.useInstallation(new File(args[0])); if (args.length > 1) { connector.useGradleUserHomeDir(new File(args[1])); } } connector.forProjectDirectory(new File(".")); ProjectConnection connection = connector.connect(); try { // Configure the build BuildLauncher launcher = connection.newBuild(); launcher.forTasks("help"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); launcher.setStandardOutput(outputStream); launcher.setStandardError(outputStream); // Run the build launcher.run(); } finally { // Clean up connection.close(); } }
Example 9
Source File: ExecuteGoal.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public void run() { cancellation.set(false); cancellationReference.set(new DefaultBuildCancellationToken()); GradleConnector connector = GradleConnector.newConnector(); connector.useInstallation(gradleHome); connector.forProjectDirectory(FileUtil.toFile(project.getProjectDirectory())); try (ProjectConnection connection = connector.connect()) { BuildLauncher buildLauncher = connection.newBuild(); buildLauncher.forTasks(taskInfo.getName()); buildLauncher.withCancellationToken(this); ProjectConfigurationProvider pcp = project.getLookup().lookup(ProjectConfigurationProvider.class); if (pcp != null && pcp.getActiveConfiguration() != null) { buildLauncher.addArguments("-Pandroid.profile=" + pcp.getActiveConfiguration()); } if (argsConfiguration != null) { buildLauncher.addArguments(argsConfiguration.getJvmArguments()); } if (jvmConfiguration == null) { buildLauncher.addJvmArguments("-Xms800m", "-Xmx2000m"); } else { buildLauncher.addJvmArguments(jvmConfiguration.getJvmArguments()); } InputOutput io = project.getLookup().lookup(InputOutput.class); if (io != null) { io.show(ImmutableSet.of(ShowOperation.OPEN, ShowOperation.MAKE_VISIBLE)); io.getOut().print("\n\r"); io.getOut().print("\n\r"); io.getOut().print("\n\r"); io.getOut().print("\n\r"); io.getOut().println(BLUE + "Executing task: " + taskInfo.getName() + BLACK); io.getOut().print("\n\r"); io.getOut().print("\n\r"); CustomWriterOutputStream cwos = new CustomWriterOutputStream(io.getOut(), "UTF-8"); buildLauncher.setStandardOutput(cwos); buildLauncher.setStandardError(cwos); buildLauncher.setColorOutput(true); } final ProgressHandle progressHandle = ProgressHandleFactory.createSystemHandle(project.getProjectDirectory().getName() + " : " + taskInfo.getDescription(), this); progressHandle.start(); buildLauncher.addProgressListener(new ProgressListener() { @Override public void statusChanged(ProgressEvent event) { progressHandle.progress(event.getDisplayName()); } }); try { buildLauncher.run(); } catch (GradleConnectionException | IllegalStateException gradleConnectionException) { if (!(gradleConnectionException instanceof BuildCancelledException)) { Exceptions.printStackTrace(gradleConnectionException); } } progressHandle.finish(); ModelRefresh modelRefresh = project.getLookup().lookup(ModelRefresh.class); if (modelRefresh != null) { modelRefresh.refreshModels(); } } catch (Exception e) { Exceptions.printStackTrace(e); } }
Example 10
Source File: GradleHandlerImpl.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
private void deserializeModels() { cancellation.set(false); cancellationReference.set(new DefaultBuildCancellationToken()); GradleHome gradleHome = lookupResult.allInstances().iterator().next(); if (gradleHome.getStatus() == GradleDownloader.Status.OK) { synchronized (gradleLocations) { gradleLocations.put(project, gradleHome); } // modelContent.set(Collections.emptyList(), null); GradleConnector connector = GradleConnector.newConnector(); connector.useInstallation(gradleHome.getGradleHome()); connector.forProjectDirectory(FileUtil.toFile(project.getProjectDirectory())); try (ProjectConnection connection = connector.connect()) { List<Object> modelList = new ArrayList<>(); for (Class model : models) { ModelBuilder modelBuilder = connection.model(model); modelBuilder.withCancellationToken(this); //Emulate Android studio modelBuilder.addArguments("-Pandroid.injected.build.model.only.versioned=3"); //Prepare load of plugin to retreive tasks from Gradle modelBuilder.addJvmArguments("-DANDROID_TOOLING_JAR=" + TOOLING_JAR); modelBuilder.addArguments("-I"); modelBuilder.addArguments(INIT_SCRIPT); if (argsConfiguration != null) { modelBuilder.addArguments(argsConfiguration.getJvmArguments()); } if (jvmConfiguration == null) { modelBuilder.addJvmArguments("-Xms800m", "-Xmx2000m"); } else { modelBuilder.addJvmArguments(jvmConfiguration.getJvmArguments()); } InputOutput io = project.getLookup().lookup(InputOutput.class); if (io != null) { io.show(ImmutableSet.of(ShowOperation.OPEN, ShowOperation.MAKE_VISIBLE)); io.getOut().print("\n\r"); io.getOut().print("\n\r"); io.getOut().print("\n\r"); io.getOut().print("\n\r"); io.getOut().println(BLUE + "Deserializing model: " + model.getSimpleName() + BLACK); io.getOut().print("\n\r"); io.getOut().print("\n\r"); CustomWriterOutputStream cwos = new CustomWriterOutputStream(io.getOut(), "UTF-8"); modelBuilder.setStandardOutput(cwos); modelBuilder.setStandardError(cwos); modelBuilder.setColorOutput(true); } final ProgressHandle progressHandle = ProgressHandleFactory.createSystemHandle(project.getProjectDirectory().getName() + ": Loading Gradle model..", this); progressHandle.start(); modelBuilder.addProgressListener(new ProgressListener() { @Override public void statusChanged(ProgressEvent event) { progressHandle.progress(event.getDisplayName()); } }); try { modelList.add(modelBuilder.get()); } catch (GradleConnectionException | IllegalStateException gradleConnectionException) { if (!(gradleConnectionException instanceof BuildCancelledException)) { Exceptions.printStackTrace(gradleConnectionException); } } progressHandle.finish(); } modelContent.set(modelList, null); } catch (Exception e) { e.printStackTrace(); } } }