]> source.dussan.org Git - archiva.git/blob
07e4a702c7a06176bd767e0664063c0dddca8fbe
[archiva.git] /
1 package org.apache.maven.archiva.web.util;
2
3 /*
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
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 //import org.apache.maven.archiva.indexer.record.StandardArtifactIndexRecord;
23 //import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
24 //import org.apache.maven.model.Dependency;
25
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.LinkedHashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 public class VersionMerger
33 {
34
35     public static List /*<DependencyWrapper>*/ wrap( List /*<StandardArtifactIndexRecord>*/ artifacts )
36     {
37         List dependencies = new ArrayList();
38
39 //        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
40 //        {
41 //            Dependency dependency = (Dependency) i.next();
42 //
43 //            dependencies.add( new DependencyWrapper( dependency ) );
44 //        }
45
46         return dependencies;
47     }
48
49     public static Collection /*<DependencyWrapper*/ merge( Collection /*<StandardArtifactIndexRecord>*/ artifacts )
50     {
51         Map dependees = new LinkedHashMap();
52
53 //        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
54 //        {
55 //            StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next();
56 //
57 //            String key = record.getGroupId() + ":" + record.getArtifactId();
58 //            if ( dependees.containsKey( key ) )
59 //            {
60 //                DependencyWrapper wrapper = (DependencyWrapper) dependees.get( key );
61 //                wrapper.addVersion( record.getVersion() );
62 //            }
63 //            else
64 //            {
65 //                DependencyWrapper wrapper = new DependencyWrapper( record );
66 //
67 //                dependees.put( key, wrapper );
68 //            }
69 //        }
70
71         return dependees.values();
72     }
73
74 //    public static class DependencyWrapper
75 //    {
76 //        private final String groupId;
77 //
78 //        private final String artifactId;
79 //
80 //        /**
81 //         * Versions added. We ignore duplicates since you might add those with varying classifiers.
82 //         */
83 //        private Set versions = new HashSet();
84 //
85 //        private String version;
86 //
87 //        private String scope;
88 //
89 //        private String classifier;
90 //
91 //        public DependencyWrapper( StandardArtifactIndexRecord record )
92 //        {
93 //            this.groupId = record.getGroupId();
94 //
95 //            this.artifactId = record.getArtifactId();
96 //
97 //            addVersion( record.getVersion() );
98 //        }
99 //
100 //        public DependencyWrapper( Dependency dependency )
101 //        {
102 //            this.groupId = dependency.getGroupId();
103 //
104 //            this.artifactId = dependency.getArtifactId();
105 //
106 //            this.scope = dependency.getScope();
107 //
108 //            this.classifier = dependency.getClassifier();
109 //
110 //            addVersion( dependency.getVersion() );
111 //        }
112 //
113 //        public String getScope()
114 //        {
115 //            return scope;
116 //        }
117 //
118 //        public String getClassifier()
119 //        {
120 //            return classifier;
121 //        }
122 //
123 //        public void addVersion( String version )
124 //        {
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 )
129 //            {
130 //                public int hashCode()
131 //                {
132 //                    int result;
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 );
138 //                    return result;
139 //                }
140 //
141 //                public boolean equals( Object o )
142 //                {
143 //                    if ( this == o )
144 //                    {
145 //                        return true;
146 //                    }
147 //                    if ( o == null || getClass() != o.getClass() )
148 //                    {
149 //                        return false;
150 //                    }
151 //
152 //                    DefaultArtifactVersion that = (DefaultArtifactVersion) o;
153 //
154 //                    if ( getBuildNumber() != that.getBuildNumber() )
155 //                    {
156 //                        return false;
157 //                    }
158 //                    if ( getIncrementalVersion() != that.getIncrementalVersion() )
159 //                    {
160 //                        return false;
161 //                    }
162 //                    if ( getMajorVersion() != that.getMajorVersion() )
163 //                    {
164 //                        return false;
165 //                    }
166 //                    if ( getMinorVersion() != that.getMinorVersion() )
167 //                    {
168 //                        return false;
169 //                    }
170 //                    if ( getQualifier() != null ? !getQualifier().equals( that.getQualifier() )
171 //                        : that.getQualifier() != null )
172 //                    {
173 //                        return false;
174 //                    }
175 //
176 //                    return true;
177 //                }
178 //            } );
179 //
180 //            if ( versions.size() == 1 )
181 //            {
182 //                this.version = version;
183 //            }
184 //            else
185 //            {
186 //                this.version = null;
187 //            }
188 //        }
189 //
190 //        public String getGroupId()
191 //        {
192 //            return groupId;
193 //        }
194 //
195 //        public String getArtifactId()
196 //        {
197 //            return artifactId;
198 //        }
199 //
200 //        public List getVersions()
201 //        {
202 //            List versions = new ArrayList( this.versions );
203 //            Collections.sort( versions );
204 //            return versions;
205 //        }
206 //
207 //        public String getVersion()
208 //        {
209 //            return version;
210 //        }
211 //    }
212 }