Subversion Repositories XServices

Rev

Rev 109 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 109 Rev 185
Line 6... Line 6...
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;
Line 21... Line 22...
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;
Line 40... Line 44...
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;
Line 43... Line 47...
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();
Line 47... Line 51...
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);
Line 53... Line 57...
53
		ItemListType cacheresult = (ItemListType) getCacheInstance().get(
57
		ItemListType cacheresult = (ItemListType) getCacheInstance().get(
54
				cachekey);
58
				cachekey);
Line 115... Line 119...
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
			});
Line 136... Line 140...
136
 
140
 
Line 137... Line 141...
137
			rlog.setHeaderAndDescOnly(false);
141
			rlog.setHeaderAndDescOnly(false);
Line 138... Line 142...
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()
Line 142... Line 146...
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);
Line 166... Line 170...
166
		return Response.ok(this.list).build();
170
		return Response.ok(this.list).build();
167
	}
171
	}
Line 168... Line 172...
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();
Line 171... Line 175...
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);
Line 194... Line 198...
194
				}
198
				}
195
			});
199
			});
196
			CheckoutCommand co = new CheckoutCommand();
200
			CheckoutCommand co = new CheckoutCommand();
197
			co.setShowModulesWithStatus(true);
201
			co.setShowModulesWithStatus(true);
Line 198... Line 202...
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");
Line 207... Line 211...
207
			}
211
			}
Line 214... Line 218...
214
		return Response.serverError().build();
218
		return Response.serverError().build();
215
	}
219
	}
Line 216... Line 220...
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();
Line 228... Line 232...
228
	}
232
	}
229
 
233
 
Line 233... Line 237...
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;
Line 236... Line 240...
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);
Line 241... Line 245...
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.");
Line 245... Line 249...
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();
Line 300... Line 304...
300
			client.getEventManager().addCVSListener(listener);
304
			client.getEventManager().addCVSListener(listener);
Line 301... Line 305...
301
 
305
 
302
			checkout.setModule(filestring);
306
			checkout.setModule(filestring);
Line 303... Line 307...
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());
Line 320... Line 324...
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
	}
Line 324... Line 328...
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;
Line 341... Line 345...
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;
Line 344... Line 348...
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.");
Line 357... Line 361...
357
			}
361
			}
358
 
362