Search in sources :

Example 1 with CompilationProgress

use of org.eclipse.jdt.core.compiler.CompilationProgress in project Gargoyle by callakrsos.

the class DefaultJavaExecutorTest method referencesPackageCompileTest.

/**
	 * 소스파일에 참고라이브러리를 포함시켜 컴파일하는 테스트
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2017. 3. 7.
	 * @throws InterruptedException
	 */
@Test
public void referencesPackageCompileTest() throws InterruptedException {
    String _srcDir = "C:\\Users\\KYJ\\eclipse\\jee-neon\\workspace\\Algorism\\src\\";
    String _srcSimpleName = "OriginalA";
    String _srcJavaFile = _srcSimpleName + ".java";
    String _compiledFile = _srcSimpleName + ".class";
    String _src = _srcDir + _srcJavaFile;
    String _dst = "c:\\ttt\\";
    File[] classpath = new File[] { new File("C:\\Users\\KYJ\\eclipse\\jee-neon\\workspace\\Algorism\\ojdbc14.jar") };
    JavaCompilerable c = new EclipseJavaCompiler(new File(_src), new File(_dst), classpath) {

        /* (non-Javadoc)
			 * @see com.kyj.fx.voeditor.visual.framework.jdt.compiler.EclipseJavaCompiler#getProgress()
			 */
        @Override
        protected CompilationProgress getProgress() {
            return new CompilationProgress() {

                @Override
                public void begin(int remainingWork) {
                    System.out.println("## Job Remaining Count : " + remainingWork);
                }

                @Override
                public void done() {
                    System.out.println("## Complted...");
                }

                @Override
                public boolean isCanceled() {
                    return false;
                }

                @Override
                public void setTaskName(String name) {
                    System.out.println("## TaskName :  " + name);
                }

                @Override
                public void worked(int workIncrement, int remainingWork) {
                    System.out.println("## working workedCount : " + workIncrement);
                }
            };
        }
    };
    //		c.run();
    //		System.out.println(c.wasCompiled());
    RuntimeJavaRunner r = new RuntimeJavaRunner(new File(_dst), new File(_compiledFile));
    AbstractJavaExecutor defaultJavaExecutor = new AsynchJavaExecutor(c, r) {
    };
    defaultJavaExecutor.execute();
    Thread.sleep(10000);
}
Also used : EclipseJavaCompiler(com.kyj.fx.voeditor.visual.framework.jdt.compiler.EclipseJavaCompiler) File(java.io.File) CompilationProgress(org.eclipse.jdt.core.compiler.CompilationProgress) RuntimeJavaRunner(com.kyj.fx.voeditor.visual.framework.jdt.javaRun.RuntimeJavaRunner) JavaCompilerable(com.kyj.fx.voeditor.visual.framework.jdt.compiler.JavaCompilerable) Test(org.junit.Test)

Example 2 with CompilationProgress

use of org.eclipse.jdt.core.compiler.CompilationProgress in project Gargoyle by callakrsos.

the class EclipseJavaCompiler method run.

/* (non-Javadoc)
	 * @see java.lang.Thread#run()
	 */
@Override
public final void run() {
    String command = getCommand();
    // instantiate your subclass
    CompilationProgress progress = getProgress();
    compiled = BatchCompiler.compile(command, new PrintWriter(out), new PrintWriter(err), progress);
}
Also used : CompilationProgress(org.eclipse.jdt.core.compiler.CompilationProgress) PrintWriter(java.io.PrintWriter)

Example 3 with CompilationProgress

use of org.eclipse.jdt.core.compiler.CompilationProgress in project Gargoyle by callakrsos.

the class DefaultJavaExecutorTest method srcDirBuildTest.

/**
	 * src 디렉토리를 이용한 컴파일 테스트
	 *
	 *  + 비동기 처리 테스트
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2017. 3. 7.
	 * @throws InterruptedException
	 */
