Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-38920

JPI plugin Manifest lacks Plugin-Class attribute when Gradle project was previously cleaned

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • gradle-jpi-plugin
    • None
    • Gradle version: 2.8
      Gradle-jpi-plugin version: 0.18.1
      JDK: java 7
      OS: OSX El Capitan and Linux Ubuntu

      JPI plugin Manifest lacks Plugin-Class attribute when Gradle project was previously cleaned.

      To reproduce:
      1. have a basic gradle project with gradle-jpi-plugin that creates some jenkins plugin
      2. run: ./gradlew clean
      3. run: ./gradlew clean jpi - the resulting hpi plugin contains "faulty" Manifest w/o Plugin-Class attribute
      4. run: ./gradlew clean jpi - the resulting hpi plugin contains Manifest with Plugin-Class attribute

      The problem lies in JpiPlugin.groovy#configureJpi (line with: project.afterEvaluate):

           project.tasks.findByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(jpi)
              project.afterEvaluate { <---
                  jpi.archiveName = "${jpiExtension.shortName}.${jpiExtension.fileExtension}"
                  jpi.extension = jpiExtension.fileExtension
                  jpi.manifest.attributes(attributesToMap(new JpiManifest(project).mainAttributes)) <--
              }
      

      This piece runs the code that collects attributes for Manifest just after "evaluation" aka "configuration" phase, i.e. when sources are not even built yet or the folder 'classes' is old (as it originates from previous build, like in #4 - clean is done after evaluation/configuration).
      Of course some attributes are being acquired by scanning generated classes, for example the problematic Plugin-Class attribute is produced only when hudson.Plugin exists and this file appears in classes folder as a result of the assemble task (created by PluginSubtypeMarker extending javax.annotation.processing.AbstractProcessor).

      I had to use the following workaround in my gradle file to ensure the Plugin-Class attribute is in place regardless of the state of the project:

      task workaround << {
       project.jpi.manifest.attributes(org.jenkinsci.gradle.plugins.jpi.JpiManifest.attributesToMap(new org.jenkinsci.gradle.plugins.jpi.JpiManifest(project).mainAttributes))
      }
      project.tasks.findByName(org.jenkinsci.gradle.plugins.jpi.Jpi.TASK_NAME).dependsOn(workaround)
      

      Apparently this issue was introduced in JENKINS-31426

          [JENKINS-38920] JPI plugin Manifest lacks Plugin-Class attribute when Gradle project was previously cleaned

          Brian Saville added a comment -

          We have run into this as well. The temporary workaround is to do something like gradlew build jpi to actually build the JPI twice to get the Plugin-Class attribute.

          Brian Saville added a comment - We have run into this as well. The temporary workaround is to do something like gradlew build jpi to actually build the JPI twice to get the Plugin-Class attribute.

          Daniel Spilker added a comment - PR: https://github.com/jenkinsci/gradle-jpi-plugin/pull/81 psko and bksaville : can you test the PR?

          Tomorrow I will give it a try.

          Piotr Skowronek added a comment - Tomorrow I will give it a try.

          daspilker, the fix works for me

          Piotr Skowronek added a comment - daspilker , the fix works for me

          Code changed in jenkins
          User: Daniel Spilker
          Path:
          CHANGELOG.md
          src/main/groovy/org/jenkinsci/gradle/plugins/jpi/JpiPlugin.groovy
          src/test/groovy/org/jenkinsci/gradle/plugins/jpi/JpiManifestSpec.groovy
          src/test/resources/org/jenkinsci/gradle/plugins/jpi/test.mf
          http://jenkins-ci.org/commit/gradle-jpi-plugin/022c059aba2dd9f4322b4624e03efb696e46b071
          Log:
          fixed problem with missing Plugin-Class attribute in generated manifest

          [FIXES JENKINS-38920]

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Spilker Path: CHANGELOG.md src/main/groovy/org/jenkinsci/gradle/plugins/jpi/JpiPlugin.groovy src/test/groovy/org/jenkinsci/gradle/plugins/jpi/JpiManifestSpec.groovy src/test/resources/org/jenkinsci/gradle/plugins/jpi/test.mf http://jenkins-ci.org/commit/gradle-jpi-plugin/022c059aba2dd9f4322b4624e03efb696e46b071 Log: fixed problem with missing Plugin-Class attribute in generated manifest [FIXES JENKINS-38920]

          Code changed in jenkins
          User: Daniel Spilker
          Path:
          CHANGELOG.md
          src/main/groovy/org/jenkinsci/gradle/plugins/jpi/JpiPlugin.groovy
          src/test/groovy/org/jenkinsci/gradle/plugins/jpi/JpiManifestSpec.groovy
          src/test/resources/org/jenkinsci/gradle/plugins/jpi/test.mf
          http://jenkins-ci.org/commit/gradle-jpi-plugin/65547ed4b757b1a476a198c9a5e5d9113be38b80
          Log:
          Merge pull request #81 from daspilker/JENKINS-38920

          JENKINS-38920 fixed problem with missing Plugin-Class attribute in generated manifest

          Compare: https://github.com/jenkinsci/gradle-jpi-plugin/compare/2acb996a417f...65547ed4b757

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Spilker Path: CHANGELOG.md src/main/groovy/org/jenkinsci/gradle/plugins/jpi/JpiPlugin.groovy src/test/groovy/org/jenkinsci/gradle/plugins/jpi/JpiManifestSpec.groovy src/test/resources/org/jenkinsci/gradle/plugins/jpi/test.mf http://jenkins-ci.org/commit/gradle-jpi-plugin/65547ed4b757b1a476a198c9a5e5d9113be38b80 Log: Merge pull request #81 from daspilker/ JENKINS-38920 JENKINS-38920 fixed problem with missing Plugin-Class attribute in generated manifest Compare: https://github.com/jenkinsci/gradle-jpi-plugin/compare/2acb996a417f...65547ed4b757

          Fixed in 0.19.0.

          Daniel Spilker added a comment - Fixed in 0.19.0.

            daspilker Daniel Spilker
            psko Piotr Skowronek
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: