| 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.AuthenticationException; |
| 26 |
|
import nl.toolforge.karma.core.vc.DevelopmentLine; |
| 27 |
|
import nl.toolforge.karma.core.vc.ModuleStatus; |
| 28 |
|
import nl.toolforge.karma.core.vc.PatchLine; |
| 29 |
|
import nl.toolforge.karma.core.vc.Runner; |
| 30 |
|
import nl.toolforge.karma.core.vc.RunnerFactory; |
| 31 |
|
import nl.toolforge.karma.core.vc.SymbolicName; |
| 32 |
|
import nl.toolforge.karma.core.vc.VersionControlException; |
| 33 |
|
import nl.toolforge.karma.core.vc.model.MainLine; |
| 34 |
|
import org.apache.commons.logging.Log; |
| 35 |
|
import org.apache.commons.logging.LogFactory; |
| 36 |
|
|
| 37 |
0 |
public final class Utils { |
| 38 |
|
|
| 39 |
28 |
private static final Log logger = LogFactory.getLog(Utils.class); |
| 40 |
24 |
|
| 41 |
52 |
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
public static SymbolicName createSymbolicName(Module module, DevelopmentLine developmentLine, Version version) { |
| 57 |
|
|
| 58 |
28 |
if (version == null) { |
| 59 |
24 |
new CVSTag(""); |
| 60 |
52 |
if (developmentLine != null) { |
| 61 |
0 |
return new CVSTag(developmentLine.getName()); |
| 62 |
0 |
} else { |
| 63 |
0 |
|
| 64 |
|
|
| 65 |
0 |
new CVSTag(""); |
| 66 |
|
} |
| 67 |
0 |
} else { |
| 68 |
28 |
if (developmentLine != null) { |
| 69 |
24 |
|
| 70 |
59 |
if (developmentLine instanceof PatchLine) { |
| 71 |
13 |
if (!(version instanceof Patch)) { |
| 72 |
19 |
throw new KarmaRuntimeException( |
| 73 |
13 |
"The provided developmentLine is a PatchLine instance. This implies " + |
| 74 |
0 |
"that the provided version should be a Patch instance."); |
| 75 |
|
} |
| 76 |
7 |
return createSymbolicName((Patch)version); |
| 77 |
6 |
} else { |
| 78 |
13 |
return new CVSTag(developmentLine.getName() + "_" + version.getVersionNumber()); |
| 79 |
|
} |
| 80 |
21 |
} else if (version instanceof Patch) { |
| 81 |
18 |
|
| 82 |
39 |
|
| 83 |
|
|
| 84 |
0 |
return new CVSTag(PatchLine.NAME_PREFIX + PatchLine.PATCH_SEPARATOR + version.getVersionNumber()); |
| 85 |
|
|
| 86 |
0 |
} else { |
| 87 |
21 |
return new CVSTag(MainLine.NAME_PREFIX + "_" + version.getVersionNumber()); |
| 88 |
18 |
} |
| 89 |
39 |
|
| 90 |
|
} |
| 91 |
0 |
return new CVSTag(""); |
| 92 |
|
} |
| 93 |
0 |
|
| 94 |
|
public static SymbolicName createSymbolicName(Module module, Version version) { |
| 95 |
7 |
return Utils.createSymbolicName(module, null, version); |
| 96 |
18 |
} |
| 97 |
39 |
|
| 98 |
|
public static SymbolicName createSymbolicName(Patch patch) { |
| 99 |
7 |
return new CVSTag(PatchLine.NAME_PREFIX + PatchLine.PATCH_SEPARATOR + patch.getVersionNumber()); |
| 100 |
6 |
} |
| 101 |
13 |
|
| 102 |
|
public static Version getLastVersion(Module module) throws VersionControlException { |
| 103 |
|
|
| 104 |
0 |
logger.debug("Getting last version for module : " + module.getName()); |
| 105 |
|
|
| 106 |
0 |
Runner runner = null; |
| 107 |
|
try { |
| 108 |
0 |
runner = RunnerFactory.getRunner(module.getLocation()); |
| 109 |
0 |
} catch (AuthenticationException e) { |
| 110 |
0 |
throw new CVSException(e.getErrorCode(), e.getMessageArguments()); |
| 111 |
0 |
} |
| 112 |
0 |
|
| 113 |
0 |
ModuleStatus status = new CVSModuleStatus(module, ((CVSRunner) runner).log(module)); |
| 114 |
0 |
return status.getLastVersion(); |
| 115 |
0 |
} |
| 116 |
0 |
|
| 117 |
|
public static Version getLocalVersion(Module module) throws VersionControlException { |
| 118 |
0 |
logger.debug("Getting local version for module : " + module.getName()); |
| 119 |
|
|
| 120 |
0 |
ModuleStatus status = new CVSModuleStatus(module); |
| 121 |
0 |
logger.debug("returning: " + status.getLocalVersion()); |
| 122 |
0 |
return status.getLocalVersion(); |
| 123 |
0 |
} |
| 124 |
0 |
|
| 125 |
|
public static boolean existsInRepository(Module module) { |
| 126 |
|
|
| 127 |
0 |
Runner runner = null; |
| 128 |
|
try { |
| 129 |
0 |
runner = RunnerFactory.getRunner(module.getLocation()); |
| 130 |
0 |
return runner.existsInRepository(module); |
| 131 |
0 |
|
| 132 |
0 |
} catch (AuthenticationException e) { |
| 133 |
0 |
return false; |
| 134 |
0 |
} catch (VersionControlException c) { |
| 135 |
0 |
return false; |
| 136 |
0 |
} |
| 137 |
0 |
} |
| 138 |
|
} |