Skip to content

Commit 0cc7d9f

Browse files
authored
feat: java-agent core support jdk11 (#120)
* feat: support JDK9 to JDK11 * fix: resume example ip to 127 * fix: spring cloud 2020 plugins not supported jdk 12+
1 parent 1d22ee6 commit 0cc7d9f

File tree

89 files changed

+3200
-953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+3200
-953
lines changed

polaris-agent-build/bin/build.sh

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
set -e
44

5-
# generate version
6-
if [ $# != 1 ]; then
7-
echo -e "invalid args, eg.bash $0 version"
8-
exit 1
9-
fi
10-
11-
version="$1"
12-
135
# workdir root
146
cd ../..
7+
version=$(xmllint --xpath "//*[local-name()='project']/*[local-name()='properties']/*[local-name()='revision']/text()" pom.xml)
158
workdir=$(pwd)
169
echo "workdir is ${workdir}"
1710

@@ -24,6 +17,9 @@ rm -rf "${folder_name}"
2417
mkdir -p "${folder_name}"
2518
mkdir -p "${folder_name}/conf"
2619
mkdir -p "${folder_name}/plugins"
20+
mkdir -p "${folder_name}/lib"
21+
mkdir -p "${folder_name}/lib/java9"
22+
mkdir -p "${folder_name}/boot"
2723

2824
cp "polaris-agent-build/conf/polaris-agent.config" "${folder_name}/conf"
2925

@@ -36,6 +32,9 @@ else
3632
fi
3733

3834
cp "polaris-agent-core/polaris-agent-core-bootstrap/target/polaris-agent-core-bootstrap.jar" "${folder_name}/"
35+
cp "polaris-agent-core/polaris-agent-core-bootstrap-common/target/polaris-agent-core-bootstrap-common-${version}.jar" "${folder_name}/lib/"
36+
cp "polaris-agent-core/polaris-agent-core-asm-java9/target/polaris-agent-core-asm-java9-${version}.jar" "${folder_name}/lib/java9/"
37+
cp "polaris-agent-core/polaris-agent-core-extension/target/polaris-agent-core-extension-${version}.jar" "${folder_name}/boot/"
3938

4039
pushd "polaris-agent-plugins"
4140
plugin_folders=$(find . -maxdepth 2 | grep -E ".+-plugin$")

polaris-agent-build/bin/build_docker.sh

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22

33
set -e
44

5-
# generate version
6-
if [ $# != 1 ]; then
7-
echo -e "invalid args, eg.bash $0 version"
8-
exit 1
9-
fi
10-
11-
version="$1"
12-
echo "${version}" > version.txt
13-
145
# workdir root
156
cd ../..
7+
version=$(xmllint --xpath "//*[local-name()='project']/*[local-name()='properties']/*[local-name()='revision']/text()" pom.xml)
168
workdir=$(pwd)
179
echo "workdir is ${workdir}"
1810

@@ -25,6 +17,9 @@ rm -rf "${folder_name}"
2517
mkdir -p "${folder_name}"
2618
mkdir -p "${folder_name}/conf"
2719
mkdir -p "${folder_name}/plugins"
20+
mkdir -p "${folder_name}/lib"
21+
mkdir -p "${folder_name}/lib/java9"
22+
mkdir -p "${folder_name}/boot"
2823

2924
cp "polaris-agent-build/conf/polaris-agent.config" "${folder_name}/conf"
3025

@@ -37,6 +32,9 @@ else
3732
fi
3833

3934
cp "polaris-agent-core/polaris-agent-core-bootstrap/target/polaris-agent-core-bootstrap.jar" "${folder_name}/"
35+
cp "polaris-agent-core/polaris-agent-core-bootstrap-common/target/polaris-agent-core-bootstrap-common-${version}.jar" "${folder_name}/lib/"
36+
cp "polaris-agent-core/polaris-agent-core-asm-java9/target/polaris-agent-core-asm-java9-${version}.jar" "${folder_name}/lib/java9/"
37+
cp "polaris-agent-core/polaris-agent-core-extension/target/polaris-agent-core-extension-${version}.jar" "${folder_name}/boot/"
4038

4139
pushd "polaris-agent-plugins"
4240
plugin_folders=$(find . -maxdepth 2 | grep -E ".+-plugin$")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>polaris-agent-core</artifactId>
7+
<groupId>com.tencent.polaris</groupId>
8+
<version>${revision}</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<groupId>org.example</groupId>
14+
<artifactId>polaris-agent-core-asm-java9</artifactId>
15+
16+
<properties>
17+
<!-- <maven.compiler.source>9</maven.compiler.source>-->
18+
<!-- <maven.compiler.target>9</maven.compiler.target>-->
19+
<jdk.version>9</jdk.version>
20+
<jdk.home>${env.JAVA_HOME}</jdk.home>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>com.tencent.polaris</groupId>
27+
<artifactId>polaris-agent-core-common</artifactId>
28+
<version>${project.version}</version>
29+
<optional>true</optional>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.tencent.polaris</groupId>
33+
<artifactId>polaris-agent-core-asm</artifactId>
34+
<version>${project.version}</version>
35+
<optional>true</optional>
36+
</dependency>
37+
</dependencies>
38+
39+
<build>
40+
<plugins>
41+
<!-- <plugin>-->
42+
<!-- <groupId>org.codehaus.mojo</groupId>-->
43+
<!-- <artifactId>build-helper-maven-plugin</artifactId>-->
44+
<!-- <version>3.2.0</version>-->
45+
<!-- <executions>-->
46+
<!-- <execution>-->
47+
<!-- <phase>generate-sources</phase>-->
48+
<!-- <goals><goal>add-source</goal></goals>-->
49+
<!-- <configuration>-->
50+
<!-- <sources>-->
51+
<!-- <source>src/main/java9</source>-->
52+
<!-- <source>src/main/java11</source>-->
53+
<!-- </sources>-->
54+
<!-- </configuration>-->
55+
<!-- </execution>-->
56+
<!-- </executions>-->
57+
<!-- </plugin>-->
58+
<plugin>
59+
<groupId>org.apache.maven.plugins</groupId>
60+
<artifactId>maven-jar-plugin</artifactId>
61+
<executions>
62+
<execution>
63+
<phase>package</phase>
64+
</execution>
65+
</executions>
66+
<configuration>
67+
<archive>
68+
<manifestEntries>
69+
<Automatic-Module-Name>polaris.bootstrap.java9</Automatic-Module-Name>
70+
</manifestEntries>
71+
</archive>
72+
</configuration>
73+
</plugin>
74+
75+
<plugin>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-compiler-plugin</artifactId>
78+
<configuration>
79+
<compilerArgs>
80+
<arg>--add-exports</arg><arg>java.base/jdk.internal.loader=ALL-UNNAMED</arg>
81+
<arg>--add-exports</arg><arg>java.base/jdk.internal.module=ALL-UNNAMED</arg>
82+
<arg>--add-exports</arg><arg>java.base/jdk.internal.access=ALL-UNNAMED</arg>
83+
<!-- jdk9 -->
84+
<!-- <arg>&#45;&#45;add-exports</arg><arg>java.base/jdk.internal.misc=ALL-UNNAMED</arg>-->
85+
<!-- jdk 11 -->
86+
<!-- <arg>&#45;&#45;add-exports</arg><arg>java.base/jdk.internal.access=ALL-UNNAMED</arg>-->
87+
</compilerArgs>
88+
</configuration>
89+
</plugin>
90+
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-surefire-plugin</artifactId>
94+
<configuration>
95+
<argLine>
96+
--add-exports java.base/jdk.internal.loader=ALL-UNNAMED
97+
--add-exports java.base/jdk.internal.module=ALL-UNNAMED
98+
--add-exports java.base/jdk.internal.access=ALL-UNNAMED
99+
<!-- jdk9 -->
100+
<!-- &#45;&#45;add-exports java.base/jdk.internal.misc=ALL-UNNAMED-->
101+
102+
<!-- jdk11 -->
103+
<!-- &#45;&#45;add-exports java.base/jdk.internal.access=ALL-UNNAMED-->
104+
</argLine>
105+
<encoding>${encoding}</encoding>
106+
</configuration>
107+
</plugin>
108+
109+
</plugins>
110+
</build>
111+
112+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package cn.polarismesh.agent.core.asm9.bootstrap;
2+
3+
import cn.polarismesh.agent.core.asm9.module.Providers;
4+
import cn.polarismesh.agent.core.common.utils.ClassUtils;
5+
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.util.*;
9+
import java.util.jar.JarEntry;
10+
import java.util.jar.JarFile;
11+
12+
public class JarFileAnalyzer {
13+
14+
private static final String META_INF = "META-INF/";
15+
16+
private static final String CLASS_EXTENSION = ".class";
17+
18+
private static final String SERVICE_LOADER = META_INF + "services/";
19+
20+
private final JarFile jarFile;
21+
private final JarEntryFilter filter;
22+
private final ServiceLoaderEntryFilter serviceLoaderEntryFilter;
23+
24+
25+
public JarFileAnalyzer(JarFile jarFile) {
26+
this.jarFile = Objects.requireNonNull(jarFile, "jarFile");
27+
this.filter = new PackageFilter();
28+
this.serviceLoaderEntryFilter = new DefaultServiceLoaderEntryFilter();
29+
}
30+
31+
public PackageInfo analyze() {
32+
Set<String> packageSet = new HashSet<>();
33+
List<Providers> providesList = new ArrayList<>();
34+
35+
final Enumeration<JarEntry> entries = jarFile.entries();
36+
while (entries.hasMoreElements()) {
37+
final JarEntry jarEntry = entries.nextElement();
38+
39+
final String packageName = this.filter.filter(jarEntry);
40+
if (packageName != null) {
41+
packageSet.add(packageName);
42+
}
43+
44+
final Providers provides = this.serviceLoaderEntryFilter.filter(jarEntry);
45+
if (provides != null) {
46+
providesList.add(provides);
47+
}
48+
}
49+
return new PackageInfo(packageSet, providesList);
50+
}
51+
52+
53+
interface ServiceLoaderEntryFilter {
54+
Providers filter(JarEntry jarEntry);
55+
}
56+
57+
class DefaultServiceLoaderEntryFilter implements ServiceLoaderEntryFilter {
58+
@Override
59+
public Providers filter(JarEntry jarEntry) {
60+
final String jarEntryName = jarEntry.getName();
61+
if (!jarEntryName.startsWith(SERVICE_LOADER)) {
62+
return null;
63+
}
64+
if (jarEntry.isDirectory()) {
65+
return null;
66+
}
67+
if (jarEntryName.indexOf('/', SERVICE_LOADER.length()) != -1) {
68+
return null;
69+
}
70+
try {
71+
InputStream inputStream = jarFile.getInputStream(jarEntry);
72+
73+
ServiceDescriptorParser parser = new ServiceDescriptorParser();
74+
List<String> serviceImplClassName = parser.parse(inputStream);
75+
String serviceClassName = jarEntryName.substring(SERVICE_LOADER.length());
76+
return new Providers(serviceClassName, serviceImplClassName);
77+
} catch (IOException e) {
78+
throw new IllegalStateException(jarFile.getName() + " File read fail ", e);
79+
}
80+
}
81+
82+
}
83+
84+
85+
interface JarEntryFilter {
86+
String filter(JarEntry jarEntry);
87+
}
88+
89+
static class PackageFilter implements JarEntryFilter {
90+
public String filter(JarEntry jarEntry) {
91+
if (jarEntry.getName().startsWith(META_INF)) {
92+
// skip META-INF
93+
return null;
94+
}
95+
if (jarEntry.isDirectory()) {
96+
// skip empty dir
97+
return null;
98+
}
99+
100+
final String fileName = jarEntry.getName();
101+
if (!checkFIleExtension(fileName, CLASS_EXTENSION)) {
102+
// skip non class file
103+
return null;
104+
}
105+
106+
final String packageName = ClassUtils.getPackageName(fileName, '/', null);
107+
if (packageName == null) {
108+
return null;
109+
}
110+
return toPackageName(packageName);
111+
}
112+
113+
private boolean checkFIleExtension(String fileName, String extension) {
114+
return fileName.endsWith(extension);
115+
}
116+
117+
118+
private String toPackageName(String dirFormat) {
119+
if (dirFormat == null) {
120+
return null;
121+
}
122+
return dirFormat.replace('/', '.');
123+
}
124+
}
125+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2019 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/* copy from pinpoint-apm
18+
* https://github.com/pinpoint-apm/pinpoint/blob/v2.3.3/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module;/PackageInfo.java
19+
*/
20+
21+
package cn.polarismesh.agent.core.asm9.bootstrap;
22+
23+
24+
import cn.polarismesh.agent.core.asm9.module.Providers;
25+
26+
import java.util.List;
27+
import java.util.Objects;
28+
import java.util.Set;
29+
30+
/**
31+
* @author Woonduk Kang(emeroad)
32+
*/
33+
public class PackageInfo {
34+
private final Set<String> packageSet;
35+
private final List<Providers> providersList;
36+
37+
public PackageInfo(Set<String> packageSet, List<Providers> providersList) {
38+
this.packageSet = Objects.requireNonNull(packageSet, "packageSet");
39+
this.providersList = Objects.requireNonNull(providersList, "providersList");
40+
}
41+
42+
public Set<String> getPackage() {
43+
return packageSet;
44+
}
45+
46+
public List<Providers> getProviders() {
47+
return providersList;
48+
}
49+
50+
@Override
51+
public String toString() {
52+
return "PackageInfo{" +
53+
"packageSet=" + packageSet +
54+
", providersList=" + providersList +
55+
'}';
56+
}
57+
}

0 commit comments

Comments
 (0)