use of org.gradle.tooling.internal.consumer.DefaultGradleConnector in project spring-boot by spring-projects.
the class ProjectCreator method createProject.
public ProjectConnection createProject(String name) throws IOException {
File projectDirectory = new File("target/" + name);
projectDirectory.mkdirs();
File gradleScript = new File(projectDirectory, "build.gradle");
if (new File("src/test/resources", name).isDirectory()) {
FileSystemUtils.copyRecursively(new File("src/test/resources", name), projectDirectory);
} else {
FileCopyUtils.copy(new File("src/test/resources/" + name + ".gradle"), gradleScript);
}
GradleConnector gradleConnector = GradleConnector.newConnector();
gradleConnector.useGradleVersion(this.gradleVersion);
((DefaultGradleConnector) gradleConnector).embedded(true);
return gradleConnector.forProjectDirectory(projectDirectory).connect();
}
use of org.gradle.tooling.internal.consumer.DefaultGradleConnector in project gradle by gradle.
the class Main method fetch.
private static void fetch(File buildDir, File gradleInstallDir, boolean embedded) {
System.out.println("* Fetching model for " + buildDir);
System.out.println("* Using tooling API " + GradleVersion.current().getVersion());
Timer timer = new Timer();
GradleConnector gradleConnector = GradleConnector.newConnector();
gradleConnector.forProjectDirectory(buildDir);
((DefaultGradleConnector) gradleConnector).embedded(embedded);
if (gradleInstallDir != null) {
gradleConnector.useInstallation(gradleInstallDir);
}
ProjectConnection connect = gradleConnector.connect();
try {
for (int i = 0; i < 5; i++) {
SyncAction.withProjectConnection(connect, null);
}
} finally {
connect.close();
}
timer.stop();
System.out.println("total time: " + timer.duration());
}
use of org.gradle.tooling.internal.consumer.DefaultGradleConnector in project gradle by gradle.
the class ToolingApiGradleExecutor method buildConnector.
private GradleConnector buildConnector(File gradleUserHome, File projectDir, boolean embedded, GradleProvider gradleProvider) {
DefaultGradleConnector gradleConnector = (DefaultGradleConnector) GradleConnector.newConnector();
gradleConnector.useDistributionBaseDir(GradleUserHomeLookup.gradleUserHome());
gradleProvider.applyTo(gradleConnector);
gradleConnector.useGradleUserHomeDir(gradleUserHome);
gradleConnector.daemonBaseDir(new File(gradleUserHome, TEST_KIT_DAEMON_DIR_NAME));
gradleConnector.forProjectDirectory(projectDir);
gradleConnector.searchUpwards(false);
gradleConnector.daemonMaxIdleTime(120, TimeUnit.SECONDS);
gradleConnector.embedded(embedded);
return gradleConnector;
}
use of org.gradle.tooling.internal.consumer.DefaultGradleConnector in project kotlin 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);
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);
}
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();
URI distributionUri = new DistributionLocator().getDistributionFor(GradleVersion.version(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 {
ProjectImportAction projectImportAction = new ProjectImportAction(false);
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 intellij-community by JetBrains.
the class GradleExecutionHelper method getConnection.
/**
* Allows to retrieve gradle api connection to use for the given project.
*
* @param projectPath target project path
* @param settings execution settings to use
* @return connection to use
* @throws IllegalStateException if it's not possible to create the connection
*/
@NotNull
private static ProjectConnection getConnection(@NotNull String projectPath, @Nullable GradleExecutionSettings settings) throws IllegalStateException {
File projectDir = new File(projectPath);
GradleConnector connector = GradleConnector.newConnector();
int ttl = -1;
if (settings != null) {
//noinspection EnumSwitchStatementWhichMissesCases
switch(settings.getDistributionType()) {
case LOCAL:
String gradleHome = settings.getGradleHome();
if (gradleHome != null) {
try {
// There were problems with symbolic links processing at the gradle side.
connector.useInstallation(new File(gradleHome).getCanonicalFile());
} catch (IOException e) {
connector.useInstallation(new File(settings.getGradleHome()));
}
}
break;
case WRAPPED:
if (settings.getWrapperPropertyFile() != null) {
File propertiesFile = new File(settings.getWrapperPropertyFile());
if (propertiesFile.exists()) {
Distribution distribution = new DistributionFactoryExt(new DefaultExecutorServiceFactory()).getWrappedDistribution(propertiesFile);
try {
setField(connector, "distribution", distribution);
} catch (Exception e) {
throw new ExternalSystemException(e);
}
}
}
break;
}
// Setup service directory if necessary.
String serviceDirectory = settings.getServiceDirectory();
if (serviceDirectory != null) {
connector.useGradleUserHomeDir(new File(serviceDirectory));
}
// Setup logging if necessary.
if (settings.isVerboseProcessing() && connector instanceof DefaultGradleConnector) {
((DefaultGradleConnector) connector).setVerboseLogging(true);
}
ttl = (int) settings.getRemoteProcessIdleTtlInMs();
}
if (ttl > 0 && connector instanceof DefaultGradleConnector) {
// do not spawn gradle daemons during test execution
final Application app = ApplicationManager.getApplication();
ttl = (app != null && app.isUnitTestMode()) ? 10000 : ttl;
((DefaultGradleConnector) connector).daemonMaxIdleTime(ttl, TimeUnit.MILLISECONDS);
}
connector.forProjectDirectory(projectDir);
ProjectConnection connection = connector.connect();
if (connection == null) {
throw new IllegalStateException(String.format("Can't create connection to the target project via gradle tooling api. Project path: '%s'", projectPath));
}
return connection;
}
Aggregations