use of org.gradle.util.GradleVersion 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.util.GradleVersion in project gradle by gradle.
the class DefaultGradleBuildInvocationSpec method setGradleVersion.
public void setGradleVersion(String gradleVersion) {
if (gradleVersion == null) {
throw new IllegalArgumentException("gradleVersion cannot be null");
}
GradleVersion version = GradleVersion.version(gradleVersion);
this.gradleVersion = version.getVersion();
}
use of org.gradle.util.GradleVersion in project gradle by gradle.
the class ToolingApiGradleExecutor method run.
@Override
public GradleExecutionResult run(GradleExecutionParameters parameters) {
final StreamByteBuffer outputBuffer = new StreamByteBuffer();
final OutputStream syncOutput = new SynchronizedOutputStream(outputBuffer.getOutputStream());
final List<BuildTask> tasks = new ArrayList<BuildTask>();
maybeRegisterCleanup();
GradleConnector gradleConnector = buildConnector(parameters.getGradleUserHome(), parameters.getProjectDir(), parameters.isEmbedded(), parameters.getGradleProvider());
ProjectConnection connection = null;
GradleVersion targetGradleVersion = null;
try {
connection = gradleConnector.connect();
targetGradleVersion = determineTargetGradleVersion(connection);
if (targetGradleVersion.compareTo(TestKitFeature.RUN_BUILDS.getSince()) < 0) {
throw new UnsupportedFeatureException(String.format("The version of Gradle you are using (%s) is not supported by TestKit. TestKit supports all Gradle versions 2.6 and later.", targetGradleVersion.getVersion()));
}
DefaultBuildLauncher launcher = (DefaultBuildLauncher) connection.newBuild();
launcher.setStandardOutput(new NoCloseOutputStream(teeOutput(syncOutput, parameters.getStandardOutput())));
launcher.setStandardError(new NoCloseOutputStream(teeOutput(syncOutput, parameters.getStandardError())));
if (parameters.getStandardInput() != null) {
launcher.setStandardInput(parameters.getStandardInput());
}
launcher.addProgressListener(new TaskExecutionProgressListener(tasks), OperationType.TASK);
launcher.withArguments(parameters.getBuildArgs().toArray(new String[0]));
launcher.setJvmArguments(parameters.getJvmArgs().toArray(new String[0]));
launcher.setEnvironmentVariables(parameters.getEnvironment());
if (!parameters.getInjectedClassPath().isEmpty()) {
if (targetGradleVersion.compareTo(TestKitFeature.PLUGIN_CLASSPATH_INJECTION.getSince()) < 0) {
throw new UnsupportedFeatureException("support plugin classpath injection", targetGradleVersion, TestKitFeature.PLUGIN_CLASSPATH_INJECTION.getSince());
}
launcher.withInjectedClassPath(parameters.getInjectedClassPath());
}
launcher.run();
} catch (UnsupportedVersionException e) {
throw new InvalidRunnerConfigurationException("The build could not be executed due to a feature not being supported by the target Gradle version", e);
} catch (BuildException t) {
return new GradleExecutionResult(new BuildOperationParameters(targetGradleVersion, parameters.isEmbedded()), outputBuffer.readAsString(), tasks, t);
} catch (GradleConnectionException t) {
StringBuilder message = new StringBuilder("An error occurred executing build with ");
if (parameters.getBuildArgs().isEmpty()) {
message.append("no args");
} else {
message.append("args '");
message.append(CollectionUtils.join(" ", parameters.getBuildArgs()));
message.append("'");
}
message.append(" in directory '").append(parameters.getProjectDir().getAbsolutePath()).append("'");
String capturedOutput = outputBuffer.readAsString();
if (!capturedOutput.isEmpty()) {
message.append(". Output before error:").append(SystemProperties.getInstance().getLineSeparator()).append(capturedOutput);
}
throw new IllegalStateException(message.toString(), t);
} finally {
if (connection != null) {
connection.close();
}
}
return new GradleExecutionResult(new BuildOperationParameters(targetGradleVersion, parameters.isEmbedded()), outputBuffer.readAsString(), tasks);
}
use of org.gradle.util.GradleVersion in project gradle by gradle.
the class WrapperDistributionCleanupAction method execute.
@Override
public boolean execute(@Nonnull CleanupProgressMonitor progressMonitor) {
long maximumTimestamp = Math.max(0, System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1));
Set<GradleVersion> usedVersions = this.usedGradleVersions.getUsedGradleVersions();
Multimap<GradleVersion, File> checksumDirsByVersion = determineChecksumDirsByVersion();
for (GradleVersion version : checksumDirsByVersion.keySet()) {
if (!usedVersions.contains(version) && version.compareTo(GradleVersion.current()) < 0) {
deleteDistributions(version, checksumDirsByVersion.get(version), maximumTimestamp, progressMonitor);
} else {
progressMonitor.incrementSkipped(checksumDirsByVersion.get(version).size());
}
}
return true;
}
Aggregations