Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Commons Lang dependency #607

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,13 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.17.0</version>
</dependency>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
</dependency>
<scope>test</scope>
</dependency>
</dependencies>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://www.gnu.org/software/tar/manual/html_node/Standard.html">Tar archive</a>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Charsets;
import org.apache.commons.compress.utils.FixedLengthBlockOutputStream;
import org.apache.commons.compress.utils.TimeUtils;
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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() {
try {
return System.getProperty("os.name");
ppkarwasz marked this conversation as resolved.
Show resolved Hide resolved
} catch (final SecurityException e) {
return null;
}
}

private SystemProperties() {
}
}
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* 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.
* </p>
* <p>If the size of this package becomes larger than 1% of the size of Commons Lang:</p>
* <ol>
* <li>Consider shading of up to 10% of the size of Commons Lang.</li>
* <li>If that does not work include Commons Lang as dependency.</li>
* </ol>
*/
package org.apache.commons.compress.internal.lang3;
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* See
* <a href="{@docRoot}/org/apache/commons/compress/internal/lang3/package-summary.html#package_description>
* {@code org.apache.commons.compress.internal.lang3} package description
* </a>
* for more information.
* </p>
*/
package org.apache.commons.compress.internal.lang3.reflect;