Subversion Repositories XServices

Rev

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

Rev 198 Rev 199
Line 10... Line 10...
10
import java.util.StringTokenizer;
10
import java.util.StringTokenizer;
Line 11... Line 11...
11
 
11
 
12
import javax.ws.rs.core.HttpHeaders;
12
import javax.ws.rs.core.HttpHeaders;
Line -... Line 13...
-
 
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;
Line 27... Line 28...
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.logging.log4j.LogManager;
-
 
33
import org.apache.logging.log4j.Logger;
32
import org.apache.commons.jcs.access.exception.CacheException;
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;
Line 43... Line 42...
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;
Line -... Line 46...
-
 
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();
Line 51... Line 51...
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);
Line 57... Line 57...
57
		ItemListType cacheresult = (ItemListType) getCacheInstance().get(
57
		ItemListType cacheresult = (ItemListType) getCacheInstance().get(
58
				cachekey);
58
				cachekey);
Line 119... Line 119...
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
			});
Line 140... Line 140...
140
 
140
 
Line 141... Line 141...
141
			rlog.setHeaderAndDescOnly(false);
141
			rlog.setHeaderAndDescOnly(false);
Line 142... Line 142...
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()
Line 146... Line 146...
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);
Line 170... Line 170...
170
		return Response.ok(this.list).build();
170
		return Response.ok(this.list).build();
171
	}
171
	}
Line 172... Line 172...
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();
Line 175... Line 175...
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);
Line 198... Line 198...
198
				}
198
				}
199
			});
199
			});
200
			CheckoutCommand co = new CheckoutCommand();
200
			CheckoutCommand co = new CheckoutCommand();
201
			co.setShowModulesWithStatus(true);
201
			co.setShowModulesWithStatus(true);
Line 202... Line 202...
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");
Line 211... Line 211...
211
			}
211
			}
Line 218... Line 218...
218
		return Response.serverError().build();
218
		return Response.serverError().build();
219
	}
219
	}
Line 220... Line 220...
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();
Line 232... Line 232...
232
	}
232
	}
233
 
233
 
Line 237... Line 237...
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;
Line 240... Line 240...
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);
Line 245... Line 245...
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.");
Line 249... Line 249...
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();
Line 304... Line 304...
304
			client.getEventManager().addCVSListener(listener);
304
			client.getEventManager().addCVSListener(listener);
Line 305... Line 305...
305
 
305
 
306
			checkout.setModule(filestring);
306
			checkout.setModule(filestring);
Line 307... Line 307...
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());
Line 328... Line 328...
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;
Line 345... Line 345...
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;
Line 348... Line 348...
348
 
348
 
349
			String cachestring = "FINDINGS-" + cvsroot;
-
 
350
			CVSInfoImpl.logger
349
			String cachestring = "FINDINGS-" + cvsroot;
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.");
Line 361... Line 360...
361
			}
360
			}
362
 
361
 
363
			if (result != null)
-
 
364
				return Response.ok(result).build();
-
 
365
		} catch (CommandAbortedException e) {
-
 
366
			e.printStackTrace();
-
 
367
		} catch (ConfigurationException e) {
362
			if (result != null)
368
			e.printStackTrace();
363
				return Response.ok(result).build();
369
		} catch (AuthenticationException e) {
364
		} catch (CommandAbortedException | AuthenticationException | ConfigurationException e) {
370
			e.printStackTrace();
365
			e.printStackTrace();
371
		}
366
		}
Line 372... Line 367...
372
		return Response.noContent().build();
367
        return Response.noContent().build();
373
	}
368
	}
374
 
369