Example usage for org.eclipse.jdt.internal.core JavaProject setRawClasspath

List of usage examples for org.eclipse.jdt.internal.core JavaProject setRawClasspath

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JavaProject setRawClasspath.

Prototype

@Override
public void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException 

Source Link

Usage

From source file:de.ovgu.featureide.ahead.actions.FeatureHouseToAHEADConversion.java

License:Open Source License

/**
 * Sets the java build path to the build folder of the given feature project.
 * @param featureProject/*w  ww .j a v  a  2  s . c  om*/
 */
private void setJavaBuildPath(IFeatureProject featureProject) {
    try {
        JavaProject javaProject = new JavaProject(featureProject.getProject(), null);
        IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
        for (int i = 0; i < classpathEntries.length; i++) {
            /** change the actual source entry **/
            if (classpathEntries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                classpathEntries[i] = setSourceEntry(classpathEntries[i]);
                javaProject.setRawClasspath(classpathEntries, null);
                return;
            }
        }

        /** case: no source entry **/
        IClasspathEntry[] newEntries = new IClasspathEntry[classpathEntries.length + 1];
        System.arraycopy(classpathEntries, 0, newEntries, 0, classpathEntries.length);
        newEntries[newEntries.length - 1] = getSourceEntry();
        javaProject.setRawClasspath(classpathEntries, null);
    } catch (JavaModelException e) {
        AheadCorePlugin.getDefault().logError(e);
    }
}

From source file:de.ovgu.featureide.aspectj.AspectJComposer.java

License:Open Source License

/**
 * Set the unselected aspects to be excluded from build
 * @param project/*from   w w  w. j  a  v  a 2 s .c o  m*/
 */
private void setBuildpaths(IProject project) {
    String buildPath = null;
    if (featureProject == null || featureProject.getBuildPath() == null) {
        buildPath = IFeatureProject.DEFAULT_SOURCE_PATH;
    } else {
        buildPath = featureProject.getBuildPath();
    }

    try {
        JavaProject javaProject = new JavaProject(project, null);
        IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
        /** check if entries already exist **/
        for (int i = 0; i < oldEntries.length; i++) {
            if (oldEntries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                /** correct the source entry **/
                oldEntries[i] = setSourceEntry(oldEntries[i]);
                javaProject.setRawClasspath(oldEntries, null);
                return;
            }
        }

        /** add the new entry **/
        IClasspathEntry[] entries = new IClasspathEntry[oldEntries.length + 1];
        System.arraycopy(oldEntries, 0, entries, 0, oldEntries.length);
        entries[oldEntries.length] = setSourceEntry(getSourceEntry(buildPath));
        javaProject.setRawClasspath(entries, null);
    } catch (JavaModelException e) {
        CorePlugin.getDefault().logError(e);
    }
}

From source file:de.ovgu.featureide.aspectj.AspectJComposer.java

License:Open Source License

private void addClasspathFile(IProject project, String buildPath) {
    if (buildPath == null) {
        if (featureProject == null || featureProject.getBuildPath() == null) {
            buildPath = IFeatureProject.DEFAULT_SOURCE_PATH;
        } else {//from www  . j  a v  a  2s.com
            buildPath = featureProject.getBuildPath();
        }
    }

    try {
        JavaProject javaProject = new JavaProject(project, null);
        IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
        boolean sourceAdded = false;
        boolean containerAdded = false;
        boolean ajContainerAdded = false;
        /** check if entries already exist **/
        for (int i = 0; i < oldEntries.length; i++) {
            if (!sourceAdded && oldEntries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                /** correct the source entry **/
                oldEntries[i] = getSourceEntry(buildPath);
                sourceAdded = true;
            } else if ((!containerAdded || !ajContainerAdded)
                    && oldEntries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                /** check the container entries **/
                if (oldEntries[i].getPath().equals(JRE_CONTAINER)) {
                    containerAdded = true;
                }
                if (oldEntries[i].getPath().equals(ASPECTJRT_CONTAINER)) {
                    ajContainerAdded = true;
                }

            }
        }
        /** case: no new entries **/
        if (sourceAdded && containerAdded && ajContainerAdded) {
            javaProject.setRawClasspath(oldEntries, null);
            return;
        }

        /** add the new entries **/
        IClasspathEntry[] entries = new IClasspathEntry[(sourceAdded ? 0 : 1) + (containerAdded ? 0 : 1)
                + (containerAdded ? 0 : 1) + oldEntries.length];
        System.arraycopy(oldEntries, 0, entries, 0, oldEntries.length);

        if (!sourceAdded) {
            entries[oldEntries.length] = getSourceEntry(buildPath);
        }
        if (!containerAdded) {
            int position = (sourceAdded ? 0 : 1) + oldEntries.length;
            entries[position] = getContainerEntry();
        }
        if (!ajContainerAdded) {
            int position = (sourceAdded ? 0 : 1) + (containerAdded ? 0 : 1) + oldEntries.length;
            entries[position] = getAJContainerEntry();
        }
        javaProject.setRawClasspath(entries, null);
    } catch (JavaModelException e) {
        CorePlugin.getDefault().logError(e);
    }
}

From source file:de.ovgu.featureide.core.builder.ComposerExtensionClass.java

License:Open Source License

private void addClasspathFile(IProject project, String buildPath) {
    try {//w  w w .  j a  va 2 s.  c o  m
        JavaProject javaProject = new JavaProject(project, null);
        IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
        boolean sourceAdded = false;
        boolean containerAdded = false;
        /** check if entries already exist **/
        for (int i = 0; i < oldEntries.length; i++) {
            if (!sourceAdded && oldEntries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                /** correct the source entry **/
                // XXX the source entry should be equivalent to the build path, 
                // but e.g. at FeatureHouse the real build path is src/config -> Builder problems
                // -> is it necessary to correct the path?
                if (oldEntries[i].getPath().toString().equals("/" + project.getName())) {
                    /** necessary after creating a new FeatureIDE project **/
                    oldEntries[i] = setSourceEntry(buildPath, oldEntries[i]);
                }
                /** find source entry **/
                sourceAdded = true;
            } else if (!containerAdded && oldEntries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                /** check the container entries **/
                if (oldEntries[i].getPath().equals(JRE_CONTAINER)) {
                    containerAdded = true;
                }
            }
        }
        /** case: no new entries **/
        if (sourceAdded && containerAdded) {
            javaProject.setRawClasspath(oldEntries, null);
            return;
        }

        /** add the new entries **/
        IClasspathEntry[] entries = new IClasspathEntry[(sourceAdded ? 0 : 1) + (containerAdded ? 0 : 1)
                + oldEntries.length];
        System.arraycopy(oldEntries, 0, entries, 0, oldEntries.length);

        if (!sourceAdded) {
            entries[oldEntries.length] = getSourceEntry(buildPath);
        }
        if (!containerAdded) {
            int position = (sourceAdded ? 0 : 1) + oldEntries.length;
            entries[position] = getContainerEntry();
        }

        javaProject.setRawClasspath(entries, null);
    } catch (JavaModelException e) {
        CorePlugin.getDefault().logError(e);
    }
}

From source file:de.ovgu.featureide.core.mpl.job.MPLRenameExternalJob.java

License:Open Source License

private static IPath setJavaBuildPath(JavaProject javaProject, IPath path, int index) {
    try {//from ww  w  .  j a v a2  s . co  m
        final IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath();

        if (index >= 0) {
            final IClasspathEntry e = classpathEntrys[index];
            if (!e.getPath().equals(path)) {
                final IPath formerSourcePath = e.getPath();
                classpathEntrys[index] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path,
                        e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(),
                        e.combineAccessRules(), e.getExtraAttributes());
                javaProject.setRawClasspath(classpathEntrys, null);
                return formerSourcePath;
            }
        } else {
            final IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1];
            System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length);
            newEntrys[newEntrys.length - 1] = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE,
                    IClasspathEntry.CPE_SOURCE, path, new IPath[0], new IPath[0], null, null, null, false, null,
                    false, new IClasspathAttribute[0]);
            javaProject.setRawClasspath(newEntrys, null);
        }
    } catch (JavaModelException e) {
        MPLPlugin.getDefault().logError(e);
    }

    return null;
}

From source file:de.ovgu.featureide.core.mpl.job.MPLRenameExternalJob.java

License:Open Source License

private static void resetJavaBuildPath(JavaProject javaProject, IPath formerSourcePath,
        int formerSourcePathIndex) {
    try {//  www . j  a  va  2s .c  om
        final IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath();

        if (formerSourcePath != null) {
            final IClasspathEntry e = classpathEntrys[formerSourcePathIndex];
            classpathEntrys[formerSourcePathIndex] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(),
                    formerSourcePath, e.getInclusionPatterns(), e.getExclusionPatterns(),
                    e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(),
                    e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes());
            javaProject.setRawClasspath(classpathEntrys, null);
        } else if (formerSourcePathIndex == -1) {
            final IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length - 1];
            System.arraycopy(classpathEntrys, 0, newEntrys, 0, newEntrys.length);
            javaProject.setRawClasspath(newEntrys, null);
        }
    } catch (JavaModelException e) {
        MPLPlugin.getDefault().logError(e);
    }
}

