CancellationToken cancelToken,
final Project project) {
ExceptionHelper.checkNotNullArgument(cancelToken, "cancelToken");
ExceptionHelper.checkNotNullArgument(project, "project");
final GradleConnector result = GradleConnector.newConnector();
Integer timeoutSec = GlobalGradleSettings.getGradleDaemonTimeoutSec().getValue();
if (timeoutSec != null && result instanceof DefaultGradleConnector) {
((DefaultGradleConnector)result).daemonMaxIdleTime(timeoutSec, TimeUnit.SECONDS);
}
NbGradleProject gradleProject = project.getLookup().lookup(NbGradleProject.class);
if (gradleProject == null) {
throw new IllegalArgumentException("Not a Gradle project: " + project.getProjectDirectory());
}
File gradleUserHome = GlobalGradleSettings.getGradleUserHomeDir().getValue();
if (gradleUserHome != null) {
result.useGradleUserHomeDir(gradleUserHome);
}
GradleLocation gradleLocation;
ProjectProperties projectProperties = gradleProject.getLoadedProperties(cancelToken);
if (projectProperties == null) {
LOGGER.warning("Could not wait for retrieving the project properties. Using the globally defined one");
gradleLocation = GlobalGradleSettings.getGradleHome().getValue();
}
else {
gradleLocation = projectProperties.getGradleLocation().getValue();
}
gradleLocation.applyLocation(gradleProject, new GradleLocation.Applier() {
@Override
public void applyVersion(String versionStr) {
result.useGradleVersion(versionStr);
}
@Override
public void applyDirectory(File gradleHome) {
result.useInstallation(gradleHome);
}
@Override
public void applyDistribution(URI location) {
result.useDistribution(location);
}
@Override
public void applyDefault() {
}