diff -r e68207c8148e glassfish.common/src/org/netbeans/modules/glassfish/common/CreateDomain.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/CreateDomain.java Fri Jul 25 15:31:50 2008 +0200 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/CreateDomain.java Fri Jul 25 20:57:54 2008 +0200 @@ -54,6 +54,7 @@ import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; import org.netbeans.modules.glassfish.spi.GlassfishModule; +import org.netbeans.modules.glassfish.spi.ServerUtilities; import org.openide.DialogDisplayer; import org.openide.ErrorManager; import org.openide.NotifyDescriptor; @@ -193,7 +194,7 @@ // The create was successful... create the instance and register it. GlassfishInstance gi = GlassfishInstance.create(ip); GlassfishInstanceProvider.getDefault().addServerInstance(gi); - NbPreferences.forModule(this.getClass()).putBoolean(GlassfishInstanceProvider.PROP_FIRST_RUN, true); + NbPreferences.forModule(this.getClass()).putBoolean(ServerUtilities.PROP_FIRST_RUN, true); } } } diff -r e68207c8148e glassfish.common/src/org/netbeans/modules/glassfish/common/GlassfishInstanceProvider.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/GlassfishInstanceProvider.java Fri Jul 25 15:31:50 2008 +0200 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/GlassfishInstanceProvider.java Fri Jul 25 20:57:54 2008 +0200 @@ -53,6 +53,7 @@ import javax.swing.event.ChangeListener; import org.netbeans.api.server.ServerInstance; import org.netbeans.modules.glassfish.spi.GlassfishModule; +import org.netbeans.modules.glassfish.spi.ServerUtilities; import org.netbeans.spi.server.ServerInstanceImplementation; import org.netbeans.spi.server.ServerInstanceProvider; import org.openide.filesystems.FileObject; @@ -73,7 +74,6 @@ static final String DIR_GLASSFISH_INSTANCES = "/GlassFish/Instances"; //NOI18N static final String INSTANCE_FO_ATTR = "InstanceFOPath"; // NOI18N - static final String PROP_FIRST_RUN = "first_run"; private static final GlassfishInstanceProvider singleton = new GlassfishInstanceProvider(); @@ -382,7 +382,7 @@ private void registerDefaultInstance() { final boolean needToRegisterDefaultServer = - !NbPreferences.forModule(this.getClass()).getBoolean(PROP_FIRST_RUN, false); + !NbPreferences.forModule(this.getClass()).getBoolean(ServerUtilities.PROP_FIRST_RUN, false); if (needToRegisterDefaultServer) { try { @@ -406,7 +406,7 @@ Integer.toString(4848)); GlassfishInstance gi = GlassfishInstance.create(ip); addServerInstance(gi); - NbPreferences.forModule(this.getClass()).putBoolean(PROP_FIRST_RUN, true); + NbPreferences.forModule(this.getClass()).putBoolean(ServerUtilities.PROP_FIRST_RUN, true); } else { ip.put(GlassfishModule.DISPLAY_NAME_ATTR, NbBundle.getMessage(this.getClass(), "PERSONAL_DOMAIN_NAME")); // NOI18N diff -r e68207c8148e glassfish.common/src/org/netbeans/modules/glassfish/spi/ServerUtilities.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/spi/ServerUtilities.java Fri Jul 25 15:31:50 2008 +0200 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/spi/ServerUtilities.java Fri Jul 25 20:57:54 2008 +0200 @@ -63,6 +63,7 @@ */ public final class ServerUtilities { + public static final String PROP_FIRST_RUN = "first_run"; public static final int ACTION_TIMEOUT = 10000; public static final TimeUnit ACTION_TIMEOUT_UNIT = TimeUnit.MILLISECONDS; public static final String GFV3_MODULES_DIR_NAME = "modules"; // NOI18N diff -r e68207c8148e glassfish.javaee/nbproject/project.xml --- a/glassfish.javaee/nbproject/project.xml Fri Jul 25 15:31:50 2008 +0200 +++ b/glassfish.javaee/nbproject/project.xml Fri Jul 25 20:57:54 2008 +0200 @@ -64,7 +64,7 @@ 4 - 1.36 + 1.51 diff -r e68207c8148e glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2OptionalFactory.java --- a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2OptionalFactory.java Fri Jul 25 15:31:50 2008 +0200 +++ b/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2OptionalFactory.java Fri Jul 25 20:57:54 2008 +0200 @@ -61,6 +61,7 @@ import org.openide.WizardDescriptor.InstantiatingIterator; import org.openide.WizardDescriptor.Panel; import org.openide.util.Lookup; +import org.openide.util.NbPreferences; /** @@ -212,4 +213,14 @@ } } + + + @Override + public void initializeServerPlugin() { + final boolean needToRegisterDefaultServer = + !NbPreferences.forModule(this.getClass()).getBoolean(ServerUtilities.PROP_FIRST_RUN, false); + if (needToRegisterDefaultServer) { + ServerUtilities.getServerProvider(); + } + } } diff -r e68207c8148e j2eeserver/apichanges.xml --- a/j2eeserver/apichanges.xml Fri Jul 25 15:31:50 2008 +0200 +++ b/j2eeserver/apichanges.xml Fri Jul 25 20:57:54 2008 +0200 @@ -113,6 +113,26 @@ + + + + Provide a way for a plugin to perform initialization action. + + + + + + +

+ OptionalDeploymentManagerFactory gets a new stub, that plugin + implementations would override. The Plugin author can assume + that the ServerRegistry is initialized to the point where it + can support the creation on instances. +

+
+ + +
diff -r e68207c8148e j2eeserver/nbproject/project.properties --- a/j2eeserver/nbproject/project.properties Fri Jul 25 15:31:50 2008 +0200 +++ b/j2eeserver/nbproject/project.properties Fri Jul 25 20:57:54 2008 +0200 @@ -39,7 +39,7 @@ is.autoload=true javac.source=1.5 -spec.version.base=1.50.0 +spec.version.base=1.51.0 javadoc.overview=${basedir}/api/doc/overview.html javadoc.arch=${basedir}/arch.xml diff -r e68207c8148e j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java Fri Jul 25 15:31:50 2008 +0200 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java Fri Jul 25 20:57:54 2008 +0200 @@ -42,10 +42,7 @@ package org.netbeans.modules.j2ee.deployment.impl; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.Writer; import java.util.logging.Logger; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; @@ -56,28 +53,25 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Enumeration; import java.util.EventListener; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.logging.Level; import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; +import org.netbeans.modules.j2ee.deployment.plugins.spi.OptionalDeploymentManagerFactory; import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; import org.openide.filesystems.FileAttributeEvent; import org.openide.filesystems.FileChangeListener; import org.openide.filesystems.FileEvent; -import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileRenameEvent; import org.openide.filesystems.FileUtil; import org.openide.filesystems.Repository; -import org.openide.modules.InstalledFileLocator; - -//import java.util.logging.*; public final class ServerRegistry implements java.io.Serializable { @@ -105,7 +99,7 @@ public synchronized static boolean wasInitialized () { return instance != null && instance.servers != null && instance.instances != null; } - private transient Map servers = null; + private transient Map servers = null; private transient Map instances = null; private transient Collection pluginListeners = new HashSet(); private transient Collection instanceListeners = new ArrayList(); @@ -134,6 +128,7 @@ for (int i = 0; i < ch.length; i++) { addPlugin(ch[i]); } + LOGGER.log(Level.FINE, "Loading server instances"); // NOI18N dir = rep.getDefaultFileSystem().findResource(DIR_INSTALLED_SERVERS); dir.addFileChangeListener(new InstanceInstallListener()); @@ -141,12 +136,27 @@ for (int i = 0; i < ch.length; i++) { addInstance(ch[i]); } + + LOGGER.log(Level.FINE, "Initializing plugins"); // NOI18N + List notInitialized = new LinkedList(); + for (Map.Entry entry : serversMap().entrySet()) { + OptionalDeploymentManagerFactory odmf = entry.getValue().getOptionalFactory(); + if (null != odmf) { + try { + odmf.initializeServerPlugin(); + } catch (Exception ex) { + LOGGER.log(Level.INFO, "Server plugin not initialized", ex); + notInitialized.add(entry.getKey()); + } + } + } + serversMap().keySet().removeAll(notInitialized); } else { LOGGER.log(Level.WARNING, "No DIR_JSR88_PLUGINS folder found, no server plugins will be availabe"); // NOI18N } } - private Map serversMap() { + private Map serversMap() { init(); return servers; } diff -r e68207c8148e j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java Fri Jul 25 15:31:50 2008 +0200 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java Fri Jul 25 20:57:54 2008 +0200 @@ -167,4 +167,13 @@ return null; } + /** + * Allows a plugin to perform initialization action. When this method + * invoked infrastructure is initialized so it can register/query instances. + * + * @since 1.51 + */ + public void initializeServerPlugin() { + } + } diff -r e68207c8148e j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistryTest.java --- a/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistryTest.java Fri Jul 25 15:31:50 2008 +0200 +++ b/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistryTest.java Fri Jul 25 20:57:54 2008 +0200 @@ -51,6 +51,7 @@ import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment; import org.netbeans.modules.j2ee.deployment.plugins.spi.OptionalDeploymentManagerFactory; import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer; +import org.netbeans.tests.j2eeserver.plugin.ManagerWrapperFactory; /** * * @author nn136682 @@ -127,5 +128,18 @@ assertEquals(1, names.length); assertEquals("META-INF/test-ejb.xml", names[0]); } + + public void testServerPluginInitialization() { + ServerRegistry registry = ServerRegistry.getInstance(); + Server testPlugin = registry.getServer("Test"); + + assertNotNull("Registry does not contain test plugin", testPlugin); + + ManagerWrapperFactory optionalFactory = (ManagerWrapperFactory) testPlugin.getOptionalFactory(); + assertTrue(optionalFactory.isInitialized()); + + testPlugin = registry.getServer("TestFailingInitialization"); + assertNull("Registry contain plugin while its initialization failed", testPlugin); + } } diff -r e68207c8148e j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/ManagerWrapperFactory.java --- a/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/ManagerWrapperFactory.java Fri Jul 25 15:31:50 2008 +0200 +++ b/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/ManagerWrapperFactory.java Fri Jul 25 20:57:54 2008 +0200 @@ -56,6 +56,8 @@ */ public class ManagerWrapperFactory extends OptionalDeploymentManagerFactory { + protected boolean initialized; + /** Creates a new instance of ManagerWrapperFactory */ public ManagerWrapperFactory() { } @@ -76,5 +78,18 @@ public ServerInstanceDescriptor getServerInstanceDescriptor(DeploymentManager dm) { return new TestInstanceDescriptor(dm); } - + + @Override + public synchronized void initializeServerPlugin() { + if (initialized) { + throw new IllegalStateException("Initialization called twice"); + } + super.initializeServerPlugin(); + initialized = true; + } + + public synchronized boolean isInitialized() { + return initialized; + } + } diff -r e68207c8148e j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/ManagerWrapperFailingFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/ManagerWrapperFailingFactory.java Fri Jul 25 20:57:54 2008 +0200 @@ -0,0 +1,61 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * 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. + */ + + +package org.netbeans.tests.j2eeserver.plugin; + +/** + * + * @author nn136682 + */ +public class ManagerWrapperFailingFactory extends ManagerWrapperFactory { + + /** Creates a new instance of ManagerWrapperFactory */ + public ManagerWrapperFailingFactory() { + } + + @Override + public void initializeServerPlugin() { + super.initializeServerPlugin(); + throw new IllegalStateException("Don't want to initialize"); + } + +} diff -r e68207c8148e j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/layer.xml --- a/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/layer.xml Fri Jul 25 15:31:50 2008 +0200 +++ b/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/layer.xml Fri Jul 25 20:57:54 2008 +0200 @@ -87,6 +87,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +