? defaultServer.diff ? defaultServer1.diff ? defaultServer2.diff ? p2.diff ? p3.diff Index: apichanges.xml =================================================================== RCS file: /cvs/j2eeserver/apichanges.xml,v retrieving revision 1.16.6.3.2.7 diff -u -r1.16.6.3.2.7 apichanges.xml --- apichanges.xml 21 Aug 2006 14:30:52 -0000 1.16.6.3.2.7 +++ apichanges.xml 1 Sep 2006 13:45:16 -0000 @@ -86,6 +86,30 @@ + + + + Default server API residues removed. + + + + + + +

+ In the past, before the J2EE support was added to NetBeans the default server + concept had been used. This concept was then abandoned since it did not work + anymore. The problem could occur for example if the default server was Tomcat + then the EJB project which was set to use the default server could not be + deployed to it, etc. +

+
+ + + + + +
Index: src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java,v retrieving revision 1.40.2.4.2.6 diff -u -r1.40.2.4.2.6 ConfigSupportImpl.java --- src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java 21 Aug 2006 14:30:53 -0000 1.40.2.4.2.6 +++ src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java 1 Sep 2006 13:45:16 -0000 @@ -80,7 +80,7 @@ private Map relativePaths = null; private Map allRelativePaths = null; - private J2eeModuleProvider provider; + private final J2eeModuleProvider provider; private final ModuleDeploymentSupport mds; private DeploymentConfiguration deploymentConfiguration; @@ -91,11 +91,26 @@ public ConfigSupportImpl (J2eeModuleProvider provider) { this.provider = provider; mds = new ModuleDeploymentSupport(provider, true); - instance = ServerRegistry.getInstance().getServerInstance(provider.getServerInstanceID()); - server = instance != null - ? instance.getServer() - : ServerRegistry.getInstance().getServer(provider.getServerID()); - provider.addPropertyChangeListener(this); + String serverInstanceId = provider.getServerInstanceID(); + if (serverInstanceId != null) { + instance = ServerRegistry.getInstance().getServerInstance(provider.getServerInstanceID()); + if (instance != null) { + // project server instance exists + server = instance.getServer(); + } + } + if (server == null) { + // project server instance is not set or does not exist + String serverID = provider.getServerID(); + if (serverID != null) { + // project server exists + server = ServerRegistry.getInstance().getServer(serverID); + } + } + // the module has no server set, do not listen to changes + if (server != null) { + provider.addPropertyChangeListener(this); + } } /** @@ -174,13 +189,12 @@ /** dispose all created deployment configurations */ public void dispose() { - provider.removePropertyChangeListener(this); - if (server == null) { - return; - } - ConfigurationSupport serverConfig = server.getConfigurationSupport(); - if (deploymentConfiguration != null && serverConfig != null) { - serverConfig.disposeConfiguration(deploymentConfiguration); + if (server != null) { + provider.removePropertyChangeListener(this); + ConfigurationSupport serverConfig = server.getConfigurationSupport(); + if (deploymentConfiguration != null && serverConfig != null) { + serverConfig.disposeConfiguration(deploymentConfiguration); + } } if (mds != null) { mds.cleanup(); @@ -253,6 +267,9 @@ } public String[] getDeploymentConfigurationFileNames() { + if (server == null) { + return new String[]{}; + } if (hasCustomSupport()) { return (String[]) getRelativePaths().keySet().toArray(new String[relativePaths.size()]); } @@ -267,6 +284,10 @@ } public void setCMPMappingInfo(final OriginalCMPMapping[] mappings) { + if (server == null) { + // the module has no target server + return; + } DeploymentConfiguration config = getDeploymentConfiguration(); ConfigurationSupport serverConfig = server.getConfigurationSupport(); serverConfig.setMappingInfo(config, mappings); @@ -279,6 +300,10 @@ if (ejbtype == null) { throw new NullPointerException("EJB type cannot be null"); // NOI18N } + if (server == null) { + // the module has no target server + return; + } DDBean ejbBean = findDDBean(ejbname, ejbtype); if (ejbBean != null) { DeploymentConfiguration config = getDeploymentConfiguration(); @@ -297,6 +322,10 @@ if (jndiName == null) { throw new NullPointerException("JNDI name cannot be null"); // NOI18N } + if (server == null) { + // the module has no target server + return; + } DDBean ejbBean = findDDBean(ejbname, ejbtype); if (ejbBean != null) { DeploymentConfiguration config = getDeploymentConfiguration(); @@ -357,6 +386,10 @@ } public boolean isDatasourceCreationSupported() { + if (server == null) { + // the module has no target server + return false; + } ConfigurationSupport configSupport = server.getConfigurationSupport(); if (configSupport == null) @@ -366,11 +399,8 @@ } public Datasource createDatasource(String jndiName, String url, String username, String password, String driver) - throws OperationUnsupportedException, DatasourceAlreadyExistsException - { - + throws OperationUnsupportedException, DatasourceAlreadyExistsException { Datasource ds = null; - if (server != null) { ConfigurationSupport configSupport = server.getConfigurationSupport(); if (configSupport != null) { @@ -384,7 +414,6 @@ } } } - return ds; } @@ -399,8 +428,11 @@ try { if (instance != null) { deploymentConfiguration = instance.getDeploymentManagerForConfiguration().createConfiguration(dobj); - } else { + } else if (server != null) { deploymentConfiguration = server.getDisconnectedDeploymentManager().createConfiguration(dobj); + } else { + // the module has no target server, there is nothing else to return + return null; } ConfigurationSupport serverConfig = server.getConfigurationSupport(); File[] files = getDeploymentConfigurationFiles(getProvider(), server); Index: src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java,v retrieving revision 1.21.6.1.2.3 diff -u -r1.21.6.1.2.3 Deployment.java --- src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java 1 Jul 2006 05:16:11 -0000 1.21.6.1.2.3 +++ src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java 1 Sep 2006 13:45:16 -0000 @@ -244,17 +244,6 @@ return null; } - public String getDefaultServerInstanceID () { - ServerString defInst = ServerRegistry.getInstance ().getDefaultInstance (); - if (defInst != null) { - ServerInstance si = defInst.getServerInstance(); - if (si != null) { - return si.getUrl (); - } - } - return null; - } - public String [] getInstancesOfServer (String id) { if (id != null) { Server server = ServerRegistry.getInstance().getServer(id); Index: src/org/netbeans/modules/j2ee/deployment/devmodules/spi/InstanceListener.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/InstanceListener.java,v retrieving revision 1.1.62.1 diff -u -r1.1.62.1 InstanceListener.java --- src/org/netbeans/modules/j2ee/deployment/devmodules/spi/InstanceListener.java 1 Jul 2006 05:16:13 -0000 1.1.62.1 +++ src/org/netbeans/modules/j2ee/deployment/devmodules/spi/InstanceListener.java 1 Sep 2006 13:45:16 -0000 @@ -31,14 +31,6 @@ public interface InstanceListener extends EventListener { /** - * Default server instance has been changed. - * - * @param oldServerInstanceID id of the old default server instance. - * @param newServerInstanceID id of the new default server instance. - */ - public void changeDefaultInstance(String oldServerInstanceID, String newServerInstanceID); - - /** * Server instance has been added. * * @param serverInstanceID id of the server instance that has been added. Index: src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java,v retrieving revision 1.47.30.3.2.5 diff -u -r1.47.30.3.2.5 J2eeModuleProvider.java --- src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java 21 Aug 2006 14:30:53 -0000 1.47.30.3.2.5 +++ src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java 1 Sep 2006 13:45:16 -0000 @@ -62,7 +62,6 @@ */ public abstract class J2eeModuleProvider { - private InstanceListener il; private ConfigSupportImpl configSupportImpl; List listeners = new ArrayList(); private ConfigFilesListener configFilesListener = null; @@ -77,10 +76,6 @@ private PropertyChangeSupport supp = new PropertyChangeSupport(this); public J2eeModuleProvider () { - il = new IL (); - ServerRegistry.getInstance ().addInstanceListener ( - (InstanceListener) WeakListeners.create( - InstanceListener.class, il, ServerRegistry.getInstance ())); } public abstract J2eeModule getJ2eeModule (); @@ -432,13 +427,6 @@ return new DefaultSourceMap(this); } - /** If the module wants to specify a target server instance for deployment - * it needs to override this method to return false. - */ - public boolean useDefaultServer () { - return true; - } - /** * Set ID of the server instance that will be used for deployment. * @@ -447,28 +435,38 @@ */ public abstract void setServerInstanceID(String severInstanceID); - /** Id of server isntance for deployment. The default implementation returns - * the default server instance selected in Server Registry. - * The return value may not be null. - * If modules override this method they also need to override {@link useDefaultServer}. + /** + * Id of server instance for deployment or null if the module has no server + * instance set. + * + * @return Id of server instance for deployment or null if the module has no server + * instance set. */ - public String getServerInstanceID () { - return ServerRegistry.getInstance ().getDefaultInstance ().getUrl (); - } + public abstract String getServerInstanceID(); /** - * Return InstanceProperties of the server instance - **/ + * Returns InstanceProperties of the server instance or null if the module has + * no server instance set or the given server instance does not exist. + * + * @return InstanceProperties of the server instance or null if the module has + * no server instance set or the given server instance does not exist. + */ public InstanceProperties getInstanceProperties(){ - return InstanceProperties.getInstanceProperties(getServerInstanceID()); + String serverInstanceID = getServerInstanceID(); + if (serverInstanceID == null) { + return null; + } + return InstanceProperties.getInstanceProperties(serverInstanceID); } - /** This method is used to determin type of target server. - * The return value must correspond to value returned from {@link getServerInstanceID}. + /** + * This method is used to determin type of target server. The return value + * must correspond to the value returned from {@link getServerInstanceID}. + * + * @return the target server type or null if the module has no target server + * type set. */ - public String getServerID () { - return ServerRegistry.getInstance ().getDefaultInstance ().getServer ().getShortName (); - } + public abstract String getServerID(); /** * Return name to be used in deployment of the module. @@ -602,46 +600,7 @@ return; configFilesListener = new ConfigFilesListener(this, listeners); } - - private final class IL implements InstanceListener { - - public void changeDefaultInstance (String oldInst, String newInst) { - ServerInstance oldServerInstance = ServerRegistry.getInstance().getServerInstance(oldInst); - ServerInstance newServerInstance = ServerRegistry.getInstance().getServerInstance(newInst); - ServerString oldInstance = oldServerInstance != null - ? new ServerString(oldServerInstance) - : null; - ServerString newInstance = newServerInstance != null - ? new ServerString(newServerInstance) - : null; - if (useDefaultServer () && newInstance != null - && (oldInstance == null || !oldInstance.getPlugin().equals(newInstance.getPlugin()))) { - if (J2eeModule.WAR.equals(getJ2eeModule().getModuleType())) { - String oldCtxPath = getConfigSupportImpl().getWebContextRoot(); - oldCtxPath = "/"+J2eeModuleProvider.this.getDeploymentName(); //NOI18N - configSupportImpl.dispose(); - J2eeModuleProvider.this.configSupportImpl = null; - getConfigSupportImpl().ensureConfigurationReady(); - String ctx = getConfigSupportImpl().getWebContextRoot (); - if (ctx == null || ctx.equals ("")) { //NOI18N - getConfigSupportImpl().setWebContextRoot(oldCtxPath); - } - } else { - configSupportImpl.dispose(); - J2eeModuleProvider.this.configSupportImpl = null; - getConfigSupportImpl().ensureConfigurationReady(); - } - } - } - - public void instanceAdded (String instance) { - } - - public void instanceRemoved (String instance) { - } - - } - + private ConfigSupportImpl getConfigSupportImpl() { return (ConfigSupportImpl) getConfigSupport(); } Index: src/org/netbeans/modules/j2ee/deployment/impl/InstancePropertiesImpl.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/InstancePropertiesImpl.java,v retrieving revision 1.9.26.1 diff -u -r1.9.26.1 InstancePropertiesImpl.java --- src/org/netbeans/modules/j2ee/deployment/impl/InstancePropertiesImpl.java 1 Jul 2006 05:16:15 -0000 1.9.26.1 +++ src/org/netbeans/modules/j2ee/deployment/impl/InstancePropertiesImpl.java 1 Sep 2006 13:45:17 -0000 @@ -109,28 +109,6 @@ return inst.getDeploymentManager(); } - public javax.enterprise.deploy.spi.Target getDefaultTarget() { - ServerRegistry registry = ServerRegistry.getInstance(); - ServerString ss = registry.getDefaultInstance(); - javax.enterprise.deploy.spi.Target[] targets = ss.toTargets(); - if (targets != null && targets.length > 0) - return targets[0]; - return null; - } - - public void setAsDefaultServer(String targetName) { - ServerRegistry registry = ServerRegistry.getInstance(); - ServerInstance inst = registry.getServerInstance(url); - ServerString server = new ServerString(inst, targetName); - registry.setDefaultInstance(server); - } - - public boolean isDefaultInstance() { - ServerRegistry registry = ServerRegistry.getInstance(); - ServerString ss = registry.getDefaultInstance(); - return ss.getUrl().equals(url); - } - public void refreshServerInstance() { ServerRegistry registry = ServerRegistry.getInstance(); ServerInstance inst = registry.getServerInstance(url); Index: src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java,v retrieving revision 1.61.2.4.2.12 diff -u -r1.61.2.4.2.12 ServerInstance.java --- src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java 7 Aug 2006 08:37:42 -0000 1.61.2.4.2.12 +++ src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java 1 Sep 2006 13:45:17 -0000 @@ -1512,10 +1512,6 @@ } } - public boolean isDefault() { - return url.equals(ServerRegistry.getInstance().getDefaultInstance().getUrl()); - } - public String toString() { return getDisplayName(); } Index: src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java,v retrieving revision 1.47.6.3.2.1 diff -u -r1.47.6.3.2.1 ServerRegistry.java --- src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java 1 Jul 2006 05:16:16 -0000 1.47.6.3.2.1 +++ src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java 1 Sep 2006 13:45:17 -0000 @@ -34,8 +34,6 @@ import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; import org.openide.modules.InstalledFileLocator; -//import java.util.logging.*; - public final class ServerRegistry implements java.io.Serializable { public static final String DIR_INSTALLED_SERVERS = "/J2EE/InstalledServers"; //NOI18N @@ -43,8 +41,6 @@ public static final String URL_ATTR = InstanceProperties.URL_ATTR; public static final String USERNAME_ATTR = InstanceProperties.USERNAME_ATTR; public static final String PASSWORD_ATTR = InstanceProperties.PASSWORD_ATTR; - public static final String FILE_DEFAULT_INSTANCE = "DefaultInstance.settings"; //NOI18N - public static final String J2EE_DEFAULT_SERVER = "j2ee.defaultServer"; //NOI18N public static final String TARGETNAME_ATTR = "targetName"; //NOI18N public static final String SERVER_NAME = "serverName"; //NOI18N private static ServerRegistry instance = null; @@ -224,20 +220,11 @@ if (url == null) return; - // Make sure defaultInstance cache is reset - ServerString def = getDefaultInstance(); - if (url.equals(def.getUrl())) { - defaultInstance = null; - } - ServerInstance instance = (ServerInstance) instancesMap().remove(url); if (instance != null) { fireInstanceListeners(url, false); removeInstanceFromFile(url); } - ServerString newinst = getDefaultInstance(false); - fireDefaultInstance(def != null ? def.getUrl() : null, - newinst != null ? newinst.getUrl() : null); } public ServerInstance[] getServerInstances() { @@ -430,87 +417,6 @@ } } - private void fireDefaultInstance(String oldInstance, String newInstance) { - InstanceListener[] instListeners = getInstanceListeners(); - for(int i = 0; i < instListeners.length; i++) { - instListeners[i].changeDefaultInstance(oldInstance, newInstance); - } - } - - public void setDefaultInstance(ServerString instance) { - if (instance != null && instance.equals(defaultInstance)) { - return; - } - - if (instance == null) { - removeDefaultInstanceFile(); - ServerString oldValue = defaultInstance; - defaultInstance = null; - fireDefaultInstance(oldValue != null ? oldValue.getUrl() : null, null); - } else { - if (ServerStringConverter.writeServerInstance(instance, DIR_INSTALLED_SERVERS, FILE_DEFAULT_INSTANCE)) { - ServerString oldValue = defaultInstance; - defaultInstance = instance; - fireDefaultInstance(oldValue != null ? oldValue.getUrl() : null, - instance != null ? instance.getUrl() : null); - } - } - } - - static private void removeDefaultInstanceFile() { - FileLock lock = null; - Writer writer = null; - try { - String pathName = DIR_INSTALLED_SERVERS + "/" + FILE_DEFAULT_INSTANCE; // NOI18N - FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(pathName); - if (fo != null) - fo.delete(); - } catch(Exception ioe) { - org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.WARNING, ioe); - } - } - - private ServerString getInstallerDefaultPlugin() { - File propFile = InstalledFileLocator.getDefault ().locate ("config/install.properties", null, false); // NOI18N - Properties installProp = readProperties(propFile); //NOI18N - - String j2eeDefaultServerFileName = installProp.getProperty(J2EE_DEFAULT_SERVER); - if (j2eeDefaultServerFileName == null) - return null; - - File serverFile = InstalledFileLocator.getDefault ().locate (j2eeDefaultServerFileName, null, false); - Properties defaultServerProp = readProperties(serverFile); - String serverName = defaultServerProp.getProperty(SERVER_NAME); - String url = defaultServerProp.getProperty(URL_ATTR); - String user = defaultServerProp.getProperty(USERNAME_ATTR); - String password = defaultServerProp.getProperty(PASSWORD_ATTR); - String targetName = defaultServerProp.getProperty(TARGETNAME_ATTR); - - try { - if (url != null) { - InstanceProperties instProp = InstanceProperties.getInstanceProperties(url); - if (instProp == null) - instProp = InstanceProperties.createInstanceProperties(url, user, password); - instProp.setProperties(defaultServerProp); - - ServerInstance inst = getServerInstance(url); - if (inst != null) - return new ServerString(inst, targetName); - - } else if (serverName != null) { - Server server = getServer(serverName); - if (server != null) { - ServerInstance[] instances = server.getInstances(); - if (instances.length > 1) - return new ServerString(instances[0]); - } - } - } catch (Exception e) { - ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); - } - return null; - } - static private Properties readProperties(File propFile) { Properties prop = new Properties(); try { @@ -522,34 +428,6 @@ return prop; } - public ServerString getDefaultInstance() { - return getDefaultInstance(true); - } - - public ServerString getDefaultInstance(boolean readFromFile) { - if (defaultInstance != null) - return defaultInstance; - - if (readFromFile) { - defaultInstance = ServerStringConverter.readServerInstance(DIR_INSTALLED_SERVERS, FILE_DEFAULT_INSTANCE); - - if (defaultInstance == null) { - defaultInstance = getInstallerDefaultPlugin(); - } - - } - - if (defaultInstance == null) { - ServerInstance[] instances = getServerInstances(); - if (instances != null && instances.length > 0) { - defaultInstance = new ServerString(instances[0]); - } - } - - setDefaultInstance(defaultInstance); - return defaultInstance; - } - public interface PluginListener { public void serverAdded(Server name); @@ -586,16 +464,6 @@ initConfigNamesByType(); Set configNames = (Set) configNamesByType.get(type); return (configNames != null && configNames.contains(name)); - } - - public ServerInstance getInstanceOrDefault(String uri) { - ServerInstance instance = getServerInstance(uri); - if (instance == null) { - instance = getDefaultInstance().getServerInstance(); - } - if (instance != null) - return instance; - throw new RuntimeException(NbBundle.getMessage(ServerRegistry.class, "MSG_NoServerInstances", uri)); } /** Return profiler if any is registered in the IDE, null otherwise. */ Index: src/org/netbeans/modules/j2ee/deployment/impl/projects/DeploymentTargetImpl.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/projects/DeploymentTargetImpl.java,v retrieving revision 1.21.30.1.2.1 diff -u -r1.21.30.1.2.1 DeploymentTargetImpl.java --- src/org/netbeans/modules/j2ee/deployment/impl/projects/DeploymentTargetImpl.java 1 Jul 2006 05:16:17 -0000 1.21.30.1.2.1 +++ src/org/netbeans/modules/j2ee/deployment/impl/projects/DeploymentTargetImpl.java 1 Sep 2006 13:45:17 -0000 @@ -122,28 +122,10 @@ private TargetModule getTargetModule() { TargetModule[] mods = getTargetModules(); - if (mods == null || mods.length == 0) - return null; - - if (mods[0].delegate() != null) + if (mods != null && mods.length > 0 && mods[0].delegate() != null) { return mods[0]; - - // determine target server instance - ServerString defaultTarget = ServerRegistry.getInstance().getDefaultInstance(); - TargetModule execMod = null; - if ( defaultTarget != null ) { - for (int i=0; i