Example usage for org.eclipse.jdt.core IClasspathEntry getOutputLocation

List of usage examples for org.eclipse.jdt.core IClasspathEntry getOutputLocation

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry getOutputLocation.

Prototype

IPath getOutputLocation();

Source Link

Document

Returns the full path to the specific location where the builder writes .class files generated for this source entry (entry kind #CPE_SOURCE ).

Usage

From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java

License:Open Source License

public static List<IClasspathEntry> resolveDependentProjectClasspath(IClasspathEntry projEntry,
        IProject requiredProj) {/*from   www.  j av a2 s.  c o  m*/
    // add all output locations and exported classpath entities
    // AspectJ compiler doesn't understand the concept of a java project
    List<IClasspathEntry> actualEntries = new ArrayList<IClasspathEntry>();

    try {
        JavaProject requiredJavaProj = (JavaProject) JavaCore.create(requiredProj);
        // bug 288395 Do not use the default mechanism for resolving classpath here
        // this will look into jar files at the Classpath header in the jar's manifest
        // and include jar files that are potentially missing, but have no effect on
        // the build.
        Object resolvedClasspath = requiredJavaProj.resolveClasspath(requiredJavaProj.getRawClasspath(), true,
                false);
        IClasspathEntry[] requiredEntries = extractRequiredEntries(resolvedClasspath);
        for (int i = 0; i < requiredEntries.length; i++) {
            IClasspathEntry requiredEntry = requiredEntries[i];
            if (requiredEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {

                // always add source entries even if not explicitly exported
                // don't add the source folder itself, but instead add the outfolder
                IPath outputLocation = requiredEntry.getOutputLocation();
                if (outputLocation != null) {
                    IAccessRule[] rules = projEntry.getAccessRules();
                    IClasspathAttribute[] attributes = projEntry.getExtraAttributes();

                    // only add the out folder if it already exists
                    if (requiredProj.getFolder(outputLocation.removeFirstSegments(1)).exists()) {
                        IClasspathEntry outFolder = JavaCore.newLibraryEntry(outputLocation,
                                requiredEntry.getPath(), requiredProj.getFullPath(), rules, attributes,
                                projEntry.isExported());
                        actualEntries.add(outFolder);
                    }
                }
            } else if (requiredEntry.isExported()) {
                // must recur through this entry and add entries that it contains
                actualEntries.addAll(resolveClasspath(requiredEntry, requiredProj));

            }
        } // for (int i = 0; i < requiredEntries.length; i++)

        IPath outputLocation = requiredJavaProj.getOutputLocation();
        // Output location may not exist.  Do not put output location of required project
        // on path unless it exists
        boolean exists = false;
        // bug 244330 check to see if the project folder is also the output folder
        if (outputLocation.segmentCount() == 1) {
            exists = true;
        } else {
            if (requiredProj.getWorkspace().getRoot().getFolder(outputLocation).exists()) {
                exists = true;
            }
        }

        if (exists) {
            IClasspathEntry outFolder = JavaCore.newLibraryEntry(outputLocation, null,
                    requiredProj.getFullPath());
            actualEntries.add(outFolder);
        }
    } catch (JavaModelException e) {
    }
    return actualEntries;
}

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

License:Open Source License

/**
 * Copies over all non-excluded resources into the out folders.
 * //  ww  w .  j a  v a  2  s  .  c om
 * Called during a full build
 * 
 * @param javaProject
 */
private void copyResources(IJavaProject project) throws CoreException {
    IClasspathEntry[] srcEntries = getSrcClasspathEntry(project);

    for (int i = 0, l = srcEntries.length; i < l; i++) {
        IClasspathEntry srcEntry = srcEntries[i];
        IPath srcPath = srcEntry.getPath().removeFirstSegments(1);
        IPath outPath = srcEntry.getOutputLocation();
        if (outPath == null) {
            outPath = project.getOutputLocation();
        }
        outPath = outPath.removeFirstSegments(1);
        if (!srcPath.equals(outPath)) {
            final char[][] inclusionPatterns = ((ClasspathEntry) srcEntry).fullInclusionPatternChars();
            final char[][] exclusionPatterns = ((ClasspathEntry) srcEntry).fullExclusionPatternChars();

            final IContainer srcContainer = getContainerForGivenPath(srcPath, project.getProject());
            if (!srcContainer.exists()) {
                continue;
            }
            final int segmentsToRemove = srcContainer.getLocation().segmentCount();
            final IContainer outContainer = getContainerForGivenPath(outPath, project.getProject());
            if (outContainer.getType() == IResource.FOLDER && (!outContainer.exists())) {
                // also ensure parent folders exist
                createFolder(outPath, getProject(), false);
            }
            IResourceVisitor copyVisitor = new IResourceVisitor() {
                public boolean visit(IResource resource) throws CoreException {
                    if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) {
                        return false;
                    } else if (resource.getType() == IResource.PROJECT) {
                        return true;
                    }

                    if (resource.getType() == IResource.FOLDER || !isSourceFile(resource)) {
                        // refresh to ensure that resource has not been deleted from file system
                        resource.refreshLocal(IResource.DEPTH_ZERO, null);

                        if (resource.exists()) {
                            switch (resource.getType()) {
                            case IResource.FOLDER:
                                // ensure folder exists and is derived
                                IPath outPath = resource.getLocation().removeFirstSegments(segmentsToRemove);
                                IFolder outFolder = (IFolder) createFolder(outPath, outContainer, true);

                                // outfolder itself should not be derived
                                if (outFolder.equals(outContainer)) {
                                    outFolder.setDerived(false, null);
                                }
                                break;

                            case IResource.FILE:
                                // if this is not a CU, then copy over and mark as derived
                                if (!isSourceFile(resource)) {
                                    outPath = resource.getLocation().removeFirstSegments(segmentsToRemove);
                                    IFile outFile = outContainer.getFile(outPath);
                                    // check to make sure that resource has not been deleted from the file
                                    // system without a refresh
                                    if (!outFile.exists()) {
                                        try {
                                            resource.copy(outFile.getFullPath(),
                                                    IResource.DERIVED | IResource.FORCE, null);
                                            Util.setReadOnly(outFile, false);
                                        } catch (ResourceException e) {
                                            resource.refreshLocal(IResource.DEPTH_ZERO, null);
                                            if (resource.exists()) {
                                                // probably hit https://bugs.eclipse.org/bugs/show_bug.cgi?id=331036
                                                // We just checked to see if the outfile exists, but we get this exception
                                                // anyway.  It might be that it has not been refreshed.
                                                if (e.getStatus()
                                                        .getCode() == IResourceStatus.FAILED_WRITE_LOCAL) {
                                                    AJLog.log(AJLog.BUILDER, "Could not write to resource '"
                                                            + resource + "'.  "
                                                            + "It probbly already exists on disk.  Try a clean build.");
                                                    outFile.refreshLocal(IResource.DEPTH_ZERO, null);
                                                } else {
                                                    throw e;
                                                }
                                            } else {
                                                // resource was deleted in the middle of the build.  Can safely ignore this
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                            return true;
                        }
                    }
                    return false;
                }
            };

            srcContainer.accept(copyVisitor);

        }
    }
}

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 //w  ww. j a va  2s  . c  om
 * 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())
}

From source file:org.eclipse.ajdt.core.CoreUtils.java

License:Open Source License

/**
 * Get the output locations for the project
 * //from   w w  w  .j  a  v a2s.co  m
 * @param project
 * @return list of IPath objects
 */
public static List<IPath> getOutputLocationPaths(IProject project) {
    List<IPath> outputLocations = new ArrayList<IPath>();
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject == null)
        return outputLocations;

    try {
        // Have been unable to create a user scenario where the following
        // for
        // loop adds something to outputLocations, therefore always
        // fall through to the following if loop. However, if a project has
        // more than one output folder, then this for loop should pick them
        // up.
        // Needs testing.......
        IClasspathEntry[] cpEntry = javaProject.getRawClasspath();
        for (int j = 0; j < cpEntry.length; j++) {
            IClasspathEntry entry = cpEntry[j];
            int contentKind = entry.getContentKind();
            if (contentKind == ClasspathEntry.K_OUTPUT) {
                if (entry.getOutputLocation() != null) {
                    outputLocations.add(entry.getOutputLocation());
                }
            }
        }
        // If we haven't added anything from reading the .classpath
        // file, then use the default output location
        if (outputLocations.size() == 0) {
            outputLocations.add(javaProject.getOutputLocation());
        }
    } catch (JavaModelException e) {
    }
    return outputLocations;
}

From source file:org.eclipse.ajdt.internal.core.ajde.CoreOutputLocationManager.java

License:Open Source License

private void handleClassPathEntry(IJavaProject jp, IClasspathEntry cpe) throws JavaModelException {
    switch (cpe.getEntryKind()) {
    case IClasspathEntry.CPE_CONTAINER:
        IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jp);
        if (container != null && container.getKind() != IClasspathContainer.K_DEFAULT_SYSTEM) {
            IClasspathEntry[] cpes = container.getClasspathEntries();
            for (int i = 0; i < cpes.length; i++) {
                handleClassPathEntry(jp, cpes[i]);
            }//from   w w  w.ja  va  2s  . com
        }
        break;
    case IClasspathEntry.CPE_LIBRARY:
        File libFile = pathToFile(cpe.getPath());
        if (libFile.isDirectory()) { // ignore jar files
            if (libFile != null && !binFolderToProject.containsKey(libFile)) {
                binFolderToProject.put(libFile, jp.getProject());
            }
        }
        break;
    case IClasspathEntry.CPE_PROJECT:
        IJavaProject jpClasspath = pathToProject(cpe.getPath());
        if (jpClasspath != null) {
            mapProject(jpClasspath);
        }
        break;

    case IClasspathEntry.CPE_SOURCE:
        File outFile = pathToFile(
                cpe.getOutputLocation() == null ? jp.getOutputLocation() : cpe.getOutputLocation());
        if (outFile != null && !binFolderToProject.containsKey(outFile)) {
            binFolderToProject.put(outFile, jp.getProject());
        }
        break;
    case IClasspathEntry.CPE_VARIABLE:
        IClasspathEntry cpeResolved = JavaCore.getResolvedClasspathEntry(cpe);
        if (cpeResolved != null) {
            handleClassPathEntry(jp, cpeResolved);
        }
        break;
    }
}

From source file:org.eclipse.ajdt.internal.core.builder.BuildClasspathResolver.java

License:Open Source License

private void computeClasspathLocations(IWorkspaceRoot root, JavaProject javaProject,
        SimpleLookupTable binaryLocationsPerProject) throws CoreException {

    /* Update cycle marker */
    IMarker cycleMarker = javaProject.getCycleMarker();
    if (cycleMarker != null) {
        int severity = JavaCore.ERROR.equals(javaProject.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true))
                ? IMarker.SEVERITY_ERROR
                : IMarker.SEVERITY_WARNING;
        if (severity != ((Integer) cycleMarker.getAttribute(IMarker.SEVERITY)).intValue())
            cycleMarker.setAttribute(IMarker.SEVERITY, severity);
    }/*  w w w  .  j  a  va2s  .  c om*/

    IClasspathEntry[] classpathEntries = javaProject.getExpandedClasspath();
    ArrayList sLocations = new ArrayList(classpathEntries.length);
    ArrayList bLocations = new ArrayList(classpathEntries.length);
    nextEntry: for (int i = 0, l = classpathEntries.length; i < l; i++) {
        ClasspathEntry entry = (ClasspathEntry) classpathEntries[i];
        IPath path = entry.getPath();
        Object target = JavaModel.getTarget(path, true);
        if (target == null)
            continue nextEntry;

        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (!(target instanceof IContainer))
                continue nextEntry;
            IPath outputPath = entry.getOutputLocation() != null ? entry.getOutputLocation()
                    : javaProject.getOutputLocation();
            IContainer outputFolder;
            if (outputPath.segmentCount() == 1) {
                outputFolder = javaProject.getProject();
            } else {
                outputFolder = root.getFolder(outputPath);
                // AspectJ Change Begin
                // This method can be executing on the wrong thread, where createFolder() will hang, so don't do it!
                // if (!outputFolder.exists())
                //    createFolder(outputFolder);
                // AspectJ Change End
            }
            sLocations.add(ClasspathLocation.forSourceFolder((IContainer) target, outputFolder,
                    entry.fullInclusionPatternChars(), entry.fullExclusionPatternChars()));
            continue nextEntry;

        case IClasspathEntry.CPE_PROJECT:
            if (!(target instanceof IProject))
                continue nextEntry;
            IProject prereqProject = (IProject) target;
            if (!JavaProject.hasJavaNature(prereqProject))
                continue nextEntry; // if project doesn't have java nature or is not accessible

            JavaProject prereqJavaProject = (JavaProject) JavaCore.create(prereqProject);
            IClasspathEntry[] prereqClasspathEntries = prereqJavaProject.getRawClasspath();
            ArrayList seen = new ArrayList();
            nextPrereqEntry: for (int j = 0, m = prereqClasspathEntries.length; j < m; j++) {
                IClasspathEntry prereqEntry = prereqClasspathEntries[j];
                if (prereqEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    Object prereqTarget = JavaModel.getTarget(prereqEntry.getPath(), true);
                    if (!(prereqTarget instanceof IContainer))
                        continue nextPrereqEntry;
                    IPath prereqOutputPath = prereqEntry.getOutputLocation() != null
                            ? prereqEntry.getOutputLocation()
                            : prereqJavaProject.getOutputLocation();
                    IContainer binaryFolder = prereqOutputPath.segmentCount() == 1 ? (IContainer) prereqProject
                            : (IContainer) root.getFolder(prereqOutputPath);
                    if (binaryFolder.exists() && !seen.contains(binaryFolder)) {
                        seen.add(binaryFolder);
                        ClasspathLocation bLocation = ClasspathLocation.forBinaryFolder(binaryFolder, true,
                                entry.getAccessRuleSet());
                        bLocations.add(bLocation);
                        if (binaryLocationsPerProject != null) { // normal builder mode
                            ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject
                                    .get(prereqProject);
                            if (existingLocations == null) {
                                existingLocations = new ClasspathLocation[] { bLocation };
                            } else {
                                int size = existingLocations.length;
                                System.arraycopy(existingLocations, 0,
                                        existingLocations = new ClasspathLocation[size + 1], 0, size);
                                existingLocations[size] = bLocation;
                            }
                            binaryLocationsPerProject.put(prereqProject, existingLocations);
                        }
                    }
                }
            }
            continue nextEntry;

        case IClasspathEntry.CPE_LIBRARY:
            if (target instanceof IResource) {
                IResource resource = (IResource) target;
                ClasspathLocation bLocation = null;
                if (resource instanceof IFile) {
                    if (!(org.eclipse.jdt.internal.compiler.util.Util
                            .isPotentialZipArchive(path.lastSegment())))
                        continue nextEntry;
                    AccessRuleSet accessRuleSet = JavaCore.IGNORE.equals(
                            javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) ? null
                                    : entry.getAccessRuleSet();
                    bLocation = ClasspathLocation.forLibrary((IFile) resource, accessRuleSet);
                } else if (resource instanceof IContainer) {
                    AccessRuleSet accessRuleSet = JavaCore.IGNORE.equals(
                            javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) ? null
                                    : entry.getAccessRuleSet();
                    bLocation = ClasspathLocation.forBinaryFolder((IContainer) target, false, accessRuleSet); // is library folder not output folder
                }
                bLocations.add(bLocation);
                if (binaryLocationsPerProject != null) { // normal builder mode
                    IProject p = resource.getProject(); // can be the project being built
                    ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject
                            .get(p);
                    if (existingLocations == null) {
                        existingLocations = new ClasspathLocation[] { bLocation };
                    } else {
                        int size = existingLocations.length;
                        System.arraycopy(existingLocations, 0,
                                existingLocations = new ClasspathLocation[size + 1], 0, size);
                        existingLocations[size] = bLocation;
                    }
                    binaryLocationsPerProject.put(p, existingLocations);
                }
            } else if (target instanceof File) {
                if (!(org.eclipse.jdt.internal.compiler.util.Util.isPotentialZipArchive(path.lastSegment())))
                    continue nextEntry;
                AccessRuleSet accessRuleSet = JavaCore.IGNORE
                        .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) ? null
                                : entry.getAccessRuleSet();
                bLocations.add(ClasspathLocation.forLibrary(path.toString(), accessRuleSet));
            }
            continue nextEntry;
        }
    }

    // now split the classpath locations... place the output folders ahead of the other .class file folders & jars
    ArrayList outputFolders = new ArrayList(1);
    this.sourceLocations = new ClasspathMultiDirectory[sLocations.size()];
    if (!sLocations.isEmpty()) {
        sLocations.toArray(this.sourceLocations);

        // collect the output folders, skipping duplicates
        next: for (int i = 0, l = sourceLocations.length; i < l; i++) {
            ClasspathMultiDirectory md = sourceLocations[i];
            IPath outputPath = md.binaryFolder.getFullPath();
            for (int j = 0; j < i; j++) { // compare against previously walked source folders
                if (outputPath.equals(sourceLocations[j].binaryFolder.getFullPath())) {
                    md.hasIndependentOutputFolder = sourceLocations[j].hasIndependentOutputFolder;
                    continue next;
                }
            }
            outputFolders.add(md);

            // also tag each source folder whose output folder is an independent folder & is not also a source folder
            for (int j = 0, m = sourceLocations.length; j < m; j++)
                if (outputPath.equals(sourceLocations[j].sourceFolder.getFullPath()))
                    continue next;
            md.hasIndependentOutputFolder = true;
        }
    }

    // combine the output folders with the binary folders & jars... place the output folders before other .class file folders & jars
    this.binaryLocations = new ClasspathLocation[outputFolders.size() + bLocations.size()];
    int index = 0;
    for (int i = 0, l = outputFolders.size(); i < l; i++)
        this.binaryLocations[index++] = (ClasspathLocation) outputFolders.get(i);
    for (int i = 0, l = bLocations.size(); i < l; i++)
        this.binaryLocations[index++] = (ClasspathLocation) bLocations.get(i);
}

From source file:org.eclipse.ajdt.internal.launching.LTWUtils.java

License:Open Source License

private static void copyToOutputFolder(IFile file, IJavaProject javaProject, IClasspathEntry srcEntry)
        throws CoreException {
    IPath outputPath = srcEntry.getOutputLocation();
    if (outputPath == null) {
        outputPath = javaProject.getOutputLocation();
    }/*from  w w  w .j  av a 2  s.com*/
    outputPath = outputPath.removeFirstSegments(1).makeRelative();
    IContainer outputFolder = getContainerForGivenPath(outputPath, javaProject.getProject());
    IContainer srcContainer = getContainerForGivenPath(srcEntry.getPath().removeFirstSegments(1),
            javaProject.getProject());
    if (!outputFolder.equals(srcContainer)) {
        IResource outputFile = outputFolder.getFile(new Path(AOP_XML_LOCATION));
        if (outputFile.exists()) {
            AJLog.log("Deleting existing file " + outputFile);//$NON-NLS-1$
            outputFile.delete(IResource.FORCE, null);
        }
        AJLog.log("Copying added file " + file);//$NON-NLS-1$
        IFolder metainf = (IFolder) ((Workspace) ResourcesPlugin.getWorkspace()).newResource(
                new Path(outputFolder.getFullPath() + "/META-INF"), //$NON-NLS-1$ 
                IResource.FOLDER);
        if (!metainf.exists()) {
            metainf.create(true, true, null);
        }
        file.copy(outputFile.getFullPath(), IResource.FORCE, null);
        outputFile.setDerived(true);
        outputFile.refreshLocal(IResource.DEPTH_ZERO, null);
    }
}

