Skip to content

Commit

Permalink
ARTEMIS-4390 Fix the upgrade-linux smoke test on Windows
Browse files Browse the repository at this point in the history
The test cannot work on Windows unless I can make the `upgrade` CLI command
respect my choice to upgrade a Linux distribution. This commit therefore adds
a new `--linux` option for the `upgrade` command, and leverages it in the
`upgrade-linux` smoke test.

* The `--cygwin` option has been preserved for backwards compatibility.
* The `IS_CYGWIN` attribute has been renamed to `IS_NIX` to reflect the change.
* The OS "recognition" method (in `InstallAbstract::run`) has been updated to
  reflect the need for enforcing *nix behavior, which is now the default if all
  other methods fail.
  • Loading branch information
jsmucr authored and clebertsuconic committed Aug 16, 2023
1 parent ab3e67a commit 999789b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ public Object run(ActionContext context) throws Exception {
writeEtc(ETC_ARTEMIS_PROFILE_CMD, etcFolder, filters, false);
}

if (!IS_WINDOWS || IS_CYGWIN) {
if (IS_NIX) {
write(BIN_ARTEMIS, filters, true);
makeExec(BIN_ARTEMIS);
write(BIN_ARTEMIS_SERVICE, filters, true);
Expand Down Expand Up @@ -847,7 +847,7 @@ public Object run(ActionContext context) throws Exception {
File service = new File(directory, BIN_ARTEMIS_SERVICE);
context.out.println("");

if (!IS_WINDOWS || IS_CYGWIN) {
if (IS_NIX) {
context.out.println("Or you can run the broker in the background using:");
context.out.println("");
context.out.println(String.format(" \"%s\" start", path(service)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class InstallAbstract extends InputAbstract {
@Option(names = "--windows", description = "Force Windows script creation. Default: based on your actual system.")
protected boolean windows = false;

@Option(names = "--cygwin", description = "Force Cygwin script creation. Default: based on your actual system.")
protected boolean cygwin = false;
@Option(names = {"--cygwin", "--linux"}, description = "Force Linux or Cygwin script creation. Default: based on your actual system.")
protected boolean nix = false;

@Option(names = "--java-options", description = "Extra Java options to be passed to the profile.")
protected List<String> javaOptions;
Expand Down Expand Up @@ -93,12 +93,29 @@ public File getHome() {
}

protected boolean IS_WINDOWS;
protected boolean IS_CYGWIN;
protected boolean IS_NIX;

public Object run(ActionContext context) throws Exception {
IS_WINDOWS = windows | System.getProperty("os.name").toLowerCase().trim().startsWith("win");
IS_CYGWIN = cygwin | IS_WINDOWS && "cygwin".equals(System.getenv("OSTYPE"));

IS_NIX = false;
IS_WINDOWS = false;
if (nix) {
IS_NIX = true;
return null;
}
if (windows) {
IS_WINDOWS = true;
return null;
}
if ("cygwin".equals(System.getenv("OSTYPE"))) {
IS_NIX = true;
return null;
}
if (System.getProperty("os.name").toLowerCase().trim().startsWith("win")) {
IS_WINDOWS = true;
return null;
}
// Fallback to *nix
IS_NIX = true;
return null;
}

Expand Down Expand Up @@ -140,7 +157,7 @@ protected void write(String source,

// and then writing out in the new target encoding.. Let's also replace \n with the values
// that is correct for the current platform.
String separator = unixTarget && IS_CYGWIN ? "\n" : System.getProperty("line.separator");
String separator = unixTarget && IS_NIX ? "\n" : System.getProperty("line.separator");
content = content.replaceAll("\\r?\\n", Matcher.quoteReplacement(separator));
ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes(encoding));
try (FileOutputStream fout = new FileOutputStream(target)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Object run(ActionContext context) throws Exception {
final File artemisScript = new File(bin, Create.ARTEMIS);

if (etc == null || etc.equals("etc")) {
if (IS_WINDOWS && !IS_CYGWIN) {
if (IS_WINDOWS) {
String pattern = "set ARTEMIS_INSTANCE_ETC=";
etcFolder = getETC(context, etcFolder, artemisCmdScript, pattern);
} else {
Expand Down Expand Up @@ -157,7 +157,7 @@ public Object run(ActionContext context) throws Exception {
"set ARTEMIS_INSTANCE=\"", "set ARTEMIS_DATA_DIR=", "set ARTEMIS_ETC_DIR=", "set ARTEMIS_OOME_DUMP=", "set ARTEMIS_INSTANCE_URI=", "set ARTEMIS_INSTANCE_ETC_URI=");
}

if (!IS_WINDOWS || IS_CYGWIN) {
if (IS_NIX) {
final File artemisScriptTmp = new File(tmp, Create.ARTEMIS);
final File artemisScriptBkp = new File(binBkp, Create.ARTEMIS);

Expand Down
7 changes: 5 additions & 2 deletions tests/smoke-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,11 @@
</goals>
<configuration>
<instance>${basedir}/target/classes/servers/linuxUpgrade</instance>
<!-- we don't pass the java memory argumnent on purpose,
as the upgrade should keep the relevant JVM arguments during the upgrade -->
<args>
<arg>--linux</arg>
<!-- we don't pass the java memory argumnent on purpose,
as the upgrade should keep the relevant JVM arguments during the upgrade -->
</args>
</configuration>
</execution>
<execution>
Expand Down

0 comments on commit 999789b

Please sign in to comment.