From a345aea56e0f3b07f65ac7630adbbb5dbd6e5e9c Mon Sep 17 00:00:00 2001 From: James Nord Date: Fri, 14 Apr 2023 14:46:27 +0100 Subject: [PATCH] Add integration test for additional plugin manifest entries (#467) --- src/it/metadata-it/invoker.properties | 20 +++++ src/it/metadata-it/plugin1/pom.xml | 18 +++++ .../plugin1/src/main/resources/index.jelly | 2 + src/it/metadata-it/plugin2/pom.xml | 36 +++++++++ .../plugin2/src/main/resources/index.jelly | 2 + src/it/metadata-it/pom.xml | 42 +++++++++++ src/it/metadata-it/verify.groovy | 75 +++++++++++++++++++ 7 files changed, 195 insertions(+) create mode 100644 src/it/metadata-it/invoker.properties create mode 100644 src/it/metadata-it/plugin1/pom.xml create mode 100644 src/it/metadata-it/plugin1/src/main/resources/index.jelly create mode 100644 src/it/metadata-it/plugin2/pom.xml create mode 100644 src/it/metadata-it/plugin2/src/main/resources/index.jelly create mode 100644 src/it/metadata-it/pom.xml create mode 100644 src/it/metadata-it/verify.groovy diff --git a/src/it/metadata-it/invoker.properties b/src/it/metadata-it/invoker.properties new file mode 100644 index 0000000000..b64baddabc --- /dev/null +++ b/src/it/metadata-it/invoker.properties @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +invoker.goals=-ntp clean package -DskipTests diff --git a/src/it/metadata-it/plugin1/pom.xml b/src/it/metadata-it/plugin1/pom.xml new file mode 100644 index 0000000000..f59ccae5b8 --- /dev/null +++ b/src/it/metadata-it/plugin1/pom.xml @@ -0,0 +1,18 @@ + + + + 4.0.0 + + + org.jenkins-ci.tools.hpi.its.git-metadata + it-parent + 1.0-SNAPSHOT + + + plugin1 + 1.0-SNAPSHOT + My First Plugin + hpi + https://plugins.jenkins.io/plugin1/ + + diff --git a/src/it/metadata-it/plugin1/src/main/resources/index.jelly b/src/it/metadata-it/plugin1/src/main/resources/index.jelly new file mode 100644 index 0000000000..cac1391f92 --- /dev/null +++ b/src/it/metadata-it/plugin1/src/main/resources/index.jelly @@ -0,0 +1,2 @@ + +
plugin1
\ No newline at end of file diff --git a/src/it/metadata-it/plugin2/pom.xml b/src/it/metadata-it/plugin2/pom.xml new file mode 100644 index 0000000000..b9a231bc62 --- /dev/null +++ b/src/it/metadata-it/plugin2/pom.xml @@ -0,0 +1,36 @@ + + + + 4.0.0 + + + org.jenkins-ci.tools.hpi.its.git-metadata + it-parent + 1.0-SNAPSHOT + + + multimodule-it-plugin2 + hpi + + https://plugins.jenkins.io/multimodule-it-plugin2/ + + + + bob + bob@example.com + Robert McBobface + + + jane + jane@example.com + + + + + + ${project.groupId} + plugin1 + ${project.version} + + + diff --git a/src/it/metadata-it/plugin2/src/main/resources/index.jelly b/src/it/metadata-it/plugin2/src/main/resources/index.jelly new file mode 100644 index 0000000000..92e7e9d54a --- /dev/null +++ b/src/it/metadata-it/plugin2/src/main/resources/index.jelly @@ -0,0 +1,2 @@ + +
multimodule-it-plugin2
\ No newline at end of file diff --git a/src/it/metadata-it/pom.xml b/src/it/metadata-it/pom.xml new file mode 100644 index 0000000000..4daa79b083 --- /dev/null +++ b/src/it/metadata-it/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + org.jenkins-ci.plugins + plugin + 4.54 + + + + org.jenkins-ci.tools.hpi.its.git-metadata + it-parent + 1.0-SNAPSHOT + pom + + + 2.361.4 + @project.version@ + jenkinsci/maven-hpi-plugin + + + + scm:git:https://github.com/${gitHubRepo}.git + scm:git:git@github.com:${gitHubRepo}.git + HEAD + https://github.com/${gitHubRepo} + + + + + MIT License + https://opensource.org/licenses/MIT + + + + + plugin1 + plugin2 + + + diff --git a/src/it/metadata-it/verify.groovy b/src/it/metadata-it/verify.groovy new file mode 100644 index 0000000000..8e543ffbe5 --- /dev/null +++ b/src/it/metadata-it/verify.groovy @@ -0,0 +1,75 @@ +import java.io.File +import java.util.jar.Attributes +import java.util.jar.JarFile +import java.util.jar.Manifest + +assert new File(basedir, 'plugin1/target/plugin1.hpi').exists() +File p1 = new File(basedir, 'plugin1/target/plugin1.hpi') + +assert p1.exists() +try (JarFile j1 = new JarFile(p1)) { + Manifest mf = j1.getManifest() + Attributes attributes = mf.getMainAttributes() + // there may be other attribute like 'Created-By' that we do not care about we are not checking everything + assert attributes.getValue('Manifest-Version').equals('1.0') // if this changes then Jenkins may not be able to parse it. + + assert attributes.getValue('Hudson-Version').equals('2.361.4') + assert attributes.getValue('Jenkins-Version').equals('2.361.4') + + assert attributes.getValue('Group-Id').equals('org.jenkins-ci.tools.hpi.its.git-metadata') + assert attributes.getValue('Artifact-Id').equals('plugin1') + + assert attributes.getValue('Short-Name').equals('plugin1') // artifactId + assert attributes.getValue('Implementation-Version').equals('1.0-SNAPSHOT') // version + + // using project.name + assert attributes.getValue('Implementation-Title').equals('My First Plugin') + assert attributes.getValue('Specification-Title').equals('My First Plugin') + assert attributes.getValue('Long-Name').equals('My First Plugin') + + assert attributes.getValue('Plugin-Developers').isEmpty() + assert attributes.getValue('Plugin-License-Name').equals('MIT License') + assert attributes.getValue('Plugin-License-Url').equals('https://opensource.org/licenses/MIT') + assert attributes.getValue('Plugin-ScmUrl').equals('https://github.com/jenkinsci/maven-hpi-plugin') + assert attributes.getValue('Plugin-Version').startsWith('1.0-SNAPSHOT') + assert attributes.getValue('Url').equals('https://plugins.jenkins.io/plugin1/') + assert attributes.getValue('Plugin-ScmConnection').equals('scm:git:https://github.com/jenkinsci/maven-hpi-plugin.git') + assert attributes.getValue('Plugin-GitHash').length() == 40 + assert attributes.getValue('Plugin-Module').equals('plugin1') +} + + +assert new File(basedir, 'plugin2/target/multimodule-it-plugin2.hpi').exists(); +File p2 = new File(basedir, 'plugin2/target/multimodule-it-plugin2.hpi') + +try (JarFile j2 = new JarFile(p2)) { + Manifest mf = j2.getManifest() + Attributes attributes = mf.getMainAttributes() + assert attributes.getValue('Manifest-Version').equals('1.0') // if this changes then Jenkins may not be able to parse it. + + assert attributes.getValue('Hudson-Version').equals('2.361.4') + assert attributes.getValue('Jenkins-Version').equals('2.361.4') + + assert attributes.getValue('Group-Id').equals('org.jenkins-ci.tools.hpi.its.git-metadata') + assert attributes.getValue('Artifact-Id').equals('multimodule-it-plugin2') + assert attributes.getValue('Short-Name').equals('multimodule-it-plugin2') // artifactId + assert attributes.getValue('Implementation-Version').equals('1.0-SNAPSHOT') // version + + // project.name not set so should fallback to project.artifactId + assert attributes.getValue('Implementation-Title').equals('multimodule-it-plugin2') + assert attributes.getValue('Specification-Title').equals('multimodule-it-plugin2') + assert attributes.getValue('Long-Name').equals('multimodule-it-plugin2') + + assert attributes.getValue('Plugin-Developers').equals('Robert McBobface:bob:bob@example.com,:jane:jane@example.com') + assert attributes.getValue('Plugin-License-Name').equals('MIT License') + assert attributes.getValue('Plugin-License-Url').equals('https://opensource.org/licenses/MIT') + assert attributes.getValue('Plugin-ScmUrl').equals('https://github.com/jenkinsci/maven-hpi-plugin') + assert attributes.getValue('Plugin-Version').startsWith('1.0-SNAPSHOT') + assert attributes.getValue('Url').equals('https://plugins.jenkins.io/multimodule-it-plugin2/') + assert attributes.getValue('Plugin-ScmConnection').equals('scm:git:https://github.com/jenkinsci/maven-hpi-plugin.git') + assert attributes.getValue('Plugin-GitHash').length() == 40 + assert attributes.getValue('Plugin-Module').equals('plugin2') + +} + +return true; \ No newline at end of file