1 package com.codehaus.mojo.vfs;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.commons.vfs2.FileObject;
25 import org.apache.commons.vfs2.FileSystemOptions;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.MojoFailureException;
28 import org.apache.maven.plugins.annotations.Mojo;
29 import org.apache.maven.plugins.annotations.Parameter;
30 import org.codehaus.mojo.vfs.MergeVfsMavenRepositories;
31 import org.codehaus.mojo.vfs.internal.DefaultMergeVfsMavenRepositories;
32
33
34
35
36 @Mojo( name = "merge-maven-repositories", requiresProject = false, threadSafe = true )
37 public class MergeMavenReposVfsMojo
38 extends AbstractVfsMojo
39 {
40
41
42
43
44
45 @Parameter( property = "source", required = true )
46 private String source;
47
48
49
50
51
52 @Parameter( property = "sourceId", required = false )
53 private String sourceId;
54
55
56
57
58
59 @Parameter( property = "destination", required = true )
60 private String destination;
61
62
63
64
65
66 @Parameter( property = "destinationId", required = false )
67 private String destinationId;
68
69
70
71
72
73 @Parameter( property = "stagingDirectory", required = false, defaultValue = "${project.build.directory}/merge-staging" )
74 private File stagingDirectory;
75
76
77
78
79
80
81 @Parameter( property = "dryRun", required = false, defaultValue = "false" )
82 private boolean dryRun = false;
83
84 public void execute()
85 throws MojoExecutionException, MojoFailureException
86 {
87
88 if ( !this.skip )
89 {
90 try
91 {
92 FileSystemOptions sourceOpts = this.getFileSystemOptions( sourceId, source );
93 FileSystemOptions destOpts = this.getFileSystemOptions( destinationId, destination );
94
95 FileObject sourceRepo = getFileSystemManager().resolveFile( source, sourceOpts );
96
97 FileObject destRepo = getFileSystemManager().resolveFile( destination, destOpts );
98
99 MergeVfsMavenRepositories repoMerger = new DefaultMergeVfsMavenRepositories();
100
101 repoMerger.merge( sourceRepo, destRepo, stagingDirectory, dryRun );
102
103 if ( dryRun )
104 {
105 this.getLog().info( "Merging operetion stopped before pushing the final contents at "
106 + this.stagingDirectory + destination );
107 }
108
109 }
110 catch ( Exception e )
111 {
112 throw new MojoFailureException( "Unable to perform a repositories merge operation", e );
113 }
114 }
115 else
116 {
117 this.getLog().info( "Skip VFS Maven repositories merge operation" );
118 }
119
120 }
121 }