diff -rwauN --strip-trailing-cr --exclude='*.patch' netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Bundle.properties netbeans/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Bundle.properties --- netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Bundle.properties 2008-11-10 00:14:16.000000000 +0100 +++ netbeans/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Bundle.properties 2009-02-11 03:17:32.000000000 +0100 @@ -43,12 +43,16 @@ # 0 - version LBL_Mongrel=Mongrel {0} # 0 - version +LBL_Passenger=Passenger {0} +# 0 - version LBL_GlassFish=GlassFish Gem {0} # 0 - server label, 1 - platform label LBL_ServerNodeName={0} ({1}) # 0..project 1..port ServerStartup=Server Startup NoServerFound=Could not connect to the web server - cannot show {0} +NoApacheFound=Apache server is stopped, please start it manually\n\ + Common way to start it is to run: sudo /etc/init.d/apache2 start Conflict=The web server failed to start because the port number {0} is already in use,\n\ and nearby ports could not be used. Edit the project properties and choose\n\ an available port, or shut down the other service using the port. diff -rwauN --strip-trailing-cr --exclude='*.patch' netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Passenger.java netbeans/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Passenger.java --- netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Passenger.java 1970-01-01 01:00:00.000000000 +0100 +++ netbeans/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Passenger.java 2009-02-11 23:15:58.000000000 +0100 @@ -0,0 +1,217 @@ +package org.netbeans.modules.ruby.railsprojects.server; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.Future; +import javax.swing.JComponent; +import javax.swing.event.ChangeListener; +import org.netbeans.api.ruby.platform.RubyPlatform; +import org.netbeans.modules.ruby.railsprojects.server.nodes.RubyServerNode; +import org.netbeans.modules.ruby.railsprojects.server.spi.RubyInstance.OperationState; +import org.netbeans.modules.ruby.railsprojects.server.spi.RubyInstance.ServerState; +import org.netbeans.spi.server.ServerInstanceImplementation; +import org.openide.nodes.Node; +import org.openide.util.ChangeSupport; +import org.openide.util.NbBundle; +import org.openide.util.Parameters; + +/** + * This class represents passenger (gem) installation + * + * @author Michal Papis + */ +class Passenger implements RubyServer, ServerInstanceImplementation { + + static final String GEM_NAME = "passenger"; + static final String SERVER_URI = "PASSENGER"; + private final RubyPlatform platform; + private final String version; + private final List applications = new ArrayList(); + private final ChangeSupport changeSupport = new ChangeSupport(this); + private Node node; + + Passenger(RubyPlatform platform, String version) { + Parameters.notNull("platform", platform); //NOI18N + this.platform = platform; + this.version = version; + } + + private Node getNode() { + if (this.node == null) { + this.node = new RubyServerNode(this); + } + return node; + } + + public String getNodeName() { + return NbBundle.getMessage(Passenger.class, "LBL_ServerNodeName", getDisplayName(), platform.getLabel()); + } + + public String getLocation() { + return null; + } + + public String getStartupParam() { + return "passenger"; + } + + public String getScriptPrefix() { + return null; + } + + public String getServerPath() { + return null; + } + + public boolean isStartupMsg(String arg0) { + //Always is started + return true; + } + + public List getApplications() { + return Collections.unmodifiableList(applications); + } + + public boolean addApplication(RailsApplication application) { + boolean result = applications.add(application); + changeSupport.fireChange(); + return result; + } + + /** + * Will remove application, instead of http port, the port will carry instance number + * @param port + * @return + */ + public boolean removeApplication(int port) { + boolean result = false; + for (RailsApplication app : applications) { + if (app.getPort() == port) { + result = applications.remove(app); + changeSupport.fireChange(); + break; + } + } + + return result; + } + + public void addChangeListener(ChangeListener listener) { + changeSupport.addChangeListener(listener); + } + + public void removeChangeListener(ChangeListener listener) { + changeSupport.removeChangeListener(listener); + } + + /** + * + * @return upercase server name + * @see ServerResolver.getExplicitlySpecifiedServer(RailsProject project) + * @see ServerRegistry.getServer(String serverId, RubyPlatform platform) + */ + public String getServerUri() { + return "PASSENGER"; + } + + public String getDisplayName() { + return NbBundle.getMessage(Passenger.class, "LBL_Passenger",version); + } + + /** + * Passenger is meant to be always running, but we could check port if it is listening for connections + * @return ServerState.RUNNING + * @see RailsServerManager.ensureRunning is currently doing this job + */ + public ServerState getServerState() { + return ServerState.RUNNING; + } + + public Future startServer(RubyPlatform arg0) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Future stopServer() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Future deploy(String arg0, File arg1) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Future stop(String arg0) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Future runApplication(RubyPlatform arg0, String arg1, File arg2) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean isPlatformSupported(RubyPlatform platform) { + return this.platform.equals(platform); + } + + public String getContextRoot(String applicationName) { + return applicationName; + } + + public int getRailsPort() { + return 80; + } + + public String getServerCommand(RubyPlatform arg0, String arg1, File arg2, int arg3, boolean arg4) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public String getServerDisplayName() { + return getNodeName(); + } + + public Node getFullNode() { + return getNode(); + } + + public Node getBasicNode() { + return getNode(); + } + + public JComponent getCustomizer() { + return null; + } + + public void remove() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean isRemovable() { + return false; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Passenger other = (Passenger) obj; + if (this.platform != other.platform && (this.platform == null || !this.platform.equals(other.platform))) { + return false; + } + if (this.version != other.version && (this.version == null || !this.version.equals(other.version))) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 55 * hash + (this.platform != null ? this.platform.hashCode() : 0); + hash = 55 * hash + (this.version != null ? this.version.hashCode() : 0); + return hash; + } +} diff -rwauN --strip-trailing-cr --exclude='*.patch' netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/RailsServerManager.java netbeans/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/RailsServerManager.java --- netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/RailsServerManager.java 2008-11-10 00:14:16.000000000 +0100 +++ netbeans/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/RailsServerManager.java 2009-02-11 23:12:26.000000000 +0100 @@ -118,7 +118,7 @@ * @todo Normalize & merge RubyServer and RubyInstance interfaces and their * various implementations (V3, WEBrick, Mongrel). * - * @author Tor Norbye, Pavel Buzek, Erno Mononen, Peter Williams + * @author Tor Norbye, Pavel Buzek, Erno Mononen, Peter Williams, Michal Papis */ public final class RailsServerManager { /** @@ -278,6 +278,29 @@ } } + ensurePortAvailable(); + //mpapis: detect passanger ... not preaty way + if (port != originalPort && instance.getServerUri().equals(Passenger.SERVER_URI)) { + synchronized (RailsServerManager.this) { + //TODO: why we have two different enums for the same thing - server state + switch (instance.getServerState()) { + case RUNNING: + status = ServerStatus.RUNNING; + break; + case STARTING: + case STOPPED: + case STOPPING: + status = ServerStatus.STARTING; + break; + } + if (status == ServerStatus.RUNNING) { + return true; + } else { + return false; + } + } + } + // check whether the user has modified script/server to use another server RubyInstance explicitlySpecified = ServerResolver.getExplicitlySpecifiedServer(project); if (explicitlySpecified instanceof RubyServer) { @@ -287,7 +310,8 @@ server = (RubyServer) instance; } - ensurePortAvailable(); +//mpapis: moved few lines up before we detect explicitly specified servers +// ensurePortAvailable(); String displayName = getServerTabName(server, projectName, port); String serverPath = server.getServerPath(); ExecutionDescriptor desc = new ExecutionDescriptor(platform, displayName, dir, serverPath); @@ -432,6 +456,12 @@ if (ensureRunning()) { RailsServerManager.showURL(getContextRoot(), relativeUrl, port, clientDebug, project); } else { + //TODO: not a preaty way, but if apache is stoped it will not start by itself + if (instance.getServerUri().equals(Passenger.SERVER_URI)) { + String msg = NbBundle.getMessage(RailsServerManager.class, "NoApacheFound"); + LOGGER.fine(msg); + StatusDisplayer.getDefault().setStatusText(msg); + } else { String displayName = NbBundle.getMessage(RailsServerManager.class, "ServerStartup"); final ProgressHandle handle = ProgressHandleFactory.createHandle(displayName,new Cancellable() { @@ -501,6 +531,7 @@ }); } } + } /** Return true if there is an HTTP response from the port on localhost. * Based on tomcatint\tomcat5\src\org.netbeans.modules.tomcat5.util.Utils.java. diff -rwauN --strip-trailing-cr --exclude='*.patch' netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/ServerRegistry.java netbeans/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/ServerRegistry.java --- netbeans-org/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/ServerRegistry.java 2008-11-10 00:14:16.000000000 +0100 +++ netbeans/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/ServerRegistry.java 2009-02-11 23:14:31.000000000 +0100 @@ -65,7 +65,7 @@ * possibly implement an instance provider for WEBrick/Mongrel instead of * handling them here. * - * @author peterw99, Erno Mononen + * @author peterw99, Erno Mononen, Michal Papis */ public class ServerRegistry implements VetoableChangeListener { @@ -159,6 +159,7 @@ result.initGlassFish(); result.initWEBrick(); result.initMongrel(); + result.initPassenger(); platform.addPropertyChangeListener(result); instances.put(platform, result); return result; @@ -218,6 +219,29 @@ } } + private void initPassenger() { + GemManager gemManager = platform.getGemManager(); + if (gemManager == null) { + return; + } + + String passengerVersion = gemManager.getLatestVersion(Passenger.GEM_NAME); + if (passengerVersion == null) { + // remove all mongrels + for (Iterator it = servers.iterator(); it.hasNext(); ) { + if (it.next() instanceof Passenger) { + it.remove(); + } + } + return; + + } + Passenger candidate = new Passenger(platform, passengerVersion); + if (!servers.contains(candidate)) { + servers.add(candidate); + } + } + private void initWEBrick() { WEBrick candidate = new WEBrick(platform); if (!servers.contains(candidate)) {