org.gradle.internal.jvm.Jvm Java Examples

The following examples show how to use org.gradle.internal.jvm.Jvm. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PayloadSerializer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public PayloadSerializer(PayloadClassLoaderRegistry registry) {
    classLoaderRegistry = registry;

    // On Java 6, there is a public method to lookup a class descriptor given a class. On Java 5, we have to use reflection
    // TODO:ADAM - move this into the service registry
    if (Jvm.current().getJavaVersion().isJava6Compatible()) {
        // Use the public method
        try {
            classLookup = (Transformer<ObjectStreamClass, Class<?>>) getClass().getClassLoader().loadClass("org.gradle.tooling.internal.provider.jdk6.Jdk6ClassLookup").newInstance();
        } catch (Exception e) {
            throw UncheckedException.throwAsUncheckedException(e);
        }
    } else {
        // Use Java 5 fallback which uses reflection
        classLookup = new ReflectionClassLookup();
    }
}
 
Example #2
Source File: AvailableJavaHomes.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Locates a JDK installation that has a different version to the current JVM, ie for which java.version is different.
 *
 * @return null if not found.
 */
@Nullable
public static JavaInfo getDifferentVersion() {
    Jvm jvm = Jvm.current();
    for (JvmInstallation candidate : getJvms()) {
        if (candidate.getJavaVersion().equals(jvm.getJavaVersion())) {
            continue;
        }
        // Currently tests implicitly assume a JDK
        if (!candidate.isJdk()) {
            continue;
        }
        return Jvm.forHome(candidate.getJavaHome());
    }

    return null;
}
 
Example #3
Source File: PayloadSerializer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public PayloadSerializer(PayloadClassLoaderRegistry registry) {
    classLoaderRegistry = registry;

    // On Java 6, there is a public method to lookup a class descriptor given a class. On Java 5, we have to use reflection
    // TODO:ADAM - move this into the service registry
    if (Jvm.current().getJavaVersion().isJava6Compatible()) {
        // Use the public method
        try {
            classLookup = (Transformer<ObjectStreamClass, Class<?>>) getClass().getClassLoader().loadClass("org.gradle.tooling.internal.provider.jdk6.Jdk6ClassLookup").newInstance();
        } catch (Exception e) {
            throw UncheckedException.throwAsUncheckedException(e);
        }
    } else {
        // Use Java 5 fallback which uses reflection
        classLookup = new ReflectionClassLookup();
    }
}
 
Example #4
Source File: JavadocExecHandleBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ExecAction getExecHandle() {
    try {
        options.write(optionsFile);
    } catch (IOException e) {
        throw new GradleException("Failed to store javadoc options.", e);
    }

    ExecAction execAction = execActionFactory.newExecAction();
    execAction.workingDir(execDirectory);
    execAction.executable(GUtil.elvis(executable, Jvm.current().getJavadocExecutable()));
    execAction.args("@" + optionsFile.getAbsolutePath());

    options.contributeCommandLineOptions(execAction);

    return execAction;
}
 
Example #5
Source File: JavadocExecHandleBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ExecAction getExecHandle() {
    try {
        options.write(optionsFile);
    } catch (IOException e) {
        throw new GradleException("Failed to store javadoc options.", e);
    }

    ExecAction execAction = execActionFactory.newExecAction();
    execAction.workingDir(execDirectory);
    execAction.executable(GUtil.elvis(executable, Jvm.current().getJavadocExecutable()));
    execAction.args("@" + optionsFile.getAbsolutePath());

    options.contributeCommandLineOptions(execAction);

    return execAction;
}
 
Example #6
Source File: CommandLineActionFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void run() {
    GradleVersion currentVersion = GradleVersion.current();

    final StringBuilder sb = new StringBuilder();
    sb.append("\n------------------------------------------------------------\nGradle ");
    sb.append(currentVersion.getVersion());
    sb.append("\n------------------------------------------------------------\n\nBuild time:   ");
    sb.append(currentVersion.getBuildTime());
    sb.append("\nBuild number: ");
    sb.append(currentVersion.getBuildNumber());
    sb.append("\nRevision:     ");
    sb.append(currentVersion.getRevision());
    sb.append("\n\nGroovy:       ");
    sb.append(GroovySystem.getVersion());
    sb.append("\nAnt:          ");
    sb.append(Main.getAntVersion());
    sb.append("\nJVM:          ");
    sb.append(Jvm.current());
    sb.append("\nOS:           ");
    sb.append(OperatingSystem.current());
    sb.append("\n");

    System.out.println(sb.toString());
}
 
Example #7
Source File: JavadocExecHandleBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ExecAction getExecHandle() {
    try {
        options.write(optionsFile);
    } catch (IOException e) {
        throw new GradleException("Failed to store javadoc options.", e);
    }

    ExecAction execAction = execActionFactory.newExecAction();
    execAction.workingDir(execDirectory);
    execAction.executable(GUtil.elvis(executable, Jvm.current().getJavadocExecutable()));
    execAction.args("@" + optionsFile.getAbsolutePath());

    options.contributeCommandLineOptions(execAction);

    return execAction;
}
 
Example #8
Source File: JvmVersionValidator.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
void validate(DaemonParameters parameters) {
    if (parameters.getEffectiveJavaHome().equals(Jvm.current().getJavaHome())) {
        return;
    }

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    ExecHandleBuilder builder = new ExecHandleBuilder();
    builder.setWorkingDir(new File(".").getAbsolutePath());
    builder.setCommandLine(parameters.getEffectiveJavaExecutable(), "-version");
    builder.setStandardOutput(new ByteArrayOutputStream());
    builder.setErrorOutput(outputStream);
    builder.build().start().waitForFinish().assertNormalExitValue();

    JavaVersion javaVersion = parseJavaVersionCommandOutput(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray()))));
    if (!javaVersion.isJava6Compatible()) {
        throw UnsupportedJavaRuntimeException.configuredWithUnsupportedVersion("Gradle", JavaVersion.VERSION_1_6, javaVersion);
    }
}
 
Example #9
Source File: JavadocExecHandleBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ExecAction getExecHandle() {
    try {
        options.write(optionsFile);
    } catch (IOException e) {
        throw new GradleException("Failed to store javadoc options.", e);
    }

    ExecAction execAction = execActionFactory.newExecAction();
    execAction.workingDir(execDirectory);
    execAction.executable(GUtil.elvis(executable, Jvm.current().getJavadocExecutable()));
    execAction.args("@" + optionsFile.getAbsolutePath());

    options.contributeCommandLineOptions(execAction);

    return execAction;
}
 
Example #10
Source File: GradleVersion.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public String prettyPrint() {
    final StringBuilder sb = new StringBuilder();
    sb.append("\n------------------------------------------------------------\nGradle ");
    sb.append(getVersion());
    sb.append("\n------------------------------------------------------------\n\nBuild time:   ");
    sb.append(getBuildTime());
    sb.append("\nBuild number: ");
    sb.append(buildNumber);
    sb.append("\nRevision:     ");
    sb.append(commitId);
    sb.append("\n\nGroovy:       ");
    sb.append(GroovySystem.getVersion());
    sb.append("\nAnt:          ");
    sb.append(Main.getAntVersion());
    sb.append("\nIvy:          ");
    sb.append(Ivy.getIvyVersion());
    sb.append("\nJVM:          ");
    sb.append(Jvm.current());
    sb.append("\nOS:           ");
    sb.append(OperatingSystem.current());
    sb.append("\n");
    return sb.toString();
}
 
Example #11
Source File: AvailableJavaHomes.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Locates a JDK installation that has a different version to the current JVM, ie for which java.version is different.
 *
 * @return null if not found.
 */
@Nullable
public static JavaInfo getDifferentVersion() {
    Jvm jvm = Jvm.current();
    for (JvmInstallation candidate : getJvms()) {
        if (candidate.getJavaVersion().equals(jvm.getJavaVersion())) {
            continue;
        }
        // Currently tests implicitly assume a JDK
        if (!candidate.isJdk()) {
            continue;
        }
        return Jvm.forHome(candidate.getJavaHome());
    }

    return null;
}
 
Example #12
Source File: AvailableJavaHomes.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Locates a JDK installation that is different to the current JVM, ie for which java.home is different.
 *
 * @return null if not found.
 */
@Nullable
public static JavaInfo getDifferentJdk() {
    Jvm jvm = Jvm.current();
    for (JvmInstallation candidate : getJvms()) {
        if (candidate.getJavaHome().equals(jvm.getJavaHome())) {
            continue;
        }

        // Currently tests implicitly assume a JDK
        if (!candidate.isJdk()) {
            continue;
        }
        return Jvm.forHome(candidate.getJavaHome());
    }

    return null;
}
 
Example #13
Source File: DefaultClassLoaderRegistry.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void initializeJdkTools() {
    // Add in tools.jar to the systemClassloader parent
    File toolsJar = Jvm.current().getToolsJar();
    if (toolsJar != null) {
        final ClassLoader systemClassLoaderParent = ClassLoader.getSystemClassLoader().getParent();
        ClasspathUtil.addUrl((URLClassLoader) systemClassLoaderParent, new DefaultClassPath(toolsJar).getAsURLs());
    }
}
 
Example #14
Source File: ZincScalaCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static com.typesafe.zinc.Compiler createCompiler(Iterable<File> scalaClasspath, Iterable<File> zincClasspath, xsbti.Logger logger) {
    ScalaLocation scalaLocation = ScalaLocation.fromPath(Lists.newArrayList(scalaClasspath));
    SbtJars sbtJars = SbtJars.fromPath(Lists.newArrayList(zincClasspath));
    Setup setup = Setup.create(scalaLocation, sbtJars, Jvm.current().getJavaHome(), true);
    if (LOGGER.isDebugEnabled()) {
        Setup.debug(setup, logger);
    }
    return com.typesafe.zinc.Compiler.getOrCreate(setup, logger);
}
 
Example #15
Source File: AvailableJavaHomes.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Locates a JRE installation for the current JVM. Prefers a stand-alone JRE installation over one that is part of a JDK install.
 *
 * @return The JRE home directory, or null if not found
 */
public static File getBestJre() {
    Jvm jvm = Jvm.current();
    Jre jre = jvm.getStandaloneJre();
    if (jre != null) {
        return jre.getHomeDir();
    }
    jre = jvm.getJre();
    if (jre != null) {
        return jre.getHomeDir();
    }
    return null;
}
 
Example #16
Source File: AvailableJavaHomes.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Locates a JDK installation for the given version.
 *
 * @return null if not found.
 */
@Nullable
public static JavaInfo getJdk(JavaVersion version) {
    for (JvmInstallation candidate : getJvms()) {
        if (candidate.getJavaVersion().equals(version) && candidate.isJdk()) {
            return Jvm.forHome(candidate.getJavaHome());
        }
    }
    return null;
}
 
Example #17
Source File: DefaultGradleDistribution.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean worksWith(Jvm jvm) {
    // Milestone 4 was broken on the IBM jvm
    if (jvm.isIbmJvm() && isVersion("1.0-milestone-4")) {
        return false;
    }
    // 0.9-rc-1 was broken for Java 5
    if (isVersion("0.9-rc-1")) {
        return jvm.getJavaVersion().isJava6Compatible();
    }
    if (isSameOrOlder("1.12")) {
        return jvm.getJavaVersion().isJava5Compatible();
    }
    return jvm.getJavaVersion().isJava6Compatible();
}
 
Example #18
Source File: InProcessGradleExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void assertCanExecute() {
    assertNull(getExecutable());
    assertEquals(getJavaHome(), Jvm.current().getJavaHome());
    String defaultEncoding = getImplicitJvmSystemProperties().get("file.encoding");
    if (defaultEncoding != null) {
        assertEquals(Charset.forName(defaultEncoding), Charset.defaultCharset());
    }
    Locale defaultLocale = getDefaultLocale();
    if (defaultLocale != null) {
        assertEquals(defaultLocale, Locale.getDefault());
    }
    assertFalse(isRequireGradleHome());
}
 
Example #19
Source File: VisualCppToolChain.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends BinaryToolSpec> void clearEnvironmentVars(CommandLineTool<T> tool, String... names) {
    Map<String, ?> environmentVariables = Jvm.current().getInheritableEnvironmentVariables(System.getenv());
    for (String name : names) {
        Object value = environmentVariables.get(name);
        if (value != null) {
            LOGGER.warn("Ignoring value '{}' set for environment variable '{}'.", value, name);
            tool.withEnvironmentVar(name, "");
        }
    }
}
 
Example #20
Source File: AvailableJavaHomes.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Locates a JRE installation for the current JVM. Prefers a stand-alone JRE installation over one that is part of a JDK install.
 *
 * @return The JRE home directory, or null if not found
 */
public static File getBestJre() {
    Jvm jvm = Jvm.current();
    Jre jre = jvm.getStandaloneJre();
    if (jre != null) {
        return jre.getHomeDir();
    }
    jre = jvm.getJre();
    if (jre != null) {
        return jre.getHomeDir();
    }
    return null;
}
 
Example #21
Source File: DefaultGradleDistribution.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean worksWith(Jvm jvm) {
    // Milestone 4 was broken on the IBM jvm
    if (jvm.isIbmJvm() && isVersion("1.0-milestone-4")) {
        return false;
    }
    // 0.9-rc-1 was broken for Java 5
    if (isVersion("0.9-rc-1")) {
        return jvm.getJavaVersion().isJava6Compatible();
    }

    return jvm.getJavaVersion().isJava5Compatible();
}
 
Example #22
Source File: DefaultGradleDistribution.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean isDaemonSupported() {
    // Milestone 7 was broken on the IBM jvm
    if (Jvm.current().isIbmJvm() && isVersion("1.0-milestone-7")) {
        return false;
    }

    if (OperatingSystem.current().isWindows()) {
        // On windows, daemon is ok for anything > 1.0-milestone-3
        return isSameOrNewer("1.0-milestone-4");
    } else {
        // Daemon is ok for anything >= 0.9
        return isSameOrNewer("0.9");
    }
}
 
Example #23
Source File: InProcessGradleExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void assertCanExecute() {
    assertNull(getExecutable());
    assertEquals(getJavaHome(), Jvm.current().getJavaHome());
    String defaultEncoding = getImplicitJvmSystemProperties().get("file.encoding");
    if (defaultEncoding != null) {
        assertEquals(Charset.forName(defaultEncoding), Charset.defaultCharset());
    }
    assertFalse(isRequireGradleHome());
}
 
Example #24
Source File: CompilerDaemonStarter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CompilerDaemonClient startDaemon(File workingDir, DaemonForkOptions forkOptions) {
    LOG.debug("Starting Gradle compiler daemon with fork options {}.", forkOptions);
    Clock clock = new Clock();
    WorkerProcessBuilder builder = workerFactory.create();
    builder.setLogLevel(startParameter.getLogLevel()); // NOTE: might make sense to respect per-compile-task log level
    builder.applicationClasspath(forkOptions.getClasspath());
    builder.sharedPackages(forkOptions.getSharedPackages());
    File toolsJar = Jvm.current().getToolsJar();
    if (toolsJar != null) {
        builder.getApplicationClasspath().add(toolsJar); // for SunJavaCompiler
    }
    JavaExecHandleBuilder javaCommand = builder.getJavaCommand();
    javaCommand.setMinHeapSize(forkOptions.getMinHeapSize());
    javaCommand.setMaxHeapSize(forkOptions.getMaxHeapSize());
    javaCommand.setJvmArgs(forkOptions.getJvmArgs());
    javaCommand.setWorkingDir(workingDir);
    WorkerProcess process = builder.worker(new CompilerDaemonServer()).setBaseName("Gradle Compiler Daemon").build();
    process.start();

    CompilerDaemonServerProtocol server = process.getConnection().addOutgoing(CompilerDaemonServerProtocol.class);
    CompilerDaemonClient client = new CompilerDaemonClient(forkOptions, process, server);
    process.getConnection().addIncoming(CompilerDaemonClientProtocol.class, client);
    process.getConnection().connect();

    LOG.info("Started Gradle compiler daemon ({}) with fork options {}.", clock.getTime(), forkOptions);

    return client;
}
 
