]> source.dussan.org Git - archiva.git/blob
1fcc0e33bfdaab467dc81b55b25717a5c94b8ffb
[archiva.git] /
1 package org.apache.maven.archiva.plugins.dev;
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 org.apache.maven.archiva.plugins.dev.testgen.DependencyGraphTestCreator;
23 import org.apache.maven.archiva.plugins.dev.testgen.MemoryRepositoryCreator;
24 import org.apache.maven.archiva.plugins.dev.utils.VariableNames;
25 import org.apache.maven.artifact.factory.ArtifactFactory;
26 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
27 import org.apache.maven.artifact.repository.ArtifactRepository;
28 import org.apache.maven.artifact.resolver.ArtifactCollector;
29 import org.apache.maven.plugin.AbstractMojo;
30 import org.apache.maven.plugin.MojoExecutionException;
31 import org.apache.maven.plugin.MojoFailureException;
32 import org.apache.maven.project.MavenProject;
33 import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
34
35 import java.io.File;
36
37 /**
38  * CreateArchivaDependencyResolutionTestCaseMojo 
39  *
40  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
41  * @version $Id$
42  * 
43  * @goal generate-dependency-tests
44  */
45 public class CreateArchivaDependencyResolutionTestCaseMojo
46     extends AbstractMojo
47 {
48     /**
49      * The project of the current build.
50      * 
51      * @parameter default-value="${project}"
52      * @required
53      * @readonly
54      */
55     private MavenProject project;
56
57     /**
58      * The artifact respository to use.
59      * 
60      * @parameter expression="${localRepository}"
61      * @required
62      * @readonly
63      */
64     private ArtifactRepository localRepository;
65     
66     /**
67      * The destination directory to generate the test files.
68      * 
69      * @parameter expression="${archivadev.outputdir}" default-value="${project.build.directory}"
70      * @required
71      */
72     private File destDir;
73
74     /**
75      * The artifact factory to use.
76      * 
77      * @component
78      */
79     private ArtifactFactory artifactFactory;
80     
81     /**
82      * @component
83      */
84     private DependencyTreeBuilder dependencyTreeBuilder;
85     
86     /**
87      * @component
88      */
89     protected ArtifactMetadataSource artifactMetadataSource;
90
91     /**
92      * @component
93      */
94     private ArtifactCollector collector;
95
96     public void execute()
97         throws MojoExecutionException, MojoFailureException
98     {
99         String classPrefix = VariableNames.toClassName( project.getArtifactId() );
100         
101         getLog().info( "Generating into " + destDir );
102         
103         createMemoryRepository( classPrefix );
104         createDependencyGraphTest( classPrefix );
105     }
106     
107     private void createDependencyGraphTest( String classPrefix ) throws MojoExecutionException
108     {
109         DependencyGraphTestCreator creator = new DependencyGraphTestCreator();
110         creator.setLog( getLog() );
111         creator.setOutputDir( destDir );
112         creator.setProject( project );
113         creator.setArtifactFactory( artifactFactory );
114         creator.setLocalRepository( localRepository );
115         creator.setDependencyTreeBuilder( dependencyTreeBuilder );
116         creator.setArtifactMetadataSource( artifactMetadataSource );
117         creator.setCollector( collector );
118         
119         creator.create( classPrefix );
120     }
121
122     private void createMemoryRepository( String classPrefix ) throws MojoExecutionException
123     {
124         MemoryRepositoryCreator creator = new MemoryRepositoryCreator();
125         creator.setLog( getLog() );
126         creator.setOutputDir( destDir );
127         creator.setProject( project );
128         creator.setArtifactFactory( artifactFactory );
129         creator.setLocalRepository( localRepository );
130         
131         creator.create( classPrefix );
132     }
133 }