-
Notifications
You must be signed in to change notification settings - Fork 107
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
Surefire/Failsafe plugin configuration propagated to Junit/TestNG launch configuration #1672
base: master
Are you sure you want to change the base?
Surefire/Failsafe plugin configuration propagated to Junit/TestNG launch configuration #1672
Conversation
feature/surefire_plugins_arguments_to_launch_config
Fixes #700 |
uncommented testng even if not executed
@treilhes thank you for this contribution. In general it is interesting and definitely a good thing to support. Unfortunately I won't have time to review this large contribution over the weekend and will then be on vacation for three weeks. |
@HannesWell |
feature/surefire_plugins_arguments_to_launch_config
feature/surefire_plugins_arguments_to_launch_config
…ents_to_launch_config
@HannesWell, I miss you so much, I long to hear from you about your vacation (and to get a bit of review) 💔 |
…ents_to_launch_config
My vacation was great, thanks for asking. I'll do my best to review this at the weekend (when I arrived back home a full ToDo-List hit immediately). |
@HannesWell Bump ❤️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @treilhes first of all a big sorry for the delay and thanks for your patience.
It's just currently a lot to do, but I still have you on my TODO list a will try my best that we can complete this before the next release (ideally with some time left).
I had a a very brief overview over this change and I find your solution to adjust the launch config very interesting. I assume this works reliably in various scenarios like creating via a short-cut or modifying an existing config? If all works as expected that's a smart solution.
I'm asking because having a mechanism for that is a longer standing issue:
Overall I didn't see any blockers and I'm glad you added extensive tests.
org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/UnitTestSupport.java
Outdated
Show resolved
Hide resolved
org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/UnitTestSupport.java
Outdated
Show resolved
Hide resolved
* @param facade the maven project facade | ||
* @param monitor the progress monitor | ||
*/ | ||
private void loadPrerequisites(ILaunchConfiguration configuration, IMavenProjectFacade facade, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't/shouldn't the list of mojos executed before the test-plugin be derived from the computed Maven lifecycle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is a bit more complex as i think it can greatly impact performance. I'm afraid executing all plugins available in the maven lifecycle until this phase without knowing which ones are effectively producing properties is risky.
The only plugin provided by the maven team can safely be handled by default but about the others ....i'm not sure.
On the other hand providing the list of plugins to execute using a property feals more like a dirty hack than a clean solution.
If you have a way to know if a plugin generate some properties or a cleaner way to provide the list of plugin to execute it would be great as i plan to use the same kind of loading in another PR to be able to provide values for --patch-module directives from the compiler plugin to eclipse .classpath file in the fututre.
At this point i only can think of other ways like:
- providing a PR to maven surefire/failsafe/compiler plugin to provide the same kind of feature as the property but i'm skeptical the maven team will accept this PR more dedicated to IDE/Eclipse than maven itself
- providing some warning markers and some potential "quick fix" into the pom warning the user that plugins aren't executed until some configuration (property/project's preference) is set. (I'm completly clueless about how to do that but it would be cool but also time consuming)
What do you (or any other interested ) think about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @HannesWell,
After some research it seems the best way to handle this may be the lifecycle-metadata-mapping.
Currently a plugin may have the following configuration in the mapping:
ignore
execute(runOnConfiguration/runOnIncremental)
generator
So i propose to add a boolean "runOnLaunchConfiguration" or something more generic to fit the compiler case like "provideProperties" to the execute element to mark all plugins that need to be executed before setting up a launch configuration.
About the "generator" case, a new method can be added to org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator :
public void configureLaunchConfiguration(LaunchConfigurationRequest request, IProgressMonitor monitor) throws CoreException
or something like
public void loadPropertiesInContext(??, IProgressMonitor monitor) throws CoreException
What do you think about that ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think leveraging the lifecycle-mapping-metadata is the the better approach.
It would be ideal if we could re-use the existing metadata, but I assume it doesn't fit well in all cases, does it?
If new arguments are added, it should as general as possible and as specific as necessary.
But from what you have described enhancing the https://github.com/codehaus-plexus/plexus-build-api would maybe be another option?
Maybe @laeubi can help here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to simplify the review of this big change, I think it would be good to move the resolution of variables created by other plugins into a separate PR.
Would that be ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made another pass over this PR and have a couple of suggestions, mainly about reducing code size.
/******************************************************************************** | ||
* Copyright (c) 2024, 2024 pascal treilhes and others | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* pascal treilhes - initial API and implementation | ||
********************************************************************************/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/******************************************************************************** | |
* Copyright (c) 2024, 2024 pascal treilhes and others | |
* | |
* This program and the accompanying materials are made available under the | |
* terms of the Eclipse Public License 2.0 which is available at | |
* http://www.eclipse.org/legal/epl-2.0. | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
* Contributors: | |
* pascal treilhes - initial API and implementation | |
********************************************************************************/ | |
/******************************************************************************** | |
* Copyright (c) 2024, 2024 Pascal Treilhes and others | |
* | |
* This program and the accompanying materials are made available under the | |
* terms of the Eclipse Public License 2.0 which is available at | |
* http://www.eclipse.org/legal/epl-2.0. | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
* Contributors: | |
* Pascal Treilhes - initial API and implementation | |
********************************************************************************/ |
/** | ||
* Get the launch arguments | ||
* | ||
* @param configuration the configuration | ||
* @param facade the maven project facade | ||
* @param monitor the progress monitor | ||
* @return the launch arguments | ||
* @throws CoreException | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding java-doc to internal/private methods is not mandatory and if it just provides the information one can easily derive from the method and parameter names I find it even disturbing.
Therefore in this case and all other cases where the java-doc only provides obvious information please remove it.
/** | |
* Get the launch arguments | |
* | |
* @param configuration the configuration | |
* @param facade the maven project facade | |
* @param monitor the progress monitor | |
* @return the launch arguments | |
* @throws CoreException | |
*/ |
/** | ||
* Holder for the surefire/failsafe launch arguments | ||
*/ | ||
private static class TestLaunchArguments { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the other internal class can be reworked to be a one/two-line record.
Documentation each element in this case is probably also not necessary if it just replicates the the component name. Therefore it can be removed in most, if not all cases.
/** | ||
* Feature flag to enable or disable the support | ||
*/ | ||
public static boolean FEATURE_ENABLED = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are late in the development cycle (sorry for this) I suggest to disable this feature by default for now and enable it after the next release. Then you can already use it by setting the corresponding VM argument.
public static boolean FEATURE_ENABLED = true; | |
public static final boolean FEATURE_ENABLED = Boolean | |
.parseBoolean(System.getProperty("m2e.process.test.configuration", "true")); |
private static final Set<String> supportedTypes = new HashSet<>(); | ||
|
||
static { | ||
supportedTypes.add(MavenRuntimeClasspathProvider.JDT_JUNIT_TEST); | ||
supportedTypes.add(MavenRuntimeClasspathProvider.JDT_TESTNG_TEST); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static final Set<String> supportedTypes = new HashSet<>(); | |
static { | |
supportedTypes.add(MavenRuntimeClasspathProvider.JDT_JUNIT_TEST); | |
supportedTypes.add(MavenRuntimeClasspathProvider.JDT_TESTNG_TEST); | |
} | |
private static final Set<String> CONSIDERED_LAUNCH_TYPES = Set.of(MavenRuntimeClasspathProvider.JDT_JUNIT_TEST, MavenRuntimeClasspathProvider.JDT_TESTNG_TEST) |
and you should ensure that callers never try to get the value of a null key.
private static boolean isSupportedType(String id) { | ||
return supportedTypes.contains(id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can just be inlined.
private static boolean isSupportedType(String id) { | |
return supportedTypes.contains(id); | |
} | |
private static boolean isSupportedType(String id) { | |
return id!=null && CONSIDERED_LAUNCH_TYPES .contains(id); | |
} |
/** | ||
* Launch configuration attribute for the main class | ||
*/ | ||
public static final String LAUNCH_CONFIG_MAIN_CLASS = "org.eclipse.jdt.launching.MAIN_TYPE"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please restrict the visibility as far as possible. And some constants are even unused.
private static IMavenProjectFacade getMavenProjectFacade(IJavaProject project) { | ||
return MavenPlugin.getMavenProjectRegistry().getProject(project.getProject()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be inlined too.
* @param facade the maven project facade | ||
* @param monitor the progress monitor | ||
*/ | ||
private void loadPrerequisites(ILaunchConfiguration configuration, IMavenProjectFacade facade, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think leveraging the lifecycle-mapping-metadata is the the better approach.
It would be ideal if we could re-use the existing metadata, but I assume it doesn't fit well in all cases, does it?
If new arguments are added, it should as general as possible and as specific as necessary.
But from what you have described enhancing the https://github.com/codehaus-plexus/plexus-build-api would maybe be another option?
Maybe @laeubi can help here too?
* @param facade the maven project facade | ||
* @param monitor the progress monitor | ||
*/ | ||
private void loadPrerequisites(ILaunchConfiguration configuration, IMavenProjectFacade facade, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to simplify the review of this big change, I think it would be good to move the resolution of variables created by other plugins into a separate PR.
Would that be ok?
The following arguments are supported:
<argLine>
,<environmentVariables>
,<systemPropertyVariables>
,<workingDirectory>
,<enableAssertions>
,Configuration is propagated on unit test launch configuration creation and also when executing
maven > update project
By default and if found, the plugin maven-dependency-plugin (goal: properties) is executed before updating the launch configuration to load properties.
If properties set by other plugins are used in the failsafe/surefire plugin configuration it is possible to override the default loading behaviour by providing the list plugins and goals to execute using the property
m2e.launch.configuration.prerequisites
The expected format is as follow:
groupId1:artifactId1:goal1[,groupIdX:artifactIdX:goalX]*
Ex:
<m2e.launch.configuration.prerequisites>org.apache.maven.plugins:maven-dependency-plugin:properties,org.codehaus.mojo:properties-maven-plugin:read-project-properties</m2e.launch.configuration.prerequisites>