This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 2766d24fda [MNG-8573] Introduce OS Service (#2099)
2766d24fda is described below

commit 2766d24fda4685db1990a342b4a0e3e123144017
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Mon Feb 10 14:12:18 2025 +0000

    [MNG-8573] Introduce OS Service (#2099)
    
    And move the OS static helper to util, is not profile specific.
    This service is meant primarily for plugins and extensions.
    Is intentionally minimalistic, in case of new requirements, we can extend 
it.
    
    ---
    
    https://issues.apache.org/jira/browse/MNG-8573
---
 .../org/apache/maven/api/services/OsService.java   | 107 +++++++++++++++++++++
 .../apache/maven/impl/model/DefaultOsService.java  |  58 +++++++++++
 .../profile/OperatingSystemProfileActivator.java   |   1 +
 .../maven/impl/{model/profile => util}/Os.java     |  13 ++-
 4 files changed, 176 insertions(+), 3 deletions(-)

diff --git 
a/api/maven-api-core/src/main/java/org/apache/maven/api/services/OsService.java 
b/api/maven-api-core/src/main/java/org/apache/maven/api/services/OsService.java
new file mode 100644
index 0000000000..a07b1eabd9
--- /dev/null
+++ 
b/api/maven-api-core/src/main/java/org/apache/maven/api/services/OsService.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.api.services;
+
+import org.apache.maven.api.Service;
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Nonnull;
+
+/**
+ * Service for detecting and providing information about the operating system 
(OS)
+ * on which the application is running.
+ * <p>
+ * This service provides a platform-independent way to:
+ * <ul>
+ * <li>Query basic OS information like name, architecture, and version</li>
+ * <li>Determine the OS family (e.g., Windows, Unix, Mac)</li>
+ * <li>Check if the current OS is Windows-based</li>
+ * </ul>
+ * <p>
+ * The service implementation uses system properties to detect OS 
characteristics:
+ * <ul>
+ * <li>os.name: The operating system name</li>
+ * <li>os.arch: The operating system architecture</li>
+ * <li>os.version: The operating system version</li>
+ * </ul>
+ * <p>
+ * Supported OS families include:
+ * <ul>
+ * <li>windows: All Windows variants</li>
+ * <li>win9x: Windows 95, 98, ME, CE</li>
+ * <li>winnt: Windows NT variants</li>
+ * <li>unix: Unix-like systems (including Linux)</li>
+ * <li>mac: macOS (including Darwin)</li>
+ * <li>os/2: OS/2 variants</li>
+ * <li>netware: Novell NetWare</li>
+ * <li>dos: DOS variants</li>
+ * <li>tandem: Tandem systems</li>
+ * <li>openvms: OpenVMS</li>
+ * <li>z/os: z/OS and OS/390</li>
+ * <li>os/400: OS/400</li>
+ * </ul>
+ *
+ * @since 4.0.0
+ */
+@Experimental
+public interface OsService extends Service {
+    /**
+     * Returns the OS full name as reported by the system property "os.name".
+     * The value is converted to lowercase for consistency.
+     *
+     * @return the operating system name (never null)
+     */
+    @Nonnull
+    String name();
+
+    /**
+     * Returns the OS architecture as reported by the system property 
"os.arch".
+     * The value is converted to lowercase for consistency.
+     *
+     * @return the operating system architecture (never null)
+     */
+    @Nonnull
+    String arch();
+
+    /**
+     * Returns the OS version as reported by the system property "os.version".
+     * The value is converted to lowercase for consistency.
+     *
+     * @return the operating system version (never null)
+     */
+    @Nonnull
+    String version();
+
+    /**
+     * Returns the OS family name based on OS detection rules.
+     * This categorizes the OS into one of the supported families
+     * (e.g., "windows", "unix", "mac").
+     *
+     * @return the operating system family name (never null)
+     */
+    @Nonnull
+    String family();
+
+    /**
+     * Checks if the current operating system belongs to the Windows family.
+     * This includes all Windows variants (95, 98, ME, NT, 2000, XP, Vista, 7, 
8, 10, 11).
+     *
+     * @return true if the current OS is any Windows variant, false otherwise
+     */
+    boolean isWindows();
+}
diff --git 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultOsService.java
 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultOsService.java
new file mode 100644
index 0000000000..eeb66d1360
--- /dev/null
+++ 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultOsService.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.impl.model;
+
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.services.OsService;
+import org.apache.maven.impl.util.Os;
+
+@Named
+@Singleton
+public class DefaultOsService implements OsService {
+    @Nonnull
+    @Override
+    public String name() {
+        return Os.OS_NAME;
+    }
+
+    @Nonnull
+    @Override
+    public String arch() {
+        return Os.OS_ARCH;
+    }
+
+    @Nonnull
+    @Override
+    public String version() {
+        return Os.OS_VERSION;
+    }
+
+    @Nonnull
+    @Override
+    public String family() {
+        return Os.OS_FAMILY;
+    }
+
+    @Override
+    public boolean isWindows() {
+        return Os.IS_WINDOWS;
+    }
+}
diff --git 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivator.java
 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivator.java
index 3aaa48bbcb..57734509bd 100644
--- 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivator.java
+++ 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivator.java
@@ -28,6 +28,7 @@
 import org.apache.maven.api.services.ModelProblemCollector;
 import org.apache.maven.api.services.model.ProfileActivationContext;
 import org.apache.maven.api.services.model.ProfileActivator;
+import org.apache.maven.impl.util.Os;
 
 /**
  * Determines profile activation based on the operating system of the current 
runtime platform.
diff --git 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/Os.java 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/util/Os.java
similarity index 95%
rename from 
impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/Os.java
rename to impl/maven-impl/src/main/java/org/apache/maven/impl/util/Os.java
index e62c22cadf..f7d1409678 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/Os.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/util/Os.java
@@ -16,8 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.maven.impl.model.profile;
+package org.apache.maven.impl.util;
 
+import java.io.File;
 import java.util.Locale;
 import java.util.stream.Stream;
 
@@ -116,6 +117,11 @@ public class Os {
      */
     private static final String FAMILY_OS400 = "os/400";
 
+    /**
+     * Unrecognized OS family. {@value}
+     */
+    private static final String FAMILY_UNKNOWN = "unknown";
+
     /**
      * OpenJDK is reported to call MacOS X "Darwin"
      *
@@ -127,7 +133,7 @@ public class Os {
     /**
      * The path separator.
      */
-    private static final String PATH_SEP = 
System.getProperty("path.separator");
+    private static final String PATH_SEP = File.pathSeparator;
 
     static {
         // Those two public constants are initialized here, as they need all 
the private constants
@@ -212,7 +218,8 @@ private static String getOsFamily() {
                         FAMILY_UNIX,
                         FAMILY_WIN9X,
                         FAMILY_WINDOWS,
-                        FAMILY_ZOS)
+                        FAMILY_ZOS,
+                        FAMILY_UNKNOWN)
                 .filter(Os::isFamily)
                 .findFirst()
                 .orElse(null);

Reply via email to