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.File;
28 import java.io.IOException;
29
30 import org.utgenome.config.UTGBConfig;
31 import org.xerial.util.StringUtil;
32 import org.xerial.util.lens.ObjectLens;
33 import org.xerial.util.log.Logger;
34 import org.xerial.util.opt.Argument;
35 import org.xerial.util.opt.Option;
36
37
38
39
40
41
42
43 public class Create extends UTGBShellCommand {
44 private static Logger _logger = Logger.getLogger(Create.class);
45
46 private String lang = "java";
47
48 @Option(symbol = "p", longName = "package", varName = "PACKAGE_NAME", description = "specify the package name, e.g. org.yourdomain.track")
49 private String packageName = null;
50
51 @Argument
52 private String projectName;
53
54 @Option(symbol = "g", longName = "group", varName = "GROUP_NAME", description = "specify the maven group name of this project. default = org.utgenome.track")
55 private String group = "org.utgenome.track";
56
57 public static enum OverwriteMode {
58 INTERACTIVE, YES_TO_ALL, NO_TO_ALL
59 }
60
61 public Create() {
62
63 }
64
65 @Override
66 public void execute(String[] args) throws Exception {
67
68 if (projectName == null)
69 throw new UTGBShellException("No project name is given. See utgb create --help for the usage.");
70
71 for (int i = 0; i < projectName.length(); i++) {
72 if (StringUtil.isWhiteSpace(projectName.substring(i, i + 1))) {
73 System.err.println("White spaces are not allowed in the project name: " + projectName);
74 return;
75 }
76 }
77
78 if (packageName == null)
79 packageName = ObjectLens.getCanonicalParameterName(projectName);
80
81 String outputFolder = globalOption.projectDir;
82 if (outputFolder == null || outputFolder.length() <= 0)
83 outputFolder = projectName;
84 else {
85 if (!outputFolder.endsWith("/"))
86 outputFolder = outputFolder + "/";
87
88 outputFolder = outputFolder + projectName;
89 }
90
91 UTGBConfig config = new UTGBConfig();
92 config.projectName = projectName;
93 config.group = group;
94 config.javaPackage = packageName;
95
96
97 createScaffold(config, outputFolder, new CreateAllScaffoldFileFilter());
98
99 }
100
101 public static interface ScaffoldFileFilter {
102 public boolean accept(String logicalPathName);
103 }
104
105 public static class CreateAllScaffoldFileFilter implements ScaffoldFileFilter {
106 public boolean accept(String pathname) {
107 return true;
108 }
109 }
110
111 public static void createScaffold(UTGBConfig config, String outputFolder, ScaffoldFileFilter generateFileFilter) throws IOException, UTGBShellException {
112 ScaffoldGenerator scaffoldGenerator = new ScaffoldGenerator(outputFolder, generateFileFilter);
113 scaffoldGenerator.createProjectScaffold(config);
114 }
115
116
117
118
119
120
121 public static void mkdirs(File dir) {
122 if (!dir.exists()) {
123 _logger.info("create a directory: " + getPath(dir));
124 dir.mkdirs();
125 }
126 }
127
128 @Override
129 public String name() {
130 return "create";
131 }
132
133 @Override
134 public String getOneLinerDescription() {
135 return "create a new project for implmenting your own track.";
136 }
137
138 }