View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  package org.basepom.inline.mojo;
15  
16  import static com.google.common.base.Preconditions.checkState;
17  
18  import java.util.List;
19  
20  import com.google.common.collect.ImmutableList;
21  import org.apache.maven.artifact.Artifact;
22  import org.eclipse.aether.graph.Dependency;
23  
24  public final class InlineDependency {
25  
26      private ArtifactIdentifier artifactIdentifier = null;
27  
28      private boolean transitive = true;
29      private boolean optionals = false;
30  
31  
32      public InlineDependency() {
33      }
34  
35      public void setArtifact(String artifact) {
36          this.artifactIdentifier = new ArtifactIdentifier(artifact);
37      }
38  
39      public ArtifactIdentifier getArtifactIdentifier() {
40          checkState(artifactIdentifier != null, "no artifact has been set!");
41          return artifactIdentifier;
42      }
43  
44      public boolean isInlineTransitive() {
45          return transitive;
46      }
47  
48      public InlineDependency setInlineTransitive(boolean transitive) {
49          this.transitive = transitive;
50          return this;
51      }
52  
53      public boolean isInlineOptionals() {
54          return optionals;
55      }
56  
57      public InlineDependency setInlineOptionals(boolean optionals) {
58          this.optionals = optionals;
59          return this;
60      }
61  
62      public boolean matchDependency(Dependency dependency) {
63          return getArtifactIdentifier().matchDependency(dependency);
64      }
65  
66      public boolean matchArtifact(Artifact artifact) {
67          return getArtifactIdentifier().matchArtifact(artifact);
68      }
69  
70      @Override
71      public String toString() {
72          String flags = transitive ? "inline transitive" : "";
73          return String.format("%s [%s]", artifactIdentifier, flags);
74      }
75  }