neilcsmith-net commented on code in PR #9650:
URL: https://github.com/apache/netbeans/pull/9650#discussion_r4172463499
##########
ide/projectapi/src/org/netbeans/api/project/ProjectManager.java:
##########
@@ -141,6 +146,54 @@ public Project findProject(@NonNull final FileObject
projectDirectory) throws IO
}
return impl.findProject(projectDirectory);
}
+
+ /** Finds a project corresponding to the given directory. This method
behaves
+ * exactly as {@link #findProject}, just instead of {@code null} it returns
+ * the <em>fallback project</em> - e.g. if the directory isn't recognized
as a project,
+ * a <em>fallback project</em> is created and registered with the
directory.
+ *
+ * <h2>Fallback Project</h2>
+ * <p>
+ * The <em>fallback project</em> is dummy representation of a folder on
+ * disk, but it can be extended via {@link LookupMerger} mechanism. The
+ * project uses {@code org-netbeans-modules-project-fallback} ID.
+ * </p>
+ * <p>
+ * For example its {@link Project#getLookup()} can be extended by
registering
+ * instance of {@link LookupProvider} into
+ * {@code Projects/org-netbeans-modules-project-fallback/Lookup}
+ * configuration directory. Either via {@code layer.xml}, or annotations
+ * that generate the layer like
+ * </p>
+ * <pre>
+ * @ProjectServiceProvider(service = LookupProvider.class, projectTypes = {
+ * @LookupProvider.Registration.ProjectType(id =
"org-netbeans-modules-project-fallback", position = 11000)
+ * })
+ * </pre>
+ * <p>
+ * It is also possible to register {@link ActionProvider} via such a
lookup.
+ * </p>
+ *
+ * @param projectDirectory the project top directory
+ * @return the project (object identity may or may not vary between calls)
+ * @throws IOException if the project was recognized but could not be
loaded
+ * @throws IllegalArgumentException if the supplied file object is null or
not a folder
+ * @since 1.111
+ */
+ @NonNull
+ public Project findProjectOrFallback(@NonNull FileObject projectDirectory)
throws IOException, IllegalArgumentException {
+ if (projectDirectory == null) {
+ throw new IllegalArgumentException("Attempted to pass a null
directory to findProject"); // NOI18N
+ }
+ if (!projectDirectory.isFolder()) {
+ throw new IllegalArgumentException("Attempted to pass a
non-directory to findProject: " + projectDirectory); // NOI18N
+ }
+ if (impl instanceof ProjectManagerImplementation.WithFallback implV2) {
+ return implV2.findProjectOrFallback(projectDirectory);
+ } else {
+ throw new IllegalArgumentException("Cannot create fallback project
for " + projectDirectory); // NOI18N
Review Comment:
> Which exception do you have in mind? The [NPE that could be throw
here](https://github.com/apache/netbeans/pull/9650/changes#diff-a882af68fbc3397e8bc42d88596b191bfed99622d3520b1c3afd3e16d6efc12cR193)?
Well, that's never going to be thrown as with `FindOptions.WITH_FALLBACK`
argument the implementation never returns `null`.
Exactly that NPE. Sure, your _implementation_ never returns `null`, but the
public SPI interface default method does. Now, if we're treating that as an
SPI that can only have one implementation, that's fine, but then the arguments
about maintaining compatibility don't really hold.
So, we _could_ have `ProjectManager::findProjectOrFallback` throw an
exception like this in cases where the implementation doesn't override the
default method. But it is _not_ then a simple drop-in replacement for
`ProjectManager::findProject`. Your changes in `DirectoryGroup` and
`OpenProjectList` retain the `null` check that is no longer needed, but will
hit a different code path if an SPI implementation causes an exception - the
latter will catch it, but the former will blow up I think?
So, if we want to treat this as a simple drop-in replacement across our
internal code _and_ treat it as a public SPI, I think it's easier to allow a
`null` return as with `ProjectManager::findProject` when fallback creation
fails. If not, then the usages in this PR might need a rethink.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists