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

wurstscript / WurstScript / 187

pending completion
187

push

circleci

Update pjass to detect functions with too many parameters

17138 of 27007 relevant lines covered (63.46%)

0.63 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/compilationserver/WurstServer.java
1
package de.peeeq.wurstio.compilationserver;
2

3
import de.peeeq.wurstio.Main;
4
import de.peeeq.wurstscript.WLogger;
5
import org.eclipse.jdt.annotation.Nullable;
6

7
import javax.swing.*;
8
import java.io.BufferedReader;
9
import java.io.IOException;
10
import java.io.InputStreamReader;
11
import java.io.PrintWriter;
12
import java.net.InetAddress;
13
import java.net.ServerSocket;
14
import java.net.Socket;
15
import java.net.SocketTimeoutException;
16
import java.util.ArrayList;
17
import java.util.List;
18
import java.util.function.Consumer;
19

20
public class WurstServer {
×
21
    private static final int portNumber = 27425;
22

23
    private volatile boolean stopped;
24
    private Consumer<String> printer = System.out::println;
×
25
    private @Nullable ServerSocket serverSocket;
26

27
    public void start() {
28
        try (ServerSocket serverSocket = new ServerSocket(portNumber, 1, InetAddress.getLoopbackAddress())) {
×
29
            this.serverSocket = serverSocket;
×
30
            println("Server started.");
×
31
            while (!stopped) {
×
32
                handleRequest(serverSocket);
×
33
                // clean up after request
34
                System.gc();
×
35
            }
36
            println("Server stopped.");
×
37
        } catch (IOException e) {
×
38
            println("Server had a problem: " + e.getMessage());
×
39
            WLogger.severe(e);
×
40
        } finally {
41
            System.out.println("end start #################");
×
42
        }
43
    }
×
44

45
    public void startInNewThread() {
46
        new Thread(this::start).start();
×
47
    }
×
48

49
    private void println(String string) {
50
        printer.accept(string);
×
51
    }
×
52

53
    public void stop() {
54
        stopped = true;
×
55
        ServerSocket socket = serverSocket;
×
56
        if (socket != null) {
×
57
            try {
58
                socket.close();
×
59
            } catch (IOException e) {
×
60
                // ignore
61
            }
×
62
        }
63
    }
×
64

65
    private void handleRequest(ServerSocket sock) {
66
        try (Socket s = sock.accept();
×
67
             PrintWriter out = new PrintWriter(s.getOutputStream(), true);
×
68
             BufferedReader in = new BufferedReader(new InputStreamReader(
×
69
                     s.getInputStream()))) {
×
70
            println("Server accepted compilation request");
×
71
            String inputLine;
72
            final List<String> args = new ArrayList<>();
×
73
            while ((inputLine = in.readLine()) != null) {
×
74
                if (inputLine.equals("<<<<")) {
×
75
                    break;
×
76
                }
77
                args.add(inputLine);
×
78
            }
79
            println(args.toString());
×
80
            long time = System.currentTimeMillis();
×
81
            if (args.contains("-stopServer")) {
×
82
                stop();
×
83
                return;
×
84
            }
85
            wurstMain(args);
×
86
            println("Server finished compilation in " + (System.currentTimeMillis() - time) + "ms");
×
87

88
            out.println("ok");
×
89
        } catch (SocketTimeoutException e) {
×
90
            // expected exception
91
        } catch (IOException e) {
×
92
            println("Error in server: " + e.getMessage());
×
93
            WLogger.severe(e);
×
94
        }
×
95
    }
×
96

97
    private void wurstMain(final List<String> args) {
98
        String[] array = args.toArray(new String[0]);
×
99
        Main.main(array);
×
100
    }
×
101

102

103
    public static void startServer() {
104
        // don't know why this is needed ...
105
        SwingUtilities.invokeLater(() -> {
×
106
        });
×
107

108
        WurstServer s = new WurstServer();
×
109
        s.start();
×
110
    }
×
111

112
    public static void main(String[] args) {
113
        startServer();
×
114
    }
×
115

116
    public void setPrinter(Consumer<String> printer) {
117
        this.printer = printer;
×
118
    }
×
119
}
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