Search in sources :

Example 1 with SignatureType

use of org.gradle.plugins.signing.type.SignatureType in project gradle by gradle.

the class Signature method getFile.

/**
 * The file for the generated signature, which may not yet exist.
 *
 * <p>The file will be placed alongside the {@link #getToSign() file to sign} with the extension of the {@link #getSignatureType() signature type}.
 *
 * @return The signature file. May be {@code null} if unknown at this time.
 * @see SignatureType#fileFor(File)
 */
@Override
@OutputFile
public File getFile() {
    File toSign = getToSign();
    SignatureType signatureType = getSignatureType();
    return toSign != null && signatureType != null ? signatureType.fileFor(toSign) : null;
}
Also used : SignatureType(org.gradle.plugins.signing.type.SignatureType) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) InputFile(org.gradle.api.tasks.InputFile) OutputFile(org.gradle.api.tasks.OutputFile)

Example 2 with SignatureType

use of org.gradle.plugins.signing.type.SignatureType in project gradle by gradle.

the class Signature method generate.

/**
 * Generates the signature file.
 *
 * <p>In order to generate the signature, the {@link #getToSign() file to sign}, {@link #getSignatory() signatory} and {@link #getSignatureType() signature type} must be known (i.e. non {@code
 * null}).</p>
 *
 * @throws InvalidUserDataException if the there is insufficient information available to generate the signature.
 */
public void generate() {
    File toSign = getToSign();
    if (toSign == null) {
        if (signatureSpec.isRequired()) {
            throw new InvalidUserDataException("Unable to generate signature as the file to sign has not been specified");
        } else {
            return;
        }
    }
    Signatory signatory = getSignatory();
    if (signatory == null) {
        if (signatureSpec.isRequired()) {
            throw new InvalidUserDataException("Unable to generate signature for \'" + toSign + "\' as no signatory is available to sign");
        } else {
            return;
        }
    }
    SignatureType signatureType = getSignatureType();
    if (signatureType == null) {
        if (signatureSpec.isRequired()) {
            throw new InvalidUserDataException("Unable to generate signature for \'" + toSign + "\' as no signature type has been configured");
        } else {
            return;
        }
    }
    signatureType.sign(signatory, toSign);
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) Signatory(org.gradle.plugins.signing.signatory.Signatory) SignatureType(org.gradle.plugins.signing.type.SignatureType) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) InputFile(org.gradle.api.tasks.InputFile)

Example 3 with SignatureType

use of org.gradle.plugins.signing.type.SignatureType in project gradle by gradle.

the class Signature method defaultFile.

@Nullable
private File defaultFile() {
    File toSign = getToSign();
    SignatureType signatureType = getSignatureType();
    return toSign != null && signatureType != null ? signatureType.fileFor(toSign) : null;
}
Also used : SignatureType(org.gradle.plugins.signing.type.SignatureType) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 4 with SignatureType

use of org.gradle.plugins.signing.type.SignatureType in project gradle by gradle.

the class Signature method defaultType.

@Nullable
private String defaultType() {
    File toSign = getToSign();
    SignatureType signatureType = getSignatureType();
    return toSign != null && signatureType != null ? signatureType.combinedExtension(toSign) : null;
}
Also used : SignatureType(org.gradle.plugins.signing.type.SignatureType) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) InputFile(org.gradle.api.tasks.InputFile) Nullable(javax.annotation.Nullable)

Example 5 with SignatureType

use of org.gradle.plugins.signing.type.SignatureType in project gradle by gradle.

the class SigningExtension method addSignatureSpecConventions.

/**
 * Adds conventions to the given spec, using this settings object's default signatory and signature type as the default signatory and signature type for the spec.
 */
protected void addSignatureSpecConventions(SignatureSpec spec) {
    if (!(spec instanceof IConventionAware)) {
        throw new InvalidUserDataException("Cannot add conventions to signature spec \'" + String.valueOf(spec) + "\' as it is not convention aware");
    }
    ConventionMapping conventionMapping = ((IConventionAware) spec).getConventionMapping();
    conventionMapping.map("signatory", new Callable<Signatory>() {

        @Override
        public Signatory call() {
            return getSignatory();
        }
    });
    conventionMapping.map("signatureType", new Callable<SignatureType>() {

        @Override
        public SignatureType call() {
            return getSignatureType();
        }
    });
    conventionMapping.map("required", new Callable<Boolean>() {

        @Override
        public Boolean call() {
            return isRequired();
        }
    });
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) Signatory(org.gradle.plugins.signing.signatory.Signatory) SignatureType(org.gradle.plugins.signing.type.SignatureType) DefaultTypeTransformation.castToBoolean(org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToBoolean) IConventionAware(org.gradle.api.internal.IConventionAware) ConventionMapping(org.gradle.api.internal.ConventionMapping)

Aggregations

SignatureType (org.gradle.plugins.signing.type.SignatureType)5 File (java.io.File)4 InputFile (org.gradle.api.tasks.InputFile)3 OutputFile (org.gradle.api.tasks.OutputFile)3 Nullable (javax.annotation.Nullable)2 InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 Signatory (org.gradle.plugins.signing.signatory.Signatory)2 DefaultTypeTransformation.castToBoolean (org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToBoolean)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 IConventionAware (org.gradle.api.internal.IConventionAware)1