From 4fd136fea2c5d5ddf057a89427275cf0266f3244 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 21 Dec 2020 15:22:24 +0100 Subject: [PATCH] Add core plugins to scm-webapp war --- buildSrc/build.gradle | 50 +++++++++ .../cloudogu/scm/CopyCorePluginsTask.groovy | 104 ++++++++++++++++++ .../scm/CorePluginsGradlePlugin.groovy | 46 ++++++++ scm-webapp/build.gradle | 9 ++ 4 files changed, 209 insertions(+) create mode 100644 buildSrc/build.gradle create mode 100644 buildSrc/src/main/groovy/com/cloudogu/scm/CopyCorePluginsTask.groovy create mode 100644 buildSrc/src/main/groovy/com/cloudogu/scm/CorePluginsGradlePlugin.groovy diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000000..0230259285 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,50 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +plugins { + id 'java-gradle-plugin' + id 'groovy' +} + +dependencies { + implementation(gradleApi()) + implementation 'com.google.guava:guava:30.0-jre' +} + +gradlePlugin { + // Define the plugin + plugins { + corePlugins { + id = 'org.scm-manager.core-plugins' + implementationClass = 'com.cloudogu.scm.CorePluginsGradlePlugin' + } + } +} + +repositories { + maven { + url "https://packages.scm-manager.org/repository/public/" + } +} diff --git a/buildSrc/src/main/groovy/com/cloudogu/scm/CopyCorePluginsTask.groovy b/buildSrc/src/main/groovy/com/cloudogu/scm/CopyCorePluginsTask.groovy new file mode 100644 index 0000000000..2397dbb1ff --- /dev/null +++ b/buildSrc/src/main/groovy/com/cloudogu/scm/CopyCorePluginsTask.groovy @@ -0,0 +1,104 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +package com.cloudogu.scm + +import org.gradle.api.DefaultTask +import org.gradle.api.GradleException +import org.gradle.api.artifacts.Configuration +import org.gradle.api.file.Directory +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.Classpath +import org.gradle.api.tasks.Internal + +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction +import groovy.xml.MarkupBuilder +import java.io.BufferedWriter + +import com.google.common.hash.Hashing +import com.google.common.io.Files + +class CopyCorePluginsTask extends DefaultTask { + + @Classpath + final Property configuration = project.objects.property(Configuration) + + @OutputDirectory + final DirectoryProperty targetDirectory = project.objects.directoryProperty() + + @Internal + final Provider> lookup = configuration.map { + it.resolvedConfiguration + .resolvedArtifacts + .findAll { + it.extension == "smp" + } + .collect { + it.file + } + } + + @TaskAction + void execute() { + File directory = targetDirectory.get().asFile + if (!directory.exists() && !directory.mkdirs()) { + throw new GradleException("failed to create plugin directory: ${directory}") + } + + List plugins = lookup.get() + + project.sync { + into(directory) + from(plugins) + } + + writeReadme(directory) + writeIndex(directory, plugins) + } + + private void writeReadme(File directory) { + File readme = new File(directory, 'README') + readme.text = 'Directory for SCM-Manager core plugin\n' + } + + private void writeIndex(File directory, List pluginFiles) { + File file = new File(directory, "plugin-index.xml") + file.withWriter { writer -> + def xml = new MarkupBuilder(writer) + xml.'plugin-index' { + pluginFiles.forEach { pluginFile -> + plugins { + name pluginFile.name + checksum Files.asByteSource(pluginFile).hash(Hashing.sha256()) + } + } + } + } + } + +} diff --git a/buildSrc/src/main/groovy/com/cloudogu/scm/CorePluginsGradlePlugin.groovy b/buildSrc/src/main/groovy/com/cloudogu/scm/CorePluginsGradlePlugin.groovy new file mode 100644 index 0000000000..15937d5cdc --- /dev/null +++ b/buildSrc/src/main/groovy/com/cloudogu/scm/CorePluginsGradlePlugin.groovy @@ -0,0 +1,46 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +package com.cloudogu.scm + + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration + +class CorePluginsGradlePlugin implements Plugin { + + void apply(Project project) { + Configuration corePlugin = project.configurations.create("corePlugin") + corePlugin.canBeConsumed = false + corePlugin.canBeResolved = true + + project.tasks.register("copy-core-plugins", CopyCorePluginsTask) { + it.configuration = corePlugin + it.targetDirectory = project.layout.buildDirectory.dir("war/WEB-INF/plugins") + } + } + +} diff --git a/scm-webapp/build.gradle b/scm-webapp/build.gradle index 4999fdc33a..203f1c549b 100644 --- a/scm-webapp/build.gradle +++ b/scm-webapp/build.gradle @@ -24,12 +24,17 @@ plugins { id 'war' + id 'org.scm-manager.core-plugins' id 'io.swagger.core.v3.swagger-gradle-plugin' version '2.1.6' } dependencies { implementation platform(project(':')) + corePlugin project(path: ':scm-plugins:scm-git-plugin', configuration: 'smp') + corePlugin project(path: ':scm-plugins:scm-hg-plugin', configuration: 'smp') + corePlugin project(path: ':scm-plugins:scm-svn-plugin', configuration: 'smp') + implementation project(':scm-core') implementation project(':scm-dao-xml') testImplementation project(':scm-test') @@ -129,6 +134,10 @@ dependencies { testImplementation 'com.github.sdorra:shiro-unit:1.0.1' } +war { + from 'build/war' + dependsOn 'copy-core-plugins' +} /** WTF???