Skip to content

Commit

Permalink
Merge pull request #3 from IntershopCommunicationsAG/simplereleasechange
Browse files Browse the repository at this point in the history
change behaviour of simple release plugin
  • Loading branch information
m-raab authored Jul 8, 2016
2 parents 6832619 + 5ed5292 commit 071d8eb
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 17 deletions.
3 changes: 2 additions & 1 deletion README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ This kind of configuration is also easier to maintain on the CI server.
|===
| System variable or Java system property | Project property | Description

| *RUNONCI* | *runOnCI* | This configuration must be true, if the project is used on a CI server.
| *RUNONCI* | *runOnCI* | This configuration must be true, if the project is used on a CI server. The version will be extended with '-LOCAL', if this value is false.

| *SNAPSHOTURL* | *snapshotURL* | Snapshot URL for publishing of snapshot builds
| *RELEASEURL* | *releaseURL* | Release URL for publishing of release builds without staging.
| *REPO_USER_NAME* | *repoUserName* | The username with the correct role/permissions for transfer
| *REPO_USER_PASSWD* | *repoUserPasswd* | The password of the user.
| *SNAPSHOT_RELEASE* | *snapshotRelease* | The version will be extended with '-SNAPSHOT' and snapshot repositories are used if this value is set to 'true'.
|===

