1 |
|
package nl.toolforge.karma.core.boot; |
2 |
|
|
3 |
|
import nl.toolforge.karma.core.ErrorCode; |
4 |
|
import nl.toolforge.karma.core.KarmaRuntimeException; |
5 |
|
import nl.toolforge.karma.core.location.Location; |
6 |
|
import nl.toolforge.karma.core.location.LocationException; |
7 |
|
import nl.toolforge.karma.core.module.Module; |
8 |
|
import nl.toolforge.karma.core.vc.AuthenticationException; |
9 |
|
import nl.toolforge.karma.core.vc.Runner; |
10 |
|
import nl.toolforge.karma.core.vc.RunnerFactory; |
11 |
|
import nl.toolforge.karma.core.vc.VersionControlException; |
12 |
|
import nl.toolforge.karma.core.vc.cvsimpl.Utils; |
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
public abstract class AdminStore implements Store { |
19 |
|
|
20 |
190 |
public static final ErrorCode STORE_CONNECTION_FAILURE = new ErrorCode("WCC-00002"); |
21 |
190 |
public static final ErrorCode AUTHENTICATOR_NOT_FOUND = new ErrorCode("WCC-00003"); |
22 |
190 |
public static final ErrorCode STORE_MODULE_NO_IN_REPOSITORY = new ErrorCode("WCC-00004"); |
23 |
|
|
24 |
1036 |
private WorkingContext workingContext = null; |
25 |
1036 |
private Location location = null; |
26 |
|
|
27 |
1036 |
private String moduleName = null; |
28 |
|
|
29 |
1036 |
protected Module module = null; |
30 |
|
|
31 |
1036 |
public AdminStore(WorkingContext workingContext) { |
32 |
|
|
33 |
1036 |
if (workingContext == null) { |
34 |
0 |
throw new IllegalArgumentException("Working context cannot be null."); |
35 |
|
} |
36 |
|
|
37 |
1036 |
this.workingContext = workingContext; |
38 |
1036 |
} |
39 |
|
|
40 |
|
public AdminStore(WorkingContext workingContext, String moduleName, Location location) { |
41 |
1020 |
this(workingContext); |
42 |
896 |
this.moduleName = moduleName; |
43 |
896 |
this.location = location; |
44 |
896 |
} |
45 |
|
|
46 |
124 |
protected final WorkingContext getWorkingContext() { |
47 |
868 |
return workingContext; |
48 |
|
} |
49 |
|
|
50 |
124 |
public final void setLocation(Location location) { |
51 |
124 |
|
52 |
0 |
if (location == null) { |
53 |
0 |
throw new IllegalArgumentException("Location cannot be null."); |
54 |
124 |
} |
55 |
|
|
56 |
0 |
this.location = location; |
57 |
0 |
} |
58 |
|
|
59 |
|
public final Location getLocation() { |
60 |
868 |
return location; |
61 |
|
} |
62 |
|
|
63 |
|
public final void update() throws AuthenticationException, VersionControlException { |
64 |
|
|
65 |
0 |
if (moduleName == null || "".equals(moduleName)) { |
66 |
0 |
throw new KarmaRuntimeException("Module name for manifest store has not been set (correctly)."); |
67 |
|
} |
68 |
124 |
|
69 |
124 |
Runner runner = RunnerFactory.getRunner(location); |
70 |
|
|
71 |
|
|
72 |
498 |
|
73 |
0 |
if (getModule().getBaseDir().exists()) { |
74 |
0 |
runner.update(getModule()); |
75 |
|
} else { |
76 |
0 |
runner.checkout(getModule()); |
77 |
|
} |
78 |
1743 |
} |
79 |
|
|
80 |
|
public final void setModuleName(String moduleName) { |
81 |
0 |
this.moduleName = moduleName; |
82 |
0 |
} |
83 |
|
|
84 |
|
public final String getModuleName() { |
85 |
1743 |
return moduleName; |
86 |
|
} |
87 |
|
|
88 |
|
public final boolean exists() { |
89 |
0 |
return Utils.existsInRepository(getModule()); |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
public ErrorCode checkConfiguration() { |
96 |
|
|
97 |
0 |
if (getLocation() == null) { |
98 |
0 |
return STORE_CONNECTION_FAILURE; |
99 |
|
} |
100 |
|
|
101 |
|
try { |
102 |
0 |
getLocation().connect(); |
103 |
0 |
} catch (AuthenticationException e) { |
104 |
0 |
return STORE_CONNECTION_FAILURE; |
105 |
0 |
} catch (LocationException e) { |
106 |
0 |
return STORE_CONNECTION_FAILURE; |
107 |
0 |
} |
108 |
|
|
109 |
0 |
if (!Utils.existsInRepository(getModule())) { |
110 |
0 |
return STORE_MODULE_NO_IN_REPOSITORY; |
111 |
|
} |
112 |
|
|
113 |
0 |
return null; |
114 |
|
} |
115 |
|
} |