| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package nl.toolforge.karma.core.vc.cvsimpl; |
| 20 |
|
|
| 21 |
|
import nl.toolforge.karma.core.KarmaRuntimeException; |
| 22 |
|
import nl.toolforge.karma.core.Patch; |
| 23 |
|
import nl.toolforge.karma.core.Version; |
| 24 |
|
import nl.toolforge.karma.core.module.Module; |
| 25 |
|
import nl.toolforge.karma.core.vc.DevelopmentLine; |
| 26 |
|
import nl.toolforge.karma.core.vc.ModuleStatus; |
| 27 |
|
import nl.toolforge.karma.core.vc.PatchLine; |
| 28 |
|
import nl.toolforge.karma.core.vc.model.MainLine; |
| 29 |
|
import org.apache.commons.logging.Log; |
| 30 |
|
import org.apache.commons.logging.LogFactory; |
| 31 |
|
import org.netbeans.lib.cvsclient.admin.Entry; |
| 32 |
|
import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; |
| 33 |
|
import org.netbeans.lib.cvsclient.command.log.LogInformation; |
| 34 |
|
|
| 35 |
|
import java.io.IOException; |
| 36 |
|
import java.util.ArrayList; |
| 37 |
|
import java.util.Collection; |
| 38 |
|
import java.util.Collections; |
| 39 |
|
import java.util.Iterator; |
| 40 |
|
import java.util.List; |
| 41 |
|
import java.util.regex.Matcher; |
| 42 |
|
import java.util.regex.Pattern; |
| 43 |
|
import java.util.regex.PatternSyntaxException; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
public class CVSModuleStatus implements ModuleStatus { |
| 50 |
|
|
| 51 |
0 |
private static final Log logger = LogFactory.getLog(Utils.class); |
| 52 |
|
|
| 53 |
0 |
private boolean existsInRepository = false; |
| 54 |
0 |
|
| 55 |
0 |
private List matchingList = null; |
| 56 |
0 |
|
| 57 |
0 |
private Module module = null; |
| 58 |
0 |
private LogInformation logInfo = null; |
| 59 |
0 |
private boolean connectionFailure = false; |
| 60 |
0 |
private boolean authenticationFailure = false; |
| 61 |
0 |
private boolean internalError = false; |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
0 |
public CVSModuleStatus(Module module, LogInformation logInfo) { |
| 71 |
0 |
this.module = module; |
| 72 |
0 |
setLogInformation(logInfo); |
| 73 |
0 |
} |
| 74 |
|
|
| 75 |
0 |
public CVSModuleStatus(Module module) { |
| 76 |
0 |
this.module = module; |
| 77 |
0 |
} |
| 78 |
|
|
| 79 |
|
public void setLogInformation(Object logInfo) { |
| 80 |
0 |
this.logInfo = (LogInformation) logInfo; |
| 81 |
0 |
matchingList = collectVersions(module); |
| 82 |
0 |
} |
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
public Version getNextVersion() { |
| 90 |
|
|
| 91 |
0 |
if (matchingList.size() == 0) { |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
0 |
if (module.hasPatchLine()) { |
| 100 |
0 |
return module.getVersion().createPatch(Patch.INITIAL_PATCH); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
0 |
return null; |
| 104 |
|
} |
| 105 |
|
|
| 106 |
0 |
Version nextVersion = null; |
| 107 |
|
|
| 108 |
|
try { |
| 109 |
0 |
nextVersion = (Version) ((Version) matchingList.get(matchingList.size() - 1)).clone(); |
| 110 |
0 |
} catch (CloneNotSupportedException e) { |
| 111 |
0 |
throw new KarmaRuntimeException(e.getMessage(), e); |
| 112 |
0 |
} |
| 113 |
|
|
| 114 |
0 |
nextVersion.increase(); |
| 115 |
|
|
| 116 |
0 |
return nextVersion; |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
public Version getNextMajorVersion() { |
| 120 |
0 |
if (matchingList.size() == 0) { |
| 121 |
0 |
return null; |
| 122 |
|
} |
| 123 |
|
|
| 124 |
0 |
Version nextVersion = null; |
| 125 |
|
|
| 126 |
|
try { |
| 127 |
0 |
nextVersion = (Version) ((Version) matchingList.get(matchingList.size() - 1)).clone(); |
| 128 |
0 |
} catch (CloneNotSupportedException e) { |
| 129 |
0 |
throw new KarmaRuntimeException(e.getMessage(), e); |
| 130 |
0 |
} |
| 131 |
|
|
| 132 |
0 |
nextVersion.increaseMajor(); |
| 133 |
|
|
| 134 |
0 |
return nextVersion; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
public Version getLastVersion() { |
| 143 |
|
|
| 144 |
0 |
if (matchingList.size() == 0) { |
| 145 |
|
|
| 146 |
0 |
if (module.hasPatchLine()) { |
| 147 |
0 |
return module.getVersion(); |
| 148 |
|
} else { |
| 149 |
0 |
return null; |
| 150 |
|
} |
| 151 |
|
} |
| 152 |
0 |
return (Version) matchingList.get(matchingList.size() - 1); |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
public Version getLocalVersion() throws CVSException { |
| 162 |
0 |
logger.debug("Retrieving local version for module: "+module.getName()); |
| 163 |
0 |
StandardAdminHandler handler = new StandardAdminHandler(); |
| 164 |
0 |
Version localVersion = null; |
| 165 |
|
|
| 166 |
|
try { |
| 167 |
0 |
Entry[] entries = handler.getEntriesAsArray(module.getBaseDir()); |
| 168 |
|
|
| 169 |
0 |
Entry moduleDescriptor = null; |
| 170 |
|
|
| 171 |
0 |
int i = 0; |
| 172 |
0 |
while (i < entries.length) { |
| 173 |
0 |
if (entries[i].getName().equals(Module.MODULE_DESCRIPTOR)) { |
| 174 |
0 |
moduleDescriptor = entries[i]; |
| 175 |
0 |
break; |
| 176 |
|
} |
| 177 |
0 |
i++; |
| 178 |
|
} |
| 179 |
|
try { |
| 180 |
|
|
| 181 |
0 |
if (moduleDescriptor == null || moduleDescriptor.getTag() == class="keyword">null || moduleDescriptor.getTag().matches(DevelopmentLine.DEVELOPMENT_LINE_PATTERN_STRING)) { |
| 182 |
0 |
logger.debug("We're on the head. Return null."); |
| 183 |
|
|
| 184 |
|
|
| 185 |
0 |
return null; |
| 186 |
|
} |
| 187 |
0 |
if (moduleDescriptor.getTag().startsWith(PatchLine.NAME_PREFIX)) { |
| 188 |
0 |
localVersion = new Patch(moduleDescriptor.getTag().substring(moduleDescriptor.getTag().indexOf("_") + 1)); |
| 189 |
0 |
logger.debug("PatchLine. Return "+localVersion); |
| 190 |
0 |
} else { |
| 191 |
0 |
localVersion = new Version(moduleDescriptor.getTag().substring(moduleDescriptor.getTag().indexOf("_") + 1)); |
| 192 |
0 |
logger.debug("MainLine. Return "+localVersion); |
| 193 |
|
} |
| 194 |
|
|
| 195 |
0 |
} catch (Exception e) { |
| 196 |
0 |
throw new CVSException(CVSException.LOCAL_MODULE_ERROR, class="keyword">new Object[]{module.getName()}); |
| 197 |
0 |
} |
| 198 |
0 |
|
| 199 |
0 |
} catch (IOException e) { |
| 200 |
0 |
throw new CVSException(CVSException.LOCAL_MODULE_ERROR, class="keyword">new Object[]{module.getName()}); |
| 201 |
0 |
} |
| 202 |
0 |
return localVersion; |
| 203 |
|
} |
| 204 |
|
|
| 205 |
|
public void setExistsInRepository(boolean exists) { |
| 206 |
0 |
existsInRepository = exists; |
| 207 |
0 |
} |
| 208 |
|
|
| 209 |
|
public boolean existsInRepository() { |
| 210 |
0 |
return existsInRepository; |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
private List collectVersions(Module module) { |
| 214 |
|
|
| 215 |
0 |
if (logInfo == null) { |
| 216 |
0 |
return new ArrayList(); |
| 217 |
0 |
} |
| 218 |
|
|
| 219 |
0 |
|
| 220 |
0 |
|
| 221 |
|
|
| 222 |
0 |
List matchingList = new ArrayList(); |
| 223 |
0 |
|
| 224 |
0 |
Collection currentVersions = logInfo.getAllSymbolicNames(); |
| 225 |
|
|
| 226 |
0 |
Pattern pattern = null; |
| 227 |
|
|
| 228 |
0 |
if (module.hasPatchLine()) { |
| 229 |
|
|
| 230 |
0 |
|
| 231 |
|
|
| 232 |
0 |
pattern = Pattern.compile(((PatchLine) module.getPatchLine()).getMatchingPattern()); |
| 233 |
|
} else { |
| 234 |
|
|
| 235 |
|
|
| 236 |
0 |
pattern = Pattern.compile(MainLine.NAME_PREFIX.concat("_").concat(Version.VERSION_PATTERN_STRING)); |
| 237 |
|
} |
| 238 |
0 |
|
| 239 |
|
|
| 240 |
|
|
| 241 |
0 |
for (Iterator it = currentVersions.iterator(); it.hasNext();) { |
| 242 |
|
|
| 243 |
0 |
String s = ((LogInformation.SymName) it.next()).getName(); |
| 244 |
|
|
| 245 |
0 |
Matcher matcher = pattern.matcher(s); |
| 246 |
0 |
if (matcher.matches()) { |
| 247 |
|
|
| 248 |
|
try { |
| 249 |
0 |
if (module.hasPatchLine()) { |
| 250 |
0 |
matchingList.add(new Patch(s.substring(s.lastIndexOf("_") + 1))); |
| 251 |
|
} else { |
| 252 |
0 |
matchingList.add(new Version(s.substring(s.lastIndexOf("_") + 1))); |
| 253 |
|
} |
| 254 |
0 |
} catch (PatternSyntaxException p) { |
| 255 |
|
|
| 256 |
0 |
} |
| 257 |
|
} |
| 258 |
|
} |
| 259 |
|
|
| 260 |
|
|
| 261 |
|
|
| 262 |
0 |
Collections.sort(matchingList); |
| 263 |
|
|
| 264 |
0 |
return matchingList; |
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
public boolean connectionFailure() { |
| 268 |
0 |
return connectionFailure; |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
public boolean authenticationFailure() { |
| 272 |
0 |
return authenticationFailure; |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
public boolean internalError() { |
| 276 |
0 |
return internalError; |
| 277 |
|
} |
| 278 |
|
|
| 279 |
|
|
| 280 |
|
|
| 281 |
|
|
| 282 |
|
public void setConnnectionFailure() { |
| 283 |
0 |
connectionFailure = true; |
| 284 |
0 |
} |
| 285 |
|
|
| 286 |
|
public void setAuthenticationFailure() { |
| 287 |
0 |
authenticationFailure = true; |
| 288 |
0 |
} |
| 289 |
|
|
| 290 |
|
public void setInternalError() { |
| 291 |
0 |
internalError = true; |
| 292 |
0 |
} |
| 293 |
|
} |