View Javadoc

1   package org.apache.maven.index;
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 java.io.File;
23  import java.io.IOException;
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.Random;
27  
28  import org.apache.maven.index.context.DefaultIndexingContext;
29  import org.apache.maven.index.context.IndexCreator;
30  import org.apache.maven.index.creator.JarFileContentsIndexCreator;
31  import org.apache.maven.index.creator.MavenArchetypeArtifactInfoIndexCreator;
32  import org.apache.maven.index.creator.MavenPluginArtifactInfoIndexCreator;
33  import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator;
34  import org.codehaus.plexus.PlexusTestCase;
35  import org.codehaus.plexus.util.FileUtils;
36  
37  public class AbstractIndexCreatorHelper
38      extends PlexusTestCase
39  {
40      public List<IndexCreator> DEFAULT_CREATORS;
41  
42      public List<IndexCreator> FULL_CREATORS;
43  
44      public List<IndexCreator> MIN_CREATORS;
45  
46      Random rand = new Random();
47  
48      @Override
49      protected void setUp()
50          throws Exception
51      {
52          super.setUp();
53  
54          DEFAULT_CREATORS = new ArrayList<IndexCreator>();
55          FULL_CREATORS = new ArrayList<IndexCreator>();
56          MIN_CREATORS = new ArrayList<IndexCreator>();
57  
58          IndexCreator min = lookup( IndexCreator.class, MinimalArtifactInfoIndexCreator.ID );
59          IndexCreator mavenPlugin = lookup( IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID );
60          IndexCreator mavenArchetype = lookup( IndexCreator.class, MavenArchetypeArtifactInfoIndexCreator.ID );
61          IndexCreator jar = lookup( IndexCreator.class, JarFileContentsIndexCreator.ID );
62  
63          MIN_CREATORS.add( min );
64  
65          DEFAULT_CREATORS.add( min );
66          DEFAULT_CREATORS.add( mavenPlugin );
67          DEFAULT_CREATORS.add( mavenArchetype );
68  
69          FULL_CREATORS.add( min );
70          FULL_CREATORS.add( mavenPlugin );
71          FULL_CREATORS.add( mavenArchetype );
72          FULL_CREATORS.add( jar );
73      }
74  
75      protected void deleteDirectory( File dir )
76          throws IOException
77      {
78          FileUtils.deleteDirectory( dir );
79      }
80  
81      protected File getDirectory( String name )
82      {
83          // pick random output location
84  
85          File outputFolder = new File( getBasedir(), "target/tests/" + name + "-" + rand.nextLong() + "/" );
86          outputFolder.delete();
87          assertFalse( outputFolder.exists() );
88          return outputFolder;
89      }
90  
91      public void testDirectory()
92          throws IOException
93      {
94          File dir = this.getDirectory( "foo" );
95          assert ( dir.getAbsolutePath().contains( "foo" ) );
96          this.deleteDirectory( dir );
97          assertFalse( dir.exists() );
98  
99          File dir2 = this.getDirectory( "foo" );
100         assertFalse( "Directories aren't unique", dir.getCanonicalPath().equals( dir2.getCanonicalPath() ) );
101     }
102 }