Mercurial > hg > heapstats
changeset 279:898008f06beb
Bug 3766: HeapStats Analyzer plugin does not work
Reviewed-by: ykubota
https://github.com/HeapStats/heapstats/pull/152
author | Yasumasa Suenaga <yasuenag@gmail.com> |
---|---|
date | Mon, 11 Nov 2019 18:08:06 +0900 |
parents | 59c5f8aba0b5 |
children | d9111a1d15cf |
files | ChangeLog README analyzer/core/pom.xml analyzer/fx/heapstats-analyzer analyzer/fx/heapstats-analyzer.bat analyzer/fx/src/main/assembly/distribution.xml analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/fx/MainWindowController.java analyzer/fx/src/main/java/module-info.java analyzer/plugin-api/pom.xml analyzer/plugin-api/src/main/java/jp/co/ntt/oss/heapstats/api/utils/HeapStatsUtils.java |
diffstat | 10 files changed, 52 insertions(+), 196 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Nov 11 17:54:33 2019 +0900 +++ b/ChangeLog Mon Nov 11 18:08:06 2019 +0900 @@ -1,6 +1,7 @@ 2019-11-11 Yasumasa Suenaga <yasuenag@gmail.com> * Bug 3764: Agent thread might not be stopped when it works + * Bug 3766: HeapStats Analyzer plugin does not work 2019-11-10 Yasumasa Suenaga <yasuenag@gmail.com>
--- a/README Mon Nov 11 17:54:33 2019 +0900 +++ b/README Mon Nov 11 18:08:06 2019 +0900 @@ -107,6 +107,10 @@ * Apache Maven * JDK 13 or later +## Add / Create Plugin + +HeapStats Analyzer supports custom plugin. See [SamplePlugin](https://github.com/HeapStats/SamplePlugin) for details. + # CLI # If you want to analyze data which are collected by HeapStats Agent on CUI environment, you can use HeapStats CLI.
--- a/analyzer/core/pom.xml Mon Nov 11 17:54:33 2019 +0900 +++ b/analyzer/core/pom.xml Mon Nov 11 18:08:06 2019 +0900 @@ -54,19 +54,16 @@ </developers> <scm> - <url>http://icedtea.classpath.org/hg/heapstats</url> - <connection>scm:hg:http://icedtea.classpath.org/hg/heapstats</connection> - <developerConnection>scm:hg:ssh://icedtea.classpath.org/hg/heapstats</developerConnection> + <url>https://github.com/HeapStats/heapstats</url> + <connection>scm:git:https://github.com/HeapStats/heapstats.git</connection> + <developerConnection>scm:git:https://github.com/HeapStats/heapstats.git</developerConnection> </scm> <distributionManagement> - <snapshotRepository> - <id>ossrh</id> - <url>https://oss.sonatype.org/content/repositories/snapshots</url> - </snapshotRepository> <repository> - <id>ossrh</id> - <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> + <id>github</id> + <name>GitHub HeapStats Apache Maven Packages</name> + <url>https://maven.pkg.github.com/HeapStats/heapstats</url> </repository> </distributionManagement> @@ -103,45 +100,6 @@ <version>3.0.2</version> </plugin> <plugin> - <groupId>org.sonatype.plugins</groupId> - <artifactId>nexus-staging-maven-plugin</artifactId> - <version>1.6.8</version> - <extensions>true</extensions> - <configuration> - <serverId>ossrh</serverId> - <nexusUrl>https://oss.sonatype.org/</nexusUrl> - <autoReleaseAfterClose>true</autoReleaseAfterClose> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <version>3.0.1</version> - <executions> - <execution> - <id>attach-sources</id> - <phase>deploy</phase> - <goals> - <goal>jar-no-fork</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <version>2.10.4</version> - <executions> - <execution> - <id>attach-javadocs</id> - <phase>deploy</phase> - <goals> - <goal>jar</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> @@ -157,34 +115,4 @@ </plugin> </plugins> </build> - <profiles> - <profile> - <id>release-sign-artifacts</id> - <!-- releasing for maven repository, mvn -DperformRelease=true deploy --> - <activation> - <property> - <name>performRelease</name> - <value>true</value> - </property> - </activation> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-gpg-plugin</artifactId> - <version>1.5</version> - <executions> - <execution> - <id>sign-artifacts</id> - <phase>verify</phase> - <goals> - <goal>sign</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> </project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/analyzer/fx/heapstats-analyzer Mon Nov 11 18:08:06 2019 +0900 @@ -0,0 +1,3 @@ +#!/bin/sh +DIR=`dirname $0` +$DIR/java --module-path $DIR/../mods -Dheapstats.boot.mode=jlink -m heapstats.fx/jp.co.ntt.oss.heapstats.fx.HeapStatsFXAnalyzer $@
--- a/analyzer/fx/heapstats-analyzer.bat Mon Nov 11 17:54:33 2019 +0900 +++ b/analyzer/fx/heapstats-analyzer.bat Mon Nov 11 18:08:06 2019 +0900 @@ -1,3 +1,3 @@ @echo off set DIR=%~dp0 -"%DIR%\java" --module-path "%DIR%..\mods" -m heapstats.fx/jp.co.ntt.oss.heapstats.fx.HeapStatsFXAnalyzer %* +"%DIR%\java" --module-path "%DIR%..\mods" -Dheapstats.boot.mode=jlink -m heapstats.fx/jp.co.ntt.oss.heapstats.fx.HeapStatsFXAnalyzer %*
--- a/analyzer/fx/src/main/assembly/distribution.xml Mon Nov 11 17:54:33 2019 +0900 +++ b/analyzer/fx/src/main/assembly/distribution.xml Mon Nov 11 18:08:06 2019 +0900 @@ -51,6 +51,11 @@ </includes> </fileSet> <fileSet> + <!-- Empty directory --> + <outputDirectory>${file.separator}plugins</outputDirectory> + <excludes><exclude>**/*</exclude></excludes> + </fileSet> + <fileSet> <directory>${project.build.directory}${file.separator}dependency</directory> <outputDirectory>${file.separator}${file.separator}mods</outputDirectory> <includes>
--- a/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/fx/MainWindowController.java Mon Nov 11 17:54:33 2019 +0900 +++ b/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/fx/MainWindowController.java Mon Nov 11 18:08:06 2019 +0900 @@ -24,9 +24,7 @@ import java.net.URLClassLoader; import java.nio.file.DirectoryStream; import java.nio.file.Files; -import java.nio.file.InvalidPathException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -281,31 +279,12 @@ this.hostServices = hostServices; } - private ClassLoader createPluginClassLoader(String appJarString){ - Path appJarPath; - - try{ - appJarPath = Paths.get(appJarString); - } - catch(InvalidPathException e){ - if((appJarString.charAt(0) == '/') && (appJarString.length() > 2)){ // for Windows - appJarPath = Paths.get(appJarString.substring(1)); - } - else{ - throw e; - } - } - - Path libPath = appJarPath.getParent(); + private ClassLoader createPluginClassLoader(){ URL[] jarURLList = null; - try(DirectoryStream<Path> jarPaths = Files.newDirectoryStream(libPath, "*.jar")){ + try(DirectoryStream<Path> jarPaths = Files.newDirectoryStream(HeapStatsUtils.getHeapStatsHomeDirectory().resolve("plugins"), "*.jar")){ jarURLList = StreamSupport.stream(jarPaths.spliterator(), false) .map(new FunctionWrapper<>(p -> p.toUri().toURL())) - .filter(u -> !u.getFile().startsWith("heapstats-")) - .filter(u -> !u.getFile().startsWith("javax.activation-api")) - .filter(u -> !u.getFile().startsWith("jaxb-api")) - .filter(u -> !u.getFile().startsWith("jgraphx-")) .collect(Collectors.toList()) .toArray(new URL[0]); } @@ -313,19 +292,15 @@ Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex); } - return (jarURLList == null) ? MainWindowController.class.getClassLoader() : new URLClassLoader(jarURLList); + var parentLoader = this.getClass().getClassLoader(); + return (jarURLList == null) ? parentLoader : new URLClassLoader("HeapStats Analyzer Plugin ClassLoader", jarURLList, parentLoader); } /** * Load plugins which is defined in heapstats.properties. */ public void loadPlugin(){ - String resourceName = "/" + this.getClass().getName().replace('.', '/') + ".class"; - String appJarString = this.getClass().getResource(resourceName).getPath(); - - pluginClassLoader = appJarString.contains("!") ? createPluginClassLoader(appJarString.substring(0, appJarString.indexOf('!')).replaceFirst("file://", "")) - : MainWindowController.class.getClassLoader(); - + pluginClassLoader = createPluginClassLoader(); FXMLLoader.setDefaultClassLoader(pluginClassLoader); List<String> plugins = new ArrayList<>();
--- a/analyzer/fx/src/main/java/module-info.java Mon Nov 11 17:54:33 2019 +0900 +++ b/analyzer/fx/src/main/java/module-info.java Mon Nov 11 18:08:06 2019 +0900 @@ -38,10 +38,10 @@ exports jp.co.ntt.oss.heapstats.fx to javafx.graphics; opens jp.co.ntt.oss.heapstats.fx to javafx.fxml; - opens jp.co.ntt.oss.heapstats.fx.plugin.builtin.log to javafx.fxml; + opens jp.co.ntt.oss.heapstats.fx.plugin.builtin.log; opens jp.co.ntt.oss.heapstats.fx.plugin.builtin.log.tabs to javafx.fxml; - opens jp.co.ntt.oss.heapstats.fx.plugin.builtin.snapshot to javafx.fxml; + opens jp.co.ntt.oss.heapstats.fx.plugin.builtin.snapshot; opens jp.co.ntt.oss.heapstats.fx.plugin.builtin.snapshot.tabs to javafx.fxml; - opens jp.co.ntt.oss.heapstats.fx.plugin.builtin.threadrecorder to javafx.fxml; - opens jp.co.ntt.oss.heapstats.fx.plugin.builtin.jvmlive to javafx.fxml; + opens jp.co.ntt.oss.heapstats.fx.plugin.builtin.threadrecorder; + opens jp.co.ntt.oss.heapstats.fx.plugin.builtin.jvmlive; }
--- a/analyzer/plugin-api/pom.xml Mon Nov 11 17:54:33 2019 +0900 +++ b/analyzer/plugin-api/pom.xml Mon Nov 11 18:08:06 2019 +0900 @@ -53,19 +53,16 @@ </developers> <scm> - <url>http://icedtea.classpath.org/hg/heapstats</url> - <connection>scm:hg:http://icedtea.classpath.org/hg/heapstats</connection> - <developerConnection>scm:hg:ssh://icedtea.classpath.org/hg/heapstats</developerConnection> + <url>https://github.com/HeapStats/heapstats</url> + <connection>scm:git:https://github.com/HeapStats/heapstats.git</connection> + <developerConnection>scm:git:https://github.com/HeapStats/heapstats.git</developerConnection> </scm> <distributionManagement> - <snapshotRepository> - <id>ossrh</id> - <url>https://oss.sonatype.org/content/repositories/snapshots</url> - </snapshotRepository> <repository> - <id>ossrh</id> - <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> + <id>github</id> + <name>GitHub HeapStats Apache Maven Packages</name> + <url>https://maven.pkg.github.com/HeapStats/heapstats</url> </repository> </distributionManagement> @@ -124,45 +121,6 @@ <version>3.0.2</version> </plugin> <plugin> - <groupId>org.sonatype.plugins</groupId> - <artifactId>nexus-staging-maven-plugin</artifactId> - <version>1.6.8</version> - <extensions>true</extensions> - <configuration> - <serverId>ossrh</serverId> - <nexusUrl>https://oss.sonatype.org/</nexusUrl> - <autoReleaseAfterClose>true</autoReleaseAfterClose> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <version>3.0.1</version> - <executions> - <execution> - <id>attach-sources</id> - <phase>deploy</phase> - <goals> - <goal>jar-no-fork</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <version>2.10.4</version> - <executions> - <execution> - <id>attach-javadocs</id> - <phase>deploy</phase> - <goals> - <goal>jar</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> @@ -178,34 +136,4 @@ </plugin> </plugins> </build> - <profiles> - <profile> - <id>release-sign-artifacts</id> - <!-- releasing for maven repository, mvn -DperformRelease=true deploy --> - <activation> - <property> - <name>performRelease</name> - <value>true</value> - </property> - </activation> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-gpg-plugin</artifactId> - <version>1.5</version> - <executions> - <execution> - <id>sign-artifacts</id> - <phase>verify</phase> - <goals> - <goal>sign</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> </project>
--- a/analyzer/plugin-api/src/main/java/jp/co/ntt/oss/heapstats/api/utils/HeapStatsUtils.java Mon Nov 11 17:54:33 2019 +0900 +++ b/analyzer/plugin-api/src/main/java/jp/co/ntt/oss/heapstats/api/utils/HeapStatsUtils.java Mon Nov 11 18:08:06 2019 +0900 @@ -36,6 +36,7 @@ import java.util.ResourceBundle; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; import javafx.scene.control.Alert; @@ -74,11 +75,22 @@ public static Path getHeapStatsHomeDirectory() { if (currentPath == null) { - String appJar = Stream.of(System.getProperty("java.class.path").split(System.getProperty("path.separator"))) - .filter(s -> s.endsWith("heapstats-analyzer.jar")) - .findFirst() - .orElse("."); - currentPath = Paths.get(appJar).toAbsolutePath().getParent(); + if (System.getProperty("heapstats.boot.mode").equals("jlink")) { + currentPath = Path.of(System.getProperty("java.home")); + } else { + Pattern pat = Pattern.compile("heaptats-analzer[^" + System.getProperty("path.separator") + "]*\\.jar$"); + currentPath = Stream.of(System.getProperty("java.class.path").split(System.getProperty("path.separator"))) + .filter(s -> pat.matcher(s).matches()) + .findFirst() + .map(Path::of) + .orElse(Path.of(".")); + + // If currentPath points to a file (e.g. heapstats-analyzer.jar), + // currentPath set to parent path. + if (currentPath.toFile().isFile()) { + currentPath = currentPath.getParent(); + } + } } return currentPath;