|
22 | 22 | import java.io.File;
|
23 | 23 | import java.io.IOException;
|
24 | 24 | import java.lang.reflect.Field;
|
| 25 | +import java.nio.file.Files; |
25 | 26 | import java.util.List;
|
26 | 27 |
|
27 | 28 | import org.apache.maven.artifact.Artifact;
|
|
43 | 44 | import org.codehaus.plexus.archiver.zip.ZipUnArchiver;
|
44 | 45 | import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
|
45 | 46 | import org.codehaus.plexus.util.FileUtils;
|
| 47 | +import org.codehaus.plexus.util.NioFiles; |
46 | 48 | import org.codehaus.plexus.util.ReflectionUtils;
|
47 | 49 | import org.codehaus.plexus.util.StringUtils;
|
48 | 50 |
|
@@ -186,6 +188,39 @@ protected void copyFile( File artifact, File destFile )
|
186 | 188 | }
|
187 | 189 | }
|
188 | 190 |
|
| 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 | + |
189 | 224 | protected void unpack( Artifact artifact, File location, String encoding )
|
190 | 225 | throws MojoExecutionException
|
191 | 226 | {
|
|
0 commit comments