1 package org.apache.maven.shared.artifact.resolver.testutil;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }