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 135447
Collapse All | Expand All

(-)netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Bundle.properties (+4 lines)
Lines 43-54 Link Here
43
# 0 - version
43
# 0 - version
44
LBL_Mongrel=Mongrel {0}
44
LBL_Mongrel=Mongrel {0}
45
# 0 - version
45
# 0 - version
46
LBL_Passenger=Passenger {0}
47
# 0 - version
46
LBL_GlassFish=GlassFish Gem {0}
48
LBL_GlassFish=GlassFish Gem {0}
47
# 0 - server label, 1 - platform label
49
# 0 - server label, 1 - platform label
48
LBL_ServerNodeName={0} ({1})
50
LBL_ServerNodeName={0} ({1})
49
# 0..project 1..port
51
# 0..project 1..port
50
ServerStartup=Server Startup
52
ServerStartup=Server Startup
51
NoServerFound=Could not connect to the web server - cannot show {0}
53
NoServerFound=Could not connect to the web server - cannot show {0}
54
NoApacheFound=Apache server is stopped, please start it manually\n\
55
 Common way to start it is to run: sudo /etc/init.d/apache2 start
52
Conflict=The web server failed to start because the port number {0} is already in use,\n\
56
Conflict=The web server failed to start because the port number {0} is already in use,\n\
53
 and nearby ports could not be used. Edit the project properties and choose\n\
57
 and nearby ports could not be used. Edit the project properties and choose\n\
54
 an available port, or shut down the other service using the port.
58
 an available port, or shut down the other service using the port.
(-)netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Passenger.java (+217 lines)
Line 0 Link Here
1
package org.netbeans.modules.ruby.railsprojects.server;
2
3
import java.io.File;
4
import java.util.ArrayList;
5
import java.util.Collections;
6
import java.util.List;
7
import java.util.concurrent.Future;
8
import javax.swing.JComponent;
9
import javax.swing.event.ChangeListener;
10
import org.netbeans.api.ruby.platform.RubyPlatform;
11
import org.netbeans.modules.ruby.railsprojects.server.nodes.RubyServerNode;
12
import org.netbeans.modules.ruby.railsprojects.server.spi.RubyInstance.OperationState;
13
import org.netbeans.modules.ruby.railsprojects.server.spi.RubyInstance.ServerState;
14
import org.netbeans.spi.server.ServerInstanceImplementation;
15
import org.openide.nodes.Node;
16
import org.openide.util.ChangeSupport;
17
import org.openide.util.NbBundle;
18
import org.openide.util.Parameters;
19
20
/**
21
 * This class represents passenger (gem) installation
22
 * 
23
 * @author Michal Papis
24
 */
25
class Passenger  implements RubyServer, ServerInstanceImplementation {
26
27
    static final String GEM_NAME = "passenger";
28
    static final String SERVER_URI = "PASSENGER";
29
    private final RubyPlatform platform;
30
    private final String version;
31
    private final List<RailsApplication> applications = new ArrayList<RailsApplication>();
32
    private final ChangeSupport changeSupport = new ChangeSupport(this);
33
    private Node node;
34
35
    Passenger(RubyPlatform platform, String version) {
36
        Parameters.notNull("platform", platform); //NOI18N
37
        this.platform = platform;
38
        this.version = version;
39
    }
40
41
    private Node getNode() {
42
        if (this.node == null) {
43
            this.node = new RubyServerNode(this);
44
        }
45
        return node;
46
    }
47
48
    public String getNodeName() {
49
        return NbBundle.getMessage(Passenger.class, "LBL_ServerNodeName", getDisplayName(), platform.getLabel());
50
    }
51
52
    public String getLocation() {
53
        return null;
54
    }
55
56
    public String getStartupParam() {
57
        return "passenger";
58
    }
59
60
    public String getScriptPrefix() {
61
        return null;
62
    }
63
64
    public String getServerPath() {
65
        return null;
66
    }
67
68
    public boolean isStartupMsg(String arg0) {
69
        //Always is started
70
        return true;
71
    }
72
73
    public List<RailsApplication> getApplications() {
74
        return Collections.unmodifiableList(applications);
75
    }
76
77
    public boolean addApplication(RailsApplication application) {
78
        boolean result = applications.add(application);
79
        changeSupport.fireChange();
80
        return result;
81
    }
82
83
    /**
84
     * Will remove application, instead of http port, the port will carry instance number
85
     * @param port
86
     * @return
87
     */
88
    public boolean removeApplication(int port) {
89
        boolean result = false;
90
        for (RailsApplication app : applications) {
91
            if (app.getPort() == port) {
92
                result = applications.remove(app);
93
                changeSupport.fireChange();
94
                break;
95
            }
96
        }
97
98
        return result;
99
    }
100
101
    public void addChangeListener(ChangeListener listener) {
102
        changeSupport.addChangeListener(listener);
103
    }
104
105
    public void removeChangeListener(ChangeListener listener) {
106
        changeSupport.removeChangeListener(listener);
107
    }
108
109
    /**
110
     *
111
     * @return upercase server name
112
     * @see ServerResolver.getExplicitlySpecifiedServer(RailsProject project)
113
     * @see ServerRegistry.getServer(String serverId, RubyPlatform platform)
114
     */
115
    public String getServerUri() {
116
        return "PASSENGER";
117
    }
118
119
    public String getDisplayName() {
120
        return NbBundle.getMessage(Passenger.class, "LBL_Passenger",version);
121
    }
122
123
    /**
124
     * Passenger is meant to be always running, but we could check port if it is listening for connections
125
     * @return ServerState.RUNNING
126
     * @see RailsServerManager.ensureRunning is currently doing this job
127
     */
128
    public ServerState getServerState() {
129
        return ServerState.RUNNING;
130
    }
131
132
    public Future<OperationState> startServer(RubyPlatform arg0) {
133
        throw new UnsupportedOperationException("Not supported yet.");
134
    }
135
136
    public Future<OperationState> stopServer() {
137
        throw new UnsupportedOperationException("Not supported yet.");
138
    }
139
140
    public Future<OperationState> deploy(String arg0, File arg1) {
141
        throw new UnsupportedOperationException("Not supported yet.");
142
    }
143
144
    public Future<OperationState> stop(String arg0) {
145
        throw new UnsupportedOperationException("Not supported yet.");
146
    }
147
148
    public Future<OperationState> runApplication(RubyPlatform arg0, String arg1, File arg2) {
149
        throw new UnsupportedOperationException("Not supported yet.");
150
    }
151
152
    public boolean isPlatformSupported(RubyPlatform platform) {
153
        return this.platform.equals(platform);
154
    }
155
156
    public String getContextRoot(String applicationName) {
157
        return applicationName;
158
    }
159
160
    public int getRailsPort() {
161
        return 80;
162
    }
163
164
    public String getServerCommand(RubyPlatform arg0, String arg1, File arg2, int arg3, boolean arg4) {
165
        throw new UnsupportedOperationException("Not supported yet.");
166
    }
167
168
    public String getServerDisplayName() {
169
        return getNodeName();
170
    }
171
172
    public Node getFullNode() {
173
        return getNode();
174
    }
175
176
    public Node getBasicNode() {
177
        return getNode();
178
    }
179
180
    public JComponent getCustomizer() {
181
        return null;
182
    }
183
184
    public void remove() {
185
        throw new UnsupportedOperationException("Not supported yet.");
186
    }
187
188
    public boolean isRemovable() {
189
        return false;
190
    }
191
192
    @Override
193
    public boolean equals(Object obj) {
194
        if (obj == null) {
195
            return false;
196
        }
197
        if (getClass() != obj.getClass()) {
198
            return false;
199
        }
200
        final Passenger other = (Passenger) obj;
201
        if (this.platform != other.platform && (this.platform == null || !this.platform.equals(other.platform))) {
202
            return false;
203
        }
204
        if (this.version != other.version && (this.version == null || !this.version.equals(other.version))) {
205
            return false;
206
        }
207
        return true;
208
    }
209
210
    @Override
211
    public int hashCode() {
212
        int hash = 3;
213
        hash = 55 * hash + (this.platform != null ? this.platform.hashCode() : 0);
214
        hash = 55 * hash + (this.version != null ? this.version.hashCode() : 0);
215
        return hash;
216
    }
217
}
(-)netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/RailsServerManager.java (-2 / +33 lines)
Lines 118-124 Link Here
118
 * @todo Normalize & merge RubyServer and RubyInstance interfaces and their
118
 * @todo Normalize & merge RubyServer and RubyInstance interfaces and their
119
 *   various implementations (V3, WEBrick, Mongrel).
119
 *   various implementations (V3, WEBrick, Mongrel).
120
 * 
120
 * 
121
 * @author Tor Norbye, Pavel Buzek, Erno Mononen, Peter Williams
121
 * @author Tor Norbye, Pavel Buzek, Erno Mononen, Peter Williams, Michal Papis
122
 */
122
 */
123
public final class RailsServerManager {
123
public final class RailsServerManager {
124
     /**
124
     /**
Lines 278-283 Link Here
278
            }
278
            }
279
        }
279
        }
280
280
281
        ensurePortAvailable();
282
        //mpapis: detect passanger ... not preaty way
283
        if (port != originalPort && instance.getServerUri().equals(Passenger.SERVER_URI)) {
284
            synchronized (RailsServerManager.this) {
285
                //TODO: why we have two different enums for the same thing - server state
286
                switch (instance.getServerState()) {
287
                    case RUNNING:
288
                        status = ServerStatus.RUNNING;
289
                        break;
290
                    case STARTING:
291
                    case STOPPED:
292
                    case STOPPING:
293
                        status = ServerStatus.STARTING;
294
                        break;
295
                }
296
                if (status == ServerStatus.RUNNING) {
297
                    return true;
298
                } else {
299
                    return false;
300
                }
301
            }
302
        }
303
281
        // check whether the user has modified script/server to use another server
304
        // check whether the user has modified script/server to use another server
282
        RubyInstance explicitlySpecified = ServerResolver.getExplicitlySpecifiedServer(project);
305
        RubyInstance explicitlySpecified = ServerResolver.getExplicitlySpecifiedServer(project);
283
        if (explicitlySpecified instanceof RubyServer) {
306
        if (explicitlySpecified instanceof RubyServer) {
Lines 287-293 Link Here
287
            server = (RubyServer) instance;
310
            server = (RubyServer) instance;
288
        }
311
        }
289
312
290
        ensurePortAvailable();
313
//mpapis: moved few lines up before we detect explicitly specified servers
314
//        ensurePortAvailable();
291
        String displayName = getServerTabName(server, projectName, port);
315
        String displayName = getServerTabName(server, projectName, port);
292
        String serverPath = server.getServerPath();
316
        String serverPath = server.getServerPath();
293
        ExecutionDescriptor desc = new ExecutionDescriptor(platform, displayName, dir, serverPath);
317
        ExecutionDescriptor desc = new ExecutionDescriptor(platform, displayName, dir, serverPath);
Lines 432-437 Link Here
432
        if (ensureRunning()) {
456
        if (ensureRunning()) {
433
            RailsServerManager.showURL(getContextRoot(), relativeUrl, port, clientDebug, project);
457
            RailsServerManager.showURL(getContextRoot(), relativeUrl, port, clientDebug, project);
434
        } else {
458
        } else {
459
            //TODO: not a preaty way, but if apache is stoped it will not start by itself
460
            if (instance.getServerUri().equals(Passenger.SERVER_URI)) {
461
                String msg = NbBundle.getMessage(RailsServerManager.class, "NoApacheFound");
462
                LOGGER.fine(msg);
463
                StatusDisplayer.getDefault().setStatusText(msg);
464
            } else {
435
            String displayName = NbBundle.getMessage(RailsServerManager.class, "ServerStartup");
465
            String displayName = NbBundle.getMessage(RailsServerManager.class, "ServerStartup");
436
            final ProgressHandle handle =
466
            final ProgressHandle handle =
437
                ProgressHandleFactory.createHandle(displayName,new Cancellable() {
467
                ProgressHandleFactory.createHandle(displayName,new Cancellable() {
Lines 501-506 Link Here
501
            });
531
            });
502
        }
532
        }
503
    }
533
    }
534
    }
504
535
505
    /** Return true if there is an HTTP response from the port on localhost.
536
    /** Return true if there is an HTTP response from the port on localhost.
506
     * Based on tomcatint\tomcat5\src\org.netbeans.modules.tomcat5.util.Utils.java.
537
     * Based on tomcatint\tomcat5\src\org.netbeans.modules.tomcat5.util.Utils.java.
(-)netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/ServerRegistry.java (-1 / +25 lines)
Lines 65-71 Link Here
65
 * possibly implement an instance provider for WEBrick/Mongrel instead of 
65
 * possibly implement an instance provider for WEBrick/Mongrel instead of 
66
 * handling them here.
66
 * handling them here.
67
 * 
67
 * 
68
 * @author peterw99, Erno Mononen
68
 * @author peterw99, Erno Mononen, Michal Papis
69
 */
69
 */
70
public class ServerRegistry implements VetoableChangeListener {
70
public class ServerRegistry implements VetoableChangeListener {
71
71
Lines 159-164 Link Here
159
            result.initGlassFish();
159
            result.initGlassFish();
160
            result.initWEBrick();
160
            result.initWEBrick();
161
            result.initMongrel();
161
            result.initMongrel();
162
            result.initPassenger();
162
            platform.addPropertyChangeListener(result);
163
            platform.addPropertyChangeListener(result);
163
            instances.put(platform, result);
164
            instances.put(platform, result);
164
            return result;
165
            return result;
Lines 218-223 Link Here
218
            }
219
            }
219
        }
220
        }
220
221
222
        private void initPassenger() {
223
            GemManager gemManager = platform.getGemManager();
224
            if (gemManager == null) {
225
                return;
226
            }
227
228
            String passengerVersion = gemManager.getLatestVersion(Passenger.GEM_NAME);
229
            if (passengerVersion == null) {
230
                // remove all mongrels
231
                for (Iterator<RubyServer> it = servers.iterator(); it.hasNext(); ) {
232
                    if (it.next() instanceof Passenger) {
233
                        it.remove();
234
                    }
235
                }
236
                return;
237
238
            }
239
            Passenger candidate = new Passenger(platform, passengerVersion);
240
            if (!servers.contains(candidate)) {
241
                servers.add(candidate);
242
            }
243
        }
244
221
        private void initWEBrick() {
245
        private void initWEBrick() {
222
            WEBrick candidate = new WEBrick(platform);
246
            WEBrick candidate = new WEBrick(platform);
223
            if (!servers.contains(candidate)) {
247
            if (!servers.contains(candidate)) {

Return to bug 135447