diff --git a/impl/src/main/java/com/sun/faces/config/manager/tasks/ProvideMetadataToAnnotationScanTask.java b/impl/src/main/java/com/sun/faces/config/manager/tasks/ProvideMetadataToAnnotationScanTask.java index 3eb07472e0..5a5c6406bf 100644 --- a/impl/src/main/java/com/sun/faces/config/manager/tasks/ProvideMetadataToAnnotationScanTask.java +++ b/impl/src/main/java/com/sun/faces/config/manager/tasks/ProvideMetadataToAnnotationScanTask.java @@ -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; @@ -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; @@ -53,15 +55,15 @@ private void initializeIvars(Set> 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 { /* @@ -72,10 +74,13 @@ private void initializeIvars(Set> annotatedSet) { * annotatedSet because the faces-config.xml that owns it has metadata-complete="true". */ ArrayList> 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())) { + URL classURI = clazz.getClassLoader().getResource(clazz.getName().replace('.', '/') + ".class"); + String jarURIString = CURRENT_RESOURCE_IN_JAR_PATTERN.split(classURI.toString(), 2)[0]; + + if (facesConfigURIString.startsWith(jarURIString)) { toRemove.add(clazz); } } diff --git a/test/example_jar_with_metadata_complete_false/pom.xml b/test/example_jar_with_metadata_complete_false/pom.xml new file mode 100644 index 0000000000..56cff34403 --- /dev/null +++ b/test/example_jar_with_metadata_complete_false/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.eclipse.mojarra.test + pom + 4.0.9-SNAPSHOT + + + example_jar_with_metadata_complete_false + jar + + Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId} + + + + org.glassfish + jakarta.faces + ${project.version} + provided + + + diff --git a/test/example_jar_with_metadata_complete_false/src/main/java/org/eclipse/mojarra/test/example_jar_with_metadata_complete_false/ExampleFacesComponent.java b/test/example_jar_with_metadata_complete_false/src/main/java/org/eclipse/mojarra/test/example_jar_with_metadata_complete_false/ExampleFacesComponent.java new file mode 100644 index 0000000000..730e32dcd8 --- /dev/null +++ b/test/example_jar_with_metadata_complete_false/src/main/java/org/eclipse/mojarra/test/example_jar_with_metadata_complete_false/ExampleFacesComponent.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which + * is available at https://openjdk.java.net/legal/gplv2+ce.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0 + */ +package org.eclipse.mojarra.test.example_jar_with_metadata_complete_false; + +import jakarta.faces.component.FacesComponent; +import jakarta.faces.component.html.HtmlOutputText; + +@FacesComponent(createTag = true, namespace="example_jar_with_metadata_complete_false") +public class ExampleFacesComponent extends HtmlOutputText { + +} diff --git a/test/example_jar_with_metadata_complete_false/src/main/resources/META-INF/faces-config.xml b/test/example_jar_with_metadata_complete_false/src/main/resources/META-INF/faces-config.xml new file mode 100644 index 0000000000..0728c095bd --- /dev/null +++ b/test/example_jar_with_metadata_complete_false/src/main/resources/META-INF/faces-config.xml @@ -0,0 +1,8 @@ + + + diff --git a/test/example_jar_with_metadata_complete_true/pom.xml b/test/example_jar_with_metadata_complete_true/pom.xml new file mode 100644 index 0000000000..672f8474bf --- /dev/null +++ b/test/example_jar_with_metadata_complete_true/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.eclipse.mojarra.test + pom + 4.0.9-SNAPSHOT + + + example_jar_with_metadata_complete_true + jar + + Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId} + + + + org.glassfish + jakarta.faces + ${project.version} + provided + + + diff --git a/test/example_jar_with_metadata_complete_true/src/main/java/org/eclipse/mojarra/test/example_jar_with_metadata_complete_true/ExampleFacesComponent.java b/test/example_jar_with_metadata_complete_true/src/main/java/org/eclipse/mojarra/test/example_jar_with_metadata_complete_true/ExampleFacesComponent.java new file mode 100644 index 0000000000..c97b56ee9f --- /dev/null +++ b/test/example_jar_with_metadata_complete_true/src/main/java/org/eclipse/mojarra/test/example_jar_with_metadata_complete_true/ExampleFacesComponent.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which + * is available at https://openjdk.java.net/legal/gplv2+ce.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0 + */ +package org.eclipse.mojarra.test.example_jar_with_metadata_complete_true; + +import jakarta.faces.component.FacesComponent; +import jakarta.faces.component.html.HtmlOutputText; + +@FacesComponent(createTag = true, namespace="example_jar_with_metadata_complete_true") +public class ExampleFacesComponent extends HtmlOutputText { + +} diff --git a/test/example_jar_with_metadata_complete_true/src/main/resources/META-INF/faces-config.xml b/test/example_jar_with_metadata_complete_true/src/main/resources/META-INF/faces-config.xml new file mode 100644 index 0000000000..ea8ec0ee60 --- /dev/null +++ b/test/example_jar_with_metadata_complete_true/src/main/resources/META-INF/faces-config.xml @@ -0,0 +1,8 @@ + + + diff --git a/test/issue5507/src/main/webapp/WEB-INF/web.xml b/test/issue5507/src/main/webapp/WEB-INF/web.xml index 31ee2d0dbe..64e14f6f40 100644 --- a/test/issue5507/src/main/webapp/WEB-INF/web.xml +++ b/test/issue5507/src/main/webapp/WEB-INF/web.xml @@ -30,7 +30,5 @@ facesServlet *.xhtml - *.jsf - /faces/* diff --git a/test/issue5511/pom.xml b/test/issue5511/pom.xml new file mode 100644 index 0000000000..d8f275ff56 --- /dev/null +++ b/test/issue5511/pom.xml @@ -0,0 +1,52 @@ + + + + 4.0.0 + + + org.eclipse.mojarra.test + pom + 4.0.9-SNAPSHOT + + + issue5511 + war + + Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId} + + + + org.eclipse.mojarra.test + example_jar_with_metadata_complete_false + ${project.version} + + + org.eclipse.mojarra.test + example_jar_with_metadata_complete_true + ${project.version} + + + + org.eclipse.mojarra.test + base + ${project.version} + test + + + diff --git a/test/issue5511/src/main/webapp/WEB-INF/beans.xml b/test/issue5511/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/issue5511/src/main/webapp/WEB-INF/web.xml b/test/issue5511/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..64e14f6f40 --- /dev/null +++ b/test/issue5511/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,34 @@ + + + + + facesServlet + jakarta.faces.webapp.FacesServlet + 1 + + + facesServlet + *.xhtml + + diff --git a/test/issue5511/src/main/webapp/issue5511-using-jar-with-metadata-complete-false.xhtml b/test/issue5511/src/main/webapp/issue5511-using-jar-with-metadata-complete-false.xhtml new file mode 100644 index 0000000000..1ac34508f5 --- /dev/null +++ b/test/issue5511/src/main/webapp/issue5511-using-jar-with-metadata-complete-false.xhtml @@ -0,0 +1,31 @@ + + + + + issue5511 - trying to use annotated @FacesComponent from JAR with metadata-complete=false + + + + + diff --git a/test/issue5511/src/main/webapp/issue5511-using-jar-with-metadata-complete-true.xhtml b/test/issue5511/src/main/webapp/issue5511-using-jar-with-metadata-complete-true.xhtml new file mode 100644 index 0000000000..eee8362ed0 --- /dev/null +++ b/test/issue5511/src/main/webapp/issue5511-using-jar-with-metadata-complete-true.xhtml @@ -0,0 +1,31 @@ + + + + + issue5511 - trying to use annotated @FacesComponent from JAR with metadata-complete=true + + + + + diff --git a/test/issue5511/src/test/java/org/eclipse/mojarra/test/issue5511/Issue5511IT.java b/test/issue5511/src/test/java/org/eclipse/mojarra/test/issue5511/Issue5511IT.java new file mode 100644 index 0000000000..debc5f4884 --- /dev/null +++ b/test/issue5511/src/test/java/org/eclipse/mojarra/test/issue5511/Issue5511IT.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which + * is available at https://openjdk.java.net/legal/gplv2+ce.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0 + */ +package org.eclipse.mojarra.test.issue5511; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.eclipse.mojarra.test.base.BaseIT; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +/** + * https://github.com/eclipse-ee4j/mojarra/issues/5511 + */ +class Issue5511IT extends BaseIT { + + @FindBy(id = "exampleFacesComponent") + private WebElement exampleFacesComponent; + + @Test + void testJarWithMetadataCompleteFalse() { + open("issue5511-using-jar-with-metadata-complete-false.xhtml"); + assertEquals("span", exampleFacesComponent.getTagName().toLowerCase(), "The @FacesComponent annotation SHOULD be processed because of metadata-complete=false on its JAR"); + assertEquals("Hello World", exampleFacesComponent.getText(), "Because it renders a span via HtmlOutputText, it should output its value as well."); + } + + @Test + void testJarWithMetadataCompleteTrue() { + open("issue5511-using-jar-with-metadata-complete-true.xhtml"); + assertEquals("ex:examplefacescomponent", exampleFacesComponent.getTagName().toLowerCase(), "The @FacesComponent annotation SHOULD NOT be processed because of metadata-complete=true on its JAR"); + assertEquals("", exampleFacesComponent.getText(), "Because it does not render to a valid HTML element, it should not output anything either."); + } +} diff --git a/test/pom.xml b/test/pom.xml index 04ded8897b..5e526f250d 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -33,11 +33,14 @@ base + example_jar_with_metadata_complete_false + example_jar_with_metadata_complete_true issue5460 issue5464 issue5488 issue5503 issue5507 + issue5511