diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/ConfigurationValidationResult.java b/maven-embedder/src/main/java/org/apache/maven/embedder/ConfigurationValidationResult.java index 30d18c8a81..8468238f14 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/ConfigurationValidationResult.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/ConfigurationValidationResult.java @@ -32,13 +32,13 @@ public interface ConfigurationValidationResult boolean isValid(); /** - * Parsed user settings, or null if there's any parse error, that can be retrieved through + * Parsed user settings. If there's any parse error, it can be retrieved through * {@link #getUserSettingsException()} */ Settings getUserSettings(); /** - * Parsed global settings, or null if there's any parse error, that can be retrieved through + * Parsed global settings. If there's any parse error, it can be retrieved through * {@link #getGlobalSettingsException()} */ Settings getGlobalSettings(); diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultConfigurationValidationResult.java b/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultConfigurationValidationResult.java index 4fa272bc50..99d6fdd389 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultConfigurationValidationResult.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultConfigurationValidationResult.java @@ -37,7 +37,7 @@ public class DefaultConfigurationValidationResult public boolean isValid() { - return ( getUserSettings() != null ) && ( getGlobalSettings() != null ); + return ( getUserSettingsException() == null ) && ( getGlobalSettingsException() == null ); } public Throwable getUserSettingsException() @@ -87,7 +87,7 @@ public class DefaultConfigurationValidationResult public boolean isGlobalSettingsFilePresent() { - return getGlobalSettingsException() instanceof FileNotFoundException; + return isSettingsFilePresent( getGlobalSettings(), getGlobalSettingsException() ); } public boolean isUserSettingsFileParses() @@ -97,7 +97,7 @@ public class DefaultConfigurationValidationResult public boolean isUserSettingsFilePresent() { - return getUserSettingsException() instanceof FileNotFoundException; + return isSettingsFilePresent( getUserSettings(), getUserSettingsException() ); } public void setGlobalSettingsFileParses( boolean globalSettingsFileParses ) @@ -124,4 +124,9 @@ public class DefaultConfigurationValidationResult { // ignored } + + private boolean isSettingsFilePresent( Settings settings, Throwable e ) + { + return ( settings != null ) || ( ( e != null ) && !( e instanceof FileNotFoundException ) ); + } } diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index 6873b7b692..e92efc4222 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -754,7 +754,10 @@ public class MavenEmbedder { try { - fileReader.close(); + if ( fileReader != null ) + { + fileReader.close(); + } } catch ( IOException e ) { diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/ValidateConfigurationTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/ValidateConfigurationTest.java index 9e079c97b9..b8bfd61c99 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/ValidateConfigurationTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/ValidateConfigurationTest.java @@ -60,7 +60,7 @@ public class ValidateConfigurationTest File global = new File( getBasedir(), "src/test/resources/settings/valid-settings.xml" ); Configuration configuration = new DefaultConfiguration() - .setUserSettingsFile( global ); + .setGlobalSettingsFile( global ); ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );