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

Surefire/Failsafe plugin configuration propagated to Junit/TestNG launch configuration #1672

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

treilhes
Copy link
Contributor

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>

@treilhes
Copy link
Contributor Author

treilhes commented Feb 13, 2024

Fixes #700

Copy link

github-actions bot commented Feb 13, 2024

Test Results

0 tests   - 665   0 ✅  - 654   0s ⏱️ - 9m 26s
0 suites  - 107   0 💤  -  10 
0 files    - 107   0 ❌  -   1 

Results for commit 9e896d2. ± Comparison against base commit 8d3ff09.

♻️ This comment has been updated with latest results.

@treilhes treilhes mentioned this pull request Feb 14, 2024
@HannesWell
Copy link
Contributor

@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.
So unless another committer reviews this your patience is kindly requested.

@treilhes
Copy link
Contributor Author

@HannesWell
Don't worry, my patience will handle this just fine. Have great holidays. thank you for having warned

@treilhes
Copy link
Contributor Author

@HannesWell, I miss you so much, I long to hear from you about your vacation (and to get a bit of review) 💔

@HannesWell
Copy link
Contributor

@HannesWell, I miss you so much, I long to hear from you about your vacation (and to get a bit of review) 💔

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).

@treilhes
Copy link
Contributor Author

@HannesWell Bump ❤️

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.

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.

* @param facade the maven project facade
* @param monitor the progress monitor
*/
private void loadPrerequisites(ILaunchConfiguration configuration, IMavenProjectFacade facade,
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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 ?

Copy link
Contributor

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?

Copy link
Contributor

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?

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.

I made another pass over this PR and have a couple of suggestions, mainly about reducing code size.

Comment on lines +1 to +12
/********************************************************************************
* 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
********************************************************************************/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/********************************************************************************
* 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
********************************************************************************/

Comment on lines +397 to +405
/**
* 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
*/
Copy link
Contributor

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.

Suggested change
/**
* 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 {
Copy link
Contributor

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;
Copy link
Contributor

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.

Suggested change
public static boolean FEATURE_ENABLED = true;
public static final boolean FEATURE_ENABLED = Boolean
.parseBoolean(System.getProperty("m2e.process.test.configuration", "true"));

Comment on lines +196 to +201
private static final Set<String> supportedTypes = new HashSet<>();

static {
supportedTypes.add(MavenRuntimeClasspathProvider.JDT_JUNIT_TEST);
supportedTypes.add(MavenRuntimeClasspathProvider.JDT_TESTNG_TEST);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines +239 to +241
private static boolean isSupportedType(String id) {
return supportedTypes.contains(id);
}
Copy link
Contributor

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.

Suggested change
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";
Copy link
Contributor

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.

Comment on lines +393 to +395
private static IMavenProjectFacade getMavenProjectFacade(IJavaProject project) {
return MavenPlugin.getMavenProjectRegistry().getProject(project.getProject());
}
Copy link
Contributor

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,
Copy link
Contributor

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,
Copy link
Contributor

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?

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.

None yet

2 participants