Search in sources :

Example 1 with LocalScmMetadataUtils

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);
}
Also used : ScmException(org.apache.maven.scm.ScmException) LocalScmProviderRepository(org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository) LocalScmMetadataUtils(org.apache.maven.scm.provider.local.metadata.LocalScmMetadataUtils) IOException(java.io.IOException) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 2 with LocalScmMetadataUtils

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);
}
Also used : ScmException(org.apache.maven.scm.ScmException) LocalScmProviderRepository(org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository) LocalScmMetadata(org.apache.maven.scm.provider.local.metadata.LocalScmMetadata) LocalScmMetadataUtils(org.apache.maven.scm.provider.local.metadata.LocalScmMetadataUtils) IOException(java.io.IOException) ScmFile(org.apache.maven.scm.ScmFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 ScmException (org.apache.maven.scm.ScmException)2 ScmFile (org.apache.maven.scm.ScmFile)2 LocalScmMetadataUtils (org.apache.maven.scm.provider.local.metadata.LocalScmMetadataUtils)2 LocalScmProviderRepository (org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository)2 LocalScmMetadata (org.apache.maven.scm.provider.local.metadata.LocalScmMetadata)1