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

Make sure that there are no encoded symbols in the jar file paths #198

Merged
merged 1 commit into from
May 17, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package org.hibernate.beanvalidation.tck.tests;

import java.net.URISyntaxException;

import com.beust.jcommander.JCommander;
import jakarta.validation.Validator;
import jakarta.validation.executable.ExecutableValidator;
Expand Down Expand Up @@ -48,18 +50,9 @@ protected static WebArchiveBuilder webArchiveBuilder() {
// Thus we use the protection domain API to obtain the original jar and include it in the war.
// According to our security policy, the TCK has the permission to access the API even if
// the security manager is enabled.
webArchiveBuilder.withAdditionalJar( Assert.class.getProtectionDomain()
.getCodeSource()
.getLocation()
.getPath()
);
webArchiveBuilder.withAdditionalJar( jarPath( Assert.class ) );
// testng 6.14.3 has dependency on jcommander
webArchiveBuilder.withAdditionalJar( JCommander.class.getProtectionDomain()
.getCodeSource()
.getLocation()
.getPath()
);

webArchiveBuilder.withAdditionalJar( jarPath( JCommander.class ) );

return webArchiveBuilder;
}
Expand All @@ -77,4 +70,17 @@ protected ExecutableValidator getExecutableValidator() {
}
return executableValidator;
}

private static String jarPath(Class<?> libraryClass) {
try {
return libraryClass.getProtectionDomain()
.getCodeSource()
.getLocation()
.toURI()
.getPath();
}
catch (URISyntaxException e) {
throw new IllegalStateException( "Cannot resolve jar path for " + libraryClass.getPackageName(), e );
}
}
}