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 Tony Chemit
32   * @since 1.0
33   */
34  @Component( role = JarSigner.class, hint = "default" )
35  public class DefaultJarSigner
36      extends AbstractJavaTool<JarSignerRequest>
37      implements JarSigner
38  {
39  
40      public DefaultJarSigner()
41      {
42          super( "jarsigner" );
43      }
44  
45      @Override
46      protected Commandline createCommandLine( JarSignerRequest request, String javaToolFile )
47          throws JavaToolException
48      {
49          JarSignerCommandLineBuilderLineBuilder.html#JarSignerCommandLineBuilder">JarSignerCommandLineBuilder cliBuilder = new JarSignerCommandLineBuilder();
50          cliBuilder.setLogger( getLogger() );
51          cliBuilder.setJarSignerFile( javaToolFile );
52          try
53          {
54              Commandline cli = cliBuilder.build( request );
55              if ( request.isVerbose() )
56              {
57                  getLogger().info( cli.toString() );
58              }
59              else
60              {
61                  getLogger().debug( cli.toString() );
62              }
63              return cli;
64          }
65          catch ( CommandLineConfigurationException e )
66          {
67              throw new JavaToolException( "Error configuring command-line. Reason: " + e.getMessage(), e );
68          }
69      }
70  
71      protected StreamConsumer createSystemOutStreamConsumer( JarSignerRequest request )
72      {
73          StreamConsumer systemOut = request.getSystemOutStreamConsumer();
74  
75          if ( systemOut == null )
76          {
77  
78              final boolean verbose = request.isVerbose();
79  
80              systemOut = new StreamConsumer()
81              {
82  
83                  /**
84                   * {@inheritDoc}
85                   */
86                  public void consumeLine( final String line )
87                  {
88                      if ( verbose )
89                      {
90                          getLogger().info( line );
91                      }
92                      else
93                      {
94                          getLogger().debug( line );
95                      }
96                  }
97  
98              };
99          }
100         return systemOut;
101     }
102 
103 }