This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 83934
Collapse All | Expand All

(-)apichanges.xml (+24 lines)
Lines 86-91 Link Here
86
    <!-- ACTUAL CHANGES BEGIN HERE: -->
86
    <!-- ACTUAL CHANGES BEGIN HERE: -->
87
87
88
    <changes>
88
    <changes>
89
        <change id="removeDefaultServerAPI">
90
            <api name="j2eeserver"/>
91
            <summary>
92
                Default server API residues removed.
93
            </summary>
94
            <version major="1" minor="21"/>
95
            <date day="31" month="8" year="2006"/>
96
            <author login="sherold"/>
97
            <compatibility binary="incompatible" source="incompatible" semantic="incompatible"/>
98
            <description>
99
                <p>
100
                    In the past, before the J2EE support was added to NetBeans the default server
101
                    concept had been used. This concept was then abandoned since it did not work
102
                    anymore. The problem could occur for example if the default server was Tomcat
103
                    then the EJB project which was set to use the default server could not be
104
                    deployed to it, etc.
105
                </p>
106
            </description>
107
            <class package="org.netbeans.modules.j2ee.deployment.devmodules.api" name="Deployment"/>
108
            <class package="org.netbeans.modules.j2ee.deployment.devmodules.spi" name="InstanceListener"/>
109
            <class package="org.netbeans.modules.j2ee.deployment.devmodules.spi" name="J2eeModuleProvider"/>
110
            <class package="org.netbeans.modules.j2ee.deployment.plugins.api" name="InstanceProperties"/>
111
            <issue number="83934"/>
112
        </change>
89
        <change id="ensureResourceDefinedUpdate">
113
        <change id="ensureResourceDefinedUpdate">
90
            <api name="j2eeserver"/>
114
            <api name="j2eeserver"/>
91
            <summary>
115
            <summary>
(-)src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java (-19 / +51 lines)
Lines 80-86 Link Here
80
    private Map relativePaths = null;
80
    private Map relativePaths = null;
81
    private Map allRelativePaths = null;
81
    private Map allRelativePaths = null;
82
    
82
    
83
    private J2eeModuleProvider provider;
83
    private final J2eeModuleProvider provider;
84
    private final ModuleDeploymentSupport mds;
84
    private final ModuleDeploymentSupport mds;
85
    private DeploymentConfiguration deploymentConfiguration;
85
    private DeploymentConfiguration deploymentConfiguration;
86
    
86
    
Lines 91-101 Link Here
91
    public ConfigSupportImpl (J2eeModuleProvider provider) {
91
    public ConfigSupportImpl (J2eeModuleProvider provider) {
92
        this.provider = provider;
92
        this.provider = provider;
93
        mds = new ModuleDeploymentSupport(provider, true);
93
        mds = new ModuleDeploymentSupport(provider, true);
94
        instance = ServerRegistry.getInstance().getServerInstance(provider.getServerInstanceID());
94
        String serverInstanceId = provider.getServerInstanceID();
95
        server = instance != null 
95
        if (serverInstanceId != null) {
96
                ? instance.getServer() 
96
            instance = ServerRegistry.getInstance().getServerInstance(provider.getServerInstanceID());
97
                : ServerRegistry.getInstance().getServer(provider.getServerID());
97
            if (instance != null) {
98
        provider.addPropertyChangeListener(this);
98
                // project server instance exists
99
                server = instance.getServer();
100
            }
101
        }
102
        if (server == null) {
103
            // project server instance is not set or does not exist
104
            String serverID = provider.getServerID();
105
            if (serverID != null) {
106
                // project server exists
107
                server = ServerRegistry.getInstance().getServer(serverID);
108
            }
109
        }
110
        // the module has no server set, do not listen to changes
111
        if (server != null) {
112
            provider.addPropertyChangeListener(this);
113
        }
99
    }
114
    }
100
    
115
    
101
    /**
116
    /**
Lines 174-186 Link Here
174
    
189
    
175
    /** dispose all created deployment configurations */
190
    /** dispose all created deployment configurations */
