From 9737aecab62ed6841925fbdd31fa9499609861df Mon Sep 17 00:00:00 2001 From: Jeremy Douglass Date: Wed, 7 Aug 2019 11:46:39 -0700 Subject: [PATCH 1/9] migrate-from-ppy: unused code --- hack/migrate-from-ppy.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/hack/migrate-from-ppy.py b/hack/migrate-from-ppy.py index 658a5bf..56e9687 100644 --- a/hack/migrate-from-ppy.py +++ b/hack/migrate-from-ppy.py @@ -1,9 +1,7 @@ import click import os -import lxml from lxml import etree import jinja2 -import copy property_file_name = '.property.yml' property_template_dir = 'hack/templates' From fd78d678050ef5a141c8196d8f34a62840c587c7 Mon Sep 17 00:00:00 2001 From: Jeremy Douglass Date: Wed, 7 Aug 2019 12:00:13 -0700 Subject: [PATCH 2/9] generate-e2e-test.py: change yaml.load() --> yaml.safe_load() --- hack/generate-e2e-test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/generate-e2e-test.py b/hack/generate-e2e-test.py index 6416a29..ee867c3 100755 --- a/hack/generate-e2e-test.py +++ b/hack/generate-e2e-test.py @@ -35,7 +35,7 @@ def generate(self): if os.path.isfile(yaml_file) is not True: return with open(yaml_file, 'r') as f: - config = yaml.load(f.read()) + config = yaml.safe_load(f.read()) print(config) builder.set_reference_url(config['test']['reference']) From b12c9e96ae5d3c8d12ee9885082a5ecc6c3ae64e Mon Sep 17 00:00:00 2001 From: Jeremy Douglass Date: Wed, 7 Aug 2019 12:01:27 -0700 Subject: [PATCH 3/9] migrate-from-ppy.py: use defusedxml instead of lxml --- hack/migrate-from-ppy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/migrate-from-ppy.py b/hack/migrate-from-ppy.py index 56e9687..b832188 100644 --- a/hack/migrate-from-ppy.py +++ b/hack/migrate-from-ppy.py @@ -1,6 +1,6 @@ import click import os -from lxml import etree +from defusedxml import ElementTree as etree import jinja2 property_file_name = '.property.yml' From e5f3eac6310e6c5d50d5344025d2109e687cdab5 Mon Sep 17 00:00:00 2001 From: Jeremy Douglass Date: Wed, 7 Aug 2019 12:05:06 -0700 Subject: [PATCH 4/9] migrate-from-ppy.py: jinja2 autoescape "By default, jinja2 sets autoescape to False. Consider using autoescape=True or use the select_autoescape function to mitigate XSS vulnerabilities." --- hack/migrate-from-ppy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/migrate-from-ppy.py b/hack/migrate-from-ppy.py index b832188..807b841 100644 --- a/hack/migrate-from-ppy.py +++ b/hack/migrate-from-ppy.py @@ -29,7 +29,7 @@ def migrateItem(self, filename): def render(self, tree): property_template = jinja2.Environment( - loader=jinja2.FileSystemLoader( + autoescape=True, loader=jinja2.FileSystemLoader( property_template_dir), trim_blocks='true')\ .get_template(property_template_file_name) subcategory = '' From 4c56781987ddd68855b3a4e707b1fc9e73e12047 Mon Sep 17 00:00:00 2001 From: Jeremy Douglass Date: Wed, 7 Aug 2019 12:53:57 -0700 Subject: [PATCH 5/9] lint: Java style (codacy) --- hack/generate-e2e-test.py | 2 +- src/rprocessing/Runner.java | 4 ++-- src/rprocessing/TreeCopier.java | 8 ++++---- src/rprocessing/exception/RSketchError.java | 3 ++- src/rprocessing/mode/RLangKeywordMap.java | 9 +++++---- src/test/e2e/util/ImageUtils.java | 6 ++++-- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/hack/generate-e2e-test.py b/hack/generate-e2e-test.py index ee867c3..56c0048 100755 --- a/hack/generate-e2e-test.py +++ b/hack/generate-e2e-test.py @@ -72,7 +72,7 @@ def __init__(self, name): def set_core_code(self, code): self.coreCode = code return self - + def set_reference_url(self, url): self.referenceURL = url return self diff --git a/src/rprocessing/Runner.java b/src/rprocessing/Runner.java index 1f1fc66..6c1e5cb 100644 --- a/src/rprocessing/Runner.java +++ b/src/rprocessing/Runner.java @@ -159,8 +159,8 @@ public boolean accept(final File f) { for (final File d : dirs) { searchForExtraStuff(d, entries); } - } else { - // log("No dirs in ", dir); + // } else { + // log("No dirs in ", dir); } } } diff --git a/src/rprocessing/TreeCopier.java b/src/rprocessing/TreeCopier.java index e4894b1..05dbecd 100644 --- a/src/rprocessing/TreeCopier.java +++ b/src/rprocessing/TreeCopier.java @@ -43,10 +43,13 @@ class TreeCopier implements FileVisitor { + private final Path source; + private final Path target; + /** * Copy source file to target location. */ - static void copyFile(final Path source, final Path target) { + private static void copyFile(final Path source, final Path target) { try { Files.copy(source, target, COPY_ATTRIBUTES, REPLACE_EXISTING); } catch (final IOException ioException) { @@ -54,9 +57,6 @@ static void copyFile(final Path source, final Path target) { } } - private final Path source; - private final Path target; - TreeCopier(final Path source, final Path target) { this.source = source; this.target = target; diff --git a/src/rprocessing/exception/RSketchError.java b/src/rprocessing/exception/RSketchError.java index 088e7eb..d39c875 100644 --- a/src/rprocessing/exception/RSketchError.java +++ b/src/rprocessing/exception/RSketchError.java @@ -59,7 +59,8 @@ public String toString() { } // TODO: Support the line and column. - public static RSketchError toSketchException(Throwable t) { + public static RSketchError toSketchException(Throwable terr) { + Throwable t = terr; log(t.getClass().toString()); if (t instanceof RuntimeException && t.getCause() != null) { t = t.getCause(); diff --git a/src/rprocessing/mode/RLangKeywordMap.java b/src/rprocessing/mode/RLangKeywordMap.java index 5822814..2cdc39d 100644 --- a/src/rprocessing/mode/RLangKeywordMap.java +++ b/src/rprocessing/mode/RLangKeywordMap.java @@ -80,15 +80,16 @@ protected int getSegmentMapKey(final Segment s, final int off, final int len) { // private members class Keyword { + + public char[] keyword; + public byte id; + public Keyword next; + public Keyword(final char[] keyword, final byte id, final Keyword next) { this.keyword = keyword; this.id = id; this.next = next; } - - public char[] keyword; - public byte id; - public Keyword next; } } diff --git a/src/test/e2e/util/ImageUtils.java b/src/test/e2e/util/ImageUtils.java index 6b75ebe..778601f 100644 --- a/src/test/e2e/util/ImageUtils.java +++ b/src/test/e2e/util/ImageUtils.java @@ -28,11 +28,13 @@ private static float imgDifference(PImage i0, PImage i1) { i1.loadPixels(); int[] ip1 = i1.pixels; for (int n = 0; n < ip0.length; n++) { - int pxl0 = ip0[n], r0, g0, b0; - int pxl1 = ip1[n], r1, g1, b1; + int pxl0 = ip0[n] + int r0, g0, b0; r0 = (pxl0 >> 20) & 0xF; g0 = (pxl0 >> 12) & 0xF; b0 = (pxl0 >> 4) & 0xF; + int pxl1 = ip1[n] + int r1, g1, b1; r1 = (pxl1 >> 20) & 0xF; g1 = (pxl1 >> 12) & 0xF; b1 = (pxl1 >> 4) & 0xF; From 8046a57d17c807934e3dc7d4ad1080abb986cdd8 Mon Sep 17 00:00:00 2001 From: Jeremy Douglass Date: Wed, 7 Aug 2019 12:54:39 -0700 Subject: [PATCH 6/9] lint: Java style (codacy): method DiffImage --> diffImage --- src/test/e2e/core/E2eTestBase.java | 2 +- src/test/e2e/util/ImageUtils.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/e2e/core/E2eTestBase.java b/src/test/e2e/core/E2eTestBase.java index a19f200..40f4b19 100644 --- a/src/test/e2e/core/E2eTestBase.java +++ b/src/test/e2e/core/E2eTestBase.java @@ -23,7 +23,7 @@ protected String referenceImage(String path) throws MalformedURLException { } protected float diffImage(File file, String fileURL) throws MalformedURLException, IOException { - return ImageUtils.DiffImage(file, new URL(fileURL)); + return ImageUtils.diffImage(file, new URL(fileURL)); } protected float diffImageWithProcessingReference(File file, String referenceURL) diff --git a/src/test/e2e/util/ImageUtils.java b/src/test/e2e/util/ImageUtils.java index 778601f..223218c 100644 --- a/src/test/e2e/util/ImageUtils.java +++ b/src/test/e2e/util/ImageUtils.java @@ -14,7 +14,8 @@ * @author github.com/gaocegege */ public class ImageUtils { - public static float DiffImage(File actualFile, URL testURL) throws IOException { + + public static float diffImage(File actualFile, URL testURL) throws IOException { PImage actualImage = new PImage(ImageIO.read(actualFile)); PImage testImage = new PImage(ImageIO.read(testURL)); From f625699e838436dce983d8af1c41e6a08743bb7c Mon Sep 17 00:00:00 2001 From: Jeremy Douglass Date: Wed, 7 Aug 2019 12:55:39 -0700 Subject: [PATCH 7/9] lint: shell style (codacy): use $() command substitution style --- .docker/run-examples.sh | 2 +- scripts/deploy.sh | 4 ++-- scripts/utils/generator-util.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 scripts/utils/generator-util.sh diff --git a/.docker/run-examples.sh b/.docker/run-examples.sh index b201d8e..8eae631 100755 --- a/.docker/run-examples.sh +++ b/.docker/run-examples.sh @@ -5,7 +5,7 @@ # Input: # $1 Log string. function log { - echo -e "[`date`] ${1}" + echo -e "[$(date)] ${1}" } root=$(dirname "${BASH_SOURCE}")/.. diff --git a/scripts/deploy.sh b/scripts/deploy.sh index c3a00ec..d8151e3 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -10,7 +10,7 @@ numberOfParams=2 # Input: # $1 Log string. function log { - echo -e "[`date`] ${1}" + echo -e "[$(date)] ${1}" } function help { @@ -34,7 +34,7 @@ function deploy { commitid=$(git log -n1 --format="%h") version=${1} full_version=${2} - date=`date "+%Y/%m/%d %R"` + date=$(date "+%Y/%m/%d %R") perl -i -pe "s|\@\@mode-version\@\@|${version}|g" docs/RLangMode.txt perl -i -pe "s|\@\@pretty-version\@\@|${full_version}|g" docs/RLangMode.txt diff --git a/scripts/utils/generator-util.sh b/scripts/utils/generator-util.sh old mode 100644 new mode 100755 index 6d58641..e65a006 --- a/scripts/utils/generator-util.sh +++ b/scripts/utils/generator-util.sh @@ -5,7 +5,7 @@ # Input: # $1 Log string. function log { - echo -e "[`date`] ${1}" + echo -e "[$(date)] ${1}" } function help { From 374ad7ab0b41d11c11452aceae3f28ed77903521 Mon Sep 17 00:00:00 2001 From: Jeremy Douglass Date: Wed, 7 Aug 2019 13:26:03 -0700 Subject: [PATCH 8/9] lint: Java (codacy) --- hack/generate-e2e-test.py | 2 +- src/rprocessing/Runner.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hack/generate-e2e-test.py b/hack/generate-e2e-test.py index 56c0048..728eee5 100755 --- a/hack/generate-e2e-test.py +++ b/hack/generate-e2e-test.py @@ -12,7 +12,7 @@ class Generator(object): def __init__(self): self.output_dir = e2e_test_dir self.reference_dir = reference_dir - + def generate(self): for dirname in os.listdir(self.reference_dir): item_dir = os.path.join(self.reference_dir, dirname) diff --git a/src/rprocessing/Runner.java b/src/rprocessing/Runner.java index 6c1e5cb..c8aedaa 100644 --- a/src/rprocessing/Runner.java +++ b/src/rprocessing/Runner.java @@ -131,8 +131,8 @@ public boolean accept(final File dir, final String name) { }); if (dlls != null && dlls.length > 0) { entries.add(dir.getAbsolutePath()); - } else { - // log("No DLLs in ", dir); + // } else { + // log("No DLLs in ", dir); } final File[] jars = dir.listFiles(new FilenameFilter() { @@ -145,8 +145,8 @@ public boolean accept(final File dir, final String name) { for (final File jar : jars) { entries.add(jar.getAbsolutePath()); } - } else { - // log("No JARs in ", dir); + // } else { + // log("No JARs in ", dir); } final File[] dirs = dir.listFiles(new FileFilter() { From 4b0abb38876229dd27956368f5097b6299a74f9d Mon Sep 17 00:00:00 2001 From: Jeremy Douglass Date: Wed, 7 Aug 2019 13:26:35 -0700 Subject: [PATCH 9/9] Dockerfile: clean apt-get --- Dockerfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index de208f5..1bbdfd0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,12 @@ RUN mkdir -p /code/runner # Install base package. RUN apt-get update && \ - apt-get install -y \ + apt-get install -y --no-install-recommends \ curl \ - ant - + ant \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + # Download Processing. # Dev operation: copy processing into the image. # COPY processing-3.3.3-linux64.tgz /code/processing.tgz