com.greenpepper.runner.repository.VFSRepository Maven / Gradle / Ivy
package com.greenpepper.runner.repository;
import com.greenpepper.dialect.SpecificationDialect;
import com.greenpepper.document.Document;
import com.greenpepper.html.HtmlDocumentBuilder;
import com.greenpepper.repository.DocumentNode;
import com.greenpepper.repository.DocumentNotFoundException;
import com.greenpepper.repository.DocumentRepository;
import com.greenpepper.repository.UnsupportedDocumentException;
import com.greenpepper.util.ExceptionImposter;
import com.greenpepper.util.IOUtil;
import com.greenpepper.shaded.org.apache.commons.vfs.FileObject;
import com.greenpepper.shaded.org.apache.commons.vfs.FileSystemException;
import com.greenpepper.shaded.org.apache.commons.vfs.FileSystemManager;
import com.greenpepper.shaded.org.apache.commons.vfs.FileType;
import com.greenpepper.shaded.org.apache.commons.vfs.VFS;
import com.greenpepper.shaded.org.apache.commons.vfs.impl.DefaultFileSystemManager;
import com.greenpepper.shaded.org.apache.commons.vfs.provider.FileProvider;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* The goal of the file system repository is to give access to specification
* documents kept in a file system directory hierarchical structure.
*
* This particular VFSRepository is implemented using commons.VFS
* (Virtual File Systems). It allows us to implements our file system with
* different kinds of protocol (file system, FTP, HTTP ...) It is also possible
* to create our own resolver and implements, for example, a file system inside
* a database table(s) or maybe, most interestigly for GreenPepper, inside a wiki.
*
* See documentation of VFS for more detail.
*
* @author clapointe
* @version $Id: $Id
*/
public class VFSRepository implements DocumentRepository
{
private final FileSystemManager fileSystemManager;
/** Constant NOT_HIDDEN_FILE_TYPE_SELECTOR
*/
protected static final NotHiddenFileTypeSelector NOT_HIDDEN_FILE_TYPE_SELECTOR = new NotHiddenFileTypeSelector(FileType.FILE);
private SpecificationDialect specificationDialect;
/**
* Constructor for VFSRepository.
*/
public VFSRepository()
{
try
{
fileSystemManager = VFS.getManager();
}
catch (FileSystemException ex)
{
throw ExceptionImposter.imposterize( ex );
}
}
/** {@inheritDoc} */
public void setDocumentAsImplemeted(String location) throws Exception {}
@Override
public DocumentNode getSpecificationsHierarchy(String project, String systemUnderTest) {
// TODO
throw new UnsupportedOperationException("This functionnality is not yet implemented!");
}
@Override
public void setSpecificationDialect(SpecificationDialect specificationDialect) {
this.specificationDialect = specificationDialect;
}
/** {@inheritDoc} */
public List listDocuments(String location) throws Exception
{
FileObject root = getFileObject( location );
if (!root.exists()) return Collections.emptyList();
List names = new ArrayList();
if (isDirectory(root))
{
for (FileObject child : root.findFiles(NOT_HIDDEN_FILE_TYPE_SELECTOR))
{
names.addAll( listDocuments(child.getName().getURI()));
}
}
else
{
names.add(root.getName().getURI());
}
return names;
}
/**
* listDocumentsInHierarchy.
*
* @return a {@link java.util.List} object.
* @throws java.lang.Exception if any.
*/
public List