1 package org.apache.maven.shared.artifact.install.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Collection;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.project.ProjectBuildingRequest;
27 import org.apache.maven.shared.artifact.install.ArtifactInstaller;
28 import org.apache.maven.shared.artifact.install.ArtifactInstallerException;
29 import org.codehaus.plexus.PlexusConstants;
30 import org.codehaus.plexus.PlexusContainer;
31 import org.codehaus.plexus.component.annotations.Component;
32 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
33 import org.codehaus.plexus.context.Context;
34 import org.codehaus.plexus.context.ContextException;
35 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
36
37
38
39
40 @Component( role = ArtifactInstaller.class )
41 public class DefaultArtifactInstaller
42 implements ArtifactInstaller, Contextualizable
43 {
44
45 private PlexusContainer container;
46
47 @Override
48 public void install( ProjectBuildingRequest request, Collection<Artifact> mavenArtifacts )
49 throws ArtifactInstallerException
50 {
51 try
52 {
53 String hint = isMaven31() ? "maven31" : "maven3";
54
55 ArtifactInstaller effectiveArtifactInstaller = container.lookup( ArtifactInstaller.class, hint );
56
57 effectiveArtifactInstaller.install( request, mavenArtifacts );
58 }
59 catch ( ComponentLookupException e )
60 {
61 throw new ArtifactInstallerException( e.getMessage(), e );
62 }
63 }
64
65 @Override
66 public void install( ProjectBuildingRequest request, File localRepositry, Collection<Artifact> mavenArtifacts )
67 throws ArtifactInstallerException
68 {
69 try
70 {
71 String hint = isMaven31() ? "maven31" : "maven3";
72
73 ArtifactInstaller effectiveArtifactInstaller = container.lookup( ArtifactInstaller.class, hint );
74
75 effectiveArtifactInstaller.install( request, localRepositry, mavenArtifacts );
76 }
77 catch ( ComponentLookupException e )
78 {
79 throw new ArtifactInstallerException( e.getMessage(), e );
80 }
81 }
82
83
84
85
86 protected static boolean isMaven31()
87 {
88 return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" );
89 }
90
91 private static boolean canFindCoreClass( String className )
92 {
93 try
94 {
95 Thread.currentThread().getContextClassLoader().loadClass( className );
96
97 return true;
98 }
99 catch ( ClassNotFoundException e )
100 {
101 return false;
102 }
103 }
104
105
106
107
108
109
110
111 public void contextualize( Context context )
112 throws ContextException
113 {
114 container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
115 }
116 }