Skip to content

Commit

Permalink
Feature: Added support for JSF 4.0 namespaces
Browse files Browse the repository at this point in the history
Previously NetBeans bundles the JSF reference implementation Mojarra in order to provide several functionality
(like namespaces) based on the parsed taglib xml files from that jar. This is somehow problematic as:
1) The dependency needs to be updated on every new JSF release
2) NetBeans needs to fulfil the expectations of Mojarra

This leads to the problem that we currently cannot update and bundle the latest Mojarra version as
Java 11 is required.

This change wants to get less dependant on that bundled JSF implementation by resolving the reference implementation
using maven. Instead of reading the taglib xml files from that bundled jar NetBeans now gets in from the local maven
repository or downloads it from maven central. If this is not possible we fallback to the bundled version.

This change also improves the situation when autosuggestion is invoked in the namespace part of JSF xhtml documents
by ordering the suggested namespace with the one on top which is most likely to be used.

This should fix apache#6069 apache#5470 apache#5470 apache#4338
  • Loading branch information
asbachb committed Jul 13, 2023
1 parent faf308b commit 67cc090
Show file tree
Hide file tree
Showing 93 changed files with 2,414 additions and 1,530 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,9 @@ jobs:
- name: enterprise/j2ee.core
run: ant $OPTS -f enterprise/j2ee.core test

- name: enterprise/maven.j2ee
run: ant $OPTS -f enterprise/maven.j2ee test

- name: enterprise/micronaut
run: .github/retry.sh ant $OPTS -f enterprise/micronaut test

Expand All @@ -1994,6 +1997,12 @@ jobs:
- name: tomcat5
run: ant $OPTS -f enterprise/tomcat5 test

- name: enterprise/web.jsf
run: .github/retry.sh ant $OPTS -f enterprise/web.jsf test

- name: enterprise/web.jsfapi
run: ant $OPTS -f enterprise/web.jsfapi test

- name: websvc.editor.hints
run: ant $OPTS -f enterprise/websvc.editor.hints test

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ derby.log
##################################
/extide/gradle/netbeans-gradle-tooling/.gradle/
/extide/gradle/netbeans-gradle-tooling/gradle/wrapper/gradle-wrapper.jar
/extide/gradle/netbeans-gradle-tooling/bin/
/extide/gradle/release/modules/gradle/daemon-loader/.gradle/
/nbbuild/misc/prepare-bundles/target/

Expand Down
4 changes: 2 additions & 2 deletions enterprise/maven.j2ee/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>0-1</release-version>
<specification-version>1.13</specification-version>
<release-version>2</release-version>
<specification-version>2.0</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.maven.j2ee;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import java.util.Optional;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import static org.apache.maven.repository.RepositorySystem.DEFAULT_REMOTE_REPO_ID;
import static org.apache.maven.repository.RepositorySystem.DEFAULT_REMOTE_REPO_URL;
import org.netbeans.modules.maven.embedder.EmbedderFactory;
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;

