Example usage for org.aspectj.ajdt.internal.core.builder CompilerConfigurationChangeFlags PROJECTSOURCERESOURCES_CHANGED

List of usage examples for org.aspectj.ajdt.internal.core.builder CompilerConfigurationChangeFlags PROJECTSOURCERESOURCES_CHANGED

Introduction

In this page you can find the example usage for org.aspectj.ajdt.internal.core.builder CompilerConfigurationChangeFlags PROJECTSOURCERESOURCES_CHANGED.

Prototype

int PROJECTSOURCERESOURCES_CHANGED

To view the source code for org.aspectj.ajdt.internal.core.builder CompilerConfigurationChangeFlags PROJECTSOURCERESOURCES_CHANGED.

Click Source Link

Usage

From source file:org.eclipse.ajdt.core.builder.AJBuilder.java

License:Open Source License

/**
 * Copies non-src resources to the output directory (bug 78579). The main
 * part of this method was taken from //  www .  ja va  2s  .  c o m
 * org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IResourceDelta,ClasspathMultiDirectory,int)
 * 
 * @param IJavaProject - the project which is being built
 * @param IResourceDelta - the projects delta
 * @param IClasspathEntry - the src entry on the classpath
 * @param int - the segment count
 * 
 * @throws CoreException
 */
private void copyResources(IJavaProject javaProject, IResourceDelta sourceDelta, IClasspathEntry srcEntry,
        int segmentCount) throws CoreException {
    IResource resource = sourceDelta.getResource();
    // bug 161739: skip excluded resources
    char[][] inclusionPatterns = ((ClasspathEntry) srcEntry).fullInclusionPatternChars();
    char[][] exclusionPatterns = ((ClasspathEntry) srcEntry).fullExclusionPatternChars();
    if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) {
        return;
    }

    IPath outputPath = srcEntry.getOutputLocation();
    if (outputPath == null) {
        outputPath = javaProject.getOutputLocation();
    }
    outputPath = outputPath.removeFirstSegments(1).makeRelative();

    IContainer outputFolder = getContainerForGivenPath(outputPath, javaProject.getProject());
    IContainer srcContainer = getContainerForGivenPath(srcEntry.getPath().removeFirstSegments(1),
            javaProject.getProject());

    IPath deltaPath = resource.getFullPath().removeFirstSegments(segmentCount);

    switch (resource.getType()) {
    case IResource.FOLDER:
        IContainer folderToRefresh = outputFolder.getFolder(deltaPath);
        switch (sourceDelta.getKind()) {
        case IResourceDelta.ADDED:
            createFolder(deltaPath, outputFolder, true); // ensure package exists in the output folder
            // fall through & collect all the resource files
        case IResourceDelta.CHANGED:
            IResourceDelta[] children = sourceDelta.getAffectedChildren();
            for (int i = 0, l = children.length; i < l; i++) {
                copyResources(javaProject, children[i], srcEntry, segmentCount);
            }
            break;

        case IResourceDelta.REMOVED:
            IClasspathEntry[] srcEntries = getSrcClasspathEntry(javaProject);
            if (srcEntries.length > 1) {
                for (int i = 0, l = srcEntries.length; i < l; i++) {
                    IPath srcPath = srcEntries[i].getPath().removeFirstSegments(1);
                    IFolder srcFolder = javaProject.getProject().getFolder(srcPath);
                    if (srcFolder.getFolder(deltaPath).exists()) {
                        // only a package fragment was removed, same as removing multiple source files
                        // ensure package exists in the output folder
                        // ADE---wait...why are we doing this???  why not just delete and be done with it?
                        // not going to change this because I don't know the ramifications.
                        createFolder(deltaPath, outputFolder, true);
                        IResourceDelta[] removedChildren = sourceDelta.getAffectedChildren();
                        for (int j = 0, m = removedChildren.length; j < m; j++) {
                            copyResources(javaProject, removedChildren[j], srcEntry, segmentCount);
                        }
                        folderToRefresh.refreshLocal(IResource.DEPTH_ZERO, null);
                        return;
                    }
                }
            }
            IFolder removedPackageFolder = outputFolder.getFolder(deltaPath);
            if (removedPackageFolder.exists()) {
                removedPackageFolder.delete(IResource.FORCE, null);
            }
            break;
        } // switch(sourceDelta.getKind())
        folderToRefresh.refreshLocal(IResource.DEPTH_ZERO, null);
        break;

    case IResource.FILE:
        // only do something if the output folder is different to the src folder
        if (!outputFolder.equals(srcContainer)) {
            // copy all resource deltas to the output folder
            if (deltaPath == null)
                return;
            // don't want to copy over .aj or .java files
            if (deltaPath.getFileExtension() != null && (deltaPath.getFileExtension().equals("aj") //$NON-NLS-1$
                    || deltaPath.getFileExtension().equals("java"))) { //$NON-NLS-1$
                break;
            }

            IResource fileToRefresh = outputFolder.getFile(deltaPath);
            switch (sourceDelta.getKind()) {
            case IResourceDelta.ADDED:
                if (fileToRefresh.exists()) {
                    AJLog.log(AJLog.BUILDER, "Deleting existing file " + deltaPath);//$NON-NLS-1$
                    fileToRefresh.delete(IResource.FORCE, null);
                }
                AJLog.log(AJLog.BUILDER, "Copying added file " + deltaPath);//$NON-NLS-1$
                createFolder(deltaPath.removeLastSegments(1), outputFolder, true);
                resource.copy(fileToRefresh.getFullPath(), IResource.FORCE | IResource.DERIVED, null);
                Util.setReadOnly(fileToRefresh, false); // just in case the original was read only
                fileToRefresh.refreshLocal(IResource.DEPTH_ZERO, null);
                // mark this change so compiler knows about it.
                CoreCompilerConfiguration.getCompilerConfigurationForProject(getProject())
                        .configurationChanged(CompilerConfigurationChangeFlags.PROJECTSOURCERESOURCES_CHANGED);
                break;
            case IResourceDelta.REMOVED:
                if (fileToRefresh.exists()) {
                    AJLog.log(AJLog.BUILDER, "Deleting removed file " + deltaPath);//$NON-NLS-1$
                    fileToRefresh.delete(IResource.FORCE, null);
                }
                // mark this change so compiler knows about it.
                CoreCompilerConfiguration.getCompilerConfigurationForProject(getProject())
                        .configurationChanged(CompilerConfigurationChangeFlags.PROJECTSOURCERESOURCES_CHANGED);
                break;
            case IResourceDelta.CHANGED:
                if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0
                        && (sourceDelta.getFlags() & IResourceDelta.ENCODING) == 0) {
                    return; // skip it since it really isn't changed
                }
                if (fileToRefresh.exists()) {
                    AJLog.log(AJLog.BUILDER, "Deleting existing file " + deltaPath);//$NON-NLS-1$
                    fileToRefresh.delete(IResource.FORCE, null);
                }
                AJLog.log(AJLog.BUILDER, "Copying changed file " + deltaPath);//$NON-NLS-1$
                createFolder(deltaPath.removeLastSegments(1), outputFolder, true);
                resource.copy(fileToRefresh.getFullPath(), IResource.FORCE | IResource.DERIVED, null);
                Util.setReadOnly(fileToRefresh, false); // just in case the original was read only
                break;
            }
            fileToRefresh.refreshLocal(IResource.DEPTH_ZERO, null);
        } // switch (sourceDelta.getKind())
        break;
    } // switch(resource.getType())
}