001 package org.apache.maven.repository.metadata;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import org.apache.maven.artifact.ArtifactScopeEnum;
023
024 /**
025 * metadata graph edge - combination of version, scope and depth define
026 * an edge in the graph
027 *
028 * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
029 *
030 */
031
032 public class MetadataGraphEdge
033 {
034 String version;
035 ArtifactScopeEnum scope;
036 int depth = -1;
037 int pomOrder = -1;
038 boolean resolved = true;
039 String artifactUri;
040
041 /**
042 * capturing where this link came from
043 * and where it is linked to.
044 *
045 * In the first implementation only source used for explanatory function
046 */
047 MetadataGraphVertex source;
048 MetadataGraphVertex target;
049
050 //----------------------------------------------------------------------------
051 public MetadataGraphEdge( String version, boolean resolved, ArtifactScopeEnum scope, String artifactUri, int depth,
052 int pomOrder )
053 {
054 super();
055 this.version = version;
056 this.scope = scope;
057 this.artifactUri = artifactUri;
058 this.depth = depth;
059 this.resolved = resolved;
060 this.pomOrder = pomOrder;
061 }
062 //----------------------------------------------------------------------------
063 /**
064 * helper for equals
065 */
066 private static boolean objectsEqual( Object o1, Object o2 )
067 {
068 if ( o1 == null && o2 == null )
069 {
070 return true;
071 }
072 if ( ( o1 == null && o2 != null ) || ( o1 != null && o2 == null ) )
073 {
074 return false;
075 }
076 return o1.equals( o2 );
077 }
078
079 //----------------------------------------------------------------------------
080 /**
081 * used to eliminate exact duplicates in the edge list
082 */
083 @Override
084 public boolean equals( Object o )
085 {
086 if ( o instanceof MetadataGraphEdge )
087 {
088 MetadataGraphEdge e = (MetadataGraphEdge) o;
089
090 return objectsEqual( version, e.version )
091 && ArtifactScopeEnum.checkScope( scope ).getScope().equals( ArtifactScopeEnum.checkScope( e.scope ).getScope() )
092 && depth == e.depth;
093 }
094 return false;
095 }
096
097 //----------------------------------------------------------------------------
098 public String getVersion()
099 {
100 return version;
101 }
102
103 public void setVersion( String version )
104 {
105 this.version = version;
106 }
107
108 public ArtifactScopeEnum getScope()
109 {
110 return scope;
111 }
112
113 public void setScope( ArtifactScopeEnum scope )
114 {
115 this.scope = scope;
116 }
117
118 public int getDepth()
119 {
120 return depth;
121 }
122
123 public void setDepth( int depth )
124 {
125 this.depth = depth;
126 }
127
128 public boolean isResolved()
129 {
130 return resolved;
131 }
132
133 public void setResolved( boolean resolved )
134 {
135 this.resolved = resolved;
136 }
137
138 public int getPomOrder()
139 {
140 return pomOrder;
141 }
142
143 public void setPomOrder( int pomOrder )
144 {
145 this.pomOrder = pomOrder;
146 }
147
148 public String getArtifactUri()
149 {
150 return artifactUri;
151 }
152
153 public void setArtifactUri( String artifactUri )
154 {
155 this.artifactUri = artifactUri;
156 }
157
158 public MetadataGraphVertex getSource()
159 {
160 return source;
161 }
162
163 public void setSource( MetadataGraphVertex source )
164 {
165 this.source = source;
166 }
167
168 public MetadataGraphVertex getTarget()
169 {
170 return target;
171 }
172
173 public void setTarget( MetadataGraphVertex target )
174 {
175 this.target = target;
176 }
177
178 @Override
179 public String toString()
180 {
181 return "[ " + "FROM:("
182 + ( source == null ? "no source" : ( source.md == null ? "no source MD" : source.md.toString() ) ) + ") "
183 + "TO:(" + ( target == null ? "no target" : ( target.md == null ? "no target MD" : target.md.toString() ) )
184 + ") " + "version=" + version + ", scope=" + ( scope == null ? "null" : scope.getScope() ) + ", depth="
185 + depth + "]";
186 }
187 //----------------------------------------------------------------------------
188 //----------------------------------------------------------------------------
189 }