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

Archetypes generate incomplete/incorrect repos with -DhostOnJenkinsGitHub=false #709

Closed
rrjjvv opened this issue Mar 15, 2024 · 1 comment · Fixed by #710
Closed

Archetypes generate incomplete/incorrect repos with -DhostOnJenkinsGitHub=false #709

rrjjvv opened this issue Mar 15, 2024 · 1 comment · Fixed by #710
Labels

Comments

@rrjjvv
Copy link
Contributor

rrjjvv commented Mar 15, 2024

Jenkins and plugins versions report

Environment

N/A

What Operating System are you using (both controller, and any agents involved in the problem)?

Linux (controller/agents N/A)

Reproduction steps

Generate an archetype with -DhostOnJenkinsGitHub=false:

$ mvn -V archetype:generate -DarchetypeGroupId=io.jenkins.archetypes -DarchetypeArtifactId=empty-plugin -DhostOnJenkinsGitHub=false -DgroupId=mygroup -Dpackage=mypackage -DartifactId=myartifact -DinteractiveMode=false
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.24] found in catalog remote
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: empty-plugin:1.24
[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
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.785 s
[INFO] Finished at: 2024-03-14T21:45:02-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] 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate (default-cli) on project standalone-pom: could not access constructor: private java.io.File(java.lang.String,java.io.File) with arguments: [Jenkinsfile, /tmp/myartifact] reason: java.lang.IllegalAccessException: class org.codehaus.groovy.reflection.CachedConstructor cannot access a member of class java.io.File (in module java.base) with modifiers "private" -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Expected Results

I expected the generation to:

  1. complete with no errors
  2. provide a valid .gitignore

After looking at the source to see what that flag is supposed to do, I'd also expect no LICENSE.md, Jenkinsfile, or .github/.

Actual Results

  1. resulted in an error (shown above)
  2. provided a file named gitignore (no leading dot); this is what got my attention
  3. files/directories that shouldn't be present:
    $ ls -a
    .  ..  .github  gitignore  Jenkinsfile  LICENSE.md  .mvn  pom.xml  README.md  src

Anything else?

The root cause is using a private constructor:

new File(it, projectPath.toFile()).delete()

The 'pre-generate' contents still get written to disk (including a pom without github info), but the first attempt at deletion causes the rest of the script to prematurely fail.

My assumption is that this originally implemented using Java 8.

Are you interested in contributing a fix?

The fix is trivial. Assuming a fix without tests might be rejected, I started down down that path, which led to more (unrelated) issues. I'll submit a PR shortly and you can decide what to do when you see it.

@rrjjvv
Copy link
Contributor Author

rrjjvv commented Mar 15, 2024

It looks like @jglick spotted that code as a potential problem as well (#602 (comment)), even though the actual issue (and symptoms) were not quite the same as mine.

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 a pull request may close this issue.

1 participant