From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java

License:Open Source License

private IContainer[] getOutputContainers(IJavaProject javaProject) throws CoreException {
    Set<IPath> outputPaths = new HashSet<IPath>();
    boolean includeDefaultOutputPath = false;
    IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
    for (int i = 0; i < roots.length; i++) {
        if (roots[i] != null) {
            IClasspathEntry cpEntry = roots[i].getRawClasspathEntry();
            if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath location = cpEntry.getOutputLocation();
                if (location != null)
                    outputPaths.add(location);
                else
                    includeDefaultOutputPath = true;
            }/*from  w  w  w  . j  ava 2 s. c om*/
        }
    }

    if (includeDefaultOutputPath) {
        // Use default output location
        outputPaths.add(javaProject.getOutputLocation());
    }

    // Convert paths to containers
    Set<IContainer> outputContainers = new HashSet<IContainer>(outputPaths.size());
    Iterator<IPath> iter = outputPaths.iterator();
    while (iter.hasNext()) {
        IPath path = iter.next();
        if (javaProject.getProject().getFullPath().equals(path))
            outputContainers.add(javaProject.getProject());
        else {
            IFolder outputFolder = createFolderHandle(path);
            if (outputFolder == null || !outputFolder.isAccessible()) {
                String msg = JarPackagerMessages.JarFileExportOperation_outputContainerNotAccessible;
                addToStatus(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(),
                        IJavaStatusConstants.INTERNAL_ERROR, msg, null)));
            } else
                outputContainers.add(outputFolder);
        }
    }
    return outputContainers.toArray(new IContainer[outputContainers.size()]);
}

