Skip to content

Commit

Permalink
Check for dependency filetypes ear, jar, war
Browse files Browse the repository at this point in the history
Issue IBM#8
  • Loading branch information
banjaxxer committed Aug 9, 2019
1 parent 1f9e3fb commit af1d89e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/main/groovy/com/ibm/cics/cbgp/CICSBundleBuilderTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.gradle.api.tasks.TaskAction
class CICSBundleBuilderTask extends DefaultTask {

public static final String CICS_BUNDLE_CONFIG_NAME = "cicsBundle"
public static final List validDependencyFileExtensions = ['ear', 'jar', 'war']

@TaskAction
def buildCICSBundle() {
Expand Down Expand Up @@ -56,6 +57,7 @@ class CICSBundleBuilderTask extends DefaultTask {
}
into "$project.buildDir/$project.name-$project.version"
}
checkCopiedFileExtensions(filesCopied)
checkDependenciesCopied(filesCopied, config)
}

Expand Down Expand Up @@ -91,4 +93,23 @@ class CICSBundleBuilderTask extends DefaultTask {
throw new GradleException("Failed, missing dependencies from '$CICS_BUNDLE_CONFIG_NAME' configuration")
}
}

private void checkCopiedFileExtensions(List filesCopied) {
def allExtensionsOk = true
filesCopied.each() {
def name = it.name
def splits = name.split('\\.')
def extension = splits[splits.length - 1]
def extensionOK = (splits.size() >= 2 && validDependencyFileExtensions.contains(extension))
if (!extensionOK) {
println("Invalid file extension '$extension' for copied dependency '$it.path'")
allExtensionsOk = false
}
}
if (!allExtensionsOk) {
throw new GradleException("Unsupported file extensions for some dependencies")
}

}

}
83 changes: 79 additions & 4 deletions src/test/groovy/com/ibm/cics/cbgp/ChecksAndCopyTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ChecksAndCopyTests extends Specification {
buildFile = testProjectDir.newFile('build.gradle')
}

def "Test jcenter central external module dependency"() {
def "Test jcenter jar dependency"() {
given:
settingsFile << "rootProject.name = 'cics-bundle-gradle'"
buildFile << """\
Expand Down Expand Up @@ -66,15 +66,15 @@ class ChecksAndCopyTests extends Specification {
.withArguments('buildCICSBundle')
.withPluginClasspath()
.build()
printTestOutput(result,"Test jcenter central external module dependency")
printTestOutput(result,"Test jcenter jar dependency")

then:
assert result.output.contains('javax.servlet-api-3.1.0.jar')
assert (getFileInBuildOutputFolder('/javax.servlet-api-3.1.0.jar').exists())
result.task(":buildCICSBundle").outcome == SUCCESS
}

def "Test maven central external module dependency"() {
def "Test maven war dependency"() {
given:
settingsFile << "rootProject.name = 'cics-bundle-gradle'"
buildFile << """\
Expand Down Expand Up @@ -103,7 +103,7 @@ class ChecksAndCopyTests extends Specification {
.withArguments('buildCICSBundle')
.withPluginClasspath()
.build()
printTestOutput(result,"Test maven central external module dependency")
printTestOutput(result,"Test maven war dependency")

then:
assert result.output.contains('org.glassfish.main.admingui')
Expand All @@ -112,6 +112,44 @@ class ChecksAndCopyTests extends Specification {
result.task(":buildCICSBundle").outcome == SUCCESS
}

def "Test maven ear dependency"() {
given:
settingsFile << "rootProject.name = 'cics-bundle-gradle'"
buildFile << """\
plugins {
id 'cics-bundle-gradle-plugin'
}
version '1.0.0-SNAPSHOT'
repositories {
mavenCentral()
}
configurations {
cicsBundle
}
dependencies {
cicsBundle(group: 'org.codehaus.cargo', name: 'simple-ear', version: '1.7.6', ext: 'ear' )
}
"""

when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('buildCICSBundle')
.withPluginClasspath()
.build()
printTestOutput(result,"Test maven ear dependency")

then:
assert result.output.contains('org.codehaus.cargo')
assert result.output.contains('simple-ear-1.7.6.ear')
assert (getFileInBuildOutputFolder('/simple-ear-1.7.6.ear').exists())
result.task(":buildCICSBundle").outcome == SUCCESS
}

def "Test incorrect configuration name"() {
given:
settingsFile << "rootProject.name = 'cics-bundle-gradle'"
Expand Down Expand Up @@ -204,6 +242,43 @@ class ChecksAndCopyTests extends Specification {
result.task(":buildCICSBundle").outcome == SUCCESS
}

def "Test incorrect dependency extension"() {
given:
settingsFile << "rootProject.name = 'cics-bundle-gradle'"
buildFile << """\
plugins {
id 'cics-bundle-gradle-plugin'
}
version '1.0.0-SNAPSHOT'
repositories {
jcenter()
}
configurations {
cicsBundle
}
dependencies {
cicsBundle(group: 'org.apache.jmeter', name: 'apache-jmeter', version: '2.3.4-atlassian-1' )
}
"""

when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('buildCICSBundle')
.withPluginClasspath()
.buildAndFail()
printTestOutput(result,"Test incorrect dependency extension")

then:
assert result.output.contains('Unsupported file extensions for some dependencies')
assert result.output.contains("Invalid file extension 'gz' for copied dependency 'apache-jmeter-2.3.4-atlassian-1.tar.gz'")
result.task(":buildCICSBundle").outcome == FAILED
}

private void printTestOutput(BuildResult result, String testname) {
def title = "\n----- '$testname' output: -----"
println(title)
Expand Down

0 comments on commit af1d89e

Please sign in to comment.