Plugin updates; misc code simplifications and optimizations

This commit is contained in:
Sean Owen 2019-12-11 15:29:40 -06:00
parent cfe8684669
commit 459c0197a7
23 changed files with 139 additions and 144 deletions

View file

@ -66,7 +66,7 @@
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>4.2.0</version>
<version>4.3.1</version>
<executions>
<execution>
<goals>

View file

@ -577,7 +577,7 @@ public final class Detector {
private final int y;
ResultPoint toResultPoint() {
return new ResultPoint(getX(), getY());
return new ResultPoint(x, y);
}
Point(int x, int y) {

View file

@ -28,8 +28,8 @@ package com.google.zxing.client.result;
*/
abstract class AbstractDoCoMoResultParser extends ResultParser {
static String[] matchDoCoMoPrefixedField(String prefix, String rawText, boolean trim) {
return matchPrefixedField(prefix, rawText, ';', trim);
static String[] matchDoCoMoPrefixedField(String prefix, String rawText) {
return matchPrefixedField(prefix, rawText, ';', true);
}
static String matchSingleDoCoMoPrefixedField(String prefix, String rawText, boolean trim) {

View file

@ -44,8 +44,8 @@ public final class AddressBookAUResultParser extends ResultParser {
String name = matchSinglePrefixedField("NAME1:", rawText, '\r', true);
String pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', true);
String[] phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText, true);
String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true);
String[] phoneNumbers = matchMultipleValuePrefix("TEL", rawText);
String[] emails = matchMultipleValuePrefix("MAIL", rawText);
String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
String[] addresses = address == null ? null : new String[] {address};
@ -67,18 +67,16 @@ public final class AddressBookAUResultParser extends ResultParser {
null);
}
private static String[] matchMultipleValuePrefix(String prefix,
int max,
String rawText,
boolean trim) {
private static String[] matchMultipleValuePrefix(String prefix, String rawText) {
List<String> values = null;
for (int i = 1; i <= max; i++) {
String value = matchSinglePrefixedField(prefix + i + ':', rawText, '\r', trim);
// For now, always 3, and always trim
for (int i = 1; i <= 3; i++) {
String value = matchSinglePrefixedField(prefix + i + ':', rawText, '\r', true);
if (value == null) {
break;
}
if (values == null) {
values = new ArrayList<>(max); // lazy init
values = new ArrayList<>(3); // lazy init
}
values.add(value);
}

View file

@ -29,7 +29,7 @@ import com.google.zxing.Result;
*
* Our understanding of the MECARD format is based on this document:
*
* http://www.mobicode.org.tw/files/OMIA%20Mobile%20Bar%20Code%20Standard%20v3.2.1.doc
* http://www.mobicode.org.tw/files/OMIA%20Mobile%20Bar%20Code%20Standard%20v3.2.1.doc
*
* @author Sean Owen
*/
@ -41,22 +41,22 @@ public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultPar
if (!rawText.startsWith("MECARD:")) {
return null;
}
String[] rawName = matchDoCoMoPrefixedField("N:", rawText, true);
String[] rawName = matchDoCoMoPrefixedField("N:", rawText);
if (rawName == null) {
return null;
}
String name = parseName(rawName[0]);
String pronunciation = matchSingleDoCoMoPrefixedField("SOUND:", rawText, true);
String[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText, true);
String[] emails = matchDoCoMoPrefixedField("EMAIL:", rawText, true);
String[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText);
String[] emails = matchDoCoMoPrefixedField("EMAIL:", rawText);
String note = matchSingleDoCoMoPrefixedField("NOTE:", rawText, false);
String[] addresses = matchDoCoMoPrefixedField("ADR:", rawText, true);
String[] addresses = matchDoCoMoPrefixedField("ADR:", rawText);
String birthday = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);
if (!isStringOfDigits(birthday, 8)) {
// No reason to throw out the whole card because the birthday is formatted wrong.
birthday = null;
}
String[] urls = matchDoCoMoPrefixedField("URL:", rawText, true);
String[] urls = matchDoCoMoPrefixedField("URL:", rawText);
// Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well
// honor it when found in the wild.

View file

@ -31,7 +31,7 @@ import java.util.List;
public final class BizcardResultParser extends AbstractDoCoMoResultParser {
// Yes, we extend AbstractDoCoMoResultParser since the format is very much
// like the DoCoMo MECARD format, but this is not technically one of
// like the DoCoMo MECARD format, but this is not technically one of
// DoCoMo's proposed formats
@Override
@ -45,7 +45,7 @@ public final class BizcardResultParser extends AbstractDoCoMoResultParser {
String fullName = buildName(firstName, lastName);
String title = matchSingleDoCoMoPrefixedField("T:", rawText, true);
String org = matchSingleDoCoMoPrefixedField("C:", rawText, true);
String[] addresses = matchDoCoMoPrefixedField("A:", rawText, true);
String[] addresses = matchDoCoMoPrefixedField("A:", rawText);
String phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText, true);
String phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true);
String phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);

View file

@ -30,7 +30,7 @@ public final class BookmarkDoCoMoResultParser extends AbstractDoCoMoResultParser
return null;
}
String title = matchSingleDoCoMoPrefixedField("TITLE:", rawText, true);
String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText, true);
String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText);
if (rawUri == null) {
return null;
}
@ -38,4 +38,4 @@ public final class BookmarkDoCoMoResultParser extends AbstractDoCoMoResultParser
return URIResultParser.isBasicallyValidURI(uri) ? new URIParsedResult(uri, title) : null;
}
}
}

View file

@ -37,7 +37,7 @@ public final class EmailDoCoMoResultParser extends AbstractDoCoMoResultParser {
if (!rawText.startsWith("MATMSG:")) {
return null;
}
String[] tos = matchDoCoMoPrefixedField("TO:", rawText, true);
String[] tos = matchDoCoMoPrefixedField("TO:", rawText);
if (tos == null) {
return null;
}
@ -61,4 +61,4 @@ public final class EmailDoCoMoResultParser extends AbstractDoCoMoResultParser {
return email != null && ATEXT_ALPHANUMERIC.matcher(email).matches() && email.indexOf('@') >= 0;
}
}
}

View file

@ -36,25 +36,25 @@ public final class VEventResultParser extends ResultParser {
return null;
}
String summary = matchSingleVCardPrefixedField("SUMMARY", rawText, true);
String start = matchSingleVCardPrefixedField("DTSTART", rawText, true);
String summary = matchSingleVCardPrefixedField("SUMMARY", rawText);
String start = matchSingleVCardPrefixedField("DTSTART", rawText);
if (start == null) {
return null;
}
String end = matchSingleVCardPrefixedField("DTEND", rawText, true);
String duration = matchSingleVCardPrefixedField("DURATION", rawText, true);
String location = matchSingleVCardPrefixedField("LOCATION", rawText, true);
String organizer = stripMailto(matchSingleVCardPrefixedField("ORGANIZER", rawText, true));
String end = matchSingleVCardPrefixedField("DTEND", rawText);
String duration = matchSingleVCardPrefixedField("DURATION", rawText);
String location = matchSingleVCardPrefixedField("LOCATION", rawText);
String organizer = stripMailto(matchSingleVCardPrefixedField("ORGANIZER", rawText));
String[] attendees = matchVCardPrefixedField("ATTENDEE", rawText, true);
String[] attendees = matchVCardPrefixedField("ATTENDEE", rawText);
if (attendees != null) {
for (int i = 0; i < attendees.length; i++) {
attendees[i] = stripMailto(attendees[i]);
}
}
String description = matchSingleVCardPrefixedField("DESCRIPTION", rawText, true);
String description = matchSingleVCardPrefixedField("DESCRIPTION", rawText);
String geoString = matchSingleVCardPrefixedField("GEO", rawText, true);
String geoString = matchSingleVCardPrefixedField("GEO", rawText);
double latitude;
double longitude;
if (geoString == null) {
@ -90,14 +90,13 @@ public final class VEventResultParser extends ResultParser {
}
private static String matchSingleVCardPrefixedField(CharSequence prefix,
String rawText,
boolean trim) {
List<String> values = VCardResultParser.matchSingleVCardPrefixedField(prefix, rawText, trim, false);
String rawText) {
List<String> values = VCardResultParser.matchSingleVCardPrefixedField(prefix, rawText, true, false);
return values == null || values.isEmpty() ? null : values.get(0);
}
private static String[] matchVCardPrefixedField(CharSequence prefix, String rawText, boolean trim) {
List<List<String>> values = VCardResultParser.matchVCardPrefixedField(prefix, rawText, trim, false);
private static String[] matchVCardPrefixedField(CharSequence prefix, String rawText) {
List<List<String>> values = VCardResultParser.matchVCardPrefixedField(prefix, rawText, true, false);
if (values == null || values.isEmpty()) {
return null;
}
@ -116,4 +115,4 @@ public final class VEventResultParser extends ResultParser {
return s;
}
}
}

View file

@ -196,8 +196,7 @@ public final class BitMatrix implements Cloneable {
* @param mask XOR mask
*/
public void xor(BitMatrix mask) {
if (width != mask.getWidth() || height != mask.getHeight()
|| rowSize != mask.getRowSize()) {
if (width != mask.width || height != mask.height || rowSize != mask.rowSize) {
throw new IllegalArgumentException("input matrix dimensions do not match");
}
BitArray rowArray = new BitArray(width);
@ -281,17 +280,17 @@ public final class BitMatrix implements Cloneable {
* Modifies this {@code BitMatrix} to represent the same but rotated 180 degrees
*/
public void rotate180() {
int width = getWidth();
int height = getHeight();
BitArray topRow = new BitArray(width);
BitArray bottomRow = new BitArray(width);
for (int i = 0; i < (height + 1) / 2; i++) {
int maxHeight = (height + 1) / 2;
for (int i = 0; i < maxHeight; i++) {
topRow = getRow(i, topRow);
bottomRow = getRow(height - 1 - i, bottomRow);
int bottomRowIndex = height - 1 - i;
bottomRow = getRow(bottomRowIndex, bottomRow);
topRow.reverse();
bottomRow.reverse();
setRow(i, bottomRow);
setRow(height - 1 - i, topRow);
setRow(bottomRowIndex, topRow);
}
}

View file

@ -134,10 +134,6 @@ public final class ErrorCorrection {
}
private static String createECCBlock(CharSequence codewords, int numECWords) {
return createECCBlock(codewords, 0, codewords.length(), numECWords);
}
private static String createECCBlock(CharSequence codewords, int start, int len, int numECWords) {
int table = -1;
for (int i = 0; i < FACTOR_SETS.length; i++) {
if (FACTOR_SETS[i] == numECWords) {
@ -154,7 +150,7 @@ public final class ErrorCorrection {
for (int i = 0; i < numECWords; i++) {
ecc[i] = 0;
}
for (int i = start; i < start + len; i++) {
for (int i = 0; i < codewords.length(); i++) {
int m = ecc[numECWords - 1] ^ codewords.charAt(i);
for (int k = numECWords - 1; k > 0; k--) {
if (m != 0 && poly[k] != 0) {

View file

@ -235,7 +235,7 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
int[] stateCount = new int[5];
for (int i = iSkip - 1; i < maxI; i += iSkip) {
// Get a row of black/white values
clearCounts(stateCount);
doClearCounts(stateCount);
int currentState = 0;
for (int j = 0; j < maxJ; j++) {
if (image.get(j, i)) {
@ -250,9 +250,9 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
if (foundPatternCross(stateCount) && handlePossibleCenter(stateCount, i, j)) { // Yes
// Clear state to start looking again
currentState = 0;
clearCounts(stateCount);
doClearCounts(stateCount);
} else { // No, shift counts back by two
shiftCounts2(stateCount);
doShiftCounts2(stateCount);
currentState = 3;
}
} else {

View file

@ -61,7 +61,7 @@ final class ExpandedRow {
return false;
}
ExpandedRow that = (ExpandedRow) o;
return this.pairs.equals(that.getPairs()) && wasReversed == that.wasReversed;
return this.pairs.equals(that.pairs) && wasReversed == that.wasReversed;
}
@Override

View file

@ -65,14 +65,14 @@ final class BoundingBox {
BoundingBox(BoundingBox boundingBox) {
this.image = boundingBox.image;
this.topLeft = boundingBox.getTopLeft();
this.bottomLeft = boundingBox.getBottomLeft();
this.topRight = boundingBox.getTopRight();
this.bottomRight = boundingBox.getBottomRight();
this.minX = boundingBox.getMinX();
this.maxX = boundingBox.getMaxX();
this.minY = boundingBox.getMinY();
this.maxY = boundingBox.getMaxY();
this.topLeft = boundingBox.topLeft;
this.bottomLeft = boundingBox.bottomLeft;
this.topRight = boundingBox.topRight;
this.bottomRight = boundingBox.bottomRight;
this.minX = boundingBox.minX;
this.maxX = boundingBox.maxX;
this.minY = boundingBox.minY;
this.maxY = boundingBox.maxY;
}
static BoundingBox merge(BoundingBox leftBox, BoundingBox rightBox) throws NotFoundException {

View file

@ -94,7 +94,7 @@ public class FinderPatternFinder {
int[] stateCount = new int[5];
for (int i = iSkip - 1; i < maxI && !done; i += iSkip) {
// Get a row of black/white values
clearCounts(stateCount);
doClearCounts(stateCount);
int currentState = 0;
for (int j = 0; j < maxJ; j++) {
if (image.get(j, i)) {
@ -130,15 +130,15 @@ public class FinderPatternFinder {
}
}
} else {
shiftCounts2(stateCount);
doShiftCounts2(stateCount);
currentState = 3;
continue;
}
// Clear state to start looking again
currentState = 0;
clearCounts(stateCount);
doClearCounts(stateCount);
} else { // No, shift counts back by two
shiftCounts2(stateCount);
doShiftCounts2(stateCount);
currentState = 3;
}
} else {
@ -232,15 +232,25 @@ public class FinderPatternFinder {
}
private int[] getCrossCheckStateCount() {
clearCounts(crossCheckStateCount);
doClearCounts(crossCheckStateCount);
return crossCheckStateCount;
}
@Deprecated
protected final void clearCounts(int[] counts) {
doClearCounts(counts);
}
@Deprecated
protected final void shiftCounts2(int[] stateCount) {
doShiftCounts2(stateCount);
}
protected static void doClearCounts(int[] counts) {
Arrays.fill(counts, 0);
}
protected final void shiftCounts2(int[] stateCount) {
protected static void doShiftCounts2(int[] stateCount) {
stateCount[0] = stateCount[2];
stateCount[1] = stateCount[3];
stateCount[2] = stateCount[4];

View file

@ -65,17 +65,18 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
// barcode image. Force any such pixel to be white:
if ((pixel & 0xFF000000) == 0) {
pixel = 0xFFFFFFFF; // = white
}
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
// 0x200 >> 10 is 0.5, it implements rounding.
buffer[x] =
// white, so we know its luminance is 255
buffer[x] = 0xFF;
} else {
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
// 0x200 >> 10 is 0.5, it implements rounding.
buffer[x] =
(306 * ((pixel >> 16) & 0xFF) +
601 * ((pixel >> 8) & 0xFF) +
117 * (pixel & 0xFF) +
0x200) >> 10;
601 * ((pixel >> 8) & 0xFF) +
117 * (pixel & 0xFF) +
0x200) >> 10;
}
}
raster.setPixels(left, y, width, 1, buffer);
}

View file

@ -125,14 +125,8 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
return barcodeReader;
}
// This workaround is used because AbstractNegativeBlackBoxTestCase overrides this method but does
// not return SummaryResults.
@Test
public void testBlackBox() throws IOException {
testBlackBoxCountingResults(true);
}
private void testBlackBoxCountingResults(boolean assertOnFailure) throws IOException {
assertFalse(testResults.isEmpty());
List<Path> imageFiles = getImageFiles();
@ -235,20 +229,18 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
}
// Then run through again and assert if any failed
if (assertOnFailure) {
for (int x = 0; x < testCount; x++) {
TestResult testResult = testResults.get(x);
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
assertTrue(label,
passedCounts[x] >= testResult.getMustPassCount());
assertTrue("Try harder, " + label,
tryHarderCounts[x] >= testResult.getTryHarderCount());
label = "Rotation " + testResult.getRotation() + " degrees: Too many images misread";
assertTrue(label,
misreadCounts[x] <= testResult.getMaxMisreads());
assertTrue("Try harder, " + label,
tryHarderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads());
}
for (int x = 0; x < testCount; x++) {
TestResult testResult = testResults.get(x);
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
assertTrue(label,
passedCounts[x] >= testResult.getMustPassCount());
assertTrue("Try harder, " + label,
tryHarderCounts[x] >= testResult.getTryHarderCount());
label = "Rotation " + testResult.getRotation() + " degrees: Too many images misread";
assertTrue(label,
misreadCounts[x] <= testResult.getMaxMisreads());
assertTrue("Try harder, " + label,
tryHarderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads());
}
}

View file

@ -51,7 +51,7 @@ import java.util.logging.Logger;
/**
* This class tests Macro PDF417 barcode specific functionality. It ensures that information, which is split into
* several barcodes can be properly combined again to yield the original data content.
*
*
* @author Guenther Grau
*/
public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
@ -69,10 +69,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
@Test
@Override
public void testBlackBox() throws IOException {
testPDF417BlackBoxCountingResults(true);
}
private void testPDF417BlackBoxCountingResults(boolean assertOnFailure) throws IOException {
assertFalse(testResults.isEmpty());
Map<String,List<Path>> imageFiles = getImageFileLists();
@ -157,13 +153,11 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
}
// Then run through again and assert if any failed
if (assertOnFailure) {
for (int x = 0; x < testCount; x++) {
TestResult testResult = testResults.get(x);
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
assertTrue(label, passedCounts[x] >= testResult.getMustPassCount());
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testResult.getTryHarderCount());
}
for (int x = 0; x < testCount; x++) {
TestResult testResult = testResults.get(x);
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
assertTrue(label, passedCounts[x] >= testResult.getMustPassCount());
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testResult.getTryHarderCount());
}
}

View file

@ -16,7 +16,7 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>javase</artifactId>
<version>3.4.1-SNAPSHOT</version>
<packaging>jar</packaging>
@ -29,7 +29,7 @@
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.72</version>
<version>1.78</version>
</dependency>
<dependency>
<groupId>com.github.jai-imageio</groupId>

View file

@ -67,17 +67,18 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
// barcode image. Force any such pixel to be white:
if ((pixel & 0xFF000000) == 0) {
pixel = 0xFFFFFFFF; // = white
}
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
// 0x200 >> 10 is 0.5, it implements rounding.
buffer[x] =
// white, so we know its luminance is 255
buffer[x] = 0xFF;
} else {
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
// 0x200 >> 10 is 0.5, it implements rounding.
buffer[x] =
(306 * ((pixel >> 16) & 0xFF) +
601 * ((pixel >> 8) & 0xFF) +
117 * (pixel & 0xFF) +
0x200) >> 10;
601 * ((pixel >> 8) & 0xFF) +
117 * (pixel & 0xFF) +
0x200) >> 10;
}
}
raster.setPixels(left, y, width, 1, buffer);
}

29
pom.xml
View file

@ -64,7 +64,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13-beta-3</version>
<version>4.13-rc-2</version>
<scope>test</scope>
</dependency>
</dependencies>
@ -82,8 +82,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<proguard.version>6.1.1</proguard.version>
<proguard.plugin.version>2.1.1</proguard.plugin.version>
<android.home>${env.ANDROID_HOME}</android.home>
<proguard.version>6.2.0</proguard.version>
<proguard.plugin.version>2.2.0</proguard.plugin.version>
<slf4j.version>1.8.0-beta4</slf4j.version>
<!-- This can't reference project.version as some subprojects version differently -->
<zxing.version>3.4.1-SNAPSHOT</zxing.version>
@ -132,7 +133,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>enforce</id>
@ -142,7 +143,7 @@
<requireUpperBoundDeps />
<dependencyConvergence />
<requireMavenVersion>
<version>3.2.5</version>
<version>3.3.9</version>
</requireMavenVersion>
<requireJavaVersion>
<version>${java.version}</version>
@ -171,7 +172,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
@ -233,12 +234,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -325,7 +326,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<version>3.0.0-M4</version>
<configuration>
<forkCount>0.5C</forkCount>
<systemPropertyVariables>
@ -354,7 +355,7 @@
</executions>
<configuration>
<sdk>
<path>${env.ANDROID_HOME}</path>
<path>${android.home}</path>
<platform>${android.platform}</platform>
</sdk>
<artifactSet>
@ -463,7 +464,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.23</version>
<version>8.27</version>
</dependency>
</dependencies>
</plugin>
@ -526,7 +527,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<version>0.8.5</version>
<executions>
<execution>
<goals>
@ -729,7 +730,7 @@
<version>${android.platform}</version>
<scope>system</scope>
<!-- ANDROID_HOME must be absolute, but redundant leading / may help Gradle Spring Boot plugin -->
<systemPath>/${env.ANDROID_HOME}/platforms/android-${android.platform}/android.jar</systemPath>
<systemPath>/${android.home}/platforms/android-${android.platform}/android.jar</systemPath>
</dependency>
</dependencies>
</dependencyManagement>
@ -764,7 +765,7 @@
<!-- repeat Android jar as library jar, as plugin ignores scope system deps -->
<proguardOptions>
<option>-libraryjars</option>
<option>${env.ANDROID_HOME}/platforms/android-${android.platform}/android.jar</option>
<option>${android.home}/platforms/android-${android.platform}/android.jar</option>
</proguardOptions>
<sign>
<debug>false</debug>

View file

@ -39,7 +39,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-android</version>
<version>28.1-android</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@ -49,7 +49,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.1.8.RELEASE</version>
<version>5.2.2.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>

View file

@ -23,6 +23,7 @@ import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.regex.Pattern;
/**
* Redirects things to HTTPS, like the main decode page, which should prefer HTTPS.
@ -30,15 +31,18 @@ import java.io.IOException;
@WebFilter("/w/decode.jspx")
public final class HTTPSFilter extends AbstractFilter {
private static final Pattern HTTP_REGEX = Pattern.compile("http://");
@Override
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse,
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse,
FilterChain chain) throws IOException, ServletException {
if (servletRequest.isSecure()) {
chain.doFilter(servletRequest, servletResponse);
} else {
HttpServletRequest request = (HttpServletRequest) servletRequest;
String target = request.getRequestURL().toString().replaceFirst("http://", "https://");
HttpServletRequest request = (HttpServletRequest) servletRequest;
String url = request.getRequestURL().toString();
String target = HTTP_REGEX.matcher(url).replaceFirst("https://");
redirect(servletResponse, target);
}
}