Skip to content

Commit e13afbe

Browse files
Merge branch 'codacy'
* codacy: Dockerfile: clean apt-get lint: Java (codacy) lint: shell style (codacy): use $() command substitution style lint: Java style (codacy): method DiffImage --> diffImage lint: Java style (codacy) migrate-from-ppy.py: jinja2 autoescape migrate-from-ppy.py: use defusedxml instead of lxml generate-e2e-test.py: change yaml.load() --> yaml.safe_load() migrate-from-ppy: unused code
2 parents 121c0fc + 4b0abb3 commit e13afbe

File tree

12 files changed

+38
-33
lines changed

12 files changed

+38
-33
lines changed

.docker/run-examples.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Input:
66
# $1 Log string.
77
function log {
8-
echo -e "[`date`] ${1}"
8+
echo -e "[$(date)] ${1}"
99
}
1010

1111
root=$(dirname "${BASH_SOURCE}")/..

Dockerfile

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ RUN mkdir -p /code/runner
55

66
# Install base package.
77
RUN apt-get update && \
8-
apt-get install -y \
8+
apt-get install -y --no-install-recommends \
99
curl \
10-
ant
11-
10+
ant \
11+
&& apt-get clean \
12+
&& rm -rf /var/lib/apt/lists/*
13+
1214
# Download Processing.
1315
# Dev operation: copy processing into the image.
1416
# COPY processing-3.3.3-linux64.tgz /code/processing.tgz

hack/generate-e2e-test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Generator(object):
1212
def __init__(self):
1313
self.output_dir = e2e_test_dir
1414
self.reference_dir = reference_dir
15-
15+
1616
def generate(self):
1717
for dirname in os.listdir(self.reference_dir):
1818
item_dir = os.path.join(self.reference_dir, dirname)
@@ -35,7 +35,7 @@ def generate(self):
3535
if os.path.isfile(yaml_file) is not True:
3636
return
3737
with open(yaml_file, 'r') as f:
38-
config = yaml.load(f.read())
38+
config = yaml.safe_load(f.read())
3939
print(config)
4040
builder.set_reference_url(config['test']['reference'])
4141

@@ -72,7 +72,7 @@ def __init__(self, name):
7272
def set_core_code(self, code):
7373
self.coreCode = code
7474
return self
75-
75+
7676
def set_reference_url(self, url):
7777
self.referenceURL = url
7878
return self

hack/migrate-from-ppy.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import click
22
import os
3-
import lxml
4-
from lxml import etree
3+
from defusedxml import ElementTree as etree
54
import jinja2
6-
import copy
75

86
property_file_name = '.property.yml'
97
property_template_dir = 'hack/templates'
@@ -31,7 +29,7 @@ def migrateItem(self, filename):
3129

3230
def render(self, tree):
3331
property_template = jinja2.Environment(
34-
loader=jinja2.FileSystemLoader(
32+
autoescape=True, loader=jinja2.FileSystemLoader(
3533
property_template_dir), trim_blocks='true')\
3634
.get_template(property_template_file_name)
3735
subcategory = ''

scripts/deploy.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ numberOfParams=2
1717
# Input:
1818
# $1 Log string.
1919
function log {
20-
echo -e "[`date`] ${1}"
20+
echo -e "[$(date)] ${1}"
2121
}
2222

2323
function help {
@@ -41,7 +41,7 @@ function deploy {
4141
commitid=$(git log -n1 --format="%h")
4242
version=${1}
4343
full_version=${2}
44-
date=`date "+%Y/%m/%d %R"`
44+
date=$(date "+%Y/%m/%d %R")
4545

4646
perl -i -pe "s|\@\@mode-version\@\@|${version}|g" docs/RLangMode.txt
4747
perl -i -pe "s|\@\@pretty-version\@\@|${full_version}|g" docs/RLangMode.txt

scripts/utils/generator-util.sh

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Input:
66
# $1 Log string.
77
function log {
8-
echo -e "[`date`] ${1}"
8+
echo -e "[$(date)] ${1}"
99
}
1010

1111
function help {

src/rprocessing/Runner.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ public boolean accept(final File dir, final String name) {
131131
});
132132
if (dlls != null && dlls.length > 0) {
133133
entries.add(dir.getAbsolutePath());
134-
} else {
135-
// log("No DLLs in ", dir);
134+
// } else {
135+
// log("No DLLs in ", dir);
136136
}
137137

138138
final File[] jars = dir.listFiles(new FilenameFilter() {
@@ -145,8 +145,8 @@ public boolean accept(final File dir, final String name) {
145145
for (final File jar : jars) {
146146
entries.add(jar.getAbsolutePath());
147147
}
148-
} else {
149-
// log("No JARs in ", dir);
148+
// } else {
149+
// log("No JARs in ", dir);
150150
}
151151

152152
final File[] dirs = dir.listFiles(new FileFilter() {
@@ -159,8 +159,8 @@ public boolean accept(final File f) {
159159
for (final File d : dirs) {
160160
searchForExtraStuff(d, entries);
161161
}
162-
} else {
163-
// log("No dirs in ", dir);
162+
// } else {
163+
// log("No dirs in ", dir);
164164
}
165165
}
166166
}

src/rprocessing/TreeCopier.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@
4343

4444
class TreeCopier implements FileVisitor<Path> {
4545

46+
private final Path source;
47+
private final Path target;
48+
4649
/**
4750
* Copy source file to target location.
4851
*/
49-
static void copyFile(final Path source, final Path target) {
52+
private static void copyFile(final Path source, final Path target) {
5053
try {
5154
Files.copy(source, target, COPY_ATTRIBUTES, REPLACE_EXISTING);
5255
} catch (final IOException ioException) {
5356
System.err.format("Unable to copy: %s: %s%n", source, ioException);
5457
}
5558
}
5659

57-
private final Path source;
58-
private final Path target;
59-
6060
TreeCopier(final Path source, final Path target) {
6161
this.source = source;
6262
this.target = target;

src/rprocessing/exception/RSketchError.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public String toString() {
5959
}
6060

6161
// TODO: Support the line and column.
62-
public static RSketchError toSketchException(Throwable t) {
62+
public static RSketchError toSketchException(Throwable terr) {
63+
Throwable t = terr;
6364
log(t.getClass().toString());
6465
if (t instanceof RuntimeException && t.getCause() != null) {
6566
t = t.getCause();

src/rprocessing/mode/RLangKeywordMap.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@ protected int getSegmentMapKey(final Segment s, final int off, final int len) {
8080

8181
// private members
8282
class Keyword {
83+
84+
public char[] keyword;
85+
public byte id;
86+
public Keyword next;
87+
8388
public Keyword(final char[] keyword, final byte id, final Keyword next) {
8489
this.keyword = keyword;
8590
this.id = id;
8691
this.next = next;
8792
}
88-
89-
public char[] keyword;
90-
public byte id;
91-
public Keyword next;
9293
}
9394

9495
}

src/test/e2e/core/E2eTestBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected String referenceImage(String path) throws MalformedURLException {
2323
}
2424

2525
protected float diffImage(File file, String fileURL) throws MalformedURLException, IOException {
26-
return ImageUtils.DiffImage(file, new URL(fileURL));
26+
return ImageUtils.diffImage(file, new URL(fileURL));
2727
}
2828

2929
protected float diffImageWithProcessingReference(File file, String referenceURL)

src/test/e2e/util/ImageUtils.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* @author github.com/gaocegege
1515
*/
1616
public class ImageUtils {
17-
public static float DiffImage(File actualFile, URL testURL) throws IOException {
17+
18+
public static float diffImage(File actualFile, URL testURL) throws IOException {
1819
PImage actualImage = new PImage(ImageIO.read(actualFile));
1920
PImage testImage = new PImage(ImageIO.read(testURL));
2021

@@ -28,11 +29,13 @@ private static float imgDifference(PImage i0, PImage i1) {
2829
i1.loadPixels();
2930
int[] ip1 = i1.pixels;
3031
for (int n = 0; n < ip0.length; n++) {
31-
int pxl0 = ip0[n], r0, g0, b0;
32-
int pxl1 = ip1[n], r1, g1, b1;
32+
int pxl0 = ip0[n]
33+
int r0, g0, b0;
3334
r0 = (pxl0 >> 20) & 0xF;
3435
g0 = (pxl0 >> 12) & 0xF;
3536
b0 = (pxl0 >> 4) & 0xF;
37+
int pxl1 = ip1[n]
38+
int r1, g1, b1;
3639
r1 = (pxl1 >> 20) & 0xF;
3740
g1 = (pxl1 >> 12) & 0xF;
3841
b1 = (pxl1 >> 4) & 0xF;

0 commit comments

Comments
 (0)