-
Notifications
You must be signed in to change notification settings - Fork 113
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
Expose ArchetypeGenerator and ArchetypeManager #922
Conversation
34a5d55
to
c0ab7c4
Compare
@laeubi The compilation inside Eclipse works fine and
The target file though contains the bundle |
I think the problem is that Tycho 2.4 is used 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.
Just moving this is IMO not enough. We need to audit what are the real operations necessary to be exposed for clients to efficiently use the Archetype API here. Many operations in the promoted APIs can probably remain implementation-internal and should then be so.
org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/archetype/ArchetypeGenerator.java
Outdated
Show resolved
Hide resolved
org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/archetype/package-info.java
Outdated
Show resolved
Hide resolved
...lipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypeGeneratorImpl.java
Outdated
Show resolved
Hide resolved
The reasoning is in #921. This PR obviously just contains the code changes. |
The reasoning "it was this way before" is not viable. The API was removed in this major version because it wasn't appearing as useful to anyone involved regularly in the development of m2e. That is already a sign that the API state should be challenged and not cloned for the future of m2e. If we're to reopen an API, it can and should be a minimal one, just like if we were starting it from scratch. |
|
So you would only need a way to run something like |
@kwin I think Tycho support requires version 3.0.0 what will be released end of month for those annotations. |
public interface ArchetypeGenerator { | ||
|
||
/** | ||
* Creates project structure using the given archetype and then imports created project(s) |
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 javadoc (although just copied from ArchetypeGeneratorImpl) seems to require an update, as Eclipse projects are no longer created by this method.
org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/archetype/ArchetypeGenerator.java
Outdated
Show resolved
Hide resolved
@kwin if you rebase on top of the current master, some (maybe all) of the CI failures should vanish. |
Before I rebase and adjust the tests I would like to know if you are fine with the proposed API exposure. |
@mickaelistria any more comments regarding API? I think this would be good to make a release after this so @kwin can adapt to the changes... |
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 looks fresher and a well focused API! I just have a couple of questions/comments inline.
org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/archetype/ArchetypeGenerator.java
Outdated
Show resolved
Hide resolved
org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/archetype/MavenArchetype.java
Outdated
Show resolved
Hide resolved
Also expose necessary MavenArchetype (as the only implementation of IArchetype) This closes eclipse-m2e#921
ca61f5a
to
d39e00f
Compare
org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/archetype/ArchetypeManager.java
Outdated
Show resolved
Hide resolved
...lipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypeGeneratorImpl.java
Outdated
Show resolved
Hide resolved
@@ -74,8 +77,8 @@ | |||
* | |||
* @author Eugene Kuleshov | |||
*/ | |||
@Component(service = ArchetypePlugin.class) | |||
public class ArchetypePlugin { | |||
@Component(service = {ArchetypeManager.class, ArchetypePlugin.class}) |
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.
ArchetypePlugin
should not be exposed as a service 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.
Not possible, as the ArchetypePlugin is the internal API which is used. If you would only register as ArchetypeManager (public API) you would need to cast in M2EUIPluginActivator. How do you want to get hold of this without casting?
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.
Internal code can cast to internal Implementations but this should not be used as declared services (wich are exposed to everyone in the OSGi framework!)
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.
you are exporting internal packages and by that exposing them to everyone in the framework anyways, but I am open to other suggestions. In case you prefer casting, what should happen if the implementation does not implement ArchetypePlugin
? DS allows to replace one service implementation with another one!
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 remember that you previously registered only to the internal API ArchetypePlugin via DS, so that pattern is not something I introduced.
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.
DS allows to replace one service implementation with another one!
This has nothing to do with DS, anyways you would be most likely wrecked then anyways. If you want be extra you can assert the type with instanceof and throw an exception otherwise...
Also remember that you previously registered only to the internal API ArchetypePlugin via DS, so that pattern is not something I introduced.
Many thing in m2e need improvements and some are just for migrating thing so we should not take this as good examples when refactoring/rework things.
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.
You shouldn’t make this a prerequisite. It can be improved by someone else in a follow up
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 Softwaredevelopment "later" often means "never" :-)
I would prefer to have a cast on the cases where it is required (that is we use no API method) as this is already done elsewhere in m2e and shows where we have an API gap...
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, fixed in 0306f85.
* @since 2.1.0 (package version 1.0.0) | ||
*/ | ||
@ProviderType | ||
public interface ArchetypeManager { |
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.
Why is ArchetypeManager public? Should ArchetypeGenerator not be enough?
Looks good so far, just wondering if we really need to make |
ArchetypeManager is used e.g. in https://github.com/apache/sling-ide-tooling/blob/93bcb69fe7cfad6b68d5caf838a14d3bdf887b92/eclipse/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ChooseArchetypeWizardPage.java#L352 to filter archetypes exposed from any of the configured catalogs. Also it is used in https://github.com/apache/sling-ide-tooling/blob/93bcb69fe7cfad6b68d5caf838a14d3bdf887b92/eclipse/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/ArchetypeParametersWizardPage.java#L273 to render a custom new project wizard for specific archetypes. |
But all these should be m2e internal, so can we not make |
I use it outside of m2e, so I prefer using it with an API. I don't want to depend on internal API for my use case which was the original driver for this PR. |
Can you explain how you use this? Do you provide own UI wizard? The main problem with this (and why it was decided to make this "non API") is that the Archetype is a separate plugin, so exposing its classes directly has two problems:
This has lead to the situation that previously m2e a very long time relied on outdated Archetype 2.x. and it was quite hard to upgrade to 3.x. The result is/was the Can you check if for your use-case something similar would be possible to have (read only) facade types with a reduced signature for |
We are going in circles here, I cannot explain better than above: #922 (comment). Have you checked the code? |
@kwin sorry I mixed that up with a previous comment from usages inside m2e. About |
About |
Our product uses the ArchetypeGenerator and friends. Is there still time to look at something and provide comments? |
I think best would be too finish this PR and then if there are still things missing start with a new PR. |
If it directly about what is changed in this PR I think comments should be made now. Of course it can be started again afterwards, but if possible why not consider them now but later? |
@kwin can you please rebase this change on top of the current master? |
|
||
/** | ||
* Creates a project structure using the given archetype in non-interactive mode. | ||
* |
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 have javadoc for params, or you'll get all the javadoc warnings especially since j17+ have turned it up, and for sure it's always a pity to not have these! esp handy is what can be null, what is optional, etc.
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 remember our integration had to dive into source to understand what "interactive mode" was
* Gets the required properties of an {@link IArchetype}. | ||
* | ||
* @param archetype the archetype possibly declaring required properties | ||
* @param remoteArchetypeRepository the remote archetype repository, can be null |
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.
param is not in sync with actual
* @param archetype the archetype possibly declaring required properties | ||
* @param remoteArchetypeRepository the remote archetype repository, can be null | ||
* @param monitor the progress monitor, can be null | ||
* @return the required properties of the archetypes, null if none is found |
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.
when your signature has a list, isn't it eclipse code guidelines to not return null and return an empty list instead?
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.
+1, it's generally a good practice to not return null for Arrays or Collections but empty ones; not only for Eclipse but for Java in general.
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.
Better return an Optional<...>
instead then. There is a difference between an Archetype not found and having no required properties... one might even throw a CoreException if not found 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.
Better return an Optional<...> instead then.
I don't think so.
There is a difference between an Archetype not found and having no required properties..
Maybe, but that's not the goal of this method to detect that an Archetype is not found. But your comment here emphasize that documentation is ambiguous and that there are different ways to interpret none
.
one might even throw a CoreException if not found here ...
CoreException is just an abstract exception in Eclipse world; creating a custom exception type would be better for an 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.
Better return an Optional<...> instead then.
I don't think so.
Why? Either is is optional (because it is fine / could happen) but then it is not valid to just return an empty list if nothing is found as a user of that method then falsely assumes everything is fine and one could potentially call this archetype (what will just fail because it is not found)...
Maybe, but that's not the goal of this method to detect that an Archetype is not found. But your comment here emphasize that documentation is ambiguous and that there are different ways to interpret none.
Obviously there is a way to detect this, so either it is an error (= exception must be thrown) or a user has to be able to distinguish the cases.
There is a lot of literature against null collections, the most "reference" one being the "Effective Java" book, Your comment is based IMO on a dogmatic vision of API development; but experience of the whole Java (and other languages as well) community has concluded that returning null collections is more an anti-pattern than a benefit.
Or maybe we just don't care about distinguishing, do we? Or maybe since we have an |
And how does it relates to returning an empty Optional in case nothing could be computed here?
The parameter is just a simple container object and obviously the creator of that method has taken into account that the archetype is not present. |
Given the comments, it seems like the overall design of those APIs is then questionable as they come with very poor guarantee about validity and lifecycle of instances. So the current IArchetype is not an IArchetype then, it's just a GAV which is more used as an ArchetypeRequest. If I have an IArchetype, in a good API, I expect the archetype exists. The issue is then not what to do with a non existing IArchetype, it's that the API should ensure an IArchetype maps to something existing. |
What's the status here? |
@kwin please rebase and resolve conflicts. |
Closing this for now as no progress and no response, but feel fre to just reopen or provide a new PR on the top of the master branch. |
This closes #921