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