diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/DefaultPluginForkedTestSuite.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/DefaultPluginForkedTestSuite.java index e7f25588ea54..872b5246ffbe 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/DefaultPluginForkedTestSuite.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/DefaultPluginForkedTestSuite.java @@ -28,7 +28,7 @@ import org.eclipse.aether.resolution.DependencyResolutionException; import org.tinylog.TaggedLogger; -import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -123,9 +123,9 @@ protected List createTestCases(PluginForkedTestContext private List createSharedCasesWithDependencies(PluginForkedTestContext context) { DependencyResolver resolver = getDependencyResolver(this.repositories); - List sharedLibs = new ArrayList<>(); - sharedLibs.add(context.getTestClassLocation()); - sharedLibs.addAll(context.getSharedLibraries()); + List sharedLibs = new ArrayList<>(); + sharedLibs.add(context.getTestClassLocationPath()); + sharedLibs.addAll(FileUtils.toPaths(context.getSharedLibraries())); if (sharedDependencies != null) { Map> dependencyMap = resolver.resolveDependencySets(sharedDependencies); for (Map.Entry> artifactEntry : dependencyMap.entrySet()) { @@ -152,7 +152,7 @@ private List createSharedCasesWithDependencies(PluginF final String testId = artifactEntry.getKey(); final List artifacts = artifactEntry.getValue(); - List libs = null; + List libs = null; try { libs = resolveArtifactsAndDependencies(resolver, artifacts); } catch (DependencyResolutionException e) { @@ -169,8 +169,8 @@ private List createSharedCasesWithDependencies(PluginF return cases; } - private List resolveArtifactsAndDependencies(DependencyResolver resolver, List artifacts) throws DependencyResolutionException { - final List files = resolver.resolveArtifactsAndDependencies(artifacts); + private List resolveArtifactsAndDependencies(DependencyResolver resolver, List artifacts) throws DependencyResolutionException { + final List files = resolver.resolveArtifactsAndDependencies(artifacts); return FileUtils.toAbsolutePath(files); } @@ -178,7 +178,7 @@ private DependencyResolver getDependencyResolver(String[] repositories) { return RESOLVER_FACTORY.get(repositories); } - private PluginForkedTestInstance newSharedProcessPluginTestCase(PluginForkedTestContext context, String testId, List libs, SharedProcessManager sharedProcessManager) { + private PluginForkedTestInstance newSharedProcessPluginTestCase(PluginForkedTestContext context, String testId, List libs, SharedProcessManager sharedProcessManager) { if (classLoding == ClassLoding.System) { return new SharedPluginForkedTestInstance(context, testId, libs, true, sharedProcessManager); } 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 7cf945be280e..5ad1a397a979 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 @@ -34,8 +34,8 @@ import org.eclipse.aether.resolution.DependencyResolutionException; import org.tinylog.TaggedLogger; -import java.io.File; import java.net.URL; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -108,9 +108,9 @@ public PluginSharedInstance createSharedInstance(PluginTestContext context) { return null; } - final List libs = new ArrayList<>(); - libs.add(context.getTestClassLocation().toString()); - libs.addAll(context.getSharedLibList()); + final List libs = new ArrayList<>(); + libs.add(context.getTestClassLocation()); + libs.addAll(FileUtils.toPaths(context.getSharedLibList())); if (ArrayUtils.hasLength(sharedDependencies)) { final DependencyResolver resolver = getDependencyResolver(repositories); @@ -150,7 +150,8 @@ private List createCasesWithDependencies(PluginTestContext c final String pluginsTest = "com.navercorp.pinpoint:pinpoint-plugins-test:" + VersionUtils.VERSION; final Map> agentDependency = resolver.resolveDependencySets(pluginsTest); - final List agentLibs = new ArrayList<>(context.getAgentLibList()); + final List agentLibs = new ArrayList<>(16); + agentLibs.addAll(FileUtils.toPaths(context.getAgentLibList())); for (Map.Entry> dependencyCase : agentDependency.entrySet()) { try { @@ -165,7 +166,7 @@ private List createCasesWithDependencies(PluginTestContext c final Map> dependencyCases = resolver.resolveDependencySets(DEPENDENCY_VERSION_FILTER, dependencies); for (Map.Entry> dependencyCase : dependencyCases.entrySet()) { final String testId = dependencyCase.getKey(); - final List libs = new ArrayList<>(); + final List libs = new ArrayList<>(); try { final List artifactList = dependencyCase.getValue(); libs.addAll(resolveArtifactsAndDependencies(resolver, artifactList)); @@ -174,12 +175,7 @@ private List createCasesWithDependencies(PluginTestContext c continue; } - final List fileList = new ArrayList<>(); - for (String classPath : agentLibs) { - File file = new File(classPath); - fileList.add(file); - } - final URL[] agentUrls = URLUtils.fileToUrls(fileList); + final URL[] agentUrls = URLUtils.pathToUrls(agentLibs); final Thread thread = Thread.currentThread(); final ClassLoader currentClassLoader = thread.getContextClassLoader(); @@ -198,8 +194,8 @@ private List createCasesWithDependencies(PluginTestContext c return pluginTestInstanceList; } - private List resolveArtifactsAndDependencies(DependencyResolver resolver, List artifacts) throws DependencyResolutionException { - final List files = resolver.resolveArtifactsAndDependencies(artifacts); + private List resolveArtifactsAndDependencies(DependencyResolver resolver, List artifacts) throws DependencyResolutionException { + final List files = resolver.resolveArtifactsAndDependencies(artifacts); return FileUtils.toAbsolutePath(files); } @@ -210,7 +206,7 @@ private DependencyResolver getDependencyResolver(String[] repositories) { private List createCasesWithJdkOnly(PluginTestContext context) throws ClassNotFoundException { final PluginTestInstanceFactory pluginTestInstanceFactory = new PluginTestInstanceFactory(context); ClassLoader contextClassLoader = ClassLoaderUtils.getContextClassLoader(); - List libs = Collections.emptyList(); + List libs = Collections.emptyList(); List transformIncludeList = Collections.emptyList(); final PluginTestInstance pluginTestInstance = pluginTestInstanceFactory.create(contextClassLoader, "", null, libs, transformIncludeList, classLoding); final List pluginTestInstanceList = new ArrayList<>(); diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginForkedTestContext.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginForkedTestContext.java index c0007d5e96ac..dcd5655dd1ab 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginForkedTestContext.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginForkedTestContext.java @@ -94,10 +94,14 @@ public List getRepositoryUrls() { return repositoryUrls; } - public String getTestClassLocation() { + public String getTestClassLocation() { return testClassLocation.toString(); } + public Path getTestClassLocationPath() { + return testClassLocation; + } + public Path getAgentJar() { return agentJar; } diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginTestInstanceFactory.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginTestInstanceFactory.java index 3c2103c15017..7c71b03893f4 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginTestInstanceFactory.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginTestInstanceFactory.java @@ -19,13 +19,14 @@ import com.navercorp.pinpoint.test.plugin.agent.PluginTestAgentStarter; import com.navercorp.pinpoint.test.plugin.classloader.PluginAgentTestClassLoader; import com.navercorp.pinpoint.test.plugin.classloader.PluginTestJunitTestClassLoader; +import com.navercorp.pinpoint.test.plugin.util.FileUtils; import com.navercorp.pinpoint.test.plugin.util.URLUtils; import org.junit.platform.commons.JUnitException; -import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.net.URL; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -40,17 +41,14 @@ public PluginTestInstanceFactory(PluginTestContext context) { public PluginTestInstance create(ClassLoader parentClassLoader, String testId, PluginAgentTestClassLoader agentClassLoader, - List libs, + List libs, List transformIncludeList, ClassLoding classLoading) throws ClassNotFoundException { final String id = testId + ":" + classLoading; PluginTestInstanceCallback instanceContext = startAgent(context.getConfigFile().toString(), agentClassLoader); - final List fileList = new ArrayList<>(); - for (String classPath : getClassPath(libs, classLoading)) { - File file = new File(classPath); - fileList.add(file); - } - final URL[] urls = URLUtils.fileToUrls(fileList); + + List classPath = getClassPath(libs, this.context); + final URL[] urls = URLUtils.pathToUrls(classPath); PluginTestJunitTestClassLoader testClassLoader = new PluginTestJunitTestClassLoader(urls, parentClassLoader, instanceContext); testClassLoader.setAgentClassLoader(agentClassLoader); @@ -61,10 +59,11 @@ public PluginTestInstance create(ClassLoader parentClassLoader, String testId, return new DefaultPluginTestInstance(id, testClassLoader, testClass, context.isManageTraceObject(), instanceContext); } - List getClassPath(List libs, ClassLoding classLoading) { - final List libList = new ArrayList<>(context.getJunitLibList()); + List getClassPath(List libs, PluginTestContext context) { + final List libList = new ArrayList<>(16); + libList.addAll(FileUtils.toPaths(context.getJunitLibList())); libList.addAll(libs); - libList.add(context.getTestClassLocation().toString()); + libList.add(context.getTestClassLocation()); return libList; } diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/SharedPluginForkedTestInstance.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/SharedPluginForkedTestInstance.java index 485f259d474c..e47d5cd07403 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/SharedPluginForkedTestInstance.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/SharedPluginForkedTestInstance.java @@ -18,9 +18,11 @@ import com.navercorp.pinpoint.test.plugin.junit5.launcher.SharedPluginForkedTestLauncher; import com.navercorp.pinpoint.test.plugin.shared.SharedProcessManager; +import com.navercorp.pinpoint.test.plugin.util.FileUtils; import java.io.File; import java.io.InputStream; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -34,11 +36,11 @@ public class SharedPluginForkedTestInstance implements PluginForkedTestInstance private final PluginForkedTestContext context; private final String testId; - private final List libs; + private final List libs; private final boolean onSystemClassLoader; private final SharedProcessManager processManager; - public SharedPluginForkedTestInstance(PluginForkedTestContext context, String testId, List libs, boolean onSystemClassLoader, SharedProcessManager processManager) { + public SharedPluginForkedTestInstance(PluginForkedTestContext context, String testId, List libs, boolean onSystemClassLoader, SharedProcessManager processManager) { this.context = context; this.testId = testId + ":" + (onSystemClassLoader ? "system" : "child") + ":" + context.getJvmVersion(); this.libs = libs; @@ -54,7 +56,7 @@ public String getTestId() { public List getClassPath() { if (onSystemClassLoader) { List libs = new ArrayList<>(context.getRequiredLibraries()); - libs.addAll(this.libs); + libs.addAll(FileUtils.toString(this.libs)); libs.add(context.getTestClassLocation()); return libs; @@ -83,8 +85,8 @@ public List getAppArgs() { StringBuilder classPath = new StringBuilder(); classPath.append(CHILD_CLASS_PATH_PREFIX); - for (String lib : libs) { - classPath.append(lib); + for (Path lib : libs) { + classPath.append(lib.toString()); classPath.append(File.pathSeparatorChar); } diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/junit5/launcher/SharedPluginForkedTestLauncher.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/junit5/launcher/SharedPluginForkedTestLauncher.java index 52fb1381bdfd..ca3cd42a7bd1 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/junit5/launcher/SharedPluginForkedTestLauncher.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/junit5/launcher/SharedPluginForkedTestLauncher.java @@ -48,6 +48,8 @@ import java.io.File; import java.io.PrintStream; import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -146,19 +148,19 @@ public SharedPluginForkedTestLauncher(String testClazzName, String testLocation, this.out = out; } - private List newTestCaseInfo(List testParameters, File testClazzLocation, String[] repositoryUrls, ClassLoader dependencyClassLoader) throws Exception { + private List newTestCaseInfo(List testParameters, Path testClazzLocation, String[] repositoryUrls, ClassLoader dependencyClassLoader) throws Exception { ReflectionDependencyResolver dependencyResolver = new ReflectionDependencyResolver(dependencyClassLoader, repositoryUrls); - List loggerDependencies = getLoggerDependencies(dependencyResolver, dependencyClassLoader); + List loggerDependencies = getLoggerDependencies(dependencyResolver, dependencyClassLoader); logger.debug("loggerDependency:{}", loggerDependencies); List testInfos = new ArrayList<>(); for (TestParameter testParameter : testParameters) { - final List testDependency = new ArrayList<>(); + final List testDependency = new ArrayList<>(); testDependency.add(testClazzLocation); testDependency.addAll(loggerDependencies); - List testParameterDependency = getTestParameterDependency(dependencyClassLoader, dependencyResolver, testParameter); + List testParameterDependency = getTestParameterDependency(dependencyClassLoader, dependencyResolver, testParameter); testDependency.addAll(testParameterDependency); final TestInfo testInfo = new TestInfo(testParameter.getTestId(), testDependency, Arrays.asList(repositoryUrls)); @@ -167,40 +169,40 @@ private List newTestCaseInfo(List testParameters, File return testInfos; } - private List getTestParameterDependency(ClassLoader mavenDependencyResolverClassLoader, + private List getTestParameterDependency(ClassLoader mavenDependencyResolverClassLoader, ReflectionDependencyResolver dependencyResolver, TestParameter testParameter) throws Exception { final List mavenDependencies = testParameter.getMavenDependencies(); - List testDependencyFileList = lookup(dependencyResolver, mavenDependencies, mavenDependencyResolverClassLoader); + List testDependencyFileList = lookup(dependencyResolver, mavenDependencies, mavenDependencyResolverClassLoader); if (logger.isDebugEnabled()) { logger.debug("@Dependency {}", mavenDependencies); - for (File file : testDependencyFileList) { + for (Path file : testDependencyFileList) { logger.debug("-> {}", file); } } return testDependencyFileList; } - private List getLoggerDependencies(ReflectionDependencyResolver dependencyResolver, ClassLoader mavenDependencyResolverClassLoader) throws Exception { + private List getLoggerDependencies(ReflectionDependencyResolver dependencyResolver, ClassLoader mavenDependencyResolverClassLoader) throws Exception { if (!testLogger) { return Collections.emptyList(); } List dependencyLib = PluginClassLoading.LOGGER_DEPENDENCY; - List libFiles = lookup(dependencyResolver, dependencyLib, mavenDependencyResolverClassLoader); + List libFiles = lookup(dependencyResolver, dependencyLib, mavenDependencyResolverClassLoader); if (logger.isDebugEnabled()) { logger.debug("LoggerDependency {}", dependencyLib); - for (File libFile : libFiles) { + for (Path libFile : libFiles) { logger.debug("-> {}", libFile); } } return libFiles; } - private List lookup(final ReflectionDependencyResolver dependencyResolver, final List dependencyLib, ClassLoader cl) throws Exception { - Callable> callable = new ThreadContextCallable<>(new Callable>() { + private List lookup(final ReflectionDependencyResolver dependencyResolver, final List dependencyLib, ClassLoader cl) throws Exception { + Callable> callable = new ThreadContextCallable<>(new Callable>() { @Override - public List call() throws Exception { + public List call() throws Exception { return dependencyResolver.lookup(dependencyLib); } }, cl); @@ -225,8 +227,9 @@ private void logTestInformation() { public void execute() throws Exception { logTestInformation(); - ClassLoader mavenDependencyResolverClassLoader = new ChildFirstClassLoader(URLUtils.fileToUrls(mavenDependencyResolverClassPaths)); - File testClazzLocation = new File(testLocation); + URL[] classPath = URLUtils.fileToUrls(mavenDependencyResolverClassPaths); + ClassLoader mavenDependencyResolverClassLoader = new ChildFirstClassLoader(classPath); + Path testClazzLocation = Paths.get(testLocation); List testInfos = newTestCaseInfo(testParameters, testClazzLocation, repositoryUrls, mavenDependencyResolverClassLoader); executes(testInfos); @@ -240,7 +243,8 @@ private void executes(List testInfos) { SharedTestExecutor sharedTestExecutor = null; SharedTestLifeCycleWrapper sharedTestLifeCycleWrapper = null; if (sharedClazzName != null && sharedDependencyResolverClassPaths != null) { - final ClassLoader sharedClassLoader = new ChildFirstClassLoader(URLUtils.fileToUrls(sharedDependencyResolverClassPaths)); + URL[] classPath = URLUtils.fileToUrls(sharedDependencyResolverClassPaths); + final ClassLoader sharedClassLoader = new ChildFirstClassLoader(classPath); sharedTestExecutor = new SharedTestExecutor(sharedClazzName, sharedClassLoader); sharedTestExecutor.startBefore(10, TimeUnit.MINUTES); sharedTestLifeCycleWrapper = sharedTestExecutor.getSharedClassWrapper(); @@ -256,13 +260,13 @@ private void executes(List testInfos) { } private ClassLoader createTestClassLoader(TestInfo testInfo) { - List dependencyFileList = testInfo.getDependencyFileList(); + List dependencyFileList = testInfo.getDependencyFileList(); if (logger.isDebugEnabled()) { - for (File dependency : dependencyFileList) { + for (Path dependency : dependencyFileList) { logger.debug("testcase cl lib :{}", dependency); } } - URL[] urls = URLUtils.fileToUrls(dependencyFileList); + URL[] urls = URLUtils.pathToUrls(dependencyFileList); return new ChildFirstClassLoader(urls, ProfilerClass.PINPOINT_PROFILER_CLASS); } diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/DependencyResolver.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/DependencyResolver.java index 24036ae0df4d..565e8db737d4 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/DependencyResolver.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/DependencyResolver.java @@ -47,7 +47,7 @@ import org.eclipse.aether.version.Version; import org.tinylog.TaggedLogger; -import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -150,22 +150,19 @@ public List getVersions(Artifact artifact, Predicate filter) th rangeRequest.setRepositories(repositories); VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest); + List versions = new ArrayList<>(); - if (filter != null) { - for (Version version : rangeResult.getVersions()) { - if (DependencyVersionFilter.NOT_FILTERED == filter.test(version.toString())) { - versions.add(version); - } + for (Version version : rangeResult.getVersions()) { + if (DependencyVersionFilter.NOT_FILTERED == filter.test(version.toString())) { + versions.add(version); } - } else { - versions = new ArrayList<>(rangeResult.getVersions()); } versions.sort(Comparator.naturalOrder()); return versions; } - public List resolveArtifactsAndDependencies(String artifactsAsString) throws DependencyResolutionException { + public List resolveArtifactsAndDependencies(String artifactsAsString) throws DependencyResolutionException { List artifactList = getArtifactList(artifactsAsString); return resolveArtifactsAndDependencies(artifactList); } @@ -179,25 +176,28 @@ private static List getArtifactList(String value) { return ArtifactIdUtils.toArtifact(artifactNameArray); } - public List resolveArtifactsAndDependencies(List artifacts) throws DependencyResolutionException { + public List resolveArtifactsAndDependencies(List artifacts) throws DependencyResolutionException { List dependencies = new ArrayList<>(); - for (Artifact artifact : artifacts) { dependencies.add(new Dependency(artifact, JavaScopes.RUNTIME)); } + List artifactResults = requestArtifact(dependencies); + + List files = new ArrayList<>(artifactResults.size()); + for (ArtifactResult artifactResult : artifactResults) { + files.add(artifactResult.getArtifact().getFile().toPath()); + } + return files; + } + + private List requestArtifact(List dependencies) throws DependencyResolutionException { CollectRequest collectRequest = new CollectRequest((Dependency) null, dependencies, repositories); DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter); DependencyResult result = system.resolveDependencies(session, dependencyRequest); - List files = new ArrayList<>(); - - for (ArtifactResult artifactResult : result.getArtifactResults()) { - files.add(artifactResult.getArtifact().getFile()); - } - - return files; + return result.getArtifactResults(); } public String getNewestVersion(String groupId, String artifactId) throws VersionRangeResolutionException { @@ -215,7 +215,7 @@ public String getNewestVersion(String groupId, String artifactId) throws Version } public Map> resolveDependencySets(String... dependencies) { - return resolveDependencySets(null, dependencies); + return resolveDependencySets(DependencyVersionFilter::isNotFiltered, dependencies); } public Map> resolveDependencySets(Predicate filter, String... dependencies) { diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/DependencyVersionFilter.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/DependencyVersionFilter.java index 40727c21f5cc..593ec6a69a68 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/DependencyVersionFilter.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/DependencyVersionFilter.java @@ -45,4 +45,8 @@ public boolean test(String value) { } return NOT_FILTERED; } + + public static boolean isNotFiltered(String value) { + return NOT_FILTERED; + } } diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/MavenRepository.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/MavenRepository.java index ac29f1d68f34..84d09578c6df 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/MavenRepository.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/maven/MavenRepository.java @@ -6,10 +6,13 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import java.io.File; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -43,7 +46,7 @@ public String resolveLocalRepository() { Path mavenConfigFile = mavenHomeDir.resolve("settings.xml"); if (isFile(mavenConfigFile)) { - final List localRepoList = getRepositoryFromSettings(mavenConfigFile.toFile()); + final List localRepoList = getRepositoryFromSettings(mavenConfigFile); for (String localRepo : localRepoList) { final Path localRepoPath = Paths.get(localRepo); if (isDirectory(localRepoPath)) { @@ -62,10 +65,9 @@ public String resolveLocalRepository() { return DEFAULT_LOCAL_REPOSITORY; } - public List getRepositoryFromSettings(File mavenConfigFile) { + public List getRepositoryFromSettings(Path mavenConfigFile) { try { - DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document document = builder.parse(mavenConfigFile); + Document document = parse(mavenConfigFile); NodeList nodeList = document.getElementsByTagName("localRepository"); List repositorySettings = new ArrayList<>(); @@ -80,6 +82,13 @@ public List getRepositoryFromSettings(File mavenConfigFile) { return Collections.emptyList(); } + private Document parse(Path mavenConfigFile) throws ParserConfigurationException, SAXException, IOException { + DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + try (InputStream is = Files.newInputStream(mavenConfigFile)) { + return builder.parse(is); + } + } + private Path getMavenRepository() { final String mavenRepo = getMavenRepositoryFromEnv(); diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/PluginSharedInstanceFactory.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/PluginSharedInstanceFactory.java index 01ade5630bd5..4182784d07a7 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/PluginSharedInstanceFactory.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/PluginSharedInstanceFactory.java @@ -20,20 +20,14 @@ import com.navercorp.pinpoint.test.plugin.util.ClassLoaderUtils; import com.navercorp.pinpoint.test.plugin.util.URLUtils; -import java.io.File; import java.net.URL; -import java.util.ArrayList; +import java.nio.file.Path; import java.util.List; public class PluginSharedInstanceFactory { - public PluginSharedInstance create(String testClassName, String sharedClassName, List libs) throws ClassNotFoundException { - final List fileList = new ArrayList<>(); - for (String classPath : libs) { - File file = new File(classPath); - fileList.add(file); - } - final URL[] urls = URLUtils.fileToUrls(fileList); + public PluginSharedInstance create(String testClassName, String sharedClassName, List libs) throws ClassNotFoundException { + final URL[] urls = URLUtils.pathToUrls(libs); final ClassLoader contextClassLoader = ClassLoaderUtils.getContextClassLoader(); final PluginTestSharedTestClassLoader classLoader = new PluginTestSharedTestClassLoader(urls, contextClassLoader); diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/ReflectionDependencyResolver.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/ReflectionDependencyResolver.java index 8216822613b3..e75df7d4b0c0 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/ReflectionDependencyResolver.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/ReflectionDependencyResolver.java @@ -18,8 +18,8 @@ import com.navercorp.pinpoint.test.plugin.util.ThreadContextCallable; -import java.io.File; import java.lang.reflect.Method; +import java.nio.file.Path; import java.util.List; import java.util.Objects; import java.util.concurrent.Callable; @@ -39,12 +39,12 @@ public ReflectionDependencyResolver(ClassLoader classLoader, String[] repository this.repositoryUrls = Objects.requireNonNull(repositoryUrls, "repositoryUrls"); } - public List lookup(final List classpathList) throws Exception { + public List lookup(final List classpathList) throws Exception { String paths = String.join(ArtifactIdUtils.ARTIFACT_SEPARATOR, classpathList); return lookup(paths); } - private List lookup(final String classpath) throws Exception { + private List lookup(final String classpath) throws Exception { synchronized (this) { if (dependencyResolverObject == null) { call(new Callable() { @@ -58,10 +58,10 @@ public Object call() throws Exception { } try { - return call(new Callable>() { + return call(new Callable>() { @Override - public List call() throws Exception { - return (List) resolveArtifactsAndDependenciesMethod.invoke(dependencyResolverObject, classpath); + public List call() throws Exception { + return (List) resolveArtifactsAndDependenciesMethod.invoke(dependencyResolverObject, classpath); } }); } catch (Exception e) { diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/SharedProcessManager.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/SharedProcessManager.java index 26fe4aff47ea..a536250f9320 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/SharedProcessManager.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/SharedProcessManager.java @@ -54,11 +54,11 @@ public class SharedProcessManager implements ProcessManager { private final PluginForkedTestContext context; private final Map> testRepository = new LinkedHashMap<>(); private final String sharedClassName; - private final List sharedLibs; + private final List sharedLibs; private Process process = null; - public SharedProcessManager(PluginForkedTestContext context, String sharedClassName, List sharedLibs) { + public SharedProcessManager(PluginForkedTestContext context, String sharedClassName, List sharedLibs) { this.context = Objects.requireNonNull(context, "context"); this.sharedClassName = sharedClassName; this.sharedLibs = sharedLibs; @@ -143,8 +143,8 @@ private List buildCommand() { option.addOptions(jvmArguments); - String classPath = ClassPath.join(context.getRequiredLibraries()); option.addOption("-cp"); + String classPath = ClassPath.join(context.getRequiredLibraries()); option.addOption(classPath); option.addOption(getAgent()); @@ -155,7 +155,7 @@ private List buildCommand() { final String mavenDependencyResolverClassPaths = ClassPath.join(context.getMavenDependencyLibraries()); option.addSystemProperty(SharedPluginTestConstants.MAVEN_DEPENDENCY_RESOLVER_CLASS_PATHS, mavenDependencyResolverClassPaths); if (sharedLibs != null) { - final String sharedDependencyResolverClassPaths = ClassPath.join(sharedLibs); + final String sharedDependencyResolverClassPaths = ClassPath.joinPath(sharedLibs); option.addSystemProperty(SharedPluginTestConstants.SHARED_DEPENDENCY_RESOLVER_CLASS_PATHS, sharedDependencyResolverClassPaths); } if (sharedClassName != null) { diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/TestInfo.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/TestInfo.java index c4415bcc3b4b..414731e11b0e 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/TestInfo.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/shared/TestInfo.java @@ -16,7 +16,7 @@ package com.navercorp.pinpoint.test.plugin.shared; -import java.io.File; +import java.nio.file.Path; import java.util.List; /** @@ -24,10 +24,10 @@ */ public class TestInfo { private final String testId; - private final List dependencyFileList; + private final List dependencyFileList; private final List repositoryUrls; - public TestInfo(String testId, List dependencyFileList, List repositoryUrls) { + public TestInfo(String testId, List dependencyFileList, List repositoryUrls) { this.testId = testId; this.dependencyFileList = dependencyFileList; this.repositoryUrls = repositoryUrls; @@ -37,7 +37,7 @@ public String getTestId() { return testId; } - public List getDependencyFileList() { + public List getDependencyFileList() { return dependencyFileList; } diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/ClassPath.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/ClassPath.java index e29760035ef9..0e22ba8bd2a6 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/ClassPath.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/ClassPath.java @@ -1,8 +1,10 @@ package com.navercorp.pinpoint.test.plugin.util; import java.io.File; +import java.nio.file.Path; import java.util.List; import java.util.Objects; +import java.util.StringJoiner; public class ClassPath { @@ -16,4 +18,12 @@ public static String[] parse(String classPath) { public static String join(List libPath) { return String.join(SEPARATOR, libPath); } + + public static String joinPath(List paths) { + StringJoiner joiner = new StringJoiner(SEPARATOR); + for (Path lib: paths) { + joiner.add(lib.toString()); + } + return joiner.toString(); + } } diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/FileUtils.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/FileUtils.java index 1ecb7b0b5797..9f8b7682f601 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/FileUtils.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/FileUtils.java @@ -16,8 +16,6 @@ package com.navercorp.pinpoint.test.plugin.util; -import java.io.File; -import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Path; @@ -33,52 +31,45 @@ public final class FileUtils { private FileUtils() { } - public static URL[] toURLs(final File[] files) throws IOException { - Objects.requireNonNull(files, "files"); - return toURLs(files, new FileFunction()); - } - - public static URL[] toURLs(final String[] filePaths) throws IOException { + public static URL[] toURLs(final String[] filePaths) throws MalformedURLException { Objects.requireNonNull(filePaths, "filePaths"); - return toURLs(filePaths, new FilePathFunction()); - } - - - public static URL[] toURLs(final T[] source, final Function function) throws IOException { - final URL[] urls = new URL[source.length]; - for (int i = 0; i < source.length; i++) { - T t = source[i]; - urls[i] = function.apply(t); + final URL[] urls = new URL[filePaths.length]; + for (int i = 0; i < filePaths.length; i++) { + String path = filePaths[i]; + urls[i] = Paths.get(path).toUri().toURL(); } return urls; } - public interface Function { - R apply(T t) throws IOException; - } - + public static List toAbsolutePath(List files) { + Objects.requireNonNull(files, "files"); - private static class FileFunction implements Function { - public URL apply(File file) throws MalformedURLException { - return file.toURI().toURL(); + List libs = new ArrayList<>(files.size()); + for (Path lib : files) { + libs.add(lib.toAbsolutePath()); } + return libs; } - private static class FilePathFunction implements Function { - public URL apply(String filePath) throws MalformedURLException { + public static List toPaths(List filePaths) { + Objects.requireNonNull(filePaths, "filePaths"); + + List result = new ArrayList<>(filePaths.size()); + for (String filePath : filePaths) { final Path file = Paths.get(filePath); - return file.toUri().toURL(); + result.add(file); } + return result; } - public static List toAbsolutePath(List files) { - Objects.requireNonNull(files, "files"); + public static List toString(List filePaths) { + Objects.requireNonNull(filePaths, "filePaths"); - List libs = new ArrayList<>(files.size()); - for (File lib : files) { - libs.add(lib.getAbsolutePath()); + List result = new ArrayList<>(filePaths.size()); + for (Path filePath : filePaths) { + result.add(filePath.toString()); } - return libs; + return result; } } diff --git a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/URLUtils.java b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/URLUtils.java index 8c4624e812be..7b0149b452a1 100644 --- a/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/URLUtils.java +++ b/agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/URLUtils.java @@ -1,13 +1,15 @@ package com.navercorp.pinpoint.test.plugin.util; -import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; public final class URLUtils { - public static URL[] fileToUrls(String[] jars) { + public static URL[] fileToUrls(String[] jars) { if (jars == null) { return new URL[0]; } @@ -19,16 +21,24 @@ public static URL[] fileToUrls(String[] jars) { } } - public static URL[] fileToUrls(List fileList) { - if (fileList == null) { + public static URL[] pathToUrls(List jars) { + if (jars == null) { return new URL[0]; } + List urls = new ArrayList<>(jars.size()); + for (Path jar : jars) { + urls.add(toURL(jar)); + } + return urls.toArray(new URL[0]); + } + + private static URL toURL(Path jar) { try { - final File[] files = fileList.toArray(new File[0]); - return FileUtils.toURLs(files); - } catch (IOException e) { - throw new RuntimeException(e. getMessage(), e); + return jar.toUri().toURL(); + } catch (MalformedURLException e) { + throw new RuntimeException(e); } } + } diff --git a/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/maven/DependencyResolverTest.java b/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/maven/DependencyResolverTest.java index 72a8e7d33783..0c3414c7cae5 100644 --- a/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/maven/DependencyResolverTest.java +++ b/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/maven/DependencyResolverTest.java @@ -22,7 +22,7 @@ import org.eclipse.aether.resolution.DependencyResolutionException; import org.junit.jupiter.api.Test; -import java.io.File; +import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -58,11 +58,11 @@ public void resolveArtifactsAndDependencies() throws DependencyResolutionExcepti int i = 0; for (Map.Entry> set : sets.entrySet()) { logger.debug("{}", i++); - List results = resolver.resolveArtifactsAndDependencies(set.getValue()); + List results = resolver.resolveArtifactsAndDependencies(set.getValue()); logger.debug(set.getKey()); - for (File result : results) { + for (Path result : results) { logger.debug("{}", result); } } diff --git a/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/shared/ReflectionDependencyResolverTest.java b/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/shared/ReflectionDependencyResolverTest.java index 385934f97c31..9f003b4cdfed 100644 --- a/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/shared/ReflectionDependencyResolverTest.java +++ b/agent-module/plugins-test-module/plugins-test/src/test/java/com/navercorp/pinpoint/test/plugin/shared/ReflectionDependencyResolverTest.java @@ -19,7 +19,7 @@ import com.navercorp.pinpoint.test.plugin.util.ClassLoaderUtils; import org.junit.jupiter.api.Test; -import java.io.File; +import java.nio.file.Path; import java.util.Collections; import java.util.List; @@ -35,7 +35,7 @@ public class ReflectionDependencyResolverTest { public void get() throws Exception { ClassLoader contextClassLoader = ClassLoaderUtils.getContextClassLoader(); ReflectionDependencyResolver dependencyResolver = new ReflectionDependencyResolver(contextClassLoader, new String[]{}); - List files = dependencyResolver.lookup(Collections.singletonList("commons-logging:commons-logging:1.2")); + List files = dependencyResolver.lookup(Collections.singletonList("commons-logging:commons-logging:1.2")); assertThat(files).hasSize(1); } } \ No newline at end of file