-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptManager.cs
More file actions
114 lines (99 loc) · 4.09 KB
/
ScriptManager.cs
File metadata and controls
114 lines (99 loc) · 4.09 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
using System;
using System.Diagnostics;
using System.IO;
namespace SuperJetEngine
{
public static class ScriptManager
{
public static bool CompileJavaFile(string javaFilePath, string outputDirectory)
{
if (!File.Exists(javaFilePath))
throw new FileNotFoundException("Java file not found.", javaFilePath);
string javacPath = Path.Combine(Environment.GetEnvironmentVariable("JAVA_HOME"), "bin", "javac.exe");
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
FileName = javacPath,
Arguments = $"-d \"{outputDirectory}\" \"{javaFilePath}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = new Process { StartInfo = processStartInfo })
{
process.Start();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
if (process.ExitCode == 0)
{
Console.WriteLine("Compilation successful.");
return true;
}
else
{
Console.WriteLine($"Compilation failed:\n{error}");
return false;
}
}
}
public static void AddJavaFile(string sourceDirectory, string javaFileName)
{
string javaFilePath = Path.Combine(sourceDirectory, javaFileName);
string outputDirectory = "compiled_scripts";
if (CompileJavaFile(javaFilePath, outputDirectory))
{
Console.WriteLine($"Java file {javaFileName} added and compiled successfully.");
}
else
{
Console.WriteLine($"Failed to compile Java file {javaFileName}.");
}
}
public static void AddJavaClass(string sourceDirectory, string javaClassName)
{
string javaClassPath = Path.Combine(sourceDirectory, javaClassName);
string outputDirectory = "compiled_scripts";
if(CompileJavaClass(javaClassName, outputDirectory))
{
Console.WriteLine($"Java class {javaClassName} added and compiled successfully.");
}
else
{
Console.WriteLine($"Failed to compile the Java Class {javaClassName}.");
}
}
public static bool CompileJavaClass(string javaClassPath, string outputDirectory)
{
if (!File.Exists(javaClassPath))
throw new FileNotFoundException("Java file not found.", javaClassPath);
string javacPath = Path.Combine(Environment.GetEnvironmentVariable("JAVA_HOME"), "bin", "javac.exe");
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
FileName = javacPath,
Arguments = $"-d \"{outputDirectory}\" \"{javaClassPath}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = new Process { StartInfo = processStartInfo })
{
process.Start();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
if (process.ExitCode == 0)
{
Console.WriteLine("Compilation successful.");
return true;
}
else
{
Console.WriteLine($"Compilation failed:\n{error}");
return false;
}
}
}
}
}