From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java

License:Open Source License

/**
 * Returns an iterator on a list with files that correspond to the
 * passed file and that are on the classpath of its project.
 *
 * @param   file         the file for which to find the corresponding classpath resources
 * @param   pathInJar      the path that the file has in the JAR (i.e. project and source folder segments removed)
 * @param   javaProject      the javaProject that contains the file
 * @param   pkgRoot         the package fragment root that contains the file
 * @return   the iterator over the corresponding classpath files for the given file
 *///from  www . ja va 2 s  .c om
protected Iterator<IFile> filesOnClasspath(IFile file, IPath pathInJar, IJavaProject javaProject,
        IPackageFragmentRoot pkgRoot, IProgressMonitor progressMonitor) throws CoreException {
    // Allow JAR Package to provide its own strategy
    IFile[] classFiles = fJarPackage.findClassfilesFor(file);
    if (classFiles != null)
        return Arrays.asList(classFiles).iterator();

    if (!isJavaFile(file))
        return Collections.<IFile>emptyList().iterator();

    IPath outputPath = null;
    if (pkgRoot != null) {
        IClasspathEntry cpEntry = pkgRoot.getRawClasspathEntry();
        if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
            outputPath = cpEntry.getOutputLocation();
    }
    if (outputPath == null)
        // Use default output location
        outputPath = javaProject.getOutputLocation();

    IContainer outputContainer;
    if (javaProject.getProject().getFullPath().equals(outputPath))
        outputContainer = javaProject.getProject();
    else {
        outputContainer = createFolderHandle(outputPath);
        if (outputContainer == null || !outputContainer.isAccessible()) {
            String msg = JarPackagerMessages.JarFileExportOperation_outputContainerNotAccessible;
            throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(),
                    IJavaStatusConstants.INTERNAL_ERROR, msg, null));
        }
    }

    // Java CU - search files with .class ending
    boolean hasErrors = hasCompileErrors(file);
    boolean hasWarnings = hasCompileWarnings(file);
    boolean canBeExported = canBeExported(hasErrors, hasWarnings);
    if (!canBeExported)
        return Collections.<IFile>emptyList().iterator();
    reportPossibleCompileProblems(file, hasErrors, hasWarnings, canBeExported);
    IContainer classContainer = outputContainer;
    if (pathInJar.segmentCount() > 1)
        classContainer = outputContainer.getFolder(pathInJar.removeLastSegments(1));

    if (fExportedClassContainers.contains(classContainer))
        return Collections.<IFile>emptyList().iterator();

    if (fClassFilesMapContainer == null || !fClassFilesMapContainer.equals(classContainer)) {
        fJavaNameToClassFilesMap = buildJavaToClassMap(classContainer);
        if (fJavaNameToClassFilesMap == null) {
            // Could not fully build map. fallback is to export whole directory
            IPath location = classContainer.getLocation();
            String containerName = ""; //$NON-NLS-1$
            if (location != null)
                containerName = location.toFile().toString();
            String msg = Messages.format(
                    JarPackagerMessages.JarFileExportOperation_missingSourceFileAttributeExportedAll,
                    containerName);
            addInfo(msg, null);
            fExportedClassContainers.add(classContainer);
            return getClassesIn(classContainer);
        }
        fClassFilesMapContainer = classContainer;
    }
    ArrayList classFileList = (ArrayList) fJavaNameToClassFilesMap.get(file.getName());
    if (classFileList == null || classFileList.isEmpty()) {
        String msg = Messages.format(
                JarPackagerMessages.JarFileExportOperation_classFileOnClasspathNotAccessible,
                file.getFullPath());
        throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(),
                IJavaStatusConstants.INTERNAL_ERROR, msg, null));
    }
    return classFileList.iterator();
}

From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java

License:Open Source License

public static boolean projectHasClassFolderDependency(IProject project, IProject projectDependedOn)
        throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    IJavaProject depProject = JavaCore.create(projectDependedOn);
    if (javaProject == null || depProject == null)
        return false;

    // first get the output location for projectDependedOn
    IPath outputLocation = null;/*  w ww  .jav a 2 s  . c om*/
    IClasspathEntry[] cp = depProject.getRawClasspath();
    for (int j = 0; j < cp.length; j++) {
        IClasspathEntry entry = cp[j];
        int contentKind = entry.getContentKind();
        if (contentKind == ClasspathEntry.K_OUTPUT) {
            outputLocation = entry.getOutputLocation();
        }
        if (entry.getEntryKind() == ClasspathEntry.K_OUTPUT) {
            outputLocation = entry.getOutputLocation();
        }
    }
    if (outputLocation == null) {
        outputLocation = depProject.getOutputLocation();
    }
    // now check the classpath entries of project for the output
    // location just calculated
    IClasspathEntry[] cpEntry = javaProject.getRawClasspath();
    for (int j = 0; j < cpEntry.length; j++) {
        IClasspathEntry entry = cpEntry[j];
        int entryKind = entry.getEntryKind();
        IPath entryPath = entry.getPath();
        if (entryKind == IClasspathEntry.CPE_LIBRARY && entryPath.equals(outputLocation)) {
            return true;
        }
    }
    return false;
}