Skip to content

Commit

Permalink
[#noissue] Remove pinpoint-commons dependency of bootstrap module
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jan 3, 2025
1 parent eeb6751 commit 9f76d77
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 37 deletions.
4 changes: 0 additions & 4 deletions agent-module/bootstraps/bootstrap-java15/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-bootstrap-core</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons</artifactId>
</dependency>

<!-- Logging dependencies -->
<dependency>
Expand Down
4 changes: 0 additions & 4 deletions agent-module/bootstraps/bootstrap-java16/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-bootstrap-core</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons</artifactId>
</dependency>

<!-- Logging dependencies -->
<dependency>
Expand Down
4 changes: 0 additions & 4 deletions agent-module/bootstraps/bootstrap-java9-internal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-bootstrap-core</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons</artifactId>
</dependency>


<!-- Logging dependencies -->
Expand Down
8 changes: 0 additions & 8 deletions agent-module/bootstraps/bootstrap-java9/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-bootstrap-core</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-bootstrap-java9-internal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.navercorp.pinpoint.bootstrap.java9.module;

import com.navercorp.pinpoint.bootstrap.module.Providers;
import com.navercorp.pinpoint.common.util.ClassUtils;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -124,28 +123,20 @@ public String filter(JarEntry jarEntry) {
}

final String fileName = jarEntry.getName();
if (!checkFIleExtension(fileName, CLASS_EXTENSION)) {
if (!checkFileExtension(fileName, CLASS_EXTENSION)) {
// skip non-class file
return null;
}

final String packageName = ClassUtils.getPackageName(fileName, '/', null);
final String packageName = ModuleUtils.getPackageName(fileName, '/');
if (packageName == null) {
return null;
}
return toPackageName(packageName);
return ModuleUtils.toPackageName(packageName);
}

private boolean checkFIleExtension(String fileName, String extension) {
private boolean checkFileExtension(String fileName, String extension) {
return fileName.endsWith(extension);
}


private String toPackageName(String dirFormat) {
if (dirFormat == null) {
return null;
}
return dirFormat.replace('/', '.');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@


import com.navercorp.pinpoint.bootstrap.module.JavaModule;
import com.navercorp.pinpoint.common.util.JvmUtils;
import com.navercorp.pinpoint.common.util.JvmVersion;

import java.lang.instrument.Instrumentation;
import java.net.URL;
Expand Down Expand Up @@ -161,8 +159,7 @@ private void prepareAgentModule(final ClassLoader classLoader, JavaModule agentM

// for Java9DefineClass
baseModule.addExports("jdk.internal.misc", agentModule);
final JvmVersion version = JvmUtils.getVersion();
if (version.onOrAfter(JvmVersion.JAVA_11)) {
if (ModuleUtils.jvmVersionUpper(11)) {
final String internalAccessModule = "jdk.internal.access";
if (baseModule.getPackages().contains(internalAccessModule)) {
baseModule.addExports(internalAccessModule, agentModule);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.navercorp.pinpoint.bootstrap.java9.module;

import java.util.Objects;

public final class ModuleUtils {
private static final int CLASS_BASE_VERSION = 44;
private static final int JAVA_VERSION = readJavaVersion();

public static String getPackageName(String fqcn, char packageSeparator) {
Objects.requireNonNull(fqcn, "fqcn");

final int lastPackageSeparatorIndex = fqcn.lastIndexOf(packageSeparator);
if (lastPackageSeparatorIndex == -1) {
return null;
}
return fqcn.substring(0, lastPackageSeparatorIndex);
}

public static String toPackageName(String dirFormat) {
if (dirFormat == null) {
return null;
}
return dirFormat.replace('/', '.');
}

public static int getJavaVersion() {
return JAVA_VERSION;
}

private static int readJavaVersion() {
return (int) Float.parseFloat(System.getProperty("java.class.version")) - CLASS_BASE_VERSION;
}

public static boolean jvmVersionUpper(int version) {
return getJavaVersion() <= version;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.navercorp.pinpoint.bootstrap.java9.module;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class ModuleUtilsTest {

@Test
void isJava11JvmVersionUpper() {
assertFalse(ModuleUtils.jvmVersionUpper(7));
assertFalse(ModuleUtils.jvmVersionUpper(8));

assertTrue(ModuleUtils.jvmVersionUpper(11));
assertTrue(ModuleUtils.jvmVersionUpper(17));
}
}

0 comments on commit 9f76d77

Please # to comment.