JAL-3130 adapted getdown src. attempt 2. first attempt failed due to cp'ed .git files
[jalview.git] / getdown / src / getdown / ant / src / main / java / com / threerings / getdown / tools / DigesterTask.java
1 //
2 // Getdown - application installer, patcher and launcher
3 // Copyright (C) 2004-2018 Getdown authors
4 // https://github.com/threerings/getdown/blob/master/LICENSE
5
6 package com.threerings.getdown.tools;
7
8 import java.io.File;
9 import java.io.IOException;
10
11 import java.security.GeneralSecurityException;
12
13 import org.apache.tools.ant.BuildException;
14 import org.apache.tools.ant.Task;
15
16 import com.threerings.getdown.data.Digest;
17
18 /**
19  * An ant task used to create a <code>digest.txt</code> for a Getdown
20  * application deployment.
21  */
22 public class DigesterTask extends Task
23 {
24     /**
25      * Sets the application directory.
26      */
27     public void setAppdir (File appdir)
28     {
29         _appdir = appdir;
30     }
31
32     /**
33      * Sets the digest signing keystore.
34      */
35     public void setKeystore (File path)
36     {
37         _storepath = path;
38     }
39
40     /**
41      * Sets the keystore decryption key.
42      */
43     public void setStorepass (String password)
44     {
45         _storepass = password;
46     }
47
48     /**
49      * Sets the private key alias.
50      */
51     public void setAlias (String alias)
52     {
53         _storealias = alias;
54     }
55
56     /**
57      * Performs the actual work of the task.
58      */
59     @Override
60     public void execute () throws BuildException
61     {
62         // make sure appdir is set
63         if (_appdir == null) {
64             throw new BuildException("Must specify the path to the application directory " +
65                                      "via the 'appdir' attribute.");
66         }
67
68         // make sure _storepass and _keyalias are set, if _storepath is set
69         if (_storepath != null && (_storepass == null || _storealias == null)) {
70             throw new BuildException(
71                     "Must specify both a keystore password and a private key alias.");
72         }
73
74         try {
75             Digester.createDigests(_appdir, _storepath, _storepass, _storealias);
76         } catch (IOException ioe) {
77             throw new BuildException("Error creating digest: " + ioe.getMessage(), ioe);
78         } catch (GeneralSecurityException gse) {
79             throw new BuildException("Error creating signature: " + gse.getMessage(), gse);
80         }
81     }
82
83     /** The application directory in which we're creating a digest file. */
84     protected File _appdir;
85
86     /** The path to the keystore we'll use to sign the digest file, if any. */
87     protected File _storepath;
88
89     /** The decryption key for the keystore. */
90     protected String _storepass;
91
92     /** The private key alias. */
93     protected String _storealias;
94 }