Repository: commons-compress Updated Branches: refs/heads/master 446843e14 -> 5481dd326
[COMPRESS-413] Travis build redundantly repeats compilation and tests redundantly #43. Patch applied except removal of Oracle 7 and 8 from Travis build. Closes #43. Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/5481dd32 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/5481dd32 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/5481dd32 Branch: refs/heads/master Commit: 5481dd326025de2da7d89089cb969759972e7a8c Parents: 446843e Author: Simon Spero <[email protected]> Authored: Fri Jun 30 16:01:53 2017 -0700 Committer: Gary Gregory <[email protected]> Committed: Fri Jun 30 16:01:53 2017 -0700 ---------------------------------------------------------------------- .mvn/wrapper/maven-wrapper.properties | 1 + .travis.yml | 17 +- mvnw | 225 +++++++++++++++++ mvnw.cmd | 143 +++++++++++ pom.xml | 40 ++- src/changes/changes.xml | 3 + .../compress/archivers/sevenz/Coders.java | 114 +++++---- .../archivers/sevenz/SevenZNativeHeapTest.java | 249 +++++++++++++++++-- 8 files changed, 718 insertions(+), 74 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/5481dd32/.mvn/wrapper/maven-wrapper.properties ---------------------------------------------------------------------- diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..56bb016 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip \ No newline at end of file http://git-wip-us.apache.org/repos/asf/commons-compress/blob/5481dd32/.travis.yml ---------------------------------------------------------------------- diff --git a/.travis.yml b/.travis.yml index 508d7e4..dfeca93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,17 +13,28 @@ # See the License for the specific language governing permissions and # limitations under the License. -language: java sudo: false +# Use Trusty as dist +dist: trusty +language: java + jdk: - openjdk7 + - openjdk8 - oraclejdk7 - oraclejdk8 + - oraclejdk9 cache: directories: - $HOME/.m2 + - .mvn +# don't run mvn install before building +install: true + +# do all the building and testing in a single phase, instead of compiling everything three times +# and running all tests twice. -after_success: - - mvn clean apache-rat:check test jacoco:report coveralls:report -Ptravis-jacoco +script: + - ./mvnw clean apache-rat:check test jacoco:report coveralls:report -Ptravis-jacoco http://git-wip-us.apache.org/repos/asf/commons-compress/blob/5481dd32/mvnw ---------------------------------------------------------------------- diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" http://git-wip-us.apache.org/repos/asf/commons-compress/blob/5481dd32/mvnw.cmd ---------------------------------------------------------------------- diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% http://git-wip-us.apache.org/repos/asf/commons-compress/blob/5481dd32/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index fdf1721..735a797 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ jar, tar, zip, dump, 7z, arj. <!-- configuration bits for cutting a release candidate --> <commons.release.version>${project.version}</commons.release.version> <commons.rc.version>RC1</commons.rc.version> - <powermock.version>1.6.6</powermock.version> + <powermock.version>1.7.0</powermock.version> <commons.pmd-plugin.version>3.7</commons.pmd-plugin.version> <!-- only show issues of the current version --> @@ -63,6 +63,11 @@ jar, tar, zip, dump, 7z, arj. <dependencies> <dependency> + <groupId>org.objenesis</groupId> + <artifactId>objenesis</artifactId> + <version>2.6</version> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> @@ -170,6 +175,10 @@ jar, tar, zip, dump, 7z, arj. <name>BELUGA BEHR</name> </contributor> <contributor> + <name>Simon Spero</name> + <email>[email protected]</email> + </contributor> + <contributor> <name>Michael Hausegger</name> <email>[email protected]</email> </contributor> @@ -192,7 +201,7 @@ jar, tar, zip, dump, 7z, arj. <quiet>true</quiet> <source>${maven.compiler.source}</source> <encoding>${commons.encoding}</encoding> - <docEncoding>${commons.docEncoding}</docEncoding> + <docencoding>${commons.docEncoding}</docencoding> <linksource>true</linksource> <links> <link>${commons.javadoc.java.link}</link> @@ -227,9 +236,22 @@ jar, tar, zip, dump, 7z, arj. <exclude>src/test/resources/**</exclude> <exclude>.pmd</exclude> <exclude>.projectile</exclude> + <exclude>.mvn/**</exclude> </excludes> </configuration> </plugin> + <plugin> + <groupId>org.eluder.coveralls</groupId> + <artifactId>coveralls-maven-plugin</artifactId> + <configuration> + <failOnServiceError>false</failOnServiceError> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>3.3.0</version> + </plugin> </plugins> </pluginManagement> <plugins> @@ -305,7 +327,7 @@ jar, tar, zip, dump, 7z, arj. <quiet>true</quiet> <source>${maven.compiler.source}</source> <encoding>${commons.encoding}</encoding> - <docEncoding>${commons.docEncoding}</docEncoding> + <docencoding>${commons.docEncoding}</docencoding> <linksource>true</linksource> <links> <link>${commons.javadoc.java.link}</link> @@ -394,6 +416,18 @@ jar, tar, zip, dump, 7z, arj. </plugins> </build> </profile> + <profile> + <id>java9</id> + <activation> + <jdk>9</jdk> + </activation> + <properties> + <maven.compiler.release>9</maven.compiler.release> + <commons.jacoco.version>0.7.9</commons.jacoco.version> + <animal.sniffer.skip>true</animal.sniffer.skip> + </properties> + </profile> + </profiles> </project> http://git-wip-us.apache.org/repos/asf/commons-compress/blob/5481dd32/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e430f25..b1db317 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -59,6 +59,9 @@ wanted to create such files."> Don't use a data descriptor in ZIP archives when copying a raw entry that already knows its size and CRC information. </action> + <action issue="COMPRESS-413" type="fix" date="2017-05-22" due-to="Simon Spero"> + Travis build redundantly repeats compilation and tests redundantly #43. + </action> <action issue="COMPRESS-397" type="add" date="2017-05-22"> Added magic MANIFEST entry Automatic-Module-Name so the module name will be org.apache.commons.compress when the jar is used http://git-wip-us.apache.org/repos/asf/commons-compress/blob/5481dd32/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java index de7c359..c04dca6 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java @@ -136,62 +136,86 @@ class Coders { final Inflater inflater = new Inflater(true); final InflaterInputStream inflaterInputStream = new InflaterInputStream(new DummyByteAddingInputStream(in), inflater); - return new InputStream() { - @Override - public int read() throws IOException { - return inflaterInputStream.read(); - } - - @Override - public int read(final byte[] b, final int off, final int len) throws IOException { - return inflaterInputStream.read(b, off, len); - } - - @Override - public int read(final byte[] b) throws IOException { - return inflaterInputStream.read(b); - } - - @Override - public void close() throws IOException { - try { - inflaterInputStream.close(); - } finally { - inflater.end(); - } - } - }; + return new DeflateDecoderInputStream(inflaterInputStream, inflater); } @Override OutputStream encode(final OutputStream out, final Object options) { final int level = numberOptionOrDefault(options, 9); final Deflater deflater = new Deflater(level, true); final DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(out, deflater); - return new OutputStream() { - @Override - public void write(final int b) throws IOException { - deflaterOutputStream.write(b); - } + return new DeflateDecoderOutputStream(deflaterOutputStream, deflater); + } - @Override - public void write(final byte[] b) throws IOException { - deflaterOutputStream.write(b); - } + static class DeflateDecoderInputStream extends InputStream { + + InflaterInputStream inflaterInputStream; + Inflater inflater; + + public DeflateDecoderInputStream(InflaterInputStream inflaterInputStream, + Inflater inflater) { + this.inflaterInputStream = inflaterInputStream; + this.inflater = inflater; + } + + @Override + public int read() throws IOException { + return inflaterInputStream.read(); + } + + @Override + public int read(final byte[] b, final int off, final int len) throws IOException { + return inflaterInputStream.read(b, off, len); + } + + @Override + public int read(final byte[] b) throws IOException { + return inflaterInputStream.read(b); + } - @Override - public void write(final byte[] b, final int off, final int len) throws IOException { - deflaterOutputStream.write(b, off, len); + @Override + public void close() throws IOException { + try { + inflaterInputStream.close(); + } finally { + inflater.end(); } + } + } + + static class DeflateDecoderOutputStream extends OutputStream { + + DeflaterOutputStream deflaterOutputStream; + Deflater deflater; + + public DeflateDecoderOutputStream(DeflaterOutputStream deflaterOutputStream, + Deflater deflater) { + this.deflaterOutputStream = deflaterOutputStream; + this.deflater = deflater; + } + + @Override + public void write(final int b) throws IOException { + deflaterOutputStream.write(b); + } + + @Override + public void write(final byte[] b) throws IOException { + deflaterOutputStream.write(b); + } + + @Override + public void write(final byte[] b, final int off, final int len) throws IOException { + deflaterOutputStream.write(b, off, len); + } - @Override - public void close() throws IOException { - try { - deflaterOutputStream.close(); - } finally { - deflater.end(); - } + @Override + public void close() throws IOException { + try { + deflaterOutputStream.close(); + } finally { + deflater.end(); } - }; + } } } http://git-wip-us.apache.org/repos/asf/commons-compress/blob/5481dd32/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java index 896af8c..d556819 100644 --- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java @@ -17,48 +17,251 @@ */ package org.apache.commons.compress.archivers.sevenz; -import org.apache.commons.compress.AbstractTestCase; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.OutputStream; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.Inflater; +import org.apache.commons.compress.AbstractTestCase; +import org.apache.commons.compress.archivers.sevenz.Coders.DeflateDecoder; +import org.apache.commons.compress.archivers.sevenz.Coders.DeflateDecoder.DeflateDecoderInputStream; +import org.apache.commons.compress.archivers.sevenz.Coders.DeflateDecoder.DeflateDecoderOutputStream; +import org.junit.Test; -@RunWith(PowerMockRunner.class) -@PrepareForTest(Coders.DeflateDecoder.class) public class SevenZNativeHeapTest extends AbstractTestCase { - @InjectMocks - Coders.DeflateDecoder deflateDecoder; @Test public void testEndDeflaterOnCloseStream() throws Exception { - final Deflater deflater = PowerMockito.spy(new Deflater()); - PowerMockito.whenNew(Deflater.class).withAnyArguments().thenReturn(deflater); + Coders.DeflateDecoder deflateDecoder = new DeflateDecoder(); - final OutputStream outputStream = deflateDecoder.encode(new ByteArrayOutputStream(), 9); + final DeflateDecoderOutputStream outputStream = + (DeflateDecoderOutputStream) deflateDecoder.encode(new ByteArrayOutputStream(), 9); + DelegatingDeflater delegatingDeflater = new DelegatingDeflater(outputStream.deflater); + outputStream.deflater = delegatingDeflater; outputStream.close(); + assertTrue(delegatingDeflater.isEnded.get()); - Mockito.verify(deflater).end(); } @Test public void testEndInflaterOnCloseStream() throws Exception { - final Inflater inflater = PowerMockito.spy(new Inflater()); - PowerMockito.whenNew(Inflater.class).withAnyArguments().thenReturn(inflater); - - final InputStream inputStream = deflateDecoder.decode("dummy",new ByteArrayInputStream(new byte[0]),0,null,null); + Coders.DeflateDecoder deflateDecoder = new DeflateDecoder(); + final DeflateDecoderInputStream inputStream = + (DeflateDecoderInputStream) deflateDecoder.decode("dummy",new ByteArrayInputStream(new byte[0]),0,null,null); + DelegatingInflater delegatingInflater = new DelegatingInflater(inputStream.inflater); + inputStream.inflater = delegatingInflater; inputStream.close(); - Mockito.verify(inflater).end(); + assertTrue(delegatingInflater.isEnded.get()); + } + + private class DelegatingInflater extends Inflater { + + private final Inflater inflater; + + public DelegatingInflater(Inflater inflater) { + this.inflater = inflater; + } + AtomicBoolean isEnded = new AtomicBoolean(); + + @Override + public void end() { + isEnded.set(true); + inflater.end(); + } + + @Override + public void setInput(byte[] b, int off, int len) { + inflater.setInput(b, off, len); + } + + @Override + public void setInput(byte[] b) { + inflater.setInput(b); + } + + @Override + public void setDictionary(byte[] b, int off, int len) { + inflater.setDictionary(b, off, len); + } + + @Override + public void setDictionary(byte[] b) { + inflater.setDictionary(b); + } + + @Override + public int getRemaining() { + return inflater.getRemaining(); + } + + @Override + public boolean needsInput() { + return inflater.needsInput(); + } + + @Override + public boolean needsDictionary() { + return inflater.needsDictionary(); + } + + @Override + public boolean finished() { + return inflater.finished(); + } + + @Override + public int inflate(byte[] b, int off, int len) throws DataFormatException { + return inflater.inflate(b, off, len); + } + + @Override + public int inflate(byte[] b) throws DataFormatException { + return inflater.inflate(b); + } + + @Override + public int getAdler() { + return inflater.getAdler(); + } + + @Override + public int getTotalIn() { + return inflater.getTotalIn(); + } + + @Override + public long getBytesRead() { + return inflater.getBytesRead(); + } + + @Override + public int getTotalOut() { + return inflater.getTotalOut(); + } + + @Override + public long getBytesWritten() { + return inflater.getBytesWritten(); + } + + @Override + public void reset() { + inflater.reset(); + } + + } + + private class DelegatingDeflater extends Deflater { + + private final Deflater deflater; + + public DelegatingDeflater(Deflater deflater) { + this.deflater = deflater; + } + + AtomicBoolean isEnded = new AtomicBoolean(); + + @Override + public void end() { + isEnded.set(true); + deflater.end(); + } + + @Override + public void setInput(byte[] b, int off, int len) { + deflater.setInput(b, off, len); + } + + @Override + public void setInput(byte[] b) { + deflater.setInput(b); + } + + @Override + public void setDictionary(byte[] b, int off, int len) { + deflater.setDictionary(b, off, len); + } + + @Override + public void setDictionary(byte[] b) { + deflater.setDictionary(b); + } + + @Override + public void setStrategy(int strategy) { + deflater.setStrategy(strategy); + } + + @Override + public void setLevel(int level) { + deflater.setLevel(level); + } + + @Override + public boolean needsInput() { + return deflater.needsInput(); + } + + @Override + public void finish() { + deflater.finish(); + } + + @Override + public boolean finished() { + return deflater.finished(); + } + + @Override + public int deflate(byte[] b, int off, int len) { + return deflater.deflate(b, off, len); + } + + @Override + public int deflate(byte[] b) { + return deflater.deflate(b); + } + + @Override + public int deflate(byte[] b, int off, int len, int flush) { + return deflater.deflate(b, off, len, flush); + } + + @Override + public int getAdler() { + return deflater.getAdler(); + } + + @Override + public int getTotalIn() { + return deflater.getTotalIn(); + } + + @Override + public long getBytesRead() { + return deflater.getBytesRead(); + } + + @Override + public int getTotalOut() { + return deflater.getTotalOut(); + } + + @Override + public long getBytesWritten() { + return deflater.getBytesWritten(); + } + + @Override + public void reset() { + deflater.reset(); + } + + } }
