Subversion Repositories XServices

Rev

Rev 198 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 198 Rev 199
1
package net.brutex.xservices.ws.rs;
1
package net.brutex.xservices.ws.rs;
2
 
2
 
3
import java.io.ByteArrayOutputStream;
3
import java.io.ByteArrayOutputStream;
4
import java.io.File;
4
import java.io.File;
5
import java.io.FileReader;
5
import java.io.FileReader;
6
import java.io.IOException;
6
import java.io.IOException;
7
import java.io.PrintStream;
7
import java.io.PrintStream;
8
import java.net.URI;
8
import java.net.URI;
9
import java.util.List;
9
import java.util.List;
10
import java.util.StringTokenizer;
10
import java.util.StringTokenizer;
11
 
11
 
12
import javax.ws.rs.core.HttpHeaders;
12
import javax.ws.rs.core.HttpHeaders;
13
import javax.ws.rs.core.Response;
13
import javax.ws.rs.core.Response;
-
 
14
 
14
 
15
import lombok.extern.slf4j.Slf4j;
15
import net.brutex.xservices.types.scm.AttributeType;
16
import net.brutex.xservices.types.scm.AttributeType;
16
import net.brutex.xservices.types.scm.ItemListType;
17
import net.brutex.xservices.types.scm.ItemListType;
17
import net.brutex.xservices.types.scm.ItemType;
18
import net.brutex.xservices.types.scm.ItemType;
18
import net.brutex.xservices.types.scm.ModuleListType;
19
import net.brutex.xservices.types.scm.ModuleListType;
19
import net.brutex.xservices.types.scm.ModuleType;
20
import net.brutex.xservices.types.scm.ModuleType;
20
import net.brutex.xservices.types.scm.ObjectFactory;
21
import net.brutex.xservices.types.scm.ObjectFactory;
21
import net.brutex.xservices.types.scm.RevisionType;
22
import net.brutex.xservices.types.scm.RevisionType;
22
import net.brutex.xservices.types.scm.TagListType;
23
import net.brutex.xservices.types.scm.TagListType;
23
import net.brutex.xservices.types.scmfindings.FindingsListType;
24
import net.brutex.xservices.types.scmfindings.FindingsListType;
24
import net.brutex.xservices.util.BasicCVSListener;
25
import net.brutex.xservices.util.BasicCVSListener;
25
import net.brutex.xservices.util.CVSClient;
26
import net.brutex.xservices.util.CVSClient;
26
import net.brutex.xservices.util.CVSRoot;
27
import net.brutex.xservices.util.CVSRoot;
27
 
28
 
28
import org.apache.commons.configuration2.ex.ConfigurationException;
29
import org.apache.commons.configuration2.ex.ConfigurationException;
29
import org.apache.commons.jcs.JCS;
30
import org.apache.commons.jcs.JCS;
30
import org.apache.commons.jcs.access.CacheAccess;
31
import org.apache.commons.jcs.access.CacheAccess;
31
import org.apache.commons.jcs.access.exception.CacheException;
32
import org.apache.commons.jcs.access.exception.CacheException;
32
import org.apache.logging.log4j.LogManager;
-
 
33
import org.apache.logging.log4j.Logger;
-
 
34
import org.netbeans.lib.cvsclient.Client;
33
import org.netbeans.lib.cvsclient.Client;
35
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
34
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
36
import org.netbeans.lib.cvsclient.command.CommandException;
35
import org.netbeans.lib.cvsclient.command.CommandException;
37
import org.netbeans.lib.cvsclient.command.FileInfoContainer;
36
import org.netbeans.lib.cvsclient.command.FileInfoContainer;
38
import org.netbeans.lib.cvsclient.command.PipedFileInformation;
37
import org.netbeans.lib.cvsclient.command.PipedFileInformation;
39
import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand;
38
import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand;
40
import org.netbeans.lib.cvsclient.command.checkout.ModuleListInformation;
39
import org.netbeans.lib.cvsclient.command.checkout.ModuleListInformation;
41
import org.netbeans.lib.cvsclient.command.log.LogInformation;
40
import org.netbeans.lib.cvsclient.command.log.LogInformation;
42
import org.netbeans.lib.cvsclient.command.log.LogInformation.Revision;
41
import org.netbeans.lib.cvsclient.command.log.LogInformation.Revision;
43
import org.netbeans.lib.cvsclient.command.log.RlogCommand;
42
import org.netbeans.lib.cvsclient.command.log.RlogCommand;
44
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
43
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
45
import org.netbeans.lib.cvsclient.event.EventManager;
44
import org.netbeans.lib.cvsclient.event.EventManager;
46
import org.netbeans.lib.cvsclient.event.FileInfoEvent;
45
import org.netbeans.lib.cvsclient.event.FileInfoEvent;
-
 
46
 
47
 
47
@Slf4j
48
public class CVSInfoImpl implements CVSInfo {
-
 
-
 
48
public class CVSInfoImpl implements CVSInfo {
49
	private static final Logger logger = LogManager.getLogger();
49
 
50
	final ObjectFactory FACTORY = new ObjectFactory();
50
	final ObjectFactory FACTORY = new ObjectFactory();
51
	final ItemListType list = this.FACTORY.createItemListType();
51
	final ItemListType list = this.FACTORY.createItemListType();
52
 
52
 
53
	public Response getRepositoryFiles(HttpHeaders h, File f, String modules,
53
	public Response getRepositoryFiles(HttpHeaders h, File f, String modules,
54
			boolean isRecursive, boolean showRevisions, boolean forceNoCache) {
54
			boolean isRecursive, boolean showRevisions, boolean forceNoCache) {
55
		String cachekey = "getFiles" + f.toURI().toString();
55
		String cachekey = "getFiles" + f.toURI().toString();
56
		CVSInfoImpl.logger.debug("forceNoCache=" + forceNoCache);
56
		log.debug("forceNoCache=" + forceNoCache);
57
		ItemListType cacheresult = (ItemListType) getCacheInstance().get(
57
		ItemListType cacheresult = (ItemListType) getCacheInstance().get(
58
				cachekey);
58
				cachekey);
59
 
59
 
60
		if ((!forceNoCache) && (cacheresult != null)) {
60
		if ((!forceNoCache) && (cacheresult != null)) {
61
			return Response.ok(cacheresult).build();
61
			return Response.ok(cacheresult).build();
62
		}
62
		}
63
		Client client;
63
		Client client;
64
		try {
64
		try {
65
			final CVSClient cvsclient = new CVSClient(f);
65
			final CVSClient cvsclient = new CVSClient(f);
66
			client = cvsclient.client;
66
			client = cvsclient.client;
67
 
67
 
68
			client.getEventManager().addCVSListener(new BasicCVSListener() {
68
			client.getEventManager().addCVSListener(new BasicCVSListener() {
69
				public void fileInfoGenerated(FileInfoEvent arg0) {
69
				public void fileInfoGenerated(FileInfoEvent arg0) {
70
					LogInformation info = (LogInformation) arg0
70
					LogInformation info = (LogInformation) arg0
71
							.getInfoContainer();
71
							.getInfoContainer();
72
					String repoPath = cvsclient.client.getRepository();
72
					String repoPath = cvsclient.client.getRepository();
73
 
73
 
74
					ItemType cvsfile = CVSInfoImpl.this.FACTORY
74
					ItemType cvsfile = CVSInfoImpl.this.FACTORY
75
							.createItemType();
75
							.createItemType();
76
					cvsfile.setIsLeaf(true);
76
					cvsfile.setIsLeaf(true);
77
					cvsfile.setIsBinary(false);
77
					cvsfile.setIsBinary(false);
78
 
78
 
79
					cvsfile.setFullname(info.getRepositoryFilename().substring(
79
					cvsfile.setFullname(info.getRepositoryFilename().substring(
80
							repoPath.length() + 2,
80
							repoPath.length() + 2,
81
							info.getRepositoryFilename().length() - 2));
81
							info.getRepositoryFilename().length() - 2));
82
 
82
 
83
					cvsfile.setRemotename(info.getRepositoryFilename());
83
					cvsfile.setRemotename(info.getRepositoryFilename());
84
					cvsfile.setRemotefullname(info.getRepositoryFilename());
84
					cvsfile.setRemotefullname(info.getRepositoryFilename());
85
					RevisionType revision = CVSInfoImpl.this.FACTORY
85
					RevisionType revision = CVSInfoImpl.this.FACTORY
86
							.createRevisionType();
86
							.createRevisionType();
87
					revision.setRevision(info.getHeadRevision());
87
					revision.setRevision(info.getHeadRevision());
88
					revision.setComment(info.getDescription());
88
					revision.setComment(info.getDescription());
89
					cvsfile.setTipRevision(revision);
89
					cvsfile.setTipRevision(revision);
90
 
90
 
91
					for (LogInformation.Revision r : info.getRevisionList()) {
91
					for (LogInformation.Revision r : info.getRevisionList()) {
92
						revision = CVSInfoImpl.this.FACTORY
92
						revision = CVSInfoImpl.this.FACTORY
93
								.createRevisionType();
93
								.createRevisionType();
94
						revision.setRevision(r.getNumber());
94
						revision.setRevision(r.getNumber());
95
						revision.setComment(r.getMessage());
95
						revision.setComment(r.getMessage());
96
						cvsfile.getRevisions().add(revision);
96
						cvsfile.getRevisions().add(revision);
97
					}
97
					}
98
 
98
 
99
					cvsfile.getAttributes().add(
99
					cvsfile.getAttributes().add(
100
							CVSInfoImpl.this.getAttribute("TOTALREVISIONS",
100
							CVSInfoImpl.this.getAttribute("TOTALREVISIONS",
101
									info.getTotalRevisions()));
101
									info.getTotalRevisions()));
102
					cvsfile.getAttributes().add(
102
					cvsfile.getAttributes().add(
103
							CVSInfoImpl.this.getAttribute("BRANCH",
103
							CVSInfoImpl.this.getAttribute("BRANCH",
104
									info.getBranch()));
104
									info.getBranch()));
105
					cvsfile.getAttributes().add(
105
					cvsfile.getAttributes().add(
106
							CVSInfoImpl.this.getAttribute(
106
							CVSInfoImpl.this.getAttribute(
107
									"KEYWORDSUBSTITUTION",
107
									"KEYWORDSUBSTITUTION",
108
									info.getKeywordSubstitution()));
108
									info.getKeywordSubstitution()));
109
					cvsfile.getAttributes().add(
109
					cvsfile.getAttributes().add(
110
							CVSInfoImpl.this.getAttribute("LOCKS",
110
							CVSInfoImpl.this.getAttribute("LOCKS",
111
									info.getLocks()));
111
									info.getLocks()));
112
					cvsfile.getAttributes().add(
112
					cvsfile.getAttributes().add(
113
							CVSInfoImpl.this.getAttribute("SELECTEDREVISIONS",
113
							CVSInfoImpl.this.getAttribute("SELECTEDREVISIONS",
114
									info.getSelectedRevisions()));
114
									info.getSelectedRevisions()));
115
					cvsfile.setROOT(cvsclient.getRoot().host + "@"
115
					cvsfile.setROOT(cvsclient.getRoot().host + "@"
116
							+ cvsclient.getRoot().repository);
116
							+ cvsclient.getRoot().repository);
117
 
117
 
118
					CVSInfoImpl.this.list.getItems().add(cvsfile);
118
					CVSInfoImpl.this.list.getItems().add(cvsfile);
119
 
119
 
120
					String key = CVSClient.generateID(cvsfile);
120
					String key = CVSClient.generateID(cvsfile);
121
					try {
121
					try {
122
						CVSInfoImpl.this.getCacheInstance().put(key, cvsfile);
122
						CVSInfoImpl.this.getCacheInstance().put(key, cvsfile);
123
					} catch (CacheException e) {
123
					} catch (CacheException e) {
124
						CVSInfoImpl.logger.error("Could not cache item '"
124
						log.error("Could not cache item '"
125
								+ key + "'", e);
125
								+ key + "'", e);
126
					}
126
					}
127
				}
127
				}
128
			});
128
			});
129
			RlogCommand rlog = new RlogCommand();
129
			RlogCommand rlog = new RlogCommand();
130
			StringTokenizer tk = new StringTokenizer(modules, ",");
130
			StringTokenizer tk = new StringTokenizer(modules, ",");
131
			while (tk.hasMoreTokens()) {
131
			while (tk.hasMoreTokens()) {
132
				rlog.setModule(tk.nextToken());
132
				rlog.setModule(tk.nextToken());
133
			}
133
			}
134
			if (rlog.getModules().length == 0) {
134
			if (rlog.getModules().length == 0) {
135
				rlog.setModule("");
135
				rlog.setModule("");
136
			}
136
			}
137
			rlog.setDefaultBranch(false);
137
			rlog.setDefaultBranch(false);
138
 
138
 
139
			rlog.setNoTags(false);
139
			rlog.setNoTags(false);
140
 
140
 
141
			rlog.setHeaderAndDescOnly(false);
141
			rlog.setHeaderAndDescOnly(false);
142
 
142
 
143
			rlog.setRecursive(isRecursive);
143
			rlog.setRecursive(isRecursive);
144
 
144
 
145
			CVSInfoImpl.logger.info("Executing CVS command '" + rlog.getCVSCommand()
145
			log.info("Executing CVS command '" + rlog.getCVSCommand()
146
					+ "' against '" + cvsclient.getRoot().host + "@"
146
					+ "' against '" + cvsclient.getRoot().host + "@"
147
					+ cvsclient.getRoot().repository + "'");
147
					+ cvsclient.getRoot().repository + "'");
148
			client.executeCommand(rlog, cvsclient.getGlobalOptions());
148
			client.executeCommand(rlog, cvsclient.getGlobalOptions());
149
 
149
 
150
			getCacheInstance().put(cachekey, this.list);
150
			getCacheInstance().put(cachekey, this.list);
151
		} catch (ConfigurationException e) {
151
		} catch (ConfigurationException e) {
152
			CVSInfoImpl.logger.error("CVS Configuration File '" + f.getAbsolutePath()
152
			log.error("CVS Configuration File '" + f.getAbsolutePath()
153
					+ f.getName() + "'not found.", e);
153
					+ f.getName() + "'not found.", e);
154
		} catch (CommandAbortedException e) {
154
		} catch (CommandAbortedException e) {
155
			e.printStackTrace();
155
			e.printStackTrace();
156
		} catch (AuthenticationException e) {
156
		} catch (AuthenticationException e) {
157
			e.printStackTrace();
157
			e.printStackTrace();
158
		} catch (CommandException e) {
158
		} catch (CommandException e) {
159
			e.printStackTrace();
159
			e.printStackTrace();
160
		} catch (CacheException e) {
160
		} catch (CacheException e) {
161
			e.printStackTrace();
161
			e.printStackTrace();
162
		}
162
		}
163
 
163
 
164
		if (!showRevisions) {
164
		if (!showRevisions) {
165
			for (ItemType t : this.list.getItems()) {
165
			for (ItemType t : this.list.getItems()) {
166
				t.getRevisions().clear();
166
				t.getRevisions().clear();
167
			}
167
			}
168
		}
168
		}
169
 
169
 
170
		return Response.ok(this.list).build();
170
		return Response.ok(this.list).build();
171
	}
171
	}
172
 
172
 
173
	public Response getModules(HttpHeaders h, File f, boolean forceNoCache) {
173
	public Response getModules(HttpHeaders h, File f, boolean forceNoCache) {
174
		String cachekey = "Modules" + f.toURI().toString();
174
		String cachekey = "Modules" + f.toURI().toString();
175
		CVSInfoImpl.logger.debug("forceNoCache=" + forceNoCache);
175
		log.debug("forceNoCache=" + forceNoCache);
176
 
176
 
177
		ModuleListType response = (ModuleListType) getCacheInstance().get(
177
		ModuleListType response = (ModuleListType) getCacheInstance().get(
178
				cachekey);
178
				cachekey);
179
		if ((!forceNoCache) && (response != null)) {
179
		if ((!forceNoCache) && (response != null)) {
180
			return Response.ok(response).build();
180
			return Response.ok(response).build();
181
		}
181
		}
182
		try {
182
		try {
183
			CVSClient cvsclient = new CVSClient(f);
183
			CVSClient cvsclient = new CVSClient(f);
184
			Client client = cvsclient.client;
184
			Client client = cvsclient.client;
185
			final ModuleListType list = this.FACTORY.createModuleListType();
185
			final ModuleListType list = this.FACTORY.createModuleListType();
186
 
186
 
187
			client.getEventManager().addCVSListener(new BasicCVSListener() {
187
			client.getEventManager().addCVSListener(new BasicCVSListener() {
188
				public void fileInfoGenerated(FileInfoEvent e) {
188
				public void fileInfoGenerated(FileInfoEvent e) {
189
					ModuleListInformation info = (ModuleListInformation) e
189
					ModuleListInformation info = (ModuleListInformation) e
190
							.getInfoContainer();
190
							.getInfoContainer();
191
					ModuleType module = CVSInfoImpl.this.FACTORY
191
					ModuleType module = CVSInfoImpl.this.FACTORY
192
							.createModuleType();
192
							.createModuleType();
193
					module.setName(info.getModuleName());
193
					module.setName(info.getModuleName());
194
					module.setStatus(info.getModuleStatus());
194
					module.setStatus(info.getModuleStatus());
195
					module.setPath(info.getPaths());
195
					module.setPath(info.getPaths());
196
					module.setType(info.getType());
196
					module.setType(info.getType());
197
					list.getModules().add(module);
197
					list.getModules().add(module);
198
				}
198
				}
199
			});
199
			});
200
			CheckoutCommand co = new CheckoutCommand();
200
			CheckoutCommand co = new CheckoutCommand();
201
			co.setShowModulesWithStatus(true);
201
			co.setShowModulesWithStatus(true);
202
 
202
 
203
			CVSInfoImpl.logger.info("Executing CVS command '" + co.getCVSCommand()
203
			log.info("Executing CVS command '" + co.getCVSCommand()
204
					+ "' against '" + cvsclient.getRoot().host + "@"
204
					+ "' against '" + cvsclient.getRoot().host + "@"
205
					+ cvsclient.getRoot().repository + "'");
205
					+ cvsclient.getRoot().repository + "'");
206
			client.executeCommand(co, cvsclient.getGlobalOptions());
206
			client.executeCommand(co, cvsclient.getGlobalOptions());
207
			if (list.getModules().size() == 0) {
207
			if (list.getModules().size() == 0) {
208
				CVSInfoImpl.logger.warn("Repository '"
208
				log.warn("Repository '"
209
						+ cvsclient.getRoot().repository
209
						+ cvsclient.getRoot().repository
210
						+ "' does not have modules");
210
						+ "' does not have modules");
211
			}
211
			}
212
 
212
 
213
			getCacheInstance().put(cachekey, list);
213
			getCacheInstance().put(cachekey, list);
214
			return Response.ok(list).build();
214
			return Response.ok(list).build();
215
		} catch (Exception e) {
215
		} catch (Exception e) {
216
			e.printStackTrace();
216
			e.printStackTrace();
217
		}
217
		}
218
		return Response.serverError().build();
218
		return Response.serverError().build();
219
	}
219
	}
220
 
220
 
221
	public Response getTags(HttpHeaders h, File f, boolean withFiles) {
221
	public Response getTags(HttpHeaders h, File f, boolean withFiles) {
222
		String cachekey = f.toURI().toString() + ":taglist";
222
		String cachekey = f.toURI().toString() + ":taglist";
223
		CVSInfoImpl.logger.debug("Retrieving Tags from cache using key '" + cachekey
223
		log.debug("Retrieving Tags from cache using key '" + cachekey
224
				+ "'");
224
				+ "'");
225
		TagListType tags = (TagListType) getCacheInstance().get(cachekey);
225
		TagListType tags = (TagListType) getCacheInstance().get(cachekey);
226
		if (tags != null) {
226
		if (tags != null) {
227
			CVSInfoImpl.logger.debug("Delivering Tags from cache.");
227
			log.debug("Delivering Tags from cache.");
228
			return Response.ok(tags).build();
228
			return Response.ok(tags).build();
229
		}
229
		}
230
		CVSInfoImpl.logger.warn("Taglist not found in cache.");
230
		log.warn("Taglist not found in cache.");
231
		return Response.noContent().build();
231
		return Response.noContent().build();
232
	}
232
	}
233
 
233
 
234
	public Response getFileContent(HttpHeaders h, File f, String filestring,
234
	public Response getFileContent(HttpHeaders h, File f, String filestring,
235
			boolean forceNoCache) {
235
			boolean forceNoCache) {
236
		final ItemType result = this.FACTORY.createItemType();
236
		final ItemType result = this.FACTORY.createItemType();
237
		final String cachekey = f.toURI().toString() + ":" + filestring
237
		final String cachekey = f.toURI().toString() + ":" + filestring
238
				+ ":content";
238
				+ ":content";
239
		ItemListType list = null;
239
		ItemListType list = null;
240
 
240
 
241
		if (!forceNoCache) {
241
		if (!forceNoCache) {
242
			CVSInfoImpl.logger.debug("Retrieving file content from cache using key '"
242
			log.debug("Retrieving file content from cache using key '"
243
					+ cachekey + "'");
243
					+ cachekey + "'");
244
			list = (ItemListType) getCacheInstance().get(cachekey);
244
			list = (ItemListType) getCacheInstance().get(cachekey);
245
		}
245
		}
246
 
246
 
247
		if (list != null) {
247
		if (list != null) {
248
			CVSInfoImpl.logger.debug("Delivering file content from cache.");
248
			log.debug("Delivering file content from cache.");
249
			return Response.ok(list).build();
249
			return Response.ok(list).build();
250
		}
250
		}
251
 
251
 
252
		CVSInfoImpl.logger.warn("File content not found in cache.");
252
		log.warn("File content not found in cache.");
253
		list = this.FACTORY.createItemListType();
253
		list = this.FACTORY.createItemListType();
254
		try {
254
		try {
255
			CVSClient cvsclient = new CVSClient(f);
255
			CVSClient cvsclient = new CVSClient(f);
256
			Client client = cvsclient.getClient();
256
			Client client = cvsclient.getClient();
257
 
257
 
258
			CheckoutCommand checkout = new CheckoutCommand();
258
			CheckoutCommand checkout = new CheckoutCommand();
259
			BasicCVSListener listener = new BasicCVSListener() {
259
			BasicCVSListener listener = new BasicCVSListener() {
260
				public void fileInfoGenerated(FileInfoEvent arg0) {
260
				public void fileInfoGenerated(FileInfoEvent arg0) {
261
					System.out.println(arg0.getInfoContainer().getFile()
261
					System.out.println(arg0.getInfoContainer().getFile()
262
							.toURI().toString());
262
							.toURI().toString());
263
					PipedFileInformation info = (PipedFileInformation) arg0
263
					PipedFileInformation info = (PipedFileInformation) arg0
264
							.getInfoContainer();
264
							.getInfoContainer();
265
					result.setName(info.getFile().getName());
265
					result.setName(info.getFile().getName());
266
					try {
266
					try {
267
						boolean isBinary = false;
267
						boolean isBinary = false;
268
						result.setIsBinary(isBinary);
268
						result.setIsBinary(isBinary);
269
						result.setRemotename(info.getRepositoryFileName());
269
						result.setRemotename(info.getRepositoryFileName());
270
						RevisionType revision = CVSInfoImpl.this.FACTORY
270
						RevisionType revision = CVSInfoImpl.this.FACTORY
271
								.createRevisionType();
271
								.createRevisionType();
272
						revision.setRevision(info.getRepositoryRevision());
272
						revision.setRevision(info.getRepositoryRevision());
273
						revision.setComment("");
273
						revision.setComment("");
274
 
274
 
275
						if (!isBinary) {
275
						if (!isBinary) {
276
							FileReader fin = new FileReader(info.getTempFile());
276
							FileReader fin = new FileReader(info.getTempFile());
277
 
277
 
278
							ByteArrayOutputStream bout = new ByteArrayOutputStream();
278
							ByteArrayOutputStream bout = new ByteArrayOutputStream();
279
							StringBuffer sbuf = new StringBuffer();
279
							StringBuffer sbuf = new StringBuffer();
280
							int c;
280
							int c;
281
							while ((c = fin.read()) != -1) {
281
							while ((c = fin.read()) != -1) {
282
								bout.write(c);
282
								bout.write(c);
283
								sbuf.append((char) c);
283
								sbuf.append((char) c);
284
							}
284
							}
285
							result.setData(bout.toByteArray());
285
							result.setData(bout.toByteArray());
286
							result.setContent(sbuf.toString());
286
							result.setContent(sbuf.toString());
287
						}
287
						}
288
 
288
 
289
					} catch (IOException e2) {
289
					} catch (IOException e2) {
290
						e2.printStackTrace();
290
						e2.printStackTrace();
291
					} catch (NullPointerException ne) {
291
					} catch (NullPointerException ne) {
292
						ne.printStackTrace();
292
						ne.printStackTrace();
293
					}
293
					}
294
 
294
 
295
					String key = CVSClient.generateID(result);
295
					String key = CVSClient.generateID(result);
296
					try {
296
					try {
297
						CVSInfoImpl.this.getCacheInstance().put(cachekey,
297
						CVSInfoImpl.this.getCacheInstance().put(cachekey,
298
								result);
298
								result);
299
					} catch (CacheException e1) {
299
					} catch (CacheException e1) {
300
						e1.printStackTrace();
300
						e1.printStackTrace();
301
					}
301
					}
302
				}
302
				}
303
			};
303
			};
304
			client.getEventManager().addCVSListener(listener);
304
			client.getEventManager().addCVSListener(listener);
305
 
305
 
306
			checkout.setModule(filestring);
306
			checkout.setModule(filestring);
307
			checkout.setPipeToOutput(true);
307
			checkout.setPipeToOutput(true);
308
 
308
 
309
			CVSInfoImpl.logger.info("Execute CVS command '" + checkout.getCVSCommand()
309
			log.info("Execute CVS command '" + checkout.getCVSCommand()
310
					+ "' against '" + cvsclient.getRoot().host + "@"
310
					+ "' against '" + cvsclient.getRoot().host + "@"
311
					+ cvsclient.getRoot().repository + "'");
311
					+ cvsclient.getRoot().repository + "'");
312
			client.executeCommand(checkout, cvsclient.getGlobalOptions());
312
			client.executeCommand(checkout, cvsclient.getGlobalOptions());
313
		} catch (CommandAbortedException e) {
313
		} catch (CommandAbortedException e) {
314
			e.printStackTrace();
314
			e.printStackTrace();
315
		} catch (ConfigurationException e) {
315
		} catch (ConfigurationException e) {
316
			e.printStackTrace();
316
			e.printStackTrace();
317
		} catch (AuthenticationException e) {
317
		} catch (AuthenticationException e) {
318
			e.printStackTrace();
318
			e.printStackTrace();
319
		} catch (CommandException e) {
319
		} catch (CommandException e) {
320
			e.printStackTrace();
320
			e.printStackTrace();
321
		}
321
		}
322
 
322
 
323
		if (result.getContent() != null) {
323
		if (result.getContent() != null) {
324
			return Response.ok(result).build();
324
			return Response.ok(result).build();
325
		}
325
		}
326
		return Response.noContent().build();
326
		return Response.noContent().build();
327
	}
327
	}
328
 
328
 
329
	public CacheAccess<Object, Object> getCacheInstance() {
329
	public CacheAccess<Object, Object> getCacheInstance() {
330
		CacheAccess<Object, Object> jcs = null;
330
		CacheAccess<Object, Object> jcs = null;
331
		String cacheinstance = "CVSCache";
331
		String cacheinstance = "CVSCache";
332
		try {
332
		try {
333
			CVSInfoImpl.logger.trace("Getting cache instance named 'CVSCache'");
333
			log.trace("Getting cache instance named 'CVSCache'");
334
			jcs = JCS.getInstance("CVSCache");
334
			jcs = JCS.getInstance("CVSCache");
335
		} catch (CacheException e) {
335
		} catch (CacheException e) {
336
			CVSInfoImpl.logger.error("Failed to get cache instance", e);
336
			log.error("Failed to get cache instance", e);
337
			e.printStackTrace();
337
			e.printStackTrace();
338
		}
338
		}
339
		return jcs;
339
		return jcs;
340
	}
340
	}
341
 
341
 
342
	public Response searchFileContent(HttpHeaders h, File f,
342
	public Response searchFileContent(HttpHeaders h, File f,
343
			String file_regexp, String content_regexp, boolean forceNoCache) {
343
			String file_regexp, String content_regexp, boolean forceNoCache) {
344
		try {
344
		try {
345
			CVSClient client = new CVSClient(f);
345
			CVSClient client = new CVSClient(f);
346
			String cvsroot = client.getRoot().host + "@"
346
			String cvsroot = client.getRoot().host + "@"
347
					+ client.getRoot().repository;
347
					+ client.getRoot().repository;
348
 
348
 
349
			String cachestring = "FINDINGS-" + cvsroot;
349
			String cachestring = "FINDINGS-" + cvsroot;
350
			CVSInfoImpl.logger
-
 
351
					.debug("Fetch searchFileContent response from cache using cachekey '"
350
			log.debug("Fetch searchFileContent response from cache using cachekey '"
352
							+ cachestring + "'");
351
							+ cachestring + "'");
353
			FindingsListType result = (FindingsListType) getCacheInstance()
352
			FindingsListType result = (FindingsListType) getCacheInstance()
354
					.get(cachestring);
353
					.get(cachestring);
355
			if (result != null)
354
			if (result != null)
356
				CVSInfoImpl.logger.debug("Found object for key '" + cachestring
355
				log.debug("Found object for key '" + cachestring
357
						+ "' in cache.");
356
						+ "' in cache.");
358
			else {
357
			else {
359
				CVSInfoImpl.logger.debug("Found no object for key '" + cachestring
358
				log.debug("Found no object for key '" + cachestring
360
						+ "' in cache.");
359
						+ "' in cache.");
361
			}
360
			}
362
 
361
 
363
			if (result != null)
362
			if (result != null)
364
				return Response.ok(result).build();
363
				return Response.ok(result).build();
365
		} catch (CommandAbortedException e) {
-
 
366
			e.printStackTrace();
-
 
367
		} catch (ConfigurationException e) {
-
 
368
			e.printStackTrace();
-
 
369
		} catch (AuthenticationException e) {
364
		} catch (CommandAbortedException | AuthenticationException | ConfigurationException e) {
370
			e.printStackTrace();
365
			e.printStackTrace();
371
		}
366
		}
372
		return Response.noContent().build();
367
        return Response.noContent().build();
373
	}
368
	}
374
 
369
 
375
	private AttributeType getAttribute(String name, String value) {
370
	private AttributeType getAttribute(String name, String value) {
376
		AttributeType attribute = this.FACTORY.createAttributeType();
371
		AttributeType attribute = this.FACTORY.createAttributeType();
377
		attribute.setName(name);
372
		attribute.setName(name);
378
		attribute.setValue(value);
373
		attribute.setValue(value);
379
		return attribute;
374
		return attribute;
380
	}
375
	}
381
}
376
}
382
 
377
 
383
Generated by GNU Enscript 1.6.5.90.
378
Generated by GNU Enscript 1.6.5.90.
384
 
379
 
385
 
380