1 package org.apache.maven.repository;
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.io.IOException;
24 import java.net.MalformedURLException;
25 import java.net.URL;
26 import java.util.Collection;
27
28 import org.codehaus.plexus.util.FileUtils;
29 import org.sonatype.aether.artifact.Artifact;
30 import org.sonatype.aether.repository.RemoteRepository;
31 import org.sonatype.aether.spi.connector.ArtifactDownload;
32 import org.sonatype.aether.spi.connector.ArtifactUpload;
33 import org.sonatype.aether.spi.connector.MetadataDownload;
34 import org.sonatype.aether.spi.connector.MetadataUpload;
35 import org.sonatype.aether.spi.connector.RepositoryConnector;
36 import org.sonatype.aether.transfer.ArtifactTransferException;
37
38
39
40
41 public class TestRepositoryConnector
42 implements RepositoryConnector
43 {
44
45 private RemoteRepository repository;
46
47 private File basedir;
48
49 public TestRepositoryConnector( RemoteRepository repository )
50 {
51 this.repository = repository;
52 try
53 {
54 basedir = FileUtils.toFile( new URL( repository.getUrl() ) );
55 }
56 catch ( MalformedURLException e )
57 {
58 throw new IllegalStateException( e );
59 }
60 }
61
62 public void close()
63 {
64 }
65
66 public void get( Collection<? extends ArtifactDownload> artifactDownloads,
67 Collection<? extends MetadataDownload> metadataDownloads )
68 {
69 if ( artifactDownloads != null )
70 {
71 for ( ArtifactDownload download : artifactDownloads )
72 {
73 File remoteFile = new File( basedir, path( download.getArtifact() ) );
74 try
75 {
76 FileUtils.copyFile( remoteFile, download.getFile() );
77 }
78 catch ( IOException e )
79 {
80 download.setException( new ArtifactTransferException( download.getArtifact(), repository, e ) );
81 }
82 }
83 }
84 }
85
86 private String path( Artifact artifact )
87 {
88 StringBuilder path = new StringBuilder( 128 );
89
90 path.append( artifact.getGroupId().replace( '.', '/' ) ).append( '/' );
91
92 path.append( artifact.getArtifactId() ).append( '/' );
93
94 path.append( artifact.getBaseVersion() ).append( '/' );
95
96 path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );
97
98 if ( artifact.getClassifier().length() > 0 )
99 {
100 path.append( '-' ).append( artifact.getClassifier() );
101 }
102
103 path.append( '.' ).append( artifact.getExtension() );
104
105 return path.toString();
106 }
107
108 public void put( Collection<? extends ArtifactUpload> artifactUploads,
109 Collection<? extends MetadataUpload> metadataUploads )
110 {
111
112
113 }
114
115 }