forked from apache/netbeans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added support for JSF 4.0 namespaces
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
Showing
93 changed files
with
2,279 additions
and
1,530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...ven.j2ee/src/org/netbeans/modules/maven/j2ee/MavenJsfReferenceImplementationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import java.util.EnumMap; | ||
import java.util.Map; | ||
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 Paths.get(jsfRIArtifact.getFile().toURI()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...unit/src/org/netbeans/modules/maven/j2ee/MavenJsfReferenceImplementationProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.