Example #1
0
 public CppCompiler(string code, IExecutionProperties execProps, ICompilerProperties compProps,
                    string[] imports = null)
 {
     SourceCode         = code;
     ExecuteProperties  = execProps;
     CompilerProperties = compProps;
 }
Example #2
0
        /// <summary>
        ///     Load javac.exe and run compilation from arguments
        /// </summary>
        /// <param name="javacPathName">Path to javac.exe (Program Files\java\jdk\bin\javac.exe)</param>
        /// <param name="javaFilePathName">Source code file name</param>
        /// <param name="properties">Compilation properties</param>
        /// <param name="commandLineOptions">Any compiler options</param>
        public static async Task <string> CompileJava(string javacPathName, string javaFilePathName,
                                                      ICompilerProperties properties, string commandLineOptions = "")
        {
            var startInfo = new ProcessStartInfo {
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                FileName    = javacPathName,
                WindowStyle = ProcessWindowStyle.Hidden,
                Arguments   = commandLineOptions + " " + javaFilePathName
            };

            using (var javacProcess = Process.Start(startInfo)) {
                if (javacProcess == null)
                {
                    throw new CompileException("javac.exe could not start!");
                }
                bool graceful = javacProcess.WaitForExit((int)properties.Timeout);

                if (graceful)
                {
                    string error = await javacProcess.StandardError.ReadToEndAsync();

                    if (!string.IsNullOrWhiteSpace(error))
                    {
                        throw new CompileException(error);
                    }
                    string output = await javacProcess.StandardOutput.ReadToEndAsync();

                    return(output);
                }
                throw new CompileException("The compilation took longer than expected!");
            }
        }
Example #3
0
 public LuaCompiler(string code, IExecutionProperties execProps, ICompilerProperties compProps,
                    IGlobals globals = null)
 {
     SourceCode         = code;
     ExecuteProperties  = execProps;
     CompilerProperties = compProps;
     Globals            = globals;
 }
Example #4
0
 public PyCompiler(string code, IExecutionProperties eProps, ICompilerProperties cProps,
                   string libSearchPath = null, IGlobals globals = null)
 {
     SourceCode         = code;
     CompilerProperties = cProps;
     ExecuteProperties  = eProps;
     LibSearchPath      = libSearchPath;
     Globals            = globals;
 }
Example #5
0
 public Properties(Language language, string code,
                   string[] imports             = null,
                   string jdkPath               = null,
                   string pyPath                = null,
                   IExecutionProperties exProps = null,
                   ICompilerProperties comProps = null,
                   IGlobals globals             = null)
 {
     Language           = language;
     Code               = code;
     Imports            = imports;
     JdkPath            = jdkPath;
     PySearchPath       = pyPath;
     ExecuteProperties  = exProps;
     CompilerProperties = comProps;
     Globals            = globals;
 }
Example #6
0
        public VbCompiler(string code, IExecutionProperties execProps, ICompilerProperties compProps,
                          string[] imports = null)
        {
            SourceCode         = code;
            ExecuteProperties  = execProps;
            CompilerProperties = compProps;
            if (imports == null)
            {
                //TODO: Load references for VB (now: C#)
                //LoadReferences();
            }
            else
            {
                Imports = imports;
            }

            Create();
        }
Example #7
0
        public CSharpCompiler(string code, IExecutionProperties execProps, ICompilerProperties compProps,
                              string[] imports = null, IGlobals globals = null)
        {
            SourceCode         = code;
            ExecuteProperties  = execProps;
            CompilerProperties = compProps;
            if (imports == null || !imports.Any())
            {
                LoadReferences();
            }
            else
            {
                Imports = imports;
            }

            Globals = globals ?? new Globals(new StringBuilder());
            Create();
        }
Example #8
0
        public JavaCompiler(string code, IExecutionProperties execProps, ICompilerProperties compProps,
                            string jdkPath = null)
        {
            SourceCode         = code;
            ExecuteProperties  = execProps;
            CompilerProperties = compProps;

            if (string.IsNullOrWhiteSpace(jdkPath) || !Directory.Exists(jdkPath))
            {
                //Search for JDK if jdkPath is invalid directory
                FindJdk();
            }
            else
            {
                //Use JDK Path parameter
                JdkPath = jdkPath;
            }
        }