Search in sources :

Example 1 with BuildContext

use of org.eclipse.jdt.core.compiler.BuildContext in project xtext-eclipse by eclipse.

the class DebugSourceInstallingCompilationParticipant method buildFinished.

@Override
public void buildFinished(IJavaProject project) {
    StoppedTask task = Stopwatches.forTask("DebugSourceInstallingCompilationParticipant.install");
    try {
        task.start();
        super.buildFinished(project);
        if (files == null)
            return;
        for (BuildContext ctx : files) {
            try {
                IFile generatedJavaFile = ctx.getFile();
                // This may fail if there is no trace file.
                IEclipseTrace traceToSource = traceInformation.getTraceToSource(generatedJavaFile);
                if (traceToSource == null) {
                    continue;
                }
                AbstractTraceRegion rootTraceRegion = findRootTraceRegion(traceToSource);
                if (rootTraceRegion == null)
                    continue;
                SourceRelativeURI dslSourceFile = rootTraceRegion.getAssociatedSrcRelativePath();
                // OutputConfigurations are only available for folders targeted by Xtext's code generation.
                OutputConfiguration outputConfiguration = findOutputConfiguration(dslSourceFile, generatedJavaFile);
                if (outputConfiguration == null)
                    continue;
                IJavaElement element = JavaCore.create(generatedJavaFile);
                if (element == null)
                    continue;
                deleteTaskMarkers(generatedJavaFile);
                markerReflector.reflectErrorMarkerInSource(generatedJavaFile, traceToSource);
                ITraceToBytecodeInstaller installer = getInstaller(outputConfiguration);
                installer.setTrace(generatedJavaFile.getName(), rootTraceRegion);
                for (IFile javaClassFile : findGeneratedJavaClassFiles(element)) {
                    InputStream contents = javaClassFile.getContents();
                    try {
                        byte[] byteCode = installer.installTrace(ByteStreams.toByteArray(contents));
                        if (byteCode != null) {
                            javaClassFile.setContents(new ByteArrayInputStream(byteCode), 0, null);
                        } else {
                            // we need to touch the class file to do a respin of the build
                            // otherwise a needsRebuild request is ignored since no IResourceDelta is available
                            javaClassFile.touch(null);
                        }
                    } finally {
                        contents.close();
                    }
                }
            } catch (Exception e) {
                String msg = "Could not process %s to install source information: %s";
                log.error(String.format(msg, ctx.getFile().getFullPath().toString(), e.getMessage()), e);
            }
        }
    } finally {
        files = null;
        task.stop();
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StoppedTask(org.eclipse.xtext.util.internal.Stopwatches.StoppedTask) CoreException(org.eclipse.core.runtime.CoreException) ITraceToBytecodeInstaller(org.eclipse.xtext.generator.trace.ITraceToBytecodeInstaller) BuildContext(org.eclipse.jdt.core.compiler.BuildContext) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 2 with BuildContext

use of org.eclipse.jdt.core.compiler.BuildContext in project jbosstools-hibernate by jbosstools.

the class HQLExpressionCompilerParticipant method buildStarting.

public void buildStarting(BuildContext[] files, boolean isBatch) {
    for (int i = 0; i < files.length; i++) {
        BuildContext context = files[i];
        ConsoleConfiguration consoleConfiguration = getConsoleConfiguration(ProjectUtils.findJavaProject(context.getFile().getProject().getName()));
        if (consoleConfiguration != null && consoleConfiguration.isSessionFactoryCreated()) {
            ASTParser parser = ASTParser.newParser(AST.JLS9);
            parser.setKind(ASTParser.K_COMPILATION_UNIT);
            parser.setSource(context.getContents());
            parser.setResolveBindings(false);
            ASTNode node = parser.createAST(null);
            CompilationUnit cu = null;
            if (node instanceof CompilationUnit) {
                cu = (CompilationUnit) node;
            }
            HQLDetector hqlDetector = new HQLDetector(cu, consoleConfiguration, context.getFile());
            node.accept(hqlDetector);
            if (!hqlDetector.getProblems().isEmpty()) {
                CategorizedProblem[] toArray = hqlDetector.getProblems().toArray(new CategorizedProblem[0]);
                context.recordNewProblems(toArray);
            }
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) BuildContext(org.eclipse.jdt.core.compiler.BuildContext) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ASTParser(org.eclipse.jdt.core.dom.ASTParser)

Example 3 with BuildContext

use of org.eclipse.jdt.core.compiler.BuildContext in project tdi-studio-se by Talend.

the class JavaCompilationParticipant method processAnnotations.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.jdt.core.compiler.CompilationParticipant#processAnnotations(org.eclipse.jdt.core.compiler.BuildContext
     * [])
     */
@Override
public void processAnnotations(final BuildContext[] files) {
    super.processAnnotations(files);
    Job routineJob = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    Messages.getString("JavaCompilationParticipant.validateRoutine")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            boolean routineToUpdate = false;
            List<IRepositoryViewObject> routineObjectList = null;
            for (BuildContext context : files) {
                String filePath = (context.getFile().getProjectRelativePath()).toString();
                if (isRoutineFile(filePath)) {
                    if (!routineToUpdate) {
                        IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
                        try {
                            routineObjectList = factory.getAll(ERepositoryObjectType.ROUTINES, false);
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                    }
                    updateProblems(routineObjectList, filePath);
                    routineToUpdate = true;
                    break;
                }
            }
            if (routineToUpdate && !CommonsPlugin.isHeadless()) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Problems.refreshProblemTreeView();
                        } catch (Exception e) {
                        // ignore any exception here, as there is no impact if refresh or not.
                        // but if don't ignore, exception could be thrown if refresh is done too early.
                        }
                    }
                });
            }
            return Status.OK_STATUS;
        }
    };
    routineJob.setUser(false);
    routineJob.setRule(null);
    routineJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BuildContext(org.eclipse.jdt.core.compiler.BuildContext) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) Job(org.eclipse.core.runtime.jobs.Job) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) SystemException(org.talend.commons.exception.SystemException) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

BuildContext (org.eclipse.jdt.core.compiler.BuildContext)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 CategorizedProblem (org.eclipse.jdt.core.compiler.CategorizedProblem)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 ASTParser (org.eclipse.jdt.core.dom.ASTParser)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)1 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)1 ITraceToBytecodeInstaller (org.eclipse.xtext.generator.trace.ITraceToBytecodeInstaller)1 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)1 IEclipseTrace (org.eclipse.xtext.ui.generator.trace.IEclipseTrace)1 StoppedTask (org.eclipse.xtext.util.internal.Stopwatches.StoppedTask)1 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)1