use of org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository in project maven-scm by apache.
the class LocalCheckInCommand method executeCheckInCommand.
/**
* {@inheritDoc}
*/
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, ScmVersion version) throws ScmException {
LocalScmProviderRepository repository = (LocalScmProviderRepository) repo;
if (version != null && StringUtils.isNotEmpty(version.getName())) {
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() + ").");
}
List<ScmFile> checkedInFiles = new ArrayList<ScmFile>();
try {
// Only copy files newer than in the repo
File repoRoot = new File(repository.getRoot(), repository.getModule());
List<File> files = fileSet.getFileList();
if (files.isEmpty()) {
@SuppressWarnings("unchecked") List<File> listFiles = FileUtils.getFiles(baseDestination, "**", null, false);
files = listFiles;
}
for (File file : files) {
String path = file.getPath().replace('\\', '/');
File repoFile = new File(repoRoot, path);
file = new File(baseDestination, path);
ScmFileStatus status;
if (repoFile.exists()) {
String repoFileContents = FileUtils.fileRead(repoFile);
String fileContents = FileUtils.fileRead(file);
if (getLogger().isDebugEnabled()) {
getLogger().debug("fileContents:" + fileContents);
getLogger().debug("repoFileContents:" + repoFileContents);
}
if (fileContents.equals(repoFileContents)) {
continue;
}
status = ScmFileStatus.CHECKED_IN;
} else if (repository.isFileAdded(path)) {
status = ScmFileStatus.CHECKED_IN;
} else {
if (getLogger().isWarnEnabled()) {
getLogger().warn("skipped unknown file in checkin:" + path);
}
// unknown file, skip
continue;
}
FileUtils.copyFile(file, repoFile);
ScmFile scmFile = new ScmFile(path, status);
getLogger().info(scmFile.toString());
checkedInFiles.add(scmFile);
}
} catch (IOException ex) {
throw new ScmException("Error while checking in the files.", ex);
}
return new CheckInScmResult(null, checkedInFiles);
}
use of org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository 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);
}
use of org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository in project maven-scm by apache.
the class LocalMkdirCommand method executeMkdirCommand.
protected MkdirScmResult executeMkdirCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal) throws ScmException {
LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
List<ScmFile> createdDirs = new ArrayList<ScmFile>();
// create/commit the directory directly in the repository
if (!createInLocal) {
File file = (File) fileSet.getFileList().get(0);
File modulePath = new File(repo.getRoot(), repo.getModule());
File dir = new File(modulePath, file.getName());
if (dir.exists()) {
return new MkdirScmResult(null, "Directory already exists!", "Directory already exists.", false);
} else {
if (getLogger().isInfoEnabled()) {
getLogger().info("Creating directory in '" + modulePath.getAbsolutePath() + "'");
}
FileUtils.mkdir(dir.getAbsolutePath());
createdDirs.add(new ScmFile(dir.getPath(), ScmFileStatus.ADDED));
}
} else {
// add the directory, but not commit
LocalAddCommand addCmd = new LocalAddCommand();
addCmd.setLogger(getLogger());
CommandParameters parameters = new CommandParameters();
parameters.setString(CommandParameter.MESSAGE, message);
parameters.setString(CommandParameter.BINARY, "false");
String path = ((File) fileSet.getFileList().get(0)).getPath();
if (repo.isFileAdded(path)) {
return new MkdirScmResult(null, "Directory already exists!", "Directory already exists.", false);
}
AddScmResult result = (AddScmResult) addCmd.execute(repository, fileSet, parameters);
createdDirs.addAll(result.getAddedFiles());
}
return new MkdirScmResult(null, createdDirs);
}
Aggregations