-
Notifications
You must be signed in to change notification settings - Fork 117
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
Move createProblemMarker() to AbstractProjectConfigurator and clean up #975
base: master
Are you sure you want to change the base?
Conversation
I think its a good idea. |
* </p> | ||
* | ||
* @param execution the execution | ||
* @param attribute the attribute to mark |
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.
It would be good to elaborate which values are valid here
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 assume that you can use any attribute of the plug-ins XML configuration, but I can check 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.
Maven pom.xml doesn’t use XML attributes. I have seen that element names have been given here.
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.
There are at least combine.*
attribute that Maven uses: https://maven.apache.org/pom.html#advanced_configuration_inheritance
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.
Those are not meant here IIUC.
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.
Actually (XML) elements
are meant her, not attributes
. Sorry for the confusion.
I just blindly copied that from the internal method.
@mickaelistria what do you think? |
Are there some connectors requesting this change? I don't mind growing the API if it does solve real problems; but growing the API without clear value should be avoided as it only prevents from further innovation. |
8b8be2e
to
44e43e0
Compare
Yes of course API additions should be well considered. But personally I don't have a need for that API at the moment. |
I have a need and would love to use the new methods in the configurators of https://github.com/apache/sling-ide-tooling/tree/master/eclipse/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal. |
facade = request.mavenProjectFacade(); | ||
} | ||
MavenProblemInfo problem = new MavenProblemInfo(message, severity, location); | ||
markerManager.addErrorMarker(facade.getPom(), IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, problem); |
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.
the marker id should be made configurable (given as additional argument) as not every consumer uses that 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.
Also IMavenConstants.MARKER_CONFIGURATION_ID
seems to be the more reasonable default for error with the configurator due to some mojo execution configuration.
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.
Also
IMavenConstants.MARKER_CONFIGURATION_ID
seems to be the more reasonable default for error with the configurator due to some mojo execution configuration.
Good point.
the marker id should be made configurable (given as additional argument) as not every consumer uses that ID
Do you want to use custom problem markers?
One problem I see here, is that in most cases consumers are probably fine with the default problem marker. But IMavenConstants.MARKER_CONFIGURATION_ID
is not part of the M2E's API so we should not encourage users to use it. Instead a overload of the method without marker-type that passes that type/id is probably more suitable. It should then make no claims about the type. If necessary we can just change the default in the future.
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.
If users want custom marker why can't they create them on their own?
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.
If users want custom marker why can't they create them on their own?
Most of the methods/classes used in that method are internal. So to create a custom marker one a consumer would have to rely on M2E internals or would have to copy a lot of other code to rely only on Eclipse/Maven API.
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 it is about the type/id String being custom. And from M2E the convenient way to add markers to a pom is wanted.
But why? Custom marker only make sense if you add custom attributes and handle those custom, otherwise one can simply reuse the m2e one.
we end up with a much larger API than just adding a overload with one additional parameter.
There are already many parameters and adding even more for unclear use-case do not make it better I think. All one needs would probably be in SourceLocationHelper
already...
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.
OK, that's a point.
Maybe @kwin can elaborate a bit more about his use case and what would fit?
Nevertheless a createProblemMarker()
method that creates IMavenConstants.MARKER_CONFIGURATION_ID
problems still seems reasonable for me.
So if suitable we can still create an API around SourceLocationHelper
and SourceLocation
later.
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.
But why? Custom marker only make sense if you add custom attributes and handle those custom, otherwise one can simply reuse the m2e one.
Custom markers appear in a dedicated section. There is not necessarily the need to set attributes on those. Also custom markers can be easily queried or cleared. So IMHO just exposing the marker ID as additional argument doesn't do any harm and allows this API to cover more use cases.
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.
OK sounds like there is a use-case for that.
Instead of having more and more arguments to that method, what do you think about encapsulating the problem data into a record with static factories?
The components would be int problemSeverity, String problemMessage, String markerId
and two static factory methods
create(int problemSeverity, String problemMessage)
create(int problemSeverity, String problemMessage, String markerId)
The first one uses IMavenConstants.MARKER_CONFIGURATION_ID
as markerId
.
The java-doc of the record should then state that only canonical constructor is considered internal and should not be called by clients (maybe with @noinstanciate
) and only the static factories should be used.
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.
Sounds good to me.
a2164db
to
3ea6ea2
Compare
This makes createProblemMarker() part of the AbstractProjectConfigurator API and therefore available to downstream implementors.
3ea6ea2
to
8514ffd
Compare
@kwin do you have any more comments on this? |
* {@link IMarker#SEVERITY_WARNING SEVERITY_WARNING} or {@link IMarker#SEVERITY_ERROR SEVERITY_ERROR} | ||
* @param problemMessage the message of the created problem marker | ||
*/ | ||
protected void createProblemMarker(MojoExecution execution, String element, ProjectConfigurationRequest request, |
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.
Could the IMarker be returned here?
What if one wants to create the marker on the value of the element? Can't we give it a text position instead, and an helper to locate an element in a mojoExecution?
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.
Could the IMarker be returned here? What if one wants to create the marker on the value of the element?
In general IMavenMarkerManager
could be changed to return the marker too.
Creating the marker at the value is not yet supported, but in general could be considered.
Can't we give it a text position instead, and an helper to locate an element in a mojoExecution?
Yes Christoph suggested that as well before.
And after some rethinking about it, it is probably the better way for a generalization because IIRC for markers of custom Ids m2e just creates them using the Eclipse Resources API. So there is no benefit in providing an extra API for that. But I have to check that again.
However I think for a simple case a convenient API method like this would be useful nevertheless.
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.
However I think for a simple case a convenient API method like this would be useful nevertheless.
There is uncertainity with this API that needs to be covered before it can be claimed "API-quality" (ie we won't want to change it for a long time), and this comes by nature of using the "element" name:
- How to place a marker on the value or a subset of the value? Or on some attribute (some mojo configuration may like it?
- What happens is the element is repeated in the configuration?
- What happens if there is no such element in the configuration?
- ...
All those questions wouldn't be raised if we clearly separate locating the marker vs creating it. If it is clear that locating the marker is the important part, and not creating it (because Platform API is enough), then instead of API to create a marker, we should have an API to reoslve locations and use already existing satisfying APIs from Platform to create it.
@mickaelistria @HannesWell @kwin do you plan to finish this one? |
Yes I do, altough it isn't my no1 priority at the moment. |
Looks like i could use this to improve the Maven Settings dialog in eclipse preferences to list all validation problems with the settings or toolchain files. Actually only the first error is squeezed into the upper text output in the dialog. All info is lost after closing the dialog. But in this case i need more a factory like |
This makes createProblemMarker() part of the
AbstractProjectConfigurator
API and therefore available to downstream implementors and makes it simpler for them to create problem markers.@mickaelistria, @laeubi what do you think?