Skip to content

Commit

Permalink
Added support for -PprojName.package=
Browse files Browse the repository at this point in the history
  • Loading branch information
jdigger committed May 30, 2017
1 parent 7e17e60 commit 9c3d8c5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
7 changes: 5 additions & 2 deletions docs/CqPackagePlugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,14 @@ This uses https://github.com/TWCable/gradle-plugin-cq-bundle/blob/master/docs/Cq

It can be useful to use an existing file rather than the output of `createPackage`.
(e.g., In a deployment pipeline where the artifact is pulled from a repository.)
Setting the `package` system property (i.e., `-Dpackage=XX`) will force the
Setting the `package` system or project property (i.e., `-Dpackage=XX` or `-Ppackage=XX`) will force the
use of the specified file.

If more control is needed, you can prepend the package key with the name of the project (with no leading colon).
For example, `-Psub-module-a.package=XX` will set the package property for just `:sub-module-a`.

This will fail if it doesn't have a file to upload, either because `createPackage` has not been run or the `package`
system property has not been set.
property has not been set.


== Task `uninstallBundles`
Expand Down
24 changes: 15 additions & 9 deletions src/main/groovy/com/twcable/gradle/cqpackage/UploadPackage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.gradle.api.GradleException
import org.gradle.api.Project

import javax.annotation.Nonnull
import javax.annotation.Nullable

import static com.twcable.gradle.cqpackage.PackageStatus.NO_PACKAGE
import static com.twcable.gradle.cqpackage.PackageStatus.UNKNOWN
Expand Down Expand Up @@ -160,6 +161,17 @@ in other words, there's no indication it's missing its dependency at this point
return uploadStatus
}


@Nullable
private static String projectOrSystemProperty(Project project, String propName) {
def hasProperty = project.hasProperty(propName)
if (hasProperty) {
return project.property(propName) as String
}

return System.getProperty(propName)
}

/**
* Returns the CQ Package file to use.
*
Expand All @@ -168,15 +180,9 @@ in other words, there's no indication it's missing its dependency at this point
*/
@Nonnull
static File getThePackageFile(Project project) {
def hasPackageProperty = project.hasProperty('package')
if (hasPackageProperty) {
final filename = project.property('package') as String
final file = new File(filename).absoluteFile
if (!file.exists()) throw new FileNotFoundException(file.toString())
return file
}
def packageProperty = projectOrSystemProperty(project, 'package') ?:
projectOrSystemProperty(project, "${project.name}.package")

def packageProperty = System.getProperty('package')
if (packageProperty != null) {
final filename = packageProperty
final file = new File(filename).absoluteFile
Expand All @@ -191,7 +197,7 @@ in other words, there's no indication it's missing its dependency at this point
}

// TODO Detect this situation at task-graph build time and automatically add the createPackage task
throw new IllegalStateException("The 'package' system property is not set and there is no output from the 'createPackage' task")
throw new IllegalStateException("The 'package' system/project property is not set, nor is \"${project.name}.package\", and there is no output from the \"createPackage\" task")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class CqPackagePluginIntSpec extends IntegrationSpec {
!result.success
def exp = result.failure.cause
exp.task.name == 'uploadPackage'
exp.cause.message.contains("there is no output from the 'createPackage' task")
exp.cause.message.contains("there is no output from the \"createPackage\" task")
}


Expand Down Expand Up @@ -341,6 +341,30 @@ class CqPackagePluginIntSpec extends IntegrationSpec {
}


def "upload package with project-specific package Project property"() {
def testPackageFilename = this.class.classLoader.getResource("testpackage-1.0.1.zip").file

getHandler.addPathResponse("/crx/packmgr/list.jsp",
new JsonBuilder(
PackageServerFixture.packageList(
PackageFixture.of("twc/test:testpackage:1.0.1")
)
).toString()
)

postHandler.addFileResponse("/crx/packmgr/service/.json", successfulPackageUpload().body)

writeSimpleBuildFile()

when:
result = runTasks("uploadPackage", "-P${moduleName}.package=${testPackageFilename}", "-x", "removePackage")

then:
result.success
!result.wasExecuted(':createPackage')
}


def "install package"() {
defaultPackageListHandler()

Expand Down

0 comments on commit 9c3d8c5

Please sign in to comment.