Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new tasks for plugin packaging #1748

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ crafter-delivery-env/
crafter-authoring
crafter-delivery
downloads/
plugins/
!utils/src/main/java/org/craftercms/bundle/utils/
utils/target
.project
.settings/
.vscode/
.vscode/
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ ext {

apply from: "downloads.gradle"
apply from: "environments.gradle"
apply from: "plugins.gradle"


def deliveryDeps = []
Expand Down
64 changes: 64 additions & 0 deletions plugins.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import java.nio.file.Files
import java.nio.file.Paths

import groovy.util.XmlParser

import org.apache.tools.ant.filters.ReplaceTokens

def dir
def tempDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "temp-crafter-plugin")
def pluginsDir = Paths.get("plugins").toFile()

def path = project.hasProperty("pluginPath")? project.getProperty("pluginPath") : null
def pluginId = project.hasProperty("pluginId")? project.getProperty("pluginId") : null
def pluginName = project.hasProperty("pluginName")? project.getProperty("pluginName") : null
def pluginVersion = project.hasProperty("pluginVersion")? project.getProperty("pluginVersion") : null
def crafterEdition = project.hasProperty("crafterEdition")? project.getProperty("crafterEdition") : null
def buildNumber = project.hasProperty("buildNumber")? project.getProperty("buildNumber") : null

task preparePlugin {
description "Task to validate the contents of the plugin directory"

if(path) {
dir = Paths.get(path)
if(!Files.exists(dir) || !Files.isDirectory(dir)) {
throw new GradleException("The path does not exist or is not a folder")
}
def manifest = dir.resolve("plugin.xml")
if(!Files.exists(manifest)) {
throw new GradleException("Missing required file ${manifest}")
}
def xml = new XmlParser().parse(Files.newInputStream(manifest))
pluginId = pluginId ?: xml.id.text()
pluginName = pluginName ?: xml.name.text()
pluginVersion = pluginVersion ?: xml.version.text()
crafterEdition = crafterEdition ?: xml['crafter-edition'].text()
buildNumber = buildNumber ?: UUID.randomUUID() as String
copy {
from dir
into tempDir
filter(ReplaceTokens,
tokens: [
PLUGIN_ID: pluginId,
PLUGIN_NAME: pluginName,
PLUGIN_VERSION: pluginVersion,
CRAFTER_EDITION: crafterEdition,
BUILD_DATE: new Date().getTime() as String,
BUILD_NUMBER: buildNumber
])
}
}
}

task packagePlugin(type: Zip, dependsOn: preparePlugin) {
description "Task to process and package Crafter Studio plugins"

from tempDir
destinationDir pluginsDir
archiveName "${pluginName}-${pluginVersion}.car"

doLast {
delete tempDir
println "Complete, plugin written to file '$pluginsDir/${pluginName}-${pluginVersion}.car'"
}
}