This is an automated email from the ASF dual-hosted git repository. jgauravgupta pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 13d5f70 Fixes fetching the Payara Server list in private network (#3018) 13d5f70 is described below commit 13d5f709df527af9d05a496be9ceccdb5469ddb3 Author: Gaurav Gupta <gaurav.gu...@payara.fish> AuthorDate: Fri Jul 23 00:24:09 2021 +0530 Fixes fetching the Payara Server list in private network (#3018) * Fixes fetching the Payara Server list in private network * Retrying fetching the Payara Server version from listed repositories * Skip empty archetypeVersion property to run the latest archetype * Fixes typo * Log UnknownHost Exception * Payara Server registration panel UI improvement * Validate local metadata root location --- .../common/wizards/AddServerLocationPanel.java | 11 +- .../wizards/AddServerLocationVisualPanel.form | 2 + .../wizards/AddServerLocationVisualPanel.java | 20 +++- .../payara/common/wizards/Bundle.properties | 3 +- .../modules/payara/common/wizards/Retriever.java | 2 +- .../fish/payara/micro/project/ui/Bundle.properties | 1 + .../project/ui/MicroProjectWizardIterator.java | 4 +- .../payara/micro/project/ui/PayaraMicroPanel.form | 39 ++++--- .../payara/micro/project/ui/PayaraMicroPanel.java | 39 +++++-- enterprise/payara.tooling/nbproject/project.xml | 25 +++-- .../payara/tooling/data/PayaraPlatformVersion.java | 119 ++++++++++++++++----- java/maven.indexer/nbproject/project.xml | 1 + .../maven/newproject/ArchetypeWizardUtils.java | 5 +- 13 files changed, 202 insertions(+), 69 deletions(-) diff --git a/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationPanel.java b/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationPanel.java index 00b3bd0..851876d 100644 --- a/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationPanel.java +++ b/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationPanel.java @@ -138,6 +138,14 @@ public class AddServerLocationPanel implements WizardDescriptor.FinishablePanel, File installDir = new File(locationStr).getAbsoluteFile(); File payaraDir = getPayaraRoot(installDir); File domainDir = getDefaultDomain(payaraDir); + StringBuilder message = new StringBuilder(); + if (wizardIterator.downloadableValues.isEmpty()) { + message.append(NbBundle.getMessage( + AddServerLocationPanel.class, + "LBL_UnableToConnectPayaraMavenRepo")) + .append(" "); // NOI18N + panel.updateMessageText(message.toString()); + } if (!installDir.exists()) { if (!isLegalFolder(installDir)) { wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage( @@ -145,8 +153,9 @@ public class AddServerLocationPanel implements WizardDescriptor.FinishablePanel, return false; } else if (canCreate(installDir)) { if (downloadState == AddServerLocationVisualPanel.DownloadState.AVAILABLE) { - panel.updateMessageText(NbBundle.getMessage(AddServerLocationPanel.class, + message.append(NbBundle.getMessage(AddServerLocationPanel.class, "LBL_NewInstallDirCanBeUsed", getSanitizedPath(installDir))); // NOI18N + panel.updateMessageText(message.toString()); wizard.putProperty(PROP_ERROR_MESSAGE, panel.getStatusText()); return false; } else { diff --git a/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationVisualPanel.form b/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationVisualPanel.form index 9248c69..e814bef 100644 --- a/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationVisualPanel.form +++ b/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationVisualPanel.form @@ -256,6 +256,8 @@ </Properties> <AuxValues> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JComboBox<PayaraVersion>(wizardIterator.downloadableValues.toArray(new PayaraVersion[0]))"/> + <AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="} else {
 updateMessageText(NbBundle.getMessage(AddServerLocationPanel.class, "LBL_UnaleToConnectPayaraMavenRepo"));
}"/> + <AuxValue name="JavaCodeGenerator_InitCodePre" type="java.lang.String" value="if (!wizardIterator.downloadableValues.isEmpty()) {"/> <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<PayaraVersion>"/> </AuxValues> </Component> diff --git a/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationVisualPanel.java b/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationVisualPanel.java index 7ee0bf4..e6dd15c 100644 --- a/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationVisualPanel.java +++ b/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/AddServerLocationVisualPanel.java @@ -51,11 +51,11 @@ public class AddServerLocationVisualPanel extends javax.swing.JPanel implements public static final String DOWNLOAD_PREFIX = "https://www.payara.fish/"; // NOI18N - private final List<ChangeListener> listeners = new CopyOnWriteArrayList<ChangeListener>(); + private final List<ChangeListener> listeners = new CopyOnWriteArrayList<>(); private Retriever retriever; private volatile DownloadState downloadState; private volatile String statusText; - private ServerWizardIterator wizardIterator; + private final ServerWizardIterator wizardIterator; public AddServerLocationVisualPanel(ServerWizardIterator swi) { this.wizardIterator = swi; @@ -65,6 +65,11 @@ public class AddServerLocationVisualPanel extends javax.swing.JPanel implements private void initUserComponents() { downloadButton.setEnabled(false); + if (wizardIterator.downloadableValues.isEmpty()) { + agreeCheckBox.setEnabled(false); + } else { + agreeCheckBox.setEnabled(true); + } setName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "TITLE_ServerLocation")); @@ -387,7 +392,11 @@ public class AddServerLocationVisualPanel extends javax.swing.JPanel implements chooseServerLabel.setLabelFor(hk2HomeTextField); org.openide.awt.Mnemonics.setLocalizedText(chooseServerLabel, org.openide.util.NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooseOne")); // NOI18N - chooseServerComboBox.setSelectedItem(wizardIterator.downloadableValues.get(0)); + if (!wizardIterator.downloadableValues.isEmpty()) { + chooseServerComboBox.setSelectedItem(wizardIterator.downloadableValues.get(0)); + } else { + updateMessageText(NbBundle.getMessage(AddServerLocationPanel.class, "LBL_UnableToConnectPayaraMavenRepo")); + } javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); @@ -467,7 +476,10 @@ private void readlicenseButtonActionPerformed(java.awt.event.ActionEvent evt) {/ private void downloadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadButtonActionPerformed if(retriever == null) { - PayaraPlatformVersionAPI selectedValue = wizardIterator.downloadableValues.get(0); + PayaraPlatformVersionAPI selectedValue = null; + if (!wizardIterator.downloadableValues.isEmpty()) { + selectedValue = wizardIterator.downloadableValues.get(0); + } if (wizardIterator.downloadableValues.size() > 1) { selectedValue = (PayaraPlatformVersionAPI) chooseServerComboBox.getSelectedItem(); } diff --git a/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/Bundle.properties b/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/Bundle.properties index 09e8d1e..bfa6626 100644 --- a/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/Bundle.properties +++ b/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/Bundle.properties @@ -55,7 +55,8 @@ A11Y_HTTP_PORT_TXT=HTTP port LBL_InitializationTitle=Initialize LBL_ReadLicenseText=<html><body><span style="text-decoration: underline;">I have read and accept the license agreement... (click)</span></body></html> -LBL_NewInstallDirCanBeUsed=<html><body>{0} does not exist but server can be downloaded and installed there.</body></html> +LBL_NewInstallDirCanBeUsed={0} does not exist but server can be downloaded and installed there. +LBL_UnableToConnectPayaraMavenRepo=Cannot establish a connection with the Payara maven repository. ERR_BlankInstallDir=Install location cannot be empty. ERR_CannotCreate=Cannot be created. diff --git a/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/Retriever.java b/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/Retriever.java index 6185a2d..8d7c8ea 100644 --- a/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/Retriever.java +++ b/enterprise/payara.common/src/org/netbeans/modules/payara/common/wizards/Retriever.java @@ -252,10 +252,10 @@ public class Retriever implements Runnable { String message = null; try { + targetUrl = new URL(getDownloadLocation()); backupDir = backupInstallDir(targetInstallDir); setDownloadState(STATUS_CONNECTING); - targetUrl = new URL(getDownloadLocation()); Logger.getLogger("payara").log(Level.FINE, "Downloading from {0}", targetUrl); // NOI18N connection = targetUrl.openConnection(); diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/Bundle.properties b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/Bundle.properties index ef89cce..76a3c66 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/Bundle.properties +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/Bundle.properties @@ -27,3 +27,4 @@ LBL_NameFormat={0} of {1} PayaraMicroPanel.contextRootLabel.toolTipText=Enables auto-bind functionality for the HTTP port PayaraMicroPanel.contextRootLabel.text=Context Root: PayaraMicroPanel.contextRootTextField.text=/ +LBL_UnableToConnectPayaraMavenRepo=<html><body>Cannot establish a connection with the Payara maven repository.</body></html> \ No newline at end of file diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/MicroProjectWizardIterator.java b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/MicroProjectWizardIterator.java index cf224d5..ed97c26 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/MicroProjectWizardIterator.java +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/MicroProjectWizardIterator.java @@ -82,7 +82,9 @@ public final class MicroProjectWizardIterator extends BaseWizardIterator { Archetype archetype = createMojoArchetype(); Map<String, String> properties = new HashMap<>(); - properties.put(PROP_PAYARA_MICRO_VERSION, payaraMicroVersion); + if (payaraMicroVersion != null) { + properties.put(PROP_PAYARA_MICRO_VERSION, payaraMicroVersion); + } properties.put(PROP_AUTO_BIND_HTTP, autoBindHttp); properties.put(PROP_CONTEXT_ROOT, contextRoot); diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/PayaraMicroPanel.form b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/PayaraMicroPanel.form index 13b5367..fac3384 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/PayaraMicroPanel.form +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/PayaraMicroPanel.form @@ -37,20 +37,28 @@ <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="0" attributes="0"> - <Group type="103" groupAlignment="0" attributes="0"> - <Component id="microVersionLabel" alignment="0" min="-2" max="-2" attributes="0"/> - <Component id="autoBindHttpLabel" alignment="0" min="-2" max="-2" attributes="0"/> - <Component id="contextRootLabel" alignment="0" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace max="-2" attributes="0"/> + <Group type="102" attributes="0"> <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" attributes="0"> - <Component id="autoBindHttpCheckBox" min="-2" max="-2" attributes="0"/> - <EmptySpace min="0" pref="91" max="32767" attributes="0"/> + <Group type="102" alignment="0" attributes="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="microVersionLabel" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="autoBindHttpLabel" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="contextRootLabel" alignment="0" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <Component id="autoBindHttpCheckBox" min="-2" max="-2" attributes="0"/> + <EmptySpace min="0" pref="91" max="32767" attributes="0"/> + </Group> + <Component id="microVersionCombobox" alignment="0" max="32767" attributes="0"/> + <Component id="contextRootTextField" alignment="1" max="32767" attributes="0"/> + </Group> + </Group> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace max="-2" attributes="0"/> + <Component id="statusMessage" max="32767" attributes="0"/> </Group> - <Component id="microVersionCombobox" alignment="0" max="32767" attributes="0"/> - <Component id="contextRootTextField" alignment="1" max="32767" attributes="0"/> </Group> <EmptySpace max="-2" attributes="0"/> </Group> @@ -73,7 +81,9 @@ <Component id="contextRootLabel" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="contextRootTextField" alignment="3" min="-2" max="-2" attributes="0"/> </Group> - <EmptySpace pref="217" max="32767" attributes="0"/> + <EmptySpace pref="188" max="32767" attributes="0"/> + <Component id="statusMessage" min="-2" pref="18" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> @@ -86,6 +96,7 @@ </Property> </Properties> <AuxValues> + <AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="if(PayaraPlatformVersion.getVersions().isEmpty()) {
 statusMessage.setText(NbBundle.getMessage(PayaraMicroPanel.class, "LBL_UnaleToConnectPayaraMavenRepo"));
} else {
 statusMessage.setText("");
}"/> <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<PayaraPlatformVersionAPI>"/> </AuxValues> </Component> @@ -133,5 +144,7 @@ </Property> </Properties> </Component> + <Component class="javax.swing.JLabel" name="statusMessage"> + </Component> </SubComponents> </Form> diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/PayaraMicroPanel.java b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/PayaraMicroPanel.java index 7ee7e66..6086e7c 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/PayaraMicroPanel.java +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ui/PayaraMicroPanel.java @@ -29,6 +29,7 @@ import static org.openide.util.NbBundle.getMessage; import static org.netbeans.modules.fish.payara.micro.plugin.Constants.PROP_CONTEXT_ROOT; import org.netbeans.modules.payara.tooling.data.PayaraPlatformVersion; import org.netbeans.modules.payara.tooling.data.PayaraPlatformVersionAPI; +import org.openide.util.NbBundle; /** * @@ -66,7 +67,9 @@ class PayaraMicroPanel extends JPanel { } void storeSettings(WizardDescriptor descriptor) { - descriptor.putProperty(PROP_PAYARA_MICRO_VERSION, microVersionCombobox.getSelectedItem().toString()); + if (microVersionCombobox.getSelectedItem() != null) { + descriptor.putProperty(PROP_PAYARA_MICRO_VERSION, microVersionCombobox.getSelectedItem().toString()); + } descriptor.putProperty(PROP_AUTO_BIND_HTTP, String.valueOf(autoBindHttpCheckBox.isSelected())); descriptor.putProperty(PROP_CONTEXT_ROOT, String.valueOf(contextRootTextField.getText().trim())); } @@ -81,6 +84,7 @@ class PayaraMicroPanel extends JPanel { autoBindHttpCheckBox = new javax.swing.JCheckBox(); contextRootLabel = new javax.swing.JLabel(); contextRootTextField = new javax.swing.JTextField(); + statusMessage = new javax.swing.JLabel(); microVersionCombobox.setModel(new DefaultComboBoxModel( PayaraPlatformVersion.getVersions() @@ -88,6 +92,11 @@ class PayaraMicroPanel extends JPanel { .sorted(Collections.reverseOrder()) .toArray(PayaraPlatformVersionAPI[]::new) )); + if(PayaraPlatformVersion.getVersions().isEmpty()) { + statusMessage.setText(NbBundle.getMessage(PayaraMicroPanel.class, "LBL_UnableToConnectPayaraMavenRepo")); + } else { + statusMessage.setText(""); + } org.openide.awt.Mnemonics.setLocalizedText(microVersionLabel, org.openide.util.NbBundle.getMessage(PayaraMicroPanel.class, "PayaraMicroPanel.microVersionLabel.text")); // NOI18N @@ -108,16 +117,21 @@ class PayaraMicroPanel extends JPanel { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(microVersionLabel) - .addComponent(autoBindHttpLabel) - .addComponent(contextRootLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addComponent(autoBindHttpCheckBox) - .addGap(0, 91, Short.MAX_VALUE)) - .addComponent(microVersionCombobox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(contextRootTextField, javax.swing.GroupLayout.Alignment.TRAILING)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(microVersionLabel) + .addComponent(autoBindHttpLabel) + .addComponent(contextRootLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(autoBindHttpCheckBox) + .addGap(0, 91, Short.MAX_VALUE)) + .addComponent(microVersionCombobox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(contextRootTextField, javax.swing.GroupLayout.Alignment.TRAILING))) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(statusMessage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( @@ -134,7 +148,9 @@ class PayaraMicroPanel extends JPanel { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(contextRootLabel) .addComponent(contextRootTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(217, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 188, Short.MAX_VALUE) + .addComponent(statusMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) ); }// </editor-fold>//GEN-END:initComponents @@ -145,6 +161,7 @@ class PayaraMicroPanel extends JPanel { private javax.swing.JTextField contextRootTextField; private javax.swing.JComboBox<PayaraPlatformVersionAPI> microVersionCombobox; private javax.swing.JLabel microVersionLabel; + private javax.swing.JLabel statusMessage; // End of variables declaration//GEN-END:variables } diff --git a/enterprise/payara.tooling/nbproject/project.xml b/enterprise/payara.tooling/nbproject/project.xml index c7750e3..0bdb476 100644 --- a/enterprise/payara.tooling/nbproject/project.xml +++ b/enterprise/payara.tooling/nbproject/project.xml @@ -26,30 +26,39 @@ <code-name-base>org.netbeans.modules.payara.tooling</code-name-base> <module-dependencies> <dependency> - <code-name-base>org.netbeans.modules.maven.embedder</code-name-base> + <code-name-base>org.netbeans.api.annotations.common</code-name-base> <build-prerequisite/> <compile-dependency/> <run-dependency> - <release-version>2</release-version> - <specification-version>2.54</specification-version> + <release-version>1</release-version> + <specification-version>1.27</specification-version> </run-dependency> </dependency> <dependency> - <code-name-base>org.netbeans.api.annotations.common</code-name-base> + <code-name-base>org.netbeans.libs.json_simple</code-name-base> <build-prerequisite/> <compile-dependency/> <run-dependency> <release-version>1</release-version> - <specification-version>1.27</specification-version> + <specification-version>0.10</specification-version> </run-dependency> </dependency> <dependency> - <code-name-base>org.netbeans.libs.json_simple</code-name-base> + <code-name-base>org.netbeans.modules.maven.embedder</code-name-base> <build-prerequisite/> <compile-dependency/> <run-dependency> - <release-version>1</release-version> - <specification-version>0.10</specification-version> + <release-version>2</release-version> + <specification-version>2.54</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.netbeans.modules.maven.indexer</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <release-version>2</release-version> + <specification-version>2.52</specification-version> </run-dependency> </dependency> <dependency> diff --git a/enterprise/payara.tooling/src/org/netbeans/modules/payara/tooling/data/PayaraPlatformVersion.java b/enterprise/payara.tooling/src/org/netbeans/modules/payara/tooling/data/PayaraPlatformVersion.java index 06201a3..81845e0 100644 --- a/enterprise/payara.tooling/src/org/netbeans/modules/payara/tooling/data/PayaraPlatformVersion.java +++ b/enterprise/payara.tooling/src/org/netbeans/modules/payara/tooling/data/PayaraPlatformVersion.java @@ -18,10 +18,12 @@ */ package org.netbeans.modules.payara.tooling.data; -import java.io.IOException; +import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.MalformedURLException; import java.net.URL; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -29,11 +31,16 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TreeMap; +import java.util.logging.Level; +import java.util.logging.Logger; import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; import org.openide.util.Exceptions; import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; +import org.netbeans.modules.maven.indexer.api.RepositoryInfo; +import org.netbeans.modules.maven.indexer.api.RepositoryPreferences; +import org.openide.util.NbBundle; /** * Payara Platform version. @@ -47,16 +54,22 @@ public class PayaraPlatformVersion implements PayaraPlatformVersionAPI, Comparab // Class attributes // //////////////////////////////////////////////////////////////////////////// + private static final Logger LOGGER = Logger.getLogger(PayaraPlatformVersion.class.getName()); + /** * Payara Server artifact download url */ - private static final String DOWNLOAD_URL = "https://oss.sonatype.org/service/local/repositories/releases/content/fish/payara/distributions/payara/%s/payara-%s.zip"; // NOI18N + private static final String DOWNLOAD_URL = "fish/payara/distributions/payara/%s/payara-%s.zip"; // NOI18N + + public static final String DEFAULT_REPOSITORY_URL = "https://repo1.maven.org/maven2/"; // NOI18N + + private static final String METADATA_URL = "fish/payara/distributions/payara/maven-metadata.xml"; // NOI18N - private static final String METADATA_URL = "https://repo1.maven.org/maven2/fish/payara/distributions/payara/maven-metadata.xml"; // NOI18N + private static final String LOCAL_METADATA_URL = "fish/payara/distributions/payara/maven-metadata-local.xml"; // NOI18N private static final String CDDL_LICENSE = "https://raw.githubusercontent.com/payara/Payara/master/LICENSE.txt"; // NOI18N - public static final PayaraPlatformVersionAPI EMPTY = new PayaraPlatformVersion((short) 0, (short) 0, (short) 0, (short) 0, "", ""); + public static final PayaraPlatformVersionAPI EMPTY = new PayaraPlatformVersion((short) 0, (short) 0, (short) 0, (short) 0, "", "", ""); private static PayaraPlatformVersionAPI latestVersion; @@ -80,35 +93,81 @@ public class PayaraPlatformVersion implements PayaraPlatformVersionAPI, Comparab public static List<PayaraPlatformVersionAPI> getVersions() { if (versions.isEmpty()) { - InputStream input = null; + String repository = DEFAULT_REPOSITORY_URL; + boolean readDefaultRepo; + URL metadata; try { - MetadataXpp3Reader reader = new MetadataXpp3Reader(); - input = new URL(METADATA_URL).openStream(); - Metadata data = reader.read(new InputStreamReader(input)); - versions.clear(); - for (String version : data.getVersioning().getVersions()) { - if (version.contains("Alpha") || version.contains("Beta")) { // NOI18N - continue; - } - PayaraPlatformVersionAPI payaraVersion = PayaraPlatformVersion.toValue(version); - versions.put(version, payaraVersion); - if (version.equals(data.getVersioning().getLatest())) { - latestVersion = payaraVersion; - } - } + metadata = new URL(repository + METADATA_URL); + readDefaultRepo = readVersions(repository, metadata); + } catch (UnknownHostException ex) { + readDefaultRepo = false; + LOGGER.log(Level.INFO, repository, ex); } catch (Exception ex) { + readDefaultRepo = false; Exceptions.printStackTrace(ex); - } finally { - try { - input.close(); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); + } + if (!readDefaultRepo) { + for (RepositoryInfo info : RepositoryPreferences.getInstance().getRepositoryInfos()) { + try { + repository = info.getRepositoryUrl(); + if (repository != null) { + metadata = new URL(repository + METADATA_URL); + } else { + repository = new File(info.getRepositoryPath() + File.separator).toURI().toString(); + if(!new File(repository + LOCAL_METADATA_URL).exists()) { + continue; + } + metadata = new URL(repository + LOCAL_METADATA_URL); + } + if (readVersions(repository, metadata)) { + break; + } + } catch (UnknownHostException ex) { + LOGGER.log(Level.INFO, repository, ex); + } catch (Exception ex) { + Exceptions.printStackTrace(ex); + } } } + } return new ArrayList<>(versions.values()); } + + + private static boolean readVersions(String repository, URL metadata) throws Exception { + try (InputStream input = metadata.openStream()) { + MetadataXpp3Reader reader = new MetadataXpp3Reader(); + Metadata data = reader.read(new InputStreamReader(input)); + versions.clear(); + for (String version : data.getVersioning().getVersions()) { + if (version.contains("Alpha") || version.contains("Beta") || version.contains("SNAPSHOT")) { // NOI18N + continue; + } + PayaraPlatformVersionAPI payaraVersion = PayaraPlatformVersion.toValue(repository, version); + versions.put(version, payaraVersion); + if (version.equals(data.getVersioning().getLatest())) { + latestVersion = payaraVersion; + } + } + if (!versions.isEmpty()) { + return true; + } + } + return false; + } + public static List<PayaraPlatformVersionAPI> getVersions(String repository) { + + return new ArrayList<>(versions.values()); + } + + @CheckForNull + public static PayaraPlatformVersionAPI toValue( + @NonNull final String versionStr) { + return toValue(DEFAULT_REPOSITORY_URL, versionStr); + } + /** * Returns a <code>PayaraPlatformVersionAPI</code> with a value represented by the * specified <code>String</code>. The <code>PayaraPlatformVersionAPI</code> returned @@ -116,13 +175,16 @@ public class PayaraPlatformVersion implements PayaraPlatformVersionAPI, Comparab * any <code>String</code> returned by <code>toString</code> method. * Otherwise <code>null</code> value is returned. * <p/> + * @param repository Value containing maven repository url <code>String</code> * @param versionStr Value containing version <code>String</code> * representation. * @return <code>PayaraPlatformVersionAPI</code> value represented by * <code>String</code> or <code>null</code> if value was not recognized. */ @CheckForNull - public static PayaraPlatformVersionAPI toValue(@NonNull final String versionStr) { + public static PayaraPlatformVersionAPI toValue( + @NonNull final String repository, + @NonNull final String versionStr) { if(versionStr.trim().isEmpty()) { return EMPTY; } @@ -143,7 +205,7 @@ public class PayaraPlatformVersion implements PayaraPlatformVersionAPI, Comparab version = new PayaraPlatformVersion( major, minor, update, build, major >= 5 ? "deployer:pfv5ee8" : "deployer:pfv4ee7", - versionStr + repository, versionStr ); } return version; @@ -191,7 +253,8 @@ public class PayaraPlatformVersion implements PayaraPlatformVersionAPI, Comparab * @param build Build version number. */ private PayaraPlatformVersion(final short major, final short minor, - final short update, final short build, String uriFragment, final String value) { + final short update, final short build, String uriFragment, + final String repository, final String value) { this.major = major; this.minor = minor; this.update = update; @@ -199,7 +262,7 @@ public class PayaraPlatformVersion implements PayaraPlatformVersionAPI, Comparab this.uriFragment = uriFragment; this.value = value; this.indirectUrl = null; - this.directUrl = String.format(DOWNLOAD_URL, value, value); + this.directUrl = repository + String.format(DOWNLOAD_URL, value, value); } //////////////////////////////////////////////////////////////////////////// diff --git a/java/maven.indexer/nbproject/project.xml b/java/maven.indexer/nbproject/project.xml index a61977e..b680bfd 100644 --- a/java/maven.indexer/nbproject/project.xml +++ b/java/maven.indexer/nbproject/project.xml @@ -145,6 +145,7 @@ <friend>org.netbeans.modules.maven.repository</friend> <friend>org.netbeans.modules.maven.search</friend> <friend>ro.emilianbold.modules.maven.search.remote</friend> + <friend>org.netbeans.modules.payara.tooling</friend> <package>org.apache.lucene</package> <package>org.apache.lucene.analysis</package> <package>org.apache.lucene.analysis.standard</package> diff --git a/java/maven/src/org/netbeans/modules/maven/newproject/ArchetypeWizardUtils.java b/java/maven/src/org/netbeans/modules/maven/newproject/ArchetypeWizardUtils.java index 7d2dbc2..6a787e1 100644 --- a/java/maven/src/org/netbeans/modules/maven/newproject/ArchetypeWizardUtils.java +++ b/java/maven/src/org/netbeans/modules/maven/newproject/ArchetypeWizardUtils.java @@ -77,7 +77,10 @@ public class ArchetypeWizardUtils { BeanRunConfig config = new BeanRunConfig(); config.setProperty("archetypeGroupId", arch.getGroupId()); //NOI18N config.setProperty("archetypeArtifactId", arch.getArtifactId()); //NOI18N - config.setProperty("archetypeVersion", arch.getVersion()); //NOI18N + if (arch.getVersion() != null + && !arch.getVersion().isEmpty()) { + config.setProperty("archetypeVersion", arch.getVersion()); //NOI18N + } String repo = arch.getRepository(); config.setProperty("archetypeRepository", repo != null ? repo : RepositorySystem.DEFAULT_REMOTE_REPO_URL); //NOI18N config.setProperty("groupId", vi.groupId); //NOI18N --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists