mirror of https://github.com/apache/maven.git
[MNG-6777] - Remove duplicate resolveFile methods
o MavenCli.resolveFile and configuration.SettingsXmlConfigurationProcessor.resolveFile utility methods are identical. Moving them into separate ResolveFile class.
This commit is contained in:
parent
38efe8444c
commit
877fcc9cd5
|
@ -113,6 +113,7 @@ import java.util.StringTokenizer;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static org.apache.maven.cli.ResolveFile.resolveFile;
|
||||||
import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
|
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
|
// 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 );
|
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
|
// System properties handling
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,6 +50,8 @@ import org.apache.maven.settings.crypto.SettingsDecrypter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static org.apache.maven.cli.ResolveFile.resolveFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SettingsXmlConfigurationProcessor
|
* SettingsXmlConfigurationProcessor
|
||||||
*/
|
*/
|
||||||
|
@ -272,25 +274,4 @@ public class SettingsXmlConfigurationProcessor
|
||||||
}
|
}
|
||||||
return defaultLocation;
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue