Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Java compiler #80

Open
NikolayIT opened this issue Aug 22, 2013 · 1 comment
Open

Implement Java compiler #80

NikolayIT opened this issue Aug 22, 2013 · 1 comment

Comments

@NikolayIT
Copy link
Owner

No description provided.

@NikolayIT
Copy link
Owner Author

Old code:

public class JavaCompiler : ICompiler
{
    public void Compile(Uri inputPath, Uri outputPath)
    {
        Uri compilerPath = new Uri(Settings.JavaCompilerPath);

        if (!File.Exists(inputPath.LocalPath))
        {
            throw new CompilerException(string.Format("Java source file not found! Searched in: \"{0}\"",
                inputPath.LocalPath));
        }

        if (!File.Exists(compilerPath.LocalPath))
        {
            throw new CompilerException(string.Format("Java compiler not found! Searched in: \"{0}\"",
                compilerPath.LocalPath));
        }

        ProcessStartInfo processStartInfo =
            new ProcessStartInfo(compilerPath.LocalPath);
        processStartInfo.RedirectStandardError = true;
        processStartInfo.UseShellExecute = false;

        processStartInfo.Arguments += string.Format("\"{0}\"", inputPath.LocalPath);

        string error;
        using (Process process = Process.Start(processStartInfo))
        {
            error = process.StandardError.ReadToEnd();
            process.WaitForExit();
        }

        string generatedOutput = inputPath.LocalPath.Substring(0, 
            inputPath.LocalPath.Length - ".java".Length) + ".class";

        if (string.IsNullOrEmpty(error))
        {
            if (File.Exists(generatedOutput))
            {
                File.Move(generatedOutput, outputPath.LocalPath);
            }
        }
        else
        {
            throw new CompilerException(error);
        }
    }
}

@ghost ghost assigned dininski Dec 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants