Skip to content

Commit

Permalink
Jakarta Namespace - Faces 3.0.0 Complete with ShowCase
Browse files Browse the repository at this point in the history
  • Loading branch information
GedMarc committed Nov 12, 2020
1 parent 8e94291 commit 4391c03
Show file tree
Hide file tree
Showing 25 changed files with 1,203 additions and 7 deletions.
3 changes: 2 additions & 1 deletion commons-beanutils/src/moditect/module-info.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module org.apache.commons.beanutils {
exports org.apache.commons.beanutils;

requires static java.xml;
requires java.xml;
requires java.desktop;

requires org.apache.commons.logging;
requires org.apache.commons.collections4;
Expand Down
6 changes: 6 additions & 0 deletions ehcache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<relocations>
<relocation>
<pattern>javax.xml.bind</pattern>
<shadedPattern>jakarta.xml.bind</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ public class GuicedCDIConfigurator
@Override
public GuiceConfig<?> configure(GuiceConfig config)
{
config.setPathScanning(true);
config.setExcludePaths(true);
config.setClasspathScanning(true);
config.setAnnotationScanning(true);
config.setMethodInfo(true);

config.setExcludeModulesAndJars(true);

return config;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.guicedee.faces.implementations.JakartaFacesConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.guicedee.faces.implementations.JakartaFacesModuleInclusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.guicedee.faces.implementations;

import com.guicedee.guicedinjection.GuiceConfig;
import com.guicedee.guicedinjection.interfaces.IGuiceConfigurator;

public class JakartaFacesConfiguration implements IGuiceConfigurator {

@Override
public GuiceConfig configure(GuiceConfig config) {
return config.setPathScanning(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.guicedee.faces.implementations;

import com.guicedee.guicedinjection.GuiceConfig;
import com.guicedee.guicedinjection.interfaces.IGuiceConfigurator;
import com.guicedee.guicedinjection.interfaces.IGuiceScanJarInclusions;
import com.guicedee.guicedinjection.interfaces.IGuiceScanModuleInclusions;
import jakarta.validation.constraints.NotNull;

import java.util.HashSet;
import java.util.Set;

public class JakartaFacesModuleInclusion implements IGuiceScanModuleInclusions<JakartaFacesModuleInclusion>, IGuiceScanJarInclusions<JakartaFacesModuleInclusion> {

@Override
public @NotNull Set<String> includeModules() {
Set<String> moduleScanningAllowed = new HashSet<>();
moduleScanningAllowed.add("jakarta.faces");
return moduleScanningAllowed;
}

@Override
public @NotNull Set<String> includeJars() {
Set<String> moduleScanningAllowed = new HashSet<>();
moduleScanningAllowed.add("javax.faces-*");
return moduleScanningAllowed;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-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: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.faces.config.configprovider;

import static com.guicedee.guicedinjection.json.StaticStrings.STRING_FORWARD_SLASH;
import static com.sun.faces.config.WebConfiguration.WebContextInitParameter.JakartaFacesConfigFiles;
import static com.sun.faces.util.Util.split;
import static java.util.Arrays.binarySearch;
import static java.util.logging.Level.WARNING;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
import java.util.logging.Logger;

import com.sun.faces.config.WebConfiguration;
import com.sun.faces.config.WebConfiguration.WebContextInitParameter;
import com.sun.faces.spi.ConfigurationResourceProvider;
import com.sun.faces.util.FacesLogger;

import jakarta.faces.FacesException;
import jakarta.servlet.ServletContext;
import com.guicedee.guicedinjection.GuiceContext;
import static com.sun.faces.facelets.util.Classpath.cleanURI;

/**
*
*/
public abstract class BaseWebConfigResourceProvider implements ConfigurationResourceProvider {

private static final Logger LOGGER = FacesLogger.CONFIG.getLogger();

// ------------------------------ Methods from ConfigurationResourceProvider

@Override
public Collection<URI> getResources(ServletContext context) {

WebConfiguration webConfig = WebConfiguration.getInstance(context);
String paths = webConfig.getOptionValue(getParameter());
Set<URI> urls = new LinkedHashSet<>(6);

if (paths != null) {
for (String token : split(context, paths.trim(), getSeparatorRegex())) {
String path = token.trim();
if (!isExcluded(path) && path.length() != 0) {
URI u = getContextURLForPath(context, path);
if (u != null) {
urls.add(u);
} else {
if (LOGGER.isLoggable(WARNING)) {
LOGGER.log(WARNING, "jsf.config.web_resource_not_found", new Object[] { path, JakartaFacesConfigFiles.getQualifiedName() });
}
}
}

}
}

return urls;
}

// ------------------------------------------------------- Protected Methods

protected abstract WebContextInitParameter getParameter();

protected abstract String[] getExcludedResources();

protected abstract String getSeparatorRegex();

protected URI getContextURLForPath(ServletContext context, String path)
{
List<URI> uris = new ArrayList<>();
if (path.startsWith(STRING_FORWARD_SLASH))
{
path = path.substring(1);
}
if (path.contains(STRING_FORWARD_SLASH))
{
path = path.substring(path.lastIndexOf(STRING_FORWARD_SLASH) + 1);
}

GuiceContext.instance()
.getScanResult()
.getResourcesWithLeafName(path)
.forEach(a -> uris.add(cleanURI(a.getURI())));
if (!uris.isEmpty())
{
return uris.get(0);
}
return null;
}


protected boolean isExcluded(String path) {
return binarySearch(getExcludedResources(), path) >= 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.sun.faces.config.configprovider;

import com.guicedee.guicedinjection.interfaces.IPathContentsScanner;

import java.util.HashSet;
import java.util.Set;

public class FacesLocationsScanner
implements IPathContentsScanner
{
@Override
public Set<String> searchFor()
{
Set<String> strings = new HashSet<>();
strings.add("/");
strings.add("");
strings.add("META-INF");
strings.add("META-INF/resources");
strings.add("WEB-INF");
strings.add("WEB-INF/classes/META-INF");
return strings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-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: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.faces.config.configprovider;

import static com.sun.faces.util.Util.getCurrentLoader;
import static java.lang.System.arraycopy;
import static java.util.Collections.emptyList;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import jakarta.faces.FacesException;
import jakarta.servlet.ServletContext;

import com.sun.faces.facelets.util.Classpath;
import com.sun.faces.spi.ConfigurationResourceProvider;

/**
*
*/
public class MetaInfFaceletTaglibraryConfigProvider
implements ConfigurationResourceProvider
{

private static final String SUFFIX = ".taglib.xml";
private static final String WEB_INF_CLASSES = "/WEB-INF/classes/META-INF";

/**
* Array of taglib.xml files included with Facelets 1.1.x. If they are on the classpath, we don't want to process them.
*/
private static final String[] FACELET_CONFIG_FILES = {
"META-INF/jsf-core.taglib.xml",
"META-INF/jsf-html.taglib.xml",
"META-INF/jsf-ui.taglib.xml",
"META-INF/jstl-core.taglib.xml",
"META-INF/jstl-fn.taglib.xml"};

private static final String[] BUILT_IN_TAGLIB_XML_FILES = {"META-INF/mojarra_ext.taglib.xml"

};

// -------------------------------------------- Methods from ConfigProcessor

@Override
public Collection<URI> getResources(ServletContext context)
{
try
{
URL[] externalTaglibUrls = Classpath.search("META-INF/", SUFFIX);
URL[] externalTaglibUrlsWebINF = Classpath.search("WEB-INF/", SUFFIX);
URL[] builtInTaglibUrls = new URL[BUILT_IN_TAGLIB_XML_FILES.length];
ClassLoader runtimeClassLoader = getClass()
.getClassLoader();

for (int i = 0; i < BUILT_IN_TAGLIB_XML_FILES.length; i++)
{
builtInTaglibUrls[i] = runtimeClassLoader.getResource(BUILT_IN_TAGLIB_XML_FILES[i]);
}

URL[] urls = new URL[externalTaglibUrls.length + builtInTaglibUrls.length + externalTaglibUrlsWebINF.length];
arraycopy(externalTaglibUrls, 0, urls, 0, externalTaglibUrls.length);
arraycopy(builtInTaglibUrls, 0, urls, externalTaglibUrls.length, builtInTaglibUrls.length);
arraycopy(externalTaglibUrlsWebINF, 0, urls, externalTaglibUrls.length + builtInTaglibUrls.length, externalTaglibUrlsWebINF.length);
// Perform some 'correctness' checking. If the user has
// removed the FaceletViewHandler from their configuration,
// but has left the jsf-facelets.jar in the classpath, we
// need to ignore the default configuration resouces from
// that JAR.
List<URI> urlsList = pruneURLs(urls);

// Special case for finding taglib files in WEB-INF/classes/META-INF
Set<String> paths = context.getResourcePaths(WEB_INF_CLASSES);
if (paths != null)
{
for (String path : paths)
{
if (path.endsWith(".taglib.xml"))
{
try
{
urlsList.add(new URI(context.getResource(path)
.toExternalForm()
.replaceAll(" ", "%20")));
}
catch (URISyntaxException ex)
{
ex.printStackTrace();
throw new FacesException(ex);
}
}
}
}
java.util.logging.Logger.getLogger("FaceletTagLibraries").log(java.util.logging.Level.CONFIG,"Found the following tag libraries - " + urlsList);
return urlsList;
}
catch (IOException ioe)
{
throw new FacesException("Error searching classpath from facelet-taglib documents", ioe);
}

}

// --------------------------------------------------------- Private Methods

private List<URI> pruneURLs(URL[] urls)
{

List<URI> ret = null;
if (urls != null && urls.length > 0)
{
for (URL url : urls)
{
String u = url.toString();
boolean found = false;
for (String excludeName : FACELET_CONFIG_FILES)
{
if (u.contains(excludeName))
{
found = true;
break;
}
}

if (!found)
{
if (ret == null)
{
ret = new ArrayList<>();
}

try
{
ret.add(new URI(url.toExternalForm()
.replaceAll(" ", "%20")));
}
catch (URISyntaxException ex)
{
ex.printStackTrace();
throw new FacesException(ex);
}
}
}
}

if (ret == null)
{
ret = emptyList();
}

return ret;
}

}

0 comments on commit 4391c03

Please sign in to comment.