1 package org.apache.maven.artifact.manager;
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.InputStream;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.apache.maven.wagon.ConnectionException;
28 import org.apache.maven.wagon.InputData;
29 import org.apache.maven.wagon.OutputData;
30 import org.apache.maven.wagon.ResourceDoesNotExistException;
31 import org.apache.maven.wagon.StreamWagon;
32 import org.apache.maven.wagon.TransferFailedException;
33 import org.apache.maven.wagon.authentication.AuthenticationException;
34 import org.apache.maven.wagon.authorization.AuthorizationException;
35 import org.apache.maven.wagon.resource.Resource;
36 import org.codehaus.plexus.util.IOUtil;
37 import org.codehaus.plexus.util.StringInputStream;
38 import org.codehaus.plexus.util.StringOutputStream;
39
40 public class StringWagon
41 extends StreamWagon
42 {
43 private Map expectedContent = new HashMap();
44
45 public void addExpectedContent( String resourceName, String expectedContent )
46 {
47 this.expectedContent.put( resourceName, expectedContent );
48 }
49
50 public String[] getSupportedProtocols()
51 {
52 return new String[] { "string" };
53 }
54
55 public void closeConnection()
56 throws ConnectionException
57 {
58 }
59
60 public void fillInputData( InputData inputData )
61 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
62 {
63 Resource resource = inputData.getResource();
64
65 String content = (String) expectedContent.get( resource.getName() );
66
67 if ( content != null )
68 {
69 resource.setContentLength( content.length() );
70 resource.setLastModified( System.currentTimeMillis() );
71
72 inputData.setInputStream( new StringInputStream( content ) );
73 }
74 else
75 {
76 throw new ResourceDoesNotExistException( "No content provided for " + resource.getName() );
77 }
78 }
79
80 public void fillOutputData( OutputData outputData )
81 throws TransferFailedException
82 {
83 outputData.setOutputStream( new StringOutputStream() );
84 }
85
86 protected void openConnectionInternal()
87 throws ConnectionException, AuthenticationException
88 {
89 }
90
91 public void clearExpectedContent()
92 {
93 expectedContent.clear();
94 }
95 }