Example usage for com.google.common.base StandardSystemProperty JAVA_CLASS_PATH

List of usage examples for com.google.common.base StandardSystemProperty JAVA_CLASS_PATH

Introduction

In this page you can find the example usage for com.google.common.base StandardSystemProperty JAVA_CLASS_PATH.

Prototype

StandardSystemProperty JAVA_CLASS_PATH

To view the source code for com.google.common.base StandardSystemProperty JAVA_CLASS_PATH.

Click Source Link

Document

Java class path.

Usage

From source file:org.glowroot.container.ClassPath.java

private static @Nullable File getJarFile(String pattern) {
    String classpath = StandardSystemProperty.JAVA_CLASS_PATH.value();
    if (classpath == null) {
        return null;
    }//from   w  w  w. j  a va2 s .c  o  m
    for (String path : Splitter.on(File.pathSeparator).split(classpath)) {
        File file = new File(path);
        if (file.getName().matches(pattern)) {
            return file;
        }
    }
    return null;
}

From source file:org.glowroot.agent.live.JvmTool.java

private static List<String> buildClasspath(@Nullable File glowrootJarFile) {
    if (glowrootJarFile == null || !isShaded()) {
        // this is just to support testing
        List<String> classpath = Lists.newArrayList();
        if (glowrootJarFile != null) {
            classpath.add(glowrootJarFile.getAbsolutePath());
        }//w  w w. j  a v  a 2s . c o m
        classpath.addAll(splitClasspath(StandardSystemProperty.JAVA_CLASS_PATH.value()));
        for (String jvmArg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
            if (jvmArg.startsWith("-Xbootclasspath/a:")) {
                classpath.addAll(splitClasspath(jvmArg.substring("-Xbootclasspath/a:".length())));
                break;
            }
        }
        return classpath;
    } else {
        return ImmutableList.of(glowrootJarFile.getAbsolutePath());
    }
}

From source file:org.glowroot.agent.live.ClasspathCache.java

@GuardedBy("this")
private void updateCacheWithClasspathClasses(Multimap<String, Location> newClassNameLocations) {
    String javaClassPath = StandardSystemProperty.JAVA_CLASS_PATH.value();
    if (javaClassPath == null) {
        return;/*from w  w  w. ja  v  a  2 s . c om*/
    }
    for (String path : Splitter.on(File.pathSeparatorChar).split(javaClassPath)) {
        File file = new File(path);
        Location location = getLocationFromFile(file);
        if (location != null) {
            loadClassNames(location, newClassNameLocations);
        }
    }
}

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 ww  . ja  va2  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 ava2  s.  co  m
    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;
}