groovy.com.cedarsolutions.gradle.CedarLabelPluginConvention.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cedar-build Show documentation
Show all versions of cedar-build Show documentation
Gradle plugins and other functionality for use with a standardized build process.
// vim: set ft=groovy ts=4 sw=4:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *
// * C E D A R
// * S O L U T I O N S "Software done right."
// * S O F T W A R E
// *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *
// * Copyright (c) 2013,2015 Kenneth J. Pronovici.
// * All rights reserved.
// *
// * This program is free software; you can redistribute it and/or
// * modify it under the terms of the Apache License, Version 2.0.
// * See LICENSE for more information about the licensing terms.
// *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *
// * Author : Kenneth J. Pronovici
// * Language : Gradle (>= 2.5)
// * Project : Common Gradle Build Functionality
// *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package com.cedarsolutions.gradle
import org.gradle.api.Project
import org.gradle.plugins.signing.Sign
import org.gradle.api.InvalidUserDataException
/**
* Plugin convention for cedarLabel.
* @author Kenneth J. Pronovici
*/
class CedarLabelPluginConvention {
/** The project tied to this convention. */
private Project project;
/** Create a convention tied to a project. */
public CedarLabelPluginConvention(Project project) {
this.project = project
}
/** Label Mercurial repositories per configuration. */
def labelMercurialRepositories() {
def enabled = project.cedarLabel.isEnabled()
if (!enabled) {
project.logger.lifecycle("CedarBuild label tool: labeling is disabled")
} else {
def projectName = project.cedarLabel.getProjectName()
def projectVersion = project.cedarLabel.getProjectVersion()
def repositories = project.cedarLabel.getRepositories()
def mercurialPath = project.cedarLabel.getMercurialPath()
if (repositories == null || repositories.isEmpty()) {
project.logger.lifecycle("CedarBuild label tool: no Mercurial repositories to label")
} else {
def label = generateLabel(projectName, projectVersion)
project.logger.lifecycle("CedarBuild label tool: applying ${label}")
repositories.each { repository ->
project.logger.lifecycle(" --> ${repository}")
project.ant.exec(executable: mercurialPath, dir: repository, failonerror: "true") {
arg(value: "tag")
arg(value: "-f")
arg(value: label)
}
}
}
}
}
/** Generate a standard label based on name and version. */
def generateLabel(String projectName, String projectVersion) {
def timestamp = new Date().format("yyyyMMddHHmmssSSS", TimeZone.getTimeZone("UTC"))
def label = "${projectName}__v${projectVersion}__${timestamp}"
return label.replace(":", "").replace(" ", "_") // Mercurial doesn't allow colon or space in tag name
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy