public UnsupportedFeatureException( String feature, GradleVersion targetGradleVersion, GradleVersion minSupportedGradleVersion) { super( String.format( "The version of Gradle you are using (%s) does not %s. Support for this is available in Gradle %s and all later versions.", targetGradleVersion.getVersion(), feature, minSupportedGradleVersion.getVersion())); }
@Test public void testDependencyScopeMerge() throws Exception { createSettingsFile("include 'api', 'impl' "); importProject( "allprojects {\n" + " apply plugin: 'java'\n" + "\n" + " sourceCompatibility = 1.5\n" + " version = '1.0'\n" + "}\n" + "\n" + "dependencies {\n" + " compile project(':api')\n" + " testCompile project(':impl'), 'junit:junit:4.11'\n" + " runtime project(':impl')\n" + "}"); assertModules( "project", "project_main", "project_test", "api", "api_main", "api_test", "impl", "impl_main", "impl_test"); assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE); assertModuleModuleDepScope("api_test", "api_main", DependencyScope.COMPILE); assertModuleModuleDepScope("impl_test", "impl_main", DependencyScope.COMPILE); assertModuleModuleDepScope("project_main", "api_main", DependencyScope.COMPILE); assertModuleModuleDepScope("project_main", "impl_main", DependencyScope.RUNTIME); assertModuleModuleDepScope("project_test", "impl_main", DependencyScope.COMPILE); assertModuleLibDepScope( "project_test", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE); assertModuleLibDepScope("project_test", "Gradle: junit:junit:4.11", DependencyScope.COMPILE); importProjectUsingSingeModulePerGradleProject(); assertModules("project", "api", "impl"); assertModuleModuleDepScope("project", "api", DependencyScope.COMPILE); if (GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("1.12")) < 0) { assertModuleModuleDepScope("project", "impl", DependencyScope.RUNTIME); } else { assertModuleModuleDepScope("project", "impl", DependencyScope.RUNTIME, DependencyScope.TEST); } assertModuleLibDepScope( "project", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.TEST); assertModuleLibDepScope("project", "Gradle: junit:junit:4.11", DependencyScope.TEST); }
@Test @TargetVersions("2.0+") public void testTransitiveNonTransitiveDependencyScopeMerge() throws Exception { createSettingsFile("include 'project1'\n" + "include 'project2'\n"); importProject( "project(':project1') {\n" + " apply plugin: 'java'\n" + " dependencies {\n" + " compile 'junit:junit:4.11'\n" + " }\n" + "}\n" + "\n" + "project(':project2') {\n" + " apply plugin: 'java'\n" + " dependencies.ext.strict = { projectPath ->\n" + " dependencies.compile dependencies.project(path: projectPath, transitive: false)\n" + " dependencies.runtime dependencies.project(path: projectPath, transitive: true)\n" + " dependencies.testRuntime dependencies.project(path: projectPath, transitive: true)\n" + " }\n" + "\n" + " dependencies {\n" + " strict ':project1'\n" + " }\n" + "}\n"); assertModules( "project", "project1", "project1_main", "project1_test", "project2", "project2_main", "project2_test"); assertModuleModuleDeps("project2_main", "project1_main"); assertModuleModuleDepScope("project2_main", "project1_main", DependencyScope.COMPILE); assertModuleLibDepScope( "project2_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.RUNTIME); assertModuleLibDepScope("project2_main", "Gradle: junit:junit:4.11", DependencyScope.RUNTIME); if (GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.5")) >= 0) { importProjectUsingSingeModulePerGradleProject(); assertModules("project", "project1", "project2"); assertModuleModuleDepScope("project2", "project1", DependencyScope.COMPILE); assertModuleLibDepScope( "project2", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.RUNTIME); assertModuleLibDepScope("project2", "Gradle: junit:junit:4.11", DependencyScope.RUNTIME); } }
public Object run( String modelName, BuildCancellationToken cancellationToken, ProviderOperationParameters providerParameters) { List<String> tasks = providerParameters.getTasks(); if (modelName.equals(ModelIdentifier.NULL_MODEL) && tasks == null) { throw new IllegalArgumentException("No model type or tasks specified."); } Parameters params = initParams(providerParameters); Class<?> type = new ModelMapping().getProtocolTypeFromModelName(modelName); if (type == InternalBuildEnvironment.class) { // we don't really need to launch the daemon to acquire information needed for // BuildEnvironment if (tasks != null) { throw new IllegalArgumentException( "Cannot run tasks and fetch the build environment model."); } return new DefaultBuildEnvironment( GradleVersion.current().getVersion(), params.daemonParams.getEffectiveJavaHome(), params.daemonParams.getEffectiveJvmArgs()); } BuildAction<BuildActionResult> action = new BuildModelAction(modelName, tasks != null); return run(action, cancellationToken, providerParameters, params.properties); }
/** Returns the default distribution to use for the specified project. */ public Distribution getDefaultDistribution(File projectDir) { Wrapper wrapper = new Wrapper(projectDir); if (wrapper.getDistribution() != null) { return getDistribution(wrapper.getDistribution()); } return getDownloadedDistribution(GradleVersion.current().getVersion()); }
/** Returns the default distribution to use for the specified project. */ public Distribution getWrappedDistribution(File propertiesFile) { //noinspection UseOfSystemOutOrSystemErr WrapperExecutor wrapper = WrapperExecutor.forWrapperPropertiesFile(propertiesFile, System.out); if (wrapper.getDistribution() != null) { return new ZippedDistribution(wrapper.getConfiguration(), userHomeDir); } return getDownloadedDistribution(GradleVersion.current().getVersion()); }
private void validateCanRun() { LOGGER.info( "Tooling API is using target Gradle version: {}.", GradleVersion.current().getVersion()); if (!JavaVersion.current().isJava6Compatible()) { throw UnsupportedJavaRuntimeException.usingUnsupportedVersion( "Gradle", JavaVersion.VERSION_1_6); } }
@Test @TargetVersions("2.0+") public void testProvidedTransitiveDependencies() throws Exception { createSettingsFile("include 'projectA', 'projectB', 'projectC' "); importProject( "project(':projectA') {\n" + " apply plugin: 'java'\n" + "}\n" + "project(':projectB') {\n" + " apply plugin: 'java'\n" + " dependencies {\n" + " compile project(':projectA')\n" + " }\n" + "}\n" + "project(':projectC') {\n" + " apply plugin: 'war'\n" + " dependencies {\n" + " providedCompile project(':projectB')\n" + " }\n" + "}"); assertModules( "project", "projectA", "projectA_main", "projectA_test", "projectB", "projectB_main", "projectB_test", "projectC", "projectC_main", "projectC_test"); assertModuleModuleDepScope("projectB_main", "projectA_main", DependencyScope.COMPILE); assertModuleModuleDepScope("projectC_main", "projectA_main", DependencyScope.PROVIDED); assertModuleModuleDepScope("projectC_main", "projectB_main", DependencyScope.PROVIDED); importProjectUsingSingeModulePerGradleProject(); assertModules("project", "projectA", "projectB", "projectC"); assertModuleModuleDepScope("projectB", "projectA", DependencyScope.COMPILE); if (GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.5")) >= 0) { assertModuleModuleDepScope("projectC", "projectA", DependencyScope.PROVIDED); } assertModuleModuleDepScope("projectC", "projectB", DependencyScope.PROVIDED); }
public void download(URI address, File destination) throws Exception { ProgressLogger progressLogger = progressLoggerFactory.newOperation(DistributionFactory.class); progressLogger.setDescription(String.format("Download %s", address)); progressLogger.started(); try { new Download("Gradle Tooling API", GradleVersion.current().getVersion()) .download(address, destination); } finally { progressLogger.completed(); } }
private Distribution getDownloadedDistribution(String gradleVersion) { URI distUri; try { distUri = new URI( new DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion))); } catch (URISyntaxException e) { throw UncheckedException.asUncheckedException(e); } return getDistribution(distUri); }
@Test public void testNonDefaultProjectConfigurationDependency() throws Exception { createSettingsFile("include 'project1'\n" + "include 'project2'\n"); importProject( "project(':project1') {\n" + " configurations {\n" + " myConf {\n" + " description = 'My Conf'\n" + " transitive = true\n" + " }\n" + " }\n" + " dependencies {\n" + " myConf 'junit:junit:4.11'\n" + " }\n" + "}\n" + "\n" + "project(':project2') {\n" + " apply plugin: 'java'\n" + " dependencies {\n" + " compile project(path: ':project1', configuration: 'myConf')\n" + " }\n" + "}\n"); assertModules("project", "project1", "project2", "project2_main", "project2_test"); assertModuleModuleDeps("project2_main"); assertModuleLibDepScope( "project2_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE); assertModuleLibDepScope("project2_main", "Gradle: junit:junit:4.11", DependencyScope.COMPILE); importProjectUsingSingeModulePerGradleProject(); assertModules("project", "project1", "project2"); assertModuleModuleDeps("project2", "project1"); if (GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.0")) > 0) { assertModuleLibDepScope( "project2", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE); assertModuleLibDepScope("project2", "Gradle: junit:junit:4.11", DependencyScope.COMPILE); } }
protected static VersionDetails getVersionDetails(String versionString) { GradleVersion version = GradleVersion.version(versionString); if (version.compareTo(GradleVersion.version("1.11")) > 0) { return new R112VersionDetails(version.getVersion()); } return new R18VersionDetails(version.getVersion()); }
@Override public void render(final T model, SimpleHtmlWriter htmlWriter) throws IOException { this.model = model; htmlWriter .startElement("head") .startElement("meta") .attribute("httpEquiv", "Content-Type") .attribute("content", "text/html; charset=utf-8") .endElement() .startElement("title") .characters(getPageTitle()) .endElement() .startElement("link") .attribute("href", "css/base-style.css") .attribute("rel", "stylesheet") .attribute("type", "text/css") .endElement() .startElement("link") .attribute("href", "css/style.css") .attribute("rel", "stylesheet") .attribute("type", "text/css") .endElement() .startElement("script") .attribute("src", "js/report.js") .attribute("type", "text/javascript") .characters("") .endElement() // html does not like <a name="..."/> .endElement(); htmlWriter .startElement("body") .startElement("div") .attribute("id", "content") .startElement("h1") .characters(getTitle()) .endElement(); getHeaderRenderer().render(model, htmlWriter); getContentRenderer().render(model, htmlWriter); htmlWriter .startElement("div") .attribute("id", "footer") .startElement("p") .characters("Generated by ") .startElement("a") .attribute("href", "http://www.gradle.org") .characters(String.format("Gradle %s", GradleVersion.current().getVersion())) .endElement() .characters(String.format(" at %s", DateFormat.getDateTimeInstance().format(new Date()))) .endElement() .endElement() .endElement(); }
/** This is used by consumers 1.0-milestone-3 and later */ public DefaultConnection() { LOGGER.debug("Tooling API provider {} created.", GradleVersion.current().getVersion()); LoggingServiceRegistry loggingServices = LoggingServiceRegistry.newEmbeddableLogging(); services = ServiceRegistryBuilder.builder() .displayName("Connection services") .parent(loggingServices) .parent(NativeServices.getInstance()) .provider(new ConnectionScopeServices(loggingServices)) .build(); adapter = services.get(ProtocolToModelAdapter.class); connection = services.get(ProviderConnection.class); }
/** A Gradle distribution identifiable by version, e.g. <code>"2.8"</code>. */ public final class VersionBasedGradleDistribution implements GradleDistribution<String> { public static final VersionBasedGradleDistribution CURRENT = new VersionBasedGradleDistribution(GradleVersion.current().getVersion()); private final String gradleVersion; public VersionBasedGradleDistribution(String gradleVersion) { this.gradleVersion = gradleVersion; } public String getHandle() { return gradleVersion; } }
public static String getUserAgentString() { String osName = System.getProperty("os.name"); String osVersion = System.getProperty("os.version"); String osArch = System.getProperty("os.arch"); String javaVendor = System.getProperty("java.vendor"); String javaVersion = SystemProperties.getInstance().getJavaVersion(); String javaVendorVersion = System.getProperty("java.vm.version"); return String.format( "Gradle/%s (%s;%s;%s) (%s;%s;%s)", GradleVersion.current().getVersion(), osName, osVersion, osArch, javaVendor, javaVersion, javaVendorVersion); }
public ProjectConnection connect() throws GradleConnectionException { LOGGER.debug( "Connecting from tooling API consumer version {}", GradleVersion.current().getVersion()); if (projectDir == null) { throw new IllegalStateException( "A project directory must be specified before creating a connection."); } if (distribution == null) { distribution = distributionFactory.getDefaultDistribution(projectDir); } return connectionFactory.create( distribution, new DefaultConnectionParameters( projectDir, gradleUserHomeDir, searchUpwards, embedded, daemonMaxIdleTimeValue, daemonMaxIdleTimeUnits)); }
private Distribution getDownloadedDistribution(String gradleVersion) { URI distUri = new DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion)); return getDistribution(distUri); }
/** This is used by consumers 1.0-milestone-3 and later */ public DefaultConnection() { LOGGER.debug("Tooling API provider {} created.", GradleVersion.current().getVersion()); connection = new ProviderConnection(); }
public DaemonStartupInfo startDaemon() { String daemonUid = UUID.randomUUID().toString(); GradleInstallation gradleInstallation = CurrentGradleInstallation.get(); ModuleRegistry registry = new DefaultModuleRegistry(gradleInstallation); ClassPath classpath; List<File> searchClassPath; if (gradleInstallation == null) { // When not running from a Gradle distro, need runtime impl for launcher plus the search path // to look for other modules classpath = new DefaultClassPath(); for (Module module : registry.getModule("gradle-launcher").getAllRequiredModules()) { classpath = classpath.plus(module.getClasspath()); } searchClassPath = registry.getAdditionalClassPath().getAsFiles(); } else { // When running from a Gradle distro, only need launcher jar. The daemon can find everything // from there. classpath = registry.getModule("gradle-launcher").getImplementationClasspath(); searchClassPath = Collections.emptyList(); } if (classpath.isEmpty()) { throw new IllegalStateException( "Unable to construct a bootstrap classpath when starting the daemon"); } versionValidator.validate(daemonParameters); List<String> daemonArgs = new ArrayList<String>(); daemonArgs.add(daemonParameters.getEffectiveJvm().getJavaExecutable().getAbsolutePath()); List<String> daemonOpts = daemonParameters.getEffectiveJvmArgs(); daemonArgs.addAll(daemonOpts); daemonArgs.add("-cp"); daemonArgs.add(CollectionUtils.join(File.pathSeparator, classpath.getAsFiles())); if (Boolean.getBoolean("org.gradle.daemon.debug")) { daemonArgs.add("-Xdebug"); daemonArgs.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"); } LOGGER.debug("Using daemon args: {}", daemonArgs); daemonArgs.add(GradleDaemon.class.getName()); // Version isn't used, except by a human looking at the output of jps. daemonArgs.add(GradleVersion.current().getVersion()); // Serialize configuration to daemon via the process' stdin ByteArrayOutputStream serializedConfig = new ByteArrayOutputStream(); FlushableEncoder encoder = new KryoBackedEncoder(new EncodedStream.EncodedOutput(serializedConfig)); try { encoder.writeString(daemonParameters.getGradleUserHomeDir().getAbsolutePath()); encoder.writeString(daemonDir.getBaseDir().getAbsolutePath()); encoder.writeSmallInt(daemonParameters.getIdleTimeout()); encoder.writeString(daemonUid); encoder.writeSmallInt(daemonOpts.size()); for (String daemonOpt : daemonOpts) { encoder.writeString(daemonOpt); } encoder.writeSmallInt(searchClassPath.size()); for (File file : searchClassPath) { encoder.writeString(file.getAbsolutePath()); } encoder.flush(); } catch (IOException e) { throw new UncheckedIOException(e); } ByteArrayInputStream stdInput = new ByteArrayInputStream(serializedConfig.toByteArray()); DaemonStartupInfo daemonInfo = startProcess(daemonArgs, daemonDir.getVersionedDir(), stdInput); listener.daemonStarted(daemonInfo); return daemonInfo; }
private InputStream getInputStream(URI url) throws IOException { final URLConnection urlConnection = url.toURL().openConnection(); urlConnection.setRequestProperty("User-Agent", GradleVersion.current().getUserAgentString()); return urlConnection.getInputStream(); }
@Test public void testCompileAndRuntimeConfigurationsTransitiveDependencyMerge() throws Exception { createSettingsFile("include 'project1'\n" + "include 'project2'\n" + "include 'project-tests'"); importProject( "subprojects {\n" + " apply plugin: \"java\"\n" + "}\n" + "\n" + "project(\":project1\") {\n" + " dependencies {\n" + " compile 'org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.0'\n" + " }\n" + "}\n" + "\n" + "project(\":project2\") {\n" + " dependencies {\n" + " runtime 'org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1'\n" + " }\n" + "}\n" + "\n" + "project(\":project-tests\") {\n" + " dependencies {\n" + " compile project(':project1')\n" + " runtime project(':project2')\n" + " compile 'junit:junit:4.11'\n" + " }\n" + "}\n"); assertModules( "project", "project1", "project1_main", "project1_test", "project2", "project2_main", "project2_test", "project-tests", "project-tests_main", "project-tests_test"); assertModuleModuleDepScope("project-tests_main", "project1_main", DependencyScope.COMPILE); assertModuleModuleDepScope("project-tests_main", "project2_main", DependencyScope.RUNTIME); assertModuleLibDepScope( "project-tests_main", "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.0", DependencyScope.COMPILE); assertModuleLibDepScope( "project-tests_main", "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1", DependencyScope.RUNTIME); importProjectUsingSingeModulePerGradleProject(); assertModuleModuleDepScope("project-tests", "project1", DependencyScope.COMPILE); assertModuleModuleDepScope("project-tests", "project2", DependencyScope.RUNTIME); if (GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.0")) > 0) { assertModuleLibDepScope( "project-tests", "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.0", DependencyScope.COMPILE); assertModuleLibDepScope( "project-tests", "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1", DependencyScope.RUNTIME); } }
@Test public void testDependencyWithDifferentClassifiers() throws Exception { final VirtualFile depJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0.jar"); final VirtualFile depTestsJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0-tests.jar"); final VirtualFile depNonJar = createProjectSubFile("lib/dep/dep/1.0/dep-1.0.someExt"); importProject( "allprojects {\n" + " apply plugin: 'java'\n" + " sourceCompatibility = 1.5\n" + " version = '1.0'\n" + "\n" + " repositories {\n" + " maven{ url file('lib') }\n" + " }\n" + "}\n" + "\n" + "dependencies {\n" + " compile 'dep:dep:1.0'\n" + " testCompile 'dep:dep:1.0:tests'\n" + " runtime 'dep:dep:1.0@someExt'\n" + "}"); assertModules("project", "project_main", "project_test"); assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE); final String depName = "Gradle: dep:dep:1.0"; assertModuleLibDep("project_main", depName, depJar.getUrl()); assertModuleLibDepScope("project_main", depName, DependencyScope.COMPILE); assertModuleLibDep("project_test", depName, depJar.getUrl()); assertModuleLibDepScope("project_test", depName, DependencyScope.COMPILE); final boolean isArtifactResolutionQuerySupported = GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.0")) >= 0; final String depTestsName = isArtifactResolutionQuerySupported ? "Gradle: dep:dep:tests:1.0" : PathUtil.toPresentableUrl(depTestsJar.getUrl()); assertModuleLibDep("project_test", depTestsName, depTestsJar.getUrl()); assertModuleLibDepScope("project_test", depTestsName, DependencyScope.COMPILE); final String depNonJarName = isArtifactResolutionQuerySupported ? "Gradle: dep:dep:someExt:1.0" : PathUtil.toPresentableUrl(depNonJar.getUrl()); assertModuleLibDep("project_main", depNonJarName, depNonJar.getUrl()); assertModuleLibDepScope("project_main", depNonJarName, DependencyScope.RUNTIME); assertModuleLibDep("project_test", depNonJarName, depNonJar.getUrl()); assertModuleLibDepScope("project_test", depNonJarName, DependencyScope.RUNTIME); importProjectUsingSingeModulePerGradleProject(); assertModules("project"); assertModuleLibDep("project", depName, depJar.getUrl()); assertModuleLibDepScope("project", depName, DependencyScope.COMPILE); assertModuleLibDep("project", "Gradle: dep:dep:1.0:tests", depTestsJar.getUrl()); assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:tests", DependencyScope.TEST); assertModuleLibDep("project", "Gradle: dep:dep:1.0:someExt", depNonJar.getUrl()); assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:someExt", DependencyScope.RUNTIME); }
public void run() { System.out.println(GradleVersion.current().prettyPrint()); }
private void logTargetVersion() { LOGGER.info( "Tooling API is using target Gradle version: {}.", GradleVersion.current().getVersion()); }