Skip to content

Commit

Permalink
FISH-9510 Fixes testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
jGauravGupta committed Nov 1, 2024
1 parent 7f20a48 commit 2c80914
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class PayaraMicroExtension {

private String payaraMicroAbsolutePath;

private String payaraVersion = DEFAULT_MICRO_VERSION;
private String payaraVersion;

private String contextRoot;

Expand Down Expand Up @@ -180,6 +180,9 @@ public void setPayaraMicroAbsolutePath(String payaraMicroAbsolutePath) {
}

public String getPayaraVersion() {
if(payaraVersion != null) {
return payaraVersion;
}
PayaraMicroVersionSelector selector = new PayaraMicroVersionSelector(project);
String version = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ private int getJakartaMajorVersion(String jakartaVersion) {
}
}

private String getPayaraMicroVersion(int jakartaMajorVersion) throws GradleException {
public static String getPayaraMicroVersion(int jakartaMajorVersion) throws GradleException {
return fetchPayaraMicroVersion(version -> version.startsWith(JAKARTA_TO_PAYARA_MAP.get(jakartaMajorVersion)));
}

private String getLatestPayaraMicroVersion() throws GradleException {
return fetchPayaraMicroVersion(version -> true);
}

private String fetchPayaraMicroVersion(Predicate<String> versionPredicate) throws GradleException {
private static String fetchPayaraMicroVersion(Predicate<String> versionPredicate) throws GradleException {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(MAVEN_METADATA_URL);
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public class BundleLifecycleTest extends BaseTest {
public void uberJarBundleTest() throws Exception {

buildProject();
buildExtension();
PayaraMicroExtension extension = buildExtension();
int jakataEEVersion = JakartaEEVersionSelector.getMajorJakartaEEVersion();
String payaraVersion = PayaraMicroVersionSelector.getPayaraMicroVersion(jakataEEVersion);
extension.setPayaraVersion(payaraVersion);
bundleMicro();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
*
* Copyright (c) 2024 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.gradle.plugins.micro;

public class JakartaEEVersionSelector {

public static int getMajorJakartaEEVersion() {
int jdkVersion = getCurrentJDKVersion();
switch (jdkVersion) {
case 21:
return 11; // Select 11 for JDK 21
case 17:
return 10; // Select 10 for JDK 17
case 11:
return 8; // Select 8 for JDK 11
default:
return 8;
}
}

private static int getCurrentJDKVersion() {
String version = System.getProperty("java.version");
String[] versionParts = version.split("\\.");
int majorVersion;

if (versionParts[0].equals("1")) {
majorVersion = Integer.parseInt(versionParts[1]); // For versions like 1.8
} else {
majorVersion = Integer.parseInt(versionParts[0]); // For versions like 9, 10, 11
}

return majorVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ public class StartStopLifecycleTest extends BaseTest {
public void warTest() throws Exception {

buildProject();
buildExtension().setDeployWar(true);

PayaraMicroExtension extension = buildExtension();
int jakataEEVersion = JakartaEEVersionSelector.getMajorJakartaEEVersion();
String payaraVersion = PayaraMicroVersionSelector.getPayaraMicroVersion(jakataEEVersion);
extension.setPayaraVersion(payaraVersion);
extension.setDeployWar(true);

createWar();
bootstrapMicro();
Expand All @@ -66,17 +71,23 @@ public void customMicroVersionTest() throws Exception {
public void uberJarTest() throws Exception {

buildProject();
buildExtension().setUseUberJar(true);
PayaraMicroExtension extension = buildExtension();
int jakataEEVersion = JakartaEEVersionSelector.getMajorJakartaEEVersion();
String payaraVersion = PayaraMicroVersionSelector.getPayaraMicroVersion(jakataEEVersion);
extension.setPayaraVersion(payaraVersion);
extension.setUseUberJar(true);

bundleMicro();
bootstrapMicro();
}

@Test
public void explodedWarTest() throws Exception {

buildProject();
PayaraMicroExtension extension = buildExtension();
int jakataEEVersion = JakartaEEVersionSelector.getMajorJakartaEEVersion();
String payaraVersion = PayaraMicroVersionSelector.getPayaraMicroVersion(jakataEEVersion);
extension.setPayaraVersion(payaraVersion);
extension.setDeployWar(true);
extension.setExploded(true);

Expand Down

0 comments on commit 2c80914

Please sign in to comment.