View Javadoc
1   /*
2    * Copyright (C) 2009 Jayway AB
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.simpligility.maven.plugins.android;
17  
18  /**
19   * Can sign Android applications (apk's).
20   *
21   * @author hugo.josefson@jayway.com
22   */
23  public class AndroidSigner
24  {
25  
26      /**
27       *
28       */
29      public enum Debug
30      {
31          TRUE, FALSE, BOTH, AUTO
32      }
33  
34      ;
35  
36      private final Debug debug;
37  
38      public AndroidSigner( String debug )
39      {
40          if ( debug == null )
41          {
42              throw new IllegalArgumentException( "android.sign.debug must be 'true', 'false', 'both' or 'auto'." );
43          }
44          try
45          {
46              this.debug = Debug.valueOf( debug.toUpperCase() );
47          }
48          catch ( IllegalArgumentException e )
49          {
50              throw new IllegalArgumentException( "android.sign.debug must be 'true', 'false', 'both' or 'auto'.", e );
51          }
52      }
53  
54      public AndroidSigner( Debug debug )
55      {
56          this.debug = debug;
57      }
58  
59      public boolean isSignWithDebugKeyStore()
60      {
61          if ( debug == Debug.TRUE )
62          {
63              return true;
64          }
65          if ( debug == Debug.BOTH )
66          {
67              return true;
68          }
69          if ( debug == Debug.FALSE )
70          {
71              return false;
72          }
73          if ( debug == Debug.AUTO )
74          {
75              //TODO: This is where to add logic for skipping debug sign if there are other keystores configured.
76              return true;
77          }
78          throw new IllegalStateException( "Could not determine whether to sign with debug keystore." );
79      }
80  
81      public boolean shouldCreateBothSignedAndUnsignedApk()
82      {
83          return debug == Debug.BOTH;
84      }
85  
86  }