2424import java .util .HashSet ;
2525import java .util .List ;
2626import java .util .Set ;
27- import java .util .logging .Level ;
28- import java .util .logging .Logger ;
2927import org .apache .maven .artifact .Artifact ;
3028import org .codehaus .plexus .util .xml .Xpp3Dom ;
3129import org .netbeans .api .java .classpath .ClassPath ;
3836import org .netbeans .modules .maven .model .ModelOperation ;
3937import org .netbeans .modules .maven .model .Utilities ;
4038import org .netbeans .modules .maven .model .pom .Dependency ;
41- import org .netbeans .modules .maven .model .pom .Repository ;
4239import org .openide .filesystems .FileObject ;
4340import javax .xml .namespace .QName ;
4441import org .apache .maven .project .MavenProject ;
42+ import org .netbeans .api .j2ee .core .Profile ;
4543import org .netbeans .modules .javaee .specs .support .api .JaxWs ;
4644import org .netbeans .modules .maven .model .pom .Build ;
4745import org .netbeans .modules .maven .model .pom .Configuration ;
5149import org .netbeans .modules .maven .model .pom .Plugin ;
5250import org .netbeans .modules .maven .model .pom .PluginExecution ;
5351import org .netbeans .modules .maven .model .pom .Resource ;
52+ import org .netbeans .modules .web .api .webmodule .WebModule ;
5453import org .netbeans .modules .websvc .wsstack .api .WSStack ;
5554
5655/**
5958 */
6059public final class MavenModelUtils {
6160
61+ private static Profile profile ;
6262 private static final String WSIPMORT_GENERATE_PREFIX = "wsimport-generate-" ; //NOI18N
6363 private static final String STALE_FILE_DIRECTORY = "${project.build.directory}/jaxws/stale/" ; //NOI18N
6464 private static final String STALE_FILE_EXTENSION = ".stale" ; //NOI18N
65- public static final String JAXWS_GROUP_ID = "org.jvnet.jax-ws-commons " ; //NOI18N
65+ public static final String JAXWS_GROUP_ID = "com.sun.xml.ws " ; //NOI18N
6666 public static final String JAXWS_ARTIFACT_ID = "jaxws-maven-plugin" ; //NOI18N
6767 public static final String JAXWS_PLUGIN_KEY = JAXWS_GROUP_ID +":" +JAXWS_ARTIFACT_ID ; //NOI18N
6868 private static final String JAXWS_CATALOG = "jax-ws-catalog.xml" ; //NOI18N
69- public static final String JAX_WS_PLUGIN_VERSION = "2.3" ; //NOI18N
69+ public static final String JAXWS_JAKARTAEE_8_PLUGIN_VERSION = "2.3.7" ; //NOI18N
70+ public static final String JAXWS_JAKARTAEE_9_PLUGIN_VERSION = "3.0.2" ; //NOI18N
71+ public static final String JAXWS_JAKARTAEE_10_PLUGIN_VERSION = "4.0.3" ; //NOI18N
72+
73+ public static final String WEBSERVICES_METRO_GROUP_ID = "org.glassfish.metro" ; //NOI18N
74+ public static final String WEBSERVICES_API_ARTIFACT_ID = "webservices-api" ; //NOI18N
75+ public static final String WEBSERVICES_RT_ARTIFACT_ID = "webservices-rt" ; //NOI18N
76+ public static final String WEBSERVICES_API_JAKARTAEE_8_VERSION = "2.4.10" ; //NOI18N
77+ public static final String WEBSERVICES_API_JAKARTAEE_9_VERISON = "3.0.3" ; //NOI18N
78+ public static final String WEBSERVICES_API_JAKARTAEE_10_VERISON = "4.0.4" ; //NOI18N
79+
80+ public static final String MAVEN_PLUGINS_GROUP_ID = "org.apache.maven.plugins" ; //NOI18N
81+ public static final String WAR_PLUGIN_ARTIFACT_ID = "maven-war-plugin" ; //NOI18N
82+ public static final String WAR_PLUGIN_VERSION = "2.3.4" ; //NOI18N
7083
7184 /**
7285 * adds jaxws plugin, requires the model to have a transaction started,
@@ -100,7 +113,7 @@ public static Plugin addJaxWSPlugin(POMModel model, String jaxWsVersion) {
100113 plugin = model .getFactory ().createPlugin ();
101114 plugin .setGroupId (JAXWS_GROUP_ID );
102115 plugin .setArtifactId (JAXWS_ARTIFACT_ID );
103- plugin .setVersion (JAX_WS_PLUGIN_VERSION );
116+ plugin .setVersion (getJaxWsVersion ( profile ));
104117 bld .addPlugin (plugin );
105118
106119 // setup global configuration
@@ -118,9 +131,9 @@ public static Plugin addJaxWSPlugin(POMModel model, String jaxWsVersion) {
118131 config .setSimpleParameter ("target" , jaxWsVersion ); //NOI18N
119132 }
120133 Dependency webservicesDep = model .getFactory ().createDependency ();
121- webservicesDep .setGroupId ("javax.xml" ); //NOI18N
122- webservicesDep .setArtifactId ("webservices-api" ); //NOI18N
123- webservicesDep .setVersion ("2.0" ); //NOI18N
134+ webservicesDep .setGroupId (WEBSERVICES_METRO_GROUP_ID );
135+ webservicesDep .setArtifactId (WEBSERVICES_API_ARTIFACT_ID );
136+ webservicesDep .setVersion (getMetroVersion ( profile ));
124137 plugin .addDependency (webservicesDep );
125138 return plugin ;
126139 }
@@ -137,12 +150,12 @@ public static Plugin addWarPlugin(POMModel model, boolean client) {
137150 bld = model .getFactory ().createBuild ();
138151 model .getProject ().setBuild (bld );
139152 }
140- Plugin plugin = bld .findPluginById ("org.apache.maven.plugins" , "maven-war-plugin" ); //NOI18N
153+ Plugin plugin = bld .findPluginById (MAVEN_PLUGINS_GROUP_ID , WAR_PLUGIN_ARTIFACT_ID );
141154 if (plugin == null ) {
142155 plugin = model .getFactory ().createPlugin ();
143- plugin .setGroupId ("org.apache.maven.plugins" ); //NOI18N
144- plugin .setArtifactId ("maven-war-plugin" ); //NOI18N
145- plugin .setVersion ("2.0.2" ); //NOI18N
156+ plugin .setGroupId (MAVEN_PLUGINS_GROUP_ID );
157+ plugin .setArtifactId (WAR_PLUGIN_ARTIFACT_ID );
158+ plugin .setVersion (WAR_PLUGIN_VERSION );
146159 bld .addPlugin (plugin );
147160 }
148161
@@ -158,7 +171,7 @@ public static Plugin addWarPlugin(POMModel model, boolean client) {
158171 config .addExtensibilityElement (webResources );
159172 }
160173 //check for resource containing jax-ws-catalog.xml
161- List <String > includes = new ArrayList <String >( 2 );
174+ List <String > includes = new ArrayList <>( 4 );
162175 Collections .addAll (includes , JAXWS_CATALOG , "wsdl/**" ); // NOI18N
163176 if (!hasResource (webResources , JAXWS_CATALOG , "WEB-INF" )) { // NOI18N
164177 addResource (model , webResources , "WEB-INF" , includes ); // NOI18N
@@ -173,7 +186,6 @@ public static Plugin addWarPlugin(POMModel model, boolean client) {
173186 *
174187 * @param handle ModelHandle object
175188 */
176-
177189 public static void addWsdlResources (POMModel model ) {
178190 assert model .isIntransaction ();
179191 Build bld = model .getProject ().getBuild ();
@@ -199,7 +211,7 @@ else if ( "src/main/resources".equals(resource.getDirectory())){
199211 Resource res = model .getFactory ().createResource ();
200212 res .setTargetPath ("META-INF" ); //NOI18N
201213 res .setDirectory ("src" ); //NOI18N
202- res .addInclude ("jax-ws-catalog.xml" ); //NOI18N
214+ res .addInclude (JAXWS_CATALOG );
203215 res .addInclude ("wsdl/**" ); //NOI18N
204216 bld .addResource (res );
205217 }
@@ -211,8 +223,6 @@ else if ( "src/main/resources".equals(resource.getDirectory())){
211223
212224 }
213225
214-
215-
216226 private static POMExtensibilityElement findChild (List <POMExtensibilityElement > elems , String name ) {
217227 for (POMExtensibilityElement e : elems ) {
218228 if (name .equals (e .getQName ().getLocalPart ())) {
@@ -404,26 +414,36 @@ public static void addMetroLibrary(Project project) {
404414 scope = Artifact .SCOPE_PROVIDED ;
405415 }
406416 ModelUtils .addDependency (project .getProjectDirectory ().getFileObject ("pom.xml" ),
407- "org.glassfish.metro" ,
408- "webservices-rt" ,
409- "2.3" ,
417+ WEBSERVICES_METRO_GROUP_ID ,
418+ WEBSERVICES_RT_ARTIFACT_ID ,
419+ getMetroVersion ( profile ) ,
410420 null , scope , null , false );
411421 }
412422
413423 /** Detect JAX-WS Library in project.
414424 *
415425 * @param project Project
426+ * @param isJakartaEENameSpace Project is at least Jakarta EE 9
416427 * @return true if library was detected
417428 */
418- public static boolean hasJaxWsAPI (Project project ) {
429+ public static boolean hasJaxWsAPI (Project project , boolean isJakartaEENameSpace ) {
419430 SourceGroup [] srcGroups = ProjectUtils .getSources (project ).getSourceGroups (
420431 JavaProjectConstants .SOURCES_TYPE_JAVA );
432+
433+ final boolean isWeb = WSUtils .isWeb (project );
434+ if (isWeb ) {
435+ WebModule wm = WebModule .getWebModule (project .getProjectDirectory ());
436+ profile = wm .getJ2eeProfile ();
437+ }
438+ // TODO: Add support for EJB modules
439+
421440 if (srcGroups .length > 0 ) {
422441 ClassPath classPath = ClassPath .getClassPath (srcGroups [0 ].getRootFolder (), ClassPath .BOOT );
423- FileObject wsFeature = classPath .findResource ("javax/xml/ws/WebServiceFeature.class" ); // NOI18N
442+ final String wsfClazz = isJakartaEENameSpace ? "jakarta/xml/ws/WebServiceFeature.class" : "javax/xml/ws/WebServiceFeature.class" ; // NOI18N
443+ FileObject wsFeature = classPath .findResource (wsfClazz );
424444 if (wsFeature == null ) {
425445 classPath = ClassPath .getClassPath (srcGroups [0 ].getRootFolder (), ClassPath .COMPILE );
426- wsFeature = classPath .findResource ("javax/xml/ws/WebServiceFeature.class" ); // NOI18N
446+ wsFeature = classPath .findResource (wsfClazz );
427447 if (wsFeature == null ) {
428448 return false ;
429449 }
@@ -452,7 +472,7 @@ static List<WsimportPomInfo> getWsdlFiles(Project project) {
452472 assert mavenProject != null ;
453473 @ SuppressWarnings ("unchecked" )
454474 List <org .apache .maven .model .Plugin > plugins = mavenProject .getBuildPlugins ();
455- List <WsimportPomInfo > wsdlList = new ArrayList <WsimportPomInfo >();
475+ List <WsimportPomInfo > wsdlList = new ArrayList <>();
456476 for (org .apache .maven .model .Plugin plg : plugins ) {
457477 if (JAXWS_PLUGIN_KEY .equalsIgnoreCase (plg .getKey ())) {
458478 @ SuppressWarnings ("unchecked" )
@@ -503,7 +523,7 @@ private static String findHandler(Xpp3Dom parent) {
503523
504524 private static void updateLibraryScope (POMModel model , String groupId , String targetScope ) {
505525 assert model .isIntransaction () : "need to call model modifications under transaction." ; //NOI18N
506- Dependency wsDep = model .getProject ().findDependencyById (groupId , "webservices-rt" , null ); //NOI18N
526+ Dependency wsDep = model .getProject ().findDependencyById (groupId , WEBSERVICES_RT_ARTIFACT_ID , null );
507527 if (wsDep != null ) {
508528 wsDep .setScope (targetScope );
509529 }
@@ -521,17 +541,17 @@ static void reactOnServerChanges(final Project prj) {
521541 boolean foundMetroDep = false ;
522542 String groupId = null ;
523543 for (org .apache .maven .model .Dependency dep :deps ) {
524- if ("com.sun.xml.ws" . equals (dep .getGroupId ()) && "webservices-rt" .equals (dep .getArtifactId ())) { //NOI18N
544+ if (JAXWS_GROUP_ID . equals (dep .getGroupId ()) && WEBSERVICES_RT_ARTIFACT_ID .equals (dep .getArtifactId ())) {
525545 String scope = dep .getScope ();
526546 metroScope = scope == null ? "compile" : scope ; //NOI18N
527547 foundMetroDep = true ;
528- groupId = "com.sun.xml.ws" ;
548+ groupId = JAXWS_GROUP_ID ;
529549 break ;
530- } else if ("org.glassfish.metro" . equals (dep .getGroupId ()) && "webservices-rt" .equals (dep .getArtifactId ())) { //NOI18N
550+ } else if (WEBSERVICES_METRO_GROUP_ID . equals (dep .getGroupId ()) && WEBSERVICES_RT_ARTIFACT_ID .equals (dep .getArtifactId ())) {
531551 String scope = dep .getScope ();
532552 metroScope = scope == null ? "compile" : scope ; //NOI18N
533553 foundMetroDep = true ;
534- groupId = "org.glassfish.metro" ;
554+ groupId = WEBSERVICES_METRO_GROUP_ID ;
535555 break ;
536556 }
537557 }
@@ -622,7 +642,7 @@ public static String getUniqueId(Plugin plugin, String id) {
622642 String result = id ;
623643 List <PluginExecution > executions = plugin .getExecutions ();
624644 if (executions != null ) {
625- Set <String > execIdSet = new HashSet <String >();
645+ Set <String > execIdSet = new HashSet <>();
626646 for (PluginExecution ex : executions ) {
627647 String execId = ex .getId ();
628648 if (execId != null ) {
@@ -641,4 +661,37 @@ public static String getUniqueId(Plugin plugin, String id) {
641661 }
642662 return result ;
643663 }
664+
665+ /**
666+ * Metro webservices-api/webservices-rt version to use e.g.
667+ * {@code Profile.JAKARTA_EE_10_WEB} will return Metro version 4.0.x
668+ * @param profile Jakarta EE profile
669+ * @return Metro webservices-api/webservices-rt version
670+ */
671+ private static String getMetroVersion (Profile profile ) {
672+ if (profile .isAtLeast (Profile .JAKARTA_EE_10_WEB )) {
673+ return WEBSERVICES_API_JAKARTAEE_10_VERISON ;
674+ } else if (profile .isAtLeast (Profile .JAKARTA_EE_9_WEB )) {
675+ return WEBSERVICES_API_JAKARTAEE_9_VERISON ;
676+ } else {
677+ return WEBSERVICES_API_JAKARTAEE_8_VERSION ;
678+ }
679+ }
680+
681+ /**
682+ * JAX-WS Plugin to use e.g. {@code Profile.JAKARTA_EE_10_WEB}
683+ * will return plugin version 4.0.X
684+ * @param profile Jakarta EE profile
685+ * @return JAX-WS Plugin version
686+ */
687+ private static String getJaxWsVersion (Profile profile ) {
688+ if (profile .isAtLeast (Profile .JAKARTA_EE_10_WEB )) {
689+ return JAXWS_JAKARTAEE_10_PLUGIN_VERSION ;
690+ } else if (profile .isAtLeast (Profile .JAKARTA_EE_9_WEB )) {
691+ return JAXWS_JAKARTAEE_9_PLUGIN_VERSION ;
692+ } else {
693+ return JAXWS_JAKARTAEE_8_PLUGIN_VERSION ;
694+ }
695+ }
696+
644697}
0 commit comments