nebula.plugin.ospackage.application.OspackageApplicationPlugin.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nebula-ospackage-plugin Show documentation
Show all versions of nebula-ospackage-plugin Show documentation
Opinionated plugins that wrap the gradle-ospackage-plugin
package nebula.plugin.ospackage.application
import com.netflix.gradle.plugins.packaging.ProjectPackagingExtension
import com.netflix.gradle.plugins.packaging.SystemPackagingBasePlugin
import com.netflix.gradle.plugins.packaging.SystemPackagingPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.internal.IConventionAware
import org.gradle.api.plugins.ApplicationPlugin
import org.gradle.api.plugins.ApplicationPluginConvention
import org.gradle.api.tasks.application.CreateStartScripts
/**
* Combine the os-package with the Application plugin. Currently heavily opinionated to where
* the code will live, though that is slightly configurable using the ospackage-application extension.
*
* TODO Make a base plugin, so that this plugin can require os-package
*
* Usage:
*
* - User has to provide a mainClassName
*
- User has to create SystemPackaging tasks, the easiest way is to apply plugin: 'os-package'
*
*/
class OspackageApplicationPlugin implements Plugin {
OspackageApplicationExtension extension
@Override
void apply(Project project) {
extension = project.extensions.create('ospackage_application', OspackageApplicationExtension)
((IConventionAware) extension).conventionMapping.map('prefix') { '/opt'}
project.plugins.apply(ApplicationPlugin)
ApplicationPluginConvention appConvention = project.convention.getPlugin(ApplicationPluginConvention)
CreateStartScripts startScripts = (CreateStartScripts) project.tasks.getByName(ApplicationPlugin.TASK_START_SCRIPTS_NAME)
project.plugins.apply(SystemPackagingBasePlugin.class)
def packagingExt = project.extensions.getByType(ProjectPackagingExtension)
packagingExt.with(appConvention.applicationDistribution)
// Using a closure here to delay evaluation of prefix
packagingExt.into { "${extension.getPrefix()}/${startScripts.applicationName}" }
// Use post-install to fix permissions
// Maybe stepping over the line, but it'll make it much easier to use.
project.plugins.apply(SystemPackagingPlugin)
}
}