Skip to content
Permalink
Browse files

Bump to 3.4.0. Require Java 8. Various code simplifications and plugi…

…n / dep updates
  • Loading branch information...
srowen committed May 13, 2019
1 parent 39d50c1 commit f1683e1f4f670a83c37f6858a7b3db70080e04ae
Showing with 249 additions and 584 deletions.
  1. +3 −6 .travis.yml
  2. +2 −2 android-core/pom.xml
  3. +2 −2 android-integration/pom.xml
  4. +4 −4 android-integration/src/main/java/com/google/zxing/integration/android/IntentIntegrator.java
  5. +1 −1 android/pom.xml
  6. +1 −1 android/src/com/google/zxing/client/android/history/HistoryItemAdapter.java
  7. +3 −3 core/pom.xml
  8. +4 −4 core/src/main/java/com/google/zxing/common/HybridBinarizer.java
  9. +1 −1 core/src/main/java/com/google/zxing/common/StringUtils.java
  10. +2 −2 core/src/main/java/com/google/zxing/datamatrix/detector/Detector.java
  11. +10 −10 core/src/main/java/com/google/zxing/datamatrix/encoder/DefaultPlacement.java
  12. +20 −47 core/src/main/java/com/google/zxing/multi/qrcode/QRCodeMultiReader.java
  13. +2 −16 core/src/main/java/com/google/zxing/multi/qrcode/detector/MultiFinderPatternFinder.java
  14. +2 −1 core/src/main/java/com/google/zxing/oned/Code39Writer.java
  15. +1 −1 core/src/main/java/com/google/zxing/oned/MultiFormatUPCEANReader.java
  16. +44 −39 core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java
  17. +0 −42 core/src/main/java/com/google/zxing/oned/rss/RSSUtils.java
  18. +1 −1 core/src/main/java/com/google/zxing/oned/rss/expanded/ExpandedPair.java
  19. +0 −4 core/src/main/java/com/google/zxing/oned/rss/expanded/ExpandedRow.java
  20. +77 −86 core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java
  21. +4 −4 core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01393xDecoder.java
  22. +0 −4 core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/DecodedNumeric.java
  23. +1 −6 core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/FieldParser.java
  24. +2 −1 core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/GeneralAppIdDecoder.java
  25. +3 −4 core/src/main/java/com/google/zxing/qrcode/decoder/Version.java
  26. +2 −3 core/src/main/java/com/google/zxing/qrcode/detector/FinderPatternFinder.java
  27. +4 −10 core/src/test/java/com/google/zxing/multi/qrcode/MultiQRCodeTestCase.java
  28. +1 −1 core/src/test/java/com/google/zxing/oned/rss/expanded/RSSExpandedImage2resultTestCase.java
  29. +2 −14 core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java
  30. +9 −48 core/src/test/java/com/google/zxing/qrcode/decoder/DataMaskTestCase.java
  31. +2 −2 javase/pom.xml
  32. +0 −47 javase/src/main/java/com/google/zxing/client/j2se/Base64Decoder.java
  33. +7 −13 javase/src/main/java/com/google/zxing/client/j2se/HtmlAssetTranslator.java
  34. +2 −1 javase/src/main/java/com/google/zxing/client/j2se/ImageReader.java
  35. +0 −36 javase/src/main/java/com/google/zxing/client/j2se/JAXBBase64Decoder.java
  36. +0 −38 javase/src/main/java/com/google/zxing/client/j2se/Java8Base64Decoder.java
  37. +3 −7 javase/src/main/java/com/google/zxing/client/j2se/StringsResourceTranslator.java
  38. +0 −35 javase/src/test/java/com/google/zxing/client/j2se/Base64DecoderTestCase.java
  39. +17 −25 pom.xml
  40. +0 −2 src/checkstyle/checkstyle.xml
  41. +2 −2 zxing.appspot.com/pom.xml
  42. +6 −6 zxingorg/pom.xml
  43. +2 −2 zxingorg/src/test/java/com/google/zxing/web/DoSFilterTestCase.java
@@ -7,14 +7,11 @@ script:
- find $HOME/.m2/repository/com/google/zxing -name "*SNAPSHOT" -type d -delete
matrix:
include:
# Covers Java 7, Open JDK, and code coverage
- jdk: openjdk7
env: JACOCO=-Pjacoco
# Covers Java 8, Android apps
- jdk: openjdk8
env: ANDROID_HOME=$HOME/android-sdk-linux
env:
- JACOCO=-Pjacoco
- ANDROID_HOME=$HOME/android-sdk-linux
before_install: if [ ! -d $HOME/android-sdk-linux/platforms ]; then curl -s https://storage.googleapis.com/zxing-build/android-sdk-linux.tar.bz2 | bunzip2 | tar xf - -C $HOME; else ls -l $HOME/android-sdk-linux; fi
# Covers Java 9
- jdk: oraclejdk9
cache:
directories:
@@ -18,7 +18,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>android-core</artifactId>
<version>3.3.4-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
@@ -31,7 +31,7 @@
<parent>
<groupId>com.google.zxing</groupId>
<artifactId>zxing-parent</artifactId>
<version>3.3.4-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
</parent>

