Search in sources :

Example 6 with LocalScmProviderRepository

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

Example 7 with LocalScmProviderRepository

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);
}
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)

Example 8 with LocalScmProviderRepository

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