jtulach commented on code in PR #9650:
URL: https://github.com/apache/netbeans/pull/9650#discussion_r4167534566
##########
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:
Done in c01de98d009b - together with introduction of a new argument type, it
is binary compatible change as [analyzed
here](https://wiki.apidesign.org/wiki/DefaultMethods#Apply_the_Knowledge).
--
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