org.gradle.tooling.BuildActionExecuter Java Examples
The following examples show how to use
org.gradle.tooling.BuildActionExecuter.
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: GradleDaemon.java From netbeans with Apache License 2.0 | 6 votes |
private static void doLoadDaemon() { GradleConnector gconn = GradleConnector.newConnector(); ProjectConnection pconn = gconn.forProjectDirectory(LOADER_PROJECT_DIR).connect(); BuildActionExecuter<String> action = pconn.action(DUMMY_ACTION); GradleCommandLine cmd = new GradleCommandLine(); cmd.addSystemProperty(PROP_TOOLING_JAR, TOOLING_JAR); cmd.setFlag(GradleCommandLine.Flag.OFFLINE, true); cmd.addParameter(GradleCommandLine.Parameter.INIT_SCRIPT, INIT_SCRIPT); cmd.configure(action); try { action.run(); } catch (GradleConnectionException | IllegalStateException ex) { // Well for some reason we were not able to load Gradle. // Ignoring that for now } finally { pconn.close(); } }
Example #2
Source File: GradleProjectCache.java From netbeans with Apache License 2.0 | 5 votes |
private static BuildActionExecuter<NbProjectInfo> createInfoAction(ProjectConnection pconn, GradleCommandLine cmd, CancellationToken token, ProgressListener pl) { BuildActionExecuter<NbProjectInfo> ret = pconn.action(new NbProjectInfoAction()); cmd.configure(ret); if (token != null) { ret.withCancellationToken(token); } if (pl != null) { ret.addProgressListener(pl); } return ret; }
Example #3
Source File: AbstractModelBuilderTest.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
@Before public void setUp() throws Exception { assumeThat(gradleVersion, versionMatcherRule.getMatcher()); ensureTempDirCreated(); String methodName = name.getMethodName(); Matcher m = TEST_METHOD_NAME_PATTERN.matcher(methodName); if (m.matches()) { methodName = m.group(1); } testDir = new File(ourTempDir, methodName); FileUtil.ensureExists(testDir); final InputStream buildScriptStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.DEFAULT_SCRIPT_NAME); try { FileUtil.writeToFile( new File(testDir, GradleConstants.DEFAULT_SCRIPT_NAME), FileUtil.loadTextAndClose(buildScriptStream) ); } finally { StreamUtil.closeStream(buildScriptStream); } final InputStream settingsStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.SETTINGS_FILE_NAME); try { if(settingsStream != null) { FileUtil.writeToFile( new File(testDir, GradleConstants.SETTINGS_FILE_NAME), FileUtil.loadTextAndClose(settingsStream) ); } } finally { StreamUtil.closeStream(settingsStream); } GradleConnector connector = GradleConnector.newConnector(); GradleVersion _gradleVersion = GradleVersion.version(gradleVersion); final URI distributionUri = new DistributionLocator().getDistributionFor(_gradleVersion); connector.useDistribution(distributionUri); connector.forProjectDirectory(testDir); int daemonMaxIdleTime = 10; try { daemonMaxIdleTime = Integer.parseInt(System.getProperty("gradleDaemonMaxIdleTime", "10")); } catch (NumberFormatException ignore) {} ((DefaultGradleConnector)connector).daemonMaxIdleTime(daemonMaxIdleTime, TimeUnit.SECONDS); ProjectConnection connection = connector.connect(); try { boolean isGradleProjectDirSupported = _gradleVersion.compareTo(GradleVersion.version("2.4")) >= 0; boolean isCompositeBuildsSupported = isGradleProjectDirSupported && _gradleVersion.compareTo(GradleVersion.version("3.1")) >= 0; final ProjectImportAction projectImportAction = new ProjectImportAction(false, isGradleProjectDirSupported, isCompositeBuildsSupported); projectImportAction.addProjectImportExtraModelProvider(new ClassSetProjectImportExtraModelProvider(getModels())); BuildActionExecuter<ProjectImportAction.AllModels> buildActionExecutor = connection.action(projectImportAction); File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses()); assertNotNull(initScript); String jdkHome = IdeaTestUtil.requireRealJdkHome(); buildActionExecutor.setJavaHome(new File(jdkHome)); buildActionExecutor.setJvmArguments("-Xmx128m", "-XX:MaxPermSize=64m"); buildActionExecutor.withArguments("--info", GradleConstants.INIT_SCRIPT_CMD_OPTION, initScript.getAbsolutePath()); allModels = buildActionExecutor.run(); assertNotNull(allModels); } finally { connection.close(); } }