Subversion Repositories XServices

Rev

Rev 94 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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