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

[PAYARA-4150] - Micro Container Updates #27

Merged
merged 9 commits into from
Oct 15, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,59 @@ 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));
}

/**
* 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)) {
Expand Down Expand Up @@ -93,4 +145,9 @@ public boolean isMoreRecentThan(PayaraVersion minimum) {
}
return true;
}

@Override
public String toString() {
return versionString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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", "", "", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,16 +200,25 @@ public void validate() throws ConfigurationException {
if (!getMicroJarFile().isFile()) {
throw new IllegalArgumentException("Could not locate the Payara Micro Jar file " + getMicroJar());
}

try (JarFile microJarFile = new JarFile(getMicroJarFile())) {
ZipEntry pomProperties = microJarFile
.getEntry("META-INF/maven/fish.payara.micro/payara-micro-boot/pom.properties");

ZipEntry pomProperties = microJarFile.getEntry(ZIP_ENTRY_FILE_DIR);

Properties microProperties = new Properties();
microProperties.load(microJarFile.getInputStream(pomProperties));
this.microVersion = new PayaraVersion(microProperties.getProperty("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 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 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.");

Expand Down