View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.api.plugin.testing.stubs;
20  
21  import java.io.File;
22  import java.nio.file.Path;
23  import java.util.Collections;
24  import java.util.List;
25  import java.util.Optional;
26  
27  import org.apache.maven.api.Artifact;
28  import org.apache.maven.api.DependencyCoordinate;
29  import org.apache.maven.api.Project;
30  import org.apache.maven.api.RemoteRepository;
31  import org.apache.maven.api.annotations.Nonnull;
32  import org.apache.maven.api.model.Model;
33  
34  /**
35   * @author Olivier Lamy
36   * @since 1.0-beta-1
37   *
38   */
39  public class ProjectStub implements Project {
40  
41      private Model model = Model.newInstance();
42      private Path basedir;
43      private File pomPath;
44      private boolean topProject;
45      private Artifact artifact;
46      private Path rootDirectory;
47  
48      public void setModel(Model model) {
49          this.model = model;
50      }
51  
52      @Nonnull
53      @Override
54      public String getGroupId() {
55          return model.getGroupId();
56      }
57  
58      @Nonnull
59      @Override
60      public String getArtifactId() {
61          return model.getArtifactId();
62      }
63  
64      @Nonnull
65      @Override
66      public String getVersion() {
67          return model.getVersion();
68      }
69  
70      public String getName() {
71          return model.getName();
72      }
73  
74      @Nonnull
75      @Override
76      public String getPackaging() {
77          return model.getPackaging();
78      }
79  
80      @Nonnull
81      @Override
82      public Artifact getArtifact() {
83          return artifact;
84      }
85  
86      @Nonnull
87      @Override
88      public Model getModel() {
89          return model;
90      }
91  
92      @Nonnull
93      @Override
94      public Optional<Path> getPomPath() {
95          return Optional.ofNullable(pomPath).map(File::toPath);
96      }
97  
98      @Nonnull
99      @Override
100     public List<DependencyCoordinate> getDependencies() {
101         return null;
102     }
103 
104     @Nonnull
105     @Override
106     public List<DependencyCoordinate> getManagedDependencies() {
107         return null;
108     }
109 
110     @Override
111     public Optional<Path> getBasedir() {
112         return Optional.ofNullable(basedir);
113     }
114 
115     public void setBasedir(Path basedir) {
116         this.basedir = basedir;
117     }
118 
119     @Override
120     public boolean isExecutionRoot() {
121         return isTopProject();
122     }
123 
124     @Override
125     public Optional<Project> getParent() {
126         return Optional.empty();
127     }
128 
129     @Override
130     public List<RemoteRepository> getRemoteProjectRepositories() {
131         return Collections.emptyList();
132     }
133 
134     @Override
135     public List<RemoteRepository> getRemotePluginRepositories() {
136         return Collections.emptyList();
137     }
138 
139     @Override
140     public boolean isTopProject() {
141         return topProject;
142     }
143 
144     @Override
145     public boolean isRootProject() {
146         return model.isRoot();
147     }
148 
149     @Override
150     public Path getRootDirectory() {
151         return rootDirectory;
152     }
153 
154     public void setGroupId(String groupId) {
155         model = model.withGroupId(groupId);
156     }
157 
158     public void setArtifactId(String artifactId) {
159         model = model.withArtifactId(artifactId);
160     }
161 
162     public void setVersion(String version) {
163         model = model.withVersion(version);
164     }
165 
166     public void setName(String name) {
167         model = model.withName(name);
168     }
169 
170     public void setPackaging(String packaging) {
171         model = model.withPackaging(packaging);
172     }
173 
174     public void setArtifact(Artifact artifact) {
175         this.artifact = artifact;
176     }
177 
178     public void setPomPath(File pomPath) {
179         this.pomPath = pomPath;
180     }
181 
182     public void setTopProject(boolean topProject) {
183         this.topProject = topProject;
184     }
185 
186     public void setMavenModel(org.apache.maven.model.Model model) {
187         this.model = model.getDelegate();
188     }
189 
190     public void setRootDirectory(Path rootDirectory) {
191         this.rootDirectory = rootDirectory;
192     }
193 }