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