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