diff -r 70a422f5c2a9 ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Bundle.properties --- a/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Bundle.properties Tue Sep 14 17:36:43 2010 +0200 +++ b/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Bundle.properties Wed Sep 15 19:24:28 2010 +0200 @@ -49,6 +49,8 @@ LBL_Passenger=Passenger {0} # 0 - version LBL_GlassFish=GlassFish Gem {0} +# 0 - version +LBL_Trinidad=Trinidad {0} # 0 - server label, 1 - platform label LBL_ServerNodeName={0} ({1}) # 0..project 1..port diff -r 70a422f5c2a9 ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/GlassFishGem.java --- a/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/GlassFishGem.java Tue Sep 14 17:36:43 2010 +0200 +++ b/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/GlassFishGem.java Wed Sep 15 19:24:28 2010 +0200 @@ -64,8 +64,9 @@ * * @author Peter Williams * @author Erno Mononen + * @author David Calavera */ -class GlassFishGem implements RubyServer, ServerInstanceImplementation { +class GlassFishGem extends JRubyServerBase { static final String GEM_NAME = "glassfish"; /** @@ -76,227 +77,31 @@ Pattern.compile(".*Press Ctrl\\+C to stop\\..*", Pattern.DOTALL), Pattern.compile(".*[0-9] milliseconds.*", Pattern.DOTALL) }; - - private final List applications = new ArrayList(); - private final RubyPlatform platform; - private final String version; - private final String location; - private final ChangeSupport changeSupport = new ChangeSupport(this); - - private Node node; + + private static final String LABEL = "LBL_GlassFish"; GlassFishGem(RubyPlatform platform, GemInfo gemInfo) { - Parameters.notNull("platform", platform); //NOI18N - this.platform = platform; - this.version = gemInfo.getVersion(); - this.location = getGemFolder(gemInfo.getSpecFile()); + super(platform, gemInfo); } - private String getGemFolder(File specFile) { - String gemFolderName = specFile.getName(); - if(gemFolderName.endsWith(".gemspec")) { - gemFolderName = gemFolderName.substring(0, gemFolderName.length() - 8); - } - - return new File(specFile.getParentFile().getParentFile(), - "gems" + File.separatorChar + gemFolderName).getAbsolutePath(); - } - - private Node getNode() { - if (this.node == null) { - this.node = new RubyServerNode(this); - } - return node; - } - - // RubyServer methods - public String getNodeName() { - return NbBundle.getMessage(GlassFishGem.class, "LBL_ServerNodeName", getDisplayName(), platform.getLabel()); - } - - public String getLocation() { - return location; - } - - public List getStartupParams(RailsVersion version) { - return Collections.emptyList(); - } - - public String getScriptPrefix() { - return "-S"; - } - + @Override public String getServerPath(RailsVersion version) { // glassfish_rails is deprecated in 0.9.4 and newer return compareVersion("0.9.4") >= 0 ? "glassfish" : "glassfish_rails"; } - public boolean isStartupMsg(String outputLine) { - for (Pattern each : PATTERNS) { - if (each.matcher(outputLine).matches()) { - return true; - } - } - return false; - } - - public List getApplications() { - return Collections.unmodifiableList(applications); - } - - public boolean addApplication(RailsApplication application) { - boolean result = applications.add(application); - changeSupport.fireChange(); - return result; - } - - 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); - } - - public int compareVersion(String targetVersion) { - int [] sv = extractVersion(version); - int [] tv = extractVersion(targetVersion); - for(int i = 0; i < 3; i++) { - if(sv[i] < tv[i]) { - return -1; - } else if(sv[i] > tv[i]) { - return 1; - } - } - return 0; - } - - private int [] extractVersion(String vs) { - int [] v = new int [] { 0, 0, 0 }; - String [] parts = vs.split("\\."); - for(int i = 0; i < 3 && i < parts.length; i++) { - v[i] = Integer.valueOf(parts[i]); - } - return v; - } - - // ServerInstanceImplementation methods - 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; - } - - // RubyInstance methods - public String getServerUri() { - return "GLASSFISH"; - } - - public String getDisplayName() { - return NbBundle.getMessage(GlassFishGem.class, "LBL_GlassFish", version); - } - - public ServerState getServerState() { - // TODO: currently handled in Rails project - return null; - } - - public Future startServer(RubyPlatform platform) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public Future stopServer() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public Future deploy(String applicationName, File applicationDir) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public Future stop(String applicationName) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public Future runApplication(RubyPlatform platform, String applicationName, File applicationDir) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public boolean isPlatformSupported(RubyPlatform platform) { - return this.platform.equals(platform); - } - - public String getContextRoot(String applicationName) { - return ""; // NOI18N - } - - public int getRailsPort() { - return 3000; - } - - public String getServerCommand(RubyPlatform platform, String classpath, - File applicationDir, int httpPort, boolean debug) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final GlassFishGem other = (GlassFishGem) 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; - } - if (this.location != other.location && (this.location == null || !this.location.equals(other.location))) { - return false; - } - return true; + protected String getLabel() { + return LABEL; } @Override - public int hashCode() { - int hash = 3; - hash = 47 * hash + (this.platform != null ? this.platform.hashCode() : 0); - hash = 47 * hash + (this.version != null ? this.version.hashCode() : 0); - return hash; + protected Pattern[] getPatterns() { + return PATTERNS; } + @Override + protected String getGemName() { + return GEM_NAME; + } } diff -r 70a422f5c2a9 ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/JRubyServerBase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/JRubyServerBase.java Wed Sep 15 19:24:28 2010 +0200 @@ -0,0 +1,313 @@ +/* + * 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 2010 Sun Microsystems, Inc. + */ + +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 java.util.regex.Pattern; +import javax.swing.JComponent; +import javax.swing.event.ChangeListener; +import org.netbeans.api.ruby.platform.RubyPlatform; +import org.netbeans.modules.ruby.platform.gems.GemInfo; +import org.netbeans.modules.ruby.railsprojects.RailsProjectUtil.RailsVersion; +import org.netbeans.modules.ruby.railsprojects.server.nodes.RubyServerNode; +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; + +/** + * + * @author David Calavera + */ +public abstract class JRubyServerBase implements RubyServer, ServerInstanceImplementation { + + private final List applications = new ArrayList(); + private final RubyPlatform platform; + private final String version; + private final String location; + private final ChangeSupport changeSupport = new ChangeSupport(this); + private Node node; + + /* abstract methods */ + protected abstract String getLabel(); + protected abstract Pattern[] getPatterns(); + protected abstract String getGemName(); + + JRubyServerBase(RubyPlatform platform, GemInfo gemInfo) { + Parameters.notNull("platform", platform); //NOI18N + this.platform = platform; + this.version = gemInfo.getVersion(); + this.location = getGemFolder(gemInfo.getSpecFile()); + } + + private String getGemFolder(File specFile) { + String gemFolderName = specFile.getName(); + if(gemFolderName.endsWith(".gemspec")) { + gemFolderName = gemFolderName.substring(0, gemFolderName.length() - 8); + } + + return new File(specFile.getParentFile().getParentFile(), + "gems" + File.separatorChar + gemFolderName).getAbsolutePath(); + } + + private Node getNode() { + if (this.node == null) { + this.node = new RubyServerNode(this); + } + return node; + } + + @Override + public String getNodeName() { + return NbBundle.getMessage(getClass(), "LBL_ServerNodeName", getDisplayName(), platform.getLabel()); + } + + @Override + public String getLocation() { + return location; + } + + @Override + public List getStartupParams(RailsVersion version) { + return Collections.emptyList(); + } + + @Override + public String getScriptPrefix() { + return "-S"; + } + + @Override + public String getServerPath(RailsVersion version) { + return getGemName().toLowerCase(); + } + + public boolean isStartupMsg(String outputLine) { + for (Pattern each : getPatterns()) { + if (each.matcher(outputLine).matches()) { + return true; + } + } + return false; + } + + @Override + public List getApplications() { + return Collections.unmodifiableList(applications); + } + + @Override + public boolean addApplication(RailsApplication application) { + boolean result = applications.add(application); + changeSupport.fireChange(); + return result; + } + + @Override + 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); + } + + public int compareVersion(String targetVersion) { + int [] sv = extractVersion(version); + int [] tv = extractVersion(targetVersion); + for(int i = 0; i < 3; i++) { + if(sv[i] < tv[i]) { + return -1; + } else if(sv[i] > tv[i]) { + return 1; + } + } + return 0; + } + + private int [] extractVersion(String vs) { + int [] v = new int [] { 0, 0, 0 }; + String [] parts = vs.split("\\."); + for(int i = 0; i < 3 && i < parts.length; i++) { + v[i] = Integer.valueOf(parts[i]); + } + return v; + } + + @Override + public String getServerUri() { + return getGemName().toUpperCase(); + } + + @Override + public String getDisplayName() { + return NbBundle.getMessage(getClass(), getLabel(), version); + } + + @Override + public ServerState getServerState() { + return null; + } + + @Override + public Future startServer(RubyPlatform platform) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Future stopServer() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Future deploy(String applicationName, File applicationDir) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Future stop(String applicationName) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Future runApplication(RubyPlatform platform, String applicationName, File applicationDir) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isPlatformSupported(RubyPlatform platform) { + return this.platform.equals(platform); + } + + @Override + public String getContextRoot(String applicationName) { + return ""; + } + + @Override + public int getRailsPort() { + return 3000; + } + + @Override + public String getServerCommand(RubyPlatform platform, String classpath, File applicationDir, int httpPort, boolean debug) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getServerDisplayName() { + return getNodeName(); + } + + @Override + public Node getFullNode() { + return getNode(); + } + + @Override + public Node getBasicNode() { + return getNode(); + } + + @Override + public JComponent getCustomizer() { + return null; + } + + @Override + public void remove() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isRemovable() { + return false; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final JRubyServerBase other = (JRubyServerBase) 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; + } + if (this.location != other.location && (this.location == null || !this.location.equals(other.location))) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 47 * hash + (this.platform != null ? this.platform.hashCode() : 0); + hash = 47 * hash + (this.version != null ? this.version.hashCode() : 0); + return hash; + } +} diff -r 70a422f5c2a9 ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/ServerRegistry.java --- a/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/ServerRegistry.java Tue Sep 14 17:36:43 2010 +0200 +++ b/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/ServerRegistry.java Wed Sep 15 19:24:28 2010 +0200 @@ -50,11 +50,9 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import org.netbeans.api.ruby.platform.RubyPlatform; import org.netbeans.api.ruby.platform.RubyPlatformManager; import org.netbeans.modules.ruby.platform.gems.GemInfo; @@ -166,6 +164,7 @@ } RubyServerFactory result = new RubyServerFactory(platform); result.initGlassFish(); + result.initTrinidad(); result.initMongrel(); result.initWEBrick(); if (ENABLE_PASSENGER) { @@ -181,56 +180,60 @@ return Collections.unmodifiableList(servers); } - private void initGlassFish() { - if (platform.isJRuby()) { - GemManager gemManager = platform.getGemManager(); - if (gemManager == null) { - return; - } - - List versions = gemManager.getVersions(GlassFishGem.GEM_NAME); - GemInfo glassFishGemInfo = versions.isEmpty() ? null : versions.get(0); - if (glassFishGemInfo == null) { - // remove all glassfish from gems - for (Iterator it = servers.iterator(); it.hasNext();) { - if (it.next() instanceof GlassFishGem) { - it.remove(); - } - } - return; - - } - - GlassFishGem candidate = new GlassFishGem(platform, glassFishGemInfo); - if (!servers.contains(candidate)) { - servers.add(candidate); - } + private RubyServer createInstance(Class clazz, GemInfo gemInfo) { + if (clazz == Trinidad.class) { + return new Trinidad(platform, gemInfo); + } else if (clazz == GlassFishGem.class) { + return new GlassFishGem(platform, gemInfo); + } else if (clazz == Mongrel.class) { + return new Mongrel(platform, gemInfo.getVersion()); + } else if (clazz == Passenger.class) { + return new Passenger(platform, gemInfo.getVersion()); } + return null; } - private void initMongrel() { + private void initServer(Class clazz, String gemName) { GemManager gemManager = platform.getGemManager(); if (gemManager == null) { return; } - String mongrelVersion = gemManager.getLatestVersion(Mongrel.GEM_NAME); - if (mongrelVersion == null) { - // remove all mongrels + List versions = gemManager.getVersions(gemName); + GemInfo gemInfo = versions.isEmpty() ? null : versions.get(0); + if (gemInfo == null) { + // remove all glassfish from gems for (Iterator it = servers.iterator(); it.hasNext();) { - if (it.next() instanceof Mongrel) { + if (it.next().getClass() == clazz) { it.remove(); } } return; } - Mongrel candidate = new Mongrel(platform, mongrelVersion); + + RubyServer candidate = createInstance(clazz, gemInfo); if (!servers.contains(candidate)) { servers.add(candidate); } } + private void initGlassFish() { + if (platform.isJRuby()) { + initServer(GlassFishGem.class, GlassFishGem.GEM_NAME); + } + } + + private void initTrinidad() { + if (platform.isJRuby()) { + initServer(Trinidad.class, Trinidad.GEM_NAME); + } + } + + private void initMongrel() { + initServer(Mongrel.class, Mongrel.GEM_NAME); + } + private void initWEBrick() { WEBrick candidate = new WEBrick(platform); if (!servers.contains(candidate)) { @@ -239,26 +242,7 @@ } private void initPassenger() { - GemManager gemManager = platform.getGemManager(); - if (gemManager == null) { - return; - } - - String passengerVersion = gemManager.getLatestVersion(Passenger.GEM_NAME); - if (passengerVersion == null) { - // remove all passengers - 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); - } + initServer(Passenger.class, Passenger.GEM_NAME); } public void propertyChange(PropertyChangeEvent evt) { diff -r 70a422f5c2a9 ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Trinidad.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ruby.railsprojects/src/org/netbeans/modules/ruby/railsprojects/server/Trinidad.java Wed Sep 15 19:24:28 2010 +0200 @@ -0,0 +1,82 @@ +/* + * 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 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.ruby.railsprojects.server; + +import java.util.regex.Pattern; +import org.netbeans.api.ruby.platform.RubyPlatform; +import org.netbeans.modules.ruby.platform.gems.GemInfo; + +/** + * + * @author David Calavera + */ +public class Trinidad extends JRubyServerBase { + + static final String GEM_NAME = "trinidad"; + + private static final Pattern[] PATTERNS = { + Pattern.compile(".*org.apache.coyote.http11.Http11Protocol start.*", Pattern.DOTALL), + Pattern.compile(".*INFO: Starting Coyote HTTP/1.1.*", Pattern.DOTALL) + }; + + private static final String LABEL = "LBL_Trinidad"; + + public Trinidad(RubyPlatform platform, GemInfo gemInfo) { + super(platform, gemInfo); + } + + @Override + protected String getLabel() { + return LABEL; + } + + @Override + protected Pattern[] getPatterns() { + return PATTERNS; + } + + @Override + protected String getGemName() { + return GEM_NAME; + } +}