maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From khmarba...@apache.org
Subject [maven] 01/01: [MNG-6777] - Remove duplicate resolveFile methods o MavenCli.resolveFile and configuration.SettingsXmlConfigurationProcessor.resolveFile utility methods are identical. Moving them into separate ResolveFile class.
Date Thu, 10 Oct 2019 17:54:42 GMT
This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a commit to branch MNG-6777
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 877fcc9cd585bd89b42911a07e65ebefe1d83718
Author: Anatoly Zaretsky <anatoly.zaretsky@gmail.com>
AuthorDate: Thu Oct 10 03:15:22 2019 +0300

    [MNG-6777] - Remove duplicate resolveFile methods
     o MavenCli.resolveFile and
       configuration.SettingsXmlConfigurationProcessor.resolveFile
       utility methods are identical. Moving them into separate
       ResolveFile class.
---
 .../main/java/org/apache/maven/cli/MavenCli.java   | 22 +---------
 .../java/org/apache/maven/cli/ResolveFile.java     | 49 ++++++++++++++++++++++
 .../SettingsXmlConfigurationProcessor.java         | 23 +---------
 3 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index d210183..7d17e18 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -113,6 +113,7 @@ import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static org.apache.maven.cli.ResolveFile.resolveFile;
 import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
 
 // TODO push all common bits back to plexus cli and prepare for transition to Guice. We don't
need 50 ways to make CLIs
@@ -1612,27 +1613,6 @@ public class MavenCli
         return (int) ( Float.valueOf( threadConfiguration.replace( "C", "" ) ) * procs );
     }
 
-    static File resolveFile( File file, String workingDirectory )
-    {
-        if ( file == null )
-        {
-            return null;
-        }
-        else if ( file.isAbsolute() )
-        {
-            return file;
-        }
-        else if ( file.getPath().startsWith( File.separator ) )
-        {
-            // drive-relative Windows path
-            return file.getAbsoluteFile();
-        }
-        else
-        {
-            return new File( workingDirectory, file.getPath() ).getAbsoluteFile();
-        }
-    }
-
     // ----------------------------------------------------------------------
     // System properties handling
     // ----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/ResolveFile.java b/maven-embedder/src/main/java/org/apache/maven/cli/ResolveFile.java
new file mode 100644
index 0000000..8622ce3
--- /dev/null
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/ResolveFile.java
@@ -0,0 +1,49 @@
+package org.apache.maven.cli;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+/**
+ * Resolve relative file path against the given base directory
+ */
+public class ResolveFile
+{
+    public static File resolveFile( File file, String baseDirectory )
+    {
+        if ( file == null )
+        {
+            return null;
+        }
+        else if ( file.isAbsolute() )
+        {
+            return file;
+        }
+        else if ( file.getPath().startsWith( File.separator ) )
+        {
+            // drive-relative Windows path
+            return file.getAbsoluteFile();
+        }
+        else
+        {
+            return new File( baseDirectory, file.getPath() ).getAbsoluteFile();
+        }
+    }
+}
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java
b/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java
index 0a862c4..5c5ce4e 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java
@@ -50,6 +50,8 @@ import org.apache.maven.settings.crypto.SettingsDecrypter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.maven.cli.ResolveFile.resolveFile;
+
 /**
  * SettingsXmlConfigurationProcessor
  */
@@ -272,25 +274,4 @@ public class SettingsXmlConfigurationProcessor
         }
         return defaultLocation;
     }
-
-    static File resolveFile( File file, String workingDirectory )
-    {
-        if ( file == null )
-        {
-            return null;
-        }
-        else if ( file.isAbsolute() )
-        {
-            return file;
-        }
-        else if ( file.getPath().startsWith( File.separator ) )
-        {
-            // drive-relative Windows path
-            return file.getAbsoluteFile();
-        }
-        else
-        {
-            return new File( workingDirectory, file.getPath() ).getAbsoluteFile();
-        }
-    }
 }


Mime
View raw message