== Nexus Publish Configuration Plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ class PublishConfigurationPlugin implements Plugin<Project> {
/*
* Repository user name
*/
final static String REPO_USER_NAME_ENV = 'repoUserName'
final static String REPO_USER_NAME_PRJ = 'REPO_USER_NAME'
final static String REPO_USER_NAME_ENV = 'REPO_USER_NAME '
final static String REPO_USER_NAME_PRJ = 'repoUserName'

/*
* Repository user password
*/
final static String REPO_USER_PASSWD_ENV = 'repoUserPasswd'
final static String REPO_USER_PASSWD_PRJ = 'REPO_USER_PASSWD'
final static String REPO_USER_PASSWD_ENV = 'REPO_USER_PASSWD'
final static String REPO_USER_PASSWD_PRJ = 'repoUserPasswd'

/**
* SNAPSHOT RELEASE
*/
final static String SNAPSHOT_RELEASE_ENV = 'SNAPSHOT_RELEASE'
final static String SNAPSHOT_RELEASE_PRJ = 'snapshotRelease'

// publication names
public final static String IVYREPONAME = 'intershopIvyCI'
Expand All @@ -57,6 +63,9 @@ class PublishConfigurationPlugin implements Plugin<Project> {
String runOnCI = getVariable(project, RUNONCI_ENV, RUNONCI_PRJ, 'false')
project.logger.info('Publishing Configuration: RunOnCI: {}', runOnCI.toBoolean())

//provide compatibility with the repo config plung
project.ext.useSCMVersionConfig = 'true'

if (runOnCI.toBoolean()) {
project.logger.info('Simple release publishing configuration will be applied to project {}', project.name)

Expand All @@ -66,34 +75,42 @@ class PublishConfigurationPlugin implements Plugin<Project> {
String repoReleaseURL = getVariable(project, RELEASE_URL_ENV, RELEASE_URL_PRJ, '')
String repoSnapshotURL = getVariable(project, SNAPSHOT_URL_ENV, SNAPSHOT_URL_PRJ, '')

String snapshotRelease = getVariable(project, SNAPSHOT_RELEASE_ENV, SNAPSHOT_RELEASE_PRJ, 'false')

if(repoSnapshotURL) {
println repoSnapshotURL
applySnapshotPublishing(project, repoSnapshotURL, repoUserLogin, repoUserPassword)
applySnapshotPublishing(project, repoSnapshotURL, repoUserLogin, repoUserPassword, snapshotRelease.toLowerCase() == 'true')
}
if(repoReleaseURL) {
applyReleasePublishing(project, repoReleaseURL, repoUserLogin, repoUserPassword)
}

project.rootProject.rootProject.afterEvaluate {
project.rootProject.afterEvaluate {
if(snapshotRelease.toLowerCase() == 'true') {
project.version = "$project.version-SNAPSHOT"
}
if(! project.version.endsWith('-SNAPSHOT')) {
// add javadoc to root project
project.getRootProject().ext.releaseWithJavaDoc = 'true'
// add javadoc to sub project
project.getRootProject().getSubprojects().each { Project subp ->
subp.ext.releaseWithJavaDoc = 'true'
}
} else {
System.setProperty('ENABLE_SNAPSHOTS', 'true')
}
}
} else {
project.rootProject.afterEvaluate {
project.logger.info('Project runs local! Local configuration will be set.')
project.status = 'local'
project.version = "$project.version-LOCAL"
}
}
}

private void applySnapshotPublishing(Project p, String snapshotURL, String repoUser, String repoUserPasswd) {
private void applySnapshotPublishing(Project p, String snapshotURL, String repoUser, String repoUserPasswd, boolean useSnapShotRepo = false) {
p.plugins.withType(IvyPublishPlugin) {
p.publishing {
repositories {
if (!delegate.findByName(IVYREPONAME) && p.version.endsWith('-SNAPSHOT')) {
if (!delegate.findByName(IVYREPONAME) && (p.version.endsWith('-SNAPSHOT') || useSnapShotRepo)) {
p.logger.info('Add Ivy publishing repository')
ivy {
name IVYREPONAME
Expand All @@ -111,7 +128,7 @@ class PublishConfigurationPlugin implements Plugin<Project> {
}
}
p.repositories {
if (!delegate.findByName(IVYREPONAME) && p.version.endsWith('-SNAPSHOT')) {
if (!delegate.findByName(IVYREPONAME) && (p.version.endsWith('-SNAPSHOT') || useSnapShotRepo)) {
p.logger.info('Ivy repository {} added to the project repository configuration', IVYREPONAME)
ivy {
name IVYREPONAME
Expand All @@ -130,7 +147,7 @@ class PublishConfigurationPlugin implements Plugin<Project> {
p.plugins.withType(MavenPublishPlugin) {
p.publishing {
repositories {
if (!delegate.findByName(MVNREPOName) && p.version.endsWith('-SNAPSHOT')) {
if (!delegate.findByName(MVNREPOName) && (p.version.endsWith('-SNAPSHOT') || useSnapShotRepo)) {
p.logger.info('Add Mvn publishing repository')
maven {
name MVNREPOName
Expand All @@ -147,7 +164,7 @@ class PublishConfigurationPlugin implements Plugin<Project> {
}
}
p.repositories {
if (!delegate.findByName(MVNREPOName) && p.version.endsWith('-SNAPSHOT')) {
if (!delegate.findByName(MVNREPOName) && (p.version.endsWith('-SNAPSHOT') || useSnapShotRepo)) {
p.logger.info('Mvn repository {} added to the project repository configuration', MVNREPOName)
maven {
name MVNREPOName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class TestDispatcher {
String line = request.getRequestLine()
String path = request.getPath()

//GET /nexusnexus/service/local/staging/profile_evaluate?t=maven2&g=com.intershop.project&a=project1a&v=1.0.0

if(path.startsWith('/nexus/service/local/staging/profile_evaluate')) {
MockResponse nexus_response = new MockResponse()
.addHeader("Content-Type", "application/json; charset=utf-8")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,101 @@ class SingleProjectSpec extends AbstractIntegrationSpec {
upLoadListCheck
}

def 'test snapshot publishing with internal version changes'() {
given:
String urlStr = server.url('/').toString()
List<String> upLoadList = []
Map<String,String> responses = [:]

server.setDispatcher(TestDispatcher.getIntegrationDispatcher(responses, upLoadList))

buildFile << """
plugins {
id 'java'
id 'ivy-publish'
id 'com.intershop.gradle.simplepublish-configuration'
}
group = 'com.intershop'
version = '1.0.0'
publishing {
publications {
ivy(IvyPublication) {
from components.java
}
}
}
""".stripIndent()

File settingsfile = file('settings.gradle')
settingsfile << """
// define root proejct name
rootProject.name = 'p_testProject'
""".stripIndent()
writeJavaTestClass("com.intershop.test")

when:
def result = getPreparedGradleRunner()
.withArguments('publish', "-DRUNONCI=true", "-PsnapshotURL=${urlStr}nexus/snapshots", "-PreleaseURL=${urlStr}nexus/releases", '-PrepoUserName=admin', '-PrepoUserPasswd=admin123', '-PsnapshotRelease=true', '-s')
.build()

boolean upLoadListCheck = true

upLoadList.each {
upLoadListCheck &= it.contains('/nexus/snapshots')
}

then:
upLoadListCheck
}

def 'test local publishing'() {
given:
String urlStr = server.url('/').toString()
List<String> upLoadList = []
Map<String,String> responses = [:]

buildFile << """
plugins {
id 'java'
id 'ivy-publish'
id 'com.intershop.gradle.simplepublish-configuration'
}
group = 'com.intershop'
version = '1.0.0'
publishing {
publications {
ivy(IvyPublication) {
from components.java
}
}
repositories {
ivy {
url "\$buildDir/repo"
}
}
}
""".stripIndent()

File settingsfile = file('settings.gradle')
settingsfile << """
// define root proejct name
rootProject.name = 'p_testProject'
""".stripIndent()
writeJavaTestClass("com.intershop.test")

when:
def result = getPreparedGradleRunner()
.withArguments('publish', "-PsnapshotURL=${urlStr}nexus/snapshots", "-PreleaseURL=${urlStr}nexus/releases", '-PrepoUserName=admin', '-PrepoUserPasswd=admin123', '-s')
.build()

then:
(new File(testProjectDir, 'build/publications/ivy/ivy.xml')).text.contains('1.0.0-LOCAL')
(new File(testProjectDir, 'build/libs/p_testProject-1.0.0-LOCAL.jar')).exists()
}

}

0 comments on commit 071d8eb

Please sign in to comment.