/**
*
* @author Benjamin Asbach
*/
@ServiceProvider(service = JsfReferenceImplementationProvider.class)
public class MavenJsfReferenceImplementationProvider implements JsfReferenceImplementationProvider {

static final Map<JsfVersion, String> JSF_VERSION_MAVEN_COORDINATES_MAPPING;
static {
EnumMap<JsfVersion, String> map = new EnumMap<>(JsfVersion.class);
map.put(JsfVersion.JSF_1_0, "javax.faces:jsf-impl:1.1_02"); //seems to be not available in maven central
map.put(JsfVersion.JSF_1_1, "javax.faces:jsf-impl:1.1_02");
map.put(JsfVersion.JSF_1_2, "javax.faces:jsf-impl:1.2");
map.put(JsfVersion.JSF_2_0, "com.sun.faces:jsf-impl:2.0.11");
map.put(JsfVersion.JSF_2_1, "com.sun.faces:jsf-impl:2.1.29");
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.19");
map.put(JsfVersion.JSF_3_0, "org.glassfish:jakarta.faces:3.0.4");
map.put(JsfVersion.JSF_4_0, "org.glassfish:jakarta.faces:4.0.2");
JSF_VERSION_MAVEN_COORDINATES_MAPPING = Collections.unmodifiableMap(map);
}

@Override
public Path artifactPathFor(JsfVersion jsfVersion) {
String[] mavenCoordinates = JSF_VERSION_MAVEN_COORDINATES_MAPPING.get(jsfVersion).split(":");
if (mavenCoordinates.length != 3) {
return null;
}
String groupId = mavenCoordinates[0];
String artifactId = mavenCoordinates[1];
String version = mavenCoordinates[2];

MavenEmbedder mavenEmbedder = EmbedderFactory.getOnlineEmbedder();

ArtifactRepository localRepository = mavenEmbedder.getLocalRepository();
ArtifactRepository remoteRepository = mavenEmbedder.createRemoteRepository(DEFAULT_REMOTE_REPO_URL, DEFAULT_REMOTE_REPO_ID);
Artifact jsfRIArtifact = mavenEmbedder.createArtifact(groupId, artifactId, version, "jar");

try {
mavenEmbedder.resolve(jsfRIArtifact, Collections.singletonList(remoteRepository), localRepository);
} catch (ArtifactResolutionException | ArtifactNotFoundException ex) {
Exceptions.printStackTrace(ex);

return null;
}

return Optional.ofNullable(jsfRIArtifact)
.map(Artifact::getFile)
.map(File::toPath)
.filter(Files::exists)
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.netbeans.api.j2ee.core.Profile;
Expand Down Expand Up @@ -221,7 +223,7 @@ private Profile getProfileFromDescriptor() {
* </ul>
* </p>
*/
private static Map<Profile, List<DependencyDesc>> javaEEMap = new HashMap<>();
private static Map<Profile, List<DependencyDesc>> javaEEMap = new LinkedHashMap<>();
static {
List<DependencyDesc> javaEE5 = new ArrayList<>();
List<DependencyDesc> javaEE6Web = new ArrayList<>();
Expand Down Expand Up @@ -262,6 +264,8 @@ private Profile getProfileFromDescriptor() {
javaEE5.add(new DependencyDesc("org.glassfish.main.extras", "glassfish-embedded-web", "2"));
javaEE6Full.add(new DependencyDesc("org.glassfish.main.extras", "glassfish-embedded-all", "3"));
javaEE6Web.add(new DependencyDesc("org.glassfish.main.extras", "glassfish-embedded-web", "3"));
javaEE7Full.add(new DependencyDesc("org.glassfish.main.extras", "glassfish-embedded-all", "4.0"));
javaEE7Web.add(new DependencyDesc("org.glassfish.main.extras", "glassfish-embedded-web", "4.0.1"));
javaEE7Full.add(new DependencyDesc("org.glassfish.main.extras", "glassfish-embedded-all", "4.1.2"));
javaEE7Web.add(new DependencyDesc("org.glassfish.main.extras", "glassfish-embedded-web", "4.1.2"));
javaEE8Full.add(new DependencyDesc("org.glassfish.main.extras", "glassfish-embedded-all", "5.1.0"));
Expand Down Expand Up @@ -296,21 +300,21 @@ private Profile getProfileFromDescriptor() {
jakartaEE8Full.add(new DependencyDesc("org.jboss.spec", "jboss-jakartaee-all-8.0", null));
jakartaEE8Web.add(new DependencyDesc("org.jboss.spec", "jboss-jakartaee-web-8.0", null));

javaEEMap.put(Profile.JAVA_EE_5, javaEE5);
javaEEMap.put(Profile.JAVA_EE_6_WEB, javaEE6Web);
javaEEMap.put(Profile.JAVA_EE_6_FULL, javaEE6Full);
javaEEMap.put(Profile.JAVA_EE_7_WEB, javaEE7Web);
javaEEMap.put(Profile.JAVA_EE_7_FULL, javaEE7Full);
javaEEMap.put(Profile.JAVA_EE_8_WEB, javaEE8Web);
javaEEMap.put(Profile.JAVA_EE_8_FULL, javaEE8Full);
javaEEMap.put(Profile.JAKARTA_EE_8_WEB, jakartaEE8Web);
javaEEMap.put(Profile.JAKARTA_EE_8_FULL, jakartaEE8Full);
javaEEMap.put(Profile.JAKARTA_EE_9_WEB, jakartaEE9Web);
javaEEMap.put(Profile.JAKARTA_EE_9_FULL, jakartaEE9Full);
javaEEMap.put(Profile.JAKARTA_EE_9_1_WEB, jakartaEE91Web);
javaEEMap.put(Profile.JAKARTA_EE_9_1_FULL, jakartaEE91Full);
javaEEMap.put(Profile.JAKARTA_EE_10_WEB, jakartaEE10Web);
javaEEMap.put(Profile.JAKARTA_EE_10_FULL, jakartaEE10Full);
javaEEMap.put(Profile.JAKARTA_EE_10_WEB, jakartaEE10Web);
javaEEMap.put(Profile.JAKARTA_EE_9_1_FULL, jakartaEE91Full);
javaEEMap.put(Profile.JAKARTA_EE_9_1_WEB, jakartaEE91Web);
javaEEMap.put(Profile.JAKARTA_EE_9_FULL, jakartaEE9Full);
javaEEMap.put(Profile.JAKARTA_EE_9_WEB, jakartaEE9Web);
javaEEMap.put(Profile.JAKARTA_EE_8_FULL, jakartaEE8Full);
javaEEMap.put(Profile.JAKARTA_EE_8_WEB, jakartaEE8Web);
javaEEMap.put(Profile.JAVA_EE_8_FULL, javaEE8Full);
javaEEMap.put(Profile.JAVA_EE_8_WEB, javaEE8Web);
javaEEMap.put(Profile.JAVA_EE_7_FULL, javaEE7Full);
javaEEMap.put(Profile.JAVA_EE_7_WEB, javaEE7Web);
javaEEMap.put(Profile.JAVA_EE_6_FULL, javaEE6Full);
javaEEMap.put(Profile.JAVA_EE_6_WEB, javaEE6Web);
javaEEMap.put(Profile.JAVA_EE_5, javaEE5);
}

private static class DependencyDesc {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.maven.j2ee;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import org.junit.Test;
import org.netbeans.modules.web.jsfapi.api.JsfVersion;

/**
*
* @author Benjamin Asbach
*/
public class MavenJsfReferenceImplementationProviderTest {

@Test
public void testAllJsfVersionsAreMapped() {
for (JsfVersion jsfVersion : JsfVersion.values()) {
assertTrue(MavenJsfReferenceImplementationProvider.JSF_VERSION_MAVEN_COORDINATES_MAPPING.containsKey(jsfVersion));
}
}

@Test
public void testAllMavenCoordinatesAreWellFormatted() {
for (String mavenCoordinates : MavenJsfReferenceImplementationProvider.JSF_VERSION_MAVEN_COORDINATES_MAPPING.values()) {
assertEquals(3, mavenCoordinates.split(":").length);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

import java.io.IOException;
import org.netbeans.api.j2ee.core.Profile;
import org.netbeans.modules.javaee.project.api.JavaEEProjectSettings;
import org.netbeans.modules.maven.j2ee.JavaEEMavenTestBase;
import org.netbeans.modules.maven.j2ee.PomBuilder;
import org.netbeans.modules.maven.j2ee.PomBuilder.PomPlugin;
import org.netbeans.modules.maven.j2ee.utils.MavenProjectSupport;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;

Expand Down
4 changes: 2 additions & 2 deletions enterprise/web.bootsfaces/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.14</specification-version>
<release-version>2</release-version>
<specification-version>2.0</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ private static boolean isJSF30(WebModule wm) {
return classpath != null && classpath.findResource("jakarta/faces/flow/Flow.class") != null; //NOI18N
}

private static boolean isJSF40(WebModule wm) {
ClassPath classpath = ClassPath.getClassPath(wm.getDocumentBase(), ClassPath.COMPILE);
return classpath != null && classpath.findResource("jakarta/faces/lifecycle/ClientWindowScoped.class") != null; //NOI18N
}

public Set<DataObject> instantiate(TemplateWizard wiz) throws IOException {
// Here is the default plain behavior. Simply takes the selected
// template (you need to have included the standard second panel
Expand Down Expand Up @@ -231,7 +236,9 @@ public Set<DataObject> instantiate(TemplateWizard wiz) throws IOException {
template = templateParent.getFileObject("JSP", "xhtml"); //NOI18N
WebModule wm = WebModule.getWebModule(df.getPrimaryFile());
if (wm != null) {
if (isJSF30(wm)) {
if (isJSF40(wm)) {
wizardProps.put("isJSF40", Boolean.TRUE);
} else if (isJSF30(wm)) {
wizardProps.put("isJSF30", Boolean.TRUE);
} else if (isJSF22(wm)) {
wizardProps.put("isJSF22", Boolean.TRUE);
Expand Down
4 changes: 2 additions & 2 deletions enterprise/web.freeform/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>0-1</release-version>
<specification-version>1.0</specification-version>
<release-version>2</release-version>
<specification-version>2.0</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion enterprise/web.jsf.editor/manifest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.modules.web.jsf.editor
OpenIDE-Module-Layer: org/netbeans/modules/web/jsf/editor/resources/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/web/jsf/editor/resources/Bundle.properties
OpenIDE-Module-Specification-Version: 1.72
OpenIDE-Module-Specification-Version: 2.0
AutoUpdate-Show-In-Client: false
8 changes: 4 additions & 4 deletions enterprise/web.jsf.editor/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.51</specification-version>
<release-version>2</release-version>
<specification-version>2.0</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand All @@ -404,8 +404,8 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.34</specification-version>
<release-version>2</release-version>
<specification-version>2.0</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.netbeans.modules.parsing.spi.ParseException;
import org.netbeans.modules.web.api.webmodule.WebModule;
import org.netbeans.modules.web.common.api.WebUtils;
import org.netbeans.modules.web.jsfapi.api.JsfVersion;
import org.netbeans.modules.web.jsfapi.api.Library;
import org.netbeans.modules.web.jsfapi.spi.LibraryUtils;
import org.netbeans.spi.editor.codegen.CodeGenerator;
Expand Down Expand Up @@ -208,14 +209,14 @@ public void run() {
//but since the library has just been created by adding an xhtml file
//to the resources/xxx/ folder we need to wait until the files
//get indexed and the library is created
final String compositeLibURL = LibraryUtils.getCompositeLibraryURL(compFolder, jsfs.isJsf22Plus());
final String compositeLibURL = LibraryUtils.getCompositeLibraryURL(compFolder, jsfs.getJsfVersion());
Source documentSource = Source.create(document);
ParserManager.parseWhenScanFinished(Collections.singletonList(documentSource), new UserTask() { //NOI18N
@Override
public void run(ResultIterator resultIterator) throws Exception {
Library lib = jsfs.getLibrary(compositeLibURL);
if (lib != null) {
if (!LibraryUtils.importLibrary(document, lib, prefix, jsfs.isJsf22Plus())) { //XXX: fix the damned static prefix !!!
if (!LibraryUtils.importLibrary(document, lib, prefix)) { //XXX: fix the damned static prefix !!!
logger.log(Level.WARNING, "Cannot import composite components library {0}", compositeLibURL); //NOI18N
}
} else {
Expand Down Expand Up @@ -248,7 +249,7 @@ public void run() {
((BaseDocument) templateInstanceDoc).runAtomic(new Runnable() {
@Override
public void run() {
LibraryUtils.importLibrary(templateInstanceDoc, importsMap, jsfs.isJsf22Plus());
LibraryUtils.importLibrary(templateInstanceDoc, importsMap);
}
});
try {
Expand Down
Loading

0 comments on commit 67cc090

Please sign in to comment.