1818import java .io .StringReader ;
1919import java .net .HttpURLConnection ;
2020import java .net .URL ;
21- import java .net .UnknownHostException ;
2221import java .util .ArrayList ;
2322import java .util .Collection ;
2423import java .util .HashMap ;
6564
6665import javax .xml .parsers .DocumentBuilder ;
6766import javax .xml .parsers .DocumentBuilderFactory ;
67+ import javax .xml .XMLConstants ;
6868
6969public class MicroProjectWizard extends Wizard implements INewWizard {
7070
@@ -92,10 +92,13 @@ public MicroProjectWizard() {
9292 public static final String ARCHETYPE_VERSION_5X = "1.5.0" ; //$NON-NLS-1$
9393 public static final String STARTER_ARCHETYPE_GROUP_ID = "fish.payara.starter" ;
9494 public static final String STARTER_ARCHETYPE_ARTIFACT_ID = "payara-starter-archetype" ;
95- public static final String ARCHETYPE_VERSION_6X = "1.0-beta9 " ; //$NON-NLS-1$
95+ public static final String STARTER_ARCHETYPE_VERSION = "2.2.1 " ; //$NON-NLS-1$
9696 private static final String ARCHETYPE_JDK_VERSION = "jdkVersion" ; //$NON-NLS-1$
9797 private static final String ARCHETYPE_JDK_VERSION_DEFAULT_VALUE = "1.8" ; //$NON-NLS-1$
98+ public static final String ARCHETYPE_JAVA_VERSION = "javaVersion" ; //$NON-NLS-1$
99+ private static final String ARCHETYPE_JAVA_VERSION_DEFAULT_VALUE = "17" ; //$NON-NLS-1$
98100 public static final String ARCHETYPE_MICRO_VERSION = "payaraMicroVersion" ; //$NON-NLS-1$
101+ public static final String ARCHETYPE_PAYARA_VERSION = "payaraVersion" ; //$NON-NLS-1$
99102 public static final String ARCHETYPE_AUTOBIND_HTTP = "autoBindHttp" ; //$NON-NLS-1$
100103 private static final String ARCHETYPE_CONCURRENT_API = "addConcurrentApi" ; //$NON-NLS-1$
101104 private static final String ARCHETYPE_RESOURCE_API = "addResourceApi" ; //$NON-NLS-1$
@@ -106,57 +109,80 @@ public MicroProjectWizard() {
106109 public static final String ARCHETYPE_CONTEXT_ROOT = "contextRoot" ; //$NON-NLS-1$
107110 private static final String ARCHETYPE_CONTEXT_ROOT_DEFAULT_VALUE = "/" ; //$NON-NLS-1$
108111 private static final String ARCHETYPE_DEPLOY_WAR = "deployWar" ; //$NON-NLS-1$
112+ public static final String ARCHETYPE_PLATFORM = "platform" ; //$NON-NLS-1$
113+ public static final String PLATFORM_SERVER = "server" ; //$NON-NLS-1$
114+ public static final String PLATFORM_MICRO = "micro" ; //$NON-NLS-1$
109115 private static final String EMPTY = "" ; //$NON-NLS-1$
110116
111117
112118 public static final String DEFAULT_REPOSITORY_URL = "https://repo1.maven.org/maven2/" ; // NOI18N
113119
114- private static final String METADATA_URL = "fish/payara/extras/payara-micro/maven-metadata.xml" ; // NOI18N
120+ private static final String PAYARA_BOM_METADATA_URL = "fish/payara/api/payara-bom/maven-metadata.xml" ; // NOI18N
121+ private static final String PAYARA_MICRO_METADATA_URL = "fish/payara/extras/payara-micro/maven-metadata.xml" ; // NOI18N
115122
116- private static final List <String > versions = new ArrayList <>();
123+ private static final Map < String , List <String >> versions = new HashMap <>();
117124 public static List <String > getVersions () {
118- if (versions .isEmpty ()) {
119- try {
120- // Construct the full URL
121- String urlString = DEFAULT_REPOSITORY_URL + METADATA_URL ;
122- URL url = new URL (urlString );
123-
124- // Open connection
125- HttpURLConnection connection = (HttpURLConnection ) url .openConnection ();
126- connection .setRequestMethod ("GET" );
127-
128- // Read the response
129- BufferedReader in = new BufferedReader (new InputStreamReader (connection .getInputStream ()));
130- StringBuilder xmlResponse = new StringBuilder ();
131- String line ;
132- while ((line = in .readLine ()) != null ) {
133- xmlResponse .append (line );
134- }
135- in .close ();
136-
137- // Parse the XML response
138- DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
139- DocumentBuilder builder = factory .newDocumentBuilder ();
140- Document doc = builder .parse (new InputSource (new StringReader (xmlResponse .toString ())));
141-
142- String latest = doc .getElementsByTagName ("latest" ).item (0 ).getTextContent ();
143- // Extract versions
144- NodeList versionNodes = doc .getElementsByTagName ("version" );
145- for (int i = versionNodes .getLength () - 1 ; i >= 0 ; i --) {
146- String version = versionNodes .item (i ).getTextContent ();
147- if ((version .contains ("Alpha" ) || version .contains ("Beta" ) || version .contains ("SNAPSHOT" )) // NOI18N
148- && !version .equals (latest )) {
149- continue ;
150- };
151- versions .add (version );
152- }
125+ return getVersions (PLATFORM_MICRO );
126+ }
153127
154- } catch ( Exception e ) {
155- e . printStackTrace ( );
156- }
128+ public static List < String > getVersions ( String platform ) {
129+ return versions . computeIfAbsent ( platform , MicroProjectWizard :: loadVersions );
130+ }
157131
132+ public static String getDefaultVersion (String platform ) {
133+ List <String > resolvedVersions = getVersions (platform );
134+ return resolvedVersions .isEmpty () ? EMPTY : resolvedVersions .get (0 );
135+ }
136+
137+ private static List <String > loadVersions (String platform ) {
138+ List <String > resolvedVersions = new ArrayList <>();
139+ try {
140+ // Construct the full URL
141+ String metadataUrl = PLATFORM_SERVER .equals (platform ) ? PAYARA_BOM_METADATA_URL : PAYARA_MICRO_METADATA_URL ;
142+ String urlString = DEFAULT_REPOSITORY_URL + metadataUrl ;
143+ URL url = new URL (urlString );
144+
145+ // Open connection
146+ HttpURLConnection connection = (HttpURLConnection ) url .openConnection ();
147+ connection .setRequestMethod ("GET" );
148+
149+ // Read the response
150+ BufferedReader in = new BufferedReader (new InputStreamReader (connection .getInputStream ()));
151+ StringBuilder xmlResponse = new StringBuilder ();
152+ String line ;
153+ while ((line = in .readLine ()) != null ) {
154+ xmlResponse .append (line );
155+ }
156+ in .close ();
157+
158+ // Parse the XML response
159+ DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
160+ factory .setFeature (XMLConstants .FEATURE_SECURE_PROCESSING , true );
161+ factory .setFeature ("http://apache.org/xml/features/disallow-doctype-decl" , true ); //$NON-NLS-1$
162+ factory .setFeature ("http://xml.org/sax/features/external-general-entities" , false ); //$NON-NLS-1$
163+ factory .setFeature ("http://xml.org/sax/features/external-parameter-entities" , false ); //$NON-NLS-1$
164+ factory .setAttribute (XMLConstants .ACCESS_EXTERNAL_DTD , EMPTY );
165+ factory .setAttribute (XMLConstants .ACCESS_EXTERNAL_SCHEMA , EMPTY );
166+ factory .setXIncludeAware (false );
167+ factory .setExpandEntityReferences (false );
168+ DocumentBuilder builder = factory .newDocumentBuilder ();
169+ Document doc = builder .parse (new InputSource (new StringReader (xmlResponse .toString ())));
170+
171+ String latest = doc .getElementsByTagName ("latest" ).item (0 ).getTextContent ();
172+ // Extract versions
173+ NodeList versionNodes = doc .getElementsByTagName ("version" );
174+ for (int i = versionNodes .getLength () - 1 ; i >= 0 ; i --) {
175+ String version = versionNodes .item (i ).getTextContent ();
176+ if ((version .contains ("Alpha" ) || version .contains ("Beta" ) || version .contains ("SNAPSHOT" )) // NOI18N
177+ && !version .equals (latest )) {
178+ continue ;
179+ };
180+ resolvedVersions .add (version );
181+ }
182+ } catch (Exception e ) {
183+ e .printStackTrace ();
158184 }
159- return versions ;
185+ return resolvedVersions ;
160186 }
161187
162188 @ Override
@@ -190,10 +216,13 @@ private Archetype getArchetype() {
190216 Archetype archetype = new Archetype ();
191217 archetype .setGroupId (STARTER_ARCHETYPE_GROUP_ID );
192218 archetype .setArtifactId (STARTER_ARCHETYPE_ARTIFACT_ID );
193- archetype .setVersion (ARCHETYPE_VERSION_6X );
219+ archetype .setVersion (STARTER_ARCHETYPE_VERSION );
194220 Properties properties = new Properties ();
195221 properties .put (ARCHETYPE_JDK_VERSION , ARCHETYPE_JDK_VERSION_DEFAULT_VALUE );
196- properties .put (ARCHETYPE_MICRO_VERSION , getVersions ().get (0 ));
222+ properties .put (ARCHETYPE_JAVA_VERSION , ARCHETYPE_JAVA_VERSION_DEFAULT_VALUE );
223+ properties .put (ARCHETYPE_PLATFORM , PLATFORM_MICRO );
224+ properties .put (ARCHETYPE_MICRO_VERSION , getDefaultVersion (PLATFORM_MICRO ));
225+ properties .put (ARCHETYPE_PAYARA_VERSION , getDefaultVersion (PLATFORM_MICRO ));
197226 properties .put (ARCHETYPE_AUTOBIND_HTTP , TRUE .toString ());
198227 properties .put (ARCHETYPE_CONCURRENT_API , FALSE .toString ());
199228 properties .put (ARCHETYPE_RESOURCE_API , FALSE .toString ());
@@ -210,6 +239,7 @@ private Archetype getArchetype() {
210239 @ Override
211240 public boolean performFinish () {
212241 Archetype archetype = microSettingsPage .getArchetype ();
242+ microSettingsPage .configureBuildTool ();
213243 final String groupId = projectSettingsPage .getGroupId ();
214244 final String artifactId = projectSettingsPage .getArtifactId ();
215245 final String version = projectSettingsPage .getVersion ();
0 commit comments