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  
15  package org.basepom.inline.mojo;
16  
17  import static com.google.common.base.Preconditions.checkState;
18  
19  import org.apache.maven.artifact.Artifact;
20  import org.eclipse.aether.graph.Dependency;
21  
22  public final class InlineDependency {
23  
24      private ArtifactIdentifier artifactIdentifier = null;
25  
26      private boolean transitive = true;
27      private boolean optionals = false;
28  
29      public void setArtifact(String artifact) {
30          this.artifactIdentifier = new ArtifactIdentifier(artifact);
31      }
32  
33      public ArtifactIdentifier getArtifactIdentifier() {
34          checkState(artifactIdentifier != null, "no artifact has been set!");
35          return artifactIdentifier;
36      }
37  
38      public boolean isInlineTransitive() {
39          return transitive;
40      }
41  
42      public InlineDependency setInlineTransitive(boolean transitive) {
43          this.transitive = transitive;
44          return this;
45      }
46  
47      public boolean isInlineOptionals() {
48          return optionals;
49      }
50  
51      public InlineDependency setInlineOptionals(boolean optionals) {
52          this.optionals = optionals;
53          return this;
54      }
55  
56      public boolean matchDependency(Dependency dependency) {
57          return getArtifactIdentifier().matchDependency(dependency);
58      }
59  
60      public boolean matchArtifact(Artifact artifact) {
61          return getArtifactIdentifier().matchArtifact(artifact);
62      }
63  
64      @Override
65      public String toString() {
66          String flags = transitive ? "inline transitive" : "";
67          return String.format("%s [%s]", artifactIdentifier, flags);
68      }
69  }