You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/03/08 18:39:28 UTC

[maven-shared-utils] 01/01: remove unreferenced non-public class

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch depre
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git

commit ea563dc54102f15294961cedbd5c9e5086bc4946
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Sun Mar 8 14:39:05 2020 -0400

    remove unreferenced non-public class
---
 .../java/org/apache/maven/shared/utils/Expand.java | 233 --------------
 .../org/apache/maven/shared/utils/ExpandTest.java  | 336 ---------------------
 2 files changed, 569 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/utils/Expand.java b/src/main/java/org/apache/maven/shared/utils/Expand.java
deleted file mode 100644
index 28c01ed..0000000
--- a/src/main/java/org/apache/maven/shared/utils/Expand.java
+++ /dev/null
@@ -1,233 +0,0 @@
-package org.apache.maven.shared.utils;
-
-/*
- * 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.
- */
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Date;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import org.apache.maven.shared.utils.io.FileUtils;
-import org.apache.maven.shared.utils.io.IOUtil;
-
-/**
- * Expand will unpack the given zip archive.
- *
- * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
- */
-class Expand
-{
-    /**
-     * Source file which should get expanded
-     */
-    private File source;
-
-    /**
-     * destination directory
-     */
-    private File dest;
-
-    /**
-     * if the unpackaging should get performed if the destination already exists.
-     */
-    private boolean overwrite = false;
-
-    private static final int BUFFER_SIZE = 2 ^ 16;
-
-
-    /**
-     * The zip archive which should get expanded.
-     *
-     * @param sourceArchive
-     */
-    public void setSrc( File sourceArchive )
-    {
-        this.source = sourceArchive;
-    }
-
-    /**
-     * Set the destination directory into which the archive should get expanded.
-     * The directory will get created if it doesn't yet exist
-     * while executing the expand.
-     *
-     * @param destinationDirectory
-     */
-    public void setDest( File destinationDirectory )
-    {
-        this.dest = destinationDirectory;
-    }
-
-    /**
-     * If the destination directory should get overwritten if the content
-     * already exists. If <code>false</code> we will only overwrite if the local
-     * file or directory is older than the one in the archive.
-     *
-     * @param overwrite
-     */
-    public void setOverwrite( boolean overwrite )
-    {
-        this.overwrite = overwrite;
-    }
-
-    /**
-     * Actually perform the unpacking of the source archive
-     * into the destination directory.
-     *
-     * @throws Exception
-     */
-    public void execute()
-        throws Exception
-    {
-        expandFile( source, dest );
-    }
-
-    /**
-     * <p>It is intended to be overwritten when implementing an own unarchiver</p>
-     * <p/>
-     * <p><b>Note:</b> we kept this protected method for the sake of backward compatibility!</p>
-     *
-     * @param srcFile The source file.
-     * @param destination The destination.
-     * @throws Exception In case of failure.
-     */
-    void expandFile( File srcFile, File destination )
-        throws Exception
-    {
-        if ( source == null )
-        {
-            throw new NullPointerException( "Source Archive must not be null!" );
-        }
-
-        File destDir = destination;
-        if ( destDir == null )
-        {
-            destDir = new File( System.getProperty( "user.dir" ) );
-        }
-
-        ZipInputStream in = null;
-        try
-        {
-            in = new ZipInputStream( new FileInputStream( srcFile ) );
-
-            for ( ZipEntry zipEntry = in.getNextEntry(); zipEntry != null; zipEntry = in.getNextEntry() )
-            {
-                String zipEntryName = zipEntry.getName();
-                Date zipEntryDate = new Date( zipEntry.getTime() );
-
-                extractFile( source, destDir, in, zipEntryName, zipEntryDate, zipEntry.isDirectory() );
-            }
-
-            in.close();
-            in = null;
-        }
-        finally
-        {
-            IOUtil.close( in );
-        }
-    }
-
-    /**
-     * Extract a single ZipEntry.
-     * <p/>
-     * <p><b>Note:</b> we kept this protected method for the sake of backward compatibility!</p>
-     *
-     * @param archive               the archive to unpack
-     * @param destDir               the destination dirctory
-     * @param compressedInputStream
-     * @param entryName
-     * @param entryDate
-     * @param isDirectory
-     * @throws Exception
-     */
-    void extractFile( File archive, File destDir, InputStream compressedInputStream, String entryName,
-                                Date entryDate, boolean isDirectory )
-        throws Exception
-    {
-        File targetFile = new File( destDir, entryName );
-
-        if ( !targetFile.getAbsolutePath().startsWith( destDir.getAbsolutePath() ) )
-        {
-            throw new IOException( "Entry '" + entryName + "' outside the target directory." );
-        }
-
-        // if overwrite is specified and the file type
-        // of the existing file does not match, then delete it
-        if ( overwrite && targetFile.exists() && targetFile.isDirectory() != isDirectory )
-        {
-            deleteFileOrDir( targetFile );
-        }
-
-        if ( !targetFile.exists() || overwrite || targetFile.lastModified() <= entryDate.getTime() )
-        {
-            if ( isDirectory )
-            {
-                targetFile.mkdirs();
-            }
-            else
-            {
-                byte[] buffer = new byte[BUFFER_SIZE];
-                OutputStream out = null;
-                try
-                {
-                    out = new FileOutputStream( targetFile );
-
-                    int len;
-                    while ( ( len = compressedInputStream.read( buffer ) ) >= 0 )
-                    {
-                        out.write( buffer, 0, len );
-                    }
-
-                    out.close();
-                    out = null;
-                }
-                finally
-                {
-                    IOUtil.close( out );
-                }
-                targetFile.setLastModified( entryDate.getTime() );
-            }
-        }
-    }
-
-    /**
-     * small helper method who deletes the given directory or file.
-     *
-     * @param targetFile
-     * @throws IOException
-     */
-    private void deleteFileOrDir( File targetFile )
-        throws IOException
-    {
-        if ( targetFile.isDirectory() )
-        {
-            FileUtils.deleteDirectory( targetFile );
-        }
-        else
-        {
-            FileUtils.delete( targetFile );
-        }
-
-    }
-}
diff --git a/src/test/java/org/apache/maven/shared/utils/ExpandTest.java b/src/test/java/org/apache/maven/shared/utils/ExpandTest.java
deleted file mode 100644
index 6718c83..0000000
--- a/src/test/java/org/apache/maven/shared/utils/ExpandTest.java
+++ /dev/null
@@ -1,336 +0,0 @@
-package org.apache.maven.shared.utils;
-
-/*
- * 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.
- */
-
-import org.apache.commons.lang3.exception.ExceptionUtils;
-import org.apache.maven.shared.utils.io.FileUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.Assert;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.net.URL;
-
-import static org.hamcrest.CoreMatchers.*;
-
-/**
- * This will test the plexus utility class {@link Expand}.
- *
- * Most of this stuff will be obsolete because java-1.4.2
- * introduced a java.util.zip package which works like a charm.
- *
- * We of course need to implement this class due to compatibility
- * reasons.
- *
- * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
- */
-public class ExpandTest
-    extends Assert
-{
-
-    private static final String TEST_ZIP_LOCATION = "/expand/expand_test.zip";
-    private static final String TEST_ZIP_TARGET_FOLDER = "expand_test_target/";
-
-    private static final String TEST_UNZIPPED_FILE = "expand_test/test_file.txt";
-    private static final String TEST_UNZIPPED_CONTENT = "TestContent";
-
-
-    @Rule
-    public TemporaryFolder tempFolder = new TemporaryFolder();
-
-    private File getSourceFile()
-    {
-        URL zipFileUrl = getClass().getResource( TEST_ZIP_LOCATION );
-
-        assertNotNull( zipFileUrl );
-
-        return new File( zipFileUrl.getFile() );
-    }
-
-    /**
-     * Create a clean target directory for unzipping.
-     * If it did exist, then clean it first.
-     *
-     * @return The target folder.
-     */
-    private File getTestTargetDir()
-        throws Exception
-    {
-        return tempFolder.newFolder( TEST_ZIP_TARGET_FOLDER );
-    }
-
-    @Test
-    public void testSetDest_No_NPE()
-    {
-        Expand expand = new Expand();
-        expand.setDest( null );
-    }
-
-    @Test
-    public void testSetSrc_No_NPE()
-    {
-        Expand expand = new Expand();
-        expand.setSrc( null );
-    }
-
-    @Test
-    public void testExecute()
-        throws Exception
-    {
-        Expand expand = new Expand();
-
-        File source = getSourceFile();
-        expand.setSrc( source );
-
-        File targetDir = getTestTargetDir();
-        expand.setDest( targetDir );
-
-        expand.execute();
-
-        verifyExpandedFileAndContent( targetDir, TEST_UNZIPPED_CONTENT );
-    }
-
-    @Test
-    public void testExecuteIntoNonexistingDirectory()
-        throws Exception
-    {
-        Expand expand = new Expand();
-
-        File source = getSourceFile();
-        expand.setSrc( source );
-
-        File nonexisingDir = new File( getTestTargetDir(), "nonexisting_dir" );
-
-        if ( nonexisingDir.exists() )
-        {
-            FileUtils.deleteDirectory( nonexisingDir );
-        }
-
-        expand.setDest( nonexisingDir );
-
-        expand.execute();
-
-        verifyExpandedFileAndContent( nonexisingDir, TEST_UNZIPPED_CONTENT );
-    }
-
-    @Test
-    public void testExecuteNonexistingSource()
-        throws Exception
-    {
-        Expand expand = new Expand();
-
-        File nonexistingSource = new File( "target/expand_test_target/nonexisting_source_file.nixda" );
-        expand.setSrc( nonexistingSource );
-
-        File targetDir = getTestTargetDir();
-        expand.setDest( targetDir );
-
-        try
-        {
-            expand.execute();
-            fail( "expand with notexiting source must throw Exception!" );
-        }
-        catch ( Exception e )
-        {
-            Throwable cause = ExceptionUtils.getRootCause( e );
-            if ( cause == null )
-            {
-                cause = e;
-            }
-
-            assertTrue( "cause must be a FileNotFoundException", cause instanceof FileNotFoundException );
-        }
-
-    }
-
-    @Test( expected = NullPointerException.class )
-    public void testExecute_NullSource()
-        throws Exception
-    {
-        Expand expand = new Expand();
-        expand.setSrc( null );
-
-        File targetDir = getTestTargetDir();
-        expand.setDest( targetDir );
-
-        expand.execute();
-    }
-
-    @Test
-    public void testExecute_NullDest()
-        throws Exception
-    {
-        Expand expand = new Expand();
-        expand.setSrc( getSourceFile() );
-
-        // execute without a dest directory seems to
-        // expand all the archive into the current working directory
-        expand.setDest( null );
-
-        String oldWorkingDirectory = System.getProperty( "user.dir" );
-
-        try
-        {
-            File targetDir = getTestTargetDir();
-            System.setProperty( "user.dir", targetDir.getAbsolutePath() );
-
-            expand.execute();
-
-            verifyExpandedFileAndContent( targetDir, TEST_UNZIPPED_CONTENT );
-        }
-        finally
-        {
-            System.setProperty( "user.dir", oldWorkingDirectory );
-        }
-    }
-
-    @Test
-    public void testExecute_Overwrite()
-        throws Exception
-    {
-        File targetDir = getTestTargetDir();
-        File expandedFile = null;
-
-        {
-            // part1: expand
-
-            Expand expand = new Expand();
-
-            File source = getSourceFile();
-            expand.setSrc( source );
-
-            expand.setDest( targetDir );
-
-            expand.execute();
-
-            expandedFile = verifyExpandedFile( targetDir );
-        }
-
-        // turn the clock back 10 seconds
-        long time = System.currentTimeMillis() - 10000L;
-
-        // round down to 1s;
-        time = time - time % 1000L;
-
-        expandedFile.setLastModified( time );
-        assertEquals( time, expandedFile.lastModified() );
-
-        {
-            // part2: expand in non-overwrite mode
-
-            Expand expand = new Expand();
-
-            File source = getSourceFile();
-            expand.setSrc( source );
-            expand.setDest( targetDir );
-
-            expand.setOverwrite( false );
-
-            expand.execute();
-
-            expandedFile = verifyExpandedFile( targetDir );
-
-            assertEquals( "file must still have the old lastModified timestamp"
-                        , time, expandedFile.lastModified() );
-
-        }
-
-        {
-            // part3: expand in overwrite mode but local file is still newer than the one in the archive
-
-            Expand expand = new Expand();
-
-            File source = getSourceFile();
-            expand.setSrc( source );
-            expand.setDest( targetDir );
-
-            expand.setOverwrite( true );
-
-            expand.execute();
-
-            expandedFile = verifyExpandedFile( targetDir );
-
-            // obviously the file will be overwritten anyway
-            assertTrue( "file must now have the original old lastModified timestamp, but was: time=" + time
-                        + " expandedFile.lastModified()= " + expandedFile.lastModified()
-                        , time > expandedFile.lastModified() );
-        }
-
-        // turn the clock back a loooong time!
-        time = 100000000L;
-
-        expandedFile.setLastModified( time );
-        assertEquals( time, expandedFile.lastModified() );
-
-        {
-            // part3: expand in overwrite mode but local file is now older than the one in the archive
-
-            Expand expand = new Expand();
-
-            File source = getSourceFile();
-            expand.setSrc( source );
-            expand.setDest( targetDir );
-
-            expand.setOverwrite( true );
-
-            expand.execute();
-
-            expandedFile = verifyExpandedFile( targetDir );
-
-            assertTrue( "file must now have newer lastModified timestamp, but was: time=" + time
-                        + " expandedFile.lastModified()= " + expandedFile.lastModified()
-                        , time < expandedFile.lastModified() );
-
-        }
-    }
-
-
-    private File verifyExpandedFile( File targetDir )
-    {
-        assertThat( "target directory must exist"
-                  , targetDir.exists()
-                  , is( true ) );
-
-        File expandedFile = new File( targetDir, TEST_UNZIPPED_FILE );
-
-        assertThat( "expanded file must exist: " + expandedFile.getAbsolutePath()
-                  , expandedFile.exists()
-                  , is( true ) );
-
-        return expandedFile;
-    }
-
-    private void verifyExpandedFileAndContent( File targetDir, String expectedContent )
-            throws FileNotFoundException
-    {
-        File expandedFile = verifyExpandedFile( targetDir );
-
-        assertNotNull( expandedFile );
-
-        java.util.Scanner scanner = new java.util.Scanner( expandedFile ).useDelimiter( "\n" );
-        String text = scanner.next();
-
-        assertThat( "expanded file content must match"
-                  , text
-                  , is( expectedContent ) );
-    }
-}