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

Fix generation of repos using -DhostOnJenkinsGitHub=false #710

Merged
merged 3 commits into from Mar 15, 2024

Conversation

rrjjvv
Copy link
Contributor

@rrjjvv rrjjvv commented Mar 15, 2024

Fixes #709

The fix itself was trivial.

I added integration tests specifically for that scenario, but the tests broke with spotbugs errors (for the generated POM). Example (snippet):

[INFO] [ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.43.0:check (default) on project testArtifact: The following files had format violations:
[INFO] [ERROR]     pom.xml
[INFO] [ERROR]         @@ -15,16 +15,14 @@
[INFO] [ERROR]          ··<packaging>hpi</packaging>
[INFO] [ERROR]          
[INFO] [ERROR]          ··<name>TODO·Plugin</name>
[INFO] [ERROR]         -··
[INFO] [ERROR]         -··
[INFO] [ERROR]         -··
[INFO] [ERROR]         +
[INFO] [ERROR]          ··<properties>
[INFO] [ERROR]          ····<revision>1.0</revision>
[INFO] [ERROR]          ····<changelist>-SNAPSHOT</changelist>
[INFO] [ERROR]          
[INFO] [ERROR]          ····<!--·https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/·-->
[INFO] [ERROR]          ····<jenkins.version>2.414.3</jenkins.version>
[INFO] [ERROR]         -····
[INFO] [ERROR]         +
[INFO] [ERROR]          ····<spotless.check.skip>false</spotless.check.skip>
[INFO] [ERROR]          ··</properties>
[INFO] [ERROR]          
[INFO] [ERROR] Run 'mvn spotless:apply' to fix these violations.

Obviously a plugin not hosted under the Jenkins umbrella would not be subject to these checks, so turning it off (only for -DhostOnJenkinsGitHub=false) might be considered a viable option, but it was not immediately obvious how to do so, so I explored how I could get the check to pass.

That led to my changing of the templates. It appears that white-space handling may be configurable (thus allowing the templates to remain as-is), but changing the template was easier and I hoped more agreeable. (Subjectively, I find it easier on the eyes as well.)

The key seemed to be having the directives at the beginning of the line. That led to

#if ....
  <stuff>
#end
#if ...
  <stuff>
#end
#if ...
  <stuff>
#end

at which point I collapsed them into a single block.

I broke it into three commits to make it easy to:

  1. take the fix only, if that's "good enough"
  2. accept the additional tests, if you have a way to turn off the spotbugs check (in lieu of the template changes)

Testing done

Executing the same invocation from #709, but with these fixes:

$ mvn -V archetype:generate -DarchetypeGroupId=io.jenkins.archetypes -DarchetypeArtifactId=empty-plugin -DhostOnJenkinsGitHub=false -DgroupId=mygroup -Dpackage=mypackage -DartifactId=myartifact -DinteractiveMode=false -DarchetypeCatalog=local
Apache Maven 3.9.2 (c9616018c7a021c1c39be70fb2843d6f5f9b8a1c)
Maven home: /opt/maven
Java version: 17.0.10, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.5.0-25-generic", arch: "amd64", family: "unix"
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] >>> archetype:3.2.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] 
[INFO] <<< archetype:3.2.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] 
[INFO] 
[INFO] --- archetype:3.2.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] Archetype [io.jenkins.archetypes:empty-plugin:1.25-SNAPSHOT] found in catalog local
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: empty-plugin:1.25-SNAPSHOT
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: mygroup
[INFO] Parameter: artifactId, Value: myartifact
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: mypackage
[INFO] Parameter: packageInPathFormat, Value: mypackage
[INFO] Parameter: package, Value: mypackage
[INFO] Parameter: hostOnJenkinsGitHub, Value: false
[INFO] Parameter: groupId, Value: mygroup
[INFO] Parameter: artifactId, Value: myartifact
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[WARNING] Don't override file /tmp/myartifact/
[INFO] Executing META-INF/archetype-post-generate.groovy post-generation script
Not hosting on Jenkins Github organisation, removing files specific to jenkinsci
[package:mypackage, hostOnJenkinsGitHub:false, groupId:mygroup, artifactId:myartifact, version:1.0-SNAPSHOT]
[INFO] Project created from Archetype in dir: /tmp/myartifact
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.838 s
[INFO] Finished at: 2024-03-14T22:23:34-06:00
[INFO] ------------------------------------------------------------------------
[WARNING] 
[WARNING] Plugin validation issues were detected in 2 plugin(s)
[WARNING] 
[WARNING]  * org.apache.maven.plugins:maven-site-plugin:3.12.1
[WARNING]  * org.apache.maven.plugins:maven-archetype-plugin:3.2.1
[WARNING] 
[WARNING] For more or less details, use 'maven.plugin.validation' property with one of the values (case insensitive): [BRIEF, DEFAULT, VERBOSE]
[WARNING]

$ ls -a myartifact/
.  ..  .gitignore  .mvn  pom.xml  README.md  src

$ grep -i github myartifact/pom.xml
<no output>
$

There are no maven failures, no LICENSE.md, no Jenkinsfile, no .github/, and a correctly named .gitignore.

The new integration tests validates the generated repo meets the same quality checks that a GitHub-hosted repo would, whatever that's worth.

Submitter checklist

Edit tasklist title
Beta Give feedback Tasklist Submitter checklist, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
    Options
  2. Ensure that the pull request title represents the desired changelog entry
    Options
  3. Please describe what you did
    Options
  4. Link to relevant issues in GitHub or Jira
    Options
  5. Link to relevant pull requests, esp. upstream and downstream changes
    Options
  6. Ensure you have provided tests - that demonstrates feature works or fixes the issue
    Options

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

seems fine, an easier approach might be to just run spotless:apply over it in the groovy post script

@timja timja merged commit eb01774 into jenkinsci:master Mar 15, 2024
2 checks passed
@timja timja removed the enhancement label Mar 15, 2024
@rrjjvv rrjjvv deleted the no-gh-fix branch March 15, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Archetypes generate incomplete/incorrect repos with -DhostOnJenkinsGitHub=false
2 participants