View Javadoc
1   package org.apache.maven.shared.artifact.resolver.testutil;
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.model.Dependency;
23  import org.apache.maven.model.DependencyManagement;
24  import org.apache.maven.model.Model;
25  
26  public class ModelCreator
27  {
28      
29      private Model model;
30      
31      public ModelCreator()
32      {
33          model = new Model();
34          model.setModelVersion( "4.0.0" );
35      }
36      
37      public ModelCreator withCoordinate( String groupId, String artifactId, String version )
38      {
39          model.setGroupId( groupId );
40          model.setArtifactId( artifactId );
41          model.setVersion( version );
42          return this;
43      }
44      
45      public ModelCreator withDependency( String groupId, String artifactId, String version )
46      {
47          Dependency dep = new Dependency();
48          dep.setGroupId( groupId );
49          dep.setArtifactId( artifactId );
50          dep.setVersion( version );
51          
52          model.addDependency( dep );
53          return this;
54      }
55      
56      public Model getModel()
57      {
58          return model;
59      }
60  
61      public ModelCreator withDefaultCoordinate()
62      {
63          return withCoordinate( "group.id", "artifact-id", "1" );
64      }
65      
66      public ModelCreator withArtifactId( String artifactId )
67      {
68          model.setArtifactId( artifactId );
69          return this;
70      }
71  
72      public ModelCreator withManagedDependency( String groupId, String artifactId, String version )
73      {
74          DependencyManagement dm = model.getDependencyManagement();
75          if ( dm == null )
76          {
77              dm = new DependencyManagement();
78              model.setDependencyManagement( dm );
79          }
80          
81          Dependency dep = new Dependency();
82          dep.setGroupId( groupId );
83          dep.setArtifactId( artifactId );
84          dep.setVersion( version );
85          
86          dm.addDependency( dep );
87          
88          return this;
89      }
90  }