| CODENOTIFIER | HelpYou are not signed inSign in |
Project: RadRails1.0
Revision: 14639
Author: cwilliams
Date: 03 Jul 2008 10:20:35
Changes:fix compatibility with Rubygems 1.2
Files:| ... | ...@@ -0,0 +1,91 @@ | |
| 1 | package com.aptana.rdt.internal.core.gems; | |
| 2 | ||
| 3 | import java.util.HashSet; | |
| 4 | import java.util.List; | |
| 5 | import java.util.Set; | |
| 6 | ||
| 7 | import com.aptana.rdt.AptanaRDTPlugin; | |
| 8 | import com.aptana.rdt.core.gems.Gem; | |
| 9 | ||
| 10 | public class GemOnePointTwoParser extends GemParser { | |
| 11 | ||
| 12 | public GemOnePointTwoParser() { | |
| 13 | super(); | |
| 14 | } | |
| 15 | ||
| 16 | public GemOnePointTwoParser(String string) { | |
| 17 | super(string); | |
| 18 | } | |
| 19 | ||
| 20 | public Set<Gem> parseOutGems(List<String> lines) { | |
| 21 | Set<Gem> gems = new HashSet<Gem>(); | |
| 22 | if (lines == null || lines.isEmpty()) | |
| 23 | return gems; | |
| 24 | ||
| 25 | String line = lines.get(0); | |
| 26 | if (line.startsWith("ERROR:")) | |
| 27 | return gems; | |
| 28 | ||
| 29 | for (int curLineIndex = 0; curLineIndex < lines.size();) { | |
| 30 | String nameAndVersion = lines.get(curLineIndex); | |
| 31 | String metadata = ""; | |
| 32 | if ((curLineIndex + 1) < lines.size()) { | |
| 33 | metadata = lines.get(curLineIndex + 1); | |
| 34 | } | |
| 35 | // read until we hit end of list or empty line | |
| 36 | int j = 2; | |
| 37 | while (true) { | |
| 38 | if ((curLineIndex + j) >= lines.size()) | |
| 39 | break; // if there is no next line, break out | |
| 40 | String nextLine = lines.get(curLineIndex + j); | |
| 41 | if (nextLine.trim().length() == 0) | |
| 42 | break; // if line is empty, break out | |
| 43 | metadata += " " + nextLine.trim(); // add line to | |
| 44 | // description | |
| 45 | j++; // move to next line | |
| 46 | } | |
| 47 | ||
| 48 | String description = ""; | |
| 49 | j++; | |
| 50 | if ((curLineIndex + j) < lines.size()) { | |
| 51 | description = lines.get(curLineIndex + j); | |
| 52 | } | |
| 53 | j++; | |
| 54 | // read until we hit end of list or empty line | |
| 55 | while (true) { | |
| 56 | if ((curLineIndex + j) >= lines.size()) | |
| 57 | break; // if there is no next line, break out | |
| 58 | String nextLine = lines.get(curLineIndex + j); | |
| 59 | if (nextLine.trim().length() == 0) | |
| 60 | break; // if line is empty, break out | |
| 61 | description += " " + nextLine.trim(); // add line to | |
| 62 | // description | |
| 63 | j++; // move to next line | |
| 64 | } | |
| 65 | ||
| 66 | int openParen = nameAndVersion.indexOf('('); | |
| 67 | if (openParen == -1) { | |
| 68 | AptanaRDTPlugin | |
| 69 | .log("Bad gems output format, no opening parenthesis for version: " | |
| 70 | + lines); | |
| 71 | return gems; | |
| 72 | } | |
| 73 | int closeParen = nameAndVersion.indexOf(')'); | |
| 74 | String name = nameAndVersion.substring(0, openParen); | |
| 75 | String version = nameAndVersion | |
| 76 | .substring(openParen + 1, closeParen); | |
| 77 | if (version.indexOf(",") != -1) { | |
| 78 | String[] versions = version.split(", "); | |
| 79 | for (int y = 0; y < versions.length; y++) | |
| 80 | gems | |
| 81 | .add(new Gem(name.trim(), versions[y], description | |
| 82 | .trim())); | |
| 83 | } else { | |
| 84 | gems.add(new Gem(name.trim(), version, description.trim())); | |
| 85 | } | |
| 86 | curLineIndex += (j + 1); | |
| 87 | } | |
| 88 | return gems; | |
| 89 | } | |
| 90 | ||
| 91 | } |
| ... | ...@@ -175,7 +175,7 @@ | |
| 175 | 175 | protected Set<Gem> loadRemoteGems(String gemIndexUrl, IProgressMonitor monitor) { |
| 176 | 176 | if (!isRubyGemsInstalled()) return new HashSet<Gem>(); |
| 177 | 177 | |
| 178 | GemParser parser = new GemParser(); | |
| 178 | GemParser parser = getGemParser(); | |
| 179 | 179 | String output = getRemoteGemsListing(gemIndexUrl); |
| 180 | 180 | return parser.parse(output); |
| 181 | 181 | } |
| ... | ...@@ -183,11 +183,17 @@ | |
| 183 | 183 | private Set<Gem> loadLocalGems() { |
| 184 | 184 | if (!isRubyGemsInstalled()) return new HashSet<Gem>(); |
| 185 | 185 | |
| 186 | GemParser parser = new GemParser(); | |
| 186 | GemParser parser = getGemParser(); | |
| 187 | 187 | String output = getLocalGemsListing(); |
| 188 | 188 | return parser.parse(output); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | protected GemParser getGemParser() { | |
| 192 | if (getVersion() != null && getVersion().isGreaterThanOrEqualTo("1.2.0")) | |
| 193 | return new GemOnePointTwoParser(); | |
| 194 | return new GemParser(); | |
| 195 | } | |
| 196 | ||
| 191 | 197 | private String launchInBackgroundAndRead(final ILaunchConfiguration config, final File file) { |
| 192 | 198 | return RubyRuntime.launchInBackgroundAndRead(config, file); |
| 193 | 199 | } |