Skip to content
Draft
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions enterprise/maven.j2ee/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.

is.eager=true
javac.compilerargs=-Xlint -Xlint:-serial -Xlint -Xlint:-serial
javac.compilerargs=-Xlint -Xlint:-serial

javac.source=1.8
javac.release=17
test.config.stableBTD.includes=**/*Test.class
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.netbeans.modules.maven.embedder.MavenEmbedder;
import org.netbeans.modules.web.jsfapi.api.JsfVersion;
import org.netbeans.modules.web.jsfapi.spi.JsfReferenceImplementationProvider;
import org.openide.util.Exceptions;
import org.openide.util.lookup.ServiceProvider;

/**
Expand All @@ -56,8 +55,8 @@ public class MavenJsfReferenceImplementationProvider implements JsfReferenceImpl
map.put(JsfVersion.JSF_2_2, "com.sun.faces:jsf-impl:2.2.20");
map.put(JsfVersion.JSF_2_3, "org.glassfish:jakarta.faces:2.3.21");
map.put(JsfVersion.JSF_3_0, "org.glassfish:jakarta.faces:3.0.5");
map.put(JsfVersion.JSF_4_0, "org.glassfish:jakarta.faces:4.0.5");
map.put(JsfVersion.JSF_4_1, "org.glassfish:jakarta.faces:4.1.0-M1");
map.put(JsfVersion.JSF_4_0, "org.glassfish:jakarta.faces:4.0.13");
map.put(JsfVersion.JSF_4_1, "org.glassfish:jakarta.faces:4.1.5");
JSF_VERSION_MAVEN_COORDINATES_MAPPING = Collections.unmodifiableMap(map);
}

Expand Down
2 changes: 1 addition & 1 deletion enterprise/web.jsf.editor/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ javac.release=17
javac.compilerargs=-Xlint -Xlint:-serial

test-unit-sys-prop.web.project.jars=\
${web.jsf12.dir}/modules/ext/jsf-2_2/javax.faces.jar:\
${web.jsf12.dir}/modules/ext/jsf-2_3/javax.faces.jar:\
${servletjspapi.dir}/modules/ext/servlet4.0-jsp2.3-api.jar

requires.nb.javac=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.modules.web.jsfapi.api.DefaultLibraryInfo;
import org.netbeans.modules.web.jsfapi.api.JsfVersion;
import org.netbeans.modules.web.jsfapi.api.Library;
import org.netbeans.modules.web.jsfapi.api.LibraryComponent;
import org.netbeans.modules.web.jsfapi.api.LibraryInfo;
Expand All @@ -49,14 +50,27 @@
public class DefaultFaceletLibraries {

private static DefaultFaceletLibraries INSTANCE;

private static String getJarPath(JsfVersion version) {
if (version == null) {
version = JsfVersion.JSF_2_3;
}
return switch (version) {
case JSF_4_1 -> "modules/ext/jsf-4_1/jakarta.faces.jar";
case JSF_4_0 -> "modules/ext/jsf-4_0/jakarta.faces.jar";
case JSF_3_0 -> "modules/ext/jsf-3_0/jakarta.faces.jar";
default -> "modules/ext/jsf-2_3/javax.faces.jar";
};
}

private File jsfImplJar;
private Collection<FileObject> libraryDescriptorsFiles;
private Map<String, FaceletsLibraryDescriptor> librariesDescriptors;
private static Map<String, Library> jsf22FaceletPseudoLibraries;

public static synchronized DefaultFaceletLibraries getInstance() {
if (INSTANCE == null) {
INSTANCE = new DefaultFaceletLibraries();
INSTANCE = new DefaultFaceletLibraries(JsfVersion.JSF_2_3);
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me nervous. Shouldn't the callers of getInstance updated to get correctly versioned variants? You create an instance per Version and get JsfVersion as parameter. Having both singletons and explicitly created instances seems wrong to me.

}
return INSTANCE;
}
Expand All @@ -67,9 +81,9 @@ public DefaultFaceletLibraries(File jsfImplJar) {
init(jsfImplJar);
}

public DefaultFaceletLibraries() {
public DefaultFaceletLibraries(JsfVersion version) {
this(InstalledFileLocator.getDefault().locate(
"modules/ext/jsf-2_2/javax.faces.jar", //NOI18N
getJarPath(version),
"org.netbeans.modules.web.jsf20", false) //NOI18N
);
}
Expand Down Expand Up @@ -105,8 +119,8 @@ private void parseLibraries() {
descritor = FaceletsLibraryDescriptor.create(lfo);
librariesDescriptors.put(descritor.getNamespace(), descritor);
} catch (LibraryDescriptorException ex) {
Logger.global.log(Level.WARNING, "Error parsing facelets library " +
FileUtil.getFileDisplayName(lfo) + " in javax.faces.jar from bundled web.jsf20 library", ex);
Logger.getGlobal().log(Level.WARNING, "Error parsing facelets library " +
FileUtil.getFileDisplayName(lfo) + " from file " + jsfImplJar, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
import org.openide.util.Utilities;

/**
*
Expand Down Expand Up @@ -285,7 +286,7 @@ private Map<String, Library> _findLibraries() {
//exclude the jsf jars from the classpath, if jsf20 library is available,
//we'll use the jars from the netbeans library instead
String fsName = cpRoot.getFileSystem().getDisplayName(); //any better way?
if(!fsName.endsWith("javax.faces.jar")) { //NOI18N
if(!fsName.endsWith("javax.faces.jar") && !fsName.endsWith("jakarta.faces.jar")) { //NOI18N
urlsToLoad.add(URLMapper.findURL(cpRoot, URLMapper.INTERNAL));
LOGGER.log(Level.FINE, "+++{0}", cpRoot); //NOI18N
} else {
Expand All @@ -297,7 +298,7 @@ private Map<String, Library> _findLibraries() {
}
}

ClassLoader proxyLoader = new URLClassLoader(urlsToLoad.toArray(new URL[]{}), originalLoader) {
ClassLoader proxyLoader = new URLClassLoader(urlsToLoad.toArray(URL[]::new), originalLoader) {

//prevent services loading from mojarra's sources
@Override
Expand Down Expand Up @@ -370,7 +371,7 @@ public Enumeration<URL> findResources(String name) throws IOException {
//happen that there is no javax-faces.jar with the .taglib.xml files
//on the compile classpath and we still want the features like code
//completion work. This happens for example in Maven web projects.
DefaultFaceletLibraries defaultFaceletLibraries = DefaultFaceletLibraries.getInstance();
DefaultFaceletLibraries defaultFaceletLibraries = new DefaultFaceletLibraries(jsfVersion);
Collection<FileObject> libraryDescriptorFiles = defaultFaceletLibraries.getLibrariesDescriptorsFiles();
final Collection<URI> libraryURIs = new ArrayList<>();
for (FileObject fo : libraryDescriptorFiles) {
Expand All @@ -382,13 +383,13 @@ public Enumeration<URL> findResources(String name) throws IOException {
}
faceletTaglibProviders.add(sc -> libraryURIs);

jsfRIJars.add(defaultFaceletLibraries.getJsfImplJar().toURI().toURL());
jsfRIJars.add(Utilities.toURI(defaultFaceletLibraries.getJsfImplJar()).toURL());
}
} catch (MalformedURLException ex) {
Exceptions.printStackTrace(ex);
}

URLClassLoader jsfRIClassLoader = new URLClassLoader(jsfRIJars.toArray(new URL[]{}));
URLClassLoader jsfRIClassLoader = new URLClassLoader(jsfRIJars.toArray(URL[]::new));

//parse the libraries
ServletContext sc = new EmptyServletContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@
import org.openide.util.Exceptions;

/**
* provider URLs of libraries defined in javax.faces.FACELETS_LIBRARIES context param of deployment descriptor
* provider URLs of libraries defined in [javax|jakarta].faces.FACELETS_LIBRARIES context param of deployment descriptor
*
* @author marekfukala
*/
public class WebFaceletTaglibResourceProvider implements ConfigurationResourceProvider {

private WebModule wm;

private static final String FACELETS_LIBRARIES_OLD_PROPERTY_NAME = "facelets.LIBRARIES"; //NOI18N
private static final String FACELETS_LIBRARIES_PROPERTY_NAME = "javax.faces.FACELETS_LIBRARIES"; //NOI18N
private static final String FACELETS_LIBRARIES_JAKARTA_PROPERTY_NAME = "jakarta.faces.FACELETS_LIBRARIES"; //NOI18N

private final WebModule wm;

public WebFaceletTaglibResourceProvider(WebModule wm) {
this.wm = wm;
Expand All @@ -65,16 +66,17 @@ public Collection<URI> getResources(ServletContext ignored) {
// This is executed just in case that the model is ready. Otherwise it leads to uncancelable work.
// Another reports against non-consistents result from the first and second invocation should be
// consulted with tzetula for better options how to fix this. Related issue is bug #232878.
faceletsLibrariesList = model.runReadAction(new MetadataModelAction<WebAppMetadata, String>() {
faceletsLibrariesList = model.runReadAction(new MetadataModelAction<>() {
@Override
public String run(WebAppMetadata metadata) throws Exception {
//TODO can be init param specified by some annotation or the dd must be present?
WebApp ddRoot = metadata.getRoot();
if (ddRoot != null) {
InitParam[] contextParams = ddRoot.getContextParam();
for (InitParam param : contextParams) {
if (FACELETS_LIBRARIES_PROPERTY_NAME.equals(param.getParamName()) ||
FACELETS_LIBRARIES_OLD_PROPERTY_NAME.equals(param.getParamName())) {
if (FACELETS_LIBRARIES_PROPERTY_NAME.equals(param.getParamName())
|| FACELETS_LIBRARIES_OLD_PROPERTY_NAME.equals(param.getParamName())
|| FACELETS_LIBRARIES_JAKARTA_PROPERTY_NAME.equals(param.getParamName())) {
return param.getParamValue();
}
}
Expand Down
2 changes: 1 addition & 1 deletion enterprise/web.jsf/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.

javac.compilerargs=-Xlint -Xlint:-serial
javac.source=1.8
javac.release=17
spec.version.base=2.11.0

test.config.default.excludes=\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Set extendImpl(WebModule webModule, TreeMap<String, JsfComponentCustomize
jsfLibrary = panel.getLibrary();
// if the selected library is a default one, add also JSTL library
if (jsfLibrary.getName().equals(JSFUtils.DEFAULT_JSF_1_2_NAME)
|| jsfLibrary.getName().equals(JSFUtils.DEFAULT_JSF_2_0_NAME)
|| jsfLibrary.getName().equals(JSFUtils.DEFAULT_JSF_2_3_NAME)
|| jsfLibrary.getName().equals(JSFUtils.DEFAULT_JSF_1_1_NAME)) {
jstlLibrary = LibraryManager.getDefault().getLibrary(JSFUtils.DEFAULT_JSTL_1_1_NAME);
}
Expand Down
15 changes: 11 additions & 4 deletions enterprise/web.jsf/src/org/netbeans/modules/web/jsf/JSFUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class JSFUtils {
// the names of bundled jsf libraries
public static final String DEFAULT_JSF_1_1_NAME = "jsf1102"; //NOI18N
public static final String DEFAULT_JSF_1_2_NAME = "jsf12"; //NOI18N
public static final String DEFAULT_JSF_2_0_NAME = "jsf20"; //NOI18N
public static final String DEFAULT_JSF_2_3_NAME = "jsf20"; //NOI18N
public static final String DEFAULT_JSF_3_0_NAME = "jsf30"; //NOI18N
public static final String DEFAULT_JSF_4_0_NAME = "jsf40"; //NOI18N
public static final String DEFAULT_JSF_4_1_NAME = "jsf41"; //NOI18N
Expand Down Expand Up @@ -120,7 +120,7 @@ public static String isJSFLibraryResource(File resource) {
}

if (resource.isDirectory()) {
// Case of JSF version 2.1.2 and older - JSF library is created from packed directory
// Case of MyFaces and Mojarra version 2.1.2 and older - JSF library is created from packed directory
File libFolder = new File(resource, LIB_FOLDER);
if (libFolder.exists()) {
File[] files = libFolder.listFiles(new FileFilter() {
Expand All @@ -136,16 +136,23 @@ public boolean accept(File pathname) {
try {
List<File> list = Arrays.asList(files);
isJSF = ClasspathUtil.containsClass(list, FACES_EXCEPTION);
if (!isJSF) {
isJSF = ClasspathUtil.containsClass(list, JAKARTAEE_FACES_EXCEPTION);
}
} catch (IOException exception) {
Exceptions.printStackTrace(exception);
}
} else {
result = NbBundle.getMessage(JSFUtils.class, "ERROR_THERE_IS_NOT_LIB_FOLDER", resource.getPath()); //NOI18N
}
} else {
// Case of JSF version 2.1.3+ - JSF library is delivered as a single JAR file
// Case of Mojarra version 2.1.3+ - JSF library is delivered as a single JAR file
try {
isJSF = ClasspathUtil.containsClass(Collections.singletonList(resource), FACES_EXCEPTION);
List<File> list = Collections.singletonList(resource);
isJSF = ClasspathUtil.containsClass(list, FACES_EXCEPTION);
if (!isJSF) {
isJSF = ClasspathUtil.containsClass(list, JAKARTAEE_FACES_EXCEPTION);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -52,7 +53,6 @@
import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
import org.openide.util.Parameters;
import org.openide.util.RequestProcessor;
import org.openide.util.WeakListeners;

/**
Expand All @@ -61,6 +61,12 @@
*/
public final class JsfVersionUtils {

private static final Set<String> SPECIFICATION_TITLES = Set.of(
"JavaServer Faces", // 1-2
"Jakarta Server Faces", // 3
"Jakarta Faces" // 4+
);

private static final LinkedHashMap<JsfVersion, String> SPECIFIC_CLASS_NAMES = new LinkedHashMap<>();

static {
Expand Down Expand Up @@ -197,7 +203,7 @@ public static JsfVersion forClasspath(@NonNull List<URL> classpath) {
@CheckForNull
public static JsfVersion forServerLibrary(@NonNull ServerLibrary lib) {
Parameters.notNull("serverLibrary", lib); //NOI18N
if ("JavaServer Faces".equals(lib.getSpecificationTitle())) { // NOI18N
if (SPECIFICATION_TITLES.contains(lib.getSpecificationTitle())) { // NOI18N
if (Version.fromJsr277NotationWithFallback("4.1").equals(lib.getSpecificationVersion())) { //NOI18N
return JsfVersion.JSF_4_1;
} else if (Version.fromJsr277NotationWithFallback("4.0").equals(lib.getSpecificationVersion())) { //NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.prefs.Preferences;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.netbeans.api.j2ee.core.Profile;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.api.project.libraries.Library;
import org.netbeans.modules.j2ee.deployment.plugins.api.ServerLibrary;
import org.netbeans.modules.web.api.webmodule.ExtenderController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ public void run() {
} else if (getProfile() != null && getProfile().isAtLeast(Profile.JAKARTA_EE_9_WEB)) {
preferredLibrary = LibraryManager.getDefault().getLibrary(JSFUtils.DEFAULT_JSF_3_0_NAME);
} else if (getProfile() != null && getProfile().isAtLeast(Profile.JAVA_EE_5)) {
preferredLibrary = LibraryManager.getDefault().getLibrary(JSFUtils.DEFAULT_JSF_2_0_NAME);
preferredLibrary = LibraryManager.getDefault().getLibrary(JSFUtils.DEFAULT_JSF_2_3_NAME);
} else {
preferredLibrary = LibraryManager.getDefault().getLibrary(JSFUtils.DEFAULT_JSF_1_2_NAME);
}
Expand Down Expand Up @@ -1859,6 +1859,10 @@ public void run() {

private class RegisteredLibraryFinder implements Runnable {

private boolean isValidLibraryItem(LibraryItem li) {
return getProfile().isAtLeast(Profile.JAKARTA_EE_9_WEB) ^ li.getVersion().isAtMost(JsfVersion.JSF_2_3);
}

@Override
public void run() {
synchronized (JSFConfigurationPanelVisual.this) {
Expand All @@ -1867,15 +1871,11 @@ public void run() {
List<URL> content = library.getContent("classpath"); //NOI18N
JsfVersion jsfVersion = JsfVersionUtils.forClasspath(content);
LibraryItem item = jsfVersion != null ? new LibraryItem(library, jsfVersion) : new LibraryItem(library, JsfVersion.JSF_1_1);
jsfLibraries.add(item);
jsfLibraries.sort(new Comparator<LibraryItem>() {
@Override
public int compare(LibraryItem li1, LibraryItem li2) {
return li1.getLibrary().getDisplayName().compareTo(li2.getLibrary().getDisplayName());
}
});
Collections.reverse(jsfLibraries);
if (isValidLibraryItem(item)) {
jsfLibraries.add(item);
}
}
jsfLibraries.sort(Comparator.comparing(LibraryItem::getVersion).reversed());

// if maven, exclude user defined libraries
if (panel.isMaven()) {
Expand All @@ -1885,11 +1885,10 @@ public int compare(LibraryItem li1, LibraryItem li2) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
List<String> registeredItems = new ArrayList<>();
for (LibraryItem libraryItem : jsfLibraries) {
registeredItems.add(libraryItem.getLibrary().getDisplayName());
}
setRegisteredLibraryModel(registeredItems.toArray(new String[0]));
String[] registeredItems = jsfLibraries.stream()
.map(lib -> lib.getLibrary().getDisplayName())
.toArray(String[]::new);
setRegisteredLibraryModel(registeredItems);
updatePreferredLanguages();
updateJsfComponents();
}
Expand Down
3 changes: 3 additions & 0 deletions enterprise/web.jsf20/external/binaries-list
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
# under the License.

CE120B9CB924B78FD3B465E6F8A402C1E5C25B84 org.glassfish:javax.faces:2.3.9
0CBD9DF94D906A4E91608DA048E3450B6E4DF77D org.glassfish:jakarta.faces:3.0.5
FF87D2AECE8F1B251F3395FEF7B31721103D9FD8 org.glassfish:jakarta.faces:4.0.13
1EF3CA919DDC0FFD6F65E257DE1A80746425FBA5 org.glassfish:jakarta.faces:4.1.5
Loading
Loading