Exemplo n.º 1
0
 /** 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());
 }
Exemplo n.º 2
0
  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 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());
 }
Exemplo n.º 4
0
 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);
   }
 }
 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();
   }
 }
Exemplo n.º 6
0
  @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();
  }
Exemplo n.º 7
0
 /** 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;
  }
}
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
  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));
  }
 public void run() {
   System.out.println(GradleVersion.current().prettyPrint());
 }
Exemplo n.º 12
0
 private InputStream getInputStream(URI url) throws IOException {
   final URLConnection urlConnection = url.toURL().openConnection();
   urlConnection.setRequestProperty("User-Agent", GradleVersion.current().getUserAgentString());
   return urlConnection.getInputStream();
 }
  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;
  }
Exemplo n.º 14
0
 /** 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();
 }
Exemplo n.º 15
0
 private void logTargetVersion() {
   LOGGER.info(
       "Tooling API is using target Gradle version: {}.", GradleVersion.current().getVersion());
 }