1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.scm.provider.svn.svnexe.command.status; 20 21 import java.io.File; 22 import java.util.ArrayList; 23 import java.util.List; 24 25 import org.apache.maven.scm.ScmFile; 26 import org.apache.maven.scm.ScmFileStatus; 27 import org.apache.maven.scm.util.AbstractConsumer; 28 29 /** 30 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> 31 * 32 */ 33 public class SvnStatusConsumer extends AbstractConsumer { 34 private final File workingDirectory; 35 36 private final List<ScmFile> changedFiles = new ArrayList<>(); 37 38 // ---------------------------------------------------------------------- 39 // 40 // ---------------------------------------------------------------------- 41 42 public SvnStatusConsumer(File workingDirectory) { 43 this.workingDirectory = workingDirectory; 44 } 45 46 // ---------------------------------------------------------------------- 47 // StreamConsumer Implementation 48 // ---------------------------------------------------------------------- 49 50 /** {@inheritDoc} */ 51 public void consumeLine(String line) { 52 if (logger.isDebugEnabled()) { 53 logger.debug(line); 54 } 55 if (line.trim().isEmpty()) { 56 return; 57 } 58 59 if (line.length() <= 7) { 60 if (logger.isWarnEnabled()) { 61 logger.warn("Unexpected input, the line must be at least seven characters long. Line: '" + line + "'."); 62 } 63 64 return; 65 } 66 67 String statusString = line.substring(0, 1); 68 69 String file = line.substring(7).trim(); 70 71 ScmFileStatus status; 72 73 // The first six columns in the output are each one character wide: 74 // First column: Says if item was added, deleted, or otherwise changed 75 // ' ' no modifications 76 // 'A' Added 77 // 'C' Conflicted 78 // 'D' Deleted 79 // 'I' Ignored 80 // 'M' Modified 81 // 'R' Replaced 82 // 'X' item is unversioned, but is used by an externals definition 83 // '?' item is not under version control 84 // '!' item is missing (removed by non-svn command) or incomplete 85 // '~' versioned item obstructed by some item of a different kind 86 // Second column: Modifications of a file's or directory's properties 87 // ' ' no modifications 88 // 'C' Conflicted 89 // 'M' Modified 90 // Third column: Whether the working copy directory is locked 91 // ' ' not locked 92 // 'L' locked 93 // Fourth column: Scheduled commit will contain addition-with-history 94 // ' ' no history scheduled with commit 95 // '+' history scheduled with commit 96 // Fifth column: Whether the item is switched relative to its parent 97 // ' ' normal 98 // 'S' switched 99 // Sixth column: Repository lock token 100 // (without -u) 101 // ' ' no lock token 102 // 'K' lock token present 103 // (with -u) 104 // ' ' not locked in repository, no lock token 105 // 'K' locked in repository, lock toKen present 106 // 'O' locked in repository, lock token in some Other working copy 107 // 'T' locked in repository, lock token present but sTolen 108 // 'B' not locked in repository, lock token present but Broken 109 // 110 // The out-of-date information appears in the eighth column (with -u): 111 // '*' a newer revision exists on the server 112 // ' ' the working copy is up to date 113 if (statusString.equals("A")) { 114 status = ScmFileStatus.ADDED; 115 } else if (statusString.equals("M") || statusString.equals("R") || statusString.equals("~")) { 116 status = ScmFileStatus.MODIFIED; 117 } else if (statusString.equals("D")) { 118 status = ScmFileStatus.DELETED; 119 } else if (statusString.equals("?")) { 120 status = ScmFileStatus.UNKNOWN; 121 } else if (statusString.equals("!")) { 122 status = ScmFileStatus.MISSING; 123 } else if (statusString.equals("C")) { 124 status = ScmFileStatus.CONFLICT; 125 } else if (statusString.equals("L")) { 126 status = ScmFileStatus.LOCKED; 127 } else if (statusString.equals("X")) { 128 // skip svn:external entries 129 return; 130 } else if (statusString.equals("I")) { 131 // skip svn:external entries 132 return; 133 } else { 134 // Parse the second column 135 statusString = line.substring(1, 1); 136 137 // The line isn't a status line, ie something like 'Performing status on external item at...' 138 // or a status defined in next columns 139 return; 140 } 141 142 // If the file isn't a file; don't add it. 143 if (!status.equals(ScmFileStatus.DELETED) && !new File(workingDirectory, file).isFile()) { 144 return; 145 } 146 147 changedFiles.add(new ScmFile(file, status)); 148 } 149 150 public List<ScmFile> getChangedFiles() { 151 return changedFiles; 152 } 153 }