Subversion Repositories XServices

Compare Revisions

No changes between revisions

Ignore whitespace Rev 93 → Rev 94

/xservices/trunk/src/java/net/brutex/xservices/types/scm/FileType.java
0,0 → 1,160
/*
* 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.types.scm;
 
import java.io.File;
import java.util.ArrayList;
import java.util.List;
 
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
 
 
/**
* @author Brian Rosenberger, bru(at)brutex.de
* @since 0.5.0-20120817
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder={"localFilename", "repositoryFilename", "description", "headRevision", "branch", "totalRevisions", "revisions"})
@XmlRootElement
public class FileType {
String localFilename;
String repositoryFilename;
String description;
String headRevision;
String branch;
String totalRevisions;
final List<Revision> revisions = new ArrayList<Revision>();
/**
* @return the revisions
*/
public List<Revision> getRevisions() {
return revisions;
}
 
public void addRevision(Revision revision) {
this.revisions.add(revision);
}
 
/**
* @return the totalRevisions
*/
public String getTotalRevisions() {
return totalRevisions;
}
 
/**
* @param totalRevisions the totalRevisions to set
*/
public void setTotalRevisions(String totalRevisions) {
this.totalRevisions = totalRevisions;
}
 
public FileType() {
}
public FileType(File file, String repositoryname, String description) {
if(file!= null ) {
this.localFilename = file.toURI().toString();
} else {
localFilename = "";
}
this.repositoryFilename = repositoryname;
this.description = description;
}
 
/**
* @return the localFilename
*/
public String getLocalFilename() {
return localFilename;
}
 
/**
* @param localFilename the localFilename to set
*/
public void setLocalFilename(String localFilename) {
this.localFilename = localFilename;
}
 
/**
* @return the repositoryFilename
*/
public String getRepositoryFilename() {
return repositoryFilename;
}
 
/**
* @param repositoryFilename the repositoryFilename to set
*/
public void setRepositoryFilename(String repositoryFilename) {
this.repositoryFilename = repositoryFilename;
}
 
/**
* @return the description
*/
public String getDescription() {
return description;
}
 
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
 
/**
* @return the headRevision
*/
public String getHeadRevision() {
return headRevision;
}
 
/**
* @param headRevision the headRevision to set
*/
public void setHeadRevision(String headRevision) {
this.headRevision = headRevision;
}
 
/**
* @return the branch
*/
public String getBranch() {
return branch;
}
 
