1818 */
1919package org .apache .maven .artifact ;
2020
21+ import javax .inject .Inject ;
22+
2123import java .io .File ;
2224import java .io .FileOutputStream ;
2325import java .io .IOException ;
3133import org .apache .maven .artifact .repository .ArtifactRepository ;
3234import org .apache .maven .artifact .repository .ArtifactRepositoryPolicy ;
3335import org .apache .maven .artifact .repository .layout .ArtifactRepositoryLayout ;
36+ import org .apache .maven .artifact .resolver .TestMavenWorkspaceReader ;
3437import org .apache .maven .execution .DefaultMavenExecutionRequest ;
3538import org .apache .maven .execution .DefaultMavenExecutionResult ;
3639import org .apache .maven .execution .MavenSession ;
3740import org .apache .maven .plugin .LegacySupport ;
3841import org .apache .maven .repository .legacy .repository .ArtifactRepositoryFactory ;
39- import org .codehaus .plexus .ContainerConfiguration ;
40- import org .codehaus .plexus .PlexusConstants ;
41- import org .codehaus .plexus .PlexusTestCase ;
42- import org .codehaus .plexus .component .repository .exception .ComponentLookupException ;
4342import org .eclipse .aether .DefaultRepositorySystemSession ;
4443import org .eclipse .aether .RepositorySystemSession ;
4544import org .eclipse .aether .collection .DependencyGraphTransformer ;
4847import org .eclipse .aether .collection .DependencyTraverser ;
4948import org .eclipse .aether .internal .impl .SimpleLocalRepositoryManagerFactory ;
5049import org .eclipse .aether .repository .LocalRepository ;
51- import org .eclipse .aether .repository .WorkspaceReader ;
5250import org .eclipse .aether .util .graph .manager .ClassicDependencyManager ;
5351import org .eclipse .aether .util .graph .selector .AndDependencySelector ;
5452import org .eclipse .aether .util .graph .selector .ExclusionDependencySelector ;
6361import org .eclipse .aether .util .graph .transformer .SimpleOptionalitySelector ;
6462import org .eclipse .aether .util .graph .traverser .FatArtifactTraverser ;
6563import org .eclipse .aether .util .repository .SimpleArtifactDescriptorPolicy ;
64+ import org .junit .jupiter .api .BeforeEach ;
65+
66+ import static org .codehaus .plexus .testing .PlexusExtension .getBasedir ;
67+ import static org .junit .jupiter .api .Assertions .fail ;
6668
6769/**
6870 * @author <a href="mailto:[email protected] ">Jason van Zyl </a> 6971 */
70- public abstract class AbstractArtifactComponentTestCase extends PlexusTestCase {
72+ public abstract class AbstractArtifactComponentTest {
73+
74+ @ Inject
7175 protected ArtifactFactory artifactFactory ;
7276
77+ @ Inject
7378 protected ArtifactRepositoryFactory artifactRepositoryFactory ;
7479
75- @ Override
76- protected void customizeContainerConfiguration (ContainerConfiguration containerConfiguration ) {
77- super .customizeContainerConfiguration (containerConfiguration );
78- containerConfiguration .setAutoWiring (true );
79- containerConfiguration .setClassPathScanning (PlexusConstants .SCANNING_INDEX );
80- }
80+ @ Inject
81+ private LegacySupport legacySupport ;
8182
82- @ Override
83+ @ Inject
84+ private ArtifactRepositoryLayout repoLayout ;
85+
86+ @ BeforeEach
8387 protected void setUp () throws Exception {
84- super .setUp ();
85- artifactFactory = lookup (ArtifactFactory .class );
86- artifactRepositoryFactory = lookup (ArtifactRepositoryFactory .class );
8788
8889 RepositorySystemSession repoSession = initRepoSession ();
8990 MavenSession session = new MavenSession (
90- getContainer () , repoSession , new DefaultMavenExecutionRequest (), new DefaultMavenExecutionResult ());
91+ null , repoSession , new DefaultMavenExecutionRequest (), new DefaultMavenExecutionResult ());
9192
92- LegacySupport legacySupport = lookup (LegacySupport .class );
9393 legacySupport .setSession (session );
9494 }
9595
96- @ Override
97- protected void tearDown () throws Exception {
98- release (artifactFactory );
99-
100- super .tearDown ();
101- }
102-
10396 protected abstract String component ();
10497
105- /**
106- * Return an existing file, not a directory - causes creation to fail.
107- *
108- * @throws Exception
109- */
110- protected ArtifactRepository badLocalRepository () throws Exception {
111- String path = "target/test-repositories/" + component () + "/bad-local-repository" ;
112-
113- File f = new File (getBasedir (), path );
114-
115- f .createNewFile ();
116-
117- ArtifactRepositoryLayout repoLayout =
118- (ArtifactRepositoryLayout ) lookup (ArtifactRepositoryLayout .ROLE , "default" );
119-
120- return artifactRepositoryFactory .createArtifactRepository (
121- "test" , "file://" + f .getPath (), repoLayout , null , null );
122- }
123-
124- protected String getRepositoryLayout () {
125- return "default" ;
126- }
127-
12898 protected ArtifactRepository localRepository () throws Exception {
12999 String path = "target/test-repositories/" + component () + "/local-repository" ;
130100
131101 File f = new File (getBasedir (), path );
132102
133- ArtifactRepositoryLayout repoLayout =
134- (ArtifactRepositoryLayout ) lookup (ArtifactRepositoryLayout .ROLE , "default" );
135-
136103 return artifactRepositoryFactory .createArtifactRepository (
137104 "local" , "file://" + f .getPath (), repoLayout , null , null );
138105 }
@@ -142,9 +109,6 @@ protected ArtifactRepository remoteRepository() throws Exception {
142109
143110 File f = new File (getBasedir (), path );
144111
145- ArtifactRepositoryLayout repoLayout =
146- (ArtifactRepositoryLayout ) lookup (ArtifactRepositoryLayout .ROLE , "default" );
147-
148112 return artifactRepositoryFactory .createArtifactRepository (
149113 "test" ,
150114 "file://" + f .getPath (),
@@ -154,25 +118,11 @@ protected ArtifactRepository remoteRepository() throws Exception {
154118 }
155119
156120 protected ArtifactRepository badRemoteRepository () throws Exception {
157- ArtifactRepositoryLayout repoLayout =
158- (ArtifactRepositoryLayout ) lookup (ArtifactRepositoryLayout .ROLE , "default" );
159121
160122 return artifactRepositoryFactory .createArtifactRepository (
161123 "test" , "http://foo.bar/repository" , repoLayout , null , null );
162124 }
163125
164- protected void assertRemoteArtifactPresent (Artifact artifact ) throws Exception {
165- ArtifactRepository remoteRepo = remoteRepository ();
166-
167- String path = remoteRepo .pathOf (artifact );
168-
169- File file = new File (remoteRepo .getBasedir (), path );
170-
171- if (!file .exists ()) {
172- fail ("Remote artifact " + file + " should be present." );
173- }
174- }
175-
176126 protected void assertLocalArtifactPresent (Artifact artifact ) throws Exception {
177127 ArtifactRepository localRepo = localRepository ();
178128
@@ -185,30 +135,6 @@ protected void assertLocalArtifactPresent(Artifact artifact) throws Exception {
185135 }
186136 }
187137
188- protected void assertRemoteArtifactNotPresent (Artifact artifact ) throws Exception {
189- ArtifactRepository remoteRepo = remoteRepository ();
190-
191- String path = remoteRepo .pathOf (artifact );
192-
193- File file = new File (remoteRepo .getBasedir (), path );
194-
195- if (file .exists ()) {
196- fail ("Remote artifact " + file + " should not be present." );
197- }
198- }
199-
200- protected void assertLocalArtifactNotPresent (Artifact artifact ) throws Exception {
201- ArtifactRepository localRepo = localRepository ();
202-
203- String path = localRepo .pathOf (artifact );
204-
205- File file = new File (localRepo .getBasedir (), path );
206-
207- if (file .exists ()) {
208- fail ("Local artifact " + file + " should not be present." );
209- }
210- }
211-
212138 // ----------------------------------------------------------------------
213139 //
214140 // ----------------------------------------------------------------------
@@ -241,14 +167,6 @@ protected Artifact createRemoteArtifact(String artifactId, String version) throw
241167 return artifact ;
242168 }
243169
244- protected void createLocalArtifact (Artifact artifact ) throws Exception {
245- createArtifact (artifact , localRepository ());
246- }
247-
248- protected void createRemoteArtifact (Artifact artifact ) throws Exception {
249- createArtifact (artifact , remoteRepository ());
250- }
251-
252170 protected void createArtifact (Artifact artifact , ArtifactRepository repository ) throws Exception {
253171 String path = repository .pathOf (artifact );
254172
@@ -315,11 +233,7 @@ protected RepositorySystemSession initRepoSession() throws Exception {
315233
316234 LocalRepository localRepo = new LocalRepository (localRepository ().getBasedir ());
317235 session .setLocalRepositoryManager (new SimpleLocalRepositoryManagerFactory ().newInstance (session , localRepo ));
318- try {
319- session .setWorkspaceReader (lookup (WorkspaceReader .class , "test" ));
320- } catch (ComponentLookupException e ) {
321- // no reader, nothing to do...
322- }
236+ session .setWorkspaceReader (new TestMavenWorkspaceReader ());
323237
324238 return session ;
325239 }
0 commit comments