Update to 4.13.2

This commit is contained in:
wk333 2023-09-25 14:57:30 +08:00
parent 3d846e7d82
commit 3dabb0837a
7 changed files with 124 additions and 146 deletions

View File

@ -0,0 +1,108 @@
From 85c780b61cd35b4544d2926393805e1699641f38 Mon Sep 17 00:00:00 2001
From: Marian Koncek <mkoncek@redhat.com>
Date: Fri, 6 Mar 2020 14:28:05 +0100
Subject: [PATCH] Port to hamcrest 2.2
---
.../org/junit/internal/matchers/StacktracePrintingMatcher.java | 3 ---
.../org/junit/internal/matchers/ThrowableCauseMatcher.java | 2 --
.../org/junit/internal/matchers/ThrowableMessageMatcher.java | 2 --
src/main/java/org/junit/matchers/JUnitMatchers.java | 2 +-
.../experimental/theories/runner/WithDataPointMethod.java | 2 +-
5 files changed, 2 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/junit/internal/matchers/StacktracePrintingMatcher.java b/src/main/java/org/junit/internal/matchers/StacktracePrintingMatcher.java
index 93a6827..3ea4a81 100644
--- a/src/main/java/org/junit/internal/matchers/StacktracePrintingMatcher.java
+++ b/src/main/java/org/junit/internal/matchers/StacktracePrintingMatcher.java
@@ -1,7 +1,6 @@
package org.junit.internal.matchers;
import org.hamcrest.Description;
-import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.junit.internal.Throwables;
@@ -39,13 +38,11 @@ public class StacktracePrintingMatcher<T extends Throwable> extends
return Throwables.getStacktrace(throwable);
}
- @Factory
public static <T extends Throwable> Matcher<T> isThrowable(
Matcher<T> throwableMatcher) {
return new StacktracePrintingMatcher<T>(throwableMatcher);
}
- @Factory
public static <T extends Exception> Matcher<T> isException(
Matcher<T> exceptionMatcher) {
return new StacktracePrintingMatcher<T>(exceptionMatcher);
diff --git a/src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java b/src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java
index 6e2ff5e..1f0a0a0 100644
--- a/src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java
+++ b/src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java
@@ -1,7 +1,6 @@
package org.junit.internal.matchers;
import org.hamcrest.Description;
-import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
@@ -43,7 +42,6 @@ public class ThrowableCauseMatcher<T extends Throwable> extends
* @param matcher to apply to the cause of the outer exception
* @param <T> type of the outer exception
*/
- @Factory
public static <T extends Throwable> Matcher<T> hasCause(final Matcher<?> matcher) {
return new ThrowableCauseMatcher<T>(matcher);
}
diff --git a/src/main/java/org/junit/internal/matchers/ThrowableMessageMatcher.java b/src/main/java/org/junit/internal/matchers/ThrowableMessageMatcher.java
index 74386a8..7d16b11 100644
--- a/src/main/java/org/junit/internal/matchers/ThrowableMessageMatcher.java
+++ b/src/main/java/org/junit/internal/matchers/ThrowableMessageMatcher.java
@@ -1,7 +1,6 @@
package org.junit.internal.matchers;
import org.hamcrest.Description;
-import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
@@ -30,7 +29,6 @@ public class ThrowableMessageMatcher<T extends Throwable> extends
matcher.describeMismatch(item.getMessage(), description);
}
- @Factory
public static <T extends Throwable> Matcher<T> hasMessage(final Matcher<String> matcher) {
return new ThrowableMessageMatcher<T>(matcher);
}
diff --git a/src/main/java/org/junit/matchers/JUnitMatchers.java b/src/main/java/org/junit/matchers/JUnitMatchers.java
index 13407cc..8889266 100644
--- a/src/main/java/org/junit/matchers/JUnitMatchers.java
+++ b/src/main/java/org/junit/matchers/JUnitMatchers.java
@@ -56,7 +56,7 @@ public class JUnitMatchers {
* @deprecated Please use {@link CoreMatchers#everyItem(Matcher)} instead.
*/
@Deprecated
- public static <T> Matcher<Iterable<T>> everyItem(final Matcher<T> elementMatcher) {
+ public static <T> Matcher<Iterable<? extends T>> everyItem(final Matcher<T> elementMatcher) {
return CoreMatchers.everyItem(elementMatcher);
}
diff --git a/src/test/java/org/junit/tests/experimental/theories/runner/WithDataPointMethod.java b/src/test/java/org/junit/tests/experimental/theories/runner/WithDataPointMethod.java
index f2b2753..e5759ed 100644
--- a/src/test/java/org/junit/tests/experimental/theories/runner/WithDataPointMethod.java
+++ b/src/test/java/org/junit/tests/experimental/theories/runner/WithDataPointMethod.java
@@ -108,7 +108,7 @@ public class WithDataPointMethod {
return JUnitCore.runClasses(type).getFailures();
}
- private Matcher<Iterable<Failure>> empty() {
+ private Matcher<Iterable<? extends Failure>> empty() {
return everyItem(nullValue(Failure.class));
}
}
--
2.25.2

View File

@ -1,63 +0,0 @@
From 24b8ee0bec2f2761b479bdd989275f19597955a3 Mon Sep 17 00:00:00 2001
From: Carsten Varming <cvarming@twitter.com>
Date: Sat, 21 May 2016 22:43:07 -0400
Subject: [PATCH] Retry TemporaryFolder.newFolder's call to mkdir if the call
does not create a new directory.
Closes #1304
---
.../java/org/junit/rules/TemporaryFolder.java | 27 +++++++++++++++----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/junit/rules/TemporaryFolder.java b/src/main/java/org/junit/rules/TemporaryFolder.java
index 8fc9d5b370..0b3e874528 100644
--- a/src/main/java/org/junit/rules/TemporaryFolder.java
+++ b/src/main/java/org/junit/rules/TemporaryFolder.java
@@ -32,6 +32,9 @@ public class TemporaryFolder extends Ext
private final File parentFolder;
private File folder;
+ private static final int TEMP_DIR_ATTEMPTS = 10000;
+ private static final String TMP_PREFIX = "junit";
+
public TemporaryFolder() {
this(null);
}
@@ -75,7 +78,7 @@ public class TemporaryFolder extends Ext
* Returns a new fresh file with a random name under the temporary folder.
*/
public File newFile() throws IOException {
- return File.createTempFile("junit", null, getRoot());
+ return File.createTempFile(TMP_PREFIX, null, getRoot());
}
/**
@@ -131,10 +134,24 @@ public class TemporaryFolder extends Ext
}
private File createTemporaryFolderIn(File parentFolder) throws IOException {
- File createdFolder = File.createTempFile("junit", "", parentFolder);
- createdFolder.delete();
- createdFolder.mkdir();
- return createdFolder;
+ File createdFolder = null;
+ for (int i = 0; i < TEMP_DIR_ATTEMPTS; ++i) {
+ // Use createTempFile to get a suitable folder name.
+ String suffix = ".tmp";
+ File tmpFile = File.createTempFile(TMP_PREFIX, suffix, parentFolder);
+ String tmpName = tmpFile.getName();
+ // Discard suffix of tmpName.
+ String folderName = tmpName.substring(0, tmpName.length() - suffix.length());
+ createdFolder = new File(parentFolder, folderName);
+ if (createdFolder.mkdir()) {
+ tmpFile.delete();
+ return createdFolder;
+ }
+ tmpFile.delete();
+ }
+ throw new IOException("Unable to create temporary directory in: "
+ + parentFolder.toString() + ". Tried " + TEMP_DIR_ATTEMPTS + " times. "
+ + "Last attempted to create: " + createdFolder.toString());
}
/**

View File

@ -1,77 +0,0 @@
From 610155b8c22138329f0723eec22521627dbc52ae Mon Sep 17 00:00:00 2001
From: Marc Philipp <mail@marcphilipp.de>
Date: Sun, 11 Oct 2020 16:56:21 +0200
Subject: [PATCH] Merge pull request from GHSA-269g-pwp5-87pp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When running on Java 7 or later, temporary directories are now created
Using Javas NIO API which restricts permissions to owner-only by
default.
---
.../java/org/junit/rules/TemporaryFolder.java | 43 ++++++++++++++++++-
.../org/junit/rules/TempFolderRuleTest.java | 37 +++++++++++++++-
2 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/junit/rules/TemporaryFolder.java b/src/main/java/org/junit/rules/TemporaryFolder.java
index 1a6a770608..a726c66e36 100644
--- a/src/main/java/org/junit/rules/TemporaryFolder.java
+++ b/src/main/java/org/junit/rules/TemporaryFolder.java
@@ -2,6 +2,9 @@
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import org.junit.Rule;
@@ -133,7 +136,45 @@ public File newFolder() throws IOException {
return createTemporaryFolderIn(getRoot());
}
- private File createTemporaryFolderIn(File parentFolder) throws IOException {
+ private static File createTemporaryFolderIn(File parentFolder) throws IOException {
+ try {
+ return createTemporaryFolderWithNioApi(parentFolder);
+ } catch (ClassNotFoundException ignore) {
+ // Fallback for Java 5 and 6
+ return createTemporaryFolderWithFileApi(parentFolder);
+ } catch (InvocationTargetException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof IOException) {
+ throw (IOException) cause;
+ }
+ if (cause instanceof RuntimeException) {
+ throw (RuntimeException) cause;
+ }
+ IOException exception = new IOException("Failed to create temporary folder in " + parentFolder);
+ exception.initCause(cause);
+ throw exception;
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to create temporary folder in " + parentFolder, e);
+ }
+ }
+
+ private static File createTemporaryFolderWithNioApi(File parentFolder) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ Class<?> filesClass = Class.forName("java.nio.file.Files");
+ Object fileAttributeArray = Array.newInstance(Class.forName("java.nio.file.attribute.FileAttribute"), 0);
+ Class<?> pathClass = Class.forName("java.nio.file.Path");
+ Object tempDir;
+ if (parentFolder != null) {
+ Method createTempDirectoryMethod = filesClass.getDeclaredMethod("createTempDirectory", pathClass, String.class, fileAttributeArray.getClass());
+ Object parentPath = File.class.getDeclaredMethod("toPath").invoke(parentFolder);
+ tempDir = createTempDirectoryMethod.invoke(null, parentPath, TMP_PREFIX, fileAttributeArray);
+ } else {
+ Method createTempDirectoryMethod = filesClass.getDeclaredMethod("createTempDirectory", String.class, fileAttributeArray.getClass());
+ tempDir = createTempDirectoryMethod.invoke(null, TMP_PREFIX, fileAttributeArray);
+ }
+ return (File) pathClass.getDeclaredMethod("toFile").invoke(tempDir);
+ }
+
+ private static File createTemporaryFolderWithFileApi(File parentFolder) throws IOException {
File createdFolder = null;
for (int i = 0; i < TEMP_DIR_ATTEMPTS; ++i) {
// Use createTempFile to get a suitable folder name.

View File

@ -1,18 +1,19 @@
Name: junit
Epoch: 1
Version: 4.12
Release: 13
Version: 4.13.2
Release: 1
Summary: A Java package for unit testing frameworks
License: EPL-1.0
URL: http://www.junit.org/
Source0: https://github.com/%{name}-team/%{name}/archive/r%{version}.tar.gz
Patch0000: CVE-2020-15250-pre.patch
Patch0001: CVE-2020-15250.patch
Patch0000: 0001-Port-to-hamcrest-2.2.patch
BuildArch: noarch
BuildRequires: maven-local mvn(org.apache.felix:maven-bundle-plugin)
BuildRequires: mvn(org.apache.maven.plugins:maven-enforcer-plugin)
BuildRequires: mvn(org.hamcrest:hamcrest-core)
BuildRequires: java-11-openjdk-devel
Requires: java-11-openjdk
Obsoletes: %{name}-demo < 4.12
@ -37,6 +38,9 @@ The junit-help package contains related documents.
find . -name "*.jar" -delete
find . -name "*.class" -delete
# InaccessibleBaseClassTest fails with Java 8
sed -i /InaccessibleBaseClassTest/d src/test/java/org/junit/tests/AllTests.java
%pom_remove_plugin :replacer
sed s/@version@/%{version}/ src/main/java/junit/runner/Version.java.template >src/main/java/junit/runner/Version.java
@ -60,9 +64,12 @@ sed s/@version@/%{version}/ src/main/java/junit/runner/Version.java.template >sr
</plugin>"
%mvn_file : junit
%mvn_alias junit:junit junit:junit-dep
%build
%mvn_build
#set openjdk11 for build
export JAVA_HOME=%{_jvmdir}/java-11-openjdk
%mvn_build -f -- -DjdkVersion=1.7 -P\!restrict-doclint
%install
%mvn_install
@ -74,6 +81,9 @@ sed s/@version@/%{version}/ src/main/java/junit/runner/Version.java.template >sr
%doc doc/*
%changelog
* Mon Sep 25 2023 wangkai <13474090681@163.com> - 1:4.13.2-1
- Update to 4.13.2
* Fri Feb 19 2021 wangxiao <wangxiao65@huawei.com> - 1:4.12-13
- Fix CVE-2020-15250

View File

@ -1,4 +1,4 @@
version_control: github
src_repo: junit-team/junit4
tag_prefix: "^r"
seperator: "."
separator: "."

Binary file not shown.

BIN
r4.13.2.tar.gz Normal file

Binary file not shown.