List of usage examples for com.google.common.base StandardSystemProperty JAVA_HOME
StandardSystemProperty JAVA_HOME
To view the source code for com.google.common.base StandardSystemProperty JAVA_HOME.
Click Source Link
From source file:com.google.devtools.kythe.platform.java.JavacOptionsUtils.java
/** Append the classpath to the list of options.*/ public static void appendJREJarsToClasspath(List<String> arguments) { List<String> paths = Lists.newArrayList(); String javaHome = StandardSystemProperty.JAVA_HOME.value(); for (String jreJar : JRE_JARS) { paths.add(PathUtil.join(javaHome, jreJar)); }/*from w w w . j a va 2 s. co m*/ for (int i = 0; i < arguments.size(); i++) { if (arguments.get(i).equals("-cp")) { if (i + 1 >= arguments.size()) { throw new IllegalArgumentException("Malformed -cp argument: " + arguments); } arguments.remove(i); for (String path : arguments.remove(i).split(":")) { paths.add(path); } break; } } arguments.add("-cp"); arguments.add(Joiner.on(":").join(paths)); }
From source file:org.glowroot.agent.live.JvmTool.java
private static List<String> buildCommand(long pid, String methodName, @Nullable File glowrootJarFile) { List<String> command = Lists.newArrayList(); String javaExecutable = StandardSystemProperty.JAVA_HOME.value() + File.separator + "bin" + File.separator + "java"; command.add(javaExecutable);//from w w w.j a va2s . com command.add("-classpath"); command.add(Joiner.on(File.pathSeparatorChar).join(buildClasspath(glowrootJarFile))); command.add(JvmTool.class.getName()); command.add(Long.toString(pid)); command.add(methodName); return command; }
From source file:org.glowroot.container.impl.JavaagentContainer.java
static List<String> buildCommand(int containerPort, File dataDir, boolean useFileDb, boolean viewerMode, List<String> extraJvmArgs) throws Exception { List<String> command = Lists.newArrayList(); String javaExecutable = StandardSystemProperty.JAVA_HOME.value() + File.separator + "bin" + File.separator + "java"; command.add(javaExecutable);//from w w w . j av a 2 s . c o m command.addAll(extraJvmArgs); // it is important for jacoco javaagent to be prior to glowroot javaagent so that jacoco // will use original class bytes to form its class id at runtime which will then match up // with the class id at analysis time command.addAll(getJacocoArgsFromCurrentJvm()); String classpath = Strings.nullToEmpty(StandardSystemProperty.JAVA_CLASS_PATH.value()); if (viewerMode) { command.add("-classpath"); command.add(classpath); command.add("-Dglowroot.testHarness.viewerMode=true"); } else { List<String> paths = Lists.newArrayList(); File javaagentJarFile = null; for (String path : Splitter.on(File.pathSeparatorChar).split(classpath)) { File file = new File(path); if (file.getName().matches("glowroot-core-[0-9.]+(-SNAPSHOT)?.jar")) { javaagentJarFile = file; } else { paths.add(path); } } if (javaagentJarFile != null) { File relocatedJavaagentJarFile = new File(dataDir, javaagentJarFile.getName()); Files.copy(javaagentJarFile, relocatedJavaagentJarFile); javaagentJarFile = relocatedJavaagentJarFile; File pluginsDir = new File(dataDir, "plugins"); pluginsDir.mkdir(); for (Iterator<String> i = paths.iterator(); i.hasNext();) { File file = new File(i.next()); if (file.getName().matches("(jdbc|servlet|logger)-plugin-[0-9.]+(-SNAPSHOT)?.jar")) { Files.copy(file, new File(pluginsDir, file.getName())); i.remove(); } } } command.add("-Xbootclasspath/a:" + Joiner.on(File.pathSeparatorChar).join(paths)); if (javaagentJarFile == null) { // create jar file in data dir since that gets cleaned up at end of test already javaagentJarFile = DelegatingJavaagent.createDelegatingJavaagentJarFile(dataDir); command.add("-javaagent:" + javaagentJarFile); command.add("-DdelegateJavaagent=" + Agent.class.getName()); } else { command.add("-javaagent:" + javaagentJarFile); } } command.add("-Dglowroot.data.dir=" + dataDir.getAbsolutePath()); command.add("-Dglowroot.internal.logging.spy=true"); if (!useFileDb) { command.add("-Dglowroot.internal.h2.memdb=true"); } // this is used inside low-entropy docker containers String sourceOfRandomness = System.getProperty("java.security.egd"); if (sourceOfRandomness != null) { command.add("-Djava.security.egd=" + sourceOfRandomness); } command.add("-Xmx" + Runtime.getRuntime().maxMemory()); for (Entry<Object, Object> entry : System.getProperties().entrySet()) { Object keyObject = entry.getKey(); if (!(keyObject instanceof String)) { continue; } String key = (String) keyObject; if (key.startsWith("glowroot.internal.")) { command.add("-D" + key + "=" + entry.getValue()); } } command.add(JavaagentMain.class.getName()); command.add(Integer.toString(containerPort)); return command; }
From source file:org.glowroot.agent.it.harness.impl.JavaagentContainer.java
private static List<String> buildCommand(int heartbeatPort, int collectorPort, int javaagentServicePort, File testDir, List<String> extraJvmArgs) throws Exception { List<String> command = Lists.newArrayList(); String javaExecutable = StandardSystemProperty.JAVA_HOME.value() + File.separator + "bin" + File.separator + "java"; command.add(javaExecutable);//from w ww . j a va 2 s . c om boolean hasXmx = false; for (String extraJvmArg : extraJvmArgs) { command.add(extraJvmArg); if (extraJvmArg.startsWith("-Xmx")) { hasXmx = true; } } // it is important for jacoco javaagent to be prior to glowroot javaagent so that jacoco // will use original class bytes to form its class id at runtime which will then match up // with the class id at analysis time command.addAll(getJacocoArgsFromCurrentJvm()); String classpath = Strings.nullToEmpty(StandardSystemProperty.JAVA_CLASS_PATH.value()); List<String> bootPaths = Lists.newArrayList(); List<String> paths = Lists.newArrayList(); List<String> maybeBootPaths = Lists.newArrayList(); File javaagentJarFile = null; for (String path : Splitter.on(File.pathSeparatorChar).split(classpath)) { File file = new File(path); String name = file.getName(); String targetClasses = File.separator + "target" + File.separator + "classes"; if (name.matches("glowroot-agent-core(-unshaded)?-[0-9.]+(-SNAPSHOT)?.jar") || name.matches("glowroot-agent-it-harness-[0-9.]+(-SNAPSHOT)?.jar")) { javaagentJarFile = file; } else if (name.matches("glowroot-common-[0-9.]+(-SNAPSHOT)?.jar") || name.matches("glowroot-wire-api-[0-9.]+(-SNAPSHOT)?.jar") || name.matches("glowroot-agent-plugin-api-[0-9.]+(-SNAPSHOT)?.jar") || name.matches("glowroot-agent-bytecode-api-[0-9.]+(-SNAPSHOT)?.jar") || name.matches("glowroot-build-error-prone-jdk6-[0-9.]+(-SNAPSHOT)?.jar")) { // these are glowroot-agent-core-unshaded transitive dependencies maybeBootPaths.add(path); } else if (file.getAbsolutePath().endsWith(File.separator + "common" + targetClasses) || file.getAbsolutePath().endsWith(File.separator + "wire-api" + targetClasses) || file.getAbsolutePath().endsWith(File.separator + "plugin-api" + targetClasses) || file.getAbsolutePath().endsWith(File.separator + "bytecode-api" + targetClasses) || file.getAbsolutePath().endsWith(File.separator + "error-prone-jdk6" + targetClasses)) { // these are glowroot-agent-core-unshaded transitive dependencies maybeBootPaths.add(path); } else if (name.matches("glowroot-agent-api-[0-9.]+(-SNAPSHOT)?.jar")) { // agent-api lives with the application paths.add(path); } else if (file.getAbsolutePath().endsWith(File.separator + "api" + targetClasses)) { // agent-api lives with the application paths.add(path); } else if (name.matches("asm-.*\\.jar") || name.matches("grpc-.*\\.jar") || name.matches("opencensus-.*\\.jar") || name.matches("guava-.*\\.jar") // dependency of guava 27.0+ (which is used by glowroot-webdriver-tests) || name.matches("failureaccess-.*\\.jar") || name.matches("HdrHistogram-.*\\.jar") || name.matches("instrumentation-api-.*\\.jar") || name.matches("jackson-.*\\.jar") || name.matches("logback-.*\\.jar") // javax.servlet-api is needed because logback-classic has // META-INF/services/javax.servlet.ServletContainerInitializer || name.matches("javax.servlet-api-.*\\.jar") || name.matches("netty-buffer-.*\\.jar") || name.matches("netty-codec-.*\\.jar") || name.matches("netty-codec-http2-.*\\.jar") || name.matches("netty-codec-http-.*\\.jar") || name.matches("netty-codec-socks-.*\\.jar") || name.matches("netty-common-.*\\.jar") || name.matches("netty-handler-.*\\.jar") || name.matches("netty-handler-proxy-.*\\.jar") || name.matches("netty-resolver-.*\\.jar") || name.matches("netty-transport-.*\\.jar") // optional netty dependency that is required by HttpContentCompressor, need to // include in bootstrap class loader since netty is || name.matches("jzlib-.*\\.jar") || name.matches("protobuf-java-.*\\.jar") || name.matches("slf4j-api-.*\\.jar") || name.matches("value-.*\\.jar") || name.matches("error_prone_annotations-.*\\.jar") || name.matches("jsr305-.*\\.jar")) { // these are glowroot-agent-core-unshaded transitive dependencies maybeBootPaths.add(path); } else if (name.matches("glowroot-common2-[0-9.]+(-SNAPSHOT)?.jar") || name.matches("glowroot-ui-[0-9.]+(-SNAPSHOT)?.jar") || name.matches("glowroot-agent-embedded(-unshaded)?-[0-9.]+(-SNAPSHOT)?.jar")) { // these are glowroot-agent-embedded-unshaded transitive dependencies paths.add(path); } else if (file.getAbsolutePath().endsWith(File.separator + "common2" + targetClasses) || file.getAbsolutePath().endsWith(File.separator + "ui" + targetClasses) || file.getAbsolutePath().endsWith(File.separator + "embedded" + targetClasses)) { // these are glowroot-agent-embedded-unshaded transitive dependencies paths.add(path); } else if (name.matches("compress-.*\\.jar") || name.matches("h2-.*\\.jar") || name.matches("mailapi-.*\\.jar") || name.matches("smtp-.*\\.jar")) { // these are glowroot-agent-embedded-unshaded transitive dependencies paths.add(path); } else if (name.matches("glowroot-agent-it-harness-unshaded-[0-9.]+(-SNAPSHOT)?.jar")) { // this is integration test harness, needs to be in bootstrap class loader when it // it is shaded (because then it contains glowroot-agent-core), and for consistency // putting it in bootstrap class loader at other times as well bootPaths.add(path); } else if (file.getAbsolutePath().endsWith(File.separator + "it-harness" + targetClasses)) { // this is integration test harness, needs to be in bootstrap class loader when it // it is shaded (because then it contains glowroot-agent-core), and for consistency // putting it in bootstrap class loader at other times as well bootPaths.add(path); } else if (name.endsWith(".jar") && file.getAbsolutePath().endsWith(File.separator + "target" + File.separator + name)) { // this is the plugin under test bootPaths.add(path); } else if (name.matches("glowroot-agent-[a-z-]+-plugin-[0-9.]+(-SNAPSHOT)?.jar")) { // this another (core) plugin that it depends on, e.g. the executor plugin bootPaths.add(path); } else if (file.getAbsolutePath().endsWith(targetClasses)) { // this is the plugin under test bootPaths.add(path); } else if (file.getAbsolutePath() .endsWith(File.separator + "target" + File.separator + "test-classes")) { // this is the plugin test classes paths.add(path); } else { // these are plugin test dependencies paths.add(path); } } if (javaagentJarFile == null) { bootPaths.addAll(maybeBootPaths); } else { boolean shaded = false; JarInputStream jarIn = new JarInputStream(new FileInputStream(javaagentJarFile)); try { JarEntry jarEntry; while ((jarEntry = jarIn.getNextJarEntry()) != null) { if (jarEntry.getName().startsWith("org/glowroot/agent/shaded/")) { shaded = true; break; } } } finally { jarIn.close(); } if (shaded) { paths.addAll(maybeBootPaths); } else { bootPaths.addAll(maybeBootPaths); } } command.add("-Xbootclasspath/a:" + Joiner.on(File.pathSeparatorChar).join(bootPaths)); command.add("-classpath"); command.add(Joiner.on(File.pathSeparatorChar).join(paths)); if (XDEBUG) { // the -agentlib arg needs to come before the -javaagent arg command.add("-Xdebug"); command.add("-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y"); } if (javaagentJarFile == null) { // create jar file in test dir since that gets cleaned up at end of test already javaagentJarFile = DelegatingJavaagent.createDelegatingJavaagentJarFile(testDir); command.add("-javaagent:" + javaagentJarFile); command.add("-DdelegateJavaagent=" + AgentPremain.class.getName()); } else { command.add("-javaagent:" + javaagentJarFile); } command.add("-Dglowroot.test.dir=" + testDir.getAbsolutePath()); if (collectorPort != 0) { command.add("-Dglowroot.collector.address=localhost:" + collectorPort); } command.add("-Dglowroot.debug.preCheckLoadedClasses=true"); // this is used inside low-entropy docker containers String sourceOfRandomness = System.getProperty("java.security.egd"); if (sourceOfRandomness != null) { command.add("-Djava.security.egd=" + sourceOfRandomness); } if (!hasXmx) { command.add("-Xmx" + Runtime.getRuntime().maxMemory()); } // leave as much memory as possible to old gen command.add("-XX:NewRatio=20"); for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) { Object keyObject = entry.getKey(); if (!(keyObject instanceof String)) { continue; } String key = (String) keyObject; if (key.startsWith("glowroot.internal.") || key.startsWith("glowroot.test.")) { command.add("-D" + key + "=" + entry.getValue()); } } command.add(JavaagentMain.class.getName()); command.add(Integer.toString(heartbeatPort)); command.add(Integer.toString(javaagentServicePort)); return command; }
From source file:org.glowroot.local.ui.JvmJsonService.java
@GET("/backend/jvm/process-info") String getProcess() throws Exception { String command = System.getProperty("sun.java.command"); String mainClass = null;//from w w w. ja va 2 s . c om List<String> arguments = ImmutableList.of(); if (command != null) { int index = command.indexOf(' '); if (index > 0) { mainClass = command.substring(0, index); arguments = Lists.newArrayList(Splitter.on(' ').split(command.substring(index + 1))); } } RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); String jvm = StandardSystemProperty.JAVA_VM_NAME.value() + " (" + StandardSystemProperty.JAVA_VM_VERSION.value() + ", " + System.getProperty("java.vm.info") + ")"; String java = "version " + StandardSystemProperty.JAVA_VERSION.value() + ", vendor " + StandardSystemProperty.JAVA_VM_VENDOR.value(); String javaHome = StandardSystemProperty.JAVA_HOME.value(); StringBuilder sb = new StringBuilder(); JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb)); jg.writeStartObject(); jg.writeNumberField("startTime", runtimeMXBean.getStartTime()); jg.writeNumberField("uptime", runtimeMXBean.getUptime()); jg.writeStringField("pid", MoreObjects.firstNonNull(processId, "<unknown>")); jg.writeStringField("mainClass", mainClass); jg.writeFieldName("mainClassArguments"); mapper.writeValue(jg, arguments); jg.writeStringField("jvm", jvm); jg.writeStringField("java", java); jg.writeStringField("javaHome", javaHome); jg.writeFieldName("jvmArguments"); mapper.writeValue(jg, runtimeMXBean.getInputArguments()); jg.writeEndObject(); jg.close(); return sb.toString(); }
From source file:org.ow2.proactive.resourcemanager.updater.RMNodeUpdater.java
/** * Build the java subprocess which will be spawned from this JVM. * @param args current JVM arguments// w ww.ja va2 s . c o m * @param jarFile up-to-date node jar file * @return */ private ProcessBuilder generateSubProcess(String[] args, String jarFile) { ProcessBuilder pb; List<String> command = new ArrayList<>(); if (StandardSystemProperty.OS_NAME.value().toLowerCase().contains("windows")) { command.add((new File(StandardSystemProperty.JAVA_HOME.value(), "bin/java.exe")).getAbsolutePath()); } else { command.add((new File(StandardSystemProperty.JAVA_HOME.value(), "bin/java")).getAbsolutePath()); } command.addAll(buildJVMOptions()); command.add("-jar"); command.add(jarFile); command.addAll(removeOptionsUnrecognizedByRMNodeStarter(args)); logger.info("Starting Java command: " + command); pb = new ProcessBuilder(command); pb.inheritIO(); if (pb.environment().containsKey("CLASSPATH")) { pb.environment().remove("CLASSPATH"); } return pb; }