@Test
public final void srcDirBuildTest() throws InterruptedException {
    String _srcDir = "C:\\Users\\KYJ\\eclipse\\jee-neon\\workspace\\Algorism";
    String _srcSimpleName = "OriginalA";
    String _srcJavaFile = _srcSimpleName + ".java";
    String _compiledFile = _srcSimpleName + ".class";
    //		String _src = _srcDir + _srcJavaFile;
    String _dst = "c:\\ttt\\";
    File[] classpath = new File[] { new File("C:\\Users\\KYJ\\eclipse\\jee-neon\\workspace\\Algorism\\ojdbc14.jar") };
    //		System.err.println(JavaCompilerable.class.getProtectionDomain().getCodeSource().getLocation());
    JavaCompilerable c = new EclipseJavaCompiler(new File(_srcDir), new File(_dst), classpath) {

        /* (non-Javadoc)
			 * @see com.kyj.fx.voeditor.visual.framework.jdt.compiler.EclipseJavaCompiler#getProgress()
			 */
        @Override
        protected CompilationProgress getProgress() {
            return new CompilationProgress() {

                @Override
                public void begin(int remainingWork) {
                    System.out.println("## Job Remaining Count : " + remainingWork);
                }

                @Override
                public void done() {
                    System.out.println("## Complted...");
                }

                @Override
                public boolean isCanceled() {
                    // TODO Auto-generated method stub
                    return false;
                }

                @Override
                public void setTaskName(String name) {
                    System.out.println("## TaskName :  " + name);
                }

                @Override
                public void worked(int workIncrement, int remainingWork) {
                    System.out.println("## working workedCount : " + workIncrement + " remainingWork : " + remainingWork);
                }
            };
        }
    };
    c.run();
    RuntimeJavaRunner r = new RuntimeJavaRunner(new File(_dst), new File(_compiledFile));
    AbstractJavaExecutor defaultJavaExecutor = new AsynchJavaExecutor(c, r) {
    };
    defaultJavaExecutor.execute();
    Thread.sleep(5000);
}
Also used : EclipseJavaCompiler(com.kyj.fx.voeditor.visual.framework.jdt.compiler.EclipseJavaCompiler) File(java.io.File) CompilationProgress(org.eclipse.jdt.core.compiler.CompilationProgress) RuntimeJavaRunner(com.kyj.fx.voeditor.visual.framework.jdt.javaRun.RuntimeJavaRunner) JavaCompilerable(com.kyj.fx.voeditor.visual.framework.jdt.compiler.JavaCompilerable) Test(org.junit.Test)

Example 4 with CompilationProgress

use of org.eclipse.jdt.core.compiler.CompilationProgress in project Gargoyle by callakrsos.

the class EclipseClasspathJavaCompiler method run.

/* (non-Javadoc)
	 * @see java.lang.Thread#run()
	 */
@Override
public final void run() {
    String command = getCommand();
    // instantiate your subclass
    CompilationProgress progress = getProgress();
    compiled = BatchCompiler.compile(command, new PrintWriter(out), new PrintWriter(err), progress);
}
Also used : CompilationProgress(org.eclipse.jdt.core.compiler.CompilationProgress) PrintWriter(java.io.PrintWriter)

Example 5 with CompilationProgress

use of org.eclipse.jdt.core.compiler.CompilationProgress in project abstools by abstools.

the class JavaJob method generateJavaClassFiles.

/**
 * generates .class files (needs .java files)
 * @param monitor
 *
 * @param absFrontendLocation -where to find the absfrontend
 * @param path - directory with java files
 * @param noWarnings - do not show any compile warnings
 * @throws AbsJobException
 */
private void generateJavaClassFiles(IProgressMonitor monitor, String absFrontendLocation, File path, boolean noWarnings) throws AbsJobException {
    monitor.subTask("Creating class files");
    // args
    String noWarn;
    if (noWarnings) {
        noWarn = "-nowarn";
    } else {
        noWarn = "";
    }
    if (!path.isDirectory() || !path.isAbsolute()) {
        if (debugMode)
            System.err.println("Not a absolute path of a directory: " + path.getAbsolutePath());
        throw new AbsJobException("Path is not an absolute path of a directory");
    }
    String args = "-1.5 " + noWarn + " -classpath " + "\"" + absFrontendLocation + "\"" + " " + "\"" + path.getAbsolutePath() + "\"";
    if (debugMode)
        System.out.println("arguments: " + args);
    // console
    try {
        ConsoleManager.displayConsoleView();
    } catch (PartInitException e) {
        standardExceptionHandling(e);
        throw new AbsJobException("Not able to show console");
    }
    // compile with jdt-BatchCompiler
    CompilationProgress progress = null;
    OutputStream os = javaConsole.getOutputStream(ConsoleManager.MessageType.MESSAGE_ERROR);
    boolean compilationSuccessful = BatchCompiler.compile(args, new PrintWriter(os), new PrintWriter(os), progress);
    if (!compilationSuccessful) {
        throw new AbsJobException("Sorry, there seems to be a bug in the java backend. The generated java " + "files could not be compiled correctly.");
    }
}
Also used : PartInitException(org.eclipse.ui.PartInitException) CompilationProgress(org.eclipse.jdt.core.compiler.CompilationProgress) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Aggregations

CompilationProgress (org.eclipse.jdt.core.compiler.CompilationProgress)5 EclipseJavaCompiler (com.kyj.fx.voeditor.visual.framework.jdt.compiler.EclipseJavaCompiler)2 JavaCompilerable (com.kyj.fx.voeditor.visual.framework.jdt.compiler.JavaCompilerable)2 RuntimeJavaRunner (com.kyj.fx.voeditor.visual.framework.jdt.javaRun.RuntimeJavaRunner)2 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2 Test (org.junit.Test)2 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)1 PartInitException (org.eclipse.ui.PartInitException)1