Example usage for org.eclipse.jdt.core JavaCore newProjectEntry

List of usage examples for org.eclipse.jdt.core JavaCore newProjectEntry

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore newProjectEntry.

Prototype

public static IClasspathEntry newProjectEntry(IPath path) 

Source Link

Document

Creates and returns a new non-exported classpath entry of kind CPE_PROJECT for the project identified by the given absolute path.

Usage

From source file:com.google.gwt.eclipse.core.runtime.GWTProjectsRuntime.java

License:Open Source License

@Override
public IClasspathEntry[] getClasspathEntries() {
    IJavaProject devProject = findDevProject();
    IJavaProject userProject = findUserProject();
    if (devProject != null && userProject != null) {
        return new IClasspathEntry[] { JavaCore.newProjectEntry(devProject.getPath()),
                JavaCore.newProjectEntry(userProject.getPath()) };
    }/*ww w .  ja v a 2  s .c  om*/

    return NO_ICLASSPATH_ENTRIES;
}

From source file:com.mountainminds.eclemma.core.JavaProjectKit.java

License:Open Source License

public void addProjectReference(JavaProjectKit otherProject) throws CoreException {
    addClassPathEntry(JavaCore.newProjectEntry(otherProject.project.getFullPath()));
}

From source file:com.siteview.mde.internal.core.SearchablePluginsManager.java

License:Open Source License

public IClasspathEntry[] computeContainerClasspathEntries() throws CoreException {
    ArrayList result = new ArrayList();

    IMonitorModelBase[] wModels = MonitorRegistry.getWorkspaceModels();
    for (int i = 0; i < wModels.length; i++) {
        IProject project = wModels[i].getUnderlyingResource().getProject();
        if (project.hasNature(JavaCore.NATURE_ID)) {
            result.add(JavaCore.newProjectEntry(project.getFullPath()));
        }/*from www . ja  va 2s. c  om*/
    }
    Iterator iter = fPluginIdSet.iterator();
    while (iter.hasNext()) {
        ModelEntry entry = MonitorRegistry.findEntry(iter.next().toString());
        if (entry != null) {
            boolean addModel = true;
            wModels = entry.getWorkspaceModels();
            for (int i = 0; i < wModels.length; i++) {
                IProject project = wModels[i].getUnderlyingResource().getProject();
                if (project.hasNature(JavaCore.NATURE_ID))
                    addModel = false;
            }
            if (!addModel)
                continue;
            IMonitorModelBase[] models = entry.getExternalModels();
            for (int i = 0; i < models.length; i++) {
                if (models[i].isEnabled())
                    ClasspathUtilCore.addLibraries(models[i], result);
            }
        }
    }

    if (result.size() > 1) {
        // sort
        Map map = new TreeMap();
        for (int i = 0; i < result.size(); i++) {
            IClasspathEntry entry = (IClasspathEntry) result.get(i);
            String key = entry.getPath().lastSegment().toString();
            if (map.containsKey(key)) {
                key += System.currentTimeMillis();
            }
            map.put(key, entry);
        }
        return (IClasspathEntry[]) map.values().toArray(new IClasspathEntry[map.size()]);
    }
    return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]);
}

From source file:com.windowtester.codegen.util.BuildPathUtil.java

License:Open Source License

/**
 * Appends target project build path with source project build path.
 * //w  w w  .  ja  va2s . co m
 * @param targetProject the target project
 * @param sourceProject the source project
 * @throws CoreException
 */
