summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build.gradle9
-rw-r--r--buildSrc/build.gradle12
-rw-r--r--buildSrc/src/main/groovy/VelocityPlugin.groovy33
-rw-r--r--buildSrc/src/main/groovy/VelocityTask.groovy58
-rw-r--r--gradle.properties2
-rw-r--r--gradle/buildscript.gradle1
-rw-r--r--src/main/java/org/anarres/cpp/CppTask.java2
-rw-r--r--src/main/java/org/anarres/cpp/DefaultPreprocessorListener.java89
-rw-r--r--src/main/java/org/anarres/cpp/FileLexerSource.java2
-rw-r--r--src/main/java/org/anarres/cpp/InputLexerSource.java2
-rw-r--r--src/main/java/org/anarres/cpp/Main.java2
-rw-r--r--src/main/java/org/anarres/cpp/PreprocessorListener.java41
-rw-r--r--src/main/java/org/anarres/cpp/Source.java5
-rw-r--r--src/test/java/org/anarres/cpp/ErrorTest.java4
14 files changed, 110 insertions, 152 deletions
diff --git a/build.gradle b/build.gradle
index c99935d..9c377cb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -26,7 +26,7 @@ apply from: file('gradle/license.gradle')
// apply from: file('gradle/release.gradle')
apply plugin: 'application'
-apply plugin: VelocityPlugin
+apply plugin: 'velocity'
dependencies {
compile 'com.google.code.findbugs:jsr305:2.0.2'
@@ -38,9 +38,10 @@ dependencies {
velocity {
def p = project
- context {
- version = p.version
- }
+ Map m = [
+ version: project.version
+ ]
+ context m
}
test {
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
deleted file mode 100644
index 324859d..0000000
--- a/buildSrc/build.gradle
+++ /dev/null
@@ -1,12 +0,0 @@
-apply plugin: 'groovy'
-apply plugin: 'idea'
-
-repositories {
- mavenCentral()
-}
-
-dependencies {
- compile gradleApi()
- compile 'org.apache.velocity:velocity:1.7'
-}
-
diff --git a/buildSrc/src/main/groovy/VelocityPlugin.groovy b/buildSrc/src/main/groovy/VelocityPlugin.groovy
deleted file mode 100644
index cc8741a..0000000
--- a/buildSrc/src/main/groovy/VelocityPlugin.groovy
+++ /dev/null
@@ -1,33 +0,0 @@
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.apache.velocity.VelocityContext
-import org.apache.velocity.app.VelocityEngine
-import org.apache.velocity.runtime.log.SystemLogChute
-
-class VelocityPluginExtension {
- String inputDir = "src/main/velocity"
- String outputDir = "build/generated-sources/velocity"
- Map<String, Object> contextValues = [:]
- def context(Closure closure) {
- contextValues.with closure
- }
-}
-
-class VelocityPlugin implements Plugin<Project> {
- void apply(Project project) {
-
- project.extensions.create("velocity", VelocityPluginExtension)
-
- project.task('velocityVpp', type: VelocityTask) {
- description "Preprocesses velocity template files."
- inputDir = project.file(project.velocity.inputDir)
- outputDir = project.file(project.velocity.outputDir)
- contextValues = project.velocity.contextValues
- }
-
- project.compileJava.dependsOn(project.velocityVpp)
- project.sourceSets.main.java.srcDir project.velocity.outputDir
-
- }
-}
-
diff --git a/buildSrc/src/main/groovy/VelocityTask.groovy b/buildSrc/src/main/groovy/VelocityTask.groovy
deleted file mode 100644
index 6a36903..0000000
--- a/buildSrc/src/main/groovy/VelocityTask.groovy
+++ /dev/null
@@ -1,58 +0,0 @@
-import org.apache.velocity.VelocityContext
-import org.apache.velocity.app.VelocityEngine
-import org.apache.velocity.runtime.log.SystemLogChute
-import org.gradle.api.DefaultTask
-import org.gradle.api.tasks.InputDirectory
-import org.gradle.api.tasks.OutputDirectory
-import org.gradle.api.tasks.TaskAction
-
-class VelocityTask extends DefaultTask {
-
- @InputDirectory
- File inputDir
-
- @OutputDirectory
- File outputDir
-
- String filter = '**/*.java'
-
- File includeDir
-
- Map<String, Object> contextValues = [:]
-
- @TaskAction
- void run() {
- outputDir.deleteDir()
- outputDir.mkdirs()
- // println "Velocity: $inputDir -> $outputDir"
-
- VelocityEngine engine = new VelocityEngine()
- engine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, SystemLogChute.class.name)
- engine.setProperty(VelocityEngine.RESOURCE_LOADER, "file")
- engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_CACHE, "true")
- if (includeDir != null)
- engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, includeDir.getAbsolutePath())
- def inputFiles = project.fileTree(
- dir: inputDir,
- include: filter
- )
- inputFiles.visit { e ->
- if (e.file.isFile()) {
- File outputFile = e.relativePath.getFile(outputDir)
- VelocityContext context = new VelocityContext()
- contextValues.each { context.put(it.key, it.value) }
- context.put('project', project)
- context.put('package', e.relativePath.parent.segments.join('.'))
- context.put('class', e.relativePath.lastName.replaceFirst("\\.java\$", ""))
- // println "Parsing ${e.file}"
- e.file.withReader { reader ->
- outputFile.parentFile.mkdirs()
- outputFile.withWriter { writer ->
- engine.evaluate(context, writer, e.relativePath.toString(), reader)
- }
- }
- }
- }
- }
-}
-
diff --git a/gradle.properties b/gradle.properties
index 162590e..54aef26 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1 +1 @@
-version=1.4.2
+version=1.4.3
diff --git a/gradle/buildscript.gradle b/gradle/buildscript.gradle
index ee80ef9..f5cd5c8 100644
--- a/gradle/buildscript.gradle
+++ b/gradle/buildscript.gradle
@@ -9,4 +9,5 @@ dependencies {
classpath "net.saliman:gradle-cobertura-plugin:2.2.2"
// classpath 'gradle-release:gradle-release:1.1.5'
classpath 'org.ajoberstar:gradle-git:0.5.0'
+ classpath 'org.anarres.gradle:gradle-velocity-plugin:1.0.0'
}
diff --git a/src/main/java/org/anarres/cpp/CppTask.java b/src/main/java/org/anarres/cpp/CppTask.java
index 5e17786..55a8eff 100644
--- a/src/main/java/org/anarres/cpp/CppTask.java
+++ b/src/main/java/org/anarres/cpp/CppTask.java
@@ -34,7 +34,7 @@ import org.apache.tools.ant.types.Path;
*/
public class CppTask extends Copy {
- private class Listener extends PreprocessorListener {
+ private class Listener extends DefaultPreprocessorListener {
@Override
protected void print(String msg) {
diff --git a/src/main/java/org/anarres/cpp/DefaultPreprocessorListener.java b/src/main/java/org/anarres/cpp/DefaultPreprocessorListener.java
new file mode 100644
index 0000000..6d3929d
--- /dev/null
+++ b/src/main/java/org/anarres/cpp/DefaultPreprocessorListener.java
@@ -0,0 +1,89 @@
+package org.anarres.cpp;
+
+/*
+ * Anarres C Preprocessor
+ * Copyright (c) 2007-2008, Shevek
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+import javax.annotation.Nonnegative;
+
+/**
+ * A handler for preprocessor events, primarily errors and warnings.
+ *
+ * If no PreprocessorListener is installed in a Preprocessor, all
+ * error and warning events will throw an exception. Installing a
+ * listener allows more intelligent handling of these events.
+ */
+public class DefaultPreprocessorListener implements PreprocessorListener {
+
+ private int errors;
+ private int warnings;
+
+ public DefaultPreprocessorListener() {
+ clear();
+ }
+
+ public void clear() {
+ errors = 0;
+ warnings = 0;
+ }
+
+ @Nonnegative
+ public int getErrors() {
+ return errors;
+ }
+
+ @Nonnegative
+ public int getWarnings() {
+ return warnings;
+ }
+
+ protected void print(String msg) {
+ System.err.println(msg);
+ }
+
+ /**
+ * Handles a warning.
+ *
+ * The behaviour of this method is defined by the
+ * implementation. It may simply record the error message, or
+ * it may throw an exception.
+ */
+ public void handleWarning(Source source, int line, int column,
+ String msg)
+ throws LexerException {
+ warnings++;
+ print(source.getName() + ":" + line + ":" + column
+ + ": warning: " + msg);
+ }
+
+ /**
+ * Handles an error.
+ *
+ * The behaviour of this method is defined by the
+ * implementation. It may simply record the error message, or
+ * it may throw an exception.
+ */
+ public void handleError(Source source, int line, int column,
+ String msg)
+ throws LexerException {
+ errors++;
+ print(source.getName() + ":" + line + ":" + column
+ + ": error: " + msg);
+ }
+
+ public void handleSourceChange(Source source, String event) {
+ }
+
+}
diff --git a/src/main/java/org/anarres/cpp/FileLexerSource.java b/src/main/java/org/anarres/cpp/FileLexerSource.java
index 1505506..bd6cbb7 100644
--- a/src/main/java/org/anarres/cpp/FileLexerSource.java
+++ b/src/main/java/org/anarres/cpp/FileLexerSource.java
@@ -79,7 +79,7 @@ public class FileLexerSource extends LexerSource {
}
@Override
- /* pp */ String getName() {
+ public String getName() {
return getPath();
}
diff --git a/src/main/java/org/anarres/cpp/InputLexerSource.java b/src/main/java/org/anarres/cpp/InputLexerSource.java
index 3e1dcb3..fac7c51 100644
--- a/src/main/java/org/anarres/cpp/InputLexerSource.java
+++ b/src/main/java/org/anarres/cpp/InputLexerSource.java
@@ -53,7 +53,7 @@ public class InputLexerSource extends LexerSource {
}
@Override
- /* pp */ String getName() {
+ public String getName() {
return "standard input";
}
diff --git a/src/main/java/org/anarres/cpp/Main.java b/src/main/java/org/anarres/cpp/Main.java
index 1902798..4c50b70 100644
--- a/src/main/java/org/anarres/cpp/Main.java
+++ b/src/main/java/org/anarres/cpp/Main.java
@@ -92,7 +92,7 @@ public class Main {
pp.addFeature(Feature.TRIGRAPHS);
pp.addFeature(Feature.LINEMARKERS);
pp.addWarning(Warning.IMPORT);
- pp.setListener(new PreprocessorListener());
+ pp.setListener(new DefaultPreprocessorListener());
pp.addMacro("__JCPP__");
pp.getSystemIncludePath().add("/usr/local/include");
pp.getSystemIncludePath().add("/usr/include");
diff --git a/src/main/java/org/anarres/cpp/PreprocessorListener.java b/src/main/java/org/anarres/cpp/PreprocessorListener.java
index a5b4339..6a4cb22 100644
--- a/src/main/java/org/anarres/cpp/PreprocessorListener.java
+++ b/src/main/java/org/anarres/cpp/PreprocessorListener.java
@@ -23,31 +23,7 @@ package org.anarres.cpp;
* error and warning events will throw an exception. Installing a
* listener allows more intelligent handling of these events.
*/
-public class PreprocessorListener {
-
- private int errors;
- private int warnings;
-
- public PreprocessorListener() {
- clear();
- }
-
- public void clear() {
- errors = 0;
- warnings = 0;
- }
-
- public int getErrors() {
- return errors;
- }
-
- public int getWarnings() {
- return warnings;
- }
-
- protected void print(String msg) {
- System.err.println(msg);
- }
+public interface PreprocessorListener {
/**
* Handles a warning.
@@ -58,11 +34,7 @@ public class PreprocessorListener {
*/
public void handleWarning(Source source, int line, int column,
String msg)
- throws LexerException {
- warnings++;
- print(source.getName() + ":" + line + ":" + column
- + ": warning: " + msg);
- }
+ throws LexerException;
/**
* Handles an error.
@@ -73,13 +45,8 @@ public class PreprocessorListener {
*/
public void handleError(Source source, int line, int column,
String msg)
- throws LexerException {
- errors++;
- print(source.getName() + ":" + line + ":" + column
- + ": error: " + msg);
- }
+ throws LexerException;
- public void handleSourceChange(Source source, String event) {
- }
+ public void handleSourceChange(Source source, String event);
}
diff --git a/src/main/java/org/anarres/cpp/Source.java b/src/main/java/org/anarres/cpp/Source.java
index ef20803..291113a 100644
--- a/src/main/java/org/anarres/cpp/Source.java
+++ b/src/main/java/org/anarres/cpp/Source.java
@@ -20,6 +20,7 @@ import java.io.Closeable;
import java.io.IOException;
import java.util.Iterator;
import javax.annotation.CheckForNull;
+import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import static org.anarres.cpp.Token.*;
@@ -139,7 +140,8 @@ public abstract class Source implements Iterable<Token>, Closeable {
/**
* Returns the human-readable name of the current Source.
*/
- /* pp */ String getName() {
+ @CheckForNull
+ public String getName() {
Source parent = getParent();
if (parent != null)
return parent.getName();
@@ -149,6 +151,7 @@ public abstract class Source implements Iterable<Token>, Closeable {
/**
* Returns the current line number within this Source.
*/
+ @Nonnegative
public int getLine() {
Source parent = getParent();
if (parent == null)
diff --git a/src/test/java/org/anarres/cpp/ErrorTest.java b/src/test/java/org/anarres/cpp/ErrorTest.java
index 8777452..42240d4 100644
--- a/src/test/java/org/anarres/cpp/ErrorTest.java
+++ b/src/test/java/org/anarres/cpp/ErrorTest.java
@@ -22,7 +22,7 @@ public class ErrorTest {
private void testError(String input) throws Exception {
StringLexerSource sl;
- PreprocessorListener pl;
+ DefaultPreprocessorListener pl;
Preprocessor p;
/* Without a PreprocessorListener, throws an exception. */
@@ -42,7 +42,7 @@ public class ErrorTest {
p = new Preprocessor();
p.addFeature(Feature.CSYNTAX);
p.addInput(sl);
- pl = new PreprocessorListener();
+ pl = new DefaultPreprocessorListener();
p.setListener(pl);
assertNotNull("CPP has listener", p.getListener());
assertTrue(testError(p));