Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pulled out copied dependencies

  • Loading branch information...
commit 37cd6f8b0c589a0f463f52a71c7a563a0c6c679b 1 parent 5965d60
Micah Martin authored
5 project.clj
View
@@ -6,8 +6,11 @@
:url "file://LICENSE"
:distribution :repo
:comments "Copyright © 2011 Micah Martin All Rights Reserved."}
- :dependencies [[org.clojure/clojure "1.2.0"]]
+ :dependencies [[org.clojure/clojure "1.2.0"]
+ [fresh "1.0.1"]
+ [mmargs "1.2.0"]]
:dev-dependencies [[lein-clojars "0.6.0"]]
:test-path "spec/"
:java-source-path "src/"
+ :uberjar-exclusions [#"^clojure/.*"]
)
214 src/fresh/core.clj
View
@@ -1,214 +0,0 @@
-; *********************************************************************************************************************
-;
-; DO NOT EDIT THIS FILE !!!
-;
-; Copied from https://github.com/slagyr/fresh so speclj can remain without dependencies.
-;
-; *********************************************************************************************************************
-
-(ns fresh.core
- (:use
- [clojure.java.io :only (file)])
- (:require
- [clojure.set :as set])
- (:import
- [java.io PushbackReader FileReader File]))
-
-(def clj-file-regex #".*\.clj")
-(defn clj-files-in
- "Returns a seq of all clojure source files contained in the given directories."
- [& dirs]
- (let [files (reduce #(into %1 (file-seq (file %2))) [] dirs)]
- (filter #(re-matches clj-file-regex (.getName %)) files)))
-
-;; Resolving ns names ---------------------------------------------------------------------------------------------------
-;
-(defn ns-to-filename
- "Converts the namespace name into a relative path for the corresponding clojure src file."
- [ns]
- (str (apply str (replace {\. \/ \- \_} (name ns))) ".clj"))
-
-(defn ns-to-file
- "Returns a java.io.File corresponding to the clojure src file for the
- given namespace. nil is returned if the file is not found in the classpath
- or if the file is not a raw text file."
- [ns]
- (let [relative-filename (ns-to-filename ns)
- url (.getResource (clojure.lang.RT/baseLoader) relative-filename)]
- (if (and url (= "file" (.getProtocol url)))
- (file (.getFile url))
- nil)))
-
-(defn ns-form?
- "Returns true if the given form is a namespace form."
- [form]
- (and (list? form) (= 'ns (first form))))
-
-(defn read-ns-form
- "Returns the namespace form on the specified clojure src file, nil if none is found."
- [file]
- (try
- (let [reader (PushbackReader. (FileReader. file))]
- (try
- (loop [form (read reader)]
- (if (ns-form? form)
- form
- (recur (read reader))))
- (finally (.close reader))))
- (catch Exception e nil)))
-;
-;; Parsing the ns form --------------------------------------------------------------------------------------------------
-;
-(defn- compose-ns [prefix lib]
- (if prefix
- (symbol (str prefix \. lib))
- lib))
-
-(defn- ns-for-part [prefix arg]
- (cond
- (symbol? arg) (compose-ns prefix arg)
- (and (vector? arg) (or (nil? (second arg)) (keyword? (second arg)))) (compose-ns prefix (first arg))
- :else (map #(ns-for-part (compose-ns prefix (first arg)) %) (rest arg))))
-
-(defn- depending-names-of-part [args]
- (map #(ns-for-part nil %) (filter (complement keyword?) (rest args))))
-
-(defn depending-ns-names-from
- "Returns a seq of symbols that are the names of the namespaces that the provided
- namespace form depends on."
- [ns-form]
- (let [dependency-parts (filter #(and (list? %) (#{:use :require} (first %))) ns-form)
- ns-list (map #(depending-names-of-part %) dependency-parts)]
- (set (flatten ns-list))))
-
-(defn depending-files-from
- "Returns a seq of java.io.File objects that the namespace form depends on."
- [ns-form]
- (if ns-form
- (let [dependency-names (depending-ns-names-from ns-form)
- dependency-filenames (map #(ns-to-file %) dependency-names)]
- (vec (filter identity dependency-filenames)))
- []))
-
-(defn ns-name-from
- "Returns the name of the namespace form"
- [ns-form]
- (if ns-form
- (second ns-form)
- nil))
-;
-;; File tracking --------------------------------------------------------------------------------------------------------
-
-(deftype FileTracker [ns mod-time dependencies]
- Object
- (toString [this] (str "ns: " ns " mod-time: " mod-time " dependencies: " dependencies)))
-
-(defn- new-file-tracker [ns mod-time dependencies]
- (FileTracker. ns mod-time dependencies))
-
-(defn- modified? [file tracker]
- (> (.lastModified file) (.mod-time tracker)))
-
-(declare update-tracking-for-files)
-(defn- update-tracking-for-file [listing file batch]
- (let [tracker (get listing file)
- no-update-required (not (or (nil? tracker) (modified? file tracker)))]
- (if no-update-required
- [listing batch]
- (let [ns-form (read-ns-form file)
- dependencies (depending-files-from ns-form)
- [listing batch] (update-tracking-for-files listing dependencies batch)
- ns (ns-name-from ns-form)
- updated-tracker (new-file-tracker ns (.lastModified file) dependencies)]
- [(assoc listing file updated-tracker) batch]))))
-
-(defn- update-tracking-for-files
- ([listing files] (first (update-tracking-for-files listing files #{})))
- ([listing files batch]
- (loop [[listing batch] [listing batch] files files]
- (if (not (seq files))
- [listing batch]
- (let [file (first files)]
- (if (contains? batch file)
- (recur [listing batch] (rest files))
- (recur (update-tracking-for-file listing file (conj batch file)) (rest files))))))))
-
-(defn- depends-on? [dependency listing dependent]
- (some (partial = dependency) (.dependencies (get listing dependent))))
-
-(defn- has-dependent? [listing file]
- (some #(depends-on? file listing %) (keys listing)))
-
-(defn- with-dependency [new-dependents dependents file tracker]
- (if (some dependents (.dependencies tracker))
- (conj new-dependents file)
- new-dependents))
-
-(defn- dependents-of
- ([listing files] (dependents-of listing (set files) #{}))
- ([listing files dependents]
- (loop [files files dependents dependents]
- (let [new-dependents (reduce (fn [new-dependents [file tracker]] (with-dependency new-dependents files file tracker)) #{} listing)]
- (if (seq new-dependents)
- (recur new-dependents (into dependents new-dependents))
- dependents)))))
-
-(defn- clean-deleted-files
- ([listing] (clean-deleted-files listing (filter #(not (.exists %)) (keys listing))))
- ([listing files-to-delete]
- (if (not (seq files-to-delete))
- listing
- (let [dependencies (reduce #(into %1 (.dependencies (get listing %2))) [] files-to-delete)
- listing (apply dissoc listing files-to-delete)
- unused-dependencies (filter #(not (has-dependent? listing %)) dependencies)]
- (clean-deleted-files listing unused-dependencies)))))
-
-(defn- unload-nses [nses]
- (doseq [ns nses] (remove-ns ns))
- (dosync (alter @#'clojure.core/*loaded-libs* set/difference (set nses))))
-
-(defn- load-nses [nses]
- (apply require nses))
-
-(defn- doto-nses [listing files & actions]
- (let [trackers (vec (filter identity (map listing files)))
- nses (vec (filter identity (map #(.ns %) trackers)))]
- (when (seq nses)
- (doseq [action actions]
- (action nses)))))
-
-(defn make-fresh
- "Does the work of freshener functions."
- [listing-atom files auditor]
- (let [listing (clean-deleted-files @listing-atom)
- tracked-files (set (keys listing))
- deleted (set/difference (set (keys @listing-atom)) tracked-files)
- new-tracked-files (set/difference (set files) tracked-files)
- modified-tracked-files (set (filter #(modified? % (get listing %)) tracked-files))
- updates (concat new-tracked-files modified-tracked-files)
- listing (update-tracking-for-files listing updates)
- new (set/difference (set (keys listing)) tracked-files)
- files-to-reload (sort (into (dependents-of listing updates) updates))
- result {:new new :deleted deleted :modified modified-tracked-files :reloaded files-to-reload}]
- (when (auditor result)
- (doto-nses @listing-atom deleted unload-nses)
- (reset! listing-atom listing)
- (doto-nses listing files-to-reload unload-nses load-nses))
- result))
-
-(defn freshener
- "Returns a freshener function that, when invoked, will ensure
-the freshness of all files provided by the provider function.
-The provider must be a no-arg function that returns a seq of java.io.File
-objects. If any of the files have been modified, they (and all
-thier dependent files), will be reloaded. New files will be loaded and
-tracked. Deleted files will be unloaded along with any dependant files
-that are no longer referenced. The freshener function returns a report map
-of seqs containings File objects: {:new :modified :deleted :reloaded}.
-The optional auditor function is called, passing in the report map,
-before the state of the runtime has been modified. Only when the auditor
-returns a truthy value will the runtime be modified."
- ([provider] (freshener provider (fn [_] true)))
- ([provider auditor]
- (let [listing-atom (atom {})]
- (fn [] (make-fresh listing-atom (provider) auditor)))))
408 src/mmargs/Arguments.java
View
@@ -1,408 +0,0 @@
-//- Copyright © 2010 Micah Martin All Rights Reserved.
-//- mmargs and all included source files are distributed under terms of the MIT License.
-
-// COPIED FROM https://github.com/slagyr/mmargs
-// DO NOT EDIT HERE
-
-package mmargs;
-
-import java.util.*;
-import java.util.regex.Pattern;
-
-public class Arguments
-{
- public static final int MAX_ROW_LENGTH = 72;
-
- private List<Parameter> parameters = new LinkedList<Parameter>();
- private List<Option> options = new LinkedList<Option>();
-
- public void addParameter(String name, String description)
- {
- parameters.add(new Parameter(name, description, true, false));
- }
-
- public void addOptionalParameter(String name, String description)
- {
- parameters.add(new Parameter(name, description, false, false));
- }
-
- public void addMultiParameter(String name, String description)
- {
- parameters.add(new Parameter(name, description, false, true));
- }
-
- public void addSwitchOption(String shortName, String fullName, String description)
- {
- addValueOption(shortName, fullName, null, description);
- }
-
- public void addValueOption(String shortName, String fullName, String valueDescription, String description)
- {
- addValueOption(shortName, fullName, valueDescription, description, false);
- }
-
- private void addValueOption(String shortName, String fullName, String valueDescription, String description, boolean multi)
- {
- if(shortName == null || fullName == null)
- throw new RuntimeException("Options require a shortName and fullName");
- options.add(new Option(shortName, fullName, valueDescription, description, multi));
- }
-
- public void addMultiOption(String shortName, String fullName, String valueDescription, String description)
- {
- addValueOption(shortName, fullName, valueDescription, description, true);
- }
-
-
- public Map<String, Object> parse(String... args)
- {
- HashMap<String, Object> results = new HashMap<String, Object>();
- LinkedList<String> params = parseOptions(args, results);
- LinkedList<String> leftOver = parseParams(params, results);
- processLeftOver(leftOver, results);
- if(leftOver.size() > 0)
- results.put("*leftover", leftOver);
-
- return results;
- }
-
- public String argString()
- {
- StringBuffer buffer = new StringBuffer();
- if(options.size() > 0)
- buffer.append("[options] ");
-
- for(int i = 0; i < parameters.size(); i++)
- {
- if(i > 0)
- buffer.append(" ");
- Parameter parameter = parameters.get(i);
- if(parameter.required)
- buffer.append("<").append(parameter.name).append(">");
- else
- buffer.append("[").append(parameter.name).append(parameter.multi ? "*" : "").append("]");
- }
-
- return buffer.toString();
- }
-
- public String parametersString()
- {
- String[] names = new String[parameters.size()];
- String[] descriptions = new String[parameters.size()];
- for(int i = 0; i < parameters.size(); i++)
- {
- final Parameter parameter = parameters.get(i);
- names[i] = parameter.name;
- descriptions[i] = parameter.description;
- }
- return tabularize(names, descriptions);
- }
-
- public String optionsString()
- {
- String[] heads = new String[options.size()];
- String[] descriptions = new String[options.size()];
- for(int i = 0; i < options.size(); i++)
- {
- final Option option = options.get(i);
- heads[i] = option.head();
- descriptions[i] = option.description;
- }
-
- return tabularize(heads, descriptions);
- }
-
- public Option findOption(String name)
- {
- for(Option option : options)
- {
- if(option.shortName.equals(name) || option.fullName.equals(name))
- return option;
- }
- return null;
- }
-
- private LinkedList<String> parseParams(LinkedList<String> args, HashMap<String, Object> results)
- {
- LinkedList<String> leftOver = new LinkedList<String>();
- LinkedList<Parameter> unfilledParams = new LinkedList<Parameter>(this.parameters);
-
- Parameter parameter = null;
- while(!args.isEmpty())
- {
- String arg = pop(args);
- if(isOption(arg))
- leftOver.add(arg);
- else
- {
- if(unfilledParams.isEmpty())
- {
- if(parameter != null && parameter.multi)
- setValue(results, parameter.name, arg, true);
- else
- leftOver.add(arg);
- }
- else
- {
- parameter = unfilledParams.removeFirst();
- setValue(results, parameter.name, arg, parameter.multi);
- }
- }
- }
-
- for(Parameter unfilledParam : unfilledParams)
- if(unfilledParam.required)
- addError(results, "Missing parameter: " + unfilledParam.name);
-
- return leftOver;
- }
-
- private void setValue(HashMap<String, Object> results, String name, String arg, boolean multi)
- {
- if(multi)
- {
- List values = (List) results.get(name);
- if(values == null)
- {
- values = new LinkedList<String>();
- results.put(name, values);
- }
- values.add(arg);
- }
- else
- results.put(name, arg);
- }
-
- private static String pop(LinkedList<String> args)
- {
- if(args.isEmpty())
- return null;
- else
- return args.removeFirst();
- }
-
- private LinkedList<String> parseOptions(String[] argArray, HashMap<String, Object> results)
- {
- LinkedList<String> args = new LinkedList<String>(Arrays.asList(argArray));
- LinkedList<String> leftOver = new LinkedList<String>();
- while(!args.isEmpty())
- {
- String arg = pop(args);
- if(isOption(arg))
- {
- OptionParser parser = new OptionParser(arg);
- if(findOption(parser.argName) != null)
- parseOption(parser, args, results);
- else
- leftOver.add(arg);
- }
- else
- leftOver.add(arg);
- }
- return leftOver;
- }
-
- private void processLeftOver(LinkedList<String> leftOver, HashMap<String, Object> results)
- {
- for(String arg : leftOver)
- {
- if(isOption(arg))
- addError(results, "Unrecognized option: " + arg);
- else
- addError(results, "Unexpected parameter: " + arg);
- }
- }
-
- private void addError(HashMap<String, Object> results, Object message)
- {
- LinkedList errors = (LinkedList) results.get("*errors");
- if(errors == null)
- {
- errors = new LinkedList<String>();
- results.put("*errors", errors);
- }
- errors.add(message);
- }
-
- private void parseOption(OptionParser parser, LinkedList<String> args, HashMap<String, Object> results)
- {
- Option option = findOption(parser.argName);
- if(option.requiresValue())
- {
- if(parser.usingEquals)
- {
- if(parser.argValue == null)
- addError(results, "Missing value for option: " + parser.argName);
- setValue(results, option.fullName, parser.argValue, option.multi);
- }
- else
- {
- final String nextArg = args.isEmpty() ? null : args.getFirst();
- if(nextArg == null || isOption(nextArg))
- addError(results, "Missing value for option: " + parser.argName);
- setValue(results, option.fullName, nextArg, option.multi);
- pop(args);
- }
- }
- else
- results.put(option.fullName, "on");
- }
-
- private boolean isOption(String arg)
- {
- return arg.startsWith("-");
- }
-
- public static String tabularize(String[] col1, String[] col2)
- {
- int maxLength = 0;
- for(String s : col1)
- {
- if(s.length() > maxLength)
- maxLength = s.length();
- }
-
- StringBuffer buffer = new StringBuffer();
- for(int i = 0; i < col1.length; i++)
- {
- buffer.append(" ").append(col1[i]);
- final int remainingSpaces = maxLength - col1[i].length();
- appendSpaces(buffer, remainingSpaces + 2);
- LinkedList<String> lines = splitIntoLines(col2[i]);
- buffer.append(pop(lines));
- buffer.append(System.getProperty("line.separator"));
- while(!lines.isEmpty())
- {
- appendSpaces(buffer, maxLength + 4);
- buffer.append(pop(lines));
- buffer.append(System.getProperty("line.separator"));
- }
- }
- return buffer.toString();
- }
-
- private static Pattern newlineRegex = Pattern.compile("\\r\\n|\\n", Pattern.MULTILINE);
-
- private static LinkedList<String> splitIntoLines(String value)
- {
- final String[] lines = newlineRegex.split(value);
- LinkedList<String> measuredLines = new LinkedList<String>();
- for(String line : lines)
- {
- while(line.length() > MAX_ROW_LENGTH)
- {
- int splitIndex = findIndexOfSpaceBefore(MAX_ROW_LENGTH, line);
- measuredLines.add(line.substring(0, splitIndex));
- line = line.substring(splitIndex + 1);
- }
- measuredLines.add(line);
- }
- return measuredLines;
- }
-
- private static int findIndexOfSpaceBefore(int end, String line)
- {
- for(int i = end; i > 0; i--)
- {
- if(line.charAt(i) == ' ')
- return i;
- }
- return MAX_ROW_LENGTH;
- }
-
- private static void appendSpaces(StringBuffer buffer, int spaces)
- {
- for(int j = 0; j < spaces; j++)
- buffer.append(" ");
- }
-
- public static class Parameter
- {
- private String name;
- private boolean required;
- private String description;
- private boolean multi;
-
- public Parameter(String name, String description, boolean required, boolean multi)
- {
- this.name = name;
- this.description = description;
- this.required = required;
- this.multi = multi;
- }
- }
-
- public static class Option
- {
- private String shortName;
- private String fullName;
- private String valueDescription;
- private String description;
- private String head;
- private boolean multi;
-
- public Option(String shortName, String fullName, String valueDescription, String description, boolean multi)
- {
- this.shortName = shortName;
- this.fullName = fullName;
- this.valueDescription = valueDescription;
- this.description = description;
- this.multi = multi;
- }
-
- public boolean requiresValue()
- {
- return valueDescription != null;
- }
-
- private String head()
- {
- if(head == null)
- {
- head = "-" + shortName + ", --" + fullName;
- if(requiresValue())
- head += "=<" + valueDescription + ">";
- }
- return head;
- }
- }
-
- private static class OptionParser
- {
- private String argName;
- private String argValue;
- private boolean usingFullName;
- private boolean usingEquals;
-
- public OptionParser(String arg)
- {
- stripDashes(arg);
-
- if(usingFullName)
- {
- int valueIndex = argName.indexOf("=");
- if(valueIndex > 0)
- {
- usingEquals = true;
- argValue = argName.substring(valueIndex + 1);
- argName = argName.substring(0, valueIndex);
- }
- }
- }
-
- private void stripDashes(String arg)
- {
- if(arg.startsWith("--"))
- {
- usingFullName = true;
- argName = arg.substring(2);
- }
- else
- {
- usingFullName = false;
- argName = arg.substring(1);
- }
- }
- }
-}
2  src/speclj/version.clj
View
@@ -5,7 +5,7 @@
(def major 1)
(def minor 3)
(def tiny 1)
-(def snapshot false)
+(def snapshot true)
(def string
(str
(str/join "." (filter identity [major minor tiny]))
Please sign in to comment.
Something went wrong with that request. Please try again.