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

Add default manifest entries with Maven #318

Merged
merged 3 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/it/verify-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@
<packaging>hpi</packaging>

<name>MyNewPlugin</name>
<description>My New Plugin</description>
<url>https://github.com/jenkinsci/maven-hpi-plugin</url>
basil marked this conversation as resolved.
Show resolved Hide resolved

<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>

<developers>
<developer>
<id>nchomsky</id>
<name>Noam Chomsky</name>
<email>[email protected]</email>
</developer>
</developers>

<scm>
<connection>scm:git:https://github.com/jenkinsci/maven-hpi-plugin.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/maven-hpi-plugin.git</developerConnection>
<tag>HEAD</tag>
<url>https://github.com/jenkinsci/maven-hpi-plugin</url>
basil marked this conversation as resolved.
Show resolved Hide resolved
</scm>

<properties>
<jenkins.version>2.249.1</jenkins.version>
Expand Down
32 changes: 32 additions & 0 deletions src/it/verify-it/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
* under the License.
*/

import java.io.InputStream
import java.nio.file.Files
import java.util.jar.Manifest

assert new File(basedir, 'target/classes').exists();
assert new File(basedir, 'target/classes/org/jenkinsci/tools/hpi/its').exists();
assert new File(basedir, 'target/classes/org/jenkinsci/tools/hpi/its/HelloWorldBuilder.class').exists();
Expand All @@ -31,6 +35,34 @@ assert new File(basedir, 'target/generated-sources/localizer/org/jenkinsci/tools
content = new File(basedir, 'target/generated-sources/localizer/org/jenkinsci/tools/hpi/its/Messages.java').text;
assert content.contains(" holder.format(\"it.msg\");");

assert new File(basedir, 'target/verify-it/META-INF/MANIFEST.MF').exists()

InputStream is = Files.newInputStream(new File(basedir, 'target/verify-it/META-INF/MANIFEST.MF').toPath())
try {
Manifest manifest = new Manifest(is)
assert !manifest.getMainAttributes().getValue('Build-Jdk-Spec').isEmpty()
assert manifest.getMainAttributes().getValue('Created-By').startsWith('Maven Archiver')
assert manifest.getMainAttributes().getValue('Extension-Name') == null // was provided by Maven 2, but core prefers Short-Name
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maven 2 set this to the short name, but Maven 3 does not. Core always checks Short-Name first and only falls back to Extension-Name if Short-Name is not present. And we always set Short-Name in this plugin. So this was always redundant and can be safely removed.

assert manifest.getMainAttributes().getValue('Group-Id').equals('org.jenkins-ci.tools.hpi.its')
assert manifest.getMainAttributes().getValue('Hudson-Version').equals('2.249.1')
assert manifest.getMainAttributes().getValue('Implementation-Title').equals('MyNewPlugin') // was project.artifactId in previous versions, now project.name
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maven 2 set this to the artifact ID, but Maven 3 sets this to the project name. I couldn't find any code in the ecosystem that relied on this being set to any particular value.

assert manifest.getMainAttributes().getValue('Implementation-Version').equals('1.0-SNAPSHOT')
assert manifest.getMainAttributes().getValue('Jenkins-Version').equals('2.249.1')
assert manifest.getMainAttributes().getValue('Long-Name').equals('MyNewPlugin')
assert manifest.getMainAttributes().getValue('Manifest-Version').equals('1.0')
assert manifest.getMainAttributes().getValue('Minimum-Java-Version').equals('1.8')
assert manifest.getMainAttributes().getValue('Plugin-Developers').equals('Noam Chomsky:nchomsky:[email protected]')
assert manifest.getMainAttributes().getValue('Plugin-License-Name').equals('MIT License')
assert manifest.getMainAttributes().getValue('Plugin-License-Url').equals('https://opensource.org/licenses/MIT')
assert manifest.getMainAttributes().getValue('Plugin-ScmUrl').equals('https://github.com/jenkinsci/maven-hpi-plugin')
assert manifest.getMainAttributes().getValue('Plugin-Version').startsWith('1.0-SNAPSHOT')
assert manifest.getMainAttributes().getValue('Short-Name').equals('verify-it')
assert manifest.getMainAttributes().getValue('Specification-Title').equals('MyNewPlugin') // was project.description in previous versions, now project.name
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core does consume this to display on the installed plugins page, but only if src/main/resources/index.jelly is not present. As of #302 we enforce the existence of src/main/resources/index.jelly, so changing the semantics of Specification-Title will not result in any change in behavior.

assert manifest.getMainAttributes().getValue('Url').equals('https://github.com/jenkinsci/maven-hpi-plugin')
} finally {
is.close()
}
basil marked this conversation as resolved.
Show resolved Hide resolved

// TODO add some test on hpi file content

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jenkinsci.maven.plugins.hpi;

import org.apache.maven.archiver.ManifestConfiguration;
import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -96,7 +97,10 @@ protected void generateManifest(MavenArchiveConfiguration archive, File manifest
ma.setOutputFile(manifestFile);

try (PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(manifestFile), StandardCharsets.UTF_8))) {
Manifest mf = ma.getManifest(project, archive.getManifest());
ManifestConfiguration config = archive.getManifest();
config.setAddDefaultSpecificationEntries(true);
config.setAddDefaultImplementationEntries(true);
Manifest mf = ma.getManifest(project, config);
Manifest.ExistingSection mainSection = mf.getMainSection();
setAttributes(mainSection);

Expand All @@ -116,23 +120,6 @@ protected void setAttributes(Manifest.ExistingSection mainSection) throws MojoEx
mainSection.addAttributeAndCheck(new Manifest.Attribute("Plugin-Class",pluginClassName));
}

mainSection.addAttributeAndCheck(
new Manifest.Attribute("Extension-Name", project.getArtifactId()));
mainSection.addAttributeAndCheck(
new Manifest.Attribute("Implementation-Title", project.getArtifactId()));
mainSection.addAttributeAndCheck(
new Manifest.Attribute("Implementation-Version", project.getVersion()));
if (project.getOrganization() != null) {
mainSection.addAttributeAndCheck(
new Manifest.Attribute("Implementation-Vendor", project.getOrganization().getName()));
}
mainSection.addAttributeAndCheck(
new Manifest.Attribute("Specification-Title", project.getDescription()));
if (project.getOrganization() != null) {
mainSection.addAttributeAndCheck(
new Manifest.Attribute("Specification-Vendor", project.getOrganization().getName()));
}

mainSection.addAttributeAndCheck(new Manifest.Attribute("Group-Id",project.getGroupId()));
mainSection.addAttributeAndCheck(new Manifest.Attribute("Short-Name",project.getArtifactId()));
mainSection.addAttributeAndCheck(new Manifest.Attribute("Long-Name",pluginName));
Expand Down