/**
* @param branch the branch to set
*/
public void setBranch(String branch) {
this.branch = branch;
}
public void clearRevisionList() {
this.revisions.clear();
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/types/scm/ModuleType.java
0,0 → 1,123
/*
* 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.types.scm;
 
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
 
 
@XmlType(propOrder={"name", "status", "description", "path", "type", "revision"})
@XmlRootElement
public class ModuleType {
String name;
String revision;
String status;
String description;
String path;
String type;
public ModuleType(String name, String status, String path, String type) {
this.name = name;
this.status = status;
this.description = "";
this.revision = "";
this.path = "/" + path;
this.type = type;
}
public ModuleType() {
//JAXB
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the revision
*/
public String getRevision() {
return revision;
}
/**
* @param revision the revision to set
*/
public void setRevision(String revision) {
this.revision = revision;
}
/**
* @return the status
*/
public String getStatus() {
return status;
}
/**
* @param status the status to set
*/
public void setStatus(String status) {
this.status = status;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
 
/**
* @return the path
*/
public String getPath() {
return path;
}
 
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
 
/**
* @return the type
*/
public String getType() {
return type;
}
 
/**
* @param type the type to set
*/
public void setType(String type) {
this.type = type;
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/types/scm/Tag.java
0,0 → 1,75
/*
* 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.types.scm;
 
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
 
/**
* @author Brian Rosenberger, bru(at)brutex.de
* @since 0.5.0-20120817
*
*/
@XmlType(name="TagType", propOrder={"name", "comment"})
@XmlRootElement
public class Tag {
 
private String name;
private String comment;
public Tag() {
}
/**
* @param name
* @param comment
*/
public Tag(String name, String comment) {
super();
this.name = name;
this.comment = comment;
}
 
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
 
/**
* @param comment the comment to set
*/
public void setComment(String comment) {
this.comment = comment;
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.types.scm.SCTag#getName()
*/
public String getName() {
return name;
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.types.scm.SCTag#getComment()
*/
 
public String getComment() {
return comment;
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/types/scm/Revision.java
0,0 → 1,78
/*
* 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.types.scm;
 
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
 
/**
* @author Brian Rosenberger, bru(at)brutex.de
* @since 0.5.0-20120817
*
*/
@XmlType(name="RevisionType", propOrder={"revision", "comment"})
@XmlRootElement
public class Revision {
private String revision;
private String comment;
public Revision() {
}
 
public Revision(String revision, String comment) {
super();
this.revision = revision;
this.comment = comment;
}
 
 
 
/* (non-Javadoc)
* @see net.brutex.xservices.types.scm.SCRevision#getRevision()
*/
@XmlElement(required=true, nillable=false)
public String getRevision() {
return revision;
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.types.scm.SCRevision#getComment()
*/
@XmlElement(required=false, nillable=true)
public String getComment() {
return comment;
}
 
/**
* @param revision the revision to set
*/
public void setRevision(String revision) {
this.revision = revision;
}
 
/**
* @param comment the comment to set
*/
public void setComment(String comment) {
this.comment = comment;
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/security/SecurityManager.java
0,0 → 1,25
/*
* 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.security;
 
import java.lang.reflect.Method;
 
public interface SecurityManager {
 
public boolean canExecute(String method, Identity identity);
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/security/StandardSecurityManager.java
0,0 → 1,13
package net.brutex.xservices.security;
 
import java.lang.reflect.Method;
 
public class StandardSecurityManager implements SecurityManager {
 
@Override
public boolean canExecute(String method, Identity identity) {
System.out.println("User '"+identity.getUUID()+"' accesses '"+method+"'");
return true;
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/security/UserIdentity.java
0,0 → 1,12
package net.brutex.xservices.security;
 
import java.util.UUID;
 
public class UserIdentity implements Identity {
 
@Override
public UUID getUUID() {
return UUID.randomUUID();
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/security/Identity.java
0,0 → 1,28
/*
* 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.security;
 
import java.util.UUID;
 
 
 
public interface Identity {
 
public UUID getUUID();
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java
13,6 → 13,8
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
 
package net.brutex.xservices.ws.impl;
 
import java.io.ByteArrayOutputStream;
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/StringServiceImpl.java
65,8 → 65,10
Pattern pattern = Pattern.compile(search, allflags);
Matcher matcher = pattern.matcher(res);
StringMatchType rm = new StringMatchType();
while (matcher.find()) {
rm.addStringMatch(matcher.start(), matcher.end(), matcher.group());
while (matcher.find()) {
for(int i=0; i<=matcher.groupCount();i++){
rm.addStringMatch(matcher.start(), matcher.end(), matcher.group(i));
}
}
return rm;
}
/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;
/xservices/trunk/src/java/net/brutex/xservices/util/CVSRoot.java
0,0 → 1,67
package net.brutex.xservices.util;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
 
/**
* A struct containing the various bits of information in a CVS root string,
* allowing easy retrieval of individual items of information
*/
public class CVSRoot {
public String connectionType;
public String user;
public String host;
public String repository;
 
public CVSRoot(String root) throws IllegalArgumentException {
if (!root.startsWith(":"))
throw new IllegalArgumentException();
 
int oldColonPosition = 0;
int colonPosition = root.indexOf(':', 1);
if (colonPosition == -1)
throw new IllegalArgumentException();
connectionType = root.substring(oldColonPosition + 1, colonPosition);
oldColonPosition = colonPosition;
colonPosition = root.indexOf('@', colonPosition + 1);
if (colonPosition == -1)
throw new IllegalArgumentException();
user = root.substring(oldColonPosition + 1, colonPosition);
oldColonPosition = colonPosition;
colonPosition = root.indexOf(':', colonPosition + 1);
if (colonPosition == -1)
throw new IllegalArgumentException();
host = root.substring(oldColonPosition + 1, colonPosition);
repository = root.substring(colonPosition + 1);
if (connectionType == null || user == null || host == null
|| repository == null)
throw new IllegalArgumentException();
}
 
public String getCVSRoot(File directory) {
String root = null;
BufferedReader r = null;
try {
File rootFile = new File(directory, "CVS/Root");
if (rootFile.exists()) {
r = new BufferedReader(new FileReader(rootFile));
root = r.readLine();
}
} catch (IOException e) {
// ignore
} finally {
try {
if (r != null)
r.close();
} catch (IOException e) {
System.err.println("Warning: could not close CVS/Root file!");
}
}
if (root == null) {
root = System.getProperty("cvs.root");
}
return root;
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/util/cache/CacheExecutorService.java
0,0 → 1,56
/*
* 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.util.cache;
 
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
 
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
 
/**
* @author Brian Rosenberger, bru(at)brutex.de
* @since 0.5.0-20120825
*/
public class CacheExecutorService implements ServletContextListener {
static final String EXECUTOR_NAME = "CACHE_EXECUTOR";
private ExecutorService executor;
 
public void contextInitialized(ServletContextEvent arg0) {
ServletContext context = arg0.getServletContext();
int nr_executors = 1;
ThreadFactory daemonFactory = new DaemonThreadFactory();
try {
nr_executors = Integer.parseInt(context.getInitParameter("cache:thread-count"));
} catch (NumberFormatException ignore ) {}
 
if(nr_executors <= 1) {
executor = Executors.newSingleThreadExecutor(daemonFactory);
} else {
executor = Executors.newFixedThreadPool(nr_executors,daemonFactory);
}
context.setAttribute(EXECUTOR_NAME, executor);
}
 
public void contextDestroyed(ServletContextEvent arg0) {
ServletContext context = arg0.getServletContext();
executor.shutdownNow(); // or process/wait until all pending jobs are done
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/util/cache/DaemonThreadFactory.java
0,0 → 1,52
/*
* 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.util.cache;
 
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
 
public class DaemonThreadFactory implements ThreadFactory {
 
private final ThreadFactory factory;
 
/**
* Construct a ThreadFactory with setDeamon(true) using
* Executors.defaultThreadFactory()
*/
public DaemonThreadFactory() {
this(Executors.defaultThreadFactory());
}
 
/**
* Construct a ThreadFactory with setDeamon(true) wrapping the given factory
*
* @param thread
* factory to wrap
*/
public DaemonThreadFactory(ThreadFactory factory) {
if (factory == null)
throw new NullPointerException("factory cannot be null");
this.factory = factory;
}
 
public Thread newThread(Runnable r) {
final Thread t = factory.newThread(r);
t.setDaemon(true);
return t;
}
}
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/util/cache/CacheServlet.java
0,0 → 1,122
/*
* 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.util.cache;
 
import java.io.File;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.ExecutorService;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.Response;
 
import org.apache.log4j.Logger;
 
import net.brutex.xservices.types.scm.ModuleType;
import net.brutex.xservices.ws.rs.CVSInfoImpl;
 
/**
* Perform Caching actions on the CVS Info actions
*
* @author Brian Rosenberger, bru(at)brutex.de
* @since 0.5.0-200120825
*
*/
public class CacheServlet extends HttpServlet {
 
private final Logger logger = Logger.getLogger(CacheServlet.class);
List<File> configfiles = new ArrayList<File>();;
int cacheinterval;
 
/*
* (non-Javadoc)
*
* @see javax.servlet.GenericServlet#init()
*/
@Override
public void init() throws ServletException {
super.init();
ExecutorService executor = (ExecutorService) getServletContext()
.getAttribute(CacheExecutorService.EXECUTOR_NAME);
 
Enumeration<String> attributes = getServletContext()
.getInitParameterNames();
while (attributes.hasMoreElements()) {
String name = attributes.nextElement();
if (name.startsWith("cvs-config-")) {
String configfile = (String) getServletContext()
.getInitParameter(name);
logger.info("CVS configuration file: " + configfile);
this.configfiles.add(new File(configfile));
}
}
cacheinterval = 15;
try {
cacheinterval = Integer.parseInt((String) getServletContext()
.getInitParameter("cvs-cache-interval"));
} catch (NumberFormatException e) {
logger.debug("Could not read parameter 'cvs-cache-interval' from web.xml. Using default value '"+cacheinterval+"' minutes");
}
logger.info("CacheServlet set to " + cacheinterval + " minutes interval.");
 
executor.submit(new Runnable() {
boolean isInterrupted = false;
 
@Override
public void run() {
while (!isInterrupted) {
for (File configfile : configfiles) {
CVSInfoImpl instance = new CVSInfoImpl();
logger.info("Caching modules from " + configfile.toURI().toString());
Response response = instance.getModules(null,
configfile, true);
List<ModuleType> list = (List<ModuleType>) ((GenericEntity) response
.getEntity()).getEntity();
if (list.size() == 0)
list.add(new ModuleType("", "", "", ""));
for (ModuleType t : list) {
try {
//Extra sleep
Thread.currentThread().sleep(5000);
} catch (InterruptedException e) {
isInterrupted = true;
break;
}
logger.info("Caching module '" + t.getName()+"'");
instance.getRepositoryFiles(null, configfile, t.getName(), true, true);
 
}
}
try {
logger.debug("Now sleeping for '"+cacheinterval+"' minutes");
Thread.currentThread().sleep(cacheinterval * 60000);
logger.debug("Waking up after '"+cacheinterval+"' minutes of sleep");
} catch (InterruptedException e) {
isInterrupted = true;
break;
}
}
 
}
});
 
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/util/BasicCVSListener.java
0,0 → 1,104
package net.brutex.xservices.util;
 
import java.io.PrintStream;
 
import org.netbeans.lib.cvsclient.command.FileInfoContainer;
import org.netbeans.lib.cvsclient.command.log.LogInformation;
import org.netbeans.lib.cvsclient.event.BinaryMessageEvent;
import org.netbeans.lib.cvsclient.event.CVSAdapter;
import org.netbeans.lib.cvsclient.event.CVSListener;
import org.netbeans.lib.cvsclient.event.FileAddedEvent;
import org.netbeans.lib.cvsclient.event.FileInfoEvent;
import org.netbeans.lib.cvsclient.event.FileRemovedEvent;
import org.netbeans.lib.cvsclient.event.FileToRemoveEvent;
import org.netbeans.lib.cvsclient.event.FileUpdatedEvent;
import org.netbeans.lib.cvsclient.event.MessageEvent;
import org.netbeans.lib.cvsclient.event.ModuleExpansionEvent;
import org.netbeans.lib.cvsclient.event.TerminationEvent;
 
public abstract class BasicCVSListener implements CVSListener
{
/**
* Stores a tagged line
*/
private final StringBuffer taggedLine = new StringBuffer();
 
/**
* Called when the server wants to send a message to be displayed to
* the user. The message is only for information purposes and clients
* can choose to ignore these messages if they wish.
* @param e the event
*/
public void messageSent(MessageEvent e)
{
String line = e.getMessage();
PrintStream stream = e.isError() ? System.err
: System.out;
 
if (e.isTagged())
{
String message = e.parseTaggedMessage(taggedLine, line);
// if we get back a non-null line, we have something
// to output. Otherwise, there is more to come and we
// should do nothing yet.
if (message != null)
{
//stream.println("Message: " + message);
}
}
else
{
//stream.println("Message: " + line);
}
}
 
@Override
public void commandTerminated(TerminationEvent arg0) {
}
 
@Override
public void fileAdded(FileAddedEvent arg0) {
}
 
@Override
public void fileInfoGenerated(FileInfoEvent arg0) {
FileInfoContainer info = arg0.getInfoContainer();
LogInformation info2 = (LogInformation) info;
System.out.println(info2.getRepositoryFilename());
System.out.println(info2.getDescription());
}
 
@Override
public void fileRemoved(FileRemovedEvent arg0) {
// TODO Auto-generated method stub
}
 
@Override
public void fileToRemove(FileToRemoveEvent arg0) {
// TODO Auto-generated method stub
}
 
@Override
public void fileUpdated(FileUpdatedEvent arg0) {
// TODO Auto-generated method stub
}
 
@Override
public void messageSent(BinaryMessageEvent arg0) {
// TODO Auto-generated method stub
}
 
@Override
public void moduleExpanded(ModuleExpansionEvent arg0) {
// TODO Auto-generated method stub
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/util/CVSClient.java
0,0 → 1,94
/*
* 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.util;
 
import java.io.File;
 
 
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.netbeans.lib.cvsclient.Client;
import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
import org.netbeans.lib.cvsclient.command.GlobalOptions;
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
import org.netbeans.lib.cvsclient.connection.PServerConnection;
 
public class CVSClient {
private final File configfile;
private final PServerConnection connection;
private final CVSRoot root;
private final GlobalOptions globalOptions;
public final Client client;
public CVSClient(File config) throws CommandAbortedException, AuthenticationException, ConfigurationException {
 
if (config == null || !config.exists() || config.isDirectory())
throw new ConfigurationException("Config file not found");
this.configfile = config;
Configuration configuration = new PropertiesConfiguration(configfile);
 
String cvsroot = configuration.getString("CVSROOT");
String workdir = configuration.getString("WORKDIR");
String password = configuration.getString("PASSWORD");
this.root = new CVSRoot(cvsroot);
this.globalOptions = new GlobalOptions();
globalOptions.setCVSRoot(cvsroot);
this.connection = new PServerConnection();
connection.setUserName(root.user);
if (password != null) {
connection.setEncodedPassword(CvsPassword.encode(password));
} else {
connection.setEncodedPassword(password);
}
 
connection.setHostName(root.host);
connection.setRepository(root.repository);
connection.open();
 
this.client = new Client(connection, new StandardAdminHandler());
client.setLocalPath(workdir);
}
/**
* @return
*/
public File getConfigFile() {
return this.configfile;
}
public GlobalOptions getGlobalOptions() {
return this.globalOptions;
}
/**
* @return the connection
*/
public PServerConnection getConnection() {
return connection;
}
/**
* @return the root
*/
public CVSRoot getRoot() {
return root;
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/util/CvsPassword.java
0,0 → 1,125
/*
* 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.util;
/*
* Copyright 2010 Andrew Kroh
*
* 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.
*/
 
 
 
/**
* A simple class for encoding and decoding passwords for CVS pserver protocol.
* Can be used to recover forgotten passwords.
*
* <p>
* Adapted from: http://blog.zmeeagain.com/2005/01/recover-cvs-pserver-passwords.html
*/
public class CvsPassword
{
private static final char[] LOOKUP_TABLE =
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 120, 53,
79, 0, 109, 72, 108, 70, 64, 76, 67, 116, 74, 68, 87, 111, 52, 75,
119, 49, 34, 82, 81, 95, 65, 112, 86, 118, 110, 122, 105, 41, 57,
83, 43, 46, 102, 40, 89, 38, 103, 45, 50, 42, 123, 91, 35, 125, 55,
54, 66, 124, 126, 59, 47, 92, 71, 115, 78, 88, 107, 106, 56, 0,
121, 117, 104, 101, 100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48,
58, 113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85};
 
/**
* Encodes a CVS password to be used in .cvspass file. Throws an exception
* if clearText is null, if a character is found outside the 0 - 126 range, or
* if within the range, one of the non-allowed characters.
*
* @param clearText
* the password in clear to be encoded
*
* @return the encoded cvs password
*/
public static String encode(String clearText)
{
// First character of encoded version is A:
char[] encoded = new char[clearText.length() + 1];
encoded[0] = 'A';
// Skip the first character:
int counter = 1;
for (char c : clearText.toCharArray())
{
if (c == '`' || c == '$' || c < 32)
{
throw new IllegalArgumentException(
"Illegal character was found in clear password.");
}
encoded[counter++] = LOOKUP_TABLE[c];
}
 
return String.valueOf(encoded);
}
 
/**
* Recovers an encoded via pserver protocol CVS password.
*
* @param encodedPassword
* the encoded password to be decoded
*
* @return the decoded password or null if the input was
* null or empty
*/
public static String decode(String encodedPassword)
{
String rtn = null;
if (encodedPassword != null && encodedPassword.length() > 0)
{
if (encodedPassword.startsWith("A"))
{
rtn = encode(encodedPassword.substring(1)).substring(1);
}
else
{
rtn = encode(encodedPassword).substring(1);
}
}
return rtn;
}
public static void main(String[] sArgs)
{
final String TEST_WORD = "i07w91";
String encoded = CvsPassword.encode(TEST_WORD);
System.out.println("Encoded: <" + encoded + ">");
String decoded = CvsPassword.decode(encoded);
System.out.println("Decoded: <" + decoded + ">");
System.out.println(decoded.equals(TEST_WORD) ? "Test Passed" : "Test Failed");
}
}
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/log4j.properties
8,5 → 8,10
 
# Print only messages of level WARN or above in the package com.foo.
log4j.logger.net.brutex.xservices=DEBUG
log4j.logger.net.brutex.xservices.ws.rs=DEBUG
 
log4j.logger.org.springframework=INFO
log4j.logger.org.springframework=INFO
 
log4j.logger.org.apache.jcs=DEBUG
 
log4j.logger.org.apache.commons=INFO
/xservices/trunk/src/java/cache.ccf
26,6 → 26,16
jcs.region.FileCache.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.FileCache.elementattributes.IsEternal=false
 
jcs.region.CVSCache=DC
jcs.region.CVSCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.CVSCache.cacheattributes.MaxObjects=50
jcs.region.CVSCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.CVSCache.cacheattributes.UseMemoryShrinker=true
jcs.region.CVSCache.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.region.CVSCache.cacheattributes.ShrinkerIntervalSeconds=60
jcs.region.CVSCache.cacheattributes.MaxSpoolPerRun=5
jcs.region.CVSCache.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.CVSCache.elementattributes.IsEternal=false
 
# AVAILABLE AUXILIARY CACHES
jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory