diff -r 7394f02a2352 glassfish.common/nbproject/project.xml --- a/glassfish.common/nbproject/project.xml Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.common/nbproject/project.xml Fri Jan 13 13:52:17 2012 +0100 @@ -54,7 +54,7 @@ 0 - 1.2 + 1.19 diff -r 7394f02a2352 glassfish.common/src/org/netbeans/modules/glassfish/common/CommonServerSupport.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/CommonServerSupport.java Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/CommonServerSupport.java Fri Jan 13 13:52:17 2012 +0100 @@ -48,6 +48,7 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.URL; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -85,7 +86,6 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.ChangeSupport; -import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; @@ -357,23 +357,15 @@ private static final RequestProcessor RP = new RequestProcessor("CommonServerSupport - start/stop/refresh",5); // NOI18N @Override - public Future startServer(final OperationStateListener stateListener) { + public Future startServer(final OperationStateListener stateListener, ServerState endState) { Logger.getLogger("glassfish").log(Level.FINEST, "CSS.startServer called on thread \"{0}\"", Thread.currentThread().getName()); // NOI18N - OperationStateListener startServerListener = new StartOperationStateListener(GlassfishModule.ServerState.RUNNING); + OperationStateListener startServerListener = new StartOperationStateListener(endState); VMIntrospector vmi = Lookups.forPath(Util.GF_LOOKUP_PATH).lookup(VMIntrospector.class); FutureTask task = new FutureTask( - new StartTask(this, getRecognizers(), vmi, startServerListener, stateListener)); - RP.post(task); - return task; - } - - @Override - public Future startServer(final OperationStateListener stateListener, FileObject jdkRoot, String[] jvmArgs) { - Logger.getLogger("glassfish").log(Level.FINEST, "CSS.startServer called on thread \"{0}\"", Thread.currentThread().getName()); // NOI18N - OperationStateListener startServerListener = new StartOperationStateListener(GlassfishModule.ServerState.STOPPED_JVM_PROFILER); - VMIntrospector vmi = Lookups.forPath(Util.GF_LOOKUP_PATH).lookup(VMIntrospector.class); - FutureTask task = new FutureTask( - new StartTask(this, getRecognizers(), vmi, jdkRoot, jvmArgs, startServerListener, stateListener)); + new StartTask(this, getRecognizers(), vmi, + (FileObject)null, + (String[])(endState == ServerState.STOPPED_JVM_PROFILER ? new String[]{""} : null), + startServerListener, stateListener)); RP.post(task); return task; } diff -r 7394f02a2352 glassfish.common/src/org/netbeans/modules/glassfish/common/GlassfishInstance.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/GlassfishInstance.java Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/GlassfishInstance.java Fri Jan 13 13:52:17 2012 +0100 @@ -48,11 +48,13 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -84,13 +86,14 @@ import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; import org.openide.windows.InputOutput; /** * * @author Peter Williams */ -public class GlassfishInstance implements ServerInstanceImplementation, LookupListener { +public class GlassfishInstance implements ServerInstanceImplementation, Lookup.Provider, LookupListener { // Reasonable default values for various server parameters. Note, don't use // these unless the server's actual setting cannot be determined in any way. @@ -111,6 +114,7 @@ private transient CommonServerSupport commonSupport; private transient InstanceContent ic; private transient Lookup lookup; + private transient Lookup full; final private transient Lookup.Result lookupResult = Lookups.forPath(Util.GF_LOOKUP_PATH).lookupResult(GlassfishModuleFactory.class);; private transient Collection currentFactories = Collections.emptyList(); @@ -123,6 +127,7 @@ try { ic = new InstanceContent(); lookup = new AbstractLookup(ic); + full = lookup; this.instanceProvider = instanceProvider; String domainDirPath = ip.get(GlassfishModule.DOMAINS_FOLDER_ATTR); String domainName = ip.get(GlassfishModule.DOMAIN_NAME_ATTR); @@ -144,13 +149,13 @@ ic.add(commonSupport); // Common action support, e.g start/stop, etc. commonInstance = ServerInstanceFactory.createServerInstance(this); - if (updateNow) { - updateModuleSupport(); - } // make this instance publicly accessible instanceProvider.addServerInstance(this); } + if (updateNow) { + updateModuleSupport(); + } } finally { if(deployerUri != null) { GlassfishInstanceProvider.activeRegistrationSet.remove(deployerUri); @@ -189,6 +194,8 @@ added.removeAll(currentFactories); currentFactories = factories; + List proxies = new ArrayList(); + proxies.add(lookup); for (GlassfishModuleFactory moduleFactory : added) { if(moduleFactory.isModuleSupported(homeFolder, asenvProps)) { Object t = moduleFactory.createModule(lookup); @@ -196,10 +203,18 @@ Logger.getLogger("glassfish").log(Level.WARNING, "{0} created a null module", moduleFactory); // NOI18N } else { ic.add(t); + if (t instanceof Lookup.Provider) { + proxies.add(Lookups.proxy((Lookup.Provider) t)); + } } } } + + if (!proxies.isEmpty()) { + full = new ProxyLookup(proxies.toArray(new Lookup[proxies.size()])); + } } + } void updateModuleSupport() { @@ -279,7 +294,9 @@ } public Lookup getLookup() { - return lookup; + synchronized (lookupResult) { + return full; + } } public void addChangeListener(final ChangeListener listener) { diff -r 7394f02a2352 glassfish.common/src/org/netbeans/modules/glassfish/common/RestartTask.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/RestartTask.java Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/RestartTask.java Fri Jan 13 13:52:17 2012 +0100 @@ -168,7 +168,7 @@ if (GlassfishModule.PROFILE_MODE.equals(o)) { support.setEnvironmentProperty(GlassfishModule.JVM_MODE, GlassfishModule.NORMAL_MODE, false); } - Future startTask = support.startServer(null); + Future startTask = support.startServer(null, ServerState.RUNNING); OperationState startResult = OperationState.FAILED; try { startResult = startTask.get(START_TIMEOUT, TIMEUNIT); diff -r 7394f02a2352 glassfish.common/src/org/netbeans/modules/glassfish/common/StartTask.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/StartTask.java Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/StartTask.java Fri Jan 13 13:52:17 2012 +0100 @@ -62,6 +62,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.SwingUtilities; +import org.netbeans.api.server.StartupArguments; import org.netbeans.modules.glassfish.spi.RegisteredDerbyServer; import org.netbeans.modules.glassfish.spi.GlassfishModule; import org.netbeans.modules.glassfish.spi.GlassfishModule.OperationState; @@ -696,9 +697,26 @@ throw new ProcessCreationException(ioe, "MSG_START_SERVER_FAILED_INVALIDPORT", instanceName, debugPortString); //NOI18N } + + for (StartupArguments args : StartupArguments.getStartupArguments( + support.getInstanceProvider().getInstance(ip.get("url")), getMode(ip.get(GlassfishModule.JVM_MODE)))) { + for (String singleArg : args.getArguments()) { + argumentBuf.append(' ').append(singleArg); + } + } return argumentBuf; } + private static StartupArguments.StartMode getMode(String gfMode) { + if (GlassfishModule.PROFILE_MODE.equals(gfMode)) { + return StartupArguments.StartMode.PROFILE; + } else if (GlassfishModule.DEBUG_MODE.equals(gfMode)) { + return StartupArguments.StartMode.DEBUG; + } else { + return StartupArguments.StartMode.NORMAL; + } + } + private String selectDebugPort() throws IOException { int debugPort = 9009; ServerSocket t = null; diff -r 7394f02a2352 glassfish.common/src/org/netbeans/modules/glassfish/common/actions/DebugAction.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/actions/DebugAction.java Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/actions/DebugAction.java Fri Jan 13 13:52:17 2012 +0100 @@ -73,7 +73,7 @@ private static void performActionImpl(final GlassfishModule commonSupport) { commonSupport.setEnvironmentProperty(GlassfishModule.JVM_MODE, GlassfishModule.DEBUG_MODE, true); - commonSupport.startServer(null); + commonSupport.startServer(null, ServerState.RUNNING); } protected boolean enable(Node[] activatedNodes) { diff -r 7394f02a2352 glassfish.common/src/org/netbeans/modules/glassfish/common/actions/ProfileAction.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/actions/ProfileAction.java Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/actions/ProfileAction.java Fri Jan 13 13:52:17 2012 +0100 @@ -47,8 +47,6 @@ import org.netbeans.modules.glassfish.common.Util; import org.netbeans.modules.glassfish.spi.GlassfishModule; import org.netbeans.modules.glassfish.spi.GlassfishModule.ServerState; -import org.netbeans.modules.glassfish.spi.ProfilerCookie; -import org.openide.filesystems.FileObject; import org.openide.nodes.Node; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; @@ -73,15 +71,8 @@ private static void performActionImpl(final GlassfishModule commonSupport, Node node) { commonSupport.setEnvironmentProperty(GlassfishModule.JVM_MODE, GlassfishModule.PROFILE_MODE, true); - // get the cookie - ProfilerCookie pc = node.getLookup().lookup(ProfilerCookie.class); - if (null != pc) { - Object[] pcData = pc.getData(); - FileObject jdkHome = (FileObject) pcData[0]; - String[] jvmArgs = (String[]) pcData[1]; - if (jvmArgs != null && jvmArgs.length > 0) - commonSupport.startServer(null,jdkHome,jvmArgs); - } + + commonSupport.startServer(null, ServerState.STOPPED_JVM_PROFILER); } protected boolean enable(Node[] activatedNodes) { @@ -104,8 +95,7 @@ } private static boolean enableImpl(GlassfishModule commonSupport, Node node) { - ProfilerCookie pc = node.getLookup().lookup(ProfilerCookie.class); - return null != pc && commonSupport.getServerState() == ServerState.STOPPED && + return commonSupport.getServerState() == ServerState.STOPPED && null != commonSupport.getInstanceProperties().get(GlassfishModule.DOMAINS_FOLDER_ATTR) && Util.isDefaultOrServerTarget(commonSupport.getInstanceProperties()); } diff -r 7394f02a2352 glassfish.common/src/org/netbeans/modules/glassfish/common/actions/StartServerAction.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/actions/StartServerAction.java Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/actions/StartServerAction.java Fri Jan 13 13:52:17 2012 +0100 @@ -71,7 +71,7 @@ private static void performActionImpl(GlassfishModule commonSupport) { commonSupport.setEnvironmentProperty(GlassfishModule.JVM_MODE, GlassfishModule.NORMAL_MODE, true); - commonSupport.startServer(null); + commonSupport.startServer(null, ServerState.RUNNING); } @Override diff -r 7394f02a2352 glassfish.common/src/org/netbeans/modules/glassfish/spi/GlassfishModule.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/spi/GlassfishModule.java Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/spi/GlassfishModule.java Fri Jan 13 13:52:17 2012 +0100 @@ -178,22 +178,11 @@ * * @param stateListener listener to listen message describing the startup * process as it progresses. Can be null. - * + * @param endState {@linkplain ServerState} the server is to be put to upon successful startup * @return Future instance that finishes when the server startup has * completed (or failed). */ - public Future startServer(OperationStateListener stateListener); - - /** - * Start the server with a specific JDK. - * - * @param stateListener listener to listen message describing the startup - * process as it progresses. Can be null. - * - * @return Future instance that finishes when the server startup has - * completed (or failed). - */ - public Future startServer(OperationStateListener stateListener,FileObject jdkRoot, String[] jvmArgs); + public Future startServer(OperationStateListener stateListener, ServerState endState); /** * Stop the server. diff -r 7394f02a2352 glassfish.common/src/org/netbeans/modules/glassfish/spi/ProfilerCookie.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/spi/ProfilerCookie.java Fri Jan 13 12:35:36 2012 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -// -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2010 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 2008 Sun Microsystems, Inc. - */ -// - -package org.netbeans.modules.glassfish.spi; - -/** - * - * @author vkraemer - */ -public interface ProfilerCookie { - /** - * This is a conduit for data that the we need to get from the profiler that - * is buried in org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler - * as org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings - * - * @return a two element array. Object[0] is a FileObject that is the root - * directory of the JDK to use for running the app server. Object[0] is a - * String[] of extra arguments that need to be used to start the JVM in - * profiled mode. - */ - public Object[] getData(); -} diff -r 7394f02a2352 glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2StartServer.java --- a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2StartServer.java Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2StartServer.java Fri Jan 13 13:52:17 2012 +0100 @@ -72,12 +72,10 @@ import org.netbeans.modules.glassfish.spi.GlassfishModule; import org.netbeans.modules.glassfish.spi.GlassfishModule.OperationState; import org.netbeans.modules.glassfish.spi.OperationStateListener; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerSupport; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; -import org.openide.filesystems.FileObject; import org.openide.util.NbBundle; /** @@ -152,7 +150,7 @@ CommandType.START, translateState(newState), ActionType.EXECUTE, message)); } - }); + }, GlassfishModule.ServerState.RUNNING); } else if (commonSupport != null) { // this is the remote case commonSupport.setEnvironmentProperty(GlassfishModule.JVM_MODE, GlassfishModule.NORMAL_MODE, true); commonSupport.restartServer(new OperationStateListener() { @@ -242,7 +240,7 @@ CommandType.START, translateState(newState), ActionType.EXECUTE, message)); } - }); + }, GlassfishModule.ServerState.RUNNING); } else if (null != commonSupport) { // this is the remote case commonSupport.setEnvironmentProperty(GlassfishModule.JVM_MODE, GlassfishModule.DEBUG_MODE, true); commonSupport.restartServer(new OperationStateListener() { @@ -431,7 +429,7 @@ } @Override - public ProgressObject startProfiling(Target target, ProfilerServerSettings settings) { + public ProgressObject startProfiling(Target target) { if (ProfilerSupport.getState() == ProfilerSupport.STATE_BLOCKING) { fireHandleProgressEvent(null, new Hk2DeploymentStatus( CommandType.START, StateType.RUNNING, ActionType.EXECUTE, @@ -453,11 +451,6 @@ // String domainLocation = commonSupport.getInstanceProperties().get(GlassfishModule.DOMAINS_FOLDER_ATTR); // String domainName = commonSupport.getInstanceProperties().get(GlassfishModule.DOMAIN_NAME_ATTR); commonSupport.setEnvironmentProperty(GlassfishModule.JVM_MODE, GlassfishModule.PROFILE_MODE, true); - Iterator iter = settings.getJavaPlatform().getInstallFolders().iterator(); - FileObject jdkRoot = null; - if (iter.hasNext()) { - jdkRoot = iter.next(); - } commonSupport.startServer(new OperationStateListener() { @Override @@ -486,7 +479,7 @@ CommandType.START, translateState(newState), ActionType.EXECUTE, message)); } - }, jdkRoot, settings.getJvmArgs()); + }, GlassfishModule.ServerState.STOPPED_JVM_PROFILER); } return this; } diff -r 7394f02a2352 glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/JavaEEServerModule.java --- a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/JavaEEServerModule.java Fri Jan 13 12:35:36 2012 +0400 +++ b/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/JavaEEServerModule.java Fri Jan 13 13:52:17 2012 +0100 @@ -44,16 +44,19 @@ import java.util.Collection; import java.util.Collections; -import org.netbeans.api.java.platform.JavaPlatform; import org.netbeans.modules.glassfish.eecommon.api.LogHyperLinkSupport; -import org.netbeans.modules.glassfish.spi.ProfilerCookie; import org.netbeans.modules.glassfish.spi.Recognizer; import org.netbeans.modules.glassfish.spi.RecognizerCookie; import org.netbeans.modules.glassfish.spi.RemoveCookie; +import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; +import org.netbeans.modules.j2ee.deployment.devmodules.api.InstanceRemovedException; +import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; +import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerInstance; import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; -import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; +import org.openide.util.Exceptions; import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; import org.openide.windows.OutputListener; @@ -61,20 +64,39 @@ * * @author Peter Williams */ -public class JavaEEServerModule implements RemoveCookie, ProfilerCookie, RecognizerCookie { +public class JavaEEServerModule implements Lookup.Provider, RemoveCookie, RecognizerCookie { private final InstanceProperties instanceProperties; private final LogHyperLinkSupport.AppServerLogSupport logSupport; - + + private final Lookup lookup; + JavaEEServerModule(Lookup instanceLookup, InstanceProperties ip) { instanceProperties = ip; logSupport = new LogHyperLinkSupport.AppServerLogSupport("", "/"); + + // is this ok, can platform change ? + ServerInstance inst = Deployment.getDefault().getServerInstance( + instanceProperties.getProperty(InstanceProperties.URL_ATTR)); + J2eePlatform platform = null; + try { + platform = inst.getJ2eePlatform(); + } catch (InstanceRemovedException ex) { + } + lookup = platform != null + ? new ProxyLookup(Lookups.fixed(platform, ip), Lookups.proxy(platform)) + : Lookup.EMPTY; } public InstanceProperties getInstanceProperties() { return instanceProperties; } - + + @Override + public Lookup getLookup() { + return lookup; + } + // ------------------------------------------------------------------------ // RemoveCookie support // ------------------------------------------------------------------------ @@ -83,26 +105,6 @@ } // ------------------------------------------------------------------------ - // ProfilerCookie support - // ------------------------------------------------------------------------ - public Object[] getData() { - Profiler profiler = Lookup.getDefault().lookup(Profiler.class); - Object[] retVal = new Object[2]; - retVal[0] = JavaPlatform.getDefault().getInstallFolders().iterator().next(); - retVal[1] = new String[0]; - if (profiler == null) { - return retVal; - } - final ProfilerServerSettings settings = profiler.getSettings(instanceProperties.getProperty(InstanceProperties.URL_ATTR)); - if (settings == null) { - return retVal; - } - retVal[0] = settings.getJavaPlatform().getInstallFolders().iterator().next(); - retVal[1] = settings.getJvmArgs(); - return retVal; - } - - // ------------------------------------------------------------------------ // RecognizerCookie support // ------------------------------------------------------------------------ public Collection getRecognizers() { diff -r 7394f02a2352 j2ee.ant/antsrc/org/netbeans/modules/j2ee/ant/StartProfiledServer.java --- a/j2ee.ant/antsrc/org/netbeans/modules/j2ee/ant/StartProfiledServer.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2ee.ant/antsrc/org/netbeans/modules/j2ee/ant/StartProfiledServer.java Fri Jan 13 13:52:17 2012 +0100 @@ -53,7 +53,6 @@ import org.netbeans.api.java.platform.JavaPlatformManager; import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; import org.openide.filesystems.*; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; @@ -102,15 +101,11 @@ if (envvar == null) { envvar = new String[0]; } - ProfilerServerSettings settings = new ProfilerServerSettings( - platform, - jvmarg.getVmCommand().getArguments(), - envvar); FileObject fo = FileUtil.toFileObject(getProject().getBaseDir()); fo.refresh(); // without this the "build" directory is not found in filesystems J2eeModuleProvider jmp = (J2eeModuleProvider)FileOwnerQuery.getOwner(fo).getLookup().lookup(J2eeModuleProvider.class); ServerInstance si = ServerRegistry.getInstance().getServerInstance(jmp.getServerInstanceID()); - if (!si.startProfile(settings, forceRestart, this)) { + if (!si.startProfile(forceRestart, this)) { String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_StartupFailed"); throw new BuildException(msg); } diff -r 7394f02a2352 j2ee.jboss4/nbproject/project.xml --- a/j2ee.jboss4/nbproject/project.xml Fri Jan 13 12:35:36 2012 +0400 +++ b/j2ee.jboss4/nbproject/project.xml Fri Jan 13 13:52:17 2012 +0100 @@ -134,7 +134,7 @@ 4 - 1.72 + 1.88 @@ -162,6 +162,15 @@ + org.netbeans.modules.server + + + + 0-1 + 1.19 + + + org.openide.actions diff -r 7394f02a2352 j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartRunnable.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartRunnable.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartRunnable.java Fri Jan 13 13:52:17 2012 +0100 @@ -62,9 +62,10 @@ import javax.enterprise.deploy.shared.CommandType; import javax.enterprise.deploy.shared.StateType; import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.server.StartupArguments; +import org.netbeans.modules.j2ee.deployment.plugins.api.CommonServerBridge; import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils; @@ -120,13 +121,11 @@ private JBDeploymentManager dm; private String instanceName; private JBStartServer startServer; - private ProfilerServerSettings profilerSettings; - JBStartRunnable(ProfilerServerSettings profilerSettings, JBDeploymentManager dm, JBStartServer startServer) { + JBStartRunnable(JBDeploymentManager dm, JBStartServer startServer) { this.dm = dm; this.instanceName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR); this.startServer = startServer; - this.profilerSettings = profilerSettings; } public void run() { @@ -205,7 +204,7 @@ } // get Java platform that will run the server - JavaPlatform platform = (startServer.getMode() != JBStartServer.MODE.PROFILE ? properties.getJavaPlatform() : profilerSettings.getJavaPlatform()); + JavaPlatform platform = properties.getJavaPlatform(); if (startServer.getMode() == JBStartServer.MODE.DEBUG && javaOptsBuilder.toString().indexOf("-Xdebug") == -1) { // NOI18N // if in debug mode and the debug options not specified manually @@ -217,18 +216,19 @@ append(",server=y,suspend=n"); // NOI18N } else if (startServer.getMode() == JBStartServer.MODE.PROFILE) { - - // get JVM arguments used for starting the server - String[] profJvmArgs = profilerSettings.getJvmArgs(); - for (int i = 0; i < profJvmArgs.length; i++) { - javaOptsBuilder.append(" ").append(profJvmArgs[i]); // NOI18N - } if (properties.isVersion(JBPluginUtils.JBOSS_6_0_0)) { javaOptsBuilder.append(" ").append("-Djboss.platform.mbeanserver") .append(" ").append("-Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl"); } } + for (StartupArguments args : StartupArguments.getStartupArguments( + CommonServerBridge.getCommonInstance(ip.getProperty("url")), getMode(startServer.getMode()))) { + for (String singleArg : args.getArguments()) { + javaOptsBuilder.append(' ').append(singleArg); + } + } + // create new environment for server javaOpts = javaOptsBuilder.toString(); String javaHome = getJavaHome(platform); @@ -241,7 +241,17 @@ }; return envp; } - + + private static StartupArguments.StartMode getMode(JBStartServer.MODE jbMode) { + if (JBStartServer.MODE.PROFILE.equals(jbMode)) { + return StartupArguments.StartMode.PROFILE; + } else if (JBStartServer.MODE.DEBUG.equals(jbMode)) { + return StartupArguments.StartMode.DEBUG; + } else { + return StartupArguments.StartMode.NORMAL; + } + } + private boolean checkPorts(final InstanceProperties ip) { try { diff -r 7394f02a2352 j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartServer.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartServer.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartServer.java Fri Jan 13 13:52:17 2012 +0100 @@ -45,7 +45,6 @@ import java.net.URISyntaxException; import java.util.Collections; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; import java.io.IOException; @@ -117,7 +116,7 @@ String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR); fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, NbBundle.getMessage(JBStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName))); //NOI18N mode = MODE.DEBUG; - RequestProcessor.getDefault().post(new JBStartRunnable(null, dm, this), 0, Thread.NORM_PRIORITY); + RequestProcessor.getDefault().post(new JBStartRunnable(dm, this), 0, Thread.NORM_PRIORITY); addDebugModeUri(); return this; } @@ -151,11 +150,11 @@ /** * Starts the server in profiling mode. */ - public ProgressObject startProfiling(Target target, ProfilerServerSettings settings) { + public ProgressObject startProfiling(Target target) { String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR); fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, NbBundle.getMessage(JBStartServer.class, "MSG_START_PROFILED_SERVER_IN_PROGRESS", serverName))); //NOI18N mode = MODE.PROFILE; - RequestProcessor.getDefault().post(new JBStartRunnable(settings, dm, this), 0, Thread.NORM_PRIORITY); + RequestProcessor.getDefault().post(new JBStartRunnable(dm, this), 0, Thread.NORM_PRIORITY); removeDebugModeUri(); return this; } @@ -188,7 +187,7 @@ String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR); fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, NbBundle.getMessage(JBStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName)));//NOI18N mode = MODE.RUN; - RequestProcessor.getDefault().post(new JBStartRunnable(null, dm, this), 0, Thread.NORM_PRIORITY); + RequestProcessor.getDefault().post(new JBStartRunnable(dm, this), 0, Thread.NORM_PRIORITY); removeDebugModeUri(); return this; } diff -r 7394f02a2352 j2ee.weblogic9/nbproject/project.xml --- a/j2ee.weblogic9/nbproject/project.xml Fri Jan 13 12:35:36 2012 +0400 +++ b/j2ee.weblogic9/nbproject/project.xml Fri Jan 13 13:52:17 2012 +0100 @@ -149,7 +149,7 @@ 4 - 1.78 + 1.88 @@ -204,6 +204,15 @@ + org.netbeans.modules.server + + + + 0-1 + 1.19 + + + org.openide.actions diff -r 7394f02a2352 j2ee.weblogic9/src/org/netbeans/modules/j2ee/weblogic9/optional/WLStartServer.java --- a/j2ee.weblogic9/src/org/netbeans/modules/j2ee/weblogic9/optional/WLStartServer.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2ee.weblogic9/src/org/netbeans/modules/j2ee/weblogic9/optional/WLStartServer.java Fri Jan 13 13:52:17 2012 +0100 @@ -69,18 +69,16 @@ import org.netbeans.api.extexecution.input.InputProcessors; import org.netbeans.api.extexecution.input.InputReaderTask; import org.netbeans.api.extexecution.input.InputReaders; -import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.server.StartupArguments; +import org.netbeans.modules.j2ee.deployment.plugins.api.CommonServerBridge; import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo; import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport; import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerSupport; import org.netbeans.modules.j2ee.weblogic9.deploy.WLDeploymentManager; import org.netbeans.modules.j2ee.weblogic9.WLDeploymentFactory; import org.netbeans.modules.j2ee.weblogic9.WLPluginProperties; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; import org.openide.util.NbBundle; import org.openide.util.Utilities; import org.openide.windows.InputOutput; @@ -202,8 +200,7 @@ * @see org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer#startProfiling(javax.enterprise.deploy.spi.Target, org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings) */ @Override - public ProgressObject startProfiling( Target target, - ProfilerServerSettings settings ) + public ProgressObject startProfiling( Target target ) { LOGGER.log(Level.FINER, "Starting server in profiling mode"); // NOI18N @@ -215,7 +212,7 @@ NbBundle.getMessage(WLStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName)); String uri = dm.getUri(); - service.submit(new WLProfilingStartTask(uri, serverProgress, dm, settings)); + service.submit(new WLProfilingStartTask(uri, serverProgress, dm)); removeServerInDebug(uri); return serverProgress; @@ -364,13 +361,10 @@ private class WLProfilingStartTask extends WLStartTask { - private final ProfilerServerSettings mySettings; - public WLProfilingStartTask(String uri, WLServerProgress serverProgress, - WLDeploymentManager dm, ProfilerServerSettings settings) { + WLDeploymentManager dm) { super( uri , serverProgress, dm ); - mySettings = settings; } /* (non-Javadoc) @@ -409,20 +403,23 @@ }*/ StringBuilder javaOptsBuilder = new StringBuilder(); - String[] profJvmArgs = getSettings().getJvmArgs(); - for (int i = 0; i < profJvmArgs.length; i++) { - javaOptsBuilder.append(" ").append(profJvmArgs[i]); // NOI18N - } String javaOpts = dm.getInstanceProperties().getProperty( WLPluginProperties.JAVA_OPTS); if ( javaOpts!= null && javaOpts.trim().length() >0 ){ javaOptsBuilder.append( " " ); // NOI18N javaOptsBuilder.append( javaOpts.trim() ); } - - if ( profJvmArgs.length >0 ){ + + for (StartupArguments args : StartupArguments.getStartupArguments( + CommonServerBridge.getCommonInstance(dm.getUri()), StartupArguments.StartMode.PROFILE)) { + for (String singleArg : args.getArguments()) { + javaOptsBuilder.append(' ').append(singleArg); + } + } + String toAdd = javaOptsBuilder.toString().trim(); + if (!toAdd.isEmpty()){ result = result.addEnvironmentVariable(JAVA_OPTIONS_VARIABLE, - javaOptsBuilder.toString()); + toAdd); } return result; } @@ -438,15 +435,6 @@ } return super.isRunning(); } - - private String getJavaHome(JavaPlatform platform) { - FileObject fo = (FileObject)platform.getInstallFolders().iterator().next(); - return FileUtil.toFile(fo).getAbsolutePath(); - } - - private ProfilerServerSettings getSettings() { - return mySettings; - } } private class WLDebugStartTask extends WLStartTask { @@ -476,6 +464,12 @@ javaOptsBuilder.append("-Xdebug -Xnoagent -Djava.compiler=none "); // NOI18N javaOptsBuilder.append("-Xrunjdwp:server=y,suspend=n,transport=dt_socket,address=");// NOI18N javaOptsBuilder.append( debugPort ); + for (StartupArguments args : StartupArguments.getStartupArguments( + CommonServerBridge.getCommonInstance(dm.getUri()), StartupArguments.StartMode.DEBUG)) { + for (String singleArg : args.getArguments()) { + javaOptsBuilder.append(' ').append(singleArg); + } + } ExternalProcessBuilder result = builder.addEnvironmentVariable( JAVA_OPTIONS_VARIABLE, javaOptsBuilder.toString()); @@ -657,9 +651,17 @@ { ExternalProcessBuilder result = builder; String javaOpts = dm.getInstanceProperties().getProperty(WLPluginProperties.JAVA_OPTS); - if ( javaOpts!= null && javaOpts.trim().length() >0 ){ - result = builder.addEnvironmentVariable(JAVA_OPTIONS_VARIABLE, - javaOpts.trim()); + StringBuilder sb = new StringBuilder((javaOpts!= null && javaOpts.trim().length() > 0) + ? javaOpts.trim() : ""); + for (StartupArguments args : StartupArguments.getStartupArguments( + CommonServerBridge.getCommonInstance(dm.getUri()), StartupArguments.StartMode.NORMAL)) { + for (String singleArg : args.getArguments()) { + sb.append(' ').append(singleArg); + } + } + if (sb.length() > 0) { + result = builder.addEnvironmentVariable(JAVA_OPTIONS_VARIABLE, + sb.toString()); } return result; } diff -r 7394f02a2352 j2eeserver/apichanges.xml --- a/j2eeserver/apichanges.xml Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/apichanges.xml Fri Jan 13 13:52:17 2012 +0100 @@ -116,6 +116,24 @@ + + + + Added CommonServerBridge utility class to provide mapping of + instance url to common api server instance. + + + + + + +

+ Added CommonServerBridge utility class to provide mapping of + instance url to common api server instance. +

+
+ +
diff -r 7394f02a2352 j2eeserver/nbproject/project.properties --- a/j2eeserver/nbproject/project.properties Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/nbproject/project.properties Fri Jan 13 13:52:17 2012 +0100 @@ -42,7 +42,7 @@ is.autoload=true javac.source=1.6 -spec.version.base=1.87.0 +spec.version.base=1.88.0 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff -r 7394f02a2352 j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/ServerManager.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/ServerManager.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/ServerManager.java Fri Jan 13 13:52:17 2012 +0100 @@ -53,6 +53,7 @@ import org.netbeans.modules.j2ee.deployment.impl.bridge.BridgingServerInstanceProvider; import org.netbeans.modules.j2ee.deployment.impl.bridge.ServerInstanceProviderLookup; import org.netbeans.modules.j2ee.deployment.impl.ui.wizard.AddServerInstanceWizard; +import org.netbeans.modules.j2ee.deployment.plugins.api.CommonServerBridge; /** * ServerManager class provides access to the Server Manager dialog. @@ -80,20 +81,7 @@ */ public static void showCustomizer(String serverInstanceID) { // bridge to new infrastructure (common server) - ServerInstance bridgingInstance = null; - org.netbeans.modules.j2ee.deployment.impl.ServerInstance j2eeInstance = - ServerRegistry.getInstance().getServerInstance(serverInstanceID); - if (j2eeInstance != null) { - Collection providers = ServerInstanceProviderLookup.getInstance().lookupAll(org.netbeans.spi.server.ServerInstanceProvider.class); - for (org.netbeans.spi.server.ServerInstanceProvider provider : providers) { - if (provider instanceof BridgingServerInstanceProvider) { - bridgingInstance = ((BridgingServerInstanceProvider) provider).getBridge(j2eeInstance); - if (bridgingInstance != null) { - break; - } - } - } - } + ServerInstance bridgingInstance = CommonServerBridge.getCommonInstance(serverInstanceID); CommonServerUIs.showCustomizer(bridgingInstance); } diff -r 7394f02a2352 j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java Fri Jan 13 13:52:17 2012 +0100 @@ -66,7 +66,6 @@ import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException; import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener.Artifact; import org.netbeans.modules.j2ee.deployment.plugins.spi.JDBCDriverDeployer; -import org.openide.filesystems.*; import java.util.*; import java.util.concurrent.TimeoutException; import java.util.logging.Level; @@ -94,7 +93,6 @@ import org.netbeans.modules.j2ee.deployment.plugins.spi.MessageDestinationDeployment; import org.netbeans.modules.j2ee.deployment.plugins.spi.ServerInstanceDescriptor; import org.netbeans.modules.j2ee.deployment.plugins.spi.ServerLibraryManager; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerSupport; import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; import org.openide.nodes.Node; @@ -180,7 +178,6 @@ private final ChangeSupport managerChangeSupport = new ChangeSupport(this); private volatile static ServerInstance profiledServerInstance; - private ProfilerServerSettings profilerSettings; private final DebuggerStateListener debuggerStateListener; @@ -1113,11 +1110,10 @@ } /** Start the admin server in the profile mode. Show UI feedback. - * @param settings settings that will be used to start the server * * @throws ServerException if the server cannot be started. */ - public void startProfile(ProfilerServerSettings settings, boolean forceRestart, ProgressUI ui) + public void startProfile(boolean forceRestart, ProgressUI ui) throws ServerException { // check whether another server not already running in profile mode // and ask whether it is ok to stop it @@ -1137,7 +1133,7 @@ try { setServerState(STATE_WAITING); // target == null - admin server - _startProfile(null, settings, forceRestart, ui); + _startProfile(null, forceRestart, ui); } finally { refresh(); } @@ -1161,7 +1157,7 @@ if (stopped) { // restart in the mode the server was running in before if (inProfile) { - _startProfile(null, profilerSettings, true, ui); + _startProfile(null, true, ui); } else if (inDebug) { startDebugTarget(null, ui); } else { @@ -1267,12 +1263,12 @@ * * @throws ServerException if the server cannot be started. */ - public boolean startProfile(final ProfilerServerSettings settings, boolean forceRestart, Deployment.Logger logger) { + public boolean startProfile(boolean forceRestart, Deployment.Logger logger) { String title = NbBundle.getMessage(ServerInstance.class, "LBL_StartServerInProfileMode", getDisplayName()); ProgressUI ui = new ProgressUI(title, false, logger); try { ui.start(); - startProfile(settings, forceRestart, ui); + startProfile(forceRestart, ui); return true; } catch (ServerException ex) { return false; @@ -1500,15 +1496,10 @@ /** start server in the profile mode */ private void _startProfile( Target target, - ProfilerServerSettings settings, boolean forceRestart, ProgressUI ui) throws ServerException { - ProfilerServerSettings tmpProfilerSettings; - synchronized (this) { - tmpProfilerSettings = profilerSettings; - } ServerInstance tmpProfiledServerInstance = profiledServerInstance; - if (tmpProfiledServerInstance == this && !forceRestart && settings.equals(tmpProfilerSettings)) { + if (tmpProfiledServerInstance == this && !forceRestart) { return; // server is already runnning in profile mode, no need to restart the server } if (tmpProfiledServerInstance != null && tmpProfiledServerInstance != this) { @@ -1528,7 +1519,7 @@ throw new ServerException(NbBundle.getMessage(ServerInstance.class, "MSG_ProfilerNotRegistered")); } profiler.notifyStarting(); - ProgressObject po = getStartServer().startProfiling(target, settings); + ProgressObject po = getStartServer().startProfiling(target); try { boolean completedSuccessfully = ProgressObjectUtil.trackProgressObject(ui, po, DEFAULT_TIMEOUT); if (!completedSuccessfully) { @@ -1540,7 +1531,6 @@ } profiledServerInstance = this; synchronized (this) { - profilerSettings = settings; managerStartedByIde = true; // coTarget = null; // targets = null; diff -r 7394f02a2352 j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/TargetServer.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/TargetServer.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/TargetServer.java Fri Jan 13 13:52:17 2012 +0100 @@ -93,10 +93,7 @@ import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment2; import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration; import org.netbeans.modules.j2ee.deployment.plugins.spi.TargetModuleIDResolver; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; -import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; import org.openide.util.Exceptions; -import org.openide.util.Lookup; /** * Encapsulates a set of ServerTarget(s), provides a wrapper for deployment @@ -519,7 +516,6 @@ break; } case PROFILE: { - ProfilerServerSettings settings = Lookup.getDefault().lookup(Profiler.class).getSettings(instance.getUrl(), false); final CountDownLatch latch = new CountDownLatch(1); ServerInstance.StateListener sl = new ServerInstance.StateListener() { @@ -534,7 +530,7 @@ instance.addStateListener(sl); try { - instance.startProfile(settings, false, ui); + instance.startProfile(false, ui); try { // need to wait for profiler to load the agent etc. // 60 seconds timeout; instrumentation may slow down the startup significantly diff -r 7394f02a2352 j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/bridge/BridgingServerInstance.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/bridge/BridgingServerInstance.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/bridge/BridgingServerInstance.java Fri Jan 13 13:52:17 2012 +0100 @@ -52,20 +52,25 @@ import org.netbeans.modules.j2ee.deployment.impl.ui.actions.CustomizerAction; import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer; import org.netbeans.spi.server.ServerInstanceFactory; +import org.netbeans.api.server.CommonServerUIs; +import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; +import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; import org.netbeans.spi.server.ServerInstanceImplementation; -import org.netbeans.api.server.CommonServerUIs; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.openide.util.HelpCtx; +import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.actions.NodeAction; import org.openide.util.actions.SystemAction; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; /** * * @author Petr Hejl */ -public class BridgingServerInstance implements ServerInstanceImplementation, Node.Cookie { +public class BridgingServerInstance implements ServerInstanceImplementation, Lookup.Provider, Node.Cookie { private final org.netbeans.modules.j2ee.deployment.impl.ServerInstance instance; @@ -135,12 +140,23 @@ instance.remove(); } + @Override + public Lookup getLookup() { + // FIXME why is the platform written in such strange way ? + J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(instance.getUrl()); + + if (platform == null) { // can happen when J2EE is activated and J2SE is not !?@# + return Lookups.singleton(instance.getInstanceProperties()); + } else { + return new ProxyLookup(Lookups.fixed(platform, instance.getInstanceProperties()), Lookups.proxy(platform)); + } + } + public ServerInstance getCommonInstance() { synchronized (this) { return commonInstance; } } - @Override public boolean equals(Object obj) { diff -r 7394f02a2352 j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ui/actions/ProfileAction.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ui/actions/ProfileAction.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ui/actions/ProfileAction.java Fri Jan 13 13:52:17 2012 +0100 @@ -47,10 +47,7 @@ import org.netbeans.modules.j2ee.deployment.impl.ServerException; import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; -import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; -import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.nodes.Node; @@ -92,21 +89,21 @@ } final ServerInstance si = (ServerInstance)nodes[0].getCookie(ServerInstance.class); if (si != null) { - Profiler profiler = ServerRegistry.getProfiler(); - if (profiler == null) { - return; - } - final ProfilerServerSettings settings = profiler.getSettings(si.getUrl()); - if (settings == null) { - return; - } +// Profiler profiler = ServerRegistry.getProfiler(); +// if (profiler == null) { +// return; +// } +// final ProfilerServerSettings settings = profiler.getSettings(si.getUrl()); +// if (settings == null) { +// return; +// } RP.post(new Runnable() { public void run() { String title = NbBundle.getMessage(DebugAction.class, "LBL_Profiling", si.getDisplayName()); ProgressUI progressUI = new ProgressUI(title, false); try { progressUI.start(); - si.startProfile(settings, false, progressUI); + si.startProfile(false, progressUI); } catch (ServerException ex) { String msg = ex.getLocalizedMessage(); NotifyDescriptor desc = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE); diff -r 7394f02a2352 j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/CommonServerBridge.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/CommonServerBridge.java Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,100 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 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 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.j2ee.deployment.plugins.api; + +import java.util.Collection; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.server.ServerInstance; +import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; +import org.netbeans.modules.j2ee.deployment.impl.bridge.BridgingServerInstanceProvider; +import org.netbeans.modules.j2ee.deployment.impl.bridge.ServerInstanceProviderLookup; +import org.netbeans.spi.server.ServerInstanceProvider; +import org.openide.util.Parameters; + +/** + * The utility class providing bridge to API classes of the common server. + * + * @author Petr Hejl + * @since 1.88 + */ +public final class CommonServerBridge { + + private CommonServerBridge() { + super(); + } + + private static final Logger LOGGER = Logger.getLogger(CommonServerBridge.class.getName()); + + /** + * Returns the {@link ServerInstance} corresponding to the server instance + * identified by the given url. + * + * @param instanceUrl the server instance url + * @return the {@link ServerInstance} corresponding to the server instance + * identified by the given url + */ + @NonNull + public static ServerInstance getCommonInstance(@NonNull String instanceUrl) { + Parameters.notNull("instanceUrl", instanceUrl); + + org.netbeans.modules.j2ee.deployment.impl.ServerInstance instance = + ServerRegistry.getInstance().getServerInstance(instanceUrl); + ServerInstance bridgingInstance = null; + Collection providers = + ServerInstanceProviderLookup.getInstance().lookupAll(ServerInstanceProvider.class); + for (ServerInstanceProvider provider : providers) { + if (provider instanceof BridgingServerInstanceProvider) { + bridgingInstance = ((BridgingServerInstanceProvider) provider).getBridge(instance); + if (bridgingInstance != null) { + break; + } + } + } + if (bridgingInstance == null) { + LOGGER.log(Level.INFO, "No bridging instance for {0}", instance); + throw new IllegalStateException("Instance registered without UI. No common instance available."); + } + return bridgingInstance; + } +} diff -r 7394f02a2352 j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/StartServer.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/StartServer.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/StartServer.java Fri Jan 13 13:52:17 2012 +0100 @@ -48,7 +48,6 @@ import javax.enterprise.deploy.spi.Target; import javax.enterprise.deploy.spi.status.ProgressObject; import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; /** * Server lifecycle services from the IDE. J2eeserver will use these @@ -247,13 +246,12 @@ * * @param target the target server in question, null target implies * the admin server. - * @param settings profiler server settings. * * @return ServerProgress object to monitor progress on start operation. * * @since 1.9 */ - public ProgressObject startProfiling(Target target, ProfilerServerSettings settings) { + public ProgressObject startProfiling(Target target) { throw new UnsupportedOperationException("Starting in profile mode is not supported by this server."); // NIO18N } diff -r 7394f02a2352 j2eeserver/src/org/netbeans/modules/j2ee/deployment/profiler/api/ProfilerServerSettings.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/profiler/api/ProfilerServerSettings.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/profiler/api/ProfilerServerSettings.java Fri Jan 13 13:52:17 2012 +0100 @@ -54,7 +54,10 @@ * Settings that will be used for profiled server startup. * * @author sherold + * + * @deprecated */ +@Deprecated public final class ProfilerServerSettings { private JavaPlatform javaPlatform; diff -r 7394f02a2352 j2eeserver/src/org/netbeans/modules/j2ee/deployment/profiler/spi/Profiler.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/profiler/spi/Profiler.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/profiler/spi/Profiler.java Fri Jan 13 13:52:17 2012 +0100 @@ -81,7 +81,10 @@ * * @return required settings or null if user cancelled starting * the server. + * + * @deprecated */ + @Deprecated ProfilerServerSettings getSettings(String serverInstanceID); /** @@ -94,7 +97,10 @@ * * @return required settings or null if user cancelled starting * the server. + * + * @deprecated */ + @Deprecated ProfilerServerSettings getSettings(String serverInstanceID, boolean verbose); /** diff -r 7394f02a2352 j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/plugins/api/CommonServerBridgeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/plugins/api/CommonServerBridgeTest.java Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,85 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.j2ee.deployment.plugins.api; + +import java.util.Collections; +import org.netbeans.api.server.ServerInstance; +import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; +import org.netbeans.modules.j2ee.deployment.impl.ServerRegistryTestBase; +import org.openide.util.Lookup; + +/** + * + * @author Petr Hejl + */ +public class CommonServerBridgeTest extends ServerRegistryTestBase { + + private static final String TEST_URL_PREFIX = "fooservice:"; + + public CommonServerBridgeTest(String name) { + super(name); + } + + public void testCommonInstance() throws InstanceCreationException { + String url = TEST_URL_PREFIX + "testCommonInstance"; + InstanceProperties.createInstanceProperties(url, "test", "test", "TestCommon"); + + ServerInstance common = CommonServerBridge.getCommonInstance(url); + assertNotNull(common); + + Lookup lookup = common.getLookup(); + assertNotNull(lookup.lookup(J2eePlatform.class)); + assertNotNull(lookup.lookup(InstanceProperties.class)); + } + + public void testNoCommonInstance() throws InstanceCreationException { + String url = TEST_URL_PREFIX + "testNoCommonInstance"; + InstanceProperties.createInstancePropertiesWithoutUI(url, "test", "test", "TestNoCommon", Collections.emptyMap()); + + try { + CommonServerBridge.getCommonInstance(url); + fail("Common instance found for EE instance registered without UI"); + } catch (IllegalStateException ex) { + // expected + } + } +} diff -r 7394f02a2352 j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/plugins/api/InstancePropertiesTest.java --- a/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/plugins/api/InstancePropertiesTest.java Fri Jan 13 12:35:36 2012 +0400 +++ b/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/plugins/api/InstancePropertiesTest.java Fri Jan 13 13:52:17 2012 +0100 @@ -46,12 +46,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import org.netbeans.api.keyring.Keyring; import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; @@ -59,7 +55,6 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem.AtomicAction; import org.openide.filesystems.FileUtil; -import org.openide.util.RequestProcessor; /** * diff -r 7394f02a2352 profiler.j2ee/nbproject/project.xml --- a/profiler.j2ee/nbproject/project.xml Fri Jan 13 12:35:36 2012 +0400 +++ b/profiler.j2ee/nbproject/project.xml Fri Jan 13 13:52:17 2012 +0100 @@ -260,6 +260,15 @@ + org.netbeans.modules.server + + + + 0-1 + 1.19 + + + org.openide.awt diff -r 7394f02a2352 profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/J2EEProfilerSPI.java --- a/profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/J2EEProfilerSPI.java Fri Jan 13 12:35:36 2012 +0400 +++ b/profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/J2EEProfilerSPI.java Fri Jan 13 13:52:17 2012 +0100 @@ -170,8 +170,6 @@ private boolean refreshServerInstance = false; private boolean serverStartedFromIDE = false; private /*static final*/ int STARTING_STATE_TIMEOUT = 20000; // timeout for starting the agent [ms] - private int profilerAgentID = -111; // should differ from default J2EEProjectTypeProfiler.getLastAgentID() - private int profilerAgentPort = 0; // should differ from default J2EEProjectTypeProfiler.getLastAgentPort() private long profilerAgentStartingTime = -1; //~ Constructors ------------------------------------------------------------------------------------------------------------- @@ -349,6 +347,8 @@ * @return state of Profiler agent instance. */ public synchronized int getState() { + int profilerAgentID = J2EEProjectProfilingSupportProvider.getLastAgentID(); + int profilerAgentPort = J2EEProjectProfilingSupportProvider.getLastAgentPort(); int agentState = checkState(); ProfilerLogger.log(">>> Profiler agent [port=" + profilerAgentPort + ", id=" + profilerAgentID + "]: " + getPublicAgentStateString(agentState)); // NOI18N @@ -418,9 +418,7 @@ * allows the Profiler to correctly detect STATE_STARTING. */ public void notifyStarting() { - profilerAgentID = J2EEProjectProfilingSupportProvider.getLastAgentID(); - profilerAgentPort = J2EEProjectProfilingSupportProvider.getLastAgentPort(); - + int profilerAgentPort = J2EEProjectProfilingSupportProvider.getLastAgentPort(); NetBeansProfiler.getDefaultNB().cleanForProfilingOnPort(profilerAgentPort); // try to kill an agent on port if some exists profilerAgentStartingTime = System.currentTimeMillis(); @@ -491,6 +489,8 @@ // we only stop the agent if in STATE_BLOCKING state if (getState() == ProfilerSupport.STATE_BLOCKING) { + int profilerAgentID = J2EEProjectProfilingSupportProvider.getLastAgentID(); + int profilerAgentPort = J2EEProjectProfilingSupportProvider.getLastAgentPort(); Profiler.getDefault().shutdownBlockedAgent("localhost", profilerAgentPort, profilerAgentID); // NOI18N for (int i = 0; i < 60; i++) { // 30sec timeout on profiled application shutdown (thread sleeps 500ms) @@ -517,6 +517,7 @@ } finally { // reset the shutdown progress flag profilerAgentShutdownProgress = false; + J2EEProjectProfilingSupportProvider.resetLastValues(); } } }; @@ -614,6 +615,8 @@ // --- Private implementation ------------------------------------------------ private int checkState() { + int profilerAgentID = J2EEProjectProfilingSupportProvider.getLastAgentID(); + int profilerAgentPort = J2EEProjectProfilingSupportProvider.getLastAgentPort(); int currentAgentState = NetBeansProfiler.getDefault().getAgentState("localhost", profilerAgentPort, profilerAgentID); // NOI18N //System.err.println(">>> Detected internal agent state: " + getInternalAgentStateString(currentAgentState)); diff -r 7394f02a2352 profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/J2EEProjectProfilingSupportProvider.java --- a/profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/J2EEProjectProfilingSupportProvider.java Fri Jan 13 12:35:36 2012 +0400 +++ b/profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/J2EEProjectProfilingSupportProvider.java Fri Jan 13 13:52:17 2012 +0100 @@ -179,6 +179,11 @@ public static int getLastAgentPort() { return lastAgentPort; } + + public static void resetLastValues() { + lastAgentID = -1; + lastAgentPort = -1; + } public static String getServerInstanceID(final Project project) { J2eeModuleProvider serverInstanceModuleProvider = project.getLookup().lookup(J2eeModuleProvider.class); diff -r 7394f02a2352 profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/impl/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/impl/Bundle.properties Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,44 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 1997-2011 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]" +# +# 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. + +## Resource bundle for package org.netbeans.modules.profiler.j2ee.impl +DESC_Profiler=NetBeans Profiler diff -r 7394f02a2352 profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/impl/ProfilerArgsProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/impl/ProfilerArgsProvider.java Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,74 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 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 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.profiler.j2ee.impl; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.netbeans.api.server.ServerInstance; +import org.netbeans.api.server.StartupArguments.StartMode; +import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; +import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; +import org.netbeans.spi.server.StartupArgumentsProvider; +import org.openide.util.Lookup; + +/** + * + * @author Jaroslav Bachorik + */ +@StartupArgumentsProvider.Registration(position=100, displayName="#DESC_Profiler", + startMode=StartMode.PROFILE) +public class ProfilerArgsProvider implements StartupArgumentsProvider { + + @Override + public List getArguments(ServerInstance instance, StartMode mode) { + if (mode == StartMode.PROFILE) { + Profiler p = Lookup.getDefault().lookup(Profiler.class); + InstanceProperties ip = instance.getLookup().lookup(InstanceProperties.class); + if (ip != null) { + return Arrays.asList(p.getSettings(ip.getProperty("url"), false).getJvmArgs()); //NOI18N + } + } + return Collections.EMPTY_LIST; + } + +} diff -r 7394f02a2352 server/apichanges.xml --- a/server/apichanges.xml Fri Jan 13 12:35:36 2012 +0400 +++ b/server/apichanges.xml Fri Jan 13 13:52:17 2012 +0100 @@ -110,6 +110,24 @@ + + + SPI to allow passing additional arguments to server VM + + + + + + This API/SPI allow third party plugins (such as JRebel) to + register providers of VM arguments. The server plugin may + optionaly query such arguments and pass them to server VM. + The ServerInstance became Lookup.Provider. + + + + + + Added UI helper method CommonServerUIs.showAddServerInstanceWizard diff -r 7394f02a2352 server/arch.xml --- a/server/arch.xml Fri Jan 13 12:35:36 2012 +0400 +++ b/server/arch.xml Fri Jan 13 13:52:17 2012 +0100 @@ -60,7 +60,8 @@

Clients can provide its instances through the SPI. They can also provide - wizards to define UI way for the server or cloud instance addition. It is done with + wizards to define UI way for the server or cloud instance addition. There + is also provider of VM arguments which can be registered in layer. It is done with where the SPIs implementation must be registered.

@@ -81,6 +82,10 @@ can extend the list of popup actions on Cloud node in Services tab.
+ + By registering providers to Servers/StartupArgumentsProviders you + can register your additional VM arguments provider. + If the action registered in Servers/Actions or Cloud/Actions folder has getValue("serverNodeHidden") == Boolean.TRUE, then @@ -236,7 +241,24 @@ can be used. It provides a way how to store and retrieve properties of the server instance.

- + + +

+ The third party plugin may want to be able provide additional arguments + for the server in a standardized way. In order to do so it will register + a implementation of + StartupArgumentsProvider + to the layer folder Servers/VMArgumentProviders. The annotation + StartupArgumentsProvider.Registration + can be used for that. +

+

+ The clients (server plugin implementations) may query the providers via the + API class + StartupArguments + and use the additional arguments for the server. +

+
diff -r 7394f02a2352 server/manifest.mf --- a/server/manifest.mf Fri Jan 13 12:35:36 2012 +0400 +++ b/server/manifest.mf Fri Jan 13 13:52:17 2012 +0100 @@ -2,7 +2,7 @@ OpenIDE-Module: org.netbeans.modules.server/0 OpenIDE-Module-Layer: org/netbeans/modules/server/resources/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/server/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.18 +OpenIDE-Module-Specification-Version: 1.19 AutoUpdate-Show-In-Client: false OpenIDE-Module-Provides: org.netbeans.modules.server diff -r 7394f02a2352 server/src/org/netbeans/api/server/ServerInstance.java --- a/server/src/org/netbeans/api/server/ServerInstance.java Fri Jan 13 12:35:36 2012 +0400 +++ b/server/src/org/netbeans/api/server/ServerInstance.java Fri Jan 13 13:52:17 2012 +0100 @@ -46,6 +46,7 @@ import org.netbeans.spi.server.ServerInstanceFactory; import org.netbeans.spi.server.ServerInstanceImplementation; import org.openide.nodes.Node; +import org.openide.util.Lookup; /** * The API representation of the single server instance. Class describes @@ -56,7 +57,7 @@ * * @author Petr Hejl */ -public final class ServerInstance { +public final class ServerInstance implements Lookup.Provider { static { ServerInstanceFactory.Accessor.DEFAULT = new ServerInstanceFactory.Accessor() { @@ -142,5 +143,17 @@ public boolean isRemovable() { return delegate.isRemovable(); } - + + /** + * Returns the lookup associated with this instance. + * + * @return the lookup associated with this instance + * @since 1.19 + */ + public Lookup getLookup() { + if (delegate instanceof Lookup.Provider) { + return ((Lookup.Provider) delegate).getLookup(); + } + return Lookup.EMPTY; + } } diff -r 7394f02a2352 server/src/org/netbeans/api/server/StartupArguments.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/org/netbeans/api/server/StartupArguments.java Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,152 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 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 2011 Sun Microsystems, Inc. + */ +package org.netbeans.api.server; + +import java.util.ArrayList; +import java.util.List; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.modules.server.annotations.StartupArgumentsRegistrationProcessor; +import org.netbeans.spi.server.StartupArgumentsProvider; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; +import org.openide.util.Parameters; +import org.openide.util.lookup.Lookups; + +/** + * The API class allowing clients, typically server plugins, to query additional + * groups of arguments it may pass to VM. + * + * @author Petr Hejl + * @since 1.19 + * @see StartupArgumentsProvider + */ +public final class StartupArguments { + + private final String description; + + private final List arguments; + + private StartupArguments(String description, List arguments) { + this.description = description; + this.arguments = arguments; + } + + /** + * Returns the groups of arguments provided by all registered + * {@link StartupArgumentsProvider} for the given start mode. + * + * @param instance the server instance being started + * @param mode the VM mode the client is going to use + * @return the groups of arguments provided by all registered + * {@link StartupArgumentsProvider} + */ + @NonNull + public static List getStartupArguments( + @NonNull ServerInstance instance, @NonNull StartMode mode) { + Parameters.notNull("instance", instance); + Parameters.notNull("mode", mode); + + Lookup lkp = Lookups.forPath(StartupArgumentsRegistrationProcessor.PATH); + + List res = new ArrayList(); + for (Lookup.Item item : lkp.lookupResult(StartupArgumentsProvider.class).allItems()) { + res.add(new StartupArguments(item.getDisplayName(), + item.getInstance().getArguments(instance, mode))); + } + return res; + } + + /** + * Returns the description of group of arguments. + * + * @return the description of group of arguments + */ + @NonNull + public String getDescription() { + return description; + } + + /** + * The list of the VM arguments. + * + * @return list of the VM arguments + */ + @NonNull + public List getArguments() { + return arguments; + } + + /** + * Class representing the startup mode of the VM. + */ + public static enum StartMode { + + /** + * The normal startup mode. + */ + @NbBundle.Messages("StartMode_Normal=Normal") + NORMAL(Bundle.StartMode_Normal()), + + /** + * The debug startup mode. + */ + @NbBundle.Messages("StartMode_Debug=Debug") + DEBUG(Bundle.StartMode_Debug()), + + /** + * The profile startup mode. + */ + @NbBundle.Messages("StartMode_Profile=Profile") + PROFILE(Bundle.StartMode_Profile()); + + private final String mode; + + private StartMode(String mode) { + this.mode = mode; + } + + @Override + public String toString() { + return mode; + } + } +} diff -r 7394f02a2352 server/src/org/netbeans/modules/server/ProxyStartupArgumentsProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/org/netbeans/modules/server/ProxyStartupArgumentsProvider.java Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,111 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.server; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.netbeans.api.server.ServerInstance; +import org.netbeans.api.server.StartupArguments.StartMode; +import org.netbeans.modules.server.annotations.StartupArgumentsRegistrationProcessor; +import org.netbeans.spi.server.StartupArgumentsProvider; + +/** + * + * @author Petr Hejl + */ +public class ProxyStartupArgumentsProvider implements StartupArgumentsProvider { + + private final Map attributes; + + private final Set startMode; + + private StartupArgumentsProvider delegate; + + public ProxyStartupArgumentsProvider(Map attributes) { + this.attributes = attributes; + + String startModeValue = (String) attributes.get( + StartupArgumentsRegistrationProcessor.START_MODE_ATTRIBUTE); + if (startModeValue == null) { + startMode = EnumSet.noneOf(StartMode.class); + } else { + Set result = new HashSet(); + for (String value : startModeValue.split(",")) { + result.add(StartMode.valueOf(value)); + } + startMode = EnumSet.copyOf(result); + } + } + + @Override + public List getArguments(ServerInstance instance, StartMode mode) { + if (startMode.contains(mode)) { + return getDelegate().getArguments(instance, mode); + } + return Collections.emptyList(); + } + + private StartupArgumentsProvider getDelegate() { + synchronized (this) { + if (delegate != null) { + return delegate; + } + } + + StartupArgumentsProvider provider = (StartupArgumentsProvider) attributes.get( + StartupArgumentsRegistrationProcessor.DELEGATE_ATTRIBUTE); + if (provider == null) { + throw new IllegalStateException("Delegate must not be null"); + } + + synchronized (this) { + if (delegate == null) { + delegate = provider; + } + return delegate; + } + } +} diff -r 7394f02a2352 server/src/org/netbeans/modules/server/annotations/StartupArgumentsRegistrationProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/org/netbeans/modules/server/annotations/StartupArgumentsRegistrationProcessor.java Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,105 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 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 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.server.annotations; + +import java.util.Set; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import org.netbeans.api.server.StartupArguments.StartMode; +import org.netbeans.spi.server.StartupArgumentsProvider; +import org.openide.filesystems.annotations.LayerBuilder.File; +import org.openide.filesystems.annotations.LayerGeneratingProcessor; +import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author Petr Hejl + */ +@SupportedAnnotationTypes("org.netbeans.spi.server.StartupArgumentsProvider.Registration") +@ServiceProvider(service = Processor.class) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class StartupArgumentsRegistrationProcessor extends LayerGeneratingProcessor { + + public static final String PATH = "Servers/StartupArgumentProviders"; // NOI18N + + public static final String DELEGATE_ATTRIBUTE = "delegate"; // NOI18N + + public static final String START_MODE_ATTRIBUTE = "startMode"; // NOI18N + + @Override + protected boolean handleProcess(Set annotations, RoundEnvironment roundEnv) throws LayerGenerationException { + if (roundEnv.processingOver()) { + return false; + } + + for (Element element : roundEnv.getElementsAnnotatedWith( + StartupArgumentsProvider.Registration.class)) { + + StartupArgumentsProvider.Registration annotation = element.getAnnotation(StartupArgumentsProvider.Registration.class); + if (annotation == null) { + continue; + } + StringBuilder builder = new StringBuilder(); + for (StartMode mode : annotation.startMode()) { + builder.append(mode.name()).append(","); + } + if (builder.length() > 0) { + builder.setLength(builder.length() - 1); + } + File f = layer(element).instanceFile(PATH, null) + .instanceAttribute(DELEGATE_ATTRIBUTE, StartupArgumentsProvider.class, annotation, null) + .stringvalue(START_MODE_ATTRIBUTE, builder.toString()) + .bundlevalue("displayName", element.getAnnotation(StartupArgumentsProvider.Registration.class).displayName()) // NOI18N + .methodvalue("instanceCreate", "org.netbeans.spi.server.StartupArguments", "createProxy") // NOI18N + .position(element.getAnnotation(StartupArgumentsProvider.Registration.class).position()); // NOI18N + f.write(); + } + return true; + } + +} diff -r 7394f02a2352 server/src/org/netbeans/spi/server/StartupArguments.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/org/netbeans/spi/server/StartupArguments.java Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,56 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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 2012 Sun Microsystems, Inc. + */ +package org.netbeans.spi.server; + +import java.util.Map; +import org.netbeans.modules.server.ProxyStartupArgumentsProvider; + +/** + * + * @author Petr Hejl + */ +final class StartupArguments { + + static StartupArgumentsProvider createProxy(Map map) { + return new ProxyStartupArgumentsProvider(map); + } +} diff -r 7394f02a2352 server/src/org/netbeans/spi/server/StartupArgumentsProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/org/netbeans/spi/server/StartupArgumentsProvider.java Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,100 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 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 2011 Sun Microsystems, Inc. + */ +package org.netbeans.spi.server; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.List; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.server.ServerInstance; +import org.netbeans.api.server.StartupArguments; + +/** + * Provides the additional arguments to server VM. Typically the server plugin + * implementor will query the arguments via API counterpart {@link StartupArguments}. + * Of course it is not mandatary for server plugin to use such arguments and + * there is no way to force it. + * + * @author Petr Hejl + * @since 1.19 + * @see StartupArguments + */ +public interface StartupArgumentsProvider { + + /** + * Returns the list of arguments to pass to the server VM for the given + * start mode. + * + * @param instance the server instance being started + * @param mode the VM mode the client is going to use + * @return the list of arguments to pass to the server VM + */ + @NonNull + List getArguments(@NonNull ServerInstance instance, @NonNull StartupArguments.StartMode mode); + + /** + * Annotation used to properly register the SPI implementations. + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE, ElementType.METHOD}) + public @interface Registration { + + /** + * The human readable description of the provider. May be a bundle key. + * For example this might be "JRebel", "Profiler" etc. + */ + String displayName(); + + /** + * Modes to which the provider will respond. + */ + StartupArguments.StartMode[] startMode(); + + /** + * Position of the provider in the list of providers. + */ + int position() default Integer.MAX_VALUE; + + } +} diff -r 7394f02a2352 server/test/unit/src/org/netbeans/api/server/StartupArgumentsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/test/unit/src/org/netbeans/api/server/StartupArgumentsTest.java Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,89 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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 2012 Sun Microsystems, Inc. + */ +package org.netbeans.api.server; + +import java.util.List; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.server.ProxyStartupArgumentsProvider; +import org.netbeans.modules.server.annotations.StartupArgumentsRegistrationProcessor; +import org.netbeans.modules.server.test.MockInstanceImplementation; +import org.netbeans.modules.server.test.MockInstanceProvider; +import org.netbeans.spi.server.StartupArgumentsProvider; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; + +/** + * + * @author Petr Hejl + */ +public class StartupArgumentsTest extends NbTestCase { + + public StartupArgumentsTest(String name) { + super(name); + } + + public void testLaziness() { + Lookup lookup = Lookups.forPath(StartupArgumentsRegistrationProcessor.PATH); + assertTrue(lookup.lookup(StartupArgumentsProvider.class) instanceof ProxyStartupArgumentsProvider); + } + + public void testArguments() { + MockInstanceImplementation instance = MockInstanceImplementation.createInstance(new MockInstanceProvider(), + "Test server", "Test instance", true); // NOI18N + + List argsDebug = + StartupArguments.getStartupArguments(instance.getServerInstance(), StartupArguments.StartMode.DEBUG); + assertEquals(1, argsDebug.size()); + assertTrue(argsDebug.get(0).getArguments().isEmpty()); + + List argsNormal = + StartupArguments.getStartupArguments(instance.getServerInstance(), StartupArguments.StartMode.NORMAL); + assertEquals(1, argsNormal.size()); + + StartupArguments args = argsNormal.get(0); + assertEquals("Test", args.getDescription()); + assertEquals(2, args.getArguments().size()); + + assertEquals("arg1", args.getArguments().get(0)); + assertEquals("arg2", args.getArguments().get(1)); + } +} diff -r 7394f02a2352 server/test/unit/src/org/netbeans/modules/server/test/MockArgumentsProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/test/unit/src/org/netbeans/modules/server/test/MockArgumentsProvider.java Fri Jan 13 13:52:17 2012 +0100 @@ -0,0 +1,62 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.server.test; + +import java.util.Arrays; +import java.util.List; +import org.netbeans.api.server.ServerInstance; +import org.netbeans.api.server.StartupArguments.StartMode; +import org.netbeans.spi.server.StartupArgumentsProvider; + +/** + * + * @author Petr Hejl + */ +@StartupArgumentsProvider.Registration(displayName="Test", startMode=StartMode.NORMAL) +public class MockArgumentsProvider implements StartupArgumentsProvider { + + @Override + public List getArguments(ServerInstance instance, StartMode mode) { + return Arrays.asList("arg1", "arg2"); + } + +} diff -r 7394f02a2352 tomcat5/nbproject/project.xml --- a/tomcat5/nbproject/project.xml Fri Jan 13 12:35:36 2012 +0400 +++ b/tomcat5/nbproject/project.xml Fri Jan 13 13:52:17 2012 +0100 @@ -176,7 +176,7 @@ 4 - 1.66 + 1.88
@@ -213,6 +213,15 @@ + org.netbeans.modules.server + + + + 0-1 + 1.19 + + + org.openide.actions diff -r 7394f02a2352 tomcat5/src/org/netbeans/modules/tomcat5/ide/StartTomcat.java --- a/tomcat5/src/org/netbeans/modules/tomcat5/ide/StartTomcat.java Fri Jan 13 12:35:36 2012 +0400 +++ b/tomcat5/src/org/netbeans/modules/tomcat5/ide/StartTomcat.java Fri Jan 13 13:52:17 2012 +0100 @@ -69,6 +69,8 @@ import javax.enterprise.deploy.spi.status.ProgressListener; import javax.enterprise.deploy.spi.status.ProgressObject; import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.server.StartupArguments; +import org.netbeans.modules.j2ee.deployment.plugins.api.CommonServerBridge; import org.netbeans.modules.tomcat5.progress.ProgressEventSupport; import org.netbeans.modules.tomcat5.progress.Status; import org.netbeans.modules.tomcat5.util.LogManager; @@ -78,7 +80,6 @@ import org.openide.util.RequestProcessor; import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo; import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer; -import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerSupport; import org.netbeans.modules.tomcat5.TomcatManager; import org.netbeans.modules.tomcat5.util.TomcatProperties; @@ -164,7 +165,7 @@ public ProgressObject startDeploymentManager () { LOGGER.log(Level.FINE, "StartTomcat.startDeploymentManager called on " + tm); // NOI18N pes.fireHandleProgressEvent (null, new Status (ActionType.EXECUTE, CommandType.START, "", StateType.RUNNING)); - SERVER_CONTROL_RP.post(new StartRunnable(MODE_RUN, CommandType.START, null), + SERVER_CONTROL_RP.post(new StartRunnable(MODE_RUN, CommandType.START), 0, Thread.NORM_PRIORITY); isDebugModeUri.remove(tm.getUri()); return this; @@ -227,7 +228,7 @@ public ProgressObject stopDeploymentManager() { LOGGER.log(Level.FINE, "StartTomcat.stopDeploymentManager called on " + tm); // NOI18N pes.fireHandleProgressEvent (null, new Status (ActionType.EXECUTE, CommandType.STOP, "", StateType.RUNNING)); - SERVER_CONTROL_RP.post(new StartRunnable(MODE_RUN, CommandType.STOP, null), + SERVER_CONTROL_RP.post(new StartRunnable(MODE_RUN, CommandType.STOP), 0, Thread.NORM_PRIORITY); isDebugModeUri.remove(tm.getUri()); return this; @@ -243,19 +244,19 @@ public ProgressObject startDebugging(Target target) { LOGGER.log(Level.FINE, "StartTomcat.startDebugging called on " + tm); // NOI18N pes.fireHandleProgressEvent (null, new Status (ActionType.EXECUTE, CommandType.START, "", StateType.RUNNING)); - SERVER_CONTROL_RP.post(new StartRunnable(MODE_DEBUG, CommandType.START, null), + SERVER_CONTROL_RP.post(new StartRunnable(MODE_DEBUG, CommandType.START), 0, Thread.NORM_PRIORITY); return this; } - public ProgressObject startProfiling(Target target, ProfilerServerSettings settings) { + public ProgressObject startProfiling(Target target) { LOGGER.log(Level.FINE, "StartTomcat.startProfiling called on " + tm); // NOI18N pes.fireHandleProgressEvent(null, new Status( ActionType.EXECUTE, CommandType.START, "", // NOI18N StateType.RUNNING)); - SERVER_CONTROL_RP.post(new StartRunnable(MODE_PROFILE, CommandType.START, settings), + SERVER_CONTROL_RP.post(new StartRunnable(MODE_PROFILE, CommandType.START), 0, Thread.NORM_PRIORITY); return this; } @@ -275,12 +276,10 @@ private int mode; private CommandType command = CommandType.START; - private ProfilerServerSettings profilerSettings; - public StartRunnable(int mode, CommandType command, ProfilerServerSettings profilerSettings) { + public StartRunnable(int mode, CommandType command) { this.mode = mode; this.command = command; - this.profilerSettings = profilerSettings; } public synchronized void run () { @@ -398,11 +397,18 @@ } } } + + + for (StartupArguments args : StartupArguments.getStartupArguments( + CommonServerBridge.getCommonInstance(tm.getUri()), getMode(mode))) { + for (String singleArg : args.getArguments()) { + sb.append(' ').append(singleArg); + } + } javaOpts = sb.toString(); } - JavaPlatform platform = mode == MODE_PROFILE ? profilerSettings.getJavaPlatform() - : getJavaPlatform(); + JavaPlatform platform = getJavaPlatform(); String jdkVersion = platform.getSpecification().getVersion().toString(); if (tm.isBundledTomcat()) { @@ -460,54 +466,6 @@ startupScript.getAbsolutePath(), StateType.FAILED); return; } - } else if ((mode == MODE_PROFILE) && (command == CommandType.START)) { - NbProcessDescriptor pd = null; - if (tp.getSecManager()) { - pd = defaultExecDesc(TAG_EXEC_CMD, TAG_EXEC_STARTUP, TAG_SECURITY_OPT); - } else { - pd = defaultExecDesc(TAG_EXEC_CMD, TAG_EXEC_STARTUP); - } - try { - fireCmdExecProgressEvent("MSG_StartingInProfileMode", StateType.RUNNING); - Process p = null; - - String[] profJvmArgs = profilerSettings.getJvmArgs(); - // TODO solve conflicts between profiler and tomcat vm args - StringBuffer catalinaOpts = new StringBuffer(); - for (int i = 0; i < profJvmArgs.length; i++) { - catalinaOpts.append(profJvmArgs[i]).append(" "); // NOI18N - } - String[] defaultEnv = new String[] { - "JAVA_HOME=" + getJavaHome(platform), // NOI18N - "JRE_HOME=", // NOI18N ensure that JRE_HOME system property won't be used instead of JAVA_HOME - "JAVA_OPTS=" + javaOpts, // NOI18N - "CATALINA_OPTS=" + catalinaOpts.toString(), // NOI18N - "CATALINA_HOME=" + homeDir.getAbsolutePath(), // NOI18N - "CATALINA_BASE=" + baseDir.getAbsolutePath(), // NOI18N - // this is used in the setclasspath.sb/bat script for work-arounding - // problems caused by the compatibility pack when running on 1.5 - "NB_TOMCAT_JDK=" + jdkVersion, // NOI18N - TomcatManager.KEY_UUID + "=" + tm.getUri() - }; - String[] profEnv = profilerSettings.getEnv(); - // merge Tomcat and profiler env properties - String[] envp = new String[defaultEnv.length + profEnv.length]; - System.arraycopy(profEnv, 0, envp, 0, profEnv.length); - System.arraycopy(defaultEnv, 0, envp, profEnv.length, defaultEnv.length); - p = pd.exec( - new TomcatFormat(startupScript, homeDir), - envp, - true, - new File(homeDir, "bin") // NOI18N - ); - tm.setTomcatProcess(p); - openLogs(); - } catch (java.io.IOException ioe) { - LOGGER.log(Level.FINE, null, ioe); - fireCmdExecProgressEvent(command == CommandType.START ? "MSG_StartFailedIOE" : "MSG_StopFailedIOE", - startupScript.getAbsolutePath(), StateType.FAILED); - return; - } } else { NbProcessDescriptor pd = null; if (command == CommandType.START) { @@ -573,7 +531,18 @@ StateType.FAILED); } } - + + private StartupArguments.StartMode getMode(int mode) { + switch (mode) { + case MODE_PROFILE: + return StartupArguments.StartMode.PROFILE; + case MODE_DEBUG: + return StartupArguments.StartMode.DEBUG; + default: + return StartupArguments.StartMode.NORMAL; + } + } + /** Open JULI log and server output */ private void openLogs() { LogManager logManager = tm.logManager();