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 public class WebappVersionHandler implements ModuleVersionHandler {
54 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(WebappVersionHandler.class);
55
56 public Version getCurrentlyInstalled(InstallContext ctx) {
57 try {
58 final boolean anyContent = ContentRepository.checkIfInitialized();
59 log.info("Content was {}found in the repository, will {}bootstrap web-app.", (anyContent ? "" : "not "), (anyContent ? "not " : ""));
60 if (anyContent) {
61 return Version.UNDEFINED_TO;
62 } else {
63
64 return null;
65 }
66
67 } catch (RepositoryException e) {
68
69 throw new RuntimeException("Couldn't check if repositories were empty: " + e.getMessage(), e);
70 }
71 }
72
73 public List<Delta> getDeltas(InstallContext ctx, Version from) {
74 if (from == null) {
75 final Version version = ctx.getCurrentModuleDefinition().getVersion();
76 return Collections.<Delta>singletonList(new WebappDelta(version));
77 } else if (!from.equals(Version.UNDEFINED_TO)) {
78 throw new IllegalStateException("This is a dummy module. It should not get updated.");
79 } else {
80 return Collections.emptyList();
81 }
82 }
83
84 public Delta getStartupDelta(InstallContext ctx) {
85 return DeltaBuilder.startup(ctx.getCurrentModuleDefinition(), Collections.<Task>emptyList());
86 }
87 }