You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/10/22 01:13:04 UTC

[GitHub] fvogler closed pull request #976: [NETBEANS-1481] Fix handling of module fragments (regression 9.0)

fvogler closed pull request #976: [NETBEANS-1481] Fix handling of module fragments (regression 9.0)
URL: https://github.com/apache/incubator-netbeans/pull/976
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/platform/o.n.bootstrap/src/org/netbeans/ModuleManager.java b/platform/o.n.bootstrap/src/org/netbeans/ModuleManager.java
index 4db13c7a00..59e183761b 100644
--- a/platform/o.n.bootstrap/src/org/netbeans/ModuleManager.java
+++ b/platform/o.n.bootstrap/src/org/netbeans/ModuleManager.java
@@ -1678,10 +1678,12 @@ public boolean hasToEnableCompatModules(Set<Module> modules) throws IllegalArgum
         }
         return false;
     }
-    
+
     private void maybeAddToEnableList(Set<Module> willEnable, Set<Module> mightEnable, Module m, boolean okToFail) {
-        if (! missingDependencies(m).isEmpty()) {
-            assert okToFail : "Module " + m + " had unexpected problems: " + missingDependencies(m) + " (willEnable: " + willEnable + " mightEnable: " + mightEnable + ")";
+        if (!missingDependencies(m).isEmpty()) {
+            if (!okToFail) {
+                Util.err.info("Module " + m + " had unexpected problems: " + missingDependencies(m) + " (willEnable: " + willEnable + " mightEnable: " + mightEnable + ")");
+            }
             // Cannot satisfy its dependencies, exclude it.
             return;
         }
@@ -1746,8 +1748,8 @@ private void maybeAddToEnableList(Set<Module> willEnable, Set<Module> mightEnabl
         }
         Collection<Module> frags = getAttachedFragments(m);
         for (Module fragMod : frags) {
-            if (! fragMod.isEnabled()) {
-                maybeAddToEnableList(willEnable, mightEnable, fragMod, false);
+            if (!fragMod.isEnabled() && !fragMod.isAutoload()) {
+                maybeAddToEnableList(willEnable, mightEnable, fragMod, fragMod.isEager());
             }
         }
     }
diff --git a/platform/o.n.bootstrap/test/unit/data/jars/fragment-module-missing-token.mf b/platform/o.n.bootstrap/test/unit/data/jars/fragment-module-missing-token.mf
new file mode 100644
index 0000000000..bb2ed93913
--- /dev/null
+++ b/platform/o.n.bootstrap/test/unit/data/jars/fragment-module-missing-token.mf
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+OpenIDE-Module: org.foo.fragment.missing.token
+OpenIDE-Module-Fragment-Host: org.foo.host
+OpenIDE-Module-Name: Fragment Content Module with missing token
+OpenIDE-Module-Requires: missing.token
diff --git a/platform/o.n.bootstrap/test/unit/data/jars/fragment-module-missing-token/org/foo2/FragmentContent.java b/platform/o.n.bootstrap/test/unit/data/jars/fragment-module-missing-token/org/foo2/FragmentContent.java
new file mode 100644
index 0000000000..9591f2c1bb
--- /dev/null
+++ b/platform/o.n.bootstrap/test/unit/data/jars/fragment-module-missing-token/org/foo2/FragmentContent.java
@@ -0,0 +1,26 @@
+/*
+ * 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.foo;
+// Does not do anything, just needs to be here & loadable.
+public class FragmentContent {
+    protected String something() {
+        return "I am an added fragment with missing token";
+    }
+}
diff --git a/platform/o.n.bootstrap/test/unit/data/jars/fragment-module-user.mf b/platform/o.n.bootstrap/test/unit/data/jars/fragment-module-user.mf
new file mode 100644
index 0000000000..b5b6c461b8
--- /dev/null
+++ b/platform/o.n.bootstrap/test/unit/data/jars/fragment-module-user.mf
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+OpenIDE-Module: org.foo.fragment.user
+OpenIDE-Module-Name: Depends on a module fragment
+OpenIDE-Module-Module-Dependencies: org.foo.fragment
+
diff --git a/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java b/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java
index 187c779fcc..8a2d6c3ebd 100644
--- a/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java
+++ b/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java
@@ -2760,6 +2760,189 @@ public void testMissingSpecVersion() throws Exception {
         Module client = mgr.create(jar, null, false, false, false);
         assertEquals(1, client.getProblems().size());
     }
+
+    public void testEnableHostWithDefautFragment() throws Exception {
+        MockModuleInstaller installer = new MockModuleInstaller();
+        MockEvents ev = new MockEvents();
+        ModuleManager mgr = new ModuleManager(installer, ev);
+        mgr.mutexPrivileged().enterWriteAccess();
+
+        Module host = mgr.create(new File(jars, "host-module.jar"), null, false, false, false);
+        Module fragment = mgr.create(new File(jars, "fragment-module.jar"), null, false, false, false);
+
+        assertTrue("Host is known", mgr.getModules().contains(host));
+        assertTrue("Fragment is known", mgr.getModules().contains(fragment));
+
+        mgr.enable(new HashSet<>(Arrays.asList(host, fragment)));
+
+        assertTrue("Host must be enabled", mgr.getEnabledModules().contains(host));
+        assertTrue("Fragment must be enabled", mgr.getEnabledModules().contains(fragment));
+    }
+
+    public void testEnableHostWithDefautFragmentUnsatisfied() throws Exception {
+        MockModuleInstaller installer = new MockModuleInstaller();
+        MockEvents ev = new MockEvents();
+        ModuleManager mgr = new ModuleManager(installer, ev);
+        mgr.mutexPrivileged().enterWriteAccess();
+
+        createTestJAR(data, jars, "fragment-module-missing-token", null);
+
+        Module host = mgr.create(new File(jars, "host-module.jar"), null, false, false, false);
+        Module fragment = mgr.create(new File(jars, "fragment-module-missing-token.jar"), null, false, false, false);
+
+        assertTrue("Host is known", mgr.getModules().contains(host));
+        assertTrue("Fragment is known", mgr.getModules().contains(fragment));
+
+        boolean expectedExceptionCatched = false;
+        try {
+            mgr.enable(fragment);
+        } catch (IllegalArgumentException e) {
+            expectedExceptionCatched = e.getMessage().startsWith("Not all requested modules can be enabled:");
+            if (!expectedExceptionCatched) {
+                throw e;
+            }
+        }
+        assertTrue(expectedExceptionCatched);
+
+        mgr.enable(host);
+
+        assertTrue("Host must be enabled", mgr.getEnabledModules().contains(host));
+        assertTrue("Fragment must not be enabled", !mgr.getEnabledModules().contains(fragment));
+    }
+
+    public void testEnableHostWithEagerFragment() throws Exception {
+        MockModuleInstaller installer = new MockModuleInstaller();
+        MockEvents ev = new MockEvents();
+        ModuleManager mgr = new ModuleManager(installer, ev);
+        mgr.mutexPrivileged().enterWriteAccess();
+
+        Module host = mgr.create(new File(jars, "host-module.jar"), null, false, false, false);
+        Module fragment = mgr.create(new File(jars, "fragment-module.jar"), null, false, false, true);
+
+        assertTrue("Host is known", mgr.getModules().contains(host));
+        assertTrue("Fragment is known", mgr.getModules().contains(fragment));
+
+        mgr.enable(host);
+
+        assertTrue("Host must be enabled", mgr.getEnabledModules().contains(host));
+        assertTrue("Fragment must be enabled", mgr.getEnabledModules().contains(fragment));
+    }
+
+    public void testEnableHostWithEagerFragmentUnsatisfied() throws Exception {
+        MockModuleInstaller installer = new MockModuleInstaller();
+        MockEvents ev = new MockEvents();
+        ModuleManager mgr = new ModuleManager(installer, ev);
+        mgr.mutexPrivileged().enterWriteAccess();
+
+        createTestJAR(data, jars, "fragment-module-missing-token", null);
+
+        Module host = mgr.create(new File(jars, "host-module.jar"), null, false, false, false);
+        Module fragment = mgr.create(new File(jars, "fragment-module-missing-token.jar"), null, false, false, true);
+
+        assertTrue("Host is known", mgr.getModules().contains(host));
+        assertTrue("Fragment is known", mgr.getModules().contains(fragment));
+
+        mgr.enable(host);
+
+        assertTrue("Host must be enabled", mgr.getEnabledModules().contains(host));
+        assertTrue("Fragment must not be enabled", !mgr.getEnabledModules().contains(fragment));
+    }
+
+    public void testEnableHostWithAutoloadFragment() throws Exception {
+        MockModuleInstaller installer = new MockModuleInstaller();
+        MockEvents ev = new MockEvents();
+        ModuleManager mgr = new ModuleManager(installer, ev);
+        mgr.mutexPrivileged().enterWriteAccess();
+
+        Module host = mgr.create(new File(jars, "host-module.jar"), null, false, false, false);
+        Module fragment = mgr.create(new File(jars, "fragment-module.jar"), null, false, true, false);
+
+        assertTrue("Host is known", mgr.getModules().contains(host));
+        assertTrue("Fragment is known", mgr.getModules().contains(fragment));
+
+        mgr.enable(host);
+
+        assertTrue("Host must be enabled", mgr.getEnabledModules().contains(host));
+        assertTrue("Fragment must not be enabled", !mgr.getEnabledModules().contains(fragment));
+    }
+
+    public void testEnableHostWithAutoloadFragmentUnsatisfied() throws Exception {
+        MockModuleInstaller installer = new MockModuleInstaller();
+        MockEvents ev = new MockEvents();
+        ModuleManager mgr = new ModuleManager(installer, ev);
+        mgr.mutexPrivileged().enterWriteAccess();
+
+        createTestJAR(data, jars, "fragment-module-missing-token", null);
+
+        Module host = mgr.create(new File(jars, "host-module.jar"), null, false, false, false);
+        Module fragment = mgr.create(new File(jars, "fragment-module-missing-token.jar"), null, false, true, false);
+
+        assertTrue("Host is known", mgr.getModules().contains(host));
+        assertTrue("Fragment is known", mgr.getModules().contains(fragment));
+
+        mgr.enable(host);
+
+        assertTrue("Host must be enabled", mgr.getEnabledModules().contains(host));
+        assertTrue("Fragment must not be enabled", !mgr.getEnabledModules().contains(fragment));
+    }
+
+    public void testEnableHostWithAutoloadFragmentAndFragmentDependency() throws Exception {
+        MockModuleInstaller installer = new MockModuleInstaller();
+        MockEvents ev = new MockEvents();
+        ModuleManager mgr = new ModuleManager(installer, ev);
+        mgr.mutexPrivileged().enterWriteAccess();
+
+        createTestJAR(data, jars, "fragment-module-user", null);
+
+        Module host = mgr.create(new File(jars, "host-module.jar"), null, false, false, false);
+        Module fragment = mgr.create(new File(jars, "fragment-module.jar"), null, false, true, false);
+        Module fragmentUser = mgr.create(new File(jars, "fragment-module-user.jar"), null, false, false, false);
+
+        assertTrue("Host is known", mgr.getModules().contains(host));
+        assertTrue("Fragment is known", mgr.getModules().contains(fragment));
+        assertTrue("User of fragment is known", mgr.getModules().contains(fragmentUser));
+
+        mgr.enable(new HashSet<>(Arrays.asList(host, fragmentUser)));
+
+        assertTrue("Host must be enabled", mgr.getEnabledModules().contains(host));
+        assertTrue("Fragment must be enabled", mgr.getEnabledModules().contains(fragmentUser));
+        assertTrue("User of fragment must be enabled", mgr.getEnabledModules().contains(fragmentUser));
+    }
+
+    public void testEnableHostWithAutoloadFragmentAndFragmentDependencyUnsatisfied() throws Exception {
+        MockModuleInstaller installer = new MockModuleInstaller();
+        MockEvents ev = new MockEvents();
+        ModuleManager mgr = new ModuleManager(installer, ev);
+        mgr.mutexPrivileged().enterWriteAccess();
+
+        createTestJAR(data, jars, "fragment-module-user", null);
+        createTestJAR(data, jars, "fragment-module-missing-token", null);
+
+        Module host = mgr.create(new File(jars, "host-module.jar"), null, false, false, false);
+        Module fragment = mgr.create(new File(jars, "fragment-module-missing-token.jar"), null, false, true, false);
+        Module fragmentUser = mgr.create(new File(jars, "fragment-module-user.jar"), null, false, false, false);
+
+        assertTrue("Host is known", mgr.getModules().contains(host));
+        assertTrue("Fragment is known", mgr.getModules().contains(fragment));
+        assertTrue("User of fragment is known", mgr.getModules().contains(fragmentUser));
+
+        boolean expectedExceptionCatched = false;
+        try {
+            mgr.enable(fragmentUser);
+        } catch (IllegalArgumentException e) {
+            expectedExceptionCatched = e.getMessage().startsWith("Not all requested modules can be enabled:");
+            if (!expectedExceptionCatched) {
+                throw e;
+            }
+        }
+        assertTrue(expectedExceptionCatched);
+
+        mgr.enable(host);
+
+        assertTrue("Host must be enabled", mgr.getEnabledModules().contains(host));
+        assertTrue("Fragment must not be enabled", !mgr.getEnabledModules().contains(fragmentUser));
+        assertTrue("User of fragment must not be enabled", !mgr.getEnabledModules().contains(fragmentUser));
+    }
     
     public void testEnableFragmentBeforeItsHost() throws Exception {
         MockModuleInstaller installer = new MockModuleInstaller();
@@ -2771,7 +2954,7 @@ public void testEnableFragmentBeforeItsHost() throws Exception {
         Module m1 = mgr.create(new File(jars, "host-module.jar"), null, false, false, false);
         Module m2 = mgr.create(new File(jars, "fragment-module.jar"), null, false, false, false);
         List toEnable = mgr.simulateEnable(Collections.singleton(m2));
-        
+
         assertTrue("Host will be enabled", toEnable.contains(m1));
         assertTrue("Known fragment must be merged in", toEnable.contains(m2));
         mgr.enable(new HashSet<>(toEnable));


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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

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