Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugins</artifactId>
<version>42</version>
<version>44</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -125,6 +125,7 @@ under the License.
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${version.maven-plugin-tools}</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.attribute.FileTime;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -59,13 +57,12 @@
import org.codehaus.plexus.archiver.tar.TarLongFileMode;
import org.codehaus.plexus.archiver.war.WarArchiver;
import org.codehaus.plexus.archiver.zip.AbstractZipArchiver;
import org.codehaus.plexus.component.configurator.BasicComponentConfigurator;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
Expand Down Expand Up @@ -98,16 +95,20 @@ public class DefaultAssemblyArchiver implements AssemblyArchiver {

private final PlexusContainer container;

private final BasicComponentConfigurator configurator;

@Inject
public DefaultAssemblyArchiver(
ArchiverManager archiverManager,
List<AssemblyArchiverPhase> assemblyPhases,
Map<String, ContainerDescriptorHandler> containerDescriptorHandlers,
PlexusContainer container) {
PlexusContainer container,
BasicComponentConfigurator configurator) {
this.archiverManager = requireNonNull(archiverManager);
this.assemblyPhases = requireNonNull(assemblyPhases);
this.containerDescriptorHandlers = requireNonNull(containerDescriptorHandlers);
this.container = requireNonNull(container);
this.configurator = requireNonNull(configurator);
}

private List<AssemblyArchiverPhase> sortedPhases() {
Expand Down Expand Up @@ -398,53 +399,14 @@ private void configureArchiver(final Archiver archiver, final AssemblerConfigura
private void configureComponent(
final Object component, final Xpp3Dom config, final AssemblerConfigurationSource configSource)
throws ComponentLookupException, ComponentConfigurationException {
final ComponentConfigurator configurator = container.lookup(ComponentConfigurator.class, "basic");

final ConfigurationListener listener = new DebugConfigurationListener(LOGGER);

final ExpressionEvaluator expressionEvaluator = new AssemblyExpressionEvaluator(configSource);

final XmlPlexusConfiguration configuration = new XmlPlexusConfiguration(config);

final Object[] containerRealm = getContainerRealm();

/*
* NOTE: The signature of configureComponent() has changed in Maven 3.x, the reflection prevents a linkage error
* and makes the code work with both Maven 2 and 3.
*/
try {
final Method configureComponent = ComponentConfigurator.class.getMethod(
"configureComponent",
Object.class,
PlexusConfiguration.class,
ExpressionEvaluator.class,
(Class<?>) containerRealm[1],
ConfigurationListener.class);

configureComponent.invoke(
configurator, component, configuration, expressionEvaluator, containerRealm[0], listener);
} catch (final NoSuchMethodException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (final InvocationTargetException e) {
if (e.getCause() instanceof ComponentConfigurationException) {
throw (ComponentConfigurationException) e.getCause();
}
throw new RuntimeException(e.getCause());
}
}

private Object[] getContainerRealm() {
/*
* NOTE: The return type of getContainerRealm() has changed in Maven 3.x, the reflection prevents a linkage
* error and makes the code work with both Maven 2 and 3.
*/
try {
final Method getContainerRealm = container.getClass().getMethod("getContainerRealm");
return new Object[] {getContainerRealm.invoke(container), getContainerRealm.getReturnType()};
} catch (final NoSuchMethodException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (final InvocationTargetException e) {
throw new RuntimeException(e.getCause());
}
configurator.configureComponent(
component, configuration, expressionEvaluator, container.getContainerRealm(), listener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.codehaus.plexus.archiver.tar.TarLongFileMode;
import org.codehaus.plexus.archiver.war.WarArchiver;
import org.codehaus.plexus.archiver.zip.ZipArchiver;
import org.codehaus.plexus.component.configurator.BasicComponentConfigurator;
import org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -74,6 +75,8 @@ public class DefaultAssemblyArchiverTest {

private PlexusContainer container;

private BasicComponentConfigurator configurator;

public static void setupInterpolators(AssemblerConfigurationSource configSource) {
when(configSource.getRepositoryInterpolator()).thenReturn(FixedStringSearchInterpolator.create());
when(configSource.getCommandLinePropsInterpolator()).thenReturn(FixedStringSearchInterpolator.create());
Expand All @@ -91,6 +94,7 @@ public static void setupInterpolators(AssemblerConfigurationSource configSource,
public void setup() throws PlexusContainerException {
this.archiverManager = mock(ArchiverManager.class);
this.container = new DefaultPlexusContainer();
this.configurator = new BasicComponentConfigurator();
}

@Test(expected = InvalidAssemblerConfigurationException.class)
Expand Down Expand Up @@ -156,7 +160,7 @@ public void testCreateArchive() throws Exception {
}

@Test
public void testCreateArchiver_ShouldConfigureArchiver() throws Exception {
public void testCreateArchiverShouldConfigureArchiver() throws Exception {
final TestArchiverWithConfig archiver = new TestArchiverWithConfig();

when(archiverManager.getArchiver("dummy")).thenReturn(archiver);
Expand Down Expand Up @@ -192,7 +196,7 @@ public void testCreateArchiver_ShouldConfigureArchiver() throws Exception {
}

@Test
public void testCreateArchiver_ShouldCreateTarArchiverWithNoCompression() throws Exception {
public void testCreateArchiverShouldCreateTarArchiverWithNoCompression() throws Exception {
final TestTarArchiver ttArchiver = new TestTarArchiver();

when(archiverManager.getArchiver("tar")).thenReturn(ttArchiver);
Expand Down Expand Up @@ -229,7 +233,7 @@ public void testCreateArchiver_ShouldCreateTarArchiverWithNoCompression() throws
}

@Test
public void testCreateArchiver_ShouldCreateWarArchiverWitEexpectWebXmlSetToFalse() throws Exception {
public void testCreateArchiverShouldCreateWarArchiverWitExpectWebXmlSetToFalse() throws Exception {
final TestWarArchiver twArchiver = new TestWarArchiver();

when(archiverManager.getArchiver("war")).thenReturn(twArchiver);
Expand Down Expand Up @@ -269,7 +273,7 @@ public void testCreateArchiver_ShouldCreateWarArchiverWitEexpectWebXmlSetToFalse
}

@Test
public void testCreateArchiver_ShouldCreateZipArchiver() throws Exception {
public void testCreateArchiverShouldCreateZipArchiver() throws Exception {
final ZipArchiver archiver = new ZipArchiver();

when(archiverManager.getArchiver("zip")).thenReturn(archiver);
Expand Down Expand Up @@ -302,7 +306,7 @@ public void testCreateArchiver_ShouldCreateZipArchiver() throws Exception {
}

@Test
public void testCreateTarArchiver_ShouldNotInitializeCompression() throws Exception {
public void testCreateTarArchiverShouldNotInitializeCompression() throws Exception {
final TestTarArchiver archiver = new TestTarArchiver();

when(archiverManager.getArchiver("tar")).thenReturn(archiver);
Expand All @@ -324,7 +328,7 @@ public void testCreateTarArchiver_ShouldNotInitializeCompression() throws Except
}

@Test
public void testCreateTarArchiver_InvalidFormat_ShouldFailWithInvalidCompression() throws Exception {
public void testCreateTarArchiverInvalidFormatShouldFailWithInvalidCompression() throws Exception {

when(archiverManager.getArchiver("tar.ZZZ")).thenThrow(new NoSuchArchiverException("no archiver"));

Expand All @@ -343,7 +347,7 @@ public void testCreateTarArchiver_InvalidFormat_ShouldFailWithInvalidCompression
}

private DefaultAssemblyArchiver createSubject(final List<AssemblyArchiverPhase> phases) {
return new DefaultAssemblyArchiver(archiverManager, phases, Collections.emptyMap(), container);
return new DefaultAssemblyArchiver(archiverManager, phases, Collections.emptyMap(), container, configurator);
}

private static final class TestTarArchiver extends TarArchiver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class AssemblyProxyArchiverTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@Test(timeout = 5000)
public void addFileSet_SkipWhenSourceIsAssemblyWorkDir() throws IOException, ArchiverException {
public void addFileSetSkipWhenSourceIsAssemblyWorkDir() throws IOException, ArchiverException {
final File sources = temporaryFolder.getRoot();

final File workdir = new File(sources, "workdir");
Expand All @@ -76,7 +76,7 @@ public void addFileSet_SkipWhenSourceIsAssemblyWorkDir() throws IOException, Arc
}

@Test(timeout = 5000)
public void addFileSet_addExcludeWhenSourceContainsAssemblyWorkDir() throws IOException, ArchiverException {
public void addFileSetAddExcludeWhenSourceContainsAssemblyWorkDir() throws IOException, ArchiverException {
final File sources = temporaryFolder.getRoot();

final File workdir = new File(sources, "workdir");
Expand Down Expand Up @@ -110,7 +110,7 @@ public void addFileSet_addExcludeWhenSourceContainsAssemblyWorkDir() throws IOEx
}

@Test
public void addFile_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
public void addFileNoPermsCallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
final Archiver delegate = mock(Archiver.class);

final CounterSelector counter = new CounterSelector(true);
Expand All @@ -131,7 +131,7 @@ public void addFile_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, Archiv

@Test
@SuppressWarnings("deprecation")
public void addDirectory_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
public void addDirectoryNoPermsCallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
final Archiver delegate = new JarArchiver();

final File output = temporaryFolder.newFile();
Expand Down Expand Up @@ -190,11 +190,11 @@ private static final class CounterSelector implements FileSelector {

private boolean answer = false;

public CounterSelector(final boolean answer) {
CounterSelector(final boolean answer) {
this.answer = answer;
}

public int getCount() {
int getCount() {
return count;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setUp() {
}

@Test
public void testExecute_ShouldAddOneDependencyFromProject()
public void testExecuteShouldAddOneDependencyFromProject()
throws AssemblyFormattingException, ArchiveCreationException, IOException,
InvalidAssemblerConfigurationException, DependencyResolutionException {
final String outputLocation = "/out";
Expand Down Expand Up @@ -95,7 +95,7 @@ public void testExecute_ShouldAddOneDependencyFromProject()
}

@Test
public void testExecute_ShouldNotAddDependenciesWhenProjectHasNone() throws Exception {
public void testExecuteShouldNotAddDependenciesWhenProjectHasNone() throws Exception {
final Assembly assembly = new Assembly();
assembly.setId("test");
assembly.setIncludeBaseDirectory(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class FileItemAssemblyPhaseTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@Test
public void testExecute_ShouldAddNothingWhenNoFileItemsArePresent() throws Exception {
public void testExecuteShouldAddNothingWhenNoFileItemsArePresent() throws Exception {
final AssemblerConfigurationSource macCS = mock(AssemblerConfigurationSource.class);

final File basedir = temporaryFolder.getRoot();
Expand All @@ -70,7 +70,7 @@ public void testExecute_ShouldAddNothingWhenNoFileItemsArePresent() throws Excep
}

@Test
public void testExecute_ShouldAddAbsoluteFileNoFilterNoLineEndingConversion() throws Exception {
public void testExecuteShouldAddAbsoluteFileNoFilterNoLineEndingConversion() throws Exception {
final AssemblerConfigurationSource macCS = mock(AssemblerConfigurationSource.class);

final File basedir = temporaryFolder.getRoot();
Expand Down Expand Up @@ -104,7 +104,7 @@ public void testExecute_ShouldAddAbsoluteFileNoFilterNoLineEndingConversion() th
}

@Test
public void testExecute_ShouldAddRelativeFileNoFilterNoLineEndingConversion() throws Exception {
public void testExecuteShouldAddRelativeFileNoFilterNoLineEndingConversion() throws Exception {
final AssemblerConfigurationSource macCS = mock(AssemblerConfigurationSource.class);

final File basedir = temporaryFolder.getRoot();
Expand Down Expand Up @@ -138,7 +138,7 @@ public void testExecute_ShouldAddRelativeFileNoFilterNoLineEndingConversion() th
}

@Test
public void testExecute_WithOutputDirectory() throws Exception {
public void testExecuteWithOutputDirectory() throws Exception {
final AssemblerConfigurationSource macCS = mock(AssemblerConfigurationSource.class);

final File basedir = temporaryFolder.getRoot();
Expand Down Expand Up @@ -217,7 +217,7 @@ public void testExecute_WithOutputDirectory() throws Exception {
}

@Test
public void testExecute_WithOutputDirectoryAndDestName() throws Exception {
public void testExecuteWithOutputDirectoryAndDestName() throws Exception {
final AssemblerConfigurationSource macCS = mock(AssemblerConfigurationSource.class);

final File basedir = temporaryFolder.getRoot();
Expand Down Expand Up @@ -299,7 +299,7 @@ public void testExecute_WithOutputDirectoryAndDestName() throws Exception {
}

@Test
public void testExecute_WithOutputDirectoryAndDestNameAndIncludeBaseDirectoryFalse() throws Exception {
public void testExecuteWithOutputDirectoryAndDestNameAndIncludeBaseDirectoryFalse() throws Exception {
final AssemblerConfigurationSource macCS = mock(AssemblerConfigurationSource.class);

final File basedir = temporaryFolder.getRoot();
Expand Down
Loading
Loading