Example usage for org.eclipse.jdt.core.compiler BuildContext recordAddedGeneratedFiles

List of usage examples for org.eclipse.jdt.core.compiler BuildContext recordAddedGeneratedFiles

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler BuildContext recordAddedGeneratedFiles.

Prototype

public void recordAddedGeneratedFiles(IFile[] addedGeneratedFiles) 

Source Link

Document

Record the added/changed generated files that need to be compiled.

Usage

From source file:de.devboost.commenttemplate.builder.CommentTemplateCompilationParticipant.java

License:Open Source License

private void buildUnsafe(BuildContext[] contexts) {

    ResourceSetImpl resourceSet = new ResourceSetImpl();
    // markers are already created by the JDT
    Map<Object, Object> loadOptions = resourceSet.getLoadOptions();
    loadOptions.put(IJavaOptions.DISABLE_CREATING_MARKERS_FOR_PROBLEMS, Boolean.TRUE);

    for (BuildContext context : contexts) {
        IFile srcFile = context.getFile();
        IPath srcFilePath = srcFile.getFullPath();
        URI uri = URI.createPlatformResourceURI(srcFilePath.toString(), true);
        if (!builder.isBuildingNeeded(uri)) {
            continue;
        }//  w  w  w.jav  a  2s .  c  o m

        Set<String> brokenVariableReferences = new LinkedHashSet<String>();
        Resource resource = resourceSet.getResource(uri, true);
        URI compiledURI = builder.build(resource, brokenVariableReferences);
        if (compiledURI == null) {
            continue;
        }

        IWorkspace workspace = srcFile.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        Path compiledSrcPath = new Path(compiledURI.toPlatformString(true));
        IFile compiledSrc = root.getFile(compiledSrcPath);
        try {
            srcFile.deleteMarkers(JavaMarkerHelper.MARKER_TYPE, false, IResource.DEPTH_ONE);
        } catch (CoreException e) {
            CommentTemplatePlugin.logError("Can't delete markers from " + srcFile, e);
        }
        if (!brokenVariableReferences.isEmpty()) {
            createWarnings(brokenVariableReferences, srcFile);
        }
        context.recordAddedGeneratedFiles(new IFile[] { compiledSrc });
        createSrcGenFolder(srcFile.getProject());
    }
}

From source file:de.devboost.emfcustomize.builder.EMFCustomizeCompilationParticipant.java

License:Open Source License

@Override
public void buildStarting(BuildContext[] files, boolean isBatch) {
    ResourceSetImpl resourceSet = new ResourceSetImpl();
    //markers are already created by the JDT
    resourceSet.getLoadOptions().put(IJavaOptions.DISABLE_CREATING_MARKERS_FOR_PROBLEMS, Boolean.TRUE);
    for (BuildContext context : files) {
        URI uri = URI.createPlatformResourceURI(context.getFile().getFullPath().toString(), true);
        if (builder.isBuildingNeeded(uri)) {
            IWorkspace workspace = context.getFile().getWorkspace();
            List<Resource> createdClasses = builder.build(resourceSet.getResource(uri, true),
                    context.getFile());/* w  w  w.ja  v a 2s.  co  m*/
            IFile[] newSrcFiles = new IFile[createdClasses.size()];
            for (int i = 0; i < createdClasses.size(); i++) {
                newSrcFiles[i] = workspace.getRoot()
                        .getFile(new Path(createdClasses.get(i).getURI().toPlatformString(true)));
            }
            context.recordAddedGeneratedFiles(newSrcFiles);
        }
    }
}