View Javadoc

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   * @author D.A. Smedes
16   * @version $Id: AdminStore.java,v 1.6 2004/11/11 10:47:45 hippe Exp $
17   */
18  public abstract class AdminStore implements Store {
19  
20    public static final ErrorCode STORE_CONNECTION_FAILURE = new ErrorCode("WCC-00002");
21    public static final ErrorCode AUTHENTICATOR_NOT_FOUND = new ErrorCode("WCC-00003");
22    public static final ErrorCode STORE_MODULE_NO_IN_REPOSITORY = new ErrorCode("WCC-00004");
23  
24    private WorkingContext workingContext = null;
25    private Location location = null;
26  
27    private String moduleName = null;
28  
29    protected Module module = null;
30  
31    public AdminStore(WorkingContext workingContext) {
32  
33      if (workingContext == null) {
34        throw new IllegalArgumentException("Working context cannot be null.");
35      }
36  
37      this.workingContext = workingContext;
38    }
39  
40    public AdminStore(WorkingContext workingContext, String moduleName, Location location) {
41      this(workingContext);
42      this.moduleName = moduleName;
43      this.location = location;
44    }
45  
46    protected final WorkingContext getWorkingContext() {
47      return workingContext;
48    }
49  
50    public final void setLocation(Location location) {
51  
52      if (location == null) {
53        throw new IllegalArgumentException("Location cannot be null.");
54      }
55  
56      this.location = location;
57    }
58  
59    public final Location getLocation() {
60      return location;
61    }
62  
63    public final void update() throws AuthenticationException, VersionControlException {
64  
65      if (moduleName == null || "".equals(moduleName)) {
66        throw new KarmaRuntimeException("Module name for manifest store has not been set (correctly).");
67      }
68  
69      Runner runner = RunnerFactory.getRunner(location);
70  
71      // todo this is a good place to check if the existing directory is from the same cvs location.
72      //
73      if (getModule().getBaseDir().exists()) {
74        runner.update(getModule());
75      } else {
76        runner.checkout(getModule());
77      }
78    }
79  
80    public final void setModuleName(String moduleName) {
81      this.moduleName = moduleName;
82    }
83  
84    public final String getModuleName() {
85      return moduleName;
86    }
87  
88    public final boolean exists() {
89        return Utils.existsInRepository(getModule());
90    }
91  
92    //
93    // inherit-doc
94    //
95    public ErrorCode checkConfiguration() {
96  
97      if (getLocation() == null) {
98        return STORE_CONNECTION_FAILURE;
99      }
100 
101     try {
102       getLocation().connect();
103     } catch (AuthenticationException e) {
104       return STORE_CONNECTION_FAILURE;
105     } catch (LocationException e) {
106       return STORE_CONNECTION_FAILURE;
107     }
108 
109     if (!Utils.existsInRepository(getModule())) {
110       return STORE_MODULE_NO_IN_REPOSITORY;
111     }
112 
113     return null;
114   }
115 }