From source file:de.ovgu.featureide.featurehouse.FeatureHouseComposer.java

License:Open Source License

/**
 * Sets the Java build path to the folder at the build folder, named like the current configuration.
 * @param buildPath The name of the current configuration
 *///from   w  w  w.j  ava  2s .co  m
private void setJavaBuildPath(String buildPath) {
    try {
        JavaProject javaProject = new JavaProject(featureProject.getProject(), null);
        IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath();

        int i = 0;
        for (IClasspathEntry e : classpathEntrys) {
            if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = featureProject.getBuildFolder().getFolder(buildPath).getFullPath();

                /** return if nothing has to be changed **/
                if (e.getPath().equals(path)) {
                    return;
                }

                /** change the actual source entry to the new build path **/
                ClasspathEntry changedEntry = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path,
                        e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(),
                        e.combineAccessRules(), e.getExtraAttributes());
                classpathEntrys[i] = changedEntry;
                javaProject.setRawClasspath(classpathEntrys, null);
                return;
            }
            i++;
        }

        /** case: there is no source entry at the class path
         *       add the source entry to the classpath **/
        IFolder folder = featureProject.getBuildFolder().getFolder(buildPath);
        ClasspathEntry sourceEntry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE,
                IClasspathEntry.CPE_SOURCE, folder.getFullPath(), new IPath[0], new IPath[0], null, null, null,
                false, null, false, new IClasspathAttribute[0]);
        IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1];
        System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length);
        newEntrys[newEntrys.length - 1] = sourceEntry;
        javaProject.setRawClasspath(newEntrys, null);
    } catch (JavaModelException e) {
        FeatureHouseCorePlugin.getDefault().logError(e);
    }
}

From source file:de.ovgu.featureide.migration.impl.DefaultSPLMigrator.java

License:Open Source License

/**
 * @param newJavaProject//  w  w w .j a  v  a 2s .  c  o  m
 * @param classpathToMigrate
 * @param newClassPath
 * @throws JavaModelException
 */
private void migrateLibraryAndContainerEntries(JavaProject newJavaProject, IClasspathEntry[] classpathToMigrate,
        List<IClasspathEntry> newClassPath) throws JavaModelException {
    for (IClasspathEntry entry : classpathToMigrate) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
            if (!newClassPath.contains(entry))
                newClassPath.add(entry);
    }
    newJavaProject.setRawClasspath(newClassPath.toArray(new IClasspathEntry[newClassPath.size()]), null);
}

From source file:de.ovgu.featureide.ui.actions.generator.Generator.java

License:Open Source License

/**
 * Sets the classpath entries for the newly created project
 * @param p The new project/*ww  w.j  a va2 s.co m*/
 */
// TODO remove redundant calculations for each configuration
// TODO copy settings
private void setClassPath(IProject p) {
    JavaProject baseProject = new JavaProject(builder.featureProject.getProject(), null);
    JavaProject newProject = new JavaProject(p, null);
    try {
        IClasspathEntry[] entries = baseProject.getRawClasspath().clone();
        for (int i = 0; i < entries.length; i++) {
            // set source entry to "src"
            IClasspathEntry e = entries[i];
            if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                entries[i] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), new Path("src"),
                        e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(),
                        e.combineAccessRules(), e.getExtraAttributes());
            } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                // set the library entries and copy the libraries 
                // which are direct at the old projects folder  
                IPath path = e.getPath().removeFirstSegments(1);
                IProject project = builder.featureProject.getProject();
                IFile file = project.getFile(path);
                if (!file.exists()) {
                    path = e.getPath();
                    file = project.getFile(path);
                    if (!file.exists()) {
                        continue;
                    }
                }
                createLibFolder(p.getFile(path).getParent());
                file.copy(p.getFile(e.getPath().removeFirstSegments(1)).getFullPath(), true, null);
                entries[i] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(),
                        e.getPath().removeFirstSegments(1), e.getInclusionPatterns(), e.getExclusionPatterns(),
                        e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(),
                        e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes());
            }
        }
        newProject.setRawClasspath(entries, null);
    } catch (JavaModelException e) {
        UIPlugin.getDefault().logError(e);
    } catch (CoreException e) {
        UIPlugin.getDefault().logError(e);
    }
}