Skip to content

Commit

Permalink
Merge pull request #9 from stuartmscott/parallel
Browse files Browse the repository at this point in the history
Enable parallel builds.
  • Loading branch information
stuartmscott committed Dec 17, 2015
2 parents 3cdbd7e + a18933c commit 3256512
Show file tree
Hide file tree
Showing 22 changed files with 225 additions and 144 deletions.
2 changes: 1 addition & 1 deletion Match
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

ant test && java -jar out/java/jar/Match.jar sample/
ant test && java -jar out/java/jar/Match.jar .
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<property name="main-class" value="main.Match"/>

<path id="classpath">
<fileset dir="${libraries.directory}" includes="**/*.jar"/>
<fileset dir="${libraries.directory}" includes="**/*.jar" excludes="**/Match*"/>
<pathelement location="${classes.directory}" />
<pathelement location="${classes.tests.directory}" />
</path>
Expand Down
6 changes: 3 additions & 3 deletions match
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@

Set(
name = "junit"
value = "libraries/junit-4.12.jar"
value = "./libraries/junit-4.12.jar"
)

Set(
name = "hamcrest"
value = "libraries/hamcrest-core-1.3.jar"
value = "./libraries/hamcrest-core-1.3.jar"
)

Set(
name = "mockito"
value = "libraries/mockito-all-1.10.19.jar"
value = "./libraries/mockito-all-1.10.19.jar"
)

