use of org.apache.maven.scm.provider.local.metadata.LocalScmMetadataUtils 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.metadata.LocalScmMetadataUtils in project maven-scm by apache.
the class LocalUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) 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 (!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() + ").");
}
if (!baseDestination.exists() && !baseDestination.isDirectory()) {
throw new ScmException("The destination directory isn't a directory or doesn't exist (" + baseDestination.getAbsolutePath() + ").");
}
List<ScmFile> updatedFiles;
try {
if (getLogger().isInfoEnabled()) {
getLogger().info("Updating '" + baseDestination.getAbsolutePath() + "' from '" + source.getAbsolutePath() + "'.");
}
@SuppressWarnings("unchecked") List<File> fileList = FileUtils.getFiles(source.getAbsoluteFile(), "**", null);
List<File> list = fileList;
updatedFiles = update(source, baseDestination, list);
// process deletions in repository
LocalScmMetadataUtils metadataUtils = new LocalScmMetadataUtils(getLogger());
LocalScmMetadata originalMetadata = metadataUtils.readMetadata(baseDestination);
if (originalMetadata != null) {
LocalScmMetadata newMetadata = metadataUtils.buildMetadata(source);
for (Iterator<String> it = originalMetadata.getRepositoryFileNames().iterator(); it.hasNext(); ) {
String filename = it.next();
if (!newMetadata.getRepositoryFileNames().contains(filename)) {
File localFile = new File(baseDestination, filename);
if (localFile.exists()) {
localFile.delete();
updatedFiles.add(new ScmFile("/" + filename, ScmFileStatus.UPDATED));
}
}
}
}
// rewrite metadata file
metadataUtils.writeMetadata(baseDestination, metadataUtils.buildMetadata(source));
} catch (IOException ex) {
throw new ScmException("Error while checking out the files.", ex);
}
return new LocalUpdateScmResult(null, updatedFiles);
}
Aggregations