View Javadoc
1   package com.codehaus.mojo.vfs;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * Merge Maven repository from one VFS to another VFS
35   */
36  @Mojo( name = "merge-maven-repositories", requiresProject = false, threadSafe = true )
37  public class MergeMavenReposVfsMojo
38      extends AbstractVfsMojo
39  {
40  
41      /**
42       * Source URL
43       * @since 1.0 beta 1
44       */
45      @Parameter( property = "source", required = true )
46      private String source;
47  
48      /**
49       * Maven settings server's source authentication id
50       * @since 1.0 beta 1
51       */
52      @Parameter( property = "sourceId", required = false )
53      private String sourceId;
54  
55      /**
56       * Destination URL
57       * @since 1.0 beta 1
58       */
59      @Parameter( property = "destination", required = true )
60      private String destination;
61  
62      /**
63       * Maven settings server's source authentication id
64       * @since 1.0 beta 1
65       */
66      @Parameter( property = "destinationId", required = false )
67      private String destinationId;
68  
69      /**
70       * Staging directory to do the merging works. If not given, and random directory is used
71       * @since 1.0 beta 1
72       */
73      @Parameter( property = "stagingDirectory", required = false, defaultValue = "${project.build.directory}/merge-staging" )
74      private File stagingDirectory;
75  
76      /**
77       * Option not to push merged content to destination repository so that you can review the merge content under
78       * ${stagingDirectory}
79       * @since 1.0 beta 1
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 }