1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package com.totalchange.osopendata.generator;
23
24 import java.io.File;
25
26 import org.apache.maven.model.Resource;
27 import org.apache.maven.plugin.AbstractMojo;
28 import org.apache.maven.plugin.MojoExecutionException;
29 import org.apache.maven.plugin.MojoFailureException;
30 import org.apache.maven.project.MavenProject;
31
32
33
34
35
36
37 public class PopulateMojo extends AbstractMojo {
38
39
40
41
42 private String codePointDirectory;
43
44
45
46
47
48 private String locatorDirectory;
49
50
51
52
53
54 private String outputDatabase;
55
56
57
58
59
60
61 private String generateInto;
62
63
64
65
66
67
68
69
70 private MavenProject project;
71
72 @Override
73 public void execute() throws MojoExecutionException, MojoFailureException {
74 File dbFile = new File(generateInto + File.separator + outputDatabase);
75
76 getLog().info(
77 "Creating OS OpenData database " + dbFile.getAbsolutePath()
78 + " based upon code point directory "
79 + codePointDirectory + " and locator directory "
80 + locatorDirectory);
81
82 File dbDataFile = new File(dbFile.getAbsolutePath() + ".data");
83 if (!dbDataFile.exists()) {
84 try {
85 dbFile.getParentFile().mkdirs();
86
87 Populate.populate(dbFile.getAbsolutePath(), codePointDirectory,
88 locatorDirectory);
89
90
91 File dbBackupFile = new File(dbFile.getAbsolutePath()
92 + ".backup");
93 dbBackupFile.delete();
94 } catch (Throwable th) {
95 throw new MojoExecutionException(
96 "Failed to create OS OpenData "
97 + "database with error: " + th.getMessage(), th);
98 }
99 } else {
100 getLog().info("Skipped database population as already exists");
101 }
102
103 Resource resource = new Resource();
104 resource.setDirectory(generateInto);
105 project.addResource(resource);
106 }
107 }