Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#11745] Apply Version templating to plugin-test module #11770

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions agent-module/plugins-test-module/plugins-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,6 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.navercorp.pinpoint.test.plugin;
public final class PluginEngineTemplate {

Check warning on line 2 in agent-module/plugins-test-module/plugins-test/src/main/java-templates/com/navercorp/pinpoint/test/plugin/PluginEngineTemplate.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins-test-module/plugins-test/src/main/java-templates/com/navercorp/pinpoint/test/plugin/PluginEngineTemplate.java#L2

Added line #L2 was not covered by tests
public static final String PROJECT_VERSION = "${project.version}";
public static final String LOG4J_VERSION = "${log4j2.version}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -145,7 +145,7 @@
final List<PluginTestInstance> 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;

Check warning on line 148 in agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/DefaultPluginTestSuite.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/DefaultPluginTestSuite.java#L148

Added line #L148 was not covered by tests
final Map<String, List<Artifact>> agentDependency = resolver.resolveDependencySets(pluginsTest);
final List<String> agentLibs = new ArrayList<>(context.getAgentLibList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,6 +10,8 @@

public final class PluginClassLoading {

private static final String VERSION = VersionUtils.VERSION;

Check warning on line 13 in agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java#L13

Added line #L13 was not covered by tests

private static final String[] CLASS_PATHS_TO_CHECK_AS_CONTAINS = new String[]{
"junit", // JUnit
"opentest4",
Expand Down Expand Up @@ -54,7 +57,7 @@
}

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()

Check warning on line 60 in agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java#L60

Added line #L60 was not covered by tests
};

public static String[] getGlobMatchesCheckClassPath() {
Expand Down Expand Up @@ -84,7 +87,7 @@
"slf4j-tinylog"
};

private static final String LOG4J2_VERSION = Log4j2VersionTemplate.VERSION;
private static final String LOG4J2_VERSION = PluginEngineTemplate.LOG4J_VERSION;
private static final String[] LOGGER_DEPENDENCY_ID = new String[]{
"org.apache.logging.log4j:log4j-api:%s",
"org.apache.logging.log4j:log4j-core:%s",
Expand All @@ -103,13 +106,13 @@
}

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

Check warning on line 110 in agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java#L109-L110

Added lines #L109 - L110 were not covered by tests
};

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)

Check warning on line 115 in agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/PluginClassLoading.java#L114-L115

Added lines #L114 - L115 were not covered by tests
};

public static final String[] PLUGIN_IT_UTILS_CONTAINS_MATCHES = new String[]{
Expand Down Expand Up @@ -142,4 +145,4 @@
Paths.get("testcase", "target").toString(),
Paths.get("testcase", "target", "classes").toString()
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@
return string.length();
}

public static String wrap(final String str, final String wrapToken) {
if (isEmpty(str)) {
return str;

Check warning on line 38 in agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/StringUtils.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/StringUtils.java#L38

Added line #L38 was not covered by tests
}
return wrapToken + str + wrapToken;

Check warning on line 40 in agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/StringUtils.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/StringUtils.java#L40

Added line #L40 was not covered by tests
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.navercorp.pinpoint.test.plugin.util;

import com.navercorp.pinpoint.test.plugin.PluginEngineTemplate;

public class VersionUtils {

Check warning on line 5 in agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/VersionUtils.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins-test-module/plugins-test/src/main/java/com/navercorp/pinpoint/test/plugin/util/VersionUtils.java#L5

Added line #L5 was not covered by tests

public static String VERSION = PluginEngineTemplate.PROJECT_VERSION;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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"});
Expand All @@ -29,42 +31,42 @@ public void filter() throws MalformedURLException {
List<URL> list = Arrays.asList(url1, url2, url3, url4, url5);
Collections.shuffle(list);

Collection<Path> result = new ArrayDeque<>();
Collection<String> 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());
}

@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;
Expand Down