Skip to content

Commit e88fe0e

Browse files
committed
make sure profiler module can be compiled with JDK 1.8 - JDK 1.5 code moved to separate jar
1 parent cf1f10a commit e88fe0e

File tree

6 files changed

+85
-23
lines changed

6 files changed

+85
-23
lines changed

visualvm/profiler/build.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,26 @@
55
<project name="org.graalvm.visualvm.profiler" default="netbeans" basedir=".">
66
<description>Builds, tests, and runs the project org.graalvm.visualvm.profiler.</description>
77
<import file="nbproject/build-impl.xml"/>
8+
<target name="compile-lib" depends="init">
9+
<mkdir dir="${build.dir}/lib-classes" />
10+
<!-- NOTE: Must be built with Source Level 1.5 to work for getting info from Java 5! -->
11+
<javac srcdir="libsrc" destdir="${build.dir}/lib-classes" deprecation="${build.compiler.deprecation}" debug="${build.compiler.debug}" source="1.5" target="1.5">
12+
<classpath>
13+
<pathelement path="${lib.cp}"/>
14+
</classpath>
15+
</javac>
16+
<copy todir="${build.dir}/lib-classes">
17+
<fileset dir="libsrc" excludes="${jar-excludes}" />
18+
</copy>
19+
</target>
20+
21+
<target name="jar-lib" depends="compile-lib">
22+
<mkdir dir="${cluster}/modules/ext" />
23+
<jar jarfile="${cluster}/modules/ext/profilerprobe.jar" manifest="libsrc/manifest.mf" compress="false">
24+
<fileset dir="${build.dir}/lib-classes" />
25+
</jar>
26+
</target>
27+
28+
<target name="compile" depends="jar-lib, projectized-common.compile" />
29+
830
</project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Main-Class: org.graalvm.visualvm.profiler.JavaSysProperies
2+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package org.graalvm.visualvm.profiler;
26+
27+
/**
28+
* NOTE: Must be built with Source Level 1.5 to work for getting info from Java 5!
29+
*
30+
*/
31+
public class JavaSysProperies {
32+
33+
public static void main(String[] args) {
34+
for (String arg : args) System.out.println(System.getProperty(arg));
35+
}
36+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
javac.source=1.5
1+
javac.source=1.8
22
license.file=../startup/src/org/graalvm/visualvm/modules/startup/LICENSE.txt
33
nbm.homepage=https://visualvm.github.io
4+
extra.module.files=modules/ext/profilerprobe.jar
45

visualvm/profiler/nbproject/project.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@
183183
<friend>org.graalvm.visualvm.profiler.startup</friend>
184184
<package>org.graalvm.visualvm.profiler</package>
185185
</friend-packages>
186+
<class-path-extension>
187+
<runtime-relative-path>ext/profilerprobe.jar</runtime-relative-path>
188+
</class-path-extension>
189+
<extra-compilation-unit>
190+
<package-root>libsrc</package-root>
191+
<classpath>${lib.cp}</classpath>
192+
<built-to>${build.dir}/lib-classes</built-to>
193+
<built-to>${cluster}/modules/ext/profilerprobe.jar</built-to>
194+
</extra-compilation-unit>
186195
</data>
187196
</configuration>
188197
</project>

visualvm/profiler/src/org/graalvm/visualvm/profiler/JavaInfo.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,20 @@
2727
import java.io.BufferedReader;
2828
import java.io.File;
2929
import java.io.InputStreamReader;
30-
import java.net.MalformedURLException;
31-
import java.net.URI;
32-
import java.net.URISyntaxException;
33-
import java.net.URL;
3430
import java.util.ArrayList;
3531
import java.util.Arrays;
3632
import java.util.List;
3733
import org.graalvm.visualvm.lib.jfluid.global.Platform;
34+
import org.openide.modules.InstalledFileLocator;
35+
import org.openide.modules.ModuleInfo;
36+
import org.openide.modules.Modules;
3837

3938
/**
40-
* NOTE: Must be built with Source Level 1.5 to work for getting info from Java 5!
4139
*
4240
* @author Jiri Sedlacek
4341
*/
4442
final class JavaInfo {
4543

46-
public static void main(String[] args) {
47-
for (String arg : args) System.out.println(System.getProperty(arg));
48-
}
49-
5044
static String getCurrentJDKExecutable() {
5145
return getJDKExecutable(System.getProperty("java.home")); // NOI18N
5246
}
@@ -65,9 +59,8 @@ static String[] getSystemProperties(File java, String... keys) {
6559
try {
6660
List<String> list = new ArrayList();
6761
list.add(java.getAbsolutePath());
68-
list.add("-cp"); // NOI18N
69-
list.add(getCPJar());
70-
list.add(JavaInfo.class.getName());
62+
list.add("-jar"); // NOI18N
63+
list.add(getProbeJar());
7164
list.addAll(Arrays.asList(keys));
7265

7366
Process p = Runtime.getRuntime().exec(list.toArray(new String[list.size()]));
@@ -91,17 +84,16 @@ static String[] getSystemProperties(File java, String... keys) {
9184
}
9285

9386

94-
private static String CP_JAR;
95-
private static synchronized String getCPJar() throws MalformedURLException, URISyntaxException {
96-
if (CP_JAR == null) {
97-
String name = JavaInfo.class.getSimpleName() + ".class"; // NOI18N
98-
URL url = JavaInfo.class.getResource(name);
99-
String path = url.getFile();
100-
String jar = path.substring(0, path.indexOf("!/")); // NOI18N
101-
URI uri = new URL(jar).toURI();
102-
CP_JAR = new File(uri).getAbsolutePath();
87+
private static final String PROBE_PATH = "modules/ext/profilerprobe.jar"; // NOI18N
88+
private static String PROBE_JAR;
89+
private static synchronized String getProbeJar() {
90+
if (PROBE_JAR == null) {
91+
InstalledFileLocator loc = InstalledFileLocator.getDefault();
92+
ModuleInfo info = Modules.getDefault().ownerOf(JavaInfo.class);
93+
File jar = loc.locate(PROBE_PATH, info.getCodeNameBase(), false);
94+
PROBE_JAR = jar.getAbsolutePath();
10395
}
104-
return CP_JAR;
96+
return PROBE_JAR;
10597
}
10698

10799
private JavaInfo() {}

0 commit comments

Comments
 (0)