diff --git a/pom.xml b/pom.xml index 879409d656a..4751c55716e 100644 --- a/pom.xml +++ b/pom.xml @@ -208,12 +208,13 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj. commons-io commons-io 2.17.0 - + org.apache.commons commons-lang3 3.17.0 - + test + diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java index a06bc26cec5..dac17f02bfc 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java @@ -48,12 +48,12 @@ import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.EntryStreamOffsets; import org.apache.commons.compress.archivers.zip.ZipEncoding; +import org.apache.commons.compress.internal.lang3.SystemProperties; import org.apache.commons.compress.utils.ArchiveUtils; import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.compress.utils.ParsingUtils; import org.apache.commons.compress.utils.TimeUtils; import org.apache.commons.io.file.attribute.FileTimes; -import org.apache.commons.lang3.SystemProperties; /** * An entry in a Tar archive. diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java index 4f3588d9b81..1dde3deae84 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java @@ -38,12 +38,12 @@ import org.apache.commons.compress.archivers.ArchiveOutputStream; import org.apache.commons.compress.archivers.zip.ZipEncoding; import org.apache.commons.compress.archivers.zip.ZipEncodingHelper; +import org.apache.commons.compress.internal.lang3.ArrayFill; import org.apache.commons.compress.utils.FixedLengthBlockOutputStream; import org.apache.commons.compress.utils.TimeUtils; import org.apache.commons.io.Charsets; import org.apache.commons.io.file.attribute.FileTimes; import org.apache.commons.io.output.CountingOutputStream; -import org.apache.commons.lang3.ArrayFill; /** * The TarOutputStream writes a UNIX tar archive as an OutputStream. Methods are provided to put entries, and then write their contents by writing to this diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/BinaryTree.java b/src/main/java/org/apache/commons/compress/archivers/zip/BinaryTree.java index c02fce78c0c..56a3be5a31e 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/BinaryTree.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/BinaryTree.java @@ -23,8 +23,8 @@ import java.io.IOException; import java.io.InputStream; +import org.apache.commons.compress.internal.lang3.ArrayFill; import org.apache.commons.compress.utils.IOUtils; -import org.apache.commons.lang3.ArrayFill; /** * Binary tree of positive values. diff --git a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java index 4d77de9ec00..9e686170748 100644 --- a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java +++ b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java @@ -28,10 +28,10 @@ import java.nio.ByteOrder; import java.util.Arrays; +import org.apache.commons.compress.internal.lang3.ArrayFill; import org.apache.commons.compress.utils.BitInputStream; import org.apache.commons.compress.utils.ByteUtils; import org.apache.commons.compress.utils.ExactMath; -import org.apache.commons.lang3.ArrayFill; /** * TODO This class can't be final because it is mocked by Mockito. diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java index 1feb1e5bc05..d2f7377a01b 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.util.Objects; -import org.apache.commons.lang3.ArrayFill; +import org.apache.commons.compress.internal.lang3.ArrayFill; /** * Helper class for compression algorithms that use the ideas of LZ77. diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java index 430e8a8670b..f111e179a3c 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java @@ -31,10 +31,10 @@ import org.apache.commons.compress.harmony.pack200.Pack200Adapter; import org.apache.commons.compress.harmony.pack200.Pack200Exception; +import org.apache.commons.compress.internal.lang3.reflect.FieldUtils; import org.apache.commons.compress.java.util.jar.Pack200.Unpacker; import org.apache.commons.io.input.BoundedInputStream; import org.apache.commons.io.input.CloseShieldInputStream; -import org.apache.commons.lang3.reflect.FieldUtils; /** * This class provides the binding between the standard Pack200 interface and the internal interface for (un)packing. diff --git a/src/main/java/org/apache/commons/compress/internal/lang3/ArrayFill.java b/src/main/java/org/apache/commons/compress/internal/lang3/ArrayFill.java new file mode 100644 index 00000000000..e172cad2d5e --- /dev/null +++ b/src/main/java/org/apache/commons/compress/internal/lang3/ArrayFill.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.compress.internal.lang3; + +import java.util.Arrays; + +public final class ArrayFill { + + public static int[] fill(final int[] a, final int val) { + Arrays.fill(a, val); + return a; + } + + public static byte[] fill(final byte[] a, final byte val) { + Arrays.fill(a, val); + return a; + } + + private ArrayFill() { + } +} diff --git a/src/main/java/org/apache/commons/compress/internal/lang3/SystemProperties.java b/src/main/java/org/apache/commons/compress/internal/lang3/SystemProperties.java new file mode 100644 index 00000000000..77d85071017 --- /dev/null +++ b/src/main/java/org/apache/commons/compress/internal/lang3/SystemProperties.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.compress.internal.lang3; + +public final class SystemProperties { + + public static String getOsName() { + return System.getProperty("os.name"); + } + + private SystemProperties() { + } +} diff --git a/src/main/java/org/apache/commons/compress/internal/lang3/package-info.java b/src/main/java/org/apache/commons/compress/internal/lang3/package-info.java new file mode 100644 index 00000000000..e47bed49a54 --- /dev/null +++ b/src/main/java/org/apache/commons/compress/internal/lang3/package-info.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/** + * Private copies of methods from Commons Lang. + *

+ * These methods currently account to less then 1% of the size of Commons Lang. + * They have been copied to prevent the addition of Commons Lang as a dependency. + *

+ *

If the size of this package becomes larger than 1% of the size of Commons Lang:

+ *
    + *
  1. Consider shading of up to 10% of the size of Commons Lang.
  2. + *
  3. If that does not work include Commons Lang as dependency.
  4. + *
+ */ +package org.apache.commons.compress.internal.lang3; diff --git a/src/main/java/org/apache/commons/compress/internal/lang3/reflect/FieldUtils.java b/src/main/java/org/apache/commons/compress/internal/lang3/reflect/FieldUtils.java new file mode 100644 index 00000000000..39494eab2e4 --- /dev/null +++ b/src/main/java/org/apache/commons/compress/internal/lang3/reflect/FieldUtils.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.compress.internal.lang3.reflect; + +import static java.util.Objects.requireNonNull; + +import java.lang.reflect.Field; + +public final class FieldUtils { + + public static Object readField(final Object target, final String fieldName, final boolean forceAccess) throws IllegalAccessException { + requireNonNull(target, "target"); + requireNonNull(fieldName, "fieldName"); + final Class cls = target.getClass(); + final Field field = getField(cls, fieldName, forceAccess); + if (field == null) { + throw new IllegalArgumentException(String.format("Cannot locate field %s on %s", fieldName, cls)); + } + return field.get(target); + } + + private static Field getField(final Class cls, final String fieldName, final boolean forceAccess) { + requireNonNull(cls, "cls"); + requireNonNull(fieldName, "fieldName"); + Class currentClass = cls; + while (currentClass != null) { + try { + final Field field = currentClass.getDeclaredField(fieldName); + // getDeclaredField checks for non-public scopes as well + // and it returns accurate results + if (forceAccess && !field.isAccessible()) { + field.setAccessible(true); + } + return field; + } catch (final NoSuchFieldException ignored) { + // ignore + } + currentClass = currentClass.getSuperclass(); + } + return null; + } + + private FieldUtils() { + } +} diff --git a/src/main/java/org/apache/commons/compress/internal/lang3/reflect/package-info.java b/src/main/java/org/apache/commons/compress/internal/lang3/reflect/package-info.java new file mode 100644 index 00000000000..42ecc5e988d --- /dev/null +++ b/src/main/java/org/apache/commons/compress/internal/lang3/reflect/package-info.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/** + * A private copy of methods from Commons Lang. + *

+ * See + *