1 package org.apache.maven.archiva.web.util;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 //import org.apache.maven.archiva.indexer.record.StandardArtifactIndexRecord;
23 //import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
24 //import org.apache.maven.model.Dependency;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.LinkedHashMap;
29 import java.util.List;
32 public class VersionMerger
35 public static List /*<DependencyWrapper>*/ wrap( List /*<StandardArtifactIndexRecord>*/ artifacts )
37 List dependencies = new ArrayList();
39 // for ( Iterator i = artifacts.iterator(); i.hasNext(); )
41 // Dependency dependency = (Dependency) i.next();
43 // dependencies.add( new DependencyWrapper( dependency ) );
49 public static Collection /*<DependencyWrapper*/ merge( Collection /*<StandardArtifactIndexRecord>*/ artifacts )
51 Map dependees = new LinkedHashMap();
53 // for ( Iterator i = artifacts.iterator(); i.hasNext(); )
55 // StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next();
57 // String key = record.getGroupId() + ":" + record.getArtifactId();
58 // if ( dependees.containsKey( key ) )
60 // DependencyWrapper wrapper = (DependencyWrapper) dependees.get( key );
61 // wrapper.addVersion( record.getVersion() );
65 // DependencyWrapper wrapper = new DependencyWrapper( record );
67 // dependees.put( key, wrapper );
71 return dependees.values();
74 // public static class DependencyWrapper
76 // private final String groupId;
78 // private final String artifactId;
81 // * Versions added. We ignore duplicates since you might add those with varying classifiers.
83 // private Set versions = new HashSet();
85 // private String version;
87 // private String scope;
89 // private String classifier;
91 // public DependencyWrapper( StandardArtifactIndexRecord record )
93 // this.groupId = record.getGroupId();
95 // this.artifactId = record.getArtifactId();
97 // addVersion( record.getVersion() );
100 // public DependencyWrapper( Dependency dependency )
102 // this.groupId = dependency.getGroupId();
104 // this.artifactId = dependency.getArtifactId();
106 // this.scope = dependency.getScope();
108 // this.classifier = dependency.getClassifier();
110 // addVersion( dependency.getVersion() );
113 // public String getScope()
118 // public String getClassifier()
120 // return classifier;
123 // public void addVersion( String version )
125 // // We use DefaultArtifactVersion to get the correct sorting order later, however it does not have
126 // // hashCode properly implemented, so we add it here.
127 // // TODO: add these methods to the actual DefaultArtifactVersion and use that.
128 // versions.add( new DefaultArtifactVersion( version )
130 // public int hashCode()
133 // result = getBuildNumber();
134 // result = 31 * result + getMajorVersion();
135 // result = 31 * result + getMinorVersion();
136 // result = 31 * result + getIncrementalVersion();
137 // result = 31 * result + ( getQualifier() != null ? getQualifier().hashCode() : 0 );
141 // public boolean equals( Object o )
147 // if ( o == null || getClass() != o.getClass() )
152 // DefaultArtifactVersion that = (DefaultArtifactVersion) o;
154 // if ( getBuildNumber() != that.getBuildNumber() )
158 // if ( getIncrementalVersion() != that.getIncrementalVersion() )
162 // if ( getMajorVersion() != that.getMajorVersion() )
166 // if ( getMinorVersion() != that.getMinorVersion() )
170 // if ( getQualifier() != null ? !getQualifier().equals( that.getQualifier() )
171 // : that.getQualifier() != null )
180 // if ( versions.size() == 1 )
182 // this.version = version;
186 // this.version = null;
190 // public String getGroupId()
195 // public String getArtifactId()
197 // return artifactId;
200 // public List getVersions()
202 // List versions = new ArrayList( this.versions );
203 // Collections.sort( versions );
207 // public String getVersion()