JavaJar(
Expand Down
14 changes: 7 additions & 7 deletions source/expression/function/Find.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public Find(IMatch match, ITarget target, Map<String, IExpression> parameters) {
*/
@Override
public void configure() {
String match = mTarget.getFile();
int index = match.lastIndexOf('/');
File root = new File(match.substring(0, index));
int index = new File(".").getAbsolutePath().length() - 1;
File root = mTarget.getFile().getParentFile();
File directory = new File(root, mDirectory.resolve());
String path = directory.getAbsolutePath().substring(index);
String pattern = mPattern == null ? ".*" : mPattern.resolve();
scanFiles(directory, mFiles, Pattern.compile(pattern));
scanFiles(directory, path, mFiles, Pattern.compile(pattern));
}

/**
Expand All @@ -68,15 +68,15 @@ public List<String> resolveList() {
return files;
}

private static void scanFiles(File directory, List<String> files, Pattern pattern) {
private static void scanFiles(File directory, String path, List<String> files, Pattern pattern) {
for (File file : directory.listFiles()) {
String fullname = String.format("%s/%s", path, file.getName());
if (file.isFile()) {
String fullname = file.getAbsolutePath();
if (pattern.matcher(fullname).matches()) {
files.add(fullname);
}
} else {
scanFiles(file, files, pattern);
scanFiles(file, fullname, files, pattern);
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions source/expression/function/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@
import expression.IExpression;
import main.IMatch;
import main.ITarget;

import java.io.File;
import java.lang.reflect.Constructor;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

public abstract class Function extends Expression implements IFunction {

public static final String ANONYMOUS = "_";
public static final String CLASS_OUTPUT = "out/java/classes";
public static final String CLASS_OUTPUT = "./out/java/classes";
public static final String DIRECTORY = "directory";
public static final String JAR_OUTPUT = "out/java/jar";
public static final String JAR_OUTPUT = "./out/java/jar";
public static final String LIBRARY = "library";
public static final String MAIN_CLASS = "main_class";
public static final String NAME = "name";
Expand Down Expand Up @@ -82,5 +85,4 @@ public static Function getFunction(String name, IMatch match, ITarget target, Ma
return null;
}
}

}
19 changes: 13 additions & 6 deletions source/expression/function/JavaJUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/
package expression.function;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import main.IMatch;
import main.ITarget;
Expand All @@ -27,9 +30,9 @@

public class JavaJUnit extends Function {

private static final String RESULT_OUTPUT = "out/results";
private static final String RESULT_OUTPUT = "./out/results";
private static final String MKDIR_COMMAND = "mkdir -p %s";
private static final String RUN_COMMAND = "java %s org.junit.runner.JUnitCore %s > %s";
private static final String RUN_COMMAND = "java %s org.junit.runner.JUnitCore %s | tee %s";

private String mName;
private String mMainClass;
Expand Down Expand Up @@ -65,14 +68,18 @@ public void configure() {
@Override
public String resolve() {
List<String> libraries = new ArrayList<>();
Set<String> libs = new HashSet<>();
libs.add("junit");
libs.add("hamcrest");
libs.add("mockito");
if (hasParameter(LIBRARY)) {
for (String library : getParameter(LIBRARY).resolveList()) {
libraries.add(mMatch.getProperty(library));
libs.add(library);
}
}
libraries.add(mMatch.getProperty("junit"));
libraries.add(mMatch.getProperty("hamcrest"));
libraries.add(mMatch.getProperty("mockito"));
for (String library : libs) {
libraries.add(mMatch.getProperty(library));
}
String classpath = String.format("-cp %s", Utilities.join(":", libraries));
mMatch.runCommand(String.format(MKDIR_COMMAND, RESULT_OUTPUT));
mMatch.runCommand(String.format(RUN_COMMAND, classpath, mMainClass, mOutput));
Expand Down
5 changes: 4 additions & 1 deletion source/expression/function/JavaJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import main.ITarget;
import main.Utilities;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -75,7 +76,9 @@ public String resolve() {
String jarClasspath = "";
if (hasParameter(LIBRARY)) {
for (String library : getParameter(LIBRARY).resolveList()) {
libraries.add(mMatch.getProperty(library));
String path = mMatch.getProperty(library);
mMatch.awaitFile(path);
libraries.add(path);
}
javacClasspath = String.format("-cp %s", Utilities.join(":", libraries));
jarClasspath = String.format("Class-Path: %s\n", Utilities.join(":", libraries));
Expand Down
7 changes: 7 additions & 0 deletions source/frontend/ILexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@
*/
package frontend;

import java.io.File;

public interface ILexer {

/**
* Gets the file being parsed.
*/
File getFile();

/**
* Gets the filename being parsed.
*/
Expand Down
23 changes: 20 additions & 3 deletions source/frontend/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@

import main.IMatch;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.util.List;

public class Lexer implements ILexer {

public IMatch mMatch;
public File mFile;
public String mFilename;
public int mLineNumber = 1;
public List<Lexem> mLexems;
Expand All @@ -35,11 +39,24 @@ public class Lexer implements ILexer {
public String mNextValue;
public Token mCurrentToken;

public Lexer(IMatch match, List<Lexem> lexems, String filename, InputStream input) {
public Lexer(IMatch match, List<Lexem> lexems, File file) {
mMatch = match;
mLexems = lexems;
mFilename = filename;
mInput = input;
mFile = file;
mFilename = file.getAbsolutePath();
try {
mInput = new FileInputStream(file);
} catch (FileNotFoundException e) {
mMatch.error(e);
}
}

/**
* {@inheritDoc}
*/
@Override
public File getFile() {
return mFile;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions source/frontend/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import main.ITarget;
import main.Target;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -33,13 +34,13 @@ public class Parser implements IParser {

private ILexer mLexer;
private IMatch mMatch;
private String mFile;
private File mFile;
private ITarget mTarget;

public Parser(IMatch match, ILexer lexer) {
mMatch = match;
mLexer = lexer;
mFile = lexer.getFilename();
mFile = lexer.getFile();
}

/**
Expand Down
18 changes: 4 additions & 14 deletions source/main/IMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public interface IMatch {
void setProperty(String key, String value);

/**
* Prints the message to the console.
* Prints the warning to the console.
*/
void print(String message);
void warn(String message);

/**
* Prints the warning to the console.
* Prints the message to the console.
*/
void warn(String message);
void println(String message);

/**
* Aborts the build and prints the message to the console.
Expand Down Expand Up @@ -68,14 +68,4 @@ public interface IMatch {
* Runs the given command.
*/
void runCommand(String command);

/**
* Sets whether the build runs silently.
*/
void setQuiet(boolean quiet);

/**
* Sets whether the build prints verbosely.
*/
void setVerbose(boolean verbose);
}
4 changes: 3 additions & 1 deletion source/main/ITarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

import expression.function.IFunction;

import java.io.File;

public interface ITarget {

/**
* @return the match file
*/
String getFile();
File getFile();

/**
* Sets the function that will build this target.
Expand Down
Loading

0 comments on commit 3256512

Please sign in to comment.