use of org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository in project maven-scm by apache.
the class LocalListCommand method executeListCommand.
/**
* {@inheritDoc}
*/
protected ListScmResult executeListCommand(ScmProviderRepository repo, ScmFileSet fileSet, boolean recursive, ScmVersion version) throws ScmException {
if (version != null) {
throw new ScmException("The local scm doesn't support tags.");
}
LocalScmProviderRepository repository = (LocalScmProviderRepository) repo;
File root = new File(repository.getRoot());
String module = repository.getModule();
File source = new File(root, module);
if (!root.exists()) {
throw new ScmException("The base directory doesn't exist (" + root.getAbsolutePath() + ").");
}
if (!source.exists()) {
throw new ScmException("The module directory doesn't exist (" + source.getAbsolutePath() + ").");
}
if (getLogger().isInfoEnabled()) {
getLogger().info("Listing files of '" + source.getAbsolutePath() + "'.");
}
try {
if (fileSet.getFileList() == null || fileSet.getFileList().isEmpty()) {
return new LocalListScmResult(null, getFiles(source, source, recursive));
} else {
List<ScmFile> files = new ArrayList<ScmFile>();
Iterator<File> it = fileSet.getFileList().iterator();
while (it.hasNext()) {
File file = (File) it.next();
files.addAll(getFiles(source, new File(source, file.getPath()), recursive));
}
return new LocalListScmResult(null, files);
}
} catch (Exception e) {
return new ListScmResult(null, "The svn command failed.", e.getMessage(), false);
}
}
use of org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository in project maven-scm by apache.
the class LocalChangeLogCommand method executeChangeLogCommand.
/**
* {@inheritDoc}
*/
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern) throws ScmException {
LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
if (branch != null) {
throw new ScmException("The local scm doesn't support tags.");
}
File root = new File(repo.getRoot());
String module = repo.getModule();
File source = new File(root, module);
File baseDestination = fileSet.getBasedir();
if (!baseDestination.exists()) {
throw new ScmException("The working directory doesn't exist (" + baseDestination.getAbsolutePath() + ").");
}
if (!root.exists()) {
throw new ScmException("The base directory doesn't exist (" + root.getAbsolutePath() + ").");
}
if (!source.exists()) {
throw new ScmException("The module directory doesn't exist (" + source.getAbsolutePath() + ").");
}
List<ChangeSet> changeLogList = new ArrayList<ChangeSet>();
try {
File repoRoot = new File(repo.getRoot(), repo.getModule());
List<File> files = fileSet.getFileList();
if (files.isEmpty()) {
@SuppressWarnings("unchecked") List<File> fileList = FileUtils.getFiles(baseDestination, "**", null, false);
files = fileList;
}
for (File file : files) {
String path = file.getPath().replace('\\', '/');
File repoFile = new File(repoRoot, path);
file = new File(baseDestination, path);
ChangeSet changeSet = new ChangeSet();
int chop = repoRoot.getAbsolutePath().length();
String fileName = "/" + repoFile.getAbsolutePath().substring(chop + 1);
changeSet.addFile(new ChangeFile(fileName, null));
if (repoFile.exists()) {
long lastModified = repoFile.lastModified();
Date modifiedDate = new Date(lastModified);
if (startDate != null) {
if (startDate.before(modifiedDate) || startDate.equals(modifiedDate)) {
if (endDate != null) {
if (endDate.after(modifiedDate) || endDate.equals(modifiedDate)) {
// nop
} else {
continue;
}
}
} else {
continue;
}
}
changeSet.setDate(modifiedDate);
changeLogList.add(changeSet);
} else {
// This file is deleted
changeLogList.add(changeSet);
}
}
} catch (IOException ex) {
throw new ScmException("Error while getting change logs.", ex);
}
return new ChangeLogScmResult(null, new ChangeLogSet(changeLogList, startDate, endDate));
}
use of org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository in project maven-scm by apache.
the class LocalCheckOutCommand method executeCheckOutCommand.
/**
* {@inheritDoc}
*/
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version, boolean recursive, boolean shallow) throws ScmException {
LocalScmProviderRepository repository = (LocalScmProviderRepository) repo;
if (version != null) {
throw new ScmException("The local scm doesn't support tags.");
}
File root = new File(repository.getRoot());
String module = repository.getModule();
File source = new File(root, module);
File baseDestination = fileSet.getBasedir();
if (!root.exists()) {
throw new ScmException("The base directory doesn't exist (" + root.getAbsolutePath() + ").");
}
if (!source.exists()) {
throw new ScmException("The module directory doesn't exist (" + source.getAbsolutePath() + ").");
}
List<ScmFile> checkedOutFiles;
try {
if (baseDestination.exists()) {
FileUtils.deleteDirectory(baseDestination);
}
if (!baseDestination.mkdirs()) {
throw new ScmException("Could not create destination directory '" + baseDestination.getAbsolutePath() + "'.");
}
if (getLogger().isInfoEnabled()) {
getLogger().info("Checking out '" + source.getAbsolutePath() + "' to '" + baseDestination.getAbsolutePath() + "'.");
}
List<File> fileList;
if (fileSet.getFileList().isEmpty()) {
@SuppressWarnings("unchecked") List<File> files = FileUtils.getFiles(source.getAbsoluteFile(), "**", null);
fileList = files;
} else {
fileList = fileSet.getFileList();
}
checkedOutFiles = checkOut(source, baseDestination, fileList, repository.getModule());
// write metadata file
LocalScmMetadataUtils metadataUtils = new LocalScmMetadataUtils(getLogger());
metadataUtils.writeMetadata(baseDestination, metadataUtils.buildMetadata(source));
} catch (IOException ex) {
throw new ScmException("Error while checking out the files.", ex);
}
return new LocalCheckOutScmResult(null, checkedOutFiles);
}
use of org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository in project maven-scm by apache.
the class LocalScmProvider method makeProviderScmRepository.
/**
* {@inheritDoc}
*/
public ScmProviderRepository makeProviderScmRepository(String scmSpecificUrl, char delimiter) throws ScmRepositoryException {
String[] tokens = StringUtils.split(scmSpecificUrl, Character.toString(delimiter));
if (tokens.length != 2) {
throw new ScmRepositoryException("The connection string didn't contain the expected number of tokens. " + "Expected 2 tokens but got " + tokens.length + " tokens.");
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
String root = tokens[0];
File rootFile = new File(root);
if (!rootFile.isAbsolute()) {
String basedir = System.getProperty("basedir", new File("").getAbsolutePath());
rootFile = new File(basedir, root);
}
if (!rootFile.exists()) {
throw new ScmRepositoryException("The root doesn't exists (" + rootFile.getAbsolutePath() + ").");
}
if (!rootFile.isDirectory()) {
throw new ScmRepositoryException("The root isn't a directory (" + rootFile.getAbsolutePath() + ").");
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
String module = tokens[1];
File moduleFile = new File(rootFile, module);
if (!moduleFile.exists()) {
throw new ScmRepositoryException("The module doesn't exist (root: " + rootFile.getAbsolutePath() + ", module: " + module + ").");
}
if (!moduleFile.isDirectory()) {
throw new ScmRepositoryException("The module isn't a directory.");
}
return new LocalScmProviderRepository(rootFile.getAbsolutePath(), module);
}
use of org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository in project maven-scm by apache.
the class LocalAddCommand method executeAddCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeAddCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
LocalScmProviderRepository localRepo = (LocalScmProviderRepository) repository;
List<ScmFile> fileList = new ArrayList<ScmFile>();
for (File file : fileSet.getFileList()) {
String path = file.getPath().replace('\\', '/');
localRepo.addFile(path);
fileList.add(new ScmFile(path, ScmFileStatus.ADDED));
}
// TODO: Also, ensure it is tested from the update test
return new AddScmResult(null, fileList);
}
Aggregations