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