public static void appendProjectBuildPath(IJavaProject targetProject, IJavaProject sourceProject)
        throws CoreException {
    try {
        // copy required entries to target
        IClasspathEntry[] srcEntries = sourceProject.getRawClasspath();
        for (int i = 0; i < srcEntries.length; i++) {
            IClasspathEntry entry = srcEntries[i];
            if (entry.isExported() || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
                continue;
            addToClasspath(targetProject, entry);
        }
        // add the source project as a project entry
        IClasspathEntry srcPrjEntry = JavaCore.newProjectEntry(sourceProject.getPath());
        addToClasspath(targetProject, srcPrjEntry);
    } catch (JavaModelException e) {
        // we interested only in core exceptions
        if (e.getCause() instanceof CoreException) {
            throw (CoreException) e.getCause();
        }
    }
}

From source file:com.windowtester.codegen.util.BuildPathUtil.java

License:Open Source License

public static IClasspathEntry getEntry(String workspaceProject, String variable, String jarName) {
    IProject wsJavaProject = ResourcesPlugin.getWorkspace().getRoot().getProject(workspaceProject);
    IClasspathEntry entry;//w  ww .j av a2s . c o m
    if (wsJavaProject.exists()) {
        entry = JavaCore.newProjectEntry(wsJavaProject.getFullPath());
    } else {
        IPath variablePath = new Path(variable);
        if (jarName != null)
            variablePath = variablePath.append(jarName);
        entry = JavaCore.newVariableEntry(variablePath, null, null);
    }
    return entry;
}

From source file:com.windowtester.codegen.util.BuildPathUtil.java

License:Open Source License

public static IClasspathEntry getEntry(String bundleName, String jarName, boolean hasJavadoc) {

    // check if bundle is a workspace project and if it is then use the project entry 
    // from workspace or otherwise resolve path from the bundle location
    IProject wsJavaProject = ResourcesPlugin.getWorkspace().getRoot().getProject(bundleName);
    if (wsJavaProject.exists())
        return JavaCore.newProjectEntry(wsJavaProject.getFullPath());

    // get the bundle
    Bundle bundle = Platform.getBundle(bundleName);
    if (bundle == null)
        return null;
    String path;/*from  w ww.  j a v a  2 s. c o m*/
    try {
        // get the bundle location
        URL location = bundle.getEntry(jarName);
        // there is no jar in bundle location
        URL jarLocation = null;
        if (location == null) {
            // assume bundle location is jared archive
            location = bundle.getEntry("/");
            jarLocation = Platform.resolve(location);
            // test if bundle is jared
            if (!jarLocation.getFile().endsWith(".jar!/")) {
                // return null if it is not jar
                return null;
            } else {
                // remove jar: protocol from URL at this step
                jarLocation = new URL(jarLocation.getPath());
            }
        } else {
            jarLocation = Platform.resolve(location);
        }
        // normalize path
        path = jarLocation.getFile();
        if (path.endsWith(".jar!/")) {
            path = path.substring(0, path.length() - 2);
        }
    } catch (IOException e) {
        Logger.log(e);
        return null;
    }

    /* $codepro.preprocessor.if version < 3.1 $ 
    return JavaCore.newLibraryEntry(new Path(path), null, null);
            
    $codepro.preprocessor.elseif version >= 3.1 $ */
    org.eclipse.jdt.core.IClasspathAttribute[] attributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES;
    if (hasJavadoc) {
        Bundle docBundle = Platform.getBundle(WINTEST_JAVADOC_PLUGIN_ID);
        if (docBundle != null) {
            URL location = bundle.getEntry(WINTEST_JAVADOC_RELATIVE_PATH);
            if (location != null) {
                attributes = new org.eclipse.jdt.core.IClasspathAttribute[] { JavaCore.newClasspathAttribute(
                        org.eclipse.jdt.core.IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                        location.toExternalForm()) };
            }
        }
    }
    return JavaCore.newLibraryEntry(new Path(path), null, null, ClasspathEntry.NO_ACCESS_RULES, attributes,
            false);

    /* $codepro.preprocessor.endif $ */
}

From source file:de.devboost.eclipse.jloop.AbstractLaunchProjectUpdater.java

License:Open Source License

private IClasspathEntry[] getClasspathEntries(IProject project, Set<String> testProjects) {
    List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();

    IPath path = project.getFullPath().append(projectData.getSourceFolder());
    IClasspathEntry srcEntry = JavaCore.newSourceEntry(path);
    path = new Path("org.eclipse.jdt.launching.JRE_CONTAINER");
    IClasspathEntry jdkEntry = JavaCore.newContainerEntry(path);

    entries.add(srcEntry);//ww  w .jav  a2s  . c om
    entries.add(jdkEntry);
    entries.addAll(getAdditionalClassPathEntries());

    Iterator<String> iterator = testProjects.iterator();
    while (iterator.hasNext()) {
        String projectName = iterator.next();

        IProject nextProject = project.getWorkspace().getRoot().getProject(projectName);
        path = nextProject.getFullPath();
        IClasspathEntry projectEntry = JavaCore.newProjectEntry(path);
        entries.add(projectEntry);
    }
    return entries.toArray(new IClasspathEntry[entries.size()]);
}

From source file:de.ovgu.featureide.core.framework.FrameworkProjectCreator.java

License:Open Source License

/**
 * Creates a new subproject inside a folder
 * /*from ww w .  java  2 s.  c o m*/
 * @param name - project name
 * @param destination - folder which contains the subproject
 * @throws CoreException
 */
public static void createSubprojectFolder(String name, IFolder destination) throws CoreException {
    final IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(name);
    description.setLocation(destination.getLocation());

    final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
    if (project.exists()) {
        return;
    }
    project.create(description, null);
    project.open(null);

    description.setNatureIds(new String[] { JavaCore.NATURE_ID });
    project.setDescription(description, null);

    final IJavaProject javaProject = JavaCore.create(project);
    javaProject.open(null);

    final IFolder binFolder = project.getFolder("bin");
    binFolder.create(true, true, null);
    javaProject.setOutputLocation(binFolder.getFullPath(), null);

    final List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
    final IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
    final LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
    for (final LibraryLocation element : locations) {
        entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null));
    }
    javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
    final IFolder sourceFolder = project.getFolder("src");
    sourceFolder.create(false, true, null);

    final IPackageFragmentRoot srcRoot = javaProject.getPackageFragmentRoot(sourceFolder);
    final IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
    final int oldLength = oldEntries.length;
    final IClasspathEntry[] newEntries = new IClasspathEntry[oldLength + 2];
    System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
    newEntries[oldLength] = JavaCore.newSourceEntry(srcRoot.getPath());
    newEntries[oldLength + 1] = JavaCore.newProjectEntry(destination.getProject().getFullPath());
    javaProject.setRawClasspath(newEntries, null);

    final IFile infoXML = destination.getFile("info.xml");
    if (!infoXML.exists()) {
        createInfoXML(destination);
    }
}

