use of org.gradle.tooling.internal.consumer.DefaultGradleConnector in project spring-boot by spring-projects.
the class GradleIT method test.
private void test(String name, String expected) throws Exception {
File projectDirectory = new File("target/gradleit/" + name);
File javaDirectory = new File("target/gradleit/" + name + "/src/main/java/org/test/");
projectDirectory.mkdirs();
javaDirectory.mkdirs();
File script = new File(projectDirectory, "build.gradle");
FileCopyUtils.copy(new File("src/it/" + name + "/build.gradle"), script);
FileCopyUtils.copy(new File("src/it/" + name + "/src/main/java/org/test/SampleApplication.java"), new File(javaDirectory, "SampleApplication.java"));
GradleConnector gradleConnector = GradleConnector.newConnector();
gradleConnector.useGradleVersion("2.9");
((DefaultGradleConnector) gradleConnector).embedded(true);
ProjectConnection project = gradleConnector.forProjectDirectory(projectDirectory).connect();
project.newBuild().forTasks("clean", "build").setStandardOutput(System.out).setStandardError(System.err).withArguments("-PbootVersion=" + getBootVersion()).run();
Verify.verify(new File("target/gradleit/" + name + "/build/libs/" + name + ".jar"), expected);
}
use of org.gradle.tooling.internal.consumer.DefaultGradleConnector in project intellij-community by JetBrains.
the class AbstractModelBuilderTest method setUp.
@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.addExtraProjectModelClasses(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", "--recompile-scripts", GradleConstants.INIT_SCRIPT_CMD_OPTION, initScript.getAbsolutePath());
allModels = buildActionExecutor.run();
assertNotNull(allModels);
} finally {
connection.close();
}
}
use of org.gradle.tooling.internal.consumer.DefaultGradleConnector in project android by JetBrains.
the class AndroidGradleTargetBuilder method getGradleConnector.
@NotNull
private static GradleConnector getGradleConnector(@NotNull BuilderExecutionSettings executionSettings) {
GradleConnector connector = GradleConnector.newConnector();
if (connector instanceof DefaultGradleConnector) {
DefaultGradleConnector defaultConnector = (DefaultGradleConnector) connector;
if (executionSettings.isEmbeddedModeEnabled()) {
LOG.info("Using Gradle embedded mode.");
defaultConnector.embedded(true);
}
defaultConnector.setVerboseLogging(executionSettings.isVerboseLoggingEnabled());
}
connector.forProjectDirectory(executionSettings.getProjectDir());
File gradleHomeDir = executionSettings.getGradleHomeDir();
if (gradleHomeDir != null) {
connector.useInstallation(gradleHomeDir);
}
File gradleServiceDir = executionSettings.getGradleServiceDir();
if (gradleServiceDir != null) {
connector.useGradleUserHomeDir(gradleServiceDir);
}
return connector;
}
Aggregations