X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=getdown%2Fsrc%2Fgetdown%2Fant%2Fsrc%2Fmain%2Fjava%2Fcom%2Fthreerings%2Fgetdown%2Ftools%2FDigesterTask.java;fp=getdown%2Fsrc%2Fgetdown%2Fant%2Fsrc%2Fmain%2Fjava%2Fcom%2Fthreerings%2Fgetdown%2Ftools%2FDigesterTask.java;h=48cc8d426f21c576e2a52711747c869c6aec370c;hb=aace9d05c0870c703bfdfb28c1608213cee019bf;hp=0000000000000000000000000000000000000000;hpb=2a3bac30ae8290e912eb7ffe7ff7ec700b6cfaac;p=jalview.git diff --git a/getdown/src/getdown/ant/src/main/java/com/threerings/getdown/tools/DigesterTask.java b/getdown/src/getdown/ant/src/main/java/com/threerings/getdown/tools/DigesterTask.java new file mode 100644 index 0000000..48cc8d4 --- /dev/null +++ b/getdown/src/getdown/ant/src/main/java/com/threerings/getdown/tools/DigesterTask.java @@ -0,0 +1,94 @@ +// +// Getdown - application installer, patcher and launcher +// Copyright (C) 2004-2018 Getdown authors +// https://github.com/threerings/getdown/blob/master/LICENSE + +package com.threerings.getdown.tools; + +import java.io.File; +import java.io.IOException; + +import java.security.GeneralSecurityException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +import com.threerings.getdown.data.Digest; + +/** + * An ant task used to create a digest.txt for a Getdown + * application deployment. + */ +public class DigesterTask extends Task +{ + /** + * Sets the application directory. + */ + public void setAppdir (File appdir) + { + _appdir = appdir; + } + + /** + * Sets the digest signing keystore. + */ + public void setKeystore (File path) + { + _storepath = path; + } + + /** + * Sets the keystore decryption key. + */ + public void setStorepass (String password) + { + _storepass = password; + } + + /** + * Sets the private key alias. + */ + public void setAlias (String alias) + { + _storealias = alias; + } + + /** + * Performs the actual work of the task. + */ + @Override + public void execute () throws BuildException + { + // make sure appdir is set + if (_appdir == null) { + throw new BuildException("Must specify the path to the application directory " + + "via the 'appdir' attribute."); + } + + // make sure _storepass and _keyalias are set, if _storepath is set + if (_storepath != null && (_storepass == null || _storealias == null)) { + throw new BuildException( + "Must specify both a keystore password and a private key alias."); + } + + try { + Digester.createDigests(_appdir, _storepath, _storepass, _storealias); + } catch (IOException ioe) { + throw new BuildException("Error creating digest: " + ioe.getMessage(), ioe); + } catch (GeneralSecurityException gse) { + throw new BuildException("Error creating signature: " + gse.getMessage(), gse); + } + } + + /** The application directory in which we're creating a digest file. */ + protected File _appdir; + + /** The path to the keystore we'll use to sign the digest file, if any. */ + protected File _storepath; + + /** The decryption key for the keystore. */ + protected String _storepass; + + /** The private key alias. */ + protected String _storealias; +}