View Javadoc

1   package org.apache.maven.shared.jarsigner;
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 org.apache.maven.shared.utils.cli.Commandline;
23  import org.apache.maven.shared.utils.cli.StreamConsumer;
24  import org.apache.maven.shared.utils.cli.javatool.AbstractJavaTool;
25  import org.apache.maven.shared.utils.cli.javatool.JavaToolException;
26  import org.codehaus.plexus.component.annotations.Component;
27  
28  /**
29   * Default implementation of component {@link JarSigner}.
30   *
31   * @author tchemit <chemit@codelutin.com>
32   * @version $Id: DefaultJarSigner.java 1551725 2013-12-17 21:37:16Z tchemit $
33   * @since 1.0
34   */
35  @Component( role = JarSigner.class, hint = "default" )
36  public class DefaultJarSigner
37      extends AbstractJavaTool<JarSignerRequest>
38      implements JarSigner
39  {
40  
41      public DefaultJarSigner()
42      {
43          super( "jarsigner" );
44      }
45  
46      @Override
47      protected Commandline createCommandLine( JarSignerRequest request, String javaToolFile )
48          throws JavaToolException
49      {
50          JarSignerCommandLineBuilder cliBuilder = new JarSignerCommandLineBuilder();
51          cliBuilder.setLogger( getLogger() );
52          cliBuilder.setJarSignerFile( javaToolFile );
53          try
54          {
55              Commandline cli = cliBuilder.build( request );
56              if ( request.isVerbose() )
57              {
58                  getLogger().info( cli.toString() );
59              }
60              else
61              {
62                  getLogger().debug( cli.toString() );
63              }
64              return cli;
65          }
66          catch ( CommandLineConfigurationException e )
67          {
68              throw new JavaToolException( "Error configuring command-line. Reason: " + e.getMessage(), e );
69          }
70      }
71  
72      protected StreamConsumer createSystemOutStreamConsumer( JarSignerRequest request )
73      {
74          StreamConsumer systemOut = request.getSystemOutStreamConsumer();
75  
76          if ( systemOut == null )
77          {
78  
79              final boolean verbose = request.isVerbose();
80  
81              systemOut = new StreamConsumer()
82              {
83  
84                  /**
85                   * {@inheritDoc}
86                   */
87                  public void consumeLine( final String line )
88                  {
89                      if ( verbose )
90                      {
91                          getLogger().info( line );
92                      }
93                      else
94                      {
95                          getLogger().debug( line );
96                      }
97                  }
98  
99              };
100         }
101         return systemOut;
102     }
103 
104 }