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

Fix #5511: don't anymore rely on CodeSource#getLocation() #5519

Merged
merged 8 commits into from
Nov 3, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.sun.faces.config.manager.tasks;

import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -30,7 +31,8 @@

public final class ProvideMetadataToAnnotationScanTask {

private static final Pattern JAR_PATTERN = Pattern.compile("(.*/(\\S*\\.jar)).*(/faces-config.xml|/*.\\.faces-config.xml)");
private static final Pattern FACES_CONFIG_XML_IN_JAR_PATTERN = Pattern.compile("(.*/(\\S*\\.jar)).*(/faces-config.xml|/*.\\.faces-config.xml)");
private static final Pattern CURRENT_RESOURCE_IN_JAR_PATTERN = Pattern.compile("(?<=\\.jar)[!/].*");

private final DocumentInfo[] documentInfos;
private final InjectionProvider containerConnector;
Expand All @@ -53,15 +55,15 @@ private void initializeIvars(Set<Class<?>> annotatedSet) {

for (DocumentInfo docInfo : documentInfos) {

URI sourceURI = docInfo.getSourceURI();
Matcher jarMatcher = JAR_PATTERN.matcher(sourceURI == null ? "" : sourceURI.toString());
URI facesConfigURI = docInfo.getSourceURI();
Matcher jarMatcher = FACES_CONFIG_XML_IN_JAR_PATTERN.matcher(facesConfigURI == null ? "" : facesConfigURI.toString());

if (jarMatcher.matches()) {
String jarName = jarMatcher.group(2);
if (!jarNames.contains(jarName)) {
FacesConfigInfo configInfo = new FacesConfigInfo(docInfo);
if (!configInfo.isMetadataComplete()) {
uris.add(sourceURI);
uris.add(facesConfigURI);
jarNames.add(jarName);
} else {
/*
Expand All @@ -72,10 +74,12 @@ private void initializeIvars(Set<Class<?>> annotatedSet) {
* annotatedSet because the faces-config.xml that owns it has metadata-complete="true".
*/
ArrayList<Class<?>> toRemove = new ArrayList<>(1);
String sourceURIString = sourceURI.toString();
String facesConfigURIString = facesConfigURI.toString();
if (annotatedSet != null) {
for (Class<?> clazz : annotatedSet) {
if (sourceURIString.contains(clazz.getProtectionDomain().getCodeSource().getLocation().toString())) {
String jarURIString = CURRENT_RESOURCE_IN_JAR_PATTERN.split(clazz.getResource(".").toString(), 2)[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not seeing a test here that validates this change over?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added integration test: 1ff6714


if (facesConfigURIString.startsWith(jarURIString)) {
toRemove.add(clazz);
}
}
Expand Down
Loading