package com.perforce.p4maven.dev;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Set;
import java.util.TreeSet;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
/**
* Add/update the contents of $P4IGNORE files.
*/
@Mojo( name = "configure-p4ignore", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.INITIALIZE )
public class ConfigureP4IgnoreMojo
extends AbstractP4MavenDevMojo
{
@Parameter( property = "p4ignore", readonly = true, required = false, defaultValue = "${env.P4IGNORE}" )
private String p4IgnoreName;
public void execute()
throws MojoExecutionException, MojoFailureException
{
if ( this.p4IgnoreName == null )
{
throw new MojoExecutionException( "P4IGNORE environment variable is not set" );
}
BufferedWriter bw = null;
try
{
File ignoreFile = new File( project.getBasedir(), this.p4IgnoreName );
Set<String> ignoreList = getExistingList( ignoreFile );
ignoreList.add( ".*" );
ignoreList.add( "target" );
if ( !p4IgnoreName.startsWith( "." ) )
{
ignoreList.add( p4IgnoreName );
}
bw = new BufferedWriter( new FileWriter( ignoreFile ) );
for ( String line : ignoreList )
{
bw.write( line );
bw.newLine();
}
bw.flush();
}
catch ( IOException e )
{
throw new MojoExecutionException( e.getMessage() );
}
finally
{
IOUtil.close( bw );
}
}
// read existing content and convert it into a set
private Set<String> getExistingList( File file )
throws IOException
{
Set<String> tokens = new TreeSet<String>();
if ( file.exists() )
{
tokens.addAll( FileUtils.loadFile( file ) );
}
return tokens;
}
}
# |
Change |
User |
Description |
Committed |
|
#1
|
10055 |
Matt Attaway |
Pull over numerous changes from @dantran's branch. |
|
|
//guest/dantran/p4maven/p4maven-dev/src/main/java/com/perforce/p4maven/dev/ConfigureP4IgnoreMojo.java |
#2
|
9663 |
dantran |
source format |
|
|
#1
|
9659 |
dantran |
add p4maven-dev to help with Eclipse IDE development environemnt |
|
|