Search in sources :

Example 1 with LocalScmProviderRepository

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);
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) LocalScmProviderRepository(org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository) ArrayList(java.util.ArrayList) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmException(org.apache.maven.scm.ScmException) ScmFile(org.apache.maven.scm.ScmFile)

Example 2 with LocalScmProviderRepository

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));
}
Also used : ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) LocalScmProviderRepository(org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) ChangeFile(org.apache.maven.scm.ChangeFile) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeFile(org.apache.maven.scm.ChangeFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 3 with LocalScmProviderRepository

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);
}
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 4 with LocalScmProviderRepository

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

Example 5 with LocalScmProviderRepository

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);
}
Also used : LocalScmProviderRepository(org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Aggregations

File (java.io.File)8 LocalScmProviderRepository (org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository)8 ScmFile (org.apache.maven.scm.ScmFile)6 ArrayList (java.util.ArrayList)5 ScmException (org.apache.maven.scm.ScmException)5 IOException (java.io.IOException)4 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)2 LocalScmMetadataUtils (org.apache.maven.scm.provider.local.metadata.LocalScmMetadataUtils)2 Date (java.util.Date)1 ChangeFile (org.apache.maven.scm.ChangeFile)1 ChangeSet (org.apache.maven.scm.ChangeSet)1 CommandParameters (org.apache.maven.scm.CommandParameters)1 ScmFileStatus (org.apache.maven.scm.ScmFileStatus)1 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)1 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1 ListScmResult (org.apache.maven.scm.command.list.ListScmResult)1 MkdirScmResult (org.apache.maven.scm.command.mkdir.MkdirScmResult)1 LocalAddCommand (org.apache.maven.scm.provider.local.command.add.LocalAddCommand)1 LocalScmMetadata (org.apache.maven.scm.provider.local.metadata.LocalScmMetadata)1