1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.index.cli;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.codehaus.plexus.util.cli.CommandLineException;
25 import org.codehaus.plexus.util.cli.CommandLineUtils;
26 import org.codehaus.plexus.util.cli.Commandline;
27 import org.codehaus.plexus.util.cli.StreamConsumer;
28
29 public class NexusIndexerCliIT extends AbstractNexusIndexerCliTest {
30
31 private StreamConsumer sout;
32
33 @Override
34 public void setUp() throws Exception {
35 super.setUp();
36
37 sout = line -> {
38 try {
39 out.write(line.getBytes());
40 out.write("\n".getBytes());
41 } catch (IOException e) {
42 throw new RuntimeException(e.getMessage(), e);
43 }
44 };
45 }
46
47 private Commandline createCommandLine() {
48 try {
49 Commandline cmd = new Commandline();
50 cmd.setExecutable("java");
51 cmd.setWorkingDirectory(new File(".").getCanonicalFile());
52 cmd.createArg().setValue("-jar");
53 cmd.createArg().setValue(new File(System.getProperty("indexerJar")).getCanonicalPath());
54 return cmd;
55 } catch (IOException e) {
56 throw new RuntimeException(e);
57 }
58 }
59
60 @Override
61 protected int execute(String... args) {
62 Commandline cmd = createCommandLine();
63 for (String arg : args) {
64 cmd.createArg().setValue(arg);
65 }
66 try {
67 return CommandLineUtils.executeCommandLine(cmd, sout, sout);
68 } catch (CommandLineException e) {
69 return -1;
70 }
71 }
72 }