Skip to content

Commit acc4241

Browse files
Add logic to base remote engine to avoid failing when running tests from IDE due to class path resolution
1 parent a7a08ac commit acc4241

File tree

1 file changed

+14
-1
lines changed
  • jmeter-java-dsl-base-remote-engine/src/main/java/us/abstracta/jmeter/javadsl/engines

1 file changed

+14
-1
lines changed

jmeter-java-dsl-base-remote-engine/src/main/java/us/abstracta/jmeter/javadsl/engines/BaseRemoteEngine.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,20 @@ private void addDependency(Object elem, Map<Class<?>, File> deps) {
147147

148148
private File getClassJarPath(Class<?> theClass) {
149149
try {
150-
return new File(theClass.getProtectionDomain().getCodeSource().getLocation().toURI());
150+
File ret = new File(theClass.getProtectionDomain().getCodeSource().getLocation().toURI());
151+
/*
152+
when using IDE, it may solve to the directory of another module, which is no good for
153+
uploading to remote engine
154+
*/
155+
if (ret.isDirectory() && ret.getPath().matches(".*[/\\\\]target[/\\\\](test-)?classes$")) {
156+
File[] jars = new File(ret.getParent())
157+
.listFiles((dir, name) -> name.endsWith(".jar")
158+
&& !name.endsWith("-tests.jar") && !name.endsWith("-javadoc.jar"));
159+
if (jars.length >= 1) {
160+
ret = jars[0];
161+
}
162+
}
163+
return ret;
151164
} catch (URISyntaxException e) {
152165
throw new RuntimeException(e);
153166
}

0 commit comments

Comments
 (0)