|
1 | 1 | package org.apache.maven.plugins.dependency.testUtils;
|
2 | 2 |
|
3 |
| -/* |
| 3 | +/* |
4 | 4 | * Licensed to the Apache Software Foundation (ASF) under one
|
5 | 5 | * or more contributor license agreements. See the NOTICE file
|
6 | 6 | * distributed with this work for additional information
|
|
28 | 28 | import org.apache.maven.artifact.Artifact;
|
29 | 29 | import org.apache.maven.artifact.ArtifactUtils;
|
30 | 30 | import org.apache.maven.artifact.versioning.VersionRange;
|
31 |
| -import org.apache.maven.plugins.dependency.fromConfiguration.ArtifactItem; |
32 | 31 | import org.apache.maven.plugin.testing.ArtifactStubFactory;
|
| 32 | +import org.apache.maven.plugins.dependency.fromConfiguration.ArtifactItem; |
| 33 | +import org.codehaus.plexus.archiver.Archiver; |
| 34 | +import org.codehaus.plexus.archiver.ArchiverException; |
| 35 | +import org.codehaus.plexus.archiver.manager.ArchiverManager; |
| 36 | +import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; |
| 37 | +import org.codehaus.plexus.archiver.war.WarArchiver; |
33 | 38 |
|
34 | 39 | public class DependencyArtifactStubFactory
|
35 | 40 | extends ArtifactStubFactory
|
36 | 41 | {
|
37 | 42 | private boolean flattenedPath = true;
|
| 43 | + private ArchiverManager archiverManager; |
38 | 44 |
|
39 | 45 | public DependencyArtifactStubFactory( File theWorkingDir, boolean theCreateFiles, boolean flattenedPath )
|
40 | 46 | {
|
@@ -95,4 +101,37 @@ public Artifact createArtifact( String groupId, String artifactId, VersionRange
|
95 | 101 |
|
96 | 102 | return artifact;
|
97 | 103 | }
|
| 104 | + |
| 105 | + |
| 106 | + @Override |
| 107 | + public void setUnpackableFile( ArchiverManager archiverManager ) |
| 108 | + { |
| 109 | + // it is needed in createUnpackableFile method |
| 110 | + this.archiverManager = archiverManager; |
| 111 | + super.setUnpackableFile( archiverManager ); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * We need override original method which try to set wrong class of logger on Archiver. |
| 116 | + * <p> |
| 117 | + * Newer version of Archiver use SLF4J instead of Plexus logger. |
| 118 | + */ |
| 119 | + @Override |
| 120 | + public void createUnpackableFile( Artifact artifact, File destFile ) |
| 121 | + throws NoSuchArchiverException, ArchiverException, IOException |
| 122 | + { |
| 123 | + Archiver archiver = archiverManager.getArchiver( destFile ); |
| 124 | + |
| 125 | + archiver.setDestFile( destFile ); |
| 126 | + archiver.addFile( getSrcFile(), getUnpackableFileName( artifact ) ); |
| 127 | + |
| 128 | + if ( archiver instanceof WarArchiver ) |
| 129 | + { |
| 130 | + WarArchiver war = (WarArchiver) archiver; |
| 131 | + // the use of this is counter-intuitive: |
| 132 | + // http://jira.codehaus.org/browse/PLX-286 |
| 133 | + war.setIgnoreWebxml( false ); |
| 134 | + } |
| 135 | + archiver.createArchive(); |
| 136 | + } |
98 | 137 | }
|
0 commit comments