Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First proposal to resolve issue #51. #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
Expand Down Expand Up @@ -97,6 +98,15 @@ public abstract class AbstractAppAssemblerMojo
@Parameter( defaultValue = "false" )
protected boolean preClean;

/**
* If set to {@code true}, overwrites existing dependencies in the repository. If set to {@code false},
* it will check if the dependency is already present in the repository prior copying to it.
*
* @since 2.0.1
*/
@Parameter( defaultValue = "true" )
protected boolean overwriteDependencies;

// -----------------------------------------------------------------------
// Read-only parameters
// -----------------------------------------------------------------------
Expand Down Expand Up @@ -169,10 +179,11 @@ protected ArtifactRepositoryLayout getArtifactRepositoryLayout()
* @param artifact The artifact to install.
* @param artifactRepository The repository where to install.
* @param useTimestampInSnapshotFileName Using timestamp for SNAPSHOT's.
* @param overwriteExistingArtifacts Set to {@code false} to avoid overwriting existing artifacts.
* @throws MojoExecutionException
*/
protected void installArtifact( Artifact artifact, ArtifactRepository artifactRepository,
boolean useTimestampInSnapshotFileName )
boolean useTimestampInSnapshotFileName, boolean overwriteExistingArtifacts )
throws MojoExecutionException
{
if ( artifact != null && artifact.getFile() != null )
Expand Down Expand Up @@ -206,13 +217,28 @@ protected void installArtifact( Artifact artifact, ArtifactRepository artifactRe
String fileName = MappingUtils.evaluateFileNameMapping( outputFileNameMapping, artifact );
destination = new File( destination.getParent(), fileName );
}
// Sometimes target/classes is in the artifact list and copyFile() would fail.
// Need to ignore this condition
FileUtils.copyFile( source, destination );
}

getLog().info( "Installing artifact " + source.getPath() + " to " + destination );
if ( overwriteExistingArtifacts )
{
// Sometimes target/classes is in the artifact list and copyFile() would fail.
// Need to ignore this condition
FileUtils.copyFile( source, destination );
getLog().info( "Installing artifact " + source.getPath() + " to " + destination );
}
else
{
if ( !Files.exists( destination.toPath() ) )
{
FileUtils.copyFile( source, destination );
}
else
{
destination.setLastModified(System.currentTimeMillis()); //'touches' the file
}

getLog().info( "Skiped installing artifact " + source.getPath() + " to " + destination + ". File already exists.");
}
}
}
catch ( IOException e )
{
Expand All @@ -235,7 +261,7 @@ protected void installArtifact( Artifact artifact, ArtifactRepository artifactRe
protected void installArtifact( Artifact artifact, ArtifactRepository artifactRepository )
throws MojoExecutionException
{
installArtifact( artifact, artifactRepository, true );
installArtifact( artifact, artifactRepository, true, true );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ protected void installDependencies( final String outputDirectory, final String r

for ( Artifact artifact : artifacts )
{
installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName );
installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName, true );
}

// install the project's artifact in the new repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void execute()
// TODO: merge with the artifacts below so no duplicate versions included
for ( Artifact artifact : artifacts )
{
installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName );
installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName, overwriteDependencies );
}

if ( installBooterArtifacts )
Expand Down Expand Up @@ -189,7 +189,7 @@ private void installBooterArtifacts( ArtifactRepository artifactRepository )
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
installArtifact( a, artifactRepository, this.useTimestampInSnapshotFileName );
installArtifact( a, artifactRepository, this.useTimestampInSnapshotFileName, true );
}
}
catch ( ArtifactResolutionException e )
Expand Down