Subversion Repositories XServices

Compare Revisions

No changes between revisions

Ignore whitespace Rev 93 → Rev 94

/xservices/trunk/src/java/net/brutex/xservices/ws/rs/CVSInfo.java
0,0 → 1,69
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws.rs;
 
import java.io.File;
import java.util.List;
 
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
 
import net.brutex.xservices.types.FileInfoType;
 
 
 
@Path("/CVSService/")
@Produces ({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public interface CVSInfo {
 
/**
* @param module
* @param withDir
* @param withFiles
* @param depth
* @param search
* @param count
* @param page
* @return List of File
*/
@GET
@Path("getRepositoryFiles/")
public Response getRepositoryFiles(@Context HttpHeaders h,
@QueryParam("config") File f,
@QueryParam("modules") @DefaultValue("") String modules,
@QueryParam("showRevisions") @DefaultValue("false") boolean showRevisions,
@QueryParam("forceNoCache") @DefaultValue("false") boolean forceNoCache
);
 
@GET
@Path("getModules")
public Response getModules(@Context HttpHeaders h,
@QueryParam("config") File f,
@QueryParam("forceNoCache") @DefaultValue("false") boolean forceNoCache);
 
}
 
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/rs/CVSInfoImpl.java
0,0 → 1,225
package net.brutex.xservices.ws.rs;
 
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
 
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
 
import org.apache.commons.configuration.ConfigurationException;
import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;
import org.apache.log4j.Logger;
import org.netbeans.lib.cvsclient.Client;
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
import org.netbeans.lib.cvsclient.command.CommandException;
import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand;
import org.netbeans.lib.cvsclient.command.checkout.ModuleListInformation;
import org.netbeans.lib.cvsclient.command.log.LogInformation;
import org.netbeans.lib.cvsclient.command.log.RlogCommand;
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
import org.netbeans.lib.cvsclient.event.FileInfoEvent;
 
import net.brutex.xservices.types.scm.ModuleType;
import net.brutex.xservices.types.scm.FileType;
import net.brutex.xservices.types.scm.Revision;
import net.brutex.xservices.util.BasicCVSListener;
import net.brutex.xservices.util.CVSClient;
 
/**
* @author Brian Rosenberger
* @since 0.5.0-20120824
*
*/
public class CVSInfoImpl implements CVSInfo {
final Logger logger = Logger.getLogger(CVSInfoImpl.class);
 
public Response getRepositoryFiles(HttpHeaders h, File f, String modules,
boolean showRevisions,
boolean forceNoCache) {
 
final List<FileType> list = new ArrayList<FileType>();
 
String cachekey = "getFiles" + f.toURI().toString();
logger.debug("forceNoCache="+forceNoCache);
List<FileType> cacheresult = (List<FileType>) getCacheInstance().get(
cachekey);
 
if (!forceNoCache && cacheresult != null) {
// Cache hit
list.addAll(cacheresult);
} else {
// Cache miss
try {
CVSClient cvsclient = new CVSClient(f);
Client client = cvsclient.client;
 
client.getEventManager().addCVSListener(new BasicCVSListener() {
@Override
public void fileInfoGenerated(FileInfoEvent arg0) {
LogInformation info = (LogInformation) arg0
.getInfoContainer();
FileType cvsfile = new FileType(info.getFile(), info
.getRepositoryFilename(), info.getDescription());
cvsfile.setHeadRevision(info.getHeadRevision());
cvsfile.setBranch(info.getBranch());
cvsfile.setTotalRevisions(info.getTotalRevisions());
for (LogInformation.Revision r : info.getRevisionList()) {
cvsfile.addRevision(new Revision(r.getNumber(), r
.getMessage()));
}
list.add(cvsfile);
}
});
 
RlogCommand rlog = new RlogCommand();
StringTokenizer tk = new StringTokenizer(modules, ",");
while (tk.hasMoreTokens()) {
rlog.setModule(tk.nextToken());
}
if (rlog.getModules().length == 0)
rlog.setModule("");
 
rlog.setDefaultBranch(true); // -b Print information about the
// revisions on the default
// branch,
// normally the highest branch
// on
// the trunk.
rlog.setNoTags(true); // -N Do not print the list of tags for
// this
// file. This option can be very useful
// when
// your site uses a lot of tags, so
// rather
// than "more"'ing over 3 pages of tag
// information, the log information is
// presented without tags at all.
rlog.setHeaderAndDescOnly(false); // -t Print only the name of
// the
// rcs file, name of the
// file in
// the working directory,
// head,
// default branch, access
// list,
// locks, symbolic names,
// and
// suffix. + description
// rlog.setRevisionFilter("1.1.");
// rlog.setSuppressHeader(true); // -S Supress log output when
// no
// revisions are selected within a file.
client.executeCommand(rlog, cvsclient.getGlobalOptions());
logger.info("Execute CVS command '" + rlog.getCVSCommand() + "' against '"+cvsclient.getRoot().host+"@" + cvsclient.getRoot().repository+"'");
//need to put a new list into cache as we will filter the result
//afterwards
getCacheInstance().put(cachekey, new ArrayList<FileType>(list));
} catch (ConfigurationException e) {
logger.error("CVS Configuration File '"
+ f.getAbsolutePath() + f.getName() + "'not found.", e);
} catch (CommandAbortedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CommandException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CacheException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
}
// prepare output after everything is cached
if (!showRevisions) {
for (FileType t : list) {
t.clearRevisionList();
}
}
GenericEntity entity = new GenericEntity<List<FileType>>(list) {};
return Response.ok(entity).build();
}
 
@Override
public Response getModules(HttpHeaders h, File f, boolean forceNoCache) {
 
// Try to deliver from Cache
String cachekey = "Modules" + f.toURI().toString();
logger.debug("forceNoCache="+forceNoCache);
List<ModuleType> response = (List<ModuleType>) getCacheInstance().get(
cachekey);
if (!forceNoCache && response != null) {
GenericEntity entity = new GenericEntity<List<ModuleType>>(response) {
};
return Response.ok(entity).build();
}
// -------------------------
 
try {
CVSClient cvsclient = new CVSClient(f);
Client client = cvsclient.client;
 
final List<ModuleType> list = new ArrayList<ModuleType>();
 
client.getEventManager().addCVSListener(new BasicCVSListener() {
public void fileInfoGenerated(FileInfoEvent e) {
ModuleListInformation info = (ModuleListInformation) e
.getInfoContainer();
 
list.add(new ModuleType(info.getModuleName(), info
.getModuleStatus(), info.getPaths(), info.getType()));
}
});
 
CheckoutCommand co = new CheckoutCommand();
co.setShowModulesWithStatus(true);
 
client.executeCommand(co, cvsclient.getGlobalOptions());
logger.info("Execute CVS command '" + co.getCVSCommand() + "' against '"+cvsclient.getRoot().host+"@" + cvsclient.getRoot().repository+"'");
if(list.size()==0) {
logger.warn("Repository '" + cvsclient.getRoot().repository + "' does not have modules");
list.add(new ModuleType("","","",""));
}
GenericEntity entity = new GenericEntity<List<ModuleType>>(list) {
};
getCacheInstance().put(cachekey, list);
return Response.ok(entity).build();
} catch (Exception e) {
e.printStackTrace();
}
return Response.serverError().build();
}
 
/**
* Get the caching manager for CVS objects
*
* @return The CVSCaching JCS region
*/
public JCS getCacheInstance() {
JCS jcs = null;
final String cacheinstance = "CVSCache";
try {
logger.debug("Getting cache instance named '"+cacheinstance+"'" );
jcs = JCS.getInstance(cacheinstance);
} catch (CacheException e) {
logger.error("Failed to get cache instance", e);
e.printStackTrace();
}
return jcs;
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/rs/FileInfoImpl.java
2,6 → 2,7
 
import java.io.File;
import java.io.FileFilter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
 
12,6 → 13,8
import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;
 
import net.brutex.xservices.security.StandardSecurityManager;
import net.brutex.xservices.security.UserIdentity;
import net.brutex.xservices.types.FileInfoType;
 
/**
23,6 → 26,15
public Response getFiles(HttpHeaders h, String dir, boolean withDir,
boolean withFiles, int level, String search, int count, int page) {
StandardSecurityManager sec = new StandardSecurityManager();
UserIdentity id = new UserIdentity();
 
if( ! sec.canExecute(Thread.currentThread().getStackTrace()[1].getMethodName(), id)) {
return null;
}
 
System.out.println("Listing directory: " + dir);
if(level <= 0) level = 1;
if(level > 3) level = 3;