]> source.dussan.org Git - archiva.git/blob
11b2d1c2cafb996afe5ed80c5fccacca82c70cf2
[archiva.git] /
1 package org.apache.maven.archiva.common;
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.artifact.repository.ArtifactRepository;
23 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
24 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
25 import org.codehaus.plexus.PlexusTestCase;
26 import org.codehaus.plexus.util.FileUtils;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.Iterator;
32 import java.util.List;
33
34 /**
35  * AbstractArchivaCommonTestCase 
36  *
37  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
38  * @version $Id$
39  */
40 public abstract class AbstractArchivaCommonTestCase
41     extends PlexusTestCase
42 {
43     protected ArtifactRepository getLegacyRepository()
44         throws Exception
45     {
46         File repoBaseDir = new File( getBasedir(), "src/test/legacy-repository" );
47         ArtifactRepository repository = createRepository( repoBaseDir, "legacy" );
48         resetRepositoryState( repository );
49         return repository;
50     }
51
52     protected ArtifactRepository getDefaultRepository()
53         throws Exception
54     {
55         File repoBaseDir = new File( getBasedir(), "src/test/repository" );
56         ArtifactRepository repository = createRepository( repoBaseDir, "default" );
57         resetRepositoryState( repository );
58         return repository;
59     }
60
61     private void resetRepositoryState( ArtifactRepository repository )
62         throws IOException
63     {
64         File repoBaseDir = new File( repository.getBasedir() );
65
66         List tmpfiles = FileUtils.getFiles( repoBaseDir, ".*", "" );
67         for ( Iterator it = tmpfiles.iterator(); it.hasNext(); )
68         {
69             File hit = (File) it.next();
70             if ( hit.exists() )
71             {
72                 if ( hit.isFile() )
73                 {
74                     hit.delete();
75                 }
76
77                 if ( hit.isDirectory() )
78                 {
79                     FileUtils.deleteDirectory( hit );
80                 }
81             }
82         }
83     }
84
85     protected ArtifactRepository createRepository( File basedir, String layout )
86         throws Exception
87     {
88         ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
89
90         ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, layout );
91
92         return factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, repoLayout, null, null );
93     }
94
95     public List getLegacyLayoutArtifactPaths()
96     {
97         List files = new ArrayList();
98
99         files.add( "invalid/jars/1.0/invalid-1.0.jar" );
100         files.add( "invalid/jars/invalid-1.0.rar" );
101         files.add( "invalid/jars/invalid.jar" );
102         files.add( "invalid/invalid-1.0.jar" );
103         files.add( "javax.sql/jars/jdbc-2.0.jar" );
104         files.add( "org.apache.maven/jars/some-ejb-1.0-client.jar" );
105         files.add( "org.apache.maven/jars/testing-1.0.jar" );
106         files.add( "org.apache.maven/jars/testing-1.0-sources.jar" );
107         files.add( "org.apache.maven/jars/testing-UNKNOWN.jar" );
108         files.add( "org.apache.maven/jars/testing-1.0.zip" );
109         files.add( "org.apache.maven/jars/testing-1.0-20050611.112233-1.jar" );
110         files.add( "org.apache.maven/jars/testing-1.0.tar.gz" );
111         files.add( "org.apache.maven.update/jars/test-not-updated-1.0.jar" );
112         files.add( "org.apache.maven.update/jars/test-updated-1.0.jar" );
113
114         return files;
115     }
116
117     public List getDefaultLayoutArtifactPaths()
118     {
119         List files = new ArrayList();
120
121         files.add( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
122         files.add( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar" );
123         files.add( "invalid/invalid/1.0/invalid-1.0b.jar" );
124         files.add( "invalid/invalid/1.0/invalid-2.0.jar" );
125         files.add( "invalid/invalid-1.0.jar" );
126         files.add( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar" );
127         files.add( "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar" );
128         files.add( "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar" );
129         files.add( "org/apache/maven/A/1.0/A-1.0.war" );
130         files.add( "org/apache/maven/A/1.0/A-1.0.pom" );
131         files.add( "org/apache/maven/B/2.0/B-2.0.pom" );
132         files.add( "org/apache/maven/B/1.0/B-1.0.pom" );
133         files.add( "org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar" );
134         files.add( "org/apache/maven/C/1.0/C-1.0.war" );
135         files.add( "org/apache/maven/C/1.0/C-1.0.pom" );
136         files.add( "org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom" );
137         files.add( "org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.jar" );
138         files.add( "org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom" );
139         files.add( "org/apache/maven/update/test-updated/1.0/test-updated-1.0.jar" );
140         files.add( "org/apache/maven/discovery/1.0/discovery-1.0.pom" );
141         files.add( "org/apache/maven/testing/1.0/testing-1.0-test-sources.jar" );
142         files.add( "org/apache/maven/testing/1.0/testing-1.0.jar" );
143         files.add( "org/apache/maven/testing/1.0/testing-1.0-sources.jar" );
144         files.add( "org/apache/maven/testing/1.0/testing-1.0.zip" );
145         files.add( "org/apache/maven/testing/1.0/testing-1.0.tar.gz" );
146         files.add( "org/apache/maven/samplejar/2.0/samplejar-2.0.pom" );
147         files.add( "org/apache/maven/samplejar/2.0/samplejar-2.0.jar" );
148         files.add( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" );
149         files.add( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" );
150         files.add( "org/apache/testgroup/discovery/1.0/discovery-1.0.pom" );
151         files.add( "javax/sql/jdbc/2.0/jdbc-2.0.jar" );
152
153         return files;
154     }
155
156     public List getDefaultLayoutMetadataPaths()
157     {
158         List files = new ArrayList();
159
160         files.add( "org/apache/maven/some-ejb/1.0/maven-metadata.xml" );
161         files.add( "org/apache/maven/update/test-not-updated/maven-metadata.xml" );
162         files.add( "org/apache/maven/update/test-updated/maven-metadata.xml" );
163         files.add( "org/apache/maven/maven-metadata.xml" );
164         files.add( "org/apache/testgroup/discovery/1.0/maven-metadata.xml" );
165         files.add( "org/apache/testgroup/discovery/maven-metadata.xml" );
166         files.add( "javax/sql/jdbc/2.0/maven-metadata-repository.xml" );
167         files.add( "javax/sql/jdbc/maven-metadata-repository.xml" );
168         files.add( "javax/sql/maven-metadata-repository.xml" );
169         files.add( "javax/maven-metadata.xml" );
170
171         return files;
172     }
173
174     public List getDefaultLayoutModelPaths()
175     {
176         List files = new ArrayList();
177
178         files.add( "org/apache/maven/A/1.0/A-1.0.pom" );
179         files.add( "org/apache/maven/B/2.0/B-2.0.pom" );
180         files.add( "org/apache/maven/B/1.0/B-1.0.pom" );
181         files.add( "org/apache/maven/C/1.0/C-1.0.pom" );
182         files.add( "org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom" );
183         files.add( "org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom" );
184         files.add( "org/apache/maven/discovery/1.0/discovery-1.0.pom" );
185         files.add( "org/apache/maven/samplejar/2.0/samplejar-2.0.pom" );
186         files.add( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" );
187         files.add( "org/apache/testgroup/discovery/1.0/discovery-1.0.pom" );
188
189         return files;
190     }
191 }