View Javadoc
1   package org.apache.maven.index.cli;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0    
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }