Skip to content

Commit

Permalink
Drop legacy plexus API and use only JSR330 components (#220)
Browse files Browse the repository at this point in the history
Drop:
- plexus container default
- legacy plexus APIs like Contextualizable
- drop Plexus Logger uses
- some minor cleanups for Java8 level
- converted Plexus XML to JSR330
- dropped plexus container (so no pcd or shim) as it is not needed anymore, plexus-io is not plx anymore as well

This is a breaking change (for example Plexus vs Slf4j logger use on APIs), so version bump is imminent.
  • Loading branch information
cstamas committed Jun 23, 2022
1 parent 337214c commit 48d3280
Show file tree
Hide file tree
Showing 123 changed files with 1,717 additions and 967 deletions.
59 changes: 50 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

<properties>
<javaVersion>8</javaVersion>
<sisuVersion>0.3.5</sisuVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<project.build.outputTimestamp>2022-06-10T17:04:57Z</project.build.outputTimestamp>
</properties>

Expand All @@ -49,13 +51,13 @@
</contributors>

<dependencies>
<!-- Plexus dependencies -->
<!-- JSR330 -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<version>2.1.1</version>
<scope>provided</scope>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Plexus dependencies -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand All @@ -64,7 +66,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-io</artifactId>
<version>3.3.1</version>
<version>3.4.0</version>
</dependency>
<!-- Apache Commons dependencies -->
<dependency>
Expand All @@ -78,6 +80,11 @@
<version>1.21</version>
</dependency>
<!-- Other dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
</dependency>
<dependency>
<groupId>org.iq80.snappy</groupId>
<artifactId>snappy</artifactId>
Expand All @@ -101,6 +108,37 @@
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>
<!-- Plexus container dependencies -->
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
<version>${sisuVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand All @@ -127,12 +165,15 @@
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
<version>${sisuVersion}</version>
<executions>
<execution>
<id>index-project</id>
<goals>
<goal>generate-metadata</goal>
<goal>main-index</goal>
<goal>test-index</goal>
</goals>
</execution>
</executions>
Expand Down
92 changes: 26 additions & 66 deletions src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Nonnull;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import javax.inject.Inject;
import javax.inject.Provider;

import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes;
import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier;
Expand All @@ -49,21 +49,22 @@
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
import org.codehaus.plexus.components.io.resources.proxy.PlexusIoProxyResourceCollection;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.codehaus.plexus.archiver.util.DefaultArchivedFileSet.archivedFileSet;
import static org.codehaus.plexus.archiver.util.DefaultFileSet.fileSet;

public abstract class AbstractArchiver
extends AbstractLogEnabled
implements Archiver, Contextualizable, FinalizerEnabled
implements Archiver, FinalizerEnabled
{

private Logger logger;
private final Logger logger = LoggerFactory.getLogger( getClass() );

protected Logger getLogger()
{
return logger;
}

private File destFile;

Expand Down Expand Up @@ -135,8 +136,12 @@ public abstract class AbstractArchiver
*/
private String overrideGroupName;

// contextualized.
private ArchiverManager archiverManager;
/**
* Injected: Allows us to pull the ArchiverManager instance out of the container without causing a chicken-and-egg
* instantiation/composition problem.
*/
@Inject
private Provider<ArchiverManager> archiverManagerProvider;

private static class AddedResourceCollection
{
Expand Down Expand Up @@ -186,7 +191,7 @@ public void setDuplicateBehavior( final String duplicate )
if ( !Archiver.DUPLICATES_VALID_BEHAVIORS.contains( duplicate ) )
{
throw new IllegalArgumentException(
"Invalid duplicate-file behavior: \'" + duplicate + "\'. Please specify one of: "
"Invalid duplicate-file behavior: '" + duplicate + "'. Please specify one of: "
+ Archiver.DUPLICATES_VALID_BEHAVIORS );
}

Expand Down Expand Up @@ -524,15 +529,15 @@ public ResourceIterator getResources()
return new ResourceIterator()
{

private final Iterator addedResourceIter = resources.iterator();
private final Iterator<Object> addedResourceIter = resources.iterator();

private AddedResourceCollection currentResourceCollection;

private Iterator ioResourceIter;

private ArchiveEntry nextEntry;

private final Set<String> seenEntries = new HashSet<String>();
private final Set<String> seenEntries = new HashSet<>();

@Override
public boolean hasNext()
Expand Down Expand Up @@ -727,24 +732,6 @@ public void setDestFile( final File destFile )
}
}

@Override
protected Logger getLogger()
{
if ( logger == null )
{
if ( super.getLogger() != null )
{
logger = super.getLogger();
}
else
{
logger = new ConsoleLogger( Logger.LEVEL_INFO, "console" );
}
}

return logger;
}

protected PlexusIoResourceCollection asResourceCollection( final ArchivedFileSet fileSet, Charset charset )
throws ArchiverException
{
Expand All @@ -753,7 +740,7 @@ protected PlexusIoResourceCollection asResourceCollection( final ArchivedFileSet
final PlexusIoResourceCollection resources;
try
{
resources = archiverManager.getResourceCollection( archiveFile );
resources = archiverManagerProvider.get().getResourceCollection( archiveFile );
}
catch ( final NoSuchArchiverException e )
{
Expand Down Expand Up @@ -880,26 +867,6 @@ public void addArchivedFileSet( @Nonnull final File archiveFile )
addArchivedFileSet( archivedFileSet( archiveFile ).includeEmptyDirs( includeEmptyDirs ) );
}

/**
* Allows us to pull the ArchiverManager instance out of the container without causing a chicken-and-egg
* instantiation/composition problem.
*/
@Override
public void contextualize( final Context context )
throws ContextException
{
final PlexusContainer container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );

try
{
archiverManager = (ArchiverManager) container.lookup( ArchiverManager.ROLE );
}
catch ( final ComponentLookupException e )
{
throw new ContextException( "Error retrieving ArchiverManager instance: " + e.getMessage(), e );
}
}

@Override
public boolean isForced()
{
Expand All @@ -917,7 +884,7 @@ public void addArchiveFinalizer( final ArchiveFinalizer finalizer )
{
if ( finalizers == null )
{
finalizers = new ArrayList<ArchiveFinalizer>();
finalizers = new ArrayList<>();
}

finalizers.add( finalizer );
Expand Down Expand Up @@ -946,7 +913,7 @@ protected boolean isUptodate()
}
final long destTimestamp = getFileLastModifiedTime(zipFile);

final Iterator it = resources.iterator();
final Iterator<Object> it = resources.iterator();
if ( !it.hasNext() )
{
getLogger().debug( "isUp2date: false (No input files.)" );
Expand Down Expand Up @@ -1314,14 +1281,7 @@ public void configureReproducibleBuild( FileTime lastModifiedTime )
setLastModifiedTime( normalizeLastModifiedTime ( lastModifiedTime ) );

// 2. sort filenames in each directory when scanning filesystem
setFilenameComparator( new Comparator<String>()
{
@Override
public int compare( String s1, String s2 )
{
return s1.compareTo( s2 );
}
} );
setFilenameComparator( String::compareTo );

// 3. ignore file/directory mode from filesystem, since they may vary based on local user umask
// notice: this overrides execute bit on Unix (that is already ignored on Windows)
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/org/codehaus/plexus/archiver/AbstractUnArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,34 @@
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;

import org.codehaus.plexus.archiver.util.ArchiveEntryUtils;
import org.codehaus.plexus.components.io.attributes.SymlinkUtils;
import org.codehaus.plexus.components.io.filemappers.FileMapper;
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// TODO there should really be constructors which take the source file.

/**
* @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
*/
public abstract class AbstractUnArchiver
extends AbstractLogEnabled
implements UnArchiver, FinalizerEnabled
{
private final Logger logger = LoggerFactory.getLogger( getClass() );

protected Logger getLogger()
{
return logger;
}

private File destDirectory;

Expand Down Expand Up @@ -384,6 +392,11 @@ else if ( isDirectory )
}
}

/**
* Counter for casing message emitted, visible for testing.
*/
final AtomicInteger casingMessageEmitted = new AtomicInteger( 0 );

// Visible for testing
protected boolean shouldExtractEntry( File targetDirectory, File targetFileName, String entryName, Date entryDate ) throws IOException
{
Expand Down Expand Up @@ -423,6 +436,7 @@ protected boolean shouldExtractEntry( File targetDirectory, File targetFileName,
if ( differentCasing )
{
getLogger().warn( casingMessage );
casingMessageEmitted.incrementAndGet();
}
return false;
}
Expand All @@ -431,6 +445,7 @@ protected boolean shouldExtractEntry( File targetDirectory, File targetFileName,
if ( differentCasing )
{
getLogger().warn( casingMessage );
casingMessageEmitted.incrementAndGet();
}

// (2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ArchiveEntry

public static final int SYMLINK = 3;

@Nonnull private PlexusIoResource resource;
@Nonnull private final PlexusIoResource resource;

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ArchiveFile
* Any element returned by the enumeration is an instance
* of {@link org.apache.commons.compress.archivers.ArchiveEntry}.
*/
public Enumeration<? extends org.apache.commons.compress.archivers.ArchiveEntry> getEntries()
Enumeration<? extends org.apache.commons.compress.archivers.ArchiveEntry> getEntries()
throws IOException;

/**
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/codehaus/plexus/archiver/Archiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ public interface Archiver
*/
int DEFAULT_SYMLILNK_MODE = UnixStat.LINK_FLAG | UnixStat.DEFAULT_LINK_PERM;

String ROLE = Archiver.class.getName();
String DUPLICATES_ADD = "add";

public static final String DUPLICATES_ADD = "add";
String DUPLICATES_PRESERVE = "preserve";

public static final String DUPLICATES_PRESERVE = "preserve";
String DUPLICATES_SKIP = "skip";

public static final String DUPLICATES_SKIP = "skip";
String DUPLICATES_FAIL = "fail";

public static final String DUPLICATES_FAIL = "fail";

public static final Set<String> DUPLICATES_VALID_BEHAVIORS = new HashSet<String>()
Set<String> DUPLICATES_VALID_BEHAVIORS = new HashSet<String>()
{

private static final long serialVersionUID = 1L;
Expand Down

0 comments on commit 48d3280

Please sign in to comment.