Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

wurstscript / WurstScript / 1198

22 Oct 2019 - 20:22 coverage decreased (-0.04%) to 62.819%
1198

Pull #899

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
fixes
Pull Request #899: Workspace config

16348 of 26024 relevant lines covered (62.82%)

0.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.63
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/RunArgs.java
1
package de.peeeq.wurstscript;
2

3
import com.google.common.collect.Lists;
4
import org.eclipse.jdt.annotation.Nullable;
5

6
import java.io.File;
7
import java.util.Collections;
8
import java.util.List;
9
import java.util.Set;
10
import java.util.function.Consumer;
11
import java.util.stream.Stream;
12

13
public class RunArgs {
14

15

16
    private final String[] args;
17
    private final RunOption optionLua;
18
    private List<String> files = Lists.newArrayList();
1×
19
    private @Nullable String mapFile = null;
1×
20
    private @Nullable String outFile = null;
1×
21
    private @Nullable String workspaceroot = null;
1×
22
    private @Nullable String inputmap = null;
1×
23

24
    private List<RunOption> options = Lists.newArrayList();
1×
25

26
    private List<File> libDirs = Lists.newArrayList();
1×
27
    private RunOption optionHelp;
28
    private RunOption optionOpt;
29
    private RunOption optionInline;
30
    private RunOption optionLocalOptimizations;
31
    private RunOption optionRuntests;
32
    private RunOption optionGui;
33
    private RunOption optionAbout;
34
    private RunOption optionHotdoc;
35
    private RunOption optionShowErrors;
36
    private RunOption optionRunCompileTimeFunctions;
37
    private RunOption optionStacktraces;
38
    private RunOption uncheckedDispatch;
39
    private RunOption optionNodebug;
40
    private RunOption optionInjectCompiletimeObjects;
41
    private RunOption optionExtractImports;
42
    private RunOption optionStartServer;
43
    private RunOption optionLanguageServer;
44
    private RunOption optionNoExtractMapScript;
45
    private RunOption optionFixInstall;
46
    private RunOption optionCopyMap;
47
    private RunOption optionDisablePjass;
48
    private RunOption optionShowVersion;
49
    private RunOption optionMeasureTimes;
50
    private RunOption optionHotStartmap;
51
    private RunOption optionHotReload;
52
    private RunOption optionBuild;
53

54
    public RunArgs with(String... additionalArgs) {
55
        return new RunArgs(Stream.concat(Stream.of(args), Stream.of(additionalArgs))
1×
56
                .toArray(String[]::new));
1×
57
    }
58

59
    private class RunOption {
60

61
        final String name;
62

63
        final String descr;
64
        final @Nullable Consumer<String> argHandler;
65
        boolean isSet;
66
        RunOption(String name, String descr) {
1×
67
            this.name = name;
1×
68
            this.descr = descr;
1×
69
            this.argHandler = null;
1×
70
        }
1×
71
        RunOption(String name, String descr, Consumer<String> argHandler2) {
1×
72
            this.name = name;
1×
73
            this.descr = descr;
1×
74
            this.argHandler = argHandler2;
1×
75
        }
1×
76

77

78
    }
79
    public static RunArgs defaults() {
80
        return new RunArgs();
1×
81
    }
82

83
    public RunArgs(String... args) {
1×
84
        this.args = args;
1×
85
        // interpreter
86
        optionRuntests = addOption("runtests", "Run all test functions found in the scripts.");
1×
87
        optionRunCompileTimeFunctions = addOption("runcompiletimefunctions", "Run all compiletime functions found in the scripts.");
1×
88
        optionInjectCompiletimeObjects = addOption("injectobjects", "Injects the objects generated by compiletime functions into the map.");
1×
89
        // optimization
90
        optionOpt = addOption("opt", "Enables identifier name compression and whitespace removal.");
1×
91
        optionInline = addOption("inline", "Enables function inlining.");
1×
92
        optionLocalOptimizations = addOption("localOptimizations", "Enables local optimizations (cpu and ram extensive, recommended for release)");
1×
93
        // debug options
94
        optionStacktraces = addOption("stacktraces", "Generate stacktrace information in the script (useful for debugging).");
1×
95
        optionNodebug = addOption("nodebug", "Remove all error messages from the script. (Not recommended)");
1×
96
        uncheckedDispatch = addOption("uncheckedDispatch", "(dangerous) Removes checks from method-dispatch code. With unchecked dispatch "
1×
97
                + "some programming errors like null-pointer-dereferences or accessing of destroyed objects can no longer be detected. "
98
                + "It is strongly recommended to not use this option, but it can give some performance benefits.");
99
        optionMeasureTimes = addOption("measure", "Measure how long each step of the translation process takes.");
1×
100
        // tools
101
        optionAbout = addOption("-about", "Show the 'about' window.");
1×
102
        optionFixInstall = addOption("-fixInstallation", "Checks your wc3 installation and applies compatibility fixes");
1×
103
        optionCopyMap = addOption("-copyMap", "copies map");
1×
104
        optionStartServer = addOption("-startServer", "Starts the compilation server.");
1×
105
        optionHotdoc = addOption("-hotdoc", "Generate hotdoc html documentation.");
1×
106
        optionShowErrors = addOption("-showerrors", "(currently not implemented.) Show errors generated by last compile.");
1×
107
        optionExtractImports = addOptionWithArg("-extractImports", "Extract all files from a map into a folder next to the mapp.", arg -> mapFile = arg);
1×
108
        optionShowVersion = addOption("-version", "Shows the version of the compiler");
1×
109

110
        // other
111
        optionNoExtractMapScript = addOption("noExtractMapScript", "Do not extract the map script from the map and use the one from the Wurst folder instead.");
1×
112
        optionGui = addOption("gui", "Show a graphical user interface (progress bar and error window).");
1×
113
        addOptionWithArg("lib", "The next argument should be a library folder which is lazily added to the build.", arg -> libDirs.add(new File(arg)));
1×
114
        addOptionWithArg("out", "Outputs the compiled script to this file.", arg -> outFile = arg);
1×
115

116
        optionLanguageServer = addOption("languageServer", "Starts a language server which can be used by editors to get services "
1×
117
                + "like code completion, validations, and find declaration. The communication to the language server is via standard input output.");
118

119
        optionHelp = addOption("help", "Prints this help message.");
1×
120
        optionDisablePjass = addOption("noPJass", "Disables PJass checks for the generated code.");
1×
121
        optionHotStartmap = addOption("hotstart", "Uses Jass Hot Code Reload (JHCR) to start the map.");
1×
122
        optionHotReload = addOption("hotreload", "Reloads the mapscript after running the map with Jass Hot Code Reload (JHCR).");
1×
123

124
        optionBuild = addOption("build", "Builds an output map from the input map and library directories.");
1×
125
        addOptionWithArg("workspaceroot", "The next argument should be the root folder of the project to build.", arg -> workspaceroot = arg);
1×
126
        addOptionWithArg("inputmap", "The next argument should be the input map.", arg -> inputmap = arg);
1×
127
        optionLua = addOption("lua", "Choose Lua as the compilation target.");
1×
128

129

130
        nextArg:
131
        for (int i = 0; i < args.length; i++) {
1×
132
            String a = args[i];
1×
133
            if (a.startsWith("-")) {
1×
134
                for (RunOption o : options) {
1×
135
                    if (("-" + o.name).equals(a)) {
1×
136
                        Consumer<String> argHandler = o.argHandler;
1×
137
                        if (argHandler != null) {
1×
138
                            i++;
1×
139
                            argHandler.accept(args[i]);
1×
140
                        }
141
                        o.isSet = true;
1×
142
                        continue nextArg;
1×
143
                    } else if ((o.argHandler != null && isDoubleArg(a, o))) {
1×
UNCOV
144
                        continue nextArg;
!
145
                    }
146
                }
1×
UNCOV
147
                throw new RuntimeException("Unknown option: " + a);
!
148
            } else {
149
                files.add(a);
!
150
                if (a.endsWith(".w3x") || a.endsWith(".w3m")) {
!
UNCOV
151
                    mapFile = a;
!
152
                }
153
            }
154
        }
155

156
        if (optionHelp.isSet) {
1×
UNCOV
157
            printHelpAndExit();
!
158
        }
159
    }
1×
160

161
    private boolean isDoubleArg(String arg, RunOption option) {
162
        return (arg.contains(" ") && ("-" + option.name).equals(arg.substring(0, arg.indexOf(" "))));
1×
163
    }
164

165
    private RunOption addOption(String name, String descr) {
166
        RunOption opt = new RunOption(name, descr);
1×
167
        options.add(opt);
1×
168
        return opt;
1×
169
    }
170

171
    private RunOption addOptionWithArg(String name, String descr, Consumer<String> argHandler) {
172
        RunOption opt = new RunOption(name, descr, argHandler);
1×
173
        options.add(opt);
1×
174
        return opt;
1×
175
    }
176

177
    public RunArgs(List<String> runArgs) {
178
        this(runArgs.toArray(new String[runArgs.size()]));
!
UNCOV
179
    }
!
180

181
    public void printHelpAndExit() {
182
        System.out.println("Usage: ");
!
183
        System.out.println("wurst <options> <files>");
!
184
        System.out.println();
!
185
        System.out.println("Example: wurst -opt common.j Blizzard.j myMap.w3x");
!
186
        System.out.println("Compiles the given map with the two script files and optimizations enabled.");
!
187
        System.out.println();
!
188
        System.out.println("Options:");
!
189
        System.out.println();
!
190
        for (RunOption opt : options) {
!
191
            System.out.println("-" + opt.name);
!
192
            System.out.println("        " + opt.descr);
!
193
            System.out.println();
!
194
        }
!
UNCOV
195
    }
!
196

197
    public List<String> getFiles() {
UNCOV
198
        return files;
!
199
    }
200

201
    public boolean isOptimize() {
202
        return optionOpt.isSet;
1×
203
    }
204

205
    public boolean isGui() {
UNCOV
206
        return optionGui.isSet;
!
207
    }
208

209
    public @Nullable String getMapFile() {
UNCOV
210
        return mapFile;
!
211
    }
212

213
    public void setMapFile(String file) {
214
        mapFile = file;
!
UNCOV
215
    }
!
216

217
    public @Nullable String getOutFile() {
UNCOV
218
        return outFile;
!
219
    }
220

221
    public boolean showAbout() {
UNCOV
222
        return optionAbout.isSet;
!
223
    }
224

225
    public boolean isFixInstall() {
UNCOV
226
        return optionFixInstall.isSet;
!
227
    }
228

229
    public boolean isStartServer() {
UNCOV
230
        return optionStartServer.isSet;
!
231
    }
232

233
    public boolean showLastErrors() {
UNCOV
234
        return optionShowErrors.isSet;
!
235
    }
236

237
    public boolean isInline() {
238
        return optionInline.isSet;
1×
239
    }
240

241
    public boolean runCompiletimeFunctions() {
242
        return optionRunCompileTimeFunctions.isSet;
1×
243
    }
244

245

246
    public boolean createHotDoc() {
UNCOV
247
        return optionHotdoc.isSet;
!
248
    }
249

250
    public boolean isNullsetting() {
251
        return true;
1×
252
    }
253

254
    public boolean isLocalOptimizations() {
255
        return optionLocalOptimizations.isSet;
1×
256
    }
257

258
    public boolean isIncludeStacktraces() {
259
        return optionStacktraces.isSet;
1×
260
    }
261

262
    public boolean isNoDebugMessages() {
263
        return optionNodebug.isSet;
1×
264
    }
265

266
    public boolean isInjectObjects() {
267
        return !isHotReload() && optionInjectCompiletimeObjects.isSet;
1×
268
    }
269

270
    public List<File> getAdditionalLibDirs() {
271
        return Collections.unmodifiableList(libDirs);
1×
272
    }
273

274
    public void addLibs(Set<String> dependencies) {
275
        for (String dep : dependencies) {
1×
276
            libDirs.add(new File(dep));
1×
277
        }
1×
278
    }
1×
279

280
    public void addLibDirs(Set<File> dependencies) {
281
        libDirs.addAll(dependencies);
1×
282
    }
1×
283

284
    public boolean showHelp() {
UNCOV
285
        return optionHelp.isSet;
!
286
    }
287

288
    public boolean isExtractImports() {
UNCOV
289
        return optionExtractImports.isSet;
!
290
    }
291

292
    public boolean isShowVersion() {
UNCOV
293
        return optionShowVersion.isSet;
!
294
    }
295

296
    public boolean isUncheckedDispatch() {
297
        return uncheckedDispatch.isSet;
1×
298
    }
299

300
    public boolean isLanguageServer() {
UNCOV
301
        return optionLanguageServer.isSet;
!
302
    }
303

304
    public boolean isNoExtractMapScript() {
UNCOV
305
        return optionNoExtractMapScript.isSet;
!
306
    }
307

308
    public boolean isCopyMap() {
UNCOV
309
        return optionCopyMap.isSet;
!
310
    }
311

312
    public boolean isDisablePjass() {
UNCOV
313
        return optionDisablePjass.isSet;
!
314
    }
315

316
    public boolean isRunTests() {
UNCOV
317
        return optionRuntests.isSet;
!
318
    }
319

320
    public boolean isMeasureTimes() {
UNCOV
321
        return optionMeasureTimes.isSet;
!
322
    }
323

324
    public boolean isHotStartmap() {
325
        return optionHotStartmap.isSet;
1×
326
    }
327

328
    public boolean isHotReload() {
329
        return optionHotReload.isSet;
1×
330
    }
331

332
    public boolean isBuild() {
UNCOV
333
        return optionBuild.isSet;
!
334
    }
335

336
    public String getWorkspaceroot() {
UNCOV
337
        return workspaceroot;
!
338
    }
339

340
    public String getInputmap() {
UNCOV
341
        return inputmap;
!
342
    }
343

344
    public boolean isLua() {
345
        return optionLua.isSet;
1×
346
    }
347

348

349
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc