Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 4bce9ef

Browse files
committed
new method linkFile(src, link) creates symlink
1 parent 8355ad6 commit 4bce9ef

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java

+35
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.File;
2323
import java.io.IOException;
2424
import java.lang.reflect.Field;
25+
import java.nio.file.Files;
2526
import java.util.List;
2627

2728
import org.apache.maven.artifact.Artifact;
@@ -43,6 +44,7 @@
4344
import org.codehaus.plexus.archiver.zip.ZipUnArchiver;
4445
import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
4546
import org.codehaus.plexus.util.FileUtils;
47+
import org.codehaus.plexus.util.NioFiles;
4648
import org.codehaus.plexus.util.ReflectionUtils;
4749
import org.codehaus.plexus.util.StringUtils;
4850

@@ -186,6 +188,39 @@ protected void copyFile( File artifact, File destFile )
186188
}
187189
}
188190

191+
/**
192+
* Does the actual linking of the file and logging.
193+
*
194+
* @param artifact represents the file to link to.
195+
* @param link file name of link.
196+
* @throws MojoExecutionException with a message if an
197+
* error occurs.
198+
*/
199+
protected void linkFile( File artifact, File link )
200+
throws MojoExecutionException
201+
{
202+
try
203+
{
204+
getLog().info( "Creating link " + link + " to "
205+
+ ( this.outputAbsoluteArtifactFilename ? artifact.getAbsolutePath() : artifact.getName() ) );
206+
207+
if ( artifact.isDirectory() )
208+
{
209+
// usual case is a future jar packaging, but there are special cases: classifier and other packaging
210+
throw new MojoExecutionException( "Artifact has not been packaged yet. When used on reactor artifact, "
211+
+ "copy should be executed after packaging: see MDEP-187." );
212+
}
213+
214+
if ( link.getParentFile() != null )
215+
Files.createDirectories( link.toPath().getParent() );
216+
NioFiles.createSymbolicLink( link, artifact);
217+
}
218+
catch ( IOException e )
219+
{
220+
throw new MojoExecutionException( "Error creating link " + link + " to " + artifact, e );
221+
}
222+
}
223+
189224
protected void unpack( Artifact artifact, File location, String encoding )
190225
throws MojoExecutionException
191226
{

0 commit comments

Comments
 (0)