1 package org.apache.maven.scm.provider.svn;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.junit.Assert;
23 import org.apache.maven.scm.ScmTestCase;
24 import org.codehaus.plexus.util.FileUtils;
25 import org.codehaus.plexus.util.cli.CommandLineException;
26 import org.codehaus.plexus.util.cli.CommandLineUtils;
27 import org.codehaus.plexus.util.cli.Commandline;
28
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.InputStream;
32
33
34
35
36
37 public final class SvnScmTestUtils
38 {
39
40 public static final String SVN_COMMAND_LINE = "svn";
41
42
43 public static final String SVNADMIN_COMMAND_LINE = "svnadmin";
44
45 private SvnScmTestUtils()
46 {
47 }
48
49 public static void initializeRepository( File repositoryRoot )
50 throws Exception
51 {
52 if ( repositoryRoot.exists() )
53 {
54 FileUtils.deleteDirectory( repositoryRoot );
55 }
56
57 Assert.assertFalse( "repositoryRoot still exists", repositoryRoot.exists() );
58
59 Assert.assertTrue( "Could not make repository root directory: " + repositoryRoot.getAbsolutePath(),
60 repositoryRoot.mkdirs() );
61
62 ScmTestCase.execute( repositoryRoot.getParentFile(), SVNADMIN_COMMAND_LINE,
63 "create " + repositoryRoot.getName() );
64
65 loadSvnDump( repositoryRoot,
66 new SvnScmTestUtils().getClass().getClassLoader().getResourceAsStream( "tck/tck.dump" ) );
67 }
68
69 public static void initializeRepository( File repositoryRoot, File dump )
70 throws Exception
71 {
72 if ( repositoryRoot.exists() )
73 {
74 FileUtils.deleteDirectory( repositoryRoot );
75 }
76
77 Assert.assertTrue( "Could not make repository root directory: " + repositoryRoot.getAbsolutePath(),
78 repositoryRoot.mkdirs() );
79
80 ScmTestCase.execute( repositoryRoot.getParentFile(), SVNADMIN_COMMAND_LINE,
81 "create " + repositoryRoot.getName() );
82
83 Assert.assertTrue( "The dump file doesn't exist: " + dump.getAbsolutePath(), dump.exists() );
84
85 loadSvnDump( repositoryRoot, new FileInputStream( dump ) );
86 }
87
88 private static void loadSvnDump( File repositoryRoot, InputStream dumpStream )
89 throws Exception
90 {
91 Commandline cl = new Commandline();
92
93 cl.setExecutable( SVNADMIN_COMMAND_LINE );
94
95 cl.setWorkingDirectory( repositoryRoot.getParentFile().getAbsolutePath() );
96
97 cl.createArg().setValue( "load" );
98
99 cl.createArg().setValue( repositoryRoot.getAbsolutePath() );
100
101 CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
102
103 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
104
105 int exitValue = CommandLineUtils.executeCommandLine( cl, dumpStream, stdout, stderr );
106
107 if ( exitValue != 0 )
108 {
109 System.err.println( "-----------------------------------------" );
110 System.err.println( "Command line: " + cl );
111 System.err.println( "Working directory: " + cl.getWorkingDirectory() );
112 System.err.println( "-----------------------------------------" );
113 System.err.println( "Standard output: " );
114 System.err.println( "-----------------------------------------" );
115 System.err.println( stdout.getOutput() );
116 System.err.println( "-----------------------------------------" );
117
118 System.err.println( "Standard error: " );
119 System.err.println( "-----------------------------------------" );
120 System.err.println( stderr.getOutput() );
121 System.err.println( "-----------------------------------------" );
122 }
123
124 if ( exitValue != 0 )
125 {
126 Assert.fail( "Exit value wasn't 0, was:" + exitValue );
127 }
128 }
129
130 public static String getScmUrl( File repositoryRootFile )
131 throws CommandLineException
132 {
133 return "scm:svn:" + repositoryRootFile.toPath().toAbsolutePath().toUri().toASCIIString();
134 }
135 }