diff -r acddb10c4b71 core.startup/apichanges.xml --- a/core.startup/apichanges.xml Mon May 20 01:28:36 2013 +0200 +++ b/core.startup/apichanges.xml Wed May 22 15:36:15 2013 +0200 @@ -56,6 +56,22 @@ + + + Disable creation of resources cache + + + + + +

+ New property API + to control creation of all-resources.data cache + after start. +

+
+ +
Main.getModuleSystem(false) diff -r acddb10c4b71 core.startup/arch.xml --- a/core.startup/arch.xml Mon May 20 01:28:36 2013 +0200 +++ b/core.startup/arch.xml Wed May 22 15:36:15 2013 +0200 @@ -678,6 +678,37 @@ in the About dialog box and in the log file.

+ + +

+ Some applications built on top of NetBeans Platform expressed + an option that certain files in caches, namely + + all-resources.dat + can be too big and that this is not good for multi-user installation. + To give such applications control over creation of this file, there + is a property to (conditionally) disable the creation of the cache file. +

+

+ Change value of org.netbeans.core.update.all.resources property + in launcher configuration file or provide it as a virtual machine + parameter on command line. + Set it to never, always or missing. + The default is to regenerate and update the cache always. + Value missing means to generate + the cache only if it has not been previously available (even in + installation location). Setting the value to never will + never disable the creation of the cache after start completely. +

+

+ Changing default value of the property may be particulary useful when there is a shared + installation of the application, there are many users with a home + (and cache) directory on a slow (network) file system and it is + expected most of them won't install additional modules into their + own user directory. +

+

diff -r acddb10c4b71 core.startup/src/org/netbeans/core/startup/Bundle.properties --- a/core.startup/src/org/netbeans/core/startup/Bundle.properties Mon May 20 01:28:36 2013 +0200 +++ b/core.startup/src/org/netbeans/core/startup/Bundle.properties Wed May 22 15:36:15 2013 +0200 @@ -184,3 +184,6 @@ # {3} - line # EXC_sax_parse_col_line=Parse error in file {1} line {3} column {2} (PUBLIC {0}) +# possible values: always, never, missing +#NOI18N +UpdateAllResources=always diff -r acddb10c4b71 core.startup/src/org/netbeans/core/startup/Main.java --- a/core.startup/src/org/netbeans/core/startup/Main.java Mon May 20 01:28:36 2013 +0200 +++ b/core.startup/src/org/netbeans/core/startup/Main.java Wed May 22 15:36:15 2013 +0200 @@ -325,7 +325,7 @@ StartLog.logProgress ("Splash hidden"); // NOI18N StartLog.logEnd ("Preparation"); // NOI18N - org.netbeans.JarClassLoader.saveArchive(); + updateAllResources(); // start to store all caches after 15s Stamps.getModulesJARs().flush(15000); // initialize life-cycle manager @@ -542,4 +542,21 @@ return handler.canContinue (); } + + static boolean updateAllResources() { + String value = System.getProperty("org.netbeans.core.update.all.resources", "always"); + if (!"never".equals(value)) { // NOI18N + if ("missing".equals(value)) { // NOI18N + if (!org.netbeans.JarClassLoader.isArchivePopulated()) { + org.netbeans.JarClassLoader.saveArchive(); + return true; + } + } else { + assert "always".equals(value); // NOI18N + org.netbeans.JarClassLoader.saveArchive(); + return true; + } + } + return false; + } } diff -r acddb10c4b71 core.startup/test/unit/src/org/netbeans/core/startup/UpdateAllResourcesTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/UpdateAllResourcesTest.java Wed May 22 15:36:15 2013 +0200 @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.core.startup; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import static junit.framework.Assert.assertTrue; +import org.netbeans.JarClassLoader; +import org.netbeans.Stamps; +import org.netbeans.junit.NbTestCase; + +/** + * + * @author Jaroslav Tulach + */ +public class UpdateAllResourcesTest extends NbTestCase{ + public UpdateAllResourcesTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + clearWorkDir(); + System.setProperty("netbeans.user", getWorkDirPath()); + System.getProperties().remove("org.netbeans.core.update.all.resources"); + resetStamps(); + } + + public void testByDefaultTheArchiveIsUpdated() { + assertTrue("Update was scheduled", Main.updateAllResources()); + } + + public void testNeverUpdate() { + System.setProperty("org.netbeans.core.update.all.resources", "never"); + assertFalse("Update was not", Main.updateAllResources()); + } + + public void testUpdateAsNotPopulated() throws Exception { + System.setProperty("org.netbeans.core.update.all.resources", "missing"); + populateCache(false); + assertFalse("No previous all-resources.dat", JarClassLoader.isArchivePopulated()); + assertTrue("Performs the update", Main.updateAllResources()); + } + + public void testDontUpdateWhenPopulated() throws Exception { + System.setProperty("org.netbeans.core.update.all.resources", "missing"); + populateCache(true); + assertFalse("No need to update, everything is populated", Main.updateAllResources()); + } + + private static void populateCache(boolean prep) throws Exception { + Method init = JarClassLoader.class.getDeclaredMethod("initializeCache"); + init.setAccessible(true); + init.invoke(null); + + Field fld = JarClassLoader.class.getDeclaredField("archive"); + fld.setAccessible(true); + Object obj = fld.get(null); + assertNotNull("Archive is initialized", obj); + + Constructor cnstr = obj.getClass().getDeclaredConstructor(boolean.class); + cnstr.setAccessible(true); + fld.set(null, cnstr.newInstance(prep)); + + assertEquals("Previous all-resources.dat", prep, JarClassLoader.isArchivePopulated()); + } + private static void resetStamps() throws Exception { + final Method m = Stamps.class.getDeclaredMethod("main", String[].class); + m.setAccessible(true); + m.invoke(null, (Object) new String[]{"reset"}); + } +} diff -r acddb10c4b71 o.n.bootstrap/arch.xml --- a/o.n.bootstrap/arch.xml Mon May 20 01:28:36 2013 +0200 +++ b/o.n.bootstrap/arch.xml Wed May 22 15:36:15 2013 +0200 @@ -1080,6 +1080,14 @@ The location is however well known for purposes of installer.

+ +

+ One can control creation of the all-resources.dat file in + the user directory via + + org.netbeans.core.update.all.resources + property. +

diff -r acddb10c4b71 o.n.bootstrap/src/org/netbeans/Archive.java --- a/o.n.bootstrap/src/org/netbeans/Archive.java Mon May 20 01:28:36 2013 +0200 +++ b/o.n.bootstrap/src/org/netbeans/Archive.java Wed May 22 15:36:15 2013 +0200 @@ -107,6 +107,12 @@ active = false; prepopulated = false; } + + Archive(boolean prep) { + gathering = false; + active = false; + prepopulated = prep; + } /** Creates a new instance of Archive that reads data from given cache */ @@ -289,6 +295,10 @@ // nothing needs to be done } + final boolean isPopulated() { + return prepopulated; + } + /* Entry layout in the buffer: * -1 1B 0x02 type identifier (0x03 for general) * 0 -> 2B src number of the source (sources are counted in file from 0) diff -r acddb10c4b71 o.n.bootstrap/src/org/netbeans/JarClassLoader.java --- a/o.n.bootstrap/src/org/netbeans/JarClassLoader.java Mon May 20 01:28:36 2013 +0200 +++ b/o.n.bootstrap/src/org/netbeans/JarClassLoader.java Wed May 22 15:36:15 2013 +0200 @@ -125,6 +125,16 @@ } } + /** Check whether the archive has already been populated during + * previous executions. + * + * @return true, if the archive is ready and non-empty + * @since 1.XXX + */ + public static boolean isArchivePopulated() { + return archive != null && archive.isPopulated(); + } + static { ProxyURLStreamHandlerFactory.register(); }