Let mvnd -v show os name and arch

This commit is contained in:
Peter Palaga
2020-08-15 08:48:39 +02:00
parent d335f0db37
commit 28d0765667
9 changed files with 51 additions and 9 deletions

View File

@@ -123,7 +123,12 @@ public class DefaultClient implements Client {
// Print version if needed
if (version || showVersion || debug) {
final String nativeSuffix = Environment.isNative() ? " (native)" : "";
final String v = Ansi.ansi().bold().a("Maven Daemon " + buildProperties.getVersion() + nativeSuffix)
final String v = Ansi.ansi().bold().a(
"Maven Daemon "
+ buildProperties.getVersion()
+ "-" + buildProperties.getOsName()
+ "-" + buildProperties.getOsArch()
+ nativeSuffix)
.reset().toString();
output.accept(v);
/*

View File

@@ -23,6 +23,7 @@ import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Locale;
import java.util.Map;
import java.util.Scanner;
import org.slf4j.Logger;
@@ -127,7 +128,7 @@ public class ScriptUtils {
private static final boolean windows;
static {
windows = System.getProperty("os.name").toLowerCase().contains("windows");
windows = System.getProperty("os.name").toLowerCase(Locale.ROOT).startsWith("windows");
}
public static boolean isWindows() {

View File

@@ -34,16 +34,31 @@ public class BuildProperties {
} catch (IOException e) {
throw new RuntimeException("Could not read build.properties");
}
return new BuildProperties(buildProperties.getProperty("version"));
return new BuildProperties(
buildProperties.getProperty("version"),
buildProperties.getProperty("os.detected.name"),
buildProperties.getProperty("os.detected.arch"));
}
private final String version;
private final String osName;
private final String osArch;
public BuildProperties(String version) {
public BuildProperties(String version, String os, String arch) {
this.version = version;
this.osName = os;
this.osArch = arch;
}
public String getVersion() {
return version;
}
public String getOsName() {
return osName;
}
public String getOsArch() {
return osArch;
}
}

View File

@@ -21,3 +21,5 @@ version=${project.version}
distributionId=${distributionId}
distributionShortName=${distributionShortName}
distributionName=${distributionName}
os.detected.name=${os.detected.name}
os.detected.arch=${os.detected.arch}

View File

@@ -36,6 +36,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
@@ -479,7 +480,8 @@ public class CliPluginRealmCache
};
public CliPluginRealmCache() {
this.watcher = System.getProperty("os.name").toLowerCase().contains("mac")
final String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT);
this.watcher = osName.startsWith("osx") || osName.startsWith("mac os x")
? new TimestampedRecordValidator()
: new MultiWatcher();
}

View File

@@ -87,6 +87,8 @@
<systemPropertyVariables>
<project.version>${project.version}</project.version>
<mvnd.home>${mvnd.home}</mvnd.home>
<os.detected.name>${os.detected.name}</os.detected.name>
<os.detected.arch>${os.detected.arch}</os.detected.arch>
</systemPropertyVariables>
</configuration>
</plugin>
@@ -111,6 +113,8 @@
<systemPropertyVariables>
<project.version>${project.version}</project.version>
<mvnd.home>${mvnd.home}</mvnd.home>
<os.detected.name>${os.detected.name}</os.detected.name>
<os.detected.arch>${os.detected.arch}</os.detected.arch>
</systemPropertyVariables>
</configuration>
</execution>

View File

@@ -48,7 +48,11 @@ public class VersionNativeIT {
Assertions.assertThat(logMessage.getAllValues())
.is(new MatchInOrderAmongOthers<>(
"\\QMaven Daemon " + System.getProperty("project.version") + "\\E",
"\\QMaven Daemon "
+ System.getProperty("project.version")
+ "-" + System.getProperty("os.detected.name")
+ "-" + System.getProperty("os.detected.arch")
+ "\\E",
"\\QMaven home: " + layout.mavenHome() + "\\E"));
}
}

View File

@@ -23,6 +23,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Stream;
import org.jboss.fuse.mvnd.client.Client;
@@ -98,7 +99,7 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
} else if (f.getType() == Client.class) {
if (resource.isNative) {
final Path mvndNativeExecutablePath = resource.layout.mavenHome().resolve(
System.getProperty("os.name").toLowerCase().contains("windows")
System.getProperty("os.name").toLowerCase(Locale.ROOT).startsWith("windows")
? "bin/mvnd.exe"
: "bin/mvnd")
.toAbsolutePath().normalize();

10
pom.xml
View File

@@ -378,6 +378,8 @@ limitations under the License.</inlineHeader>
</goals>
<configuration>
<source>
// Naming conventions coined by GraalVM
// https://github.com/graalvm/graalvm-ce-builds/releases/
String osName = System.getProperty('os.name').toLowerCase(Locale.ROOT)
if (osName.startsWith('windows')) {
project.properties['os.detected.name'] = 'windows'
@@ -386,7 +388,13 @@ limitations under the License.</inlineHeader>
} else if (osName.startsWith('osx') || osName.startsWith('mac os x')) {
project.properties['os.detected.name'] = 'darwin'
} else {
throw new IllegalStateException('Unknown OS ' + osName);
project.properties['os.detected.name'] = osName
}
String osArch = System.getProperty('os.arch').toLowerCase(Locale.ROOT)
if (osArch.equals('amd64') || osArch.equals('x86_64')) {
project.properties['os.detected.arch'] = 'amd64'
} else {
project.properties['os.detected.arch'] = osArch
}
</source>
</configuration>