Skip to content

Commit

Permalink
Add logging & set comment in written properties file
Browse files Browse the repository at this point in the history
Signed-off-by: Alin Dreghiciu <adreghiciu@gmail.com>
  • Loading branch information
adreghiciu committed Nov 13, 2012
1 parent 7da9ef1 commit 7eddd9d
Showing 1 changed file with 41 additions and 24 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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 )
{
Expand All @@ -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<Object, Object> entry : properties.entrySet() )
{
getLog().debug( entry.toString() );
}
}
}

}

0 comments on commit 7eddd9d

Please sign in to comment.