You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ma...@apache.org on 2021/03/03 20:50:53 UTC

[netbeans] branch master updated: [NETBEANS-5380] Override generated ant projects for MX with NetBeans support

This is an automated email from the ASF dual-hosted git repository.

matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 460042b  [NETBEANS-5380] Override generated ant projects for MX with NetBeans support
     new e7e63e5  Merge pull request #2789 from matthiasblaesing/netbeans-5380
460042b is described below

commit 460042be723b28b430f88c77c1ee7ab18f364892
Author: Matthias Bläsing <mb...@doppel-helix.eu>
AuthorDate: Sat Feb 27 08:57:59 2021 +0100

    [NETBEANS-5380] Override generated ant projects for MX with NetBeans support
    
    In profiles from repositry updater runs a huge CPU load originating
    from SuiteFileOwnerQueryImpl was found. In parallel excessive runtimes
    for project scanning were observed.
    
    Comparing SuiteFileOwnerQueryImpl and SimpleFileOwnerQueryImplementation
    the latter has an aggressive caching system, which results in much less
    cpu usage. Just removing SuiteFileOwnerQueryImpl is not a solution, as
    it is used to override the default project detection from
    SimpleFileOwnerQueryImplementation.
    
    Explanation from Jaroslav Tulach:
    
    [...] Historically the Graal project provided mx netbeansinit support
    which generates 8.2 Ant nbproject/project.xml projects based on content
    of suite/mx.suite/suite.py. They were usually located in
    suite/src/*/nbproject directories.
    
    To fix this, the idea is, not only to use the current MX project
    detection (it requires a folder `mx.proj` to be found in the project
    folder `proj`), but also look two level ups from the current directory.
    If that directory is recognised as a MX project, that project will
    be returned as the project for the requested directory.
---
 .../modules/java/mx/project/SuiteFactory.java      | 43 +++++++++++++-
 .../java/mx/project/SuiteFileOwnerQueryImpl.java   | 69 ----------------------
 2 files changed, 40 insertions(+), 72 deletions(-)

diff --git a/java/java.mx.project/src/org/netbeans/modules/java/mx/project/SuiteFactory.java b/java/java.mx.project/src/org/netbeans/modules/java/mx/project/SuiteFactory.java
index 4f9763a..9118b48 100644
--- a/java/java.mx.project/src/org/netbeans/modules/java/mx/project/SuiteFactory.java
+++ b/java/java.mx.project/src/org/netbeans/modules/java/mx/project/SuiteFactory.java
@@ -29,7 +29,22 @@ import org.openide.filesystems.FileObject;
 import org.openide.util.ImageUtilities;
 import org.openide.util.lookup.ServiceProvider;
 
-@ServiceProvider(service = ProjectFactory.class)
+/**
+ * Project API Interation for MX projects.
+ *
+ * <p>The MX project support makes the assumption, that MX projects can be
+ * identified by the convention, that the project dir 'proj' has a child folder
+ * named 'mx.proj'. So the expected path is 'proj/mx.proj'.</p>
+ *
+ * <p>To support loading legacy MX projects, for which NetBeans Java projects
+ * were generated by running {@code mx netbeansinit}, it is further assumed,
+ * that the "subprojects" are always inside the src folder of the "real"
+ * project. Based on the above subprojects can be found in 'proj/src/subproj'
+ * and to identify the real project, the folder two levels higher needs to be
+ * checked.
+ * </p>
+ */
+@ServiceProvider(service = ProjectFactory.class, position = 50 /* must be lower than ant java project support*/)
 public class SuiteFactory implements ProjectFactory2 {
     @Override
     public boolean isProject(FileObject fo) {
@@ -39,7 +54,22 @@ public class SuiteFactory implements ProjectFactory2 {
     static FileObject findSuitePy(FileObject fo) {
         final String mxDirName = "mx." + fo.getNameExt();
         FileObject suitePy = fo.getFileObject(mxDirName + '/' + "suite.py");
-        return suitePy;
+        if(suitePy != null) {
+            return suitePy;
+        }
+
+        // Support the case where a subproject is directly opened. The mx
+        // netbeans configuration generator generates java ant projects on the
+        // subproject level. This is detected and overriden by this factory.
+        FileObject baseDir2 = fo.getParent() != null ? fo.getParent().getParent() : null;
+
+        if (baseDir2 != null) {
+            final String mxDirName2 = "mx." + baseDir2.getNameExt();
+            FileObject suitePy2 = baseDir2.getFileObject(mxDirName2 + '/' + "suite.py");
+            return suitePy2;
+        } else {
+            return null;
+        }
     }
 
     @Override
@@ -49,7 +79,14 @@ public class SuiteFactory implements ProjectFactory2 {
             return null;
         }
         MxSuite suite = MxSuite.parse(suitePy.toURL());
-        return new SuiteProject(dir, suitePy, suite);
+        if(dir.equals(suitePy.getParent().getParent())) {
+            return new SuiteProject(dir, suitePy, suite);
+        } else {
+            // loadProject could be called on a subproject, in that the "right"
+            // path is still the parent folder of the folder, suite.py was found
+            // in
+            return ProjectManager.getDefault().findProject(suitePy.getParent().getParent());
+        }
     }
 
     @Override
diff --git a/java/java.mx.project/src/org/netbeans/modules/java/mx/project/SuiteFileOwnerQueryImpl.java b/java/java.mx.project/src/org/netbeans/modules/java/mx/project/SuiteFileOwnerQueryImpl.java
deleted file mode 100644
index 23bbe87..0000000
--- a/java/java.mx.project/src/org/netbeans/modules/java/mx/project/SuiteFileOwnerQueryImpl.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.netbeans.modules.java.mx.project;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import org.netbeans.api.project.Project;
-import org.netbeans.api.project.ProjectManager;
-import org.netbeans.spi.project.FileOwnerQueryImplementation;
-import org.openide.filesystems.FileObject;
-import org.openide.filesystems.URLMapper;
-import org.openide.util.Exceptions;
-import org.openide.util.lookup.ServiceProvider;
-
-@ServiceProvider(service = FileOwnerQueryImplementation.class, position = 11)
-public final class SuiteFileOwnerQueryImpl implements FileOwnerQueryImplementation {
-    @Override
-    public Project getOwner(URI url) {
-            for (;;) {
-                FileObject fo;
-                try {
-                    fo = URLMapper.findFileObject(url.toURL());
-                } catch (MalformedURLException ex) {
-                    fo = null;
-                }
-                if (fo != null) {
-                    return getOwner(fo);
-                }
-                url = url.resolve("..");
-            }
-    }
-
-    @Override
-    public Project getOwner(FileObject file) {
-        for (;;) {
-            if (file == null) {
-                return null;
-            }
-            if (file.getFileObject(".mxignore") != null) {
-                return null;
-            }
-            if (SuiteFactory.findSuitePy(file) != null) {
-                try {
-                    return ProjectManager.getDefault().findProject(file);
-                } catch (IOException ex) {
-                    Exceptions.printStackTrace(ex);
-                }
-            }
-            file = file.getParent();
-        }
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists