From 3f77c41d78c2220901cadd8dd88cea531a44ab2e Mon Sep 17 00:00:00 2001 From: Cuba Date: Thu, 10 Oct 2019 11:19:19 +0100 Subject: [PATCH 1/9] Minor PayaraVersion update --- .../arquillian/container/payara/PayaraVersion.java | 11 ++++++++++- .../managed/PayaraMicroContainerConfiguration.java | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java b/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java index 70872bcf..054bdb2c 100644 --- a/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java +++ b/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java @@ -53,6 +53,15 @@ public PayaraVersion(String versionString) { this.versionString = versionString; } + /** + * A Utility method used for comparing PayaraVersion objects + * + * When the parsed PayaraVersion is equal to the version it's being compared + * to, the method will return true + * + * @param minimum - the version you wish to compare to + * @return true if minimum is equal to or greater than the version to compare + */ public boolean isMoreRecentThan(PayaraVersion minimum) { String minString = minimum.versionString; try (Scanner minScanner = new Scanner(minString); Scanner vScanner = new Scanner(versionString)) { @@ -83,7 +92,7 @@ public boolean isMoreRecentThan(PayaraVersion minimum) { vPart--; } - if (vPart > minPart) { + if (vPart >= minPart) { return true; } if (minPart > vPart) { diff --git a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java index 03190e4d..157fe72a 100644 --- a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java +++ b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java @@ -201,7 +201,11 @@ public void validate() throws ConfigurationException { try (JarFile microJarFile = new JarFile(getMicroJarFile())) { ZipEntry pomProperties = microJarFile - .getEntry("META-INF/maven/fish.payara.micro/payara-micro-boot/pom.properties"); + .getEntry( + + //TO-DO: Add Version Check Code + + "META-INF/maven/fish.payara.micro/payara-micro-boot/pom.properties"); Properties microProperties = new Properties(); microProperties.load(microJarFile.getInputStream(pomProperties)); this.microVersion = new PayaraVersion(microProperties.getProperty("version")); From 094ec18e8846d6b89e4788438cf1a0e7ced57a24 Mon Sep 17 00:00:00 2001 From: Cuba Date: Thu, 10 Oct 2019 11:41:49 +0100 Subject: [PATCH 2/9] Updated container to accomodate new package names --- .../container/payara/PayaraVersion.java | 4 ++++ .../PayaraMicroContainerConfiguration.java | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java b/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java index 054bdb2c..21a9058d 100644 --- a/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java +++ b/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java @@ -52,6 +52,10 @@ public PayaraVersion(String versionString) { } this.versionString = versionString; } + + public boolean isMoreRecentThan(String versionString) { + return isMoreRecentThan(new PayaraVersion(versionString)); + } /** * A Utility method used for comparing PayaraVersion objects diff --git a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java index 157fe72a..1a0004cd 100644 --- a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java +++ b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java @@ -200,18 +200,22 @@ public void validate() throws ConfigurationException { } try (JarFile microJarFile = new JarFile(getMicroJarFile())) { - ZipEntry pomProperties = microJarFile - .getEntry( - - //TO-DO: Add Version Check Code - - "META-INF/maven/fish.payara.micro/payara-micro-boot/pom.properties"); + + //Change made to accommodate package refactor in version 5.194+ + String zipEntryDir = (getMicroVersion().isMoreRecentThan("5.194-SNAPSHOT")) + ? "META-INF/maven/fish.payara.server.internal.extras/payara-micro-boot/pom.properties" + : "META-INF/maven/fish.payara.micro/payara-micro-boot/pom.properties"; + + ZipEntry pomProperties = microJarFile.getEntry(zipEntryDir); Properties microProperties = new Properties(); microProperties.load(microJarFile.getInputStream(pomProperties)); this.microVersion = new PayaraVersion(microProperties.getProperty("version")); } catch (IOException e) { throw new IllegalArgumentException( "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar.", e); + } catch (IllegalStateException e) { + throw new IllegalArgumentException( + "Unable to find Payara Micro Boot Properties. Are you using the latest arquillian container?", e); } notNull(getMicroVersion(), "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar."); From b97d059daa8c8615fe736e4035ff507b97dcb197 Mon Sep 17 00:00:00 2001 From: Cuba Date: Thu, 10 Oct 2019 16:00:50 +0100 Subject: [PATCH 3/9] Used glassfish props instead of micro boot props for version num --- .../PayaraMicroContainerConfiguration.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java index 1a0004cd..b2d33f46 100644 --- a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java +++ b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java @@ -199,21 +199,20 @@ public void validate() throws ConfigurationException { throw new IllegalArgumentException("Could not locate the Payara Micro Jar file " + getMicroJar()); } + String zipEntryDir = ""; //Created here for the sakes of debugging in case of NPE + try (JarFile microJarFile = new JarFile(getMicroJarFile())) { - //Change made to accommodate package refactor in version 5.194+ - String zipEntryDir = (getMicroVersion().isMoreRecentThan("5.194-SNAPSHOT")) - ? "META-INF/maven/fish.payara.server.internal.extras/payara-micro-boot/pom.properties" - : "META-INF/maven/fish.payara.micro/payara-micro-boot/pom.properties"; - + zipEntryDir = "MICRO-INF/domain/branding/glassfish-version.properties"; ZipEntry pomProperties = microJarFile.getEntry(zipEntryDir); + Properties microProperties = new Properties(); microProperties.load(microJarFile.getInputStream(pomProperties)); - this.microVersion = new PayaraVersion(microProperties.getProperty("version")); + this.microVersion = new PayaraVersion(microProperties.getProperty("major_version") + microProperties.getProperty("minor_version")); } catch (IOException e) { throw new IllegalArgumentException( - "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar.", e); - } catch (IllegalStateException e) { + "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar." + zipEntryDir, e); + } catch (NullPointerException e) { throw new IllegalArgumentException( "Unable to find Payara Micro Boot Properties. Are you using the latest arquillian container?", e); } From 6d33e08bc7dc27cfa8cac4c4c4cc5840ec40a904 Mon Sep 17 00:00:00 2001 From: Cuba Date: Thu, 10 Oct 2019 16:07:07 +0100 Subject: [PATCH 4/9] Added to NPE message --- .../payara/managed/PayaraMicroContainerConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java index b2d33f46..c42fd7e0 100644 --- a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java +++ b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java @@ -211,10 +211,10 @@ public void validate() throws ConfigurationException { this.microVersion = new PayaraVersion(microProperties.getProperty("major_version") + microProperties.getProperty("minor_version")); } catch (IOException e) { throw new IllegalArgumentException( - "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar." + zipEntryDir, e); + "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar.", e); } catch (NullPointerException e) { throw new IllegalArgumentException( - "Unable to find Payara Micro Boot Properties. Are you using the latest arquillian container?", e); + "Unable to find Payara Micro Boot Properties. Are you using the latest arquillian container? \n Directory searched: " + zipEntryDir, e); } notNull(getMicroVersion(), "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar."); From 556107b26e21011141aa05823d4ae8cdb7d9c23d Mon Sep 17 00:00:00 2001 From: Cuba Date: Thu, 10 Oct 2019 16:26:05 +0100 Subject: [PATCH 5/9] Review amendments --- .../managed/PayaraMicroContainerConfiguration.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java index c42fd7e0..48ea10eb 100644 --- a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java +++ b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java @@ -199,22 +199,22 @@ public void validate() throws ConfigurationException { throw new IllegalArgumentException("Could not locate the Payara Micro Jar file " + getMicroJar()); } - String zipEntryDir = ""; //Created here for the sakes of debugging in case of NPE + String zipEntryFileDir = ""; //Created here for the sakes of debugging in case of NPE try (JarFile microJarFile = new JarFile(getMicroJarFile())) { - zipEntryDir = "MICRO-INF/domain/branding/glassfish-version.properties"; - ZipEntry pomProperties = microJarFile.getEntry(zipEntryDir); + zipEntryFileDir = "MICRO-INF/domain/branding/glassfish-version.properties"; + ZipEntry pomProperties = microJarFile.getEntry(zipEntryFileDir); Properties microProperties = new Properties(); microProperties.load(microJarFile.getInputStream(pomProperties)); - this.microVersion = new PayaraVersion(microProperties.getProperty("major_version") + microProperties.getProperty("minor_version")); + this.microVersion = new PayaraVersion(microProperties.getProperty("major_version") + "." + microProperties.getProperty("minor_version")); } catch (IOException e) { throw new IllegalArgumentException( - "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar.", e); + "Unable to find Payara Micro Version. Please check the file is a valid Payara Micro Jar.", e); } catch (NullPointerException e) { throw new IllegalArgumentException( - "Unable to find Payara Micro Boot Properties. Are you using the latest arquillian container? \n Directory searched: " + zipEntryDir, e); + "Unable to find Payara Micro Version. Please check the file is a valid Payara Micro Jar.\nProperties File Used: " + zipEntryFileDir, e); } notNull(getMicroVersion(), "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar."); From f3d413b7578e0e47c6130fd8d3810a25171e037a Mon Sep 17 00:00:00 2001 From: Cuba Date: Fri, 11 Oct 2019 09:45:06 +0100 Subject: [PATCH 6/9] Declared constant for zip entry dir --- .../managed/PayaraMicroContainerConfiguration.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java index 48ea10eb..fd83b8cb 100644 --- a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java +++ b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java @@ -73,6 +73,8 @@ public class PayaraMicroContainerConfiguration implements ContainerConfiguration private String cmdOptions = getConfigurableVariable("payara.cmdOptions", "MICRO_CMD_OPTIONS", null); private String extraMicroOptions = getConfigurableVariable("payara.extraMicroOptions", "EXTRA_MICRO_OPTIONS", null); + + private final String ZIP_ENTRY_FILE_DIR = "MICRO-INF/domain/branding/glassfish-version.properties"; public String getMicroJar() { return microJar; @@ -198,13 +200,10 @@ public void validate() throws ConfigurationException { if (!getMicroJarFile().isFile()) { throw new IllegalArgumentException("Could not locate the Payara Micro Jar file " + getMicroJar()); } - - String zipEntryFileDir = ""; //Created here for the sakes of debugging in case of NPE try (JarFile microJarFile = new JarFile(getMicroJarFile())) { - zipEntryFileDir = "MICRO-INF/domain/branding/glassfish-version.properties"; - ZipEntry pomProperties = microJarFile.getEntry(zipEntryFileDir); + ZipEntry pomProperties = microJarFile.getEntry(ZIP_ENTRY_FILE_DIR); Properties microProperties = new Properties(); microProperties.load(microJarFile.getInputStream(pomProperties)); @@ -214,7 +213,7 @@ public void validate() throws ConfigurationException { "Unable to find Payara Micro Version. Please check the file is a valid Payara Micro Jar.", e); } catch (NullPointerException e) { throw new IllegalArgumentException( - "Unable to find Payara Micro Version. Please check the file is a valid Payara Micro Jar.\nProperties File Used: " + zipEntryFileDir, e); + "Unable to find Payara Micro Version. Please check the file is a valid Payara Micro Jar.\nProperties File Used: " + ZIP_ENTRY_FILE_DIR, e); } notNull(getMicroVersion(), "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar."); From b6f5d00714b4bde7f371d3799e406b362efcb008 Mon Sep 17 00:00:00 2001 From: Cuba Date: Fri, 11 Oct 2019 10:45:43 +0100 Subject: [PATCH 7/9] Updated PayaraVersion class --- .../container/payara/PayaraVersion.java | 46 ++++++++++++++++++- .../container/payara/PayaraVersionTest.java | 29 ++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java b/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java index 21a9058d..693c5229 100644 --- a/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java +++ b/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java @@ -53,6 +53,45 @@ public PayaraVersion(String versionString) { this.versionString = versionString; } + /** + * This Method takes in properties from a glassfish-version.properties file and constructs + * a new PayaraVersion object from this data. It is assumed that there will always be a + * major and minor version but update, payaraMajor and payaraMinor may be null. + * + * @param major - Major version of the server + * @param minor - Minor version of the server + * @param update - Stability/Feature patch version of the server + * @param payaraMinor - Minor version of Payara 4 versions + * @param payaraUpdate - Stability/Feat patch version of Payara 4 versions + * @return + */ + public static PayaraVersion buildVersionFromBrandingProperties(String major, String minor, String update, + String payaraMinor, String payaraUpdate) + throws IllegalArgumentException { + StringBuilder versionBuilder = new StringBuilder(); + String[] subVersionValues = {minor, update, payaraMinor, payaraUpdate}; + + if(major == null || major.isEmpty()) { + throw new IllegalArgumentException("Invalid properties - Major version value cannot be null or empty."); + } + + versionBuilder.append(major); //should always be a major version with value + + for(int i = 0; i < subVersionValues.length; i++) { + + String curVersionValue = subVersionValues[i]; + + if(curVersionValue != null && !curVersionValue.isEmpty()) { + versionBuilder.append("."); + versionBuilder.append(curVersionValue); + } else { + break; + } + } + + return new PayaraVersion(versionBuilder.toString()); + } + public boolean isMoreRecentThan(String versionString) { return isMoreRecentThan(new PayaraVersion(versionString)); } @@ -97,7 +136,7 @@ public boolean isMoreRecentThan(PayaraVersion minimum) { } if (vPart >= minPart) { - return true; + continue; } if (minPart > vPart) { return false; @@ -106,4 +145,9 @@ public boolean isMoreRecentThan(PayaraVersion minimum) { } return true; } + + @Override + public String toString() { + return versionString; + } } \ No newline at end of file diff --git a/payara-common/src/test/java/fish/payara/arquillian/container/payara/PayaraVersionTest.java b/payara-common/src/test/java/fish/payara/arquillian/container/payara/PayaraVersionTest.java index 4bc30215..a9cea740 100644 --- a/payara-common/src/test/java/fish/payara/arquillian/container/payara/PayaraVersionTest.java +++ b/payara-common/src/test/java/fish/payara/arquillian/container/payara/PayaraVersionTest.java @@ -37,6 +37,7 @@ */ package fish.payara.arquillian.container.payara; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -76,4 +77,32 @@ public void moreRecentVersionTest() { v2 = new PayaraVersion("5.181"); assertTrue("The version check failed.", v2.isMoreRecentThan(v1)); } + + @Test + public void testVersionBuilderFromProperties() { + + PayaraVersion testVersion = PayaraVersion.buildVersionFromBrandingProperties("5", "192", "", "", ""); + assertEquals("5.192", testVersion.toString()); + + testVersion = PayaraVersion.buildVersionFromBrandingProperties("5", "192", "3", "", ""); + assertEquals("5.192.3", testVersion.toString()); + + testVersion = PayaraVersion.buildVersionFromBrandingProperties("4", "1", "2", null, null); + assertEquals("4.1.2", testVersion.toString()); + + testVersion = PayaraVersion.buildVersionFromBrandingProperties("4", "1", "2", "191", ""); + assertEquals("4.1.2.191", testVersion.toString()); + + testVersion = PayaraVersion.buildVersionFromBrandingProperties("4", "1", "2", "191", "7"); + assertEquals("4.1.2.191.7", testVersion.toString()); + + testVersion = PayaraVersion.buildVersionFromBrandingProperties("4", "1", null, "191", "7"); + assertEquals("4.1", testVersion.toString()); + + } + + @Test(expected = IllegalArgumentException.class) + public void whenMajorValueIsNull_thanExpectIllegalArgument() { + PayaraVersion testVersion = PayaraVersion.buildVersionFromBrandingProperties(null, "192", "", "", ""); + } } \ No newline at end of file From 51c726adda5b9bea8aac38d3f5be73c8af3d4233 Mon Sep 17 00:00:00 2001 From: Cuba Date: Fri, 11 Oct 2019 10:46:21 +0100 Subject: [PATCH 8/9] Changed logic to support all version values in glassfish props --- .../payara/managed/PayaraMicroContainerConfiguration.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java index fd83b8cb..9a6a62a0 100644 --- a/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java +++ b/payara-micro/src/main/java/fish/payara/arquillian/container/payara/managed/PayaraMicroContainerConfiguration.java @@ -207,7 +207,12 @@ public void validate() throws ConfigurationException { Properties microProperties = new Properties(); microProperties.load(microJarFile.getInputStream(pomProperties)); - this.microVersion = new PayaraVersion(microProperties.getProperty("major_version") + "." + microProperties.getProperty("minor_version")); + this.microVersion = PayaraVersion.buildVersionFromBrandingProperties(microProperties.getProperty("major_version"), + microProperties.getProperty("minor_version"), + microProperties.getProperty("update_version"), + microProperties.getProperty("payara_version"), + microProperties.getProperty("payara_update_version")); + } catch (IOException e) { throw new IllegalArgumentException( "Unable to find Payara Micro Version. Please check the file is a valid Payara Micro Jar.", e); From f0ec812883872adb94ddd1c9b468a25423a04ae2 Mon Sep 17 00:00:00 2001 From: Cuba Date: Fri, 11 Oct 2019 10:58:51 +0100 Subject: [PATCH 9/9] Reverted change to isMoreRecentThan method --- .../payara/arquillian/container/payara/PayaraVersion.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java b/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java index 693c5229..71a7c60f 100644 --- a/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java +++ b/payara-common/src/main/java/fish/payara/arquillian/container/payara/PayaraVersion.java @@ -135,8 +135,8 @@ public boolean isMoreRecentThan(PayaraVersion minimum) { vPart--; } - if (vPart >= minPart) { - continue; + if (vPart > minPart) { + return true; } if (minPart > vPart) { return false;