• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wurstscript / WurstScript / 249

03 Mar 2024 01:51PM UTC coverage: 62.279% (-0.03%) from 62.309%
249

push

circleci

Frotty
fix map script caching

17278 of 27743 relevant lines covered (62.28%)

0.62 hits per line

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

0.0
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/BuildMap.java
1
package de.peeeq.wurstio.languageserver.requests;
2

3
import config.WurstProjectConfig;
4
import config.WurstProjectConfigData;
5
import de.peeeq.wurstio.gui.WurstGuiImpl;
6
import de.peeeq.wurstio.languageserver.ModelManager;
7
import de.peeeq.wurstio.languageserver.WFile;
8
import de.peeeq.wurstio.languageserver.WurstLanguageServer;
9
import de.peeeq.wurstio.mpq.MpqEditor;
10
import de.peeeq.wurstio.mpq.MpqEditorFactory;
11
import de.peeeq.wurstscript.WLogger;
12
import de.peeeq.wurstscript.attributes.CompileError;
13
import de.peeeq.wurstscript.gui.WurstGui;
14
import org.eclipse.lsp4j.MessageType;
15

16
import java.io.File;
17
import java.io.IOException;
18
import java.util.List;
19
import java.util.Optional;
20

21
import static de.peeeq.wurstio.languageserver.ProjectConfigBuilder.FILE_NAME;
22

23
/**
24
 * Created by peter on 16.05.16.
25
 */
26
public class BuildMap extends MapRequest {
27

28
    public BuildMap(WurstLanguageServer languageServer, WFile workspaceRoot, Optional<String> wc3Path, Optional<File> map,
29
                    List<String> compileArgs) {
30
        super(languageServer, map, compileArgs, workspaceRoot, wc3Path);
×
31
    }
×
32

33
    @Override
34
    public Object execute(ModelManager modelManager) throws IOException {
35
        if (modelManager.hasErrors()) {
×
36
            throw new RequestFailedException(MessageType.Error, "Fix errors in your code before building a release.\n" + modelManager.getFirstErrorDescription());
×
37
        }
38

39
        WurstProjectConfigData projectConfig = WurstProjectConfig.INSTANCE.loadProject(workspaceRoot.getFile().toPath().resolve(FILE_NAME));
×
40
        if (projectConfig == null) {
×
41
            throw new RequestFailedException(MessageType.Error, FILE_NAME + " file doesn't exist or is invalid. " +
×
42
                "Please install your project using grill or the wurst setup tool.");
43
        }
44

45
        WLogger.info("buildMap " + map + " " + compileArgs);
×
46
        WurstGui gui = new WurstGuiImpl(workspaceRoot.getFile().getAbsolutePath());
×
47
        try {
48
            if (!map.isPresent()) {
×
49
                throw new RequestFailedException(MessageType.Error, "Map is null");
×
50
            }
51
            if (!map.get().exists()) {
×
52
                throw new RequestFailedException(MessageType.Error, map.get().getAbsolutePath() + " does not exist.");
×
53
            }
54

55
            MapRequest.mapLastModified = map.get().lastModified();
×
56
            MapRequest.mapPath = map.get().getAbsolutePath();
×
57

58
            gui.sendProgress("Copying map");
×
59

60
            // first we copy in same location to ensure validity
61
            File buildDir = getBuildDir();
×
62
            String fileName = projectConfig.getBuildMapData().getFileName();
×
63
            Optional<File> targetMap = Optional.of(
×
64
                new File(buildDir, fileName.isEmpty() ? projectConfig.getProjectName() + ".w3x" : fileName + ".w3x"));
×
65
            CompilationResult result = compileScript(modelManager, gui, targetMap, projectConfig, buildDir, true);
×
66

67
            injectMapData(gui, targetMap, result);
×
68

69
            //noinspection EmptyTryBlock
70
            try(MpqEditor ignored = MpqEditorFactory.getEditor(targetMap)) {
×
71
                // Just finalization
72
            }
×
73

74
            gui.sendProgress("Done.");
×
75
        } catch (CompileError e) {
×
76
            WLogger.info(e);
×
77
            throw new RequestFailedException(MessageType.Error, "A compilation error occurred when building the map:\n" + e);
×
78
        } catch (Exception e) {
×
79
            WLogger.warning("Exception occurred", e);
×
80
            throw new RequestFailedException(MessageType.Error, "An exception was thrown when building the map:\n" + e);
×
81
        } finally {
82
            if (gui.getErrorCount() == 0) {
×
83
                gui.sendFinished();
×
84
            }
85
        }
86
        return "ok"; // TODO
×
87
    }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc