Search in sources :

Example 21 with ScmFileStatus

use of org.apache.maven.scm.ScmFileStatus 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 22 with ScmFileStatus

use of org.apache.maven.scm.ScmFileStatus in project maven-scm by apache.

the class GitChangeLogConsumer method processGetFile.

/**
 * Process the current input line in the GET_FILE state.  This state
 * adds each file entry line to the current change log entry.  Note,
 * the revision number for the entire entry is used for the revision
 * number of each file.
 *
 * @param line A line of text from the git log output
 */
private void processGetFile(String line) {
    if (line.length() == 0) {
        if (currentChange != null) {
            entries.add(currentChange);
        }
        resetChangeLog();
        status = STATUS_GET_HEADER;
    } else {
        Matcher matcher = FILE_PATTERN.matcher(line);
        if (!matcher.matches()) {
            return;
        }
        final String actionChar = matcher.group(1);
        // action is currently not used
        final ScmFileStatus action;
        String name = matcher.group(2);
        String originalName = null;
        String originalRevision = null;
        if ("A".equals(actionChar)) {
            action = ScmFileStatus.ADDED;
        } else if ("M".equals(actionChar)) {
            action = ScmFileStatus.MODIFIED;
        } else if ("D".equals(actionChar)) {
            action = ScmFileStatus.DELETED;
        } else if ("R".equals(actionChar)) {
            action = ScmFileStatus.RENAMED;
            originalName = name;
            name = matcher.group(4);
            originalRevision = currentChange.getParentRevision();
        } else if ("C".equals(actionChar)) {
            action = ScmFileStatus.COPIED;
            originalName = name;
            name = matcher.group(4);
            originalRevision = currentChange.getParentRevision();
        } else {
            action = ScmFileStatus.UNKNOWN;
        }
        final ChangeFile changeFile = new ChangeFile(name, currentRevision);
        changeFile.setAction(action);
        changeFile.setOriginalName(originalName);
        changeFile.setOriginalRevision(originalRevision);
        currentChange.addFile(changeFile);
    }
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) Matcher(java.util.regex.Matcher) ChangeFile(org.apache.maven.scm.ChangeFile)

Example 23 with ScmFileStatus

use of org.apache.maven.scm.ScmFileStatus in project maven-scm by apache.

the class GitDiffRawConsumer method consumeLine.

// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
public void consumeLine(String line) {
    if (logger.isDebugEnabled()) {
        logger.debug(line);
    }
    if (StringUtils.isEmpty(line)) {
        return;
    }
    ScmFileStatus status = null;
    String[] parts = line.split("\\s", 6);
    if (parts.length != 6) {
        logger.warn("Skipping line because it doesn't contain the right status parameters: " + line);
        return;
    }
    String modus = parts[4];
    String file = parts[5];
    if ("A".equals(modus)) {
        status = ScmFileStatus.ADDED;
    } else if ("M".equals(modus)) {
        // attention! 'M' is 'updated', and _not_ ScmFileStatus.MODIFIED (which is for 'modified locally')
        status = ScmFileStatus.UPDATED;
    } else if ("D".equals(modus)) {
        status = ScmFileStatus.DELETED;
    } else {
        logger.warn("unknown status detected in line: " + line);
        return;
    }
    changedFiles.add(new ScmFile(file, status));
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) ScmFile(org.apache.maven.scm.ScmFile)

Example 24 with ScmFileStatus

use of org.apache.maven.scm.ScmFileStatus in project maven-scm by apache.

the class GitChangeLogConsumerTest method testConsumer2.

public void testConsumer2() throws Exception {
    GitChangeLogConsumer consumer = new GitChangeLogConsumer(new DefaultLog(), null);
    File f = getTestFile("/src/test/resources/git/changelog/gitwhatchanged2.gitlog");
    BufferedReader r = new BufferedReader(new FileReader(f));
    String line;
    while ((line = r.readLine()) != null) {
        consumer.consumeLine(line);
    }
    List<ChangeSet> modifications = consumer.getModifications();
    // must use *Linked* HashMap to have predictable toString
    final Map<ScmFileStatus, AtomicInteger> summary = new LinkedHashMap<ScmFileStatus, AtomicInteger>();
    for (Iterator<ChangeSet> i = modifications.iterator(); i.hasNext(); ) {
        ChangeSet entry = i.next();
        assertEquals("Mark Struberg <struberg@yahoo.de>", entry.getAuthor());
        assertNotNull(entry.getDate());
        assertTrue(entry.getComment() != null && entry.getComment().length() > 0);
        assertNotNull(entry.getRevision());
        assertNotNull(entry.getFiles());
        assertFalse(entry.getFiles().isEmpty());
        for (ChangeFile file : entry.getFiles()) {
            final ScmFileStatus action = file.getAction();
            if (!summary.containsKey(action)) {
                summary.put(action, new AtomicInteger());
            }
            summary.get(action).incrementAndGet();
        }
    }
    Assert.assertEquals("Action summary differs from expectations", "{modified=21, added=88, deleted=1}", summary.toString());
    assertEquals(8, modifications.size());
    ChangeSet entry = modifications.get(4);
    assertEquals("Mark Struberg <struberg@yahoo.de>", entry.getAuthor());
    assertNotNull(entry.getDate());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    assertEquals("2007-11-27 13:05:36 +0000", sdf.format(entry.getDate()));
    assertEquals("52733aa427041cafd760833cb068ffe897fd35db", entry.getRevision());
    assertEquals("fixed a GitCommandLineUtil and provice first version of the checkin command.", entry.getComment());
    assertNotNull(entry.getFiles());
    assertEquals(10, entry.getFiles().size());
    ChangeFile cf = entry.getFiles().get(0);
    assertEquals("maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java", cf.getName());
    assertTrue(cf.getRevision() != null && cf.getRevision().length() > 0);
}
Also used : DefaultLog(org.apache.maven.scm.log.DefaultLog) LinkedHashMap(java.util.LinkedHashMap) ScmFileStatus(org.apache.maven.scm.ScmFileStatus) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ChangeFile(org.apache.maven.scm.ChangeFile) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ChangeFile(org.apache.maven.scm.ChangeFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ScmFileStatus (org.apache.maven.scm.ScmFileStatus)24 ScmFile (org.apache.maven.scm.ScmFile)17 File (java.io.File)7 Matcher (java.util.regex.Matcher)6 ChangeFile (org.apache.maven.scm.ChangeFile)6 ArrayList (java.util.ArrayList)4 ChangeSet (org.apache.maven.scm.ChangeSet)4 ScmException (org.apache.maven.scm.ScmException)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 ScmResult (org.apache.maven.scm.ScmResult)1 BranchScmResult (org.apache.maven.scm.command.branch.BranchScmResult)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1 DefaultLog (org.apache.maven.scm.log.DefaultLog)1