176
    public void dispose() {
191
    public void dispose() {
177
        provider.removePropertyChangeListener(this);
192
        if (server != null) {
178
        if (server == null) {
193
            provider.removePropertyChangeListener(this);
179
            return;
194
            ConfigurationSupport serverConfig = server.getConfigurationSupport();
180
        }
195
            if (deploymentConfiguration != null && serverConfig != null) {
181
        ConfigurationSupport serverConfig = server.getConfigurationSupport();
196
                serverConfig.disposeConfiguration(deploymentConfiguration);
182
        if (deploymentConfiguration != null && serverConfig != null) {
197
            }
183
            serverConfig.disposeConfiguration(deploymentConfiguration);
184
        }
198
        }
185
        if (mds != null) {
199
        if (mds != null) {
186
            mds.cleanup();
200
            mds.cleanup();
Lines 253-258 Link Here
253
    }
267
    }
254
        
268
        
255
    public String[] getDeploymentConfigurationFileNames() {
269
    public String[] getDeploymentConfigurationFileNames() {
270
        if (server == null) {
271
            return new String[]{};
272
        }
256
        if (hasCustomSupport()) {
273
        if (hasCustomSupport()) {
257
            return (String[]) getRelativePaths().keySet().toArray(new String[relativePaths.size()]);
274
            return (String[]) getRelativePaths().keySet().toArray(new String[relativePaths.size()]);
258
        }
275
        }
Lines 267-272 Link Here
267
    }
284
    }
268
    
285
    
269
    public void setCMPMappingInfo(final OriginalCMPMapping[] mappings) {
286
    public void setCMPMappingInfo(final OriginalCMPMapping[] mappings) {
287
        if (server == null) {
288
            // the module has no target server
289
            return;
290
        }
270
        DeploymentConfiguration config = getDeploymentConfiguration();
291
        DeploymentConfiguration config = getDeploymentConfiguration();
271
        ConfigurationSupport serverConfig = server.getConfigurationSupport();
292
        ConfigurationSupport serverConfig = server.getConfigurationSupport();
272
        serverConfig.setMappingInfo(config, mappings);
293
        serverConfig.setMappingInfo(config, mappings);
Lines 279-284 Link Here
279
        if (ejbtype == null) {
300
        if (ejbtype == null) {
280
            throw new NullPointerException("EJB type cannot be null"); // NOI18N
301
            throw new NullPointerException("EJB type cannot be null"); // NOI18N
281
        }
302
        }
303
        if (server == null) {
304
            // the module has no target server
305
            return;
306
        }
282
        DDBean ejbBean = findDDBean(ejbname, ejbtype);
307
        DDBean ejbBean = findDDBean(ejbname, ejbtype);
283
        if (ejbBean != null) {
308
        if (ejbBean != null) {
284
            DeploymentConfiguration config = getDeploymentConfiguration();
309
            DeploymentConfiguration config = getDeploymentConfiguration();
Lines 297-302 Link Here
297
        if (jndiName == null) {
322
        if (jndiName == null) {
298
            throw new NullPointerException("JNDI name cannot be null"); // NOI18N
323
            throw new NullPointerException("JNDI name cannot be null"); // NOI18N
299
        }
324
        }
325
        if (server == null) {
326
            // the module has no target server
327
            return;
328
        }
300
        DDBean ejbBean = findDDBean(ejbname, ejbtype);
329
        DDBean ejbBean = findDDBean(ejbname, ejbtype);
301
        if (ejbBean != null) {
330
        if (ejbBean != null) {
302
            DeploymentConfiguration config = getDeploymentConfiguration();
331
            DeploymentConfiguration config = getDeploymentConfiguration();
Lines 357-362 Link Here
357
    }
386
    }
358
387
359
    public boolean isDatasourceCreationSupported() {
388
    public boolean isDatasourceCreationSupported() {
389
        if (server == null) {
390
            // the module has no target server
391
            return false;
392
        }
360
        ConfigurationSupport configSupport = server.getConfigurationSupport();
393
        ConfigurationSupport configSupport = server.getConfigurationSupport();
361
        
394
        
362
        if (configSupport == null)
395
        if (configSupport == null)
Lines 366-376 Link Here
366
    }
399
    }
367
    
400
    
368
    public Datasource createDatasource(String jndiName, String  url, String username, String password, String driver) 
401
    public Datasource createDatasource(String jndiName, String  url, String username, String password, String driver) 
369
    throws OperationUnsupportedException, DatasourceAlreadyExistsException
402
    throws OperationUnsupportedException, DatasourceAlreadyExistsException {
370
    {
371
372
        Datasource ds = null;
403
        Datasource ds = null;
373
        
374
        if (server != null) {
404
        if (server != null) {
375
            ConfigurationSupport configSupport = server.getConfigurationSupport();
405
            ConfigurationSupport configSupport = server.getConfigurationSupport();
376
            if (configSupport != null) {
406
            if (configSupport != null) {
Lines 384-390 Link Here
384
                }
414
                }
385
            }
415
            }
386
        }
416
        }
387
        
388
        return ds;
417
        return ds;
389
    }    
418
    }    
390
    
419
    
Lines 399-406 Link Here
399
            try {
428
            try {
400
                if (instance != null) {
429
                if (instance != null) {
401
                    deploymentConfiguration = instance.getDeploymentManagerForConfiguration().createConfiguration(dobj);
430
                    deploymentConfiguration = instance.getDeploymentManagerForConfiguration().createConfiguration(dobj);
402
                } else {
431
                } else if (server != null) {
403
                    deploymentConfiguration = server.getDisconnectedDeploymentManager().createConfiguration(dobj);
432
                    deploymentConfiguration = server.getDisconnectedDeploymentManager().createConfiguration(dobj);
433
                } else {
434
                    // the module has no target server, there is nothing else to return
435
                    return null;
404
                }
436
                }
405
                ConfigurationSupport serverConfig = server.getConfigurationSupport();
437
                ConfigurationSupport serverConfig = server.getConfigurationSupport();
406
                File[] files = getDeploymentConfigurationFiles(getProvider(), server);
438
                File[] files = getDeploymentConfigurationFiles(getProvider(), server);
(-)src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java (-11 lines)
Lines 244-260 Link Here
244
        return null;
244
        return null;
245
    }
245
    }
246
    
246
    
247
    public String getDefaultServerInstanceID () {
248
        ServerString defInst = ServerRegistry.getInstance ().getDefaultInstance ();
249
        if (defInst != null) {
250
            ServerInstance si = defInst.getServerInstance();
251
            if (si != null) {
252
                return si.getUrl ();
253
            }
254
        }
255
        return null;
256
    }
257
    
258
    public String [] getInstancesOfServer (String id) {
247
    public String [] getInstancesOfServer (String id) {
259
        if (id != null) {
248
        if (id != null) {
260
            Server server = ServerRegistry.getInstance().getServer(id);
249
            Server server = ServerRegistry.getInstance().getServer(id);
(-)src/org/netbeans/modules/j2ee/deployment/devmodules/spi/InstanceListener.java (-8 lines)
Lines 31-44 Link Here
31
public interface InstanceListener extends EventListener {
31
public interface InstanceListener extends EventListener {
32
        
32
        
33
        /**
33
        /**
34
         * Default server instance has been changed.
35
         *
36
         * @param oldServerInstanceID id of the old default server instance.
37
         * @param newServerInstanceID id of the new default server instance.
38
         */
39
        public void changeDefaultInstance(String oldServerInstanceID, String newServerInstanceID);
40
        
41
        /**
42
         * Server instance has been added.
34
         * Server instance has been added.
43
         *
35
         *
44
         * @param serverInstanceID id of the server instance that has been added.
36
         * @param serverInstanceID id of the server instance that has been added.
(-)src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java (-67 / +26 lines)
Lines 62-68 Link Here
62
 */
62
 */
63
public abstract class J2eeModuleProvider {
63
public abstract class J2eeModuleProvider {
64
    
64
    
65
    private InstanceListener il;
66
    private ConfigSupportImpl configSupportImpl;
65
    private ConfigSupportImpl configSupportImpl;
67
    List listeners = new ArrayList();
66
    List listeners = new ArrayList();
68
    private ConfigFilesListener configFilesListener = null;
67
    private ConfigFilesListener configFilesListener = null;
Lines 77-86 Link Here
77
    private PropertyChangeSupport supp = new PropertyChangeSupport(this);
76
    private PropertyChangeSupport supp = new PropertyChangeSupport(this);
78
    
77
    
79
    public J2eeModuleProvider () {
78
    public J2eeModuleProvider () {
80
        il = new IL ();
81
        ServerRegistry.getInstance ().addInstanceListener (
82
            (InstanceListener) WeakListeners.create(
83
                InstanceListener.class, il, ServerRegistry.getInstance ()));
84
    }
79
    }
85
    
80
    
86
    public abstract J2eeModule getJ2eeModule ();
81
    public abstract J2eeModule getJ2eeModule ();
Lines 432-444 Link Here
432
        return new DefaultSourceMap(this);
427
        return new DefaultSourceMap(this);
433
    }
428
    }
434
    
429
    
435
    /** If the module wants to specify a target server instance for deployment 
436
     * it needs to override this method to return false. 
437
     */
438
    public boolean useDefaultServer () {
439
        return true;
440
    }
441
    
442
    /**
430
    /**
443
     * Set ID of the server instance that will be used for deployment.
431
     * Set ID of the server instance that will be used for deployment.
444
     * 
432
     * 
Lines 447-474 Link Here
447
     */
435
     */
448
    public abstract void setServerInstanceID(String severInstanceID);
436
    public abstract void setServerInstanceID(String severInstanceID);
449
    
437
    
450
    /** Id of server isntance for deployment. The default implementation returns
438
    /** 
451
     * the default server instance selected in Server Registry. 
439
     * Id of server instance for deployment or null if the module has no server
452
     * The return value may not be null.
440
     * instance set.
453
     * If modules override this method they also need to override {@link useDefaultServer}.
441
     *
442
     * @return Id of server instance for deployment or null if the module has no server
443
     *         instance set.
454
     */
444
     */
455
    public String getServerInstanceID () {
445
    public abstract String getServerInstanceID();
456
        return ServerRegistry.getInstance ().getDefaultInstance ().getUrl ();
457
    }
458
    
446
    
459
    /**
447
    /**
460
     * Return InstanceProperties of the server instance
448
     * Returns InstanceProperties of the server instance or null if the module has
461
     **/
449
     * no server instance set or the given server instance does not exist.
450
     *
451
     * @return InstanceProperties of the server instance or null if the module has
452
     *         no server instance set or the given server instance does not exist.
453
     */
462
    public InstanceProperties getInstanceProperties(){
454
    public InstanceProperties getInstanceProperties(){
463
        return InstanceProperties.getInstanceProperties(getServerInstanceID());
455
        String serverInstanceID = getServerInstanceID();
456
        if (serverInstanceID == null) {
457
            return null;
458
        }
459
        return InstanceProperties.getInstanceProperties(serverInstanceID);
464
    }
460
    }
465
461
466
    /** This method is used to determin type of target server.
462
    /** 
467
     * The return value must correspond to value returned from {@link getServerInstanceID}.
463
     * This method is used to determin type of target server. The return value 
464
     * must correspond to the value returned from {@link getServerInstanceID}.
465
     *
466
     * @return the target server type or null if the module has no target server
467
     *         type set.
468
     */
468
     */
469
    public String getServerID () {
469
    public abstract String getServerID();
470
        return ServerRegistry.getInstance ().getDefaultInstance ().getServer ().getShortName ();
471
    }
472
    
470
    
473
    /**
471
    /**
474
     * Return name to be used in deployment of the module.
472
     * Return name to be used in deployment of the module.
Lines 602-647 Link Here
602
            return;
600
            return;
603
        configFilesListener = new ConfigFilesListener(this, listeners);
601
        configFilesListener = new ConfigFilesListener(this, listeners);
604
    }
602
    }
605
    
603
   
606
    private final class IL implements InstanceListener {
607
        
608
        public void changeDefaultInstance (String oldInst, String newInst) {
609
            ServerInstance oldServerInstance = ServerRegistry.getInstance().getServerInstance(oldInst);
610
            ServerInstance newServerInstance = ServerRegistry.getInstance().getServerInstance(newInst);
611
            ServerString oldInstance = oldServerInstance != null 
612
                                            ? new ServerString(oldServerInstance) 
613
                                            : null;
614
            ServerString newInstance = newServerInstance != null 
615
                                            ? new ServerString(newServerInstance) 
616
                                            : null;
617
            if (useDefaultServer () && newInstance != null 
618
                    && (oldInstance == null || !oldInstance.getPlugin().equals(newInstance.getPlugin()))) {
619
                if (J2eeModule.WAR.equals(getJ2eeModule().getModuleType())) {
620
                    String oldCtxPath = getConfigSupportImpl().getWebContextRoot();
621
                    oldCtxPath = "/"+J2eeModuleProvider.this.getDeploymentName(); //NOI18N
622
                    configSupportImpl.dispose();
623
                    J2eeModuleProvider.this.configSupportImpl = null;
624
                    getConfigSupportImpl().ensureConfigurationReady();
625
                    String ctx = getConfigSupportImpl().getWebContextRoot ();
626
                    if (ctx == null || ctx.equals ("")) { //NOI18N
627
                        getConfigSupportImpl().setWebContextRoot(oldCtxPath);
628
                    }
629
                } else {
630
                    configSupportImpl.dispose();
631
                    J2eeModuleProvider.this.configSupportImpl = null;
632
                    getConfigSupportImpl().ensureConfigurationReady();
633
                }
634
            }
635
        }
636
        
637
        public void instanceAdded (String instance) {
638
        }
639
        
640
        public void instanceRemoved (String instance) {
641
        }
642
        
643
    }
644
    
645
    private ConfigSupportImpl getConfigSupportImpl() {
604
    private ConfigSupportImpl getConfigSupportImpl() {
646
        return (ConfigSupportImpl) getConfigSupport();
605
        return (ConfigSupportImpl) getConfigSupport();
647
    }
606
    }
(-)src/org/netbeans/modules/j2ee/deployment/impl/InstancePropertiesImpl.java (-22 lines)
Lines 109-136 Link Here
109
        return inst.getDeploymentManager();
109
        return inst.getDeploymentManager();
110
    }
110
    }
111
    
111
    
112
    public javax.enterprise.deploy.spi.Target getDefaultTarget() {
113
        ServerRegistry registry = ServerRegistry.getInstance();
114
        ServerString ss = registry.getDefaultInstance();
115
        javax.enterprise.deploy.spi.Target[] targets = ss.toTargets();
116
        if (targets != null && targets.length > 0)
117
            return targets[0];
118
        return null;
119
    }
120
    
121
    public void setAsDefaultServer(String targetName) {
122
        ServerRegistry registry = ServerRegistry.getInstance();
123
        ServerInstance inst = registry.getServerInstance(url);
124
        ServerString server = new ServerString(inst, targetName);
125
        registry.setDefaultInstance(server);
126
    }
127
    
128
    public boolean isDefaultInstance() {
129
        ServerRegistry registry = ServerRegistry.getInstance();
130
        ServerString ss = registry.getDefaultInstance();
131
        return ss.getUrl().equals(url);
132
    }
133
    
134
    public void refreshServerInstance() {
112
    public void refreshServerInstance() {
135
        ServerRegistry registry = ServerRegistry.getInstance();
113
        ServerRegistry registry = ServerRegistry.getInstance();
136
        ServerInstance inst = registry.getServerInstance(url);
114
        ServerInstance inst = registry.getServerInstance(url);
(-)src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java (-4 lines)
Lines 1512-1521 Link Here
1512
        }
1512
        }
1513
    }
1513
    }
1514
    
1514
    
1515
    public boolean isDefault() {
1516
        return url.equals(ServerRegistry.getInstance().getDefaultInstance().getUrl());
1517
    }
1518
    
1519
    public String toString() {
1515
    public String toString() {
1520
        return getDisplayName();
1516
        return getDisplayName();
1521
    }
1517
    }
(-)src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java (-132 lines)
Lines 34-41 Link Here
34
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
34
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
35
import org.openide.modules.InstalledFileLocator;
35
import org.openide.modules.InstalledFileLocator;
36
36
37
//import java.util.logging.*;
38
39
public final class ServerRegistry implements java.io.Serializable {
37
public final class ServerRegistry implements java.io.Serializable {
40
    
38
    
41
    public static final String DIR_INSTALLED_SERVERS = "/J2EE/InstalledServers"; //NOI18N
39
    public static final String DIR_INSTALLED_SERVERS = "/J2EE/InstalledServers"; //NOI18N
Lines 43-50 Link Here
43
    public static final String URL_ATTR = InstanceProperties.URL_ATTR;
41
    public static final String URL_ATTR = InstanceProperties.URL_ATTR;
44
    public static final String USERNAME_ATTR = InstanceProperties.USERNAME_ATTR;
42
    public static final String USERNAME_ATTR = InstanceProperties.USERNAME_ATTR;
45
    public static final String PASSWORD_ATTR = InstanceProperties.PASSWORD_ATTR;
43
    public static final String PASSWORD_ATTR = InstanceProperties.PASSWORD_ATTR;
46
    public static final String FILE_DEFAULT_INSTANCE = "DefaultInstance.settings"; //NOI18N
47
    public static final String J2EE_DEFAULT_SERVER = "j2ee.defaultServer"; //NOI18N
48
    public static final String TARGETNAME_ATTR = "targetName"; //NOI18N
44
    public static final String TARGETNAME_ATTR = "targetName"; //NOI18N
49
    public static final String SERVER_NAME = "serverName"; //NOI18N
45
    public static final String SERVER_NAME = "serverName"; //NOI18N
50
    private static ServerRegistry instance = null;
46
    private static ServerRegistry instance = null;
Lines 224-243 Link Here
224
        if (url == null)
220
        if (url == null)
225
            return;
221
            return;
226
        
222
        
227
        // Make sure defaultInstance cache is reset
228
        ServerString def = getDefaultInstance();
229
        if (url.equals(def.getUrl())) {
230
            defaultInstance = null;
231
        }
232
        
233
        ServerInstance instance = (ServerInstance) instancesMap().remove(url);
223
        ServerInstance instance = (ServerInstance) instancesMap().remove(url);
234
        if (instance != null) {
224
        if (instance != null) {
235
            fireInstanceListeners(url, false);
225
            fireInstanceListeners(url, false);
236
            removeInstanceFromFile(url);
226
            removeInstanceFromFile(url);
237
        }
227
        }
238
        ServerString newinst = getDefaultInstance(false);
239
        fireDefaultInstance(def != null ? def.getUrl() : null, 
240
                newinst != null ? newinst.getUrl() : null);
241
    }
228
    }
242
    
229
    
243
    public ServerInstance[] getServerInstances() {
230
    public ServerInstance[] getServerInstances() {
Lines 430-516 Link Here
430
        }
417
        }
431
    }
418
    }
432
    
419
    
433
    private void fireDefaultInstance(String oldInstance, String newInstance) {
434
        InstanceListener[] instListeners = getInstanceListeners();
435
        for(int i = 0; i < instListeners.length; i++) {
436
            instListeners[i].changeDefaultInstance(oldInstance, newInstance);
437
        }
438
    }
439
    
440
    public void setDefaultInstance(ServerString instance) {
441
        if (instance != null && instance.equals(defaultInstance)) {
442
            return;
443
        }
444
        
445
        if (instance == null) {
446
            removeDefaultInstanceFile();
447
            ServerString oldValue = defaultInstance;
448
            defaultInstance = null;
449
            fireDefaultInstance(oldValue != null ? oldValue.getUrl() : null, null);
450
        } else {
451
            if (ServerStringConverter.writeServerInstance(instance, DIR_INSTALLED_SERVERS, FILE_DEFAULT_INSTANCE)) {
452
                ServerString oldValue = defaultInstance;
453
                defaultInstance = instance;
454
                fireDefaultInstance(oldValue != null ? oldValue.getUrl() : null,
455
                        instance != null ? instance.getUrl() : null);
456
            }
457
        }
458
    }
459
460
    static private void removeDefaultInstanceFile() {
461
        FileLock lock = null;
462
        Writer writer = null;
463
        try {
464
            String pathName = DIR_INSTALLED_SERVERS + "/" + FILE_DEFAULT_INSTANCE; // NOI18N
465
            FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(pathName);
466
            if (fo != null)
467
                fo.delete();
468
        } catch(Exception ioe) {
469
            org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.WARNING, ioe);
470
        }
471
    }
472
473
    private ServerString getInstallerDefaultPlugin() {
474
        File propFile = InstalledFileLocator.getDefault ().locate ("config/install.properties", null, false); // NOI18N
475
        Properties installProp = readProperties(propFile); //NOI18N
476
        
477
        String j2eeDefaultServerFileName = installProp.getProperty(J2EE_DEFAULT_SERVER);
478
        if (j2eeDefaultServerFileName == null)
479
            return null;
480
        
481
        File serverFile = InstalledFileLocator.getDefault ().locate (j2eeDefaultServerFileName, null, false);
482
        Properties defaultServerProp = readProperties(serverFile);
483
        String serverName = defaultServerProp.getProperty(SERVER_NAME);
484
        String url = defaultServerProp.getProperty(URL_ATTR);
485
        String user = defaultServerProp.getProperty(USERNAME_ATTR);
486
        String password = defaultServerProp.getProperty(PASSWORD_ATTR);
487
        String targetName = defaultServerProp.getProperty(TARGETNAME_ATTR);
488
        
489
        try {
490
            if (url != null) {
491
                InstanceProperties instProp = InstanceProperties.getInstanceProperties(url);
492
                if (instProp == null)
493
                    instProp = InstanceProperties.createInstanceProperties(url, user, password);
494
                instProp.setProperties(defaultServerProp);
495
                
496
                ServerInstance inst = getServerInstance(url);
497
                if (inst != null)
498
                    return new ServerString(inst, targetName);
499
                
500
            } else if (serverName != null) {
501
                Server server = getServer(serverName);
502
                if (server != null) {
503
                    ServerInstance[] instances = server.getInstances();
504
                    if (instances.length > 1)
505
                        return new ServerString(instances[0]);
506
                }
507
            }
508
        } catch (Exception e) {
509
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
510
        }
511
        return null;
512
    }
513
    
514
    static private Properties readProperties(File propFile) {
420
    static private Properties readProperties(File propFile) {
515
        Properties prop = new Properties();
421
        Properties prop = new Properties();
516
        try {
422
        try {
Lines 522-555 Link Here
522
        return prop;
428
        return prop;
523
    }
429
    }
524
    
430
    
525
    public ServerString getDefaultInstance() {
526
        return getDefaultInstance(true);
527
    }
528
    
529
    public ServerString getDefaultInstance(boolean readFromFile) {
530
        if (defaultInstance != null)
531
            return defaultInstance;
532
        
533
        if (readFromFile) {
534
            defaultInstance = ServerStringConverter.readServerInstance(DIR_INSTALLED_SERVERS, FILE_DEFAULT_INSTANCE);
535
            
536
            if (defaultInstance == null) {
537
                defaultInstance = getInstallerDefaultPlugin();
538
            }
539
            
540
        }
541
        
542
        if (defaultInstance == null) {
543
            ServerInstance[] instances = getServerInstances();
544
            if (instances != null && instances.length > 0) {
545
                defaultInstance = new ServerString(instances[0]);
546
            }
547
        }
548
        
549
        setDefaultInstance(defaultInstance);
550
        return defaultInstance;
551
    }
552
    
553
    public interface PluginListener {
431
    public interface PluginListener {
554
        
432
        
555
        public void serverAdded(Server name);
433
        public void serverAdded(Server name);
Lines 586-601 Link Here
586
	initConfigNamesByType();
464
	initConfigNamesByType();
587
	Set configNames = (Set) configNamesByType.get(type);
465
	Set configNames = (Set) configNamesByType.get(type);
588
	return (configNames != null && configNames.contains(name));
466
	return (configNames != null && configNames.contains(name));
589
    }
590
    
591
    public ServerInstance getInstanceOrDefault(String uri) {
592
        ServerInstance instance = getServerInstance(uri);
593
        if (instance == null) {
594
            instance = getDefaultInstance().getServerInstance();
595
        }
596
        if (instance != null)
597
            return instance;
598
        throw new RuntimeException(NbBundle.getMessage(ServerRegistry.class, "MSG_NoServerInstances", uri));
599
    }
467
    }
600
    
468
    
601
    /** Return profiler if any is registered in the IDE, null otherwise. */
469
    /** Return profiler if any is registered in the IDE, null otherwise. */
(-)src/org/netbeans/modules/j2ee/deployment/impl/projects/DeploymentTargetImpl.java (-20 / +2 lines)
Lines 122-149 Link Here
122
    
122
    
123
    private TargetModule getTargetModule() {
123
    private TargetModule getTargetModule() {
124
        TargetModule[] mods = getTargetModules();
124
        TargetModule[] mods = getTargetModules();
125
        if (mods == null || mods.length == 0)
125
        if (mods != null && mods.length > 0 && mods[0].delegate() != null) {
126
            return null;
127
        
128
        if (mods[0].delegate() != null)
129
            return mods[0];
126
            return mods[0];
130
        
131
        // determine target server instance
132
        ServerString defaultTarget = ServerRegistry.getInstance().getDefaultInstance();
133
        TargetModule execMod = null;
134
        if ( defaultTarget != null ) {
135
            for (int i=0; i<mods.length; i++) {
136
                if (mods[i].getInstanceUrl().equals(defaultTarget.getUrl()) &&
137
                    mods[i].getTargetName().equals(defaultTarget.getTargets(true)[0])) {
138
                    execMod = mods[i];
139
                    break;
140
                }
141
            }
142
        }
127
        }
143
128
        return null;
144
        if (execMod == null) execMod = mods[0];
145
        execMod.initDelegate((ModuleType)getModule().getModuleType());
146
        return execMod;
147
    }
129
    }
148
    
130
    
149
    /**
131
    /**
(-)src/org/netbeans/modules/j2ee/deployment/plugins/api/InstanceProperties.java (-24 lines)
Lines 150-162 Link Here
150
    public static String[] getInstanceList() {
150
    public static String[] getInstanceList() {
151
        return ServerRegistry.getInstance().getInstanceURLs();
151
        return ServerRegistry.getInstance().getInstanceURLs();
152
    }
152
    }
153
154
    /**
155
     * Return default instance properties.
156
     */
157
    public static InstanceProperties getDefaultInstance() {
158
        return new InstancePropertiesImpl(ServerRegistry.getInstance().getDefaultInstance().getServerInstance());
159
    }
160
    
153
    
161
    /**
154
    /**
162
     * Set instance properties.
155
     * Set instance properties.
Lines 189-214 Link Here
189
    public abstract java.util.Enumeration propertyNames() throws IllegalStateException;
182
    public abstract java.util.Enumeration propertyNames() throws IllegalStateException;
190
    
183
    
191
    /**
184
    /**
192
     * Is the target server the default J2EE server for deployment?
193
     * @return true if the target server or admin server is the default.
194
     */
195
    public abstract boolean isDefaultInstance();
196
    
197
    /**
198
     * Return DeploymentManager associated with this instance.
185
     * Return DeploymentManager associated with this instance.
199
     */
186
     */
200
    public abstract DeploymentManager getDeploymentManager();
187
    public abstract DeploymentManager getDeploymentManager();
201
    
202
    /**
203
     * Return default Target object for the target server from this instance, if any.
204
     */
205
    public abstract Target getDefaultTarget();
206
    
207
    /**
208
     * Set the target server the default server.
209
     * @param targetName name of the target server; null if admin server is also single target.
210
     */
211
    public abstract void setAsDefaultServer(String targetName);
212
    
188
    
213
    /**
189
    /**
214
     * Ask the server instance to reset cached deployment manager, J2EE
190
     * Ask the server instance to reset cached deployment manager, J2EE

Return to bug 83934