<name>ZXing Android Core</name>
@@ -18,7 +18,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>android-integration</artifactId>
<version>3.3.4-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
@@ -31,7 +31,7 @@
<parent>
<groupId>com.google.zxing</groupId>
<artifactId>zxing-parent</artifactId>
<version>3.3.4-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
</parent>

<name>ZXing Android Integration lib</name>
@@ -40,7 +40,7 @@
* way to invoke barcode scanning and receive the result, without any need to integrate, modify, or learn the
* project's source code.</p>
*
* <h2>Initiating a barcode scan</h2>
* <h1>Initiating a barcode scan</h1>
*
* <p>To integrate, create an instance of {@code IntentIntegrator} and call {@link #initiateScan()} and wait
* for the result in your app.</p>
@@ -88,13 +88,13 @@
* do so. The apps that are allowed to response can be set with {@link #setTargetApplications(List)}.
* For example, set to {@link #TARGET_BARCODE_SCANNER_ONLY} to only target the Barcode Scanner app itself.</p>
*
* <h2>Sharing text via barcode</h2>
* <h1>Sharing text via barcode</h1>
*
* <p>To share text, encoded as a QR Code on-screen, similarly, see {@link #shareText(CharSequence)}.</p>
*
* <p>Some code, particularly download integration, was contributed from the Anobiit application.</p>
*
* <h2>Enabling experimental barcode formats</h2>
* <h1>Enabling experimental barcode formats</h1>
*
* <p>Some formats are not enabled by default even when scanning with {@link #ALL_CODE_TYPES}, such as
* PDF417. Use {@link #initiateScan(Collection)} with
@@ -151,7 +151,7 @@
private String buttonYes;
private String buttonNo;
private List<String> targetApplications;
private final Map<String,Object> moreExtras = new HashMap<String,Object>(3);
private final Map<String,Object> moreExtras = new HashMap<>(3);

/**
* @param activity {@link Activity} invoking the integration
@@ -39,7 +39,7 @@
<parent>
<groupId>com.google.zxing</groupId>
<artifactId>zxing-parent</artifactId>
<version>3.3.4-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
</parent>

<build>
@@ -34,7 +34,7 @@
private final Context activity;

HistoryItemAdapter(Context activity) {
super(activity, R.layout.history_list_item, new ArrayList<HistoryItem>());
super(activity, R.layout.history_list_item, new ArrayList<>());
this.activity = activity;
}

@@ -18,7 +18,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>core</artifactId>
<version>3.3.4-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
@@ -32,7 +32,7 @@
<parent>
<groupId>com.google.zxing</groupId>
<artifactId>zxing-parent</artifactId>
<version>3.3.4-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
</parent>

<name>ZXing Core</name>
@@ -66,7 +66,7 @@
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.5.0</version> <!-- 4.0.0 requires Java 8 -->
<version>4.2.0</version>
<executions>
<execution>
<goals>
@@ -112,13 +112,13 @@ private static void calculateThresholdForBlock(byte[] luminances,
if (yoffset > maxYOffset) {
yoffset = maxYOffset;
}
int top = cap(y, 2, subHeight - 3);
int top = cap(y, subHeight - 3);
for (int x = 0; x < subWidth; x++) {
int xoffset = x << BLOCK_SIZE_POWER;
if (xoffset > maxXOffset) {
xoffset = maxXOffset;
}
int left = cap(x, 2, subWidth - 3);
int left = cap(x, subWidth - 3);
int sum = 0;
for (int z = -2; z <= 2; z++) {
int[] blackRow = blackPoints[top + z];
@@ -130,8 +130,8 @@ private static void calculateThresholdForBlock(byte[] luminances,
}
}

private static int cap(int value, int min, int max) {
return value < min ? min : value > max ? max : value;
private static int cap(int value, int max) {
return value < 2 ? 2 : value > max ? max : value;
}

/**
@@ -166,7 +166,7 @@ public static String guessEncoding(byte[] bytes, Map<DecodeHintType,?> hints) {
if (canBeUTF8 && (utf8bom || utf2BytesChars + utf3BytesChars + utf4BytesChars > 0)) {
return UTF8;
}
// Easy -- if assuming Shift_JIS or at least 3 valid consecutive not-ascii characters (and no evidence it can't be), done
// Easy -- if assuming Shift_JIS or >= 3 valid consecutive not-ascii characters (and no evidence it can't be), done
if (canBeShiftJIS && (ASSUME_SHIFT_JIS || sjisMaxKatakanaWordLength >= 3 || sjisMaxDoubleBytesWordLength >= 3)) {
return SHIFT_JIS;
}
@@ -87,13 +87,13 @@ public DetectorResult detect() throws NotFoundException {
return new DetectorResult(bits, new ResultPoint[]{topLeft, bottomLeft, bottomRight, topRight});
}

private ResultPoint shiftPoint(ResultPoint point, ResultPoint to, int div) {
private static ResultPoint shiftPoint(ResultPoint point, ResultPoint to, int div) {
float x = (to.getX() - point.getX()) / (div + 1);
float y = (to.getY() - point.getY()) / (div + 1);
return new ResultPoint(point.getX() + x, point.getY() + y);
}

private ResultPoint moveAway(ResultPoint point, float fromX, float fromY) {
private static ResultPoint moveAway(ResultPoint point, float fromX, float fromY) {
float x = point.getX();
float y = point.getY();

@@ -63,8 +63,8 @@ private void setBit(int col, int row, boolean bit) {
bits[row * numcols + col] = (byte) (bit ? 1 : 0);
}

private boolean hasBit(int col, int row) {
return bits[row * numcols + col] >= 0;
private boolean noBit(int col, int row) {
return bits[row * numcols + col] < 0;
}

public final void place() {
@@ -73,7 +73,7 @@ public final void place() {
int col = 0;

do {
/* repeatedly first check for one of the special corner cases, then... */
// repeatedly first check for one of the special corner cases, then...
if ((row == numrows) && (col == 0)) {
corner1(pos++);
}
@@ -86,9 +86,9 @@ public final void place() {
if ((row == numrows + 4) && (col == 2) && ((numcols % 8) == 0)) {
corner4(pos++);
}
/* sweep upward diagonally, inserting successive characters... */
// sweep upward diagonally, inserting successive characters...
do {
if ((row < numrows) && (col >= 0) && !hasBit(col, row)) {
if ((row < numrows) && (col >= 0) && noBit(col, row)) {
utah(row, col, pos++);
}
row -= 2;
@@ -97,9 +97,9 @@ public final void place() {
row++;
col += 3;

/* and then sweep downward diagonally, inserting successive characters, ... */
// and then sweep downward diagonally, inserting successive characters, ...
do {
if ((row >= 0) && (col < numcols) && !hasBit(col, row)) {
if ((row >= 0) && (col < numcols) && noBit(col, row)) {
utah(row, col, pos++);
}
row += 2;
@@ -108,11 +108,11 @@ public final void place() {
row += 3;
col++;

/* ...until the entire array is scanned */
// ...until the entire array is scanned
} while ((row < numrows) || (col < numcols));

/* Lastly, if the lower righthand corner is untouched, fill in fixed pattern */
if (!hasBit(numcols - 1, numrows - 1)) {
// Lastly, if the lower right-hand corner is untouched, fill in fixed pattern
if (noBit(numcols - 1, numrows - 1)) {
setBit(numcols - 1, numrows - 1, true);
setBit(numcols - 2, numrows - 2, true);
}
@@ -31,9 +31,9 @@
import com.google.zxing.qrcode.QRCodeReader;
import com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData;

import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Collections;
@@ -97,20 +97,6 @@
}

static List<Result> processStructuredAppend(List<Result> results) {
boolean hasSA = false;

// first, check, if there is at least on SA result in the list
for (Result result : results) {
if (result.getResultMetadata().containsKey(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE)) {
hasSA = true;
break;
}
}
if (!hasSA) {
return results;
}

// it is, second, split the lists and built a new result list
List<Result> newResults = new ArrayList<>();
List<Result> saResults = new ArrayList<>();
for (Result result : results) {
@@ -120,45 +106,32 @@
newResults.add(result);
}
}
if (saResults.isEmpty()) {
return results;
}

// sort and concatenate the SA list items
Collections.sort(saResults, new SAComparator());
StringBuilder concatedText = new StringBuilder();
int rawBytesLen = 0;
int byteSegmentLength = 0;
for (Result saResult : saResults) {
concatedText.append(saResult.getText());
rawBytesLen += saResult.getRawBytes().length;
if (saResult.getResultMetadata().containsKey(ResultMetadataType.BYTE_SEGMENTS)) {
@SuppressWarnings("unchecked")
Iterable<byte[]> byteSegments =
(Iterable<byte[]>) saResult.getResultMetadata().get(ResultMetadataType.BYTE_SEGMENTS);
for (byte[] segment : byteSegments) {
byteSegmentLength += segment.length;
}
}
}
byte[] newRawBytes = new byte[rawBytesLen];
byte[] newByteSegment = new byte[byteSegmentLength];
int newRawBytesIndex = 0;
int byteSegmentIndex = 0;
StringBuilder newText = new StringBuilder();
ByteArrayOutputStream newRawBytes = new ByteArrayOutputStream();
ByteArrayOutputStream newByteSegment = new ByteArrayOutputStream();
for (Result saResult : saResults) {
System.arraycopy(saResult.getRawBytes(), 0, newRawBytes, newRawBytesIndex, saResult.getRawBytes().length);
newRawBytesIndex += saResult.getRawBytes().length;
if (saResult.getResultMetadata().containsKey(ResultMetadataType.BYTE_SEGMENTS)) {
@SuppressWarnings("unchecked")
Iterable<byte[]> byteSegments =
(Iterable<byte[]>) saResult.getResultMetadata().get(ResultMetadataType.BYTE_SEGMENTS);
newText.append(saResult.getText());
byte[] saBytes = saResult.getRawBytes();
newRawBytes.write(saBytes, 0, saBytes.length);
@SuppressWarnings("unchecked")
Iterable<byte[]> byteSegments =
(Iterable<byte[]>) saResult.getResultMetadata().get(ResultMetadataType.BYTE_SEGMENTS);
if (byteSegments != null) {
for (byte[] segment : byteSegments) {
System.arraycopy(segment, 0, newByteSegment, byteSegmentIndex, segment.length);
byteSegmentIndex += segment.length;
newByteSegment.write(segment, 0, segment.length);
}
}
}
Result newResult = new Result(concatedText.toString(), newRawBytes, NO_POINTS, BarcodeFormat.QR_CODE);
if (byteSegmentLength > 0) {
Collection<byte[]> byteSegmentList = new ArrayList<>();
byteSegmentList.add(newByteSegment);
newResult.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegmentList);

Result newResult = new Result(newText.toString(), newRawBytes.toByteArray(), NO_POINTS, BarcodeFormat.QR_CODE);
if (newByteSegment.size() > 0) {
newResult.putMetadata(ResultMetadataType.BYTE_SEGMENTS, Collections.singletonList(newByteSegment.toByteArray()));
}
newResults.add(newResult);
return newResults;
@@ -49,6 +49,7 @@
final class MultiFinderPatternFinder extends FinderPatternFinder {

private static final FinderPatternInfo[] EMPTY_RESULT_ARRAY = new FinderPatternInfo[0];
private static final FinderPattern[] EMPTY_FP_ARRAY = new FinderPattern[0];
private static final FinderPattern[][] EMPTY_FP_2D_ARRAY = new FinderPattern[0][];

// TODO MIN_MODULE_COUNT and MAX_MODULE_COUNT would be great hints to ask the user for
@@ -85,15 +86,6 @@ public int compare(FinderPattern center1, FinderPattern center2) {
}
}

/**
* <p>Creates a finder that will search the image for three finder patterns.</p>
*
* @param image image to search
*/
MultiFinderPatternFinder(BitMatrix image) {
super(image);
}

MultiFinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback) {
super(image, resultPointCallback);
}
@@ -117,13 +109,7 @@ public int compare(FinderPattern center1, FinderPattern center2) {
* Begin HE modifications to safely detect multiple codes of equal size
*/
if (size == 3) {
return new FinderPattern[][]{
new FinderPattern[]{
possibleCenters.get(0),
possibleCenters.get(1),
possibleCenters.get(2)
}
};
return new FinderPattern[][] { possibleCenters.toArray(EMPTY_FP_ARRAY) };
}

// Sort by estimated module size to speed up the upcoming checks
@@ -136,7 +136,8 @@ private static String tryToConvertToExtendedMode(String contents) {
extendedContent.append('%');
extendedContent.append((char) ('P' + (character - 123)));
} else {
throw new IllegalArgumentException("Requested content contains a non-encodable character: '" + contents.charAt(i) + "'");
throw new IllegalArgumentException(
"Requested content contains a non-encodable character: '" + contents.charAt(i) + "'");
}
break;
}
@@ -98,7 +98,7 @@ public Result decodeRow(int rowNumber,
boolean canReturnUPCA = possibleFormats == null || possibleFormats.contains(BarcodeFormat.UPC_A);

if (ean13MayBeUPCA && canReturnUPCA) {
// Transfer the metdata across
// Transfer the metadata across
Result resultUPCA = new Result(result.getText().substring(1),
result.getRawBytes(),
result.getResultPoints(),

0 comments on commit f1683e1

Please sign in to comment.
You can’t perform that action at this time.