1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 package org.eclipse.jgit.transport;
48
49 import java.io.File;
50 import java.io.FileInputStream;
51 import java.io.FileNotFoundException;
52 import java.io.InputStream;
53 import java.util.Arrays;
54 import java.util.Collections;
55 import java.util.LinkedHashSet;
56 import java.util.Set;
57
58 import org.eclipse.jgit.errors.NotSupportedException;
59 import org.eclipse.jgit.errors.TransportException;
60 import org.eclipse.jgit.internal.JGitText;
61 import org.eclipse.jgit.lib.Repository;
62 import org.eclipse.jgit.util.FS;
63
64 class TransportBundleFile extends Transport implements TransportBundle {
65 static final TransportProtocol PROTO_BUNDLE = new TransportProtocol() {
66 private final String[] schemeNames = { "bundle", "file" };
67
68 private final Set<String> schemeSet = Collections
69 .unmodifiableSet(new LinkedHashSet<>(Arrays
70 .asList(schemeNames)));
71
72 @Override
73 public String getName() {
74 return JGitText.get().transportProtoBundleFile;
75 }
76
77 @Override
78 public Set<String> getSchemes() {
79 return schemeSet;
80 }
81
82 @Override
83 public boolean canHandle(URIish uri, Repository local, String remoteName) {
84 if (uri.getPath() == null
85 || uri.getPort() > 0
86 || uri.getUser() != null
87 || uri.getPass() != null
88 || uri.getHost() != null
89 || (uri.getScheme() != null && !getSchemes().contains(uri.getScheme())))
90 return false;
91 return true;
92 }
93
94 @Override
95 public Transport open(URIish uri, Repository local, String remoteName)
96 throws NotSupportedException, TransportException {
97 if ("bundle".equals(uri.getScheme())) {
98 File path = FS.DETECTED.resolve(new File("."), uri.getPath());
99 return new TransportBundleFile(local, uri, path);
100 }
101
102
103
104
105
106
107 return TransportLocal.PROTO_LOCAL.open(uri, local, remoteName);
108 }
109
110 @Override
111 public Transport open(URIish uri) throws NotSupportedException,
112 TransportException {
113 if ("bundle".equals(uri.getScheme())) {
114 File path = FS.DETECTED.resolve(new File("."), uri.getPath());
115 return new TransportBundleFile(uri, path);
116 }
117 return TransportLocal.PROTO_LOCAL.open(uri);
118 }
119 };
120
121 private final File bundle;
122
123 TransportBundleFile(Repository local, URIish uri, File bundlePath) {
124 super(local, uri);
125 bundle = bundlePath;
126 }
127
128
129
130
131
132
133
134
135
136 public TransportBundleFile(URIish uri, File bundlePath) {
137 super(uri);
138 bundle = bundlePath;
139 }
140
141
142 @Override
143 public FetchConnection openFetch() throws NotSupportedException,
144 TransportException {
145 final InputStream src;
146 try {
147 src = new FileInputStream(bundle);
148 } catch (FileNotFoundException err) {
149 throw new TransportException(uri, JGitText.get().notFound);
150 }
151 return new BundleFetchConnection(this, src);
152 }
153
154
155 @Override
156 public PushConnection openPush() throws NotSupportedException {
157 throw new NotSupportedException(
158 JGitText.get().pushIsNotSupportedForBundleTransport);
159 }
160
161
162 @Override
163 public void close() {
164
165 }
166
167 }