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

Let maven do the hard work of archetype generation #767

Merged
merged 1 commit into from
Jun 13, 2022

Conversation

laeubi
Copy link
Member

@laeubi laeubi commented Jun 10, 2022

Prerequisite for #249

Copy link
Contributor

@HannesWell HannesWell left a comment

Choose a reason for hiding this comment

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

This change looks very good.
Addressing the potential crashing of Eclipse by post scripts is IMHO important and this looks like a good step forward to maybe even get completely rid of the embedded archetype dependency?

I basically only have one remark: Could you please provide a more descriptive commit message, like: Generate archtetype projects in separate Maven-build process

@laeubi laeubi force-pushed the call_maven_for_archetype branch 10 times, most recently from da19243 to 64966dd Compare June 11, 2022 18:28
@laeubi laeubi marked this pull request as ready for review June 11, 2022 18:55
@laeubi
Copy link
Member Author

laeubi commented Jun 11, 2022

I'm struggling a bit to get the test repo filled completely (I probably will enable online maven central as it otherwise becomes really cumbersome), but the code itself is now functional and thus is ready to be reviewed.

@laeubi laeubi force-pushed the call_maven_for_archetype branch from 64966dd to 14b8e24 Compare June 12, 2022 03:53
@laeubi
Copy link
Member Author

laeubi commented Jun 12, 2022

All tests are green now!

Copy link
Contributor

@HannesWell HannesWell left a comment

Choose a reason for hiding this comment

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

In general this looks good to me.

I just have a few minor remarks.

throw new CoreException(Status.error(msg, cause));
String goals = "-U org.apache.maven.plugins:maven-archetype-plugin:2.4:generate";
if(emptyPom != null) {
goals += " -f " + emptyPom.getAbsolutePath();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this logic new? Maybe it should be rejected with an error to create an archetype project where a pom.xml file already exists instead of using an alternative pom that is deleted afterwards.
Is the created project then valid after the empty-pom used for creation is deleted? Or is there a relevant use case for such scenario?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean by 'new'? This is to prevent m2e to first generate the code at a temporary place and then move it around, without the empty pom you will get higher build times and can't create a module of a parent that has pom-errors and at least there is a test for that (don't know if it uses intentionally an incomplete module pom).

Copy link
Member Author

Choose a reason for hiding this comment

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

By the way there are currently two restrictions one might report to maven and submit a patch, but this would then take some time until it is released:

  1. If running mvn inside an empty folder / without a pom, it uses a "no-pom build", one can then force a different location of the pom by -f but if the folder contains no pom I can't force to ignore that file.
  2. maven-archetype always generates the archetype at the folder $outputDir/$artifactId while here it would be good if we can just generate it in the current folder (what would be empty anyways).

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by 'new'? This is to prevent m2e to first generate the code at a temporary place and then move it around, without the empty pom you will get higher build times and can't create a module of a parent that has pom-errors and at least there is a test for that (don't know if it uses intentionally an incomplete module pom).

I meant if that the logic you just described was available before too.
Nevertheless what you describe sounds very reasonable. Thank you for your elaboration.

@laeubi laeubi requested a review from HannesWell June 13, 2022 07:53
@laeubi
Copy link
Member Author

laeubi commented Jun 13, 2022

@HannesWell I have applied your suggestion and fixed the compile issues, if you are fine I'll swash all content into one before merge...

Copy link
Contributor

@HannesWell HannesWell left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thank you.

@HannesWell I have applied your suggestion and fixed the compile issues, if you are fine I'll swash all content into one before merge...

Sure squash it, I see no need to keep the review history in git. :)

}
Files.writeString(tempFile.toPath(),
"<project><modelVersion>4.0.0</modelVersion><groupId>empty</groupId><artifactId>empty</artifactId><version>1</version><name>Generating archetype</name></project>",
StandardCharsets.UTF_8);
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed that Files.writeString() uses UTF-8 by default so specifying the charset explicitly is actually not necessary.

throw new CoreException(Status.error(msg, cause));
String goals = "-U org.apache.maven.plugins:maven-archetype-plugin:2.4:generate";
if(emptyPom != null) {
goals += " -f " + emptyPom.getAbsolutePath();
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by 'new'? This is to prevent m2e to first generate the code at a temporary place and then move it around, without the empty pom you will get higher build times and can't create a module of a parent that has pom-errors and at least there is a test for that (don't know if it uses intentionally an incomplete module pom).

I meant if that the logic you just described was available before too.
Nevertheless what you describe sounds very reasonable. Thank you for your elaboration.

@laeubi laeubi force-pushed the call_maven_for_archetype branch from cd483ef to 9074c27 Compare June 13, 2022 08:57
@laeubi
Copy link
Member Author

laeubi commented Jun 13, 2022

Okay, lets merge when build runs fine then (after reverting the modules link).

@laeubi laeubi force-pushed the call_maven_for_archetype branch from 9074c27 to 371a0b7 Compare June 13, 2022 10:35
@laeubi laeubi merged commit c76ec87 into eclipse-m2e:master Jun 13, 2022
@mickaelistria
Copy link
Contributor

I still don't like much IMavenLauncher (but at least it's internal, so not a too big deal)

I actually want to execute a maven run (with console) like when you do Run As > Maven Build and while the RunPomAction uses the AbstractMavenRuntime to build all the JVM parameters, the actual execution happens as a jvm process and not through AbstractMavenRuntime

Couldn't this be a new method to AbstractMavenRuntime then, something like IProcess runExtenally(...) ?

@laeubi
Copy link
Member Author

laeubi commented Jun 13, 2022

Couldn't this be a new method to AbstractMavenRuntime then, something like IProcess runExtenally(...) ?

If you like, just try it out I won't mind adjusting that part of the code as it is covered by tests and not used elsewhere until now we can change relative easy here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants