diff -r b810e7ed6c12 glassfish.common/src/org/netbeans/modules/glassfish/spi/ServerUtilities.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/spi/ServerUtilities.java Sat Jul 26 14:43:53 2008 +0200 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/spi/ServerUtilities.java Sun Jul 27 10:16:49 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 b810e7ed6c12 glassfish.javaee/nbproject/project.xml --- a/glassfish.javaee/nbproject/project.xml Sat Jul 26 14:43:53 2008 +0200 +++ b/glassfish.javaee/nbproject/project.xml Sun Jul 27 10:16:49 2008 +0200 @@ -64,7 +64,7 @@ 4 - 1.36 + 1.51 diff -r b810e7ed6c12 glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2OptionalFactory.java --- a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2OptionalFactory.java Sat Jul 26 14:43:53 2008 +0200 +++ b/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2OptionalFactory.java Sun Jul 27 10:16:49 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 finishServerInitialization() { + final boolean needToRegisterDefaultServer = + !NbPreferences.forModule(this.getClass()).getBoolean(ServerUtilities.PROP_FIRST_RUN, false); + if (needToRegisterDefaultServer) { + ServerUtilities.getServerProvider(); + } + } } diff -r b810e7ed6c12 j2eeserver/apichanges.xml --- a/j2eeserver/apichanges.xml Sat Jul 26 14:43:53 2008 +0200 +++ b/j2eeserver/apichanges.xml Sun Jul 27 10:16:49 2008 +0200 @@ -113,6 +113,27 @@ + + + + Provide a way for a plugin to perform post 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 b810e7ed6c12 j2eeserver/nbproject/project.properties --- a/j2eeserver/nbproject/project.properties Sat Jul 26 14:43:53 2008 +0200 +++ b/j2eeserver/nbproject/project.properties Sun Jul 27 10:16:49 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 b810e7ed6c12 j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java Sat Jul 26 14:43:53 2008 +0200 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java Sun Jul 27 10:16:49 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.finishServerInitialization(); + } 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 b810e7ed6c12 j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java Sat Jul 26 14:43:53 2008 +0200 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java Sun Jul 27 10:16:49 2008 +0200 @@ -167,4 +167,14 @@ return null; } + /** + * Allows a plugin to perform post initialization action. When this method + * invoked infrastructure is initialized so it can register/query instances. + * + * @throws ServerInitializationException if an initalization fails + * @since 1.51 + */ + public void finishServerInitialization() throws ServerInitializationException { + } + } diff -r b810e7ed6c12 j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/ServerInitializationException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/ServerInitializationException.java Sun Jul 27 10:16:49 2008 +0200 @@ -0,0 +1,56 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 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]" + * + * 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 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.j2ee.deployment.plugins.spi; + +/** + * + * @author Petr Hejl + */ +public class ServerInitializationException extends Exception { + + public ServerInitializationException(String message) { + super(message); + } + + public ServerInitializationException(String message, Throwable cause) { + super(message, cause); + } + +} diff -r b810e7ed6c12 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 Sat Jul 26 14:43:53 2008 +0200 +++ b/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistryTest.java Sun Jul 27 10:16:49 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 b810e7ed6c12 j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/ManagerWrapperFactory.java --- a/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/ManagerWrapperFactory.java Sat Jul 26 14:43:53 2008 +0200 +++ b/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/ManagerWrapperFactory.java Sun Jul 27 10:16:49 2008 +0200 @@ -47,6 +47,7 @@ import org.netbeans.modules.j2ee.deployment.plugins.spi.FindJSPServlet; 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.ServerInitializationException; import org.netbeans.modules.j2ee.deployment.plugins.spi.ServerInstanceDescriptor; import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer; @@ -55,6 +56,8 @@ * @author nn136682 */ public class ManagerWrapperFactory extends OptionalDeploymentManagerFactory { + + protected boolean initialized; /** Creates a new instance of ManagerWrapperFactory */ public ManagerWrapperFactory() { @@ -76,5 +79,18 @@ public ServerInstanceDescriptor getServerInstanceDescriptor(DeploymentManager dm) { return new TestInstanceDescriptor(dm); } - + + @Override + public synchronized void finishServerInitialization() throws ServerInitializationException { + if (initialized) { + throw new IllegalStateException("Initialization called twice"); + } + super.finishServerInitialization(); + initialized = true; + } + + public synchronized boolean isInitialized() { + return initialized; + } + } diff -r b810e7ed6c12 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 Sun Jul 27 10:16:49 2008 +0200 @@ -0,0 +1,63 @@ +/* + * 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; + +import org.netbeans.modules.j2ee.deployment.plugins.spi.ServerInitializationException; + +/** + * + * @author nn136682 + */ +public class ManagerWrapperFailingFactory extends ManagerWrapperFactory { + + /** Creates a new instance of ManagerWrapperFactory */ + public ManagerWrapperFailingFactory() { + } + + @Override + public void finishServerInitialization() throws ServerInitializationException { + super.finishServerInitialization(); + throw new ServerInitializationException("Don't want to initialize"); + } + +} diff -r b810e7ed6c12 j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/layer.xml --- a/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/layer.xml Sat Jul 26 14:43:53 2008 +0200 +++ b/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/layer.xml Sun Jul 27 10:16:49 2008 +0200 @@ -87,6 +87,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +