Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-9444 Payara Eclipse Tools with Payara 7 support #84

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
/features/fish.payara.eclipse.tools.server.feature/.polyglot.build.properties
/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.1.0.20221015-0744.xml
/.metadata/
/.idea
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020-2022 Payara Foundation
* Copyright (c) 2020-2024 Payara Foundation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -89,7 +89,7 @@ public List<String> getStartCommand(String contextPath, String microVersion, Str
} else {
commands.add("package");
}
commands.add(PLUGIN + "start");
commands.add(PLUGIN + "dev");
if (contextPath != null && !contextPath.trim().isEmpty()) {
commands.add("-DcontextRoot=" + contextPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ runtimeName=Runtime Name
emptyRuntimeName=Runtime name is required!
duplicateRuntimeName=Runtime name {0} is already used!
runtimeIdentified=Found Payara Server version {0}.
unsupportedVersion=Only Payara 6, 5, 4 and 3.1 are supported
unsupportedVersion=Only Payara 7, 6, 5, 4 and 3.1 are supported
versionsNotMatching=The versions of local and remote server do not match.
runtimeNotValid=There is no valid Payara runtime in specified directory.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020-2022 Payara Foundation
* Copyright (c) 2020-2024 Payara Foundation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand All @@ -9,7 +9,6 @@
*/
package fish.payara.eclipse.tools.micro.ui;

import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.ARCHETYPE_MICRO_VERSIONS;
import static fish.payara.eclipse.tools.micro.MicroConstants.ATTR_BUILD_ARTIFACT;
import static fish.payara.eclipse.tools.micro.MicroConstants.ATTR_CONTEXT_PATH;
import static fish.payara.eclipse.tools.micro.MicroConstants.ATTR_DEBUG_PORT;
Expand All @@ -35,6 +34,7 @@
import java.util.List;
import java.util.Map;

import fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void createControl(Composite parent) {

group = SWTFactory.createGroup(mainComposite, Messages.microVersionComponentLabel, 1, 1,
GridData.FILL_HORIZONTAL);
microVersionText = SWTFactory.createCombo(group, SWT.READ_ONLY, 1, ARCHETYPE_MICRO_VERSIONS);
microVersionText = SWTFactory.createCombo(group, SWT.READ_ONLY, 1, MicroProjectWizard.getVersions().toArray(new String[0]));
microVersionText.addModifyListener(getDefaultListener());

group = SWTFactory.createGroup(mainComposite, Messages.buildArtifactComponentLabel, 1, 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020-2022 Payara Foundation
* Copyright (c) 2020-2024 Payara Foundation
* Copyright (c) 2008-2010 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand All @@ -13,6 +13,12 @@
import static java.lang.Boolean.TRUE;
import static java.util.stream.Collectors.toList;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -53,6 +59,12 @@
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkingSet;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

public class MicroProjectWizard extends Wizard implements INewWizard {

Expand All @@ -75,24 +87,15 @@ public MicroProjectWizard() {
private static final String NAME = "\\[name\\]"; //$NON-NLS-1$
private static final String PROJECT_NAME_REGEX = "\\$\\{[^\\}]++\\}"; //$NON-NLS-1$

private static final String ARCHETYPE_GROUP_ID = "fish.payara.maven.archetypes"; //$NON-NLS-1$
private static final String ARCHETYPE_ARTIFACT_ID = "payara-micro-maven-archetype"; //$NON-NLS-1$
public static final String ARCHETYPE_GROUP_ID = "fish.payara.maven.archetypes"; //$NON-NLS-1$
public static final String ARCHETYPE_ARTIFACT_ID = "payara-micro-maven-archetype"; //$NON-NLS-1$
public static final String ARCHETYPE_VERSION_5X = "1.4.0"; //$NON-NLS-1$
public static final String ARCHETYPE_VERSION_6X = "2.0"; //$NON-NLS-1$
public static final String STARTER_ARCHETYPE_GROUP_ID = "fish.payara.starter";
public static final String STARTER_ARCHETYPE_ARTIFACT_ID = "payara-starter-archetype";
public static final String ARCHETYPE_VERSION_6X = "1.0-beta9"; //$NON-NLS-1$
private static final String ARCHETYPE_JDK_VERSION = "jdkVersion"; //$NON-NLS-1$
private static final String ARCHETYPE_JDK_VERSION_DEFAULT_VALUE = "1.8"; //$NON-NLS-1$
public static final String ARCHETYPE_MICRO_VERSION = "payaraMicroVersion"; //$NON-NLS-1$
private static final String ARCHETYPE_MICRO_VERSION_DEFAULT_VALUE = "6.2023.2"; //$NON-NLS-1$
public static final String[] ARCHETYPE_MICRO_VERSIONS = new String[]{"6.2023.2", "6.2023.1", "6.2022.2", "6.2022.1",
"5.2022.5", "5.2022.4", "5.2022.3",
"5.2022.2", "5.2022.1", "5.2021.10",
"5.2021.9", "5.2021.8", "5.2021.7",
"5.2021.6", "5.2021.5", "5.2021.4",
"5.2021.3", "5.2021.2", "5.2021.1",
"5.2020.7", "5.2020.6", "5.2020.5",
"5.2020.4", "5.2020.3", "5.2020.2",
"5.201", "5.194", "5.193.1", "5.192",
"5.191", "5.184", "5.183", "5.182", "5.181"}; //$NON-NLS-1$
public static final String ARCHETYPE_AUTOBIND_HTTP = "autoBindHttp"; //$NON-NLS-1$
private static final String ARCHETYPE_CONCURRENT_API = "addConcurrentApi"; //$NON-NLS-1$
private static final String ARCHETYPE_RESOURCE_API = "addResourceApi"; //$NON-NLS-1$
Expand All @@ -105,6 +108,57 @@ public MicroProjectWizard() {
private static final String ARCHETYPE_DEPLOY_WAR = "deployWar"; //$NON-NLS-1$
private static final String EMPTY = ""; //$NON-NLS-1$


public static final String DEFAULT_REPOSITORY_URL = "https://repo1.maven.org/maven2/"; // NOI18N

private static final String METADATA_URL = "fish/payara/extras/payara-micro/maven-metadata.xml"; // NOI18N

private static final List<String> versions = new ArrayList<>();
public static List<String> getVersions() {
if (versions.isEmpty()) {
try {
// Construct the full URL
String urlString = DEFAULT_REPOSITORY_URL + METADATA_URL;
URL url = new URL(urlString);

// Open connection
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");

// Read the response
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder xmlResponse = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
xmlResponse.append(line);
}
in.close();

// Parse the XML response
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xmlResponse.toString())));

String latest = doc.getElementsByTagName("latest").item(0).getTextContent();
// Extract versions
NodeList versionNodes = doc.getElementsByTagName("version");
for (int i = versionNodes.getLength() - 1; i >= 0; i--) {
String version = versionNodes.item(i).getTextContent();
if ((version.contains("Alpha") || version.contains("Beta") || version.contains("SNAPSHOT")) // NOI18N
&& !version.equals(latest)) {
continue;
};
versions.add(version);
}

} catch (Exception e) {
e.printStackTrace();
}

}
return versions;
}

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.selection = selection;
Expand Down Expand Up @@ -134,12 +188,12 @@ public void createPageControls(Composite pageContainer) {

private Archetype getArchetype() {
Archetype archetype = new Archetype();
archetype.setGroupId(ARCHETYPE_GROUP_ID);
archetype.setArtifactId(ARCHETYPE_ARTIFACT_ID);
archetype.setGroupId(STARTER_ARCHETYPE_GROUP_ID);
archetype.setArtifactId(STARTER_ARCHETYPE_ARTIFACT_ID);
archetype.setVersion(ARCHETYPE_VERSION_6X);
Properties properties = new Properties();
properties.put(ARCHETYPE_JDK_VERSION, ARCHETYPE_JDK_VERSION_DEFAULT_VALUE);
properties.put(ARCHETYPE_MICRO_VERSION, ARCHETYPE_MICRO_VERSION_DEFAULT_VALUE);
properties.put(ARCHETYPE_MICRO_VERSION, getVersions().get(0));
properties.put(ARCHETYPE_AUTOBIND_HTTP, TRUE.toString());
properties.put(ARCHETYPE_CONCURRENT_API, FALSE.toString());
properties.put(ARCHETYPE_RESOURCE_API, FALSE.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020-2022 Payara Foundation
* Copyright (c) 2020-2024 Payara Foundation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand All @@ -12,15 +12,17 @@
import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.ARCHETYPE_AUTOBIND_HTTP;
import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.ARCHETYPE_CONTEXT_ROOT;
import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.ARCHETYPE_MICRO_VERSION;
import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.ARCHETYPE_MICRO_VERSIONS;
import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.ARCHETYPE_VERSION_5X;
import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.ARCHETYPE_VERSION_6X;
import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.ARCHETYPE_GROUP_ID;
import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.ARCHETYPE_ARTIFACT_ID;
import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.STARTER_ARCHETYPE_GROUP_ID;
import static fish.payara.eclipse.tools.micro.ui.wizards.MicroProjectWizard.STARTER_ARCHETYPE_ARTIFACT_ID;
import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

import org.apache.maven.archetype.catalog.Archetype;
Expand Down Expand Up @@ -76,7 +78,7 @@ private void createUI(Composite parent) {
microVersionCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
microVersionCombo.setData("name", ARCHETYPE_MICRO_VERSION); //$NON-NLS-1$
microVersionCombo.addModifyListener(e -> validate());
microVersionCombo.setItems(ARCHETYPE_MICRO_VERSIONS);
microVersionCombo.setItems(MicroProjectWizard.getVersions().toArray(new String[0]));

Label autobindLabel = new Label(parent, SWT.NONE);
autobindLabel.setText(Messages.autobindComponentLabel);
Expand Down Expand Up @@ -129,19 +131,25 @@ private String validateInput() {
}

public Archetype getArchetype() {
String[] versionToken = microVersionCombo.getText().trim().split("\\.");
archetype.setVersion(versionToken.length > 1 && Integer.parseInt(versionToken[0]) < 6 ? ARCHETYPE_VERSION_5X : ARCHETYPE_VERSION_6X);
String[] versionToken = microVersionCombo.getText().trim().split("\\.");
if (versionToken.length > 1 && Integer.parseInt(versionToken[0]) < 6) {
archetype.setGroupId(ARCHETYPE_GROUP_ID);
archetype.setArtifactId(ARCHETYPE_ARTIFACT_ID);
archetype.setVersion(ARCHETYPE_VERSION_5X);
} else {
archetype.setGroupId(STARTER_ARCHETYPE_GROUP_ID);
archetype.setArtifactId(STARTER_ARCHETYPE_ARTIFACT_ID);
archetype.setVersion(ARCHETYPE_VERSION_6X);
}

return archetype;
}

public Map<String, String> getProperties() {
Map<String, String> properties = archetype.getProperties()
.entrySet().stream().collect(
Collectors.toMap(
e -> e.getKey().toString(),
e -> e.getValue().toString()
)
);
Map<String, String> properties = archetype.getProperties()
.entrySet()
.stream()
.collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()));
String contextRoot = contextPathCombo.getText().trim();
try {
contextRoot = contextRoot.startsWith("/") ? '/' + URLEncoder.encode(contextRoot.substring(1), UTF_8.name())
Expand Down
4 changes: 2 additions & 2 deletions bundles/fish.payara.eclipse.tools.server/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ runtimeTypeVendor=Oracle Corporation
runtimeTypeGlassFishVendor=Payara

runtimeTypeNameglassfish=Payara
runtimeTypeDescriptionglassfish=Supports Payara 6, 5, 4 and 3.1
runtimeTypeDescriptionglassfish=Supports Payara 7, 6, 5, 4 and 3.1
serverTypeNameglassfish=Payara
serverTypeDescriptionPayara=Supports Payara Server 6, 5 and 4. Can also be used for GlassFish.
serverTypeDescriptionPayara=Supports Payara Server 7, 6, 5 and 4. Can also be used for GlassFish.

payara.server.runConfigurationName=Payara Server
payara.micro.runConfigurationName=Payara Micro
Expand Down
44 changes: 37 additions & 7 deletions bundles/fish.payara.eclipse.tools.server/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<moduleType types="jst.web" versions="2.2, 2.3, 2.4, 2.5, 3.0, 3.1, 4.0, 5.0, 6.0, 6.1"/>
<moduleType types="jst.ejb" versions="1.1, 2.0, 2.1, 3.0, 3.1, 3.2, 4.0, 4.1"/>
<moduleType types="jst.connector" versions="1.0, 1.5, 1.6, 1.7, 2.0, 2.1"/>
<moduleType types="jst.ear" versions="1.2, 1.3, 1.4, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0"/>
<moduleType types="jst.ear" versions="1.2, 1.3, 1.4, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0"/>
<moduleType types="jst.utility" versions="1.0"/>
<moduleType types="jst.appclient" versions="1.2, 1.3, 1.4, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0"/>
<moduleType types="jst.appclient" versions="1.2, 1.3, 1.4, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0"/>
</runtimeType>
</extension>

Expand Down Expand Up @@ -88,6 +88,7 @@
<runtime-component-version type="payara.runtime" version="4"/>
<runtime-component-version type="payara.runtime" version="5"/>
<runtime-component-version type="payara.runtime" version="6"/>
<runtime-component-version type="payara.runtime" version="7"/>

<supported>
<runtime-component id="payara.runtime" version="3.1"/>
Expand Down Expand Up @@ -127,7 +128,7 @@
<facet id="jst.utility" version="1.0"/>
<facet id="jst.webfragment" version="4.0]" />
</supported>

<supported>
<runtime-component id="payara.runtime" version="6"/>
<facet id="glassfish.web" version="6.0]"/>
Expand All @@ -137,9 +138,22 @@
<facet id="jst.ear" version="10.0]"/>
<facet id="jst.connector" version="2.1]"/>
<facet id="jst.appclient" version="10.0]"/>
<facet id="jst.utility" version="1.0"/>
<facet id="jst.utility" version="1.0"/>
<facet id="jst.webfragment" version="6.0]" />
</supported>

<supported>
<runtime-component id="payara.runtime" version="7"/>
<facet id="glassfish.web" version="7.0]"/>
<facet id="glassfish.ejb" version="7.0]"/>
<facet id="jst.web" version="7.0]"/>
<facet id="jst.ejb" version="4.0]"/>
<facet id="jst.ear" version="11.0]"/>
<facet id="jst.connector" version="2.1]"/>
<facet id="jst.appclient" version="11.0]"/>
<facet id="jst.utility" version="1.0"/>
<facet id="jst.webfragment" version="7.0]" />
</supported>
</extension>

<extension point="org.eclipse.wst.common.project.facet.core.runtimes">
Expand Down Expand Up @@ -317,23 +331,39 @@
<fixed-facet id="jst.ejb"/>
</context>
<facet id="glassfish.ejb" version="5.0" />
</default-facets>
</default-facets>

<default-facets>
<context>
<runtime-component id="payara.runtime" version="6"/>
<fixed-facet id="jst.web"/>
</context>
<facet id="glassfish.web" version="6.0" />
</default-facets>
</default-facets>

<default-facets>
<context>
<runtime-component id="payara.runtime" version="6"/>
<fixed-facet id="jst.ejb"/>
</context>
<facet id="glassfish.ejb" version="6.0" />
</default-facets>
</default-facets>

<default-facets>
<context>
<runtime-component id="payara.runtime" version="7"/>
<fixed-facet id="jst.web"/>
</context>
<facet id="glassfish.web" version="7.0" />
</default-facets>

<default-facets>
<context>
<runtime-component id="payara.runtime" version="7"/>
<fixed-facet id="jst.ejb"/>
</context>
<facet id="glassfish.ejb" version="7.0" />
</default-facets>
</extension>

<extension point="org.eclipse.wst.common.project.facet.core.runtimeBridges">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ runtimeName=Runtime Name
emptyRuntimeName=Runtime name is required!
duplicateRuntimeName=Runtime name {0} is already used!
runtimeIdentified=Found Payara Server version {0}.
unsupportedVersion=Only Payara 6, 5, 4 and 3.1 are supported
unsupportedVersion=Only Payara 7, 6, 5, 4 and 3.1 are supported
versionsNotMatching=The versions of local and remote server do not match.
runtimeNotValid=There is no valid Payara runtime in specified directory.

Expand Down
Loading