cleaned up the setFiles interface

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@607555 13f79535-47bb-0310-9956-ffa450edef68
master
Brian E Fox 2007-12-30 16:36:34 +00:00
parent 4909a36c81
commit b358e1ae93
2 changed files with 62 additions and 7 deletions

View File

@ -122,30 +122,86 @@ public class ArtifactStubFactory
Artifact artifact = Artifact artifact =
new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier, ah, optional ); new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier, ah, optional );
//i have no idea why this needs to be done manually when isSnapshot is able to figure it out. // i have no idea why this needs to be done manually when isSnapshot is able to figure it out.
artifact.setRelease( !artifact.isSnapshot() ); artifact.setRelease( !artifact.isSnapshot() );
if ( createFiles ) if ( createFiles )
{ {
setArtifactFile( artifact ); setArtifactFile( artifact,this.workingDir,this.srcFile,this.createUnpackableFile );
} }
return artifact; return artifact;
} }
/**
* Creates a new empty file and attaches it to the artifact.
*
* @param artifact to attach the file to.
* @param workingDir where to locate the new file
* @throws IOException
*/
public void setArtifactFile( Artifact artifact, File workingDir )
throws IOException
{
setArtifactFile( artifact, workingDir, null, false );
}
/**
* Copyies the srcFile to the workingDir and then attaches it to the artifact. If srcFile is null, a new empty file
* will be created.
*
* @param artifact to attach
* @param workingDir where to copy the srcFile.
* @param srcFile file to be attached.
* @throws IOException
*/
public void setArtifactFile( Artifact artifact, File workingDir, File srcFile )
throws IOException
{
setArtifactFile( artifact, workingDir, srcFile, false );
}
/**
* Creates an unpackable file (zip,jar etc) containing an empty file.
*
* @param artifact to attach
* @param workingDir where to create the file.
* @throws IOException
*/
public void setUnpackableArtifactFile( Artifact artifact, File workingDir )
throws IOException
{
setArtifactFile( artifact, workingDir, null, true );
}
/**
* Creates an unpackable file (zip,jar etc) containing the srcFile. If srcFile is null, a new empty file will be
* created.
*
* @param artifact to attach
* @param workingDir where to create the file.
* @throws IOException
*/
public void setUnpackableArtifactFile( Artifact artifact, File workingDir, File srcFile )
throws IOException
{
setArtifactFile( artifact, workingDir, srcFile, true );
}
/* /*
* Creates a file that can be copied or unpacked based on the passed in artifact * Creates a file that can be copied or unpacked based on the passed in artifact
*/ */
public void setArtifactFile( Artifact artifact ) private void setArtifactFile( Artifact artifact, File workingDir, File srcFile, boolean createUnpackableFile )
throws IOException throws IOException
{ {
if ( this.workingDir == null ) if ( workingDir == null )
{ {
throw new IllegalArgumentException( "The workingDir must be set if createFiles is true." ); throw new IllegalArgumentException(
"The workingDir must be set if trying to create an actual artifact file." );
} }
String fileName = getFormattedFileName( artifact, false ); String fileName = getFormattedFileName( artifact, false );
File theFile = new File( this.workingDir, fileName ); File theFile = new File( workingDir, fileName );
theFile.getParentFile().mkdirs(); theFile.getParentFile().mkdirs();
if ( srcFile == null ) if ( srcFile == null )

View File

@ -21,6 +21,5 @@ public class ArtifactStubFactoryTest
{ {
ArtifactStubFactory factory = new ArtifactStubFactory(); ArtifactStubFactory factory = new ArtifactStubFactory();
assertFalse(factory.isCreateFiles()); assertFalse(factory.isCreateFiles());
factory.getReleaseArtifact();
} }
} }