-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.java
More file actions
133 lines (114 loc) · 5.04 KB
/
Build.java
File metadata and controls
133 lines (114 loc) · 5.04 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.*;
import java.util.List;
import java.util.ArrayList;
public class Build {
public static void main(String[] args) {
boolean showProgressBar = false;
for (String arg : args) {
if (arg.equals("-p")) {
showProgressBar = true;
break;
}
}
String[] files = {
"TraditionalCiphers/CaesarCipher.java",
"TraditionalCiphers/VigenereCipher.java",
"TraditionalCiphers/PlayfairCipher.java",
"TraditionalCiphers/HillCipher.java",
"ModernCiphers/CipherTools/CipherToolkit.java",
"ModernCiphers/DES/DESKeygen.java",
"ModernCiphers/DES/DESEncryption.java",
"ModernCiphers/RC4/KeyScheduler.java",
"ModernCiphers/RC4/PseudoRandomGenerator.java",
"ModernCiphers/RC4/RC4Encryption.java",
"ModernCiphers/RC4/RC4Decryption.java",
"ModernCiphers/AES/AESKeyExpansion.java",
"ModernCiphers/AES/AESEncryption.java",
"SimpleSocket/SimpleServer.java",
"SimpleSocket/SimpleClient.java",
"AsymmetricCiphers/HelperTools/HelperTools.java",
"AsymmetricCiphers/HelperTools/ECCPoint.java",
"AsymmetricCiphers/RSA/RSAClient.java",
"AsymmetricCiphers/RSA/RSAServer.java",
"AsymmetricCiphers/Elgamal/ElgamalServer.java",
"AsymmetricCiphers/Elgamal/ElgamalClient.java",
"AsymmetricCiphers/DiffieHellman/DiffieHellmanServer.java",
"AsymmetricCiphers/DiffieHellman/DiffieHellmanClient.java",
"AsymmetricCiphers/DiffieMITM/DiffieMITMServer.java",
"AsymmetricCiphers/DiffieMITM/DiffieMITMClientA.java",
"AsymmetricCiphers/DiffieMITM/DiffieMITMClientB.java",
"AsymmetricCiphers/ECCElgamal/ECCElgamalServer.java",
"AsymmetricCiphers/ECCElgamal/ECCElgamalClient.java"
};
System.out.println("Starting Compilation...\n");
int successCount = 0;
int failureCount = 0;
int totalFiles = files.length;
int lastPrintedProgress = 0;
// Use ExecutorService to compile files in parallel
ExecutorService executorService = Executors.newFixedThreadPool(4); // Use 4 threads (can adjust based on system)
List<Future<Boolean>> results = new ArrayList<>();
for (String file : files) {
// Submit compilation task to ExecutorService
results.add(executorService.submit(() -> compileFile(file)));
}
// Wait for all tasks to complete
for (int i = 0; i < results.size(); i++) {
try {
boolean success = results.get(i).get(); // Get the result (blocking until done)
String file = files[i];
if (success) {
System.out.println("[+] Compiled \"" + file + "\" successfully.");
successCount++;
} else {
System.out.println("[-] Failed to compile \"" + file + "\".");
failureCount++;
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
failureCount++;
}
// Update Progress Bar if flag is set
if (showProgressBar) {
int progress = (int) Math.round(((i + 1) * 100.0) / totalFiles);
if (progress >= lastPrintedProgress + 10) {
lastPrintedProgress = progress;
printProgressBar(progress);
}
}
}
executorService.shutdown(); // Shutdown the ExecutorService
System.out.println("\nCompilation Summary:");
System.out.println("✔ " + successCount + " files compiled successfully.");
System.out.println("❌ " + failureCount + " files failed to compile.");
System.out.println();
}
private static boolean compileFile(String file) {
try {
ProcessBuilder builder = new ProcessBuilder("javac", file);
Process process = builder.start();
int exitCode = process.waitFor();
if (exitCode == 0) {
return true;
} else {
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while ((line = errorReader.readLine()) != null) {
System.out.println(" > " + line);
}
return false;
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
return false;
}
}
private static void printProgressBar(int progress) {
int barLength = 30;
int filled = (progress * barLength) / 100;
System.out.print("\r[" + "=".repeat(filled) + " ".repeat(barLength - filled) + "] " + progress + "%\n");
}
}