mirror of https://github.com/apache/maven.git
Gather more information on settings validation
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@570805 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
50b73df74b
commit
591efea5e8
|
@ -19,26 +19,82 @@ package org.apache.maven.embedder;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
/** @author Jason van Zyl */
|
||||
import org.apache.maven.settings.Settings;
|
||||
|
||||
/**
|
||||
* @author Jason van Zyl
|
||||
*/
|
||||
public interface ConfigurationValidationResult
|
||||
{
|
||||
/**
|
||||
* Whether both user and global settings are valid
|
||||
*/
|
||||
boolean isValid();
|
||||
|
||||
/**
|
||||
* Parsed user settings, or null if there's any parse error, that can be retrieved through
|
||||
* {@link #getUserSettingsException()}
|
||||
*/
|
||||
Settings getUserSettings();
|
||||
|
||||
/**
|
||||
* Parsed global settings, or null if there's any parse error, that can be retrieved through
|
||||
* {@link #getGlobalSettingsException()}
|
||||
*/
|
||||
Settings getGlobalSettings();
|
||||
|
||||
/**
|
||||
* Any exception that happened during parsing user settings, or null if there were no errors.
|
||||
*/
|
||||
Throwable getUserSettingsException();
|
||||
|
||||
/**
|
||||
* Any exception that happened during parsing global settings, or null if there were no errors.
|
||||
*/
|
||||
Throwable getGlobalSettingsException();
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
boolean isUserSettingsFilePresent();
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
void setUserSettingsFilePresent( boolean userSettingsFilePresent );
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
boolean isUserSettingsFileParses();
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
void setUserSettingsFileParses( boolean userSettingsFileParses );
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
boolean isGlobalSettingsFilePresent();
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
void setGlobalSettingsFilePresent( boolean globalSettingsFilePresent );
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
boolean isGlobalSettingsFileParses();
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
void setGlobalSettingsFileParses( boolean globalSettingsFileParses );
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
void display();
|
||||
}
|
||||
|
|
|
@ -19,69 +19,109 @@ package org.apache.maven.embedder;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
/** @author Jason van Zyl */
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import org.apache.maven.settings.Settings;
|
||||
|
||||
/**
|
||||
* @author Jason van Zyl
|
||||
*/
|
||||
public class DefaultConfigurationValidationResult
|
||||
implements ConfigurationValidationResult
|
||||
{
|
||||
private boolean userSettingsFilePresent = true;
|
||||
private Throwable userSettingsException;
|
||||
|
||||
private boolean userSettingsFileParses = true;
|
||||
private Throwable globalSettingsException;
|
||||
|
||||
private boolean globalSettingsFilePresent = true;
|
||||
|
||||
private boolean globalSettingsFileParses = true;
|
||||
private Settings userSettings, globalSettings;
|
||||
|
||||
public boolean isValid()
|
||||
{
|
||||
return userSettingsFilePresent && userSettingsFileParses && globalSettingsFilePresent &&
|
||||
globalSettingsFileParses;
|
||||
return ( getUserSettings() != null ) && ( getGlobalSettings() != null );
|
||||
}
|
||||
|
||||
public boolean isUserSettingsFilePresent()
|
||||
public Throwable getUserSettingsException()
|
||||
{
|
||||
return userSettingsFilePresent;
|
||||
return userSettingsException;
|
||||
}
|
||||
|
||||
public void setUserSettingsFilePresent( boolean userSettingsFilePresent )
|
||||
public void setUserSettingsException( Throwable e )
|
||||
{
|
||||
this.userSettingsFilePresent = userSettingsFilePresent;
|
||||
this.userSettingsException = e;
|
||||
}
|
||||
|
||||
public boolean isUserSettingsFileParses()
|
||||
public Throwable getGlobalSettingsException()
|
||||
{
|
||||
return userSettingsFileParses;
|
||||
return globalSettingsException;
|
||||
}
|
||||
|
||||
public void setUserSettingsFileParses( boolean userSettingsFileParses )
|
||||
public void setGlobalSettingsException( Throwable e )
|
||||
{
|
||||
this.userSettingsFileParses = userSettingsFileParses;
|
||||
this.globalSettingsException = e;
|
||||
}
|
||||
|
||||
public boolean isGlobalSettingsFilePresent()
|
||||
public Settings getUserSettings()
|
||||
{
|
||||
return globalSettingsFilePresent;
|
||||
return userSettings;
|
||||
}
|
||||
|
||||
public void setGlobalSettingsFilePresent( boolean globalSettingsFilePresent )
|
||||
public void setUserSettings( Settings settings )
|
||||
{
|
||||
this.globalSettingsFilePresent = globalSettingsFilePresent;
|
||||
this.userSettings = settings;
|
||||
}
|
||||
|
||||
public Settings getGlobalSettings()
|
||||
{
|
||||
return globalSettings;
|
||||
}
|
||||
|
||||
public void setGlobalSettings( Settings globalSettings )
|
||||
{
|
||||
this.globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
public boolean isGlobalSettingsFileParses()
|
||||
{
|
||||
return globalSettingsFileParses;
|
||||
return getGlobalSettings() != null;
|
||||
}
|
||||
|
||||
public boolean isGlobalSettingsFilePresent()
|
||||
{
|
||||
return getGlobalSettingsException() instanceof FileNotFoundException;
|
||||
}
|
||||
|
||||
public boolean isUserSettingsFileParses()
|
||||
{
|
||||
return getUserSettings() != null;
|
||||
}
|
||||
|
||||
public boolean isUserSettingsFilePresent()
|
||||
{
|
||||
return getUserSettingsException() instanceof FileNotFoundException;
|
||||
}
|
||||
|
||||
public void setGlobalSettingsFileParses( boolean globalSettingsFileParses )
|
||||
{
|
||||
this.globalSettingsFileParses = globalSettingsFileParses;
|
||||
// ignored
|
||||
}
|
||||
|
||||
public void setGlobalSettingsFilePresent( boolean globalSettingsFilePresent )
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
public void setUserSettingsFileParses( boolean userSettingsFileParses )
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
public void setUserSettingsFilePresent( boolean userSettingsFilePresent )
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
public void display()
|
||||
{
|
||||
System.out.println( "userSettingsFilePresent = " + userSettingsFilePresent );
|
||||
System.out.println( "globalSettingsFileParses = " + globalSettingsFileParses );
|
||||
System.out.println( "globalSettingsFilePresent = " + globalSettingsFilePresent );
|
||||
System.out.println( "globalSettingsFileParses = " + globalSettingsFileParses );
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@ import org.jdom.Element;
|
|||
import org.jdom.output.Format;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
@ -729,9 +728,9 @@ public class MavenEmbedder
|
|||
|
||||
public static ConfigurationValidationResult validateConfiguration( Configuration configuration )
|
||||
{
|
||||
ConfigurationValidationResult result = new DefaultConfigurationValidationResult();
|
||||
DefaultConfigurationValidationResult result = new DefaultConfigurationValidationResult();
|
||||
|
||||
Reader fileReader;
|
||||
Reader fileReader = null;
|
||||
|
||||
// User settings
|
||||
|
||||
|
@ -741,19 +740,26 @@ public class MavenEmbedder
|
|||
{
|
||||
fileReader = new FileReader( configuration.getUserSettingsFile() );
|
||||
|
||||
new SettingsXpp3Reader().read( fileReader );
|
||||
}
|
||||
catch ( FileNotFoundException e )
|
||||
{
|
||||
result.setUserSettingsFilePresent( false );
|
||||
result.setUserSettings( new SettingsXpp3Reader().read( fileReader ) );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
result.setUserSettingsFileParses( false );
|
||||
result.setUserSettingsException( e );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
result.setUserSettingsFileParses( false );
|
||||
result.setUserSettingsException( e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
fileReader.close();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -765,19 +771,26 @@ public class MavenEmbedder
|
|||
{
|
||||
fileReader = new FileReader( configuration.getGlobalSettingsFile() );
|
||||
|
||||
new SettingsXpp3Reader().read( fileReader );
|
||||
}
|
||||
catch ( FileNotFoundException e )
|
||||
{
|
||||
result.setGlobalSettingsFilePresent( false );
|
||||
result.setGlobalSettings( new SettingsXpp3Reader().read( fileReader ) );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
result.setGlobalSettingsFileParses( false );
|
||||
result.setGlobalSettingsException( e );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
result.setGlobalSettingsFileParses( false );
|
||||
result.setGlobalSettingsException( e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
fileReader.close();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue