|
From: <caw...@us...> - 2007-06-19 14:27:44
|
Revision: 2630
http://svn.sourceforge.net/rubyeclipse/?rev=2630&view=rev
Author: cawilliams
Date: 2007-06-19 07:27:41 -0700 (Tue, 19 Jun 2007)
Log Message:
-----------
add a new updateAll action and button to update all gems.
When refreshing local gems, save cached copy to file.
move out parsing of gems to GemParser class and add tests for parsing.
try to avoid index out of bounds exceptions when parsing local gems.
When launching interactive consoles for GemManager (install, update) set flag to make it not launch in background (so console should pop forward to user in case they need to provide input).
Modified Paths:
--------------
trunk/com.aptana.rdt/META-INF/MANIFEST.MF
trunk/com.aptana.rdt/plugin.xml
trunk/com.aptana.rdt/src/com/aptana/rdt/core/gems/IGemManager.java
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemManager.java
trunk/com.aptana.rdt.tests/META-INF/MANIFEST.MF
Added Paths:
-----------
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemParser.java
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/actions/UpdateAllActionDelegate.java
trunk/com.aptana.rdt.tests/src/com/aptana/rdt/AptanaRDTTests.java
trunk/com.aptana.rdt.tests/src/com/aptana/rdt/internal/core/gems/
trunk/com.aptana.rdt.tests/src/com/aptana/rdt/internal/core/gems/GemParserTest.java
trunk/com.aptana.rdt.tests/src/com/aptana/rdt/internal/core/gems/local.txt
Modified: trunk/com.aptana.rdt/META-INF/MANIFEST.MF
===================================================================
--- trunk/com.aptana.rdt/META-INF/MANIFEST.MF 2007-06-19 14:13:40 UTC (rev 2629)
+++ trunk/com.aptana.rdt/META-INF/MANIFEST.MF 2007-06-19 14:27:41 UTC (rev 2630)
@@ -8,9 +8,10 @@
Eclipse-LazyStart: true
Bundle-Vendor: Aptana, Inc.
Export-Package: com.aptana.rdt,
+ com.aptana.rdt.core.gems,
+ com.aptana.rdt.internal.core.gems;x-friends:="com.aptana.rdt.tests",
com.aptana.rdt.internal.parser.warnings,
- com.aptana.rdt.internal.ui.preferences,
- com.aptana.rdt.core.gems
+ com.aptana.rdt.internal.ui.preferences
Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.runtime,
org.eclipse.jface.text,
Modified: trunk/com.aptana.rdt/plugin.xml
===================================================================
--- trunk/com.aptana.rdt/plugin.xml 2007-06-19 14:13:40 UTC (rev 2629)
+++ trunk/com.aptana.rdt/plugin.xml 2007-06-19 14:27:41 UTC (rev 2630)
@@ -180,6 +180,7 @@
label="Remove"
style="push"
toolbarPath="additions"
+ enablesFor="1"
tooltip="Remove"/>
<action
class="com.aptana.rdt.internal.ui.actions.RefreshGemsActionDelegate"
@@ -195,8 +196,17 @@
id="com.aptana.gems.ui.ActionUpdateGem"
label="Update Gem"
style="push"
+ enablesFor="1"
toolbarPath="additions"
tooltip="Update Gem"/>
+ <action
+ class="com.aptana.rdt.internal.ui.actions.UpdateAllActionDelegate"
+ icon="icons/upgrade.gif"
+ id="com.aptana.gems.ui.ActionUpdateAllGems"
+ label="Update All Gems"
+ style="push"
+ toolbarPath="additions"
+ tooltip="Update All Gems"/>
</viewContribution>
</extension>
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/core/gems/IGemManager.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/core/gems/IGemManager.java 2007-06-19 14:13:40 UTC (rev 2629)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/core/gems/IGemManager.java 2007-06-19 14:27:41 UTC (rev 2630)
@@ -30,4 +30,6 @@
public abstract IPath getGemPath(String gemName, String version);
+ public abstract boolean updateAll();
+
}
\ No newline at end of file
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemManager.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemManager.java 2007-06-19 14:13:40 UTC (rev 2629)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemManager.java 2007-06-19 14:27:41 UTC (rev 2630)
@@ -311,44 +311,15 @@
private Set<Gem> loadLocalGems() {
ILaunchConfiguration config = createGemLaunchConfiguration(LIST_COMMAND + " " + LOCAL_SWITCH, false);
List<String> lines = readOutput(config);
- if (lines.size() > 2) {
- lines.remove(0); // Remove first 3 lines from local list
- lines.remove(0);
- lines.remove(0);
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < lines.size(); i++) {
+ buffer.append(lines.get(i));
+ if (i < (lines.size() - 1)) buffer.append("\n");
}
- return parseOutGems(lines);
+ GemParser parser = new GemParser();
+ return parser.parse(buffer.toString());
}
- private Set<Gem> parseOutGems(List<String> lines) {
- Set<Gem> gems = new HashSet<Gem>();
- for (int i = 0; i < lines.size();) {
- try {
- String nameAndVersion = lines.get(i);
- String description = lines.get(i + 1);
- int j = 2;
- if ((i + 2) < lines.size()) {
- String nextLine = lines.get(i + 2);
- while (nextLine.trim().length() != 0) {
- j++;
- description += " " + nextLine.trim();
- nextLine = lines.get(i + j);
- }
- }
- int openParen = nameAndVersion.indexOf('(');
- int closeParen = nameAndVersion.indexOf(')');
- String name = nameAndVersion.substring(0, openParen);
- String version = nameAndVersion
- .substring(openParen + 1, closeParen);
- gems.add(new Gem(name.trim(), version, description.trim()));
- i += (j + 1);
- } catch (RuntimeException e) {
- AptanaRDTPlugin.log(new IllegalStateException("Was unable to parse local gems correctly from: " + lines.toString()));
- AptanaRDTPlugin.log(e);
- }
- }
- return gems;
- }
-
/*
* (non-Javadoc)
*
@@ -406,9 +377,9 @@
IRubyLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP,
map);
wc.setAttribute(IDebugUIConstants.ATTR_PRIVATE, true);
+ wc.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND,
+ !interactive);
if (!interactive) {
- wc.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND,
- true);
wc.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE,
false);
IPath outFilePath = AptanaRDTPlugin.getDefault()
@@ -503,8 +474,8 @@
public boolean refresh() {
Set<Gem> newGems = loadLocalGems();
if (!newGems.isEmpty()) {
- gems.clear();
gems = newGems;
+ storeGemCache(gems, getConfigFile(LOCAL_GEMS_CACHE_FILE));
for (GemListener listener : listeners) {
listener.gemsRefreshed();
}
@@ -629,4 +600,15 @@
public IPath getGemPath(String gemName, String version) {
return getGemPath(gemName + "-" + version);
}
+
+ public boolean updateAll() {
+ try {
+ ILaunchConfiguration config = createGemLaunchConfiguration(UPDATE_COMMAND, true);
+ config.launch(ILaunchManager.RUN_MODE, null);
+ } catch (CoreException e) {
+ AptanaRDTPlugin.log(e);
+ return false;
+ }
+ return true;
+ }
}
Added: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemParser.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemParser.java (rev 0)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemParser.java 2007-06-19 14:27:41 UTC (rev 2630)
@@ -0,0 +1,59 @@
+package com.aptana.rdt.internal.core.gems;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.aptana.rdt.AptanaRDTPlugin;
+import com.aptana.rdt.core.gems.Gem;
+
+public class GemParser {
+
+ public Set<Gem> parse(String string) {
+ String[] raw = string.split("\n");
+ List<String> lines = new ArrayList<String>();
+ for (int i = 0; i < raw.length; i++) {
+ lines.add(raw[i]);
+ }
+ if (lines.size() > 2) {
+ lines.remove(0); // Remove first 3 lines from local list
+ lines.remove(0);
+ lines.remove(0);
+ }
+ return parseOutGems(lines);
+ }
+
+ public Set<Gem> parseOutGems(List<String> lines) {
+ Set<Gem> gems = new HashSet<Gem>();
+ for (int i = 0; i < lines.size();) {
+ try {
+ String nameAndVersion = lines.get(i);
+ String description = "";
+ if ((i + 1) < lines.size()) {
+ description = lines.get(i + 1);
+ }
+ int j = 2;
+ while (true) {
+ if ((i + j) >= lines.size()) break; // if there is no next line, break out
+ String nextLine = lines.get(i + j);
+ if (nextLine.trim().length() == 0) break; // if line is empty, break out
+ description += " " + nextLine.trim(); // add line to description
+ j++; // move to next line
+ }
+ int openParen = nameAndVersion.indexOf('(');
+ int closeParen = nameAndVersion.indexOf(')');
+ String name = nameAndVersion.substring(0, openParen);
+ String version = nameAndVersion
+ .substring(openParen + 1, closeParen);
+ gems.add(new Gem(name.trim(), version, description.trim()));
+ i += (j + 1);
+ } catch (RuntimeException e) {
+ AptanaRDTPlugin.log(new IllegalStateException("Was unable to parse local gems correctly from: " + lines.toString()));
+ AptanaRDTPlugin.log(e);
+ }
+ }
+ return gems;
+ }
+
+}
Added: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/actions/UpdateAllActionDelegate.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/actions/UpdateAllActionDelegate.java (rev 0)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/actions/UpdateAllActionDelegate.java 2007-06-19 14:27:41 UTC (rev 2630)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2005 RadRails.org and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package com.aptana.rdt.internal.ui.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+
+import com.aptana.rdt.internal.core.gems.GemManager;
+
+/**
+ * Install a gem
+ *
+ * @author cwilliams
+ */
+public class UpdateAllActionDelegate implements IObjectActionDelegate, IViewActionDelegate {
+
+
+ /**
+ * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
+ * org.eclipse.ui.IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ GemManager.getInstance().updateAll();
+ }
+
+ });
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
+ * org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
+ */
+ public void init(IViewPart view) {
+ }
+
+}
Modified: trunk/com.aptana.rdt.tests/META-INF/MANIFEST.MF
===================================================================
--- trunk/com.aptana.rdt.tests/META-INF/MANIFEST.MF 2007-06-19 14:13:40 UTC (rev 2629)
+++ trunk/com.aptana.rdt.tests/META-INF/MANIFEST.MF 2007-06-19 14:27:41 UTC (rev 2630)
@@ -11,3 +11,5 @@
org.eclipse.core.runtime,
org.junit
Bundle-Vendor: Aptana, Inc.
+Bundle-Activator: com.aptana.rdt.AptanaRDTTests
+Eclipse-LazyStart: true
Added: trunk/com.aptana.rdt.tests/src/com/aptana/rdt/AptanaRDTTests.java
===================================================================
--- trunk/com.aptana.rdt.tests/src/com/aptana/rdt/AptanaRDTTests.java (rev 0)
+++ trunk/com.aptana.rdt.tests/src/com/aptana/rdt/AptanaRDTTests.java 2007-06-19 14:27:41 UTC (rev 2630)
@@ -0,0 +1,45 @@
+package com.aptana.rdt;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Plugin;
+
+
+public class AptanaRDTTests extends Plugin {
+
+ // The shared instance
+ private static AptanaRDTTests plugin;
+
+ /**
+ * The constructor
+ */
+ public AptanaRDTTests() {
+ super();
+ plugin = this;
+ }
+
+ public static File getFileInPlugin(IPath path) {
+ try {
+ URL installURL = new URL(
+ getDefault().getBundle().getEntry("/"), path.toString()); //$NON-NLS-1$
+ URL localURL = FileLocator.toFileURL(installURL);
+ return new File(localURL.getFile());
+ } catch (IOException ioe) {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static AptanaRDTTests getDefault() {
+ return plugin;
+ }
+
+
+}
Added: trunk/com.aptana.rdt.tests/src/com/aptana/rdt/internal/core/gems/GemParserTest.java
===================================================================
--- trunk/com.aptana.rdt.tests/src/com/aptana/rdt/internal/core/gems/GemParserTest.java (rev 0)
+++ trunk/com.aptana.rdt.tests/src/com/aptana/rdt/internal/core/gems/GemParserTest.java 2007-06-19 14:27:41 UTC (rev 2630)
@@ -0,0 +1,54 @@
+package com.aptana.rdt.internal.core.gems;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.Path;
+
+import com.aptana.rdt.AptanaRDTTests;
+import com.aptana.rdt.core.gems.Gem;
+
+public class GemParserTest extends TestCase {
+
+ public void testParsingLocalGems() {
+ GemParser parser = new GemParser();
+ String contents = getContents("src/com/aptana/rdt/internal/core/gems/local.txt");
+ Set<Gem> gems = parser.parse(contents);
+ assertEquals(31, gems.size());
+ }
+
+ private String getContents(String path) {
+ File file = AptanaRDTTests.getFileInPlugin(new Path(path));
+ BufferedReader reader = null;
+ StringBuffer buffer;
+ try {
+ reader = new BufferedReader(new FileReader(file));
+ String line = null;
+ buffer = new StringBuffer();
+ while((line = reader.readLine()) != null) {
+ buffer.append(line);
+ buffer.append("\n");
+ }
+ buffer.deleteCharAt(buffer.length() - 1); // delete last newline
+ return buffer.toString();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (reader != null) reader.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return null;
+ }
+
+}
Added: trunk/com.aptana.rdt.tests/src/com/aptana/rdt/internal/core/gems/local.txt
===================================================================
--- trunk/com.aptana.rdt.tests/src/com/aptana/rdt/internal/core/gems/local.txt (rev 0)
+++ trunk/com.aptana.rdt.tests/src/com/aptana/rdt/internal/core/gems/local.txt 2007-06-19 14:27:41 UTC (rev 2630)
@@ -0,0 +1,100 @@
+
+*** LOCAL GEMS ***
+
+actionmailer (1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.5, 1.2.4)
+ Service layer for easy email delivery and testing.
+
+actionpack (1.13.3, 1.13.2, 1.13.1, 1.13.0, 1.12.5, 1.12.4)
+ Web-flow and rendering framework putting the VC in MVC.
+
+actionwebservice (1.2.3, 1.2.2, 1.2.1, 1.2.0, 1.1.6, 1.1.5, 1.1.4, 1.1.3, 1.1.2, 1.1.1, 1.1.0, 0.9.4)
+ Web service support for Action Pack.
+
+activerecord (1.15.3, 1.15.2, 1.15.1, 1.15.0, 1.14.4)
+ Implements the ActiveRecord pattern for ORM.
+
+activesupport (1.4.2, 1.4.1, 1.4.0, 1.3.1)
+ Support and utility classes used by the Rails framework.
+
+cgi_multipart_eof_fix (2.1)
+ Fix an exploitable bug in CGI multipart parsing which affects Ruby
+ <= 1.8.5 when multipart boundary attribute contains a non-halting
+ regular expression string.
+
+fastercsv (1.2.0)
+ FasterCSV is CSV, but faster, smaller, and cleaner.
+
+fxri (0.3.6)
+ Graphical interface to the RI documentation, with search engine.
+
+fxruby (1.6.11, 1.6.6)
+ FXRuby is the Ruby binding to the FOX GUI toolkit.
+
+gem_plugin (0.2.2)
+ A plugin system based only on rubygems that uses dependencies only
+
+hpricot (0.6, 0.4)
+ a swift, liberal HTML parser with a fantastic library
+
+log4r (1.0.5)
+ Log4r is a comprehensive and flexible logging library for Ruby.
+
+mongrel (1.0.1)
+ A small fast HTTP library and server that runs Rails, Camping, Nitro
+ and Iowa apps.
+
+rails (1.2.3, 1.2.2, 1.2.1, 1.2.0, 1.1.6, 1.1.5)
+ Web-application framework with template engine, control-flow layer,
+ and ORM.
+
+rake (0.7.3, 0.7.2)
+ Ruby based make-like utility.
+
+rspec (1.0.5, 0.9.4)
+ RSpec-1.0.5 (r2081) - BDD for Ruby http://rspec.rubyforge.org/
+
+ruby-debug (0.9.3, 0.9.2)
+ Command line interface (CLI) for ruby-debug-base
+
+ruby-debug-base (0.9.3, 0.9.2)
+ Fast Ruby debugger
+
+ruby-debug-ide (0.1.6, 0.1.4, 0.1.2)
+ IDE interface for ruby-debug.
+
+sources (0.0.1)
+ This package provides download sources for remote gem installation
+
+sqlite3-ruby (1.2.1)
+ SQLite3/Ruby is a module to allow Ruby scripts to interface with a
+ SQLite database.
+
+tzinfo (0.3.3)
+ Daylight-savings aware timezone library
+
+win32-clipboard (0.4.2, 0.4.1)
+ A package for interacting with the Windows clipboard
+
+win32-dir (0.3.1)
+ Extra constants and methods for the Dir class on Windows.
+
+win32-eventlog (0.4.3)
+ Interface for the MS Windows Event Log.
+
+win32-file (0.5.4, 0.5.3)
+ Extra or redefined methods for the File class on Windows.
+
+win32-file-stat (1.2.5, 1.2.3)
+ A File::Stat class tailored to MS Windows
+
+win32-process (0.5.2, 0.5.1)
+ Adds fork, wait, wait2, waitpid, waitpid2 and a special kill method
+
+win32-sapi (0.1.3)
+ An interface to the MS SAPI (Sound API) library.
+
+win32-sound (0.4.0)
+ A package for playing with sound on Windows.
+
+windows-pr (0.6.6, 0.6.2)
+ Windows functions and constants predefined via Win32API
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|