1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.webapp;
35
36 import info.magnolia.cms.beans.config.ContentRepository;
37 import info.magnolia.module.InstallContext;
38 import info.magnolia.module.ModuleVersionHandler;
39 import info.magnolia.module.delta.Delta;
40 import info.magnolia.module.delta.DeltaBuilder;
41 import info.magnolia.module.delta.Task;
42 import info.magnolia.module.model.Version;
43
44 import javax.jcr.RepositoryException;
45 import java.util.Collections;
46 import java.util.List;
47
48
49
50
51
52
53
54
55 public class WebappVersionHandler implements ModuleVersionHandler {
56 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(WebappVersionHandler.class);
57
58 public Version getCurrentlyInstalled(InstallContext ctx) {
59 try {
60 final boolean anyContent = ContentRepository.checkIfInitialized();
61 log.info("Content was {}found in the repository, will {}bootstrap web-app.", (anyContent ? "" : "not "), (anyContent ? "not " : ""));
62 if (anyContent) {
63 return Version.UNDEFINED_TO;
64 } else {
65
66 return null;
67 }
68
69 } catch (RepositoryException e) {
70
71 throw new RuntimeException("Couldn't check if repositories were empty: " + e.getMessage(), e);
72 }
73 }
74
75 public List<Delta> getDeltas(InstallContext ctx, Version from) {
76 if (from == null) {
77 final Version version = ctx.getCurrentModuleDefinition().getVersion();
78 return Collections.<Delta>singletonList(new WebappDelta(version));
79 } else if (!from.equals(Version.UNDEFINED_TO)) {
80 throw new IllegalStateException("This is a dummy module. It should not get updated.");
81 } else {
82 return Collections.emptyList();
83 }
84 }
85
86 public Delta getStartupDelta(InstallContext ctx) {
87 return DeltaBuilder.startup(ctx.getCurrentModuleDefinition(), Collections.<Task>emptyList());
88 }
89 }