diff --git a/plugin/src/main/java/org/sonatype/sisu/maven/bridge/plugin/ExportMojo.java b/plugin/src/main/java/org/sonatype/sisu/maven/bridge/plugin/ExportMojo.java index 1ab11c7..f443163 100644 --- a/plugin/src/main/java/org/sonatype/sisu/maven/bridge/plugin/ExportMojo.java +++ b/plugin/src/main/java/org/sonatype/sisu/maven/bridge/plugin/ExportMojo.java @@ -17,6 +17,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Map; import java.util.Properties; import org.apache.maven.execution.MavenSession; @@ -84,30 +85,6 @@ public void execute() writeProperties( properties ); } - private void writeProperties( final Properties properties ) - throws MojoFailureException - { - FileOutputStream out = null; - try - { - propertiesFile.getParentFile().mkdirs(); - propertiesFile.createNewFile(); - - out = new FileOutputStream( propertiesFile ); - properties.store( out, null ); - } - catch ( IOException e ) - { - throw new MojoFailureException( - "Could not write provided properties file '" + propertiesFile.getAbsolutePath() + "'", e - ); - } - finally - { - Closeables.closeQuietly( out ); - } - } - private void setIfNotPresent( final Properties properties, final String key, final String value ) { // TODO ? shall we not override exiting properties? because if "mvn clean" is not called second run will not overwrite @@ -134,6 +111,8 @@ private Properties eventuallyReadExistingProperties() { in = new FileInputStream( propertiesFile ); properties.load( in ); + getLog().debug( "Using existing properties file '" + propertiesFile.getAbsolutePath() + "'" ); + logProperties( properties ); } catch ( final FileNotFoundException e ) { @@ -152,4 +131,42 @@ private Properties eventuallyReadExistingProperties() return properties; } + private void writeProperties( final Properties properties ) + throws MojoFailureException + { + FileOutputStream out = null; + try + { + propertiesFile.getParentFile().mkdirs(); + propertiesFile.createNewFile(); + + out = new FileOutputStream( propertiesFile ); + properties.store( out, "Parts generated by sisu-maven-bridge-plugin" ); + getLog().info( "Properties exported to file '" + propertiesFile.getAbsolutePath() + "'" ); + logProperties( properties ); + } + catch ( IOException e ) + { + throw new MojoFailureException( + "Could not write provided properties file '" + propertiesFile.getAbsolutePath() + "'", e + ); + } + finally + { + Closeables.closeQuietly( out ); + } + } + + private void logProperties( final Properties properties ) + { + if ( getLog().isDebugEnabled() && !properties.isEmpty() ) + { + getLog().debug( "" ); + for ( Map.Entry entry : properties.entrySet() ) + { + getLog().debug( entry.toString() ); + } + } + } + }