Example #25
Source File: DefaultGradleDistribution.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean isDaemonSupported() {
    // Milestone 7 was broken on the IBM jvm
    if (Jvm.current().isIbmJvm() && isVersion("1.0-milestone-7")) {
        return false;
    }

    if (OperatingSystem.current().isWindows()) {
        // On windows, daemon is ok for anything > 1.0-milestone-3
        return isSameOrNewer("1.0-milestone-4");
    } else {
        // Daemon is ok for anything >= 0.9
        return isSameOrNewer("0.9");
    }
}
 
Example #26
Source File: DefaultClassLoaderRegistry.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void initializeJdkTools() {
    // Add in tools.jar to the systemClassloader parent
    File toolsJar = Jvm.current().getToolsJar();
    if (toolsJar != null) {
        final ClassLoader systemClassLoaderParent = ClassLoader.getSystemClassLoader().getParent();
        ClasspathUtil.addUrl((URLClassLoader) systemClassLoaderParent, new DefaultClassPath(toolsJar).getAsURLs());
    }
}
 
Example #27
Source File: SonarRunnerPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Collection<File> getLibraries(SourceSet main) {
    List<File> libraries = Lists.newLinkedList(Iterables.filter(main.getRuntimeClasspath(), IS_FILE));
    File runtimeJar = Jvm.current().getRuntimeJar();
    if (runtimeJar != null) {
        libraries.add(runtimeJar);
    }

    return libraries;
}
 
Example #28
Source File: DefaultClassLoaderRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void initializeJdkTools() {
    // Add in tools.jar to the systemClassloader parent
    File toolsJar = Jvm.current().getToolsJar();
    if (toolsJar != null) {
        final ClassLoader systemClassLoaderParent = ClassLoader.getSystemClassLoader().getParent();
        ClasspathUtil.addUrl((URLClassLoader) systemClassLoaderParent, new DefaultClassPath(toolsJar).getAsURLs());
    }
}
 
Example #29
Source File: ZincScalaCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static com.typesafe.zinc.Compiler createCompiler(Iterable<File> scalaClasspath, Iterable<File> zincClasspath, xsbti.Logger logger) {
    ScalaLocation scalaLocation = ScalaLocation.fromPath(Lists.newArrayList(scalaClasspath));
    SbtJars sbtJars = SbtJars.fromPath(Lists.newArrayList(zincClasspath));
    Setup setup = Setup.create(scalaLocation, sbtJars, Jvm.current().getJavaHome(), true);
    if (LOGGER.isDebugEnabled()) {
        Setup.debug(setup, logger);
    }
    return com.typesafe.zinc.Compiler.getOrCreate(setup, logger);
}
 
Example #30
Source File: Jdk6JavaCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static JavaCompiler findCompiler() {
    File realJavaHome = Jvm.current().getJavaHome();
    File javaHomeFromToolProvidersPointOfView = new File(System.getProperty("java.home"));
    if (realJavaHome.equals(javaHomeFromToolProvidersPointOfView)) {
        return ToolProvider.getSystemJavaCompiler();
    }

    System.setProperty("java.home", realJavaHome.getAbsolutePath());
    try {
        return ToolProvider.getSystemJavaCompiler();
    } finally {
        System.setProperty("java.home", javaHomeFromToolProvidersPointOfView.getAbsolutePath());
    }
}