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 import org.junit.Test;
35
36 import static org.junit.Assert.assertFalse;
37 import static org.junit.Assert.assertNotEquals;
38
39 public class AbstractIndexCreatorHelper
40 extends AbstractTestSupport
41 {
42 public List<IndexCreator> DEFAULT_CREATORS;
43
44 public List<IndexCreator> FULL_CREATORS;
45
46 public List<IndexCreator> MIN_CREATORS;
47
48 Random rand = new Random();
49
50 @Override
51 public void setUp()
52 throws Exception
53 {
54 super.setUp();
55
56 DEFAULT_CREATORS = new ArrayList<>();
57 FULL_CREATORS = new ArrayList<>();
58 MIN_CREATORS = new ArrayList<>();
59
60 IndexCreator min = lookup( IndexCreator.class, MinimalArtifactInfoIndexCreator.ID );
61 IndexCreator mavenPlugin = lookup( IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID );
62 IndexCreator mavenArchetype = lookup( IndexCreator.class, MavenArchetypeArtifactInfoIndexCreator.ID );
63 IndexCreator jar = lookup( IndexCreator.class, JarFileContentsIndexCreator.ID );
64
65 MIN_CREATORS.add( min );
66
67 DEFAULT_CREATORS.add( min );
68 DEFAULT_CREATORS.add( mavenPlugin );
69 DEFAULT_CREATORS.add( mavenArchetype );
70
71 FULL_CREATORS.add( min );
72 FULL_CREATORS.add( mavenPlugin );
73 FULL_CREATORS.add( mavenArchetype );
74 FULL_CREATORS.add( jar );
75 }
76
77 protected void deleteDirectory( File dir )
78 throws IOException
79 {
80 FileUtils.deleteDirectory( dir );
81 }
82
83 protected File getDirectory( String name )
84 {
85
86
87 File outputFolder = new File( getBasedir(), "target/tests/" + name + "-" + rand.nextLong() + "/" );
88 outputFolder.delete();
89 assertFalse( outputFolder.exists() );
90 return outputFolder;
91 }
92
93 @Test
94 public void testDirectory()
95 throws IOException
96 {
97 File dir = this.getDirectory( "foo" );
98 assert ( dir.getAbsolutePath().contains( "foo" ) );
99 this.deleteDirectory( dir );
100 assertFalse( dir.exists() );
101
102 File dir2 = this.getDirectory( "foo" );
103 assertNotEquals( "Directories aren't unique", dir.getCanonicalPath(), dir2.getCanonicalPath() );
104 }
105 }