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 package org.utgenome.shell;
26
27 import java.io.BufferedReader;
28 import java.io.File;
29 import java.io.FileReader;
30 import java.io.FileWriter;
31
32 import org.utgenome.config.OldViewXML;
33 import org.utgenome.config.TrackConfiguration;
34 import org.utgenome.config.UTGBConfig;
35 import org.utgenome.gwt.utgb.client.view.TrackView;
36 import org.utgenome.shell.Create.ScaffoldFileFilter;
37 import org.xerial.lens.XMLLens;
38 import org.xerial.silk.SilkWriter;
39 import org.xerial.util.FileType;
40 import org.xerial.util.StringUtil;
41 import org.xerial.util.log.Logger;
42
43 public class Upgrade extends UTGBShellCommand {
44
45 private static Logger _logger = Logger.getLogger(Upgrade.class);
46
47 @Override
48 public void execute(String[] args) throws Exception {
49
50
51 if (!isInProjectRoot()) {
52
53 File oldConfigXML = getObsolteConfigurationFile();
54 if (oldConfigXML.exists()) {
55 _logger.info(String.format("old-track configuration file %s is found", oldConfigXML));
56
57
58 TrackConfiguration oldConfig = XMLLens.loadXML(TrackConfiguration.class, new BufferedReader(new FileReader(oldConfigXML)));
59 UTGBConfig newConfig = oldConfig.convert();
60 String silk = newConfig.toSilk();
61
62
63 File newConfigFile = new File("config/common.silk");
64 if (!newConfigFile.exists()) {
65 _logger.info("needs upgrade");
66 _logger.info("generating " + newConfigFile);
67 FileWriter fout = new FileWriter(newConfigFile);
68 fout.append(silk);
69 fout.append(StringUtil.newline());
70 fout.flush();
71 fout.close();
72 }
73
74
75 for (String configFile : new String[] { "config/development.silk", "config/production.silk", "config/test.silk" }) {
76 final String targetFile = configFile;
77 Create.createScaffold(newConfig, "./", new ScaffoldFileFilter() {
78 public boolean accept(String logicalPathName) {
79 return logicalPathName.startsWith(targetFile);
80 }
81 });
82 }
83 }
84 }
85
86
87 if (isInProjectRoot()) {
88 _logger.info("converting view files...");
89 File oldViewFolder = new File(getProjectRoot(), "src/main/webapp/view");
90 File[] viewXMLFiles = oldViewFolder.listFiles();
91 if (viewXMLFiles != null) {
92
93
94 File viewFolder = new File(getProjectRoot(), "config/view");
95 viewFolder.mkdirs();
96
97
98 for (File viewXML : viewXMLFiles) {
99 if (FileType.getFileType(viewXML.getName()) != FileType.XML) {
100 _logger.info(String.format("skip %s", viewXML));
101 continue;
102 }
103
104 File newViewFile = new File(viewFolder, FileType.removeFileExt(viewXML.getName()) + ".silk");
105 if (newViewFile.exists()) {
106 _logger.info(String.format("skip convertion from %s to %s: %s exists", viewXML, newViewFile, newViewFile));
107 continue;
108 }
109
110 _logger.info(String.format("generating %s from %s", newViewFile, viewXML));
111 OldViewXML oldView = XMLLens.loadXML(OldViewXML.class, new FileReader(viewXML));
112 TrackView tv = oldView.toTrackView();
113 SilkWriter silk = new SilkWriter(new FileWriter(newViewFile));
114 silk.preamble();
115 silk.toSilk(tv);
116 silk.close();
117 }
118 }
119 }
120
121
122 if (isInProjectRoot()) {
123
124 _logger.info("upgrade pom.xml");
125 UTGBShell.runCommand(globalOption, "repair -y -f pom.xml");
126 }
127
128 _logger.info("upgrade done.");
129 }
130
131 @Override
132 public String getOneLinerDescription() {
133 return "upgrade your UTGB project";
134 }
135
136 @Override
137 public String name() {
138 return "upgrade";
139 }
140
141 }