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.repository.metadata;
20  
21  import org.apache.maven.artifact.ArtifactScopeEnum;
22  
23  /**
24   * metadata graph edge - combination of version, scope and depth define
25   * an edge in the graph
26   *
27   *
28   */
29  @Deprecated
30  public class MetadataGraphEdge {
31      String version;
32      ArtifactScopeEnum scope;
33      int depth = -1;
34      int pomOrder = -1;
35      boolean resolved = true;
36      String artifactUri;
37  
38      /**
39       * capturing where this link came from
40       * and where it is linked to.
41       *
42       *   In the first implementation only source used for explanatory function
43       */
44      MetadataGraphVertex source;
45  
46      MetadataGraphVertex target;
47  
48      // ----------------------------------------------------------------------------
49      public MetadataGraphEdge(
50              String version, boolean resolved, ArtifactScopeEnum scope, String artifactUri, int depth, int pomOrder) {
51          super();
52          this.version = version;
53          this.scope = scope;
54          this.artifactUri = artifactUri;
55          this.depth = depth;
56          this.resolved = resolved;
57          this.pomOrder = pomOrder;
58      }
59      // ----------------------------------------------------------------------------
60      /**
61       * helper for equals
62       */
63      private static boolean objectsEqual(Object o1, Object o2) {
64          if (o1 == null && o2 == null) {
65              return true;
66          }
67          if (o1 == null || o2 == null) {
68              return false; // as they are not both null
69          }
70          return o1.equals(o2);
71      }
72  
73      // ----------------------------------------------------------------------------
74      /**
75       * used to eliminate exact duplicates in the edge list
76       */
77      @Override
78      @SuppressWarnings("checkstyle:equalshashcode")
79      public boolean equals(Object o) {
80          if (o instanceof MetadataGraphEdge) {
81              MetadataGraphEdge e = (MetadataGraphEdge) o;
82  
83              return objectsEqual(version, e.version)
84                      && ArtifactScopeEnum.checkScope(scope)
85                              .getScope()
86                              .equals(ArtifactScopeEnum.checkScope(e.scope).getScope())
87                      && depth == e.depth;
88          }
89          return false;
90      }
91  
92      // ----------------------------------------------------------------------------
93      public String getVersion() {
94          return version;
95      }
96  
97      public void setVersion(String version) {
98          this.version = version;
99      }
100 
101     public ArtifactScopeEnum getScope() {
102         return scope;
103     }
104 
105     public void setScope(ArtifactScopeEnum scope) {
106         this.scope = scope;
107     }
108 
109     public int getDepth() {
110         return depth;
111     }
112 
113     public void setDepth(int depth) {
114         this.depth = depth;
115     }
116 
117     public boolean isResolved() {
118         return resolved;
119     }
120 
121     public void setResolved(boolean resolved) {
122         this.resolved = resolved;
123     }
124 
125     public int getPomOrder() {
126         return pomOrder;
127     }
128 
129     public void setPomOrder(int pomOrder) {
130         this.pomOrder = pomOrder;
131     }
132 
133     public String getArtifactUri() {
134         return artifactUri;
135     }
136 
137     public void setArtifactUri(String artifactUri) {
138         this.artifactUri = artifactUri;
139     }
140 
141     public MetadataGraphVertex getSource() {
142         return source;
143     }
144 
145     public void setSource(MetadataGraphVertex source) {
146         this.source = source;
147     }
148 
149     public MetadataGraphVertex getTarget() {
150         return target;
151     }
152 
153     public void setTarget(MetadataGraphVertex target) {
154         this.target = target;
155     }
156 
157     @Override
158     public String toString() {
159         return "[ " + "FROM:("
160                 + (source == null ? "no source" : (source.md == null ? "no source MD" : source.md.toString())) + ") "
161                 + "TO:(" + (target == null ? "no target" : (target.md == null ? "no target MD" : target.md.toString()))
162                 + ") " + "version=" + version + ", scope=" + (scope == null ? "null" : scope.getScope()) + ", depth="
163                 + depth + "]";
164     }
165     // ----------------------------------------------------------------------------
166     // ----------------------------------------------------------------------------
167 }