Skip to content

Commit

Permalink
[bug] Closes #89 - shadow/application dists have wrongs files.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrengelman committed Aug 26, 2014
1 parent 0157ecc commit 885319c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ class ShadowApplicationPlugin implements Plugin<Project> {

protected <T extends AbstractArchiveTask> void addArchiveTask(Project project, String name, Class<T> type) {
ApplicationPluginConvention pluginConvention = project.convention.plugins.application
ShadowExtension extension = project.extensions.findByName(ShadowBasePlugin.EXTENSION_NAME)

def archiveTask = project.tasks.create(name, type)
archiveTask.description = "Bundles the project as a JVM application with libs and OS specific scripts."
archiveTask.group = ApplicationPlugin.APPLICATION_GROUP
archiveTask.conventionMapping.baseName = { pluginConvention.applicationName }
def baseDir = { archiveTask.archiveName - ".${archiveTask.extension}" }
archiveTask.into(baseDir) {
with(pluginConvention.applicationDistribution)
with(extension.applicationDistribution)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository
import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification
import org.apache.tools.zip.ZipFile
import org.gradle.testkit.functional.ExecutionResult
import spock.lang.Issue

import java.util.jar.Attributes
import java.util.jar.JarFile
Expand Down Expand Up @@ -215,7 +217,7 @@ class PublishingSpec extends PluginSpecification {
and: 'And that jar file as the correct files in it'
contains(installedJar, ['a.properties', 'a2.properties', 'myapp/Main.class'])

and: 'Check the manifest attributes in the jar file are corret'
and: 'Check the manifest attributes in the jar file are correct'
JarFile jar = new JarFile(installedJar)
Attributes attributes = jar.manifest.mainAttributes
assert attributes.getValue('Main-Class') == 'myapp.Main'
Expand All @@ -224,5 +226,69 @@ class PublishingSpec extends PluginSpecification {
File startScript = file('build/installShadow/myapp/bin/myapp')
assert startScript.exists()
assert startScript.text.contains("-jar \$APP_HOME/lib/myapp-1.0-all.jar")

cleanup:
jar?.close()
}

@Issue('SHADOW-89')
def 'shadow application distributions should use shadow jar'() {
given:
repo.module('shadow', 'a', '1.0')
.insertFile('a.properties', 'a')
.insertFile('a2.properties', 'a2')
.publish()

file('src/main/java/myapp/Main.java') << """
|package myapp;
|public class Main {
| public static void main(String[] args) {
| System.out.println("TestApp: Hello World! (" + args[0] + ")");
| }
|}
""".stripMargin()

buildFile << """
|apply plugin: ${ShadowPlugin.name}
|apply plugin: 'application'
|apply plugin: 'java'
|
|mainClassName = 'myapp.Main'
|
|version = '1.0'
|
|repositories {
| maven { url "${repo.uri}" }
|}
|
|dependencies {
| shadow 'shadow:a:1.0'
|}
|
|runShadow {
| args 'foo'
|}
""".stripMargin()

settingsFile << "rootProject.name = 'myapp'"

when:
runner.arguments << 'distShadowZip'
ExecutionResult result = runner.run()

then:
success(result)

then: 'Check that the distribution zip was created'
File zip = file('build/distributions/myapp-1.0.zip')
assert zip.exists()

and: 'Check that the zip contains the correct library files & scripts'
ZipFile zipFile = new ZipFile(zip)
assert zipFile.entries.find { it.name == 'myapp-1.0/lib/myapp-1.0-all.jar' }
assert zipFile.entries.find { it.name == 'myapp-1.0/lib/a-1.0.jar'}

cleanup:
zipFile?.close()
}
}

0 comments on commit 885319c

Please sign in to comment.