Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/yaml/PubYamlUtils.java

Issue 11884046: change the way we find package name from pubspec.yaml file (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/yaml/PubYamlUtils.java
===================================================================
--- editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/yaml/PubYamlUtils.java (revision 17022)
+++ editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/yaml/PubYamlUtils.java (working copy)
@@ -38,6 +38,8 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Utility class for using Snake YAML parser and other yaml utility methods
@@ -92,6 +94,8 @@
}
}
+ public static String PATTERN_PUBSPEC_NAME_LINE = "(?m)^(?:(?!--|').|'(?:''|[^'])*')*(name:.*)$";
+
/**
* Return a yaml string for the given {@link PubYamlObject}
*
@@ -154,6 +158,23 @@
}
/**
+ * Return the name of the package as specified in pubspec.yaml (name: sample)
+ *
+ * @param contents string contents of the pubspec.yaml file
+ * @return String package name
+ */
+ public static String getPubspecName(String contents) {
+ Matcher m = Pattern.compile(PubYamlUtils.PATTERN_PUBSPEC_NAME_LINE).matcher(contents);
+ if (m.find()) {
+ String[] strings = m.group(1).split(":");
+ if (strings.length == 2) {
+ return strings[1].replaceAll(" ", "");
+ }
+ }
+ return null;
+ }
+
+ /**
* Parse the pubspec.yaml string contents to an Map
*/
@SuppressWarnings("unchecked")
@@ -183,7 +204,6 @@
DartCore.logError(e);
return null;
}
-
}
}

Powered by Google App Engine
This is Rietveld 408576698