Subversion Repositories XServices

Rev

Rev 109 | Rev 198 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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