1 | |
package org.apache.maven.scm.provider.git; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import junit.framework.Assert; |
23 | |
import org.codehaus.plexus.PlexusTestCase; |
24 | |
import org.codehaus.plexus.util.FileUtils; |
25 | |
import org.codehaus.plexus.util.Os; |
26 | |
import org.codehaus.plexus.util.StringUtils; |
27 | |
import org.codehaus.plexus.util.cli.CommandLineException; |
28 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
29 | |
import org.codehaus.plexus.util.cli.Commandline; |
30 | |
|
31 | |
import java.io.File; |
32 | |
import java.io.IOException; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public final class GitScmTestUtils |
39 | |
{ |
40 | |
private GitScmTestUtils() |
41 | 0 | { |
42 | 0 | } |
43 | |
|
44 | |
public static void initRepo( File repository, File workingDirectory, File assertionDirectory ) |
45 | |
throws IOException |
46 | |
{ |
47 | 0 | initRepo( "src/test/repository/", repository, workingDirectory ); |
48 | |
|
49 | 0 | FileUtils.deleteDirectory( assertionDirectory ); |
50 | |
|
51 | 0 | Assert.assertTrue( assertionDirectory.mkdirs() ); |
52 | 0 | } |
53 | |
|
54 | |
public static void initRepo( String source, File repository, File workingDirectory ) |
55 | |
throws IOException |
56 | |
{ |
57 | |
|
58 | 0 | File src = PlexusTestCase.getTestFile( source ); |
59 | |
|
60 | 0 | FileUtils.deleteDirectory( repository ); |
61 | |
|
62 | 0 | Assert.assertTrue( repository.mkdirs() ); |
63 | |
|
64 | 0 | FileUtils.copyDirectoryStructure( src, repository ); |
65 | |
|
66 | |
|
67 | 0 | deleteAllDirectories( repository, ".svn" ); |
68 | |
|
69 | 0 | FileUtils.deleteDirectory( workingDirectory ); |
70 | |
|
71 | 0 | Assert.assertTrue( workingDirectory.mkdirs() ); |
72 | 0 | } |
73 | |
|
74 | |
public static String getScmUrl( File repositoryRootFile, String provider ) |
75 | |
throws CommandLineException |
76 | |
{ |
77 | 0 | String repositoryRoot = repositoryRootFile.getAbsolutePath(); |
78 | |
|
79 | |
|
80 | |
|
81 | 0 | if ( "true".equals( System.getProperty( "cygwin" ) ) ) |
82 | |
{ |
83 | 0 | Commandline cl = new Commandline(); |
84 | |
|
85 | 0 | cl.setExecutable( "cygpath" ); |
86 | |
|
87 | 0 | cl.createArg().setValue( "--unix" ); |
88 | |
|
89 | 0 | cl.createArg().setValue( repositoryRoot ); |
90 | |
|
91 | 0 | CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); |
92 | |
|
93 | 0 | int exitValue = CommandLineUtils.executeCommandLine( cl, stdout, null ); |
94 | |
|
95 | 0 | if ( exitValue != 0 ) |
96 | |
{ |
97 | 0 | throw new CommandLineException( "Unable to convert cygwin path, exit code = " + exitValue ); |
98 | |
} |
99 | |
|
100 | 0 | repositoryRoot = stdout.getOutput().trim(); |
101 | 0 | } |
102 | 0 | else if ( Os.isFamily( "windows" ) ) |
103 | |
{ |
104 | 0 | repositoryRoot = "/" + StringUtils.replace( repositoryRoot, "\\", "/" ); |
105 | |
} |
106 | |
|
107 | 0 | return "scm:" + provider + ":file://" + repositoryRoot; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
public static void deleteAllDirectories( File startDirectory, String pattern ) |
112 | |
throws IOException |
113 | |
{ |
114 | 0 | if ( startDirectory.isDirectory() ) |
115 | |
{ |
116 | 0 | File[] childs = startDirectory.listFiles(); |
117 | 0 | for ( int i = 0; i < childs.length; i++ ) |
118 | |
{ |
119 | 0 | File child = childs[ i ]; |
120 | 0 | if ( child.isDirectory() ) |
121 | |
{ |
122 | 0 | if ( child.getName().equals( pattern ) ) |
123 | |
{ |
124 | 0 | FileUtils.deleteDirectory( child ); |
125 | |
} |
126 | |
else |
127 | |
{ |
128 | 0 | deleteAllDirectories( child, pattern ); |
129 | |
} |
130 | |
} |
131 | |
} |
132 | |
} |
133 | 0 | } |
134 | |
|
135 | |
} |