Mercurial > public > develkit
comparison init20.gradle @ 215:5bebb590b30e
DEP-11: determine project version based on branch
author | smith@nwoca.org |
---|---|
date | Tue, 28 Jun 2016 23:01:21 +0100 |
parents | 0ca4f3c952b7 |
children | b628d49d2891 |
comparison
equal
deleted
inserted
replaced
214:0ca4f3c952b7 | 215:5bebb590b30e |
---|---|
1 import groovy.sql.Sql | 1 import groovy.sql.Sql |
2 import groovy.transform.Sortable | |
2 import groovy.transform.ToString | 3 import groovy.transform.ToString |
4 import groovy.transform.TupleConstructor | |
3 | 5 |
4 buildscript { | 6 buildscript { |
5 repositories { | 7 repositories { |
6 maven { url 'http://repos.ssdt.nwoca.org/artifactory/gradle-plugins' } | 8 maven { url 'http://repos.ssdt.nwoca.org/artifactory/gradle-plugins' } |
7 maven { url 'http://repos.ssdt.nwoca.org/artifactory/ssdt-repo' } | 9 maven { url 'http://repos.ssdt.nwoca.org/artifactory/ssdt-repo' } |
71 | 73 |
72 gradle.ext.branch = new BranchInfo(System.getenv('bamboo_planRepository_branch')) | 74 gradle.ext.branch = new BranchInfo(System.getenv('bamboo_planRepository_branch')) |
73 gradle.ext.branchName = gradle.branch.name | 75 gradle.ext.branchName = gradle.branch.name |
74 gradle.ext.branchStream = gradle.branch.stream | 76 gradle.ext.branchStream = gradle.branch.stream |
75 gradle.ext.branchHash = gradle.branch.hash | 77 gradle.ext.branchHash = gradle.branch.hash |
76 println "${gradle.hgRepositoryUrl} ${gradle.branch} ${gradle.branch.imageId} ${gradle.branch.deployName}" | 78 println "${gradle.hgRepositoryUrl} ${gradle.branch} ${gradle.branch.version}" |
77 println "$gradle.runtimeInfo" | |
78 | 79 |
79 loadEnvironments() | 80 loadEnvironments() |
80 | 81 |
81 gradle.environment.put('hgRepositoryUrl', gradle.hgRepositoryUrl) | 82 gradle.environment.put('hgRepositoryUrl', gradle.hgRepositoryUrl) |
82 gradle.environment.put('branchName', gradle.branch.name) | 83 gradle.environment.put('branchName', gradle.branch.name) |
342 class ArtifactoryGradleSettings extends BuildAdapter implements BuildListener { | 343 class ArtifactoryGradleSettings extends BuildAdapter implements BuildListener { |
343 | 344 |
344 def void projectsEvaluated(Gradle gradle) { | 345 def void projectsEvaluated(Gradle gradle) { |
345 def ssdtArtifactory = 'http://repos.ssdt.nwoca.org/artifactory' | 346 def ssdtArtifactory = 'http://repos.ssdt.nwoca.org/artifactory' |
346 Project root = gradle.getRootProject() | 347 Project root = gradle.getRootProject() |
348 | |
349 | |
350 def branchVersioning = gradle.rootProject.version == 'unspecified' | |
351 | |
347 root.allprojects { | 352 root.allprojects { |
348 | 353 |
349 def thisProject = delegate | 354 def thisProject = delegate |
350 thisProject.status = 'integration' | 355 thisProject.status = 'integration' |
351 if (gradle.branchStream) { | 356 if (gradle.branchStream) { |
352 thisProject.status = 'integration' | 357 if (branchVersioning) { |
353 def fixupVersion = thisProject.version - ".SNAPSHOT" | 358 thisProject.version = gradle.branch.version |
354 if (gradle.branchStream == 'feature') { | 359 thisProject.status = gradle.branch.defaultDependencyStatus |
355 fixupVersion = fixupVersion + ".SNAPSHOT" | 360 } else { |
356 } | 361 |
357 if (gradle.branchStream == 'develop') { | 362 thisProject.status = 'integration' |
358 fixupVersion = fixupVersion + ".SNAPSHOT" | 363 def fixupVersion = thisProject.version - ".SNAPSHOT" |
359 } | 364 if (gradle.branchStream == 'feature') { |
360 if (gradle.branchStream in ['production', 'release','hotfix']) { | 365 fixupVersion = fixupVersion + ".SNAPSHOT" |
361 thisProject.status = 'release' | 366 } |
362 } | 367 if (gradle.branchStream == 'develop') { |
363 thisProject.version = fixupVersion | 368 fixupVersion = fixupVersion + ".SNAPSHOT" |
369 } | |
370 if (gradle.branchStream in ['production', 'release', 'hotfix']) { | |
371 thisProject.status = 'release' | |
372 } | |
373 thisProject.version = fixupVersion | |
374 } | |
364 } | 375 } |
365 | 376 |
366 configurations.all { | 377 configurations.all { |
367 resolutionStrategy.cacheChangingModulesFor gradle.cacheTimeout, 'seconds' | 378 resolutionStrategy.cacheChangingModulesFor gradle.cacheTimeout, 'seconds' |
368 resolutionStrategy.cacheDynamicVersionsFor gradle.cacheTimeout, 'seconds' | 379 resolutionStrategy.cacheDynamicVersionsFor gradle.cacheTimeout, 'seconds' |
580 } | 591 } |
581 | 592 |
582 } | 593 } |
583 | 594 |
584 | 595 |
596 @TupleConstructor | |
597 @Sortable | |
598 class Version { | |
599 | |
600 Integer major = 0 | |
601 Integer minor = 0 | |
602 Integer patch = 0 | |
603 Boolean snapshot = true | |
604 | |
605 Version nextVersion() { | |
606 new Version(major, minor + 1, 0) | |
607 } | |
608 | |
609 String toString() { | |
610 "${major}.${minor}.${patch}${snapshot ? '.SNAPSHOT' : ''}" | |
611 } | |
612 | |
613 } | |
614 | |
615 | |
585 @ToString(includes=['name','shortName','buildVersion','imageId','deployName'],includeNames= true) | 616 @ToString(includes=['name','shortName','buildVersion','imageId','deployName'],includeNames= true) |
586 class BranchInfo { | 617 class BranchInfo { |
587 def name | 618 def name |
588 def stream = "none" | 619 def stream = "none" |
589 def buildNumber = "" | 620 def buildNumber = "" |
590 def changeset = "" | 621 def changeset = "" |
622 def version | |
591 | 623 |
592 BranchInfo(name) { | 624 BranchInfo(name) { |
593 this.name = name | 625 this.name = name |
594 if (!name) { | 626 if (!name) { |
595 this.name = determineName() ?: '' | 627 this.name = determineName() ?: '' |
596 } | 628 } |
597 this.name = this.name.replace('@', '-') | 629 this.name = this.name.replace('@', '-') |
598 determineStream() | 630 determineStream() |
599 buildNumber = System.getenv('bamboo_buildNumber') ?: "" | 631 buildNumber = System.getenv('bamboo_buildNumber') ?: "" |
600 changeset = System.getenv('bamboo_planRepository_revision') ?: "" | 632 changeset = System.getenv('bamboo_planRepository_revision') ?: "" |
601 | |
602 } | 633 } |
603 | 634 |
604 String getDefaultDependencyStatus() { | 635 String getDefaultDependencyStatus() { |
605 return stream in ['release','hotfix'] ? 'release' : 'integration' | 636 return isRelease() ? 'release' : 'integration' |
606 } | 637 } |
607 | 638 |
608 def getShortName() { | 639 private boolean isRelease() { |
640 return stream in ['release', 'hotfix'] | |
641 } | |
642 | |
643 def getShortName() { | |
609 def result = name.contains('/') ? name.split('/')[1] : name | 644 def result = name.contains('/') ? name.split('/')[1] : name |
610 } | 645 } |
611 | 646 |
612 def getBuildVersion() { | 647 String getBuildVersion() { |
613 stream in ['release','hotfix'] ? shortName - "v": "" | 648 def v = isRelease() ? shortName - "v": "" |
614 } | 649 return v |
615 | 650 } |
616 def getImageId() { | 651 |
652 def Version getVersion() { | |
653 if (!version) { | |
654 if (isRelease()) { | |
655 version = new Version(*getBuildVersion().split('\\.')*.toInteger(), false) | |
656 } else { | |
657 version = findSnapshotVersion() | |
658 } | |
659 } | |
660 return version | |
661 } | |
662 | |
663 def getImageId() { | |
617 (buildVersion ?: shortName.take(25)) + (buildNumber ? "-${buildNumber}" : "-0") | 664 (buildVersion ?: shortName.take(25)) + (buildNumber ? "-${buildNumber}" : "-0") |
618 } | 665 } |
619 | 666 |
620 def getDeployName() { | 667 def getDeployName() { |
621 (buildVersion ?: shortName.take(25)).toLowerCase().collectReplacements { | 668 (buildVersion ?: shortName.take(25)).toLowerCase().collectReplacements { |
629 def generateMD5(String s) { | 676 def generateMD5(String s) { |
630 def digest = java.security.MessageDigest.getInstance("MD5") | 677 def digest = java.security.MessageDigest.getInstance("MD5") |
631 digest.update(s.bytes); | 678 digest.update(s.bytes); |
632 new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') | 679 new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') |
633 } | 680 } |
681 | |
682 private findSnapshotVersion() { | |
683 def versions = "hg branches --closed".execute().text.split('\n').findAll { | |
684 it.startsWith( 'release') || it.startsWith( 'hotfix') | |
685 }.collect { | |
686 it.replaceAll('\\s+',' ').split(' ')[0].split('/')[1] - 'v' | |
687 }.collect { | |
688 new Version(*it.split('\\.')*.toInteger()) | |
689 }.sort { v1, v2 -> v2 <=> v1 } | |
690 | |
691 return versions ? versions.first().nextVersion() : new Version().nextVersion() | |
692 | |
693 } | |
694 | |
634 | 695 |
635 def determineName() { | 696 def determineName() { |
636 try { | 697 try { |
637 def branch = "hg branch".execute().text.trim() | 698 def branch = "hg branch".execute().text.trim() |
638 def rawParents = 'hg parents'.execute().text | 699 def rawParents = 'hg parents'.execute().text |