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.module.InstallContext;
37 import info.magnolia.module.files.FileExtractionLogger;
38 import info.magnolia.module.files.MD5CheckingFileExtractor;
39 import info.magnolia.module.files.ModuleFileExtractorTransformer;
40
41 import java.io.IOException;
42
43 import javax.jcr.RepositoryException;
44 import javax.jcr.Session;
45
46
47
48
49 public class ModuleFilesExtraction extends AbstractTask {
50
51 public ModuleFilesExtraction() {
52 super("Files extraction", "Extracts module files.");
53 }
54
55 @Override
56 public void execute(final InstallContext ctx) throws TaskExecutionException {
57 final String moduleName = ctx.getCurrentModuleDefinition().getName();
58
59 try {
60 final Session session = ctx.getConfigJCRSession();
61 final MD5CheckingFileExtractor extractor = new MD5CheckingFileExtractor(new InstallContextLogger(ctx), session);
62 extractor.extractFiles(new ModuleFileExtractorTransformer(moduleName));
63 } catch (IOException e) {
64 throw new TaskExecutionException("Could not extract files for module " + ctx.getCurrentModuleDefinition() + ": " + e.getMessage(), e);
65 } catch (RepositoryException e) {
66 throw new TaskExecutionException("Could not extract files for module " + ctx.getCurrentModuleDefinition() + ": " + e.getMessage(), e);
67 }
68 }
69
70 private static class InstallContextLogger implements FileExtractionLogger {
71 private final InstallContext ctx;
72
73 public InstallContextLogger(InstallContext ctx) {
74 this.ctx = ctx;
75 }
76
77 @Override
78 public void error(String message) {
79 ctx.warn(message);
80 }
81 }
82 }