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.delta;
35
36 import info.magnolia.cms.util.ClasspathResourcesUtil;
37 import info.magnolia.importexport.BootstrapUtil;
38 import info.magnolia.module.InstallContext;
39
40 import javax.jcr.ImportUUIDBehavior;
41 import javax.jcr.RepositoryException;
42 import java.io.IOException;
43
44
45
46
47
48
49
50 public abstract class BootstrapResourcesTask extends AbstractTask {
51 private final int importUUIDBehavior;
52
53 public BootstrapResourcesTask(String name, String description) {
54 this(name, description, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
55 }
56
57 public BootstrapResourcesTask(String name, String description, int importUUIDBehavior) {
58 super(name, description);
59 this.importUUIDBehavior = importUUIDBehavior;
60 }
61
62
63 @Override
64 public void execute(final InstallContext installContext) throws TaskExecutionException {
65 try {
66 final String[] resourcesToBootstrap = getResourcesToBootstrap(installContext);
67 BootstrapUtil.bootstrap(resourcesToBootstrap, importUUIDBehavior);
68 } catch (IOException e) {
69 throw new TaskExecutionException("Could not bootstrap: " + e.getMessage(), e);
70 } catch (RepositoryException e) {
71 throw new TaskExecutionException("Could not bootstrap: " + e.getMessage(), e);
72 }
73 }
74
75
76
77
78 protected String[] getResourcesToBootstrap(final InstallContext installContext) {
79 String[] resourcesToBootstrap = ClasspathResourcesUtil.findResources(new ClasspathResourcesUtil.Filter() {
80 @Override
81 public boolean accept(final String name) {
82 return acceptResource(installContext, name);
83 }
84 });
85 return resourcesToBootstrap;
86
87 }
88
89
90
91
92 protected boolean acceptResource(final InstallContext installContext, final String resourceName) {
93 return false;
94 }
95 }