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()); }
protected boolean supportsWhiteSpaceInEnvVars() { final Jvm current = Jvm.current(); if (getJavaHome().equals(current.getJavaHome())) { // we can tell for sure return current.getJavaVersion().isJava7Compatible(); } else { // TODO improve lookup by reusing AvailableJavaHomes testfixture // for now we play it safe and just return false; return false; } }
/** * Locates a JVM 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; } return Jvm.forHome(candidate.getJavaHome()); } return null; }
/** * 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; }
/** * 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; }
public DefaultIsolatedAntBuilder( ClassPathRegistry classPathRegistry, ClassLoaderFactory classLoaderFactory) { this.classPathRegistry = classPathRegistry; this.classLoaderFactory = classLoaderFactory; this.libClasspath = new DefaultClassPath(); GroovySystemLoaderFactory groovySystemLoaderFactory = new GroovySystemLoaderFactory(); this.classLoaderCache = new ClassPathToClassLoaderCache(groovySystemLoaderFactory); List<File> antClasspath = Lists.newArrayList(classPathRegistry.getClassPath("ANT").getAsFiles()); // Need tools.jar for compile tasks File toolsJar = Jvm.current().getToolsJar(); if (toolsJar != null) { antClasspath.add(toolsJar); } antLoader = classLoaderFactory.createIsolatedClassLoader(new DefaultClassPath(antClasspath)); FilteringClassLoader loggingLoader = new FilteringClassLoader(getClass().getClassLoader()); loggingLoader.allowPackage("org.slf4j"); loggingLoader.allowPackage("org.apache.commons.logging"); loggingLoader.allowPackage("org.apache.log4j"); loggingLoader.allowClass(Logger.class); loggingLoader.allowClass(LogLevel.class); this.baseAntLoader = new CachingClassLoader(new MultiParentClassLoader(antLoader, loggingLoader)); // Need gradle core to pick up ant logging adapter, AntBuilder and such ClassPath gradleCoreUrls = classPathRegistry.getClassPath("GRADLE_CORE"); gradleCoreUrls = gradleCoreUrls.plus(classPathRegistry.getClassPath("GROOVY")); // Need Transformer (part of AntBuilder API) from base services gradleCoreUrls = gradleCoreUrls.plus(classPathRegistry.getClassPath("GRADLE_BASE_SERVICES")); this.antAdapterLoader = new URLClassLoader(gradleCoreUrls.getAsURLArray(), baseAntLoader); gradleApiGroovyLoader = groovySystemLoaderFactory.forClassLoader(this.getClass().getClassLoader()); antAdapterGroovyLoader = groovySystemLoaderFactory.forClassLoader(antAdapterLoader); // register finalizer for the root builder only! FINALIZERS.add(new Finalizer(this, FINALIZER_REFQUEUE)); }
public File getEffectiveJavaHome() { if (javaHome == null) { return canonicalise(Jvm.current().getJavaHome()); } return javaHome; }
public File getEffectiveJavaExecutable() { if (javaHome == null) { return Jvm.current().getJavaExecutable(); } return Jvm.forHome(javaHome).getJavaExecutable(); }
public class DaemonParameters { static final int DEFAULT_IDLE_TIMEOUT = 3 * 60 * 60 * 1000; static final int DEFAULT_PERIODIC_CHECK_INTERVAL_MILLIS = 10 * 1000; public static final List<String> DEFAULT_JVM_ARGS = ImmutableList.of("-Xmx1024m", "-XX:MaxPermSize=256m", "-XX:+HeapDumpOnOutOfMemoryError"); public static final List<String> DEFAULT_JVM_9_ARGS = ImmutableList.of("-Xmx1024m", "-XX:+HeapDumpOnOutOfMemoryError"); public static final String INTERACTIVE_TOGGLE = "org.gradle.interactive"; private final File gradleUserHomeDir; private File baseDir; private int idleTimeout = DEFAULT_IDLE_TIMEOUT; private int periodicCheckInterval = DEFAULT_PERIODIC_CHECK_INTERVAL_MILLIS; private final DaemonJvmOptions jvmOptions = new DaemonJvmOptions(new IdentityFileResolver()); private boolean enabled = true; private boolean hasJvmArgs; private boolean foreground; private boolean stop; private boolean status; private boolean interactive = System.console() != null || Boolean.getBoolean(INTERACTIVE_TOGGLE); private JavaInfo jvm = Jvm.current(); public DaemonParameters(BuildLayoutParameters layout) { this(layout, Collections.<String, String>emptyMap()); } public DaemonParameters(BuildLayoutParameters layout, Map<String, String> extraSystemProperties) { jvmOptions.systemProperties(extraSystemProperties); baseDir = new File(layout.getGradleUserHomeDir(), "daemon"); gradleUserHomeDir = layout.getGradleUserHomeDir(); } public boolean isInteractive() { return interactive; } public boolean isEnabled() { return enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public File getBaseDir() { return baseDir; } public File getGradleUserHomeDir() { return gradleUserHomeDir; } public int getIdleTimeout() { return idleTimeout; } public void setIdleTimeout(int idleTimeout) { this.idleTimeout = idleTimeout; } public int getPeriodicCheckInterval() { return periodicCheckInterval; } public void setPeriodicCheckInterval(int periodicCheckInterval) { this.periodicCheckInterval = periodicCheckInterval; } public List<String> getEffectiveJvmArgs() { return jvmOptions.getAllImmutableJvmArgs(); } public List<String> getEffectiveSingleUseJvmArgs() { return jvmOptions.getAllSingleUseImmutableJvmArgs(); } public JavaInfo getEffectiveJvm() { return jvm; } @Nullable public DaemonParameters setJvm(JavaInfo jvm) { this.jvm = jvm == null ? Jvm.current() : jvm; return this; } public void applyDefaultsFor(JavaVersion javaVersion) { if (hasJvmArgs) { return; } if (javaVersion.compareTo(JavaVersion.VERSION_1_9) >= 0) { jvmOptions.jvmArgs(DEFAULT_JVM_9_ARGS); } else { jvmOptions.jvmArgs(DEFAULT_JVM_ARGS); } } public Map<String, String> getSystemProperties() { Map<String, String> systemProperties = new HashMap<String, String>(); GUtil.addToMap(systemProperties, jvmOptions.getMutableSystemProperties()); return systemProperties; } public Map<String, String> getEffectiveSystemProperties() { Map<String, String> systemProperties = new HashMap<String, String>(); GUtil.addToMap(systemProperties, jvmOptions.getMutableSystemProperties()); GUtil.addToMap(systemProperties, jvmOptions.getImmutableDaemonProperties()); GUtil.addToMap(systemProperties, System.getProperties()); return systemProperties; } public void setJvmArgs(Iterable<String> jvmArgs) { hasJvmArgs = true; jvmOptions.setAllJvmArgs(jvmArgs); } public void setDebug(boolean debug) { jvmOptions.setDebug(debug); } public DaemonParameters setBaseDir(File baseDir) { this.baseDir = baseDir; return this; } public boolean getDebug() { return jvmOptions.getDebug(); } public boolean isForeground() { return foreground; } public void setForeground(boolean foreground) { this.foreground = foreground; } public boolean isStop() { return stop; } public void setStop(boolean stop) { this.stop = stop; } public boolean isStatus() { return status; } public void setStatus(boolean status) { this.status = status; } }
@Nullable public DaemonParameters setJvm(JavaInfo jvm) { this.jvm = jvm == null ? Jvm.current() : jvm; return this; }
public File getJavaHome() { return javaHome == null ? Jvm.current().getJavaHome() : javaHome; }