1 package org.apache.maven.index.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
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
30 extends AbstractNexusIndexerCliTest
31 {
32
33 private StreamConsumer sout;
34
35 @Override
36 protected void setUp()
37 throws Exception
38 {
39 super.setUp();
40
41 sout = line ->
42 {
43 try
44 {
45 out.write( line.getBytes() );
46 out.write( "\n".getBytes() );
47 }
48 catch ( IOException e )
49 {
50 throw new RuntimeException( e.getMessage(), e );
51 }
52 };
53 }
54
55 private Commandline createCommandLine()
56 {
57 try
58 {
59 Commandline cmd = new Commandline();
60 cmd.setExecutable( "java" );
61 cmd.setWorkingDirectory( new File( "." ).getCanonicalFile() );
62 cmd.createArg().setValue( "-jar" );
63 cmd.createArg().setValue( new File( System.getProperty( "indexerJar" ) ).getCanonicalPath() );
64 return cmd;
65 }
66 catch ( IOException e )
67 {
68 throw new RuntimeException( e );
69 }
70 }
71
72 @Override
73 protected int execute( String... args )
74 {
75 Commandline cmd = createCommandLine();
76 for ( String arg : args )
77 {
78 cmd.createArg().setValue( arg );
79 }
80 try
81 {
82 return CommandLineUtils.executeCommandLine( cmd, sout, sout );
83 }
84 catch ( CommandLineException e )
85 {
86 return -1;
87 }
88 }
89
90 }