diff --git a/agent-module/plugins-test-module/plugins-test/pom.xml b/agent-module/plugins-test-module/plugins-test/pom.xml index 1b71bd83a5be..a8ab351a1257 100644 --- a/agent-module/plugins-test-module/plugins-test/pom.xml +++ b/agent-module/plugins-test-module/plugins-test/pom.xml @@ -195,12 +195,6 @@ - - - src/main/resources - true - - org.codehaus.mojo diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java-templates/com/navercorp/pinpoint/test/plugin/VersionTemplate.java b/agent-module/plugins-test-module/plugins-test/src/main/java-templates/com/navercorp/pinpoint/test/plugin/VersionTemplate.java new file mode 100644 index 000000000000..dc9f0fc84eca --- /dev/null +++ b/agent-module/plugins-test-module/plugins-test/src/main/java-templates/com/navercorp/pinpoint/test/plugin/VersionTemplate.java @@ -0,0 +1,4 @@ +package com.navercorp.pinpoint.test.plugin; +public final class VersionTemplate { + public static final String VERSION_TEMPLATE = "${project.version}"; +} \ No newline at end of file diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/DefaultPluginTestSuite.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/DefaultPluginTestSuite.java index 94bddb460b07..42aeb9d594a8 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/DefaultPluginTestSuite.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/DefaultPluginTestSuite.java @@ -15,7 +15,6 @@ */ package com.navercorp.pinpoint.test.plugin; -import com.navercorp.pinpoint.common.Version; import com.navercorp.pinpoint.common.util.ArrayUtils; import com.navercorp.pinpoint.test.plugin.classloader.PluginAgentTestClassLoader; import com.navercorp.pinpoint.test.plugin.shared.PluginSharedInstance; @@ -26,6 +25,7 @@ import com.navercorp.pinpoint.test.plugin.util.FileUtils; import com.navercorp.pinpoint.test.plugin.util.TestLogger; import com.navercorp.pinpoint.test.plugin.util.URLUtils; +import com.navercorp.pinpoint.test.plugin.util.VersionUtils; import org.eclipse.aether.ConfigurationProperties; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.resolution.DependencyResolutionException; @@ -145,7 +145,7 @@ private List createCasesWithDependencies(PluginTestContext c final List pluginTestInstanceList = new ArrayList<>(); final DependencyResolver resolver = getDependencyResolver(repositories); - final String pluginsTest = "com.navercorp.pinpoint:pinpoint-plugins-test:" + Version.VERSION; + final String pluginsTest = "com.navercorp.pinpoint:pinpoint-plugins-test:" + VersionUtils.VERSION; final Map> agentDependency = resolver.resolveDependencySets(pluginsTest); final List agentLibs = new ArrayList<>(context.getAgentLibList()); diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/LibraryFilter.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/LibraryFilter.java index 383f8b07efc4..c3a85c6619a8 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/LibraryFilter.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/LibraryFilter.java @@ -16,12 +16,11 @@ package com.navercorp.pinpoint.test.plugin; -import java.io.File; -import java.net.URL; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.PathMatcher; +import java.nio.file.Paths; import java.util.Objects; class LibraryFilter { @@ -41,10 +40,6 @@ public boolean filter(String cp) { return false; } - public boolean filter(URL url) { - return filter(url.getFile()); - } - interface LibraryMatcher { boolean include(String filePath); } @@ -97,9 +92,7 @@ private GlobMatcher(String[] paths) { @Override public boolean include(String filePath) { - Path path = new File(filePath).toPath(); - - + Path path = Paths.get(filePath); for (PathMatcher pathMatcher : pathMatchers) { if (pathMatcher.matches(path)) { return true; diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java index 2f42fd91c05a..2e6f3ef5515d 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java @@ -1,6 +1,7 @@ package com.navercorp.pinpoint.test.plugin; -import com.navercorp.pinpoint.common.Version; +import com.navercorp.pinpoint.test.plugin.util.StringUtils; +import com.navercorp.pinpoint.test.plugin.util.VersionUtils; import java.io.File; import java.nio.file.Paths; @@ -9,6 +10,8 @@ public final class PluginClassLoading { + private static final String VERSION = VersionUtils.VERSION; + private static final String[] CLASS_PATHS_TO_CHECK_AS_CONTAINS = new String[]{ "junit", // JUnit "opentest4", @@ -54,7 +57,7 @@ public static String[] getContainsCheckSharedClassPath() { } private static final String[] CLASS_PATHS_TO_CHECK_AS_GLOB_MATCHES = new String[]{ - "**" + File.separator + "pinpoint-*-plugin-" + Version.VERSION + ".jar", // required when executing test via mvn command + Paths.get("**", "pinpoint-*-plugin-" + VERSION + ".jar").toString() }; public static String[] getGlobMatchesCheckClassPath() { @@ -103,13 +106,13 @@ public static List format(String[] libs, String version) { } public static final String[] PLUGIN_GLOB_MATCHES = new String[]{ - "**" + File.separator + "pinpoint-*-plugin-" + Version.VERSION + ".jar", // required when executing test via mvn command - "**" + File.separator + "naver-pinpoint-*-plugin-" + Version.VERSION + ".jar" // required when executing test via mvn command + Paths.get("**", "pinpoint-*-plugin-" + VERSION + ".jar").toString(), // required when executing test via mvn command + Paths.get("**", "naver-pinpoint-*-plugin-" + VERSION + ".jar").toString() // required when executing test via mvn command }; public static final String[] PLUGIN_CONTAINS_MATCHES = new String[]{ - File.separator + "pinpoint" + File.separator + "agent-module" + File.separator + "plugins" + File.separator, - File.separator + "pinpoint-naver" + File.separator + "agent-module" + File.separator + "naver-plugins" + File.separator + StringUtils.wrap(Paths.get("pinpoint", "agent-module", "plugins").toString(), File.separator), + StringUtils.wrap(Paths.get("pinpoint-naver", "agent-module", "naver-plugins").toString(), File.separator) }; public static final String[] PLUGIN_IT_UTILS_CONTAINS_MATCHES = new String[]{ diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/StringUtils.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/StringUtils.java index d1b420e66bb6..b53e0c29315b 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/StringUtils.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/StringUtils.java @@ -33,4 +33,11 @@ public static int getLength(final String string, final int nullValue) { return string.length(); } + public static String wrap(final String str, final String wrapToken) { + if (isEmpty(str)) { + return str; + } + return wrapToken + str + wrapToken; + } + } diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/TestPluginVersion.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/TestPluginVersion.java index d87df29b2636..968a0e00efae 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/TestPluginVersion.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/TestPluginVersion.java @@ -1,58 +1,9 @@ package com.navercorp.pinpoint.test.plugin.util; -import java.io.Closeable; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - public final class TestPluginVersion { - private static final String VERSION_PROPERTIES = "testplugin-version.properties"; - - private static final String VERSION_KEY = "PROJECT_VERSION"; - private static final String NOT_COMPILED = "${project.version}"; - - private static final String VERSION; - - static { - InputStream stream = TestPluginVersion.class.getClassLoader().getResourceAsStream(VERSION_PROPERTIES); - Properties properties = loadProperties(stream); - - VERSION = readString(properties, VERSION_KEY); - } - private static String readString(Properties properties, String key) { - final String projectVersion = properties.getProperty(key); - if (projectVersion == null) { - throw new IllegalStateException(key + " key not found"); - } - if (NOT_COMPILED.equals(projectVersion)) { - throw new IllegalStateException("Install pinpoint-test module( $test> mvn install)"); - } - return projectVersion; - } - - private static void close(Closeable closeable) { - if (closeable != null) { - try { - closeable.close(); - } catch (IOException ignored) { - } - } - } - - private static Properties loadProperties(InputStream stream) { - Properties properties = new Properties(); - try { - properties.load(stream); - return properties; - } catch (IOException e) { - throw new RuntimeException("properties load failed", e); - } finally { - close(stream); - } - } public static String getVersion() { - return VERSION; + return VersionUtils.VERSION; } } diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/VersionUtils.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/VersionUtils.java new file mode 100644 index 000000000000..cdb562a587a6 --- /dev/null +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/VersionUtils.java @@ -0,0 +1,6 @@ +package com.navercorp.pinpoint.test.plugin.util; + +public class VersionUtils { + + public static String VERSION = com.navercorp.pinpoint.test.plugin.VersionTemplate.VERSION_TEMPLATE; +} diff --git a/agent-module/plugins-test-module/plugins-test/src/main/resources/testplugin-version.properties b/agent-module/plugins-test-module/plugins-test/src/main/resources/testplugin-version.properties deleted file mode 100644 index 7f9b780d401e..000000000000 --- a/agent-module/plugins-test-module/plugins-test/src/main/resources/testplugin-version.properties +++ /dev/null @@ -1 +0,0 @@ -PROJECT_VERSION=${project.version} \ No newline at end of file diff --git a/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/LibraryFinderTest.java b/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/LibraryFinderTest.java index bd3bbfe15587..4b5f1aafe0a9 100644 --- a/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/LibraryFinderTest.java +++ b/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/LibraryFinderTest.java @@ -1,6 +1,6 @@ package com.navercorp.pinpoint.test.plugin; -import com.navercorp.pinpoint.common.Version; +import com.navercorp.pinpoint.test.plugin.util.VersionUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -17,6 +17,8 @@ public class LibraryFinderTest { + private static final String VERSION = VersionUtils.VERSION; + @Test public void filter() throws MalformedURLException { LibraryFilter.LibraryMatcher matcher = LibraryFilter.createContainsMatcher(new String[]{"abc", "123"}); @@ -29,10 +31,11 @@ public void filter() throws MalformedURLException { List list = Arrays.asList(url1, url2, url3, url4, url5); Collections.shuffle(list); - Collection result = new ArrayDeque<>(); + Collection result = new ArrayDeque<>(); for (URL url : list) { - if (libraryFinder.filter(url)) { - result.add(Paths.get(url.getPath())); + String path = url.getPath(); + if (libraryFinder.filter(path)) { + result.add(path); } } Assertions.assertEquals(2, result.size()); @@ -40,31 +43,30 @@ public void filter() throws MalformedURLException { @Test public void globTest() throws MalformedURLException { - String jarPath = File.separator + "home" - + File.separator + "pinpoint-mssql-jdbc-driver-plugin" - + File.separator + Version.VERSION - + File.separator + "pinpoint-mssql-jdbc-driver-plugin-" + Version.VERSION + ".jar"; + String jarPath = File.separator + Paths.get("home", + "pinpoint-mssql-jdbc-driver-plugin", + VERSION, + "pinpoint-mssql-jdbc-driver-plugin-" + VERSION + ".jar" + ); - String matchPath = "pinpoint-*-plugin-" + Version.VERSION + ".jar"; + String matchPath = "pinpoint-*-plugin-" + VERSION + ".jar"; Path result = globMatches(jarPath, matchPath); Assertions.assertNull(result); - matchPath = "*" + File.separator + "pinpoint-*-plugin-" + Version.VERSION + ".jar"; - result = globMatches(jarPath, matchPath); - Assertions.assertNull(result); + String matchPath2 = Paths.get("*", "pinpoint-*-plugin-" + VERSION + ".jar").toString(); + Path result2 = globMatches(jarPath, matchPath2); + Assertions.assertNull(result2); - matchPath = "**" + File.separator + "pinpoint-*-plugin-" + Version.VERSION + ".jar"; - result = globMatches(jarPath, matchPath); - Assertions.assertEquals(Paths.get(jarPath), result); + String matchPath3 = Paths.get("**", "pinpoint-*-plugin-" + VERSION + ".jar").toString(); + Path result3 = globMatches(jarPath, matchPath3); + Assertions.assertEquals(Paths.get(jarPath), result3); } private Path globMatches(String jarPath, String matchPath) throws MalformedURLException { LibraryFilter.LibraryMatcher matcher = LibraryFilter.createGlobMatcher(new String[]{matchPath}); LibraryFilter libraryFinder = new LibraryFilter(matcher); - File file = new File(jarPath); - URL url = file.toURI().toURL(); - if (libraryFinder.filter(url)) { + if (libraryFinder.filter(jarPath)) { return Paths.get(jarPath); } return null;