Add intellij project files

This commit is contained in:
R. Tyler Croy 2015-04-18 21:00:03 -07:00
parent 29845b34c2
commit 9eec100c54
8 changed files with 1478 additions and 14 deletions

3
.gitignore vendored
View File

@ -4,3 +4,6 @@ build/
# Ignore Gradle GUI config
gradle-app.setting
*.sw*
// intellij
*.ipr
*.iws

View File

@ -9,6 +9,7 @@ buildscript {
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: "com.jfrog.bintray"
version = '0.1.0'
@ -73,3 +74,6 @@ artifacts {
archives groovydocJar
}
//////////////////////
defaultTasks 'check', 'assemble'

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,9 @@ abstract class AbstractScmHandler {
*/
abstract boolean isAvailable()
/** Return the current revision of the tree */
abstract String getRevision()
/** Return an annotated version string with data provided by the handler */
abstract String annotatedVersion(String baseVersion)

View File

@ -24,6 +24,16 @@ class GerritHandler extends AbstractScmHandler {
return this.env.containsKey(GERRIT_CHANGE)
}
/**
* Return the value of GERRIT_PATCHSET_REVISION if present
*/
String getRevision() {
if (this.env.containsKey(GERRIT_REVISION)) {
return this.env[GERRIT_REVISION]
}
return ""
}
/**
* Return a {@code String} based on the environment variables provided with
* Gerrit changeset information
@ -33,7 +43,7 @@ class GerritHandler extends AbstractScmHandler {
baseVersion,
this.env[GERRIT_CHANGE],
this.env[GERRIT_PATCH],
this.env[GERRIT_REVISION])
this.revision)
}

View File

@ -0,0 +1,46 @@
package com.github.lookout.serviceartifact.scm
import groovy.transform.TypeChecked
import org.ajoberstar.grgit.Grgit
/**
* Git handler for a project in a traditional Git repository
*/
@TypeChecked
class GitHandler extends AbstractScmHandler {
private Grgit _git = null
GitHandler(Map<String, String> environment) {
this.env = environment
}
boolean isAvailable() {
if (this.git != null) {
return true
}
return false
}
String getRevision() {
return ''
}
String annotatedVersion(String baseVersion) {
return baseVersion
}
@Override
static AbstractScmHandler build(Map<String, String> env) {
return new GitHandler(env)
}
/** Return an {@code Grgit} object for internal use */
private Grgit getGit() {
if (this._git == null) {
this._git = Grgit.open('.')
}
return this._git
}
}

View File

@ -3,35 +3,53 @@ package com.github.lookout.serviceartifact.scm
import spock.lang.*
class GerritHandlerSpec extends Specification {
protected GerritHandler handler
Map<String, String> gerritEnv() {
return [
'GERRIT_CHANGE_NUMBER' : 1,
'GERRIT_PATCHSET_NUMBER' : 1,
'GERRIT_PATCHSET_REVISION' : '0xdeadbeef',
]
}
def "isAvailable() should be false by default"() {
given:
this.handler = new GerritHandler([:])
def handler = new GerritHandler([:])
expect:
!this.handler.isAvailable()
!handler.isAvailable()
}
def "isAvailable() should be true if the env has Gerrit env vars"() {
given:
this.handler = new GerritHandler([
'GERRIT_CHANGE_NUMBER' : 1,
])
def handler = new GerritHandler(gerritEnv())
expect:
this.handler.isAvailable()
handler.isAvailable()
}
def "getRevision() should return an empty string by default"() {
given:
def handler = new GerritHandler([:])
expect:
handler.revision == ''
}
def "getRevision() should return the GERRIT_PATCHSET_REVISION when present"() {
given:
def handler = new GerritHandler(gerritEnv())
expect:
handler.revision == gerritEnv()['GERRIT_PATCHSET_REVISION']
}
def "annotatedVersion() should include change and patchset numbers, and SHA1"() {
given:
this.handler = new GerritHandler([
'GERRIT_CHANGE_NUMBER' : 1,
'GERRIT_PATCHSET_NUMBER' : 1,
'GERRIT_PATCHSET_REVISION' : '0xdeadbeef',
])
def handler = new GerritHandler(gerritEnv())
when:
String version = this.handler.annotatedVersion('1.0')
String version = handler.annotatedVersion('1.0')
then:
version == '1.0.1.1+0xdeadbeef'

View File

@ -0,0 +1,51 @@
package com.github.lookout.serviceartifact.scm
import spock.lang.*
import org.ajoberstar.grgit.Grgit
class GitHandlerSpec extends Specification {
def "isAvailable() should be false by default"() {
given:
def handler = Spy(GitHandler, constructorArgs: [[:]])
1 * handler.getProperty('git') >> null
expect:
!handler.isAvailable()
}
def "isAvailable() should be true if .git is present"() {
given:
def handler = Spy(GitHandler, constructorArgs: [[:]])
def gitMock = Mock(Grgit)
1 * handler.getProperty('git') >> gitMock
expect:
handler.isAvailable()
}
def "annotatedVersion() when .git is NOT present should no-op"() {
given:
def handler = new GitHandler([:])
when:
String version = handler.annotatedVersion('1.0')
then:
version == '1.0'
}
@Ignore
def "annotatedVersion() when .git is present should include SHA+1"() {
given:
def handler = new GitHandler([:])
when:
String version = handler.annotatedVersion('1.0')
then:
version == '1.0+0xdeadbeef'
}
}