From source file:fr.inria.diverse.k3.ui.templates.k3al.UserEcoreBasicAspectTemplate.java

License:Open Source License

@Override
protected void generateFiles(IProgressMonitor monitor) throws CoreException {
    updateDataFromOptions();//from   w ww  . jav  a2s . co m
    super.generateFiles(monitor);

    k3.language.aspectgenerator.AspectGenerator.aspectGenerate(new ArrayList<String>(),
            "File:///" + _data.projectLocation, _data.projectName, null, //_data.operationName,
            "File:///" + _data.ecoreIFile.getLocation().toOSString(), new ArrayList<String>(), //_data.listNewClass, (no need to create empty classes)
            new ArrayList<String>()//_data.operationParams
    );

    // now also fix the project configuration

    // If this is a plugin
    if (_data.kindsOfProject == KindsOfProject.PLUGIN) {
        ManifestChanger manifestChanger;
        try {
            manifestChanger = new ManifestChanger(project.getFile("META-INF/MANIFEST.MF"));
            manifestChanger.addPluginDependency(_data.ecoreIFile.getProject().getName(), "0.0.0", false, true);
            manifestChanger.writeManifest(project.getFile("META-INF/MANIFEST.MF"));
        } catch (IOException | BundleException e) {
            Activator.logErrorMessage(e.getMessage(), e);
        }
    } else if (_data.kindsOfProject == KindsOfProject.STANDALONE) {
        // must update the build path
        ClasspathHelper.addEntry(project, JavaCore.newProjectEntry(_data.ecoreIFile.getProject().getFullPath()),
                monitor);
    } else if (_data.kindsOfProject == KindsOfProject.MAVEN) {

        ClasspathHelper.addEntry(project, JavaCore.newProjectEntry(_data.ecoreIFile.getProject().getFullPath()),
                monitor);
        // TODO must update the pom.xml
    }

}

From source file:gov.redhawk.ide.codegen.java.internal.SoftPkgRefClasspathContainer.java

License:Open Source License

public SoftPkgRefClasspathContainer(final IPath containerPath, final IJavaProject javaProject)
        throws CoreException {
    this.containerPath = containerPath;
    this.javaProject = javaProject;
    IFile softPkgFile = this.javaProject.getProject()
            .getFile(javaProject.getProject().getName() + SpdPackage.FILE_EXTENSION);

    paths = new ArrayList<IClasspathEntry>();

    ResourceSet set = ScaResourceFactoryUtil.createResourceSet();
    Resource resource;//ww w.  jav  a  2s .  c o  m
    try {
        resource = set.getResource(
                URI.createPlatformResourceURI(softPkgFile.getFullPath().toPortableString(), true), true);
        resource.load(set.getLoadOptions());
    } catch (Exception e) { // SUPPRESS CHECKSTYLE Logged Catch all exception
        throw new CoreException(new Status(Status.ERROR, JavaGeneratorPlugin.PLUGIN_ID,
                "Failed to load spd file: " + softPkgFile, e));
    }
    SoftPkg spd = (SoftPkg) resource.getEObject(SoftPkg.EOBJECT_PATH);
    EList<Implementation> impls = spd.getImplementation();
    // TODO How do we determine which impl to use here?
    Implementation impl = impls.get(0);
    EList<Dependency> deps = impl.getDependency();
    for (Dependency dep : deps) {
        SoftPkgRef ref = dep.getSoftPkgRef();
        if (ref != null) {
            SoftPkg depSpd = ref.getSoftPkg();
            if (depSpd != null && spd.eResource() != null && depSpd.eResource().getURI() != null) {
                if (depSpd.eResource().getURI().isPlatformResource()) {
                    IFile jarFile = ResourcesPlugin.getWorkspace().getRoot()
                            .getFile(new Path(depSpd.eResource().getURI().toPlatformString(true)));
                    paths.add(JavaCore.newProjectEntry(jarFile.getProject().getFullPath()));
                } else {
                    // TODO How do we determine which impl to use here?
                    String jarFile = depSpd.getImplementation().get(0).getCode().getLocalFile().getName();
                    URI uri = depSpd.eResource().getURI().trimSegments(1).appendSegments(jarFile.split("/"));
                    IFileStore store = EFS.getStore(java.net.URI.create(uri.toString()));
                    if (store.fetchInfo().exists()) {
                        File local = store.toLocalFile(EFS.NONE, null);
                        paths.add(JavaCore.newLibraryEntry(new Path(local.getAbsolutePath()), null, null));
                    }
                }
            }
        }
    }
}