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

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

Introduction

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

Prototype

IPath getOutputLocation() throws JavaModelException;

Source Link

Document

Returns the default output location for this project as a workspace- relative absolute path.

Usage

From source file:org.eclipse.pde.internal.core.ClasspathComputer.java

License:Open Source License

public static IClasspathEntry[] getClasspath(IProject project, IPluginModelBase model,
        Map<?, ?> sourceLibraryMap, boolean clear, boolean overrideCompliance) throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    ArrayList<IClasspathEntry> result = new ArrayList<IClasspathEntry>();
    IBuild build = getBuild(project);//from  w  w  w.ja v a2s . com

    // add JRE and set compliance options
    String ee = getExecutionEnvironment(model.getBundleDescription());
    result.add(createEntryUsingPreviousEntry(javaProject, ee, PDECore.JRE_CONTAINER_PATH));
    setComplianceOptions(JavaCore.create(project), ee, overrideCompliance);

    // add pde container
    result.add(createEntryUsingPreviousEntry(javaProject, ee, PDECore.REQUIRED_PLUGINS_CONTAINER_PATH));

    // add own libraries/source
    addSourceAndLibraries(project, model, build, clear, sourceLibraryMap, result);

    IClasspathEntry[] entries = result.toArray(new IClasspathEntry[result.size()]);
    IJavaModelStatus validation = JavaConventions.validateClasspath(javaProject, entries,
            javaProject.getOutputLocation());
    if (!validation.isOK()) {
        PDECore.logErrorMessage(validation.getMessage());
        throw new CoreException(validation);
    }
    return result.toArray(new IClasspathEntry[result.size()]);
}

From source file:org.eclipse.pde.internal.core.ClasspathHelper.java

License:Open Source License

private static Map<IPath, ArrayList<IPath>> getClasspathMap(IProject project, boolean checkExcluded,
        boolean absolutePaths) throws JavaModelException {
    List<Path> excluded = getFoldersToExclude(project, checkExcluded);
    IJavaProject jProject = JavaCore.create(project);
    HashMap<IPath, ArrayList<IPath>> map = new HashMap<IPath, ArrayList<IPath>>();
    IClasspathEntry[] entries = jProject.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
        // most of the paths we get will be project relative, so we need to make the paths relative
        // we will have problems adding an "absolute" path that is workspace relative
        IPath output = null, source = null;
        if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            source = entries[i].getPath();
            output = entries[i].getOutputLocation();
            if (output == null)
                output = jProject.getOutputLocation();
        } else if (entries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            source = entries[i].getPath();
            output = entries[i].getPath();
            if (source.segmentCount() == 1)
                source = new Path(DOT);
        }/*w w w .  j  av a2  s  . co m*/
        if (output != null && !excluded.contains(output)) {
            IResource file = project.findMember(output.removeFirstSegments(1));
            // make the path either relative or absolute
            if (file != null) {
                boolean isLinked = file.isLinked(IResource.CHECK_ANCESTORS);
                if (isLinked || absolutePaths) {
                    IPath location = file.getLocation();
                    if (location != null) {
                        output = location.makeAbsolute();
                    } else {
                        PDECore.log(new Status(IStatus.ERROR, PDECore.PLUGIN_ID,
                                NLS.bind(PDECoreMessages.ClasspathHelper_BadFileLocation, file.getFullPath())));
                        continue;
                    }
                } else {
                    output = output.makeRelative();
                }
            } else
                continue;
            ArrayList<IPath> list = map.get(source);
            if (list == null)
                list = new ArrayList<IPath>();
            list.add(output);
            map.put(source, list);
        }
    }

    // Add additional entries from contributed bundle classpath resolvers
    IBundleClasspathResolver[] resolvers = PDECore.getDefault().getClasspathContainerResolverManager()
            .getBundleClasspathResolvers(project);
    for (int i = 0; i < resolvers.length; i++) {
        Map<IPath, Collection<IPath>> resolved = resolvers[i].getAdditionalClasspathEntries(jProject);
        Iterator<Entry<IPath, Collection<IPath>>> resolvedIter = resolved.entrySet().iterator();
        while (resolvedIter.hasNext()) {
            Map.Entry<IPath, Collection<IPath>> resolvedEntry = resolvedIter.next();
            IPath ceSource = resolvedEntry.getKey();
            ArrayList<IPath> list = map.get(ceSource);
            if (list == null) {
                list = new ArrayList<IPath>();
                map.put(ceSource, list);
            }
            list.addAll(resolvedEntry.getValue());
        }
    }

    return map;
}

From source file:org.eclipse.pde.internal.core.exports.WorkspaceExportHelper.java

License:Open Source License

private Map<String, Set<IPath>> getPluginOutputFolders(IBuildModel buildModel, IJavaProject javaProject)
        throws JavaModelException {
    Map<String, Set<IPath>> outputEntries = new HashMap<String, Set<IPath>>();

    IBuildEntry[] buildEntries = buildModel.getBuild().getBuildEntries();
    for (int i = 0; i < buildEntries.length; i++) {
        String name = buildEntries[i].getName();
        if (name.startsWith(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX)) {
            Set<IPath> outputPaths = new HashSet<IPath>();

            String[] sourceFolders = buildEntries[i].getTokens();
            for (int j = 0; j < sourceFolders.length; j++) {

                IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
                for (int k = 0; k < classpathEntries.length; k++) {
                    if (classpathEntries[k].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                        IPath sourcePath = classpathEntries[k].getPath().removeFirstSegments(1); // Entries include project as first segment
                        if (sourcePath.equals(new Path(sourceFolders[j]))) {
                            IPath outputPath = classpathEntries[k].getOutputLocation();
                            if (outputPath == null) {
                                outputPath = javaProject.getOutputLocation();
                            }/* www.j av a  2  s.com*/
                            outputPaths.add(outputPath.removeFirstSegments(1)); // Entries include project as first segment
                        }
                    }
                }
            }
            if (!outputPaths.isEmpty()) {
                outputEntries.put(name.substring(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX.length()),
                        outputPaths);
            }
        }
    }
    return outputEntries;
}

From source file:org.eclipse.pde.internal.core.project.BundleProjectDescription.java

License:Open Source License

/**
 * Initialize settings from the given project.
 * /*  w ww . j  a v  a 2s .  c o  m*/
 * @param project project
 * @exception CoreException if unable to initialize
 */
private void initialize(IProject project) throws CoreException {
    IContainer root = PDEProject.getBundleRoot(project);
    if (root != project) {
        setBundleRoot(root.getProjectRelativePath());
    }
    IEclipsePreferences node = new ProjectScope(project).getNode(PDECore.PLUGIN_ID);
    if (node != null) {
        setExtensionRegistry(node.getBoolean(ICoreConstants.EXTENSIONS_PROPERTY, true));
        setEquinox(node.getBoolean(ICoreConstants.EQUINOX_PROPERTY, true));
    }
    // export wizard and launch shortcuts
    setExportWizardId(PDEProject.getExportWizard(project));
    setLaunchShortcuts(PDEProject.getLaunchShortcuts(project));
    // location and natures
    setLocationURI(project.getDescription().getLocationURI());
    setNatureIds(project.getDescription().getNatureIds());

    IFile manifest = PDEProject.getManifest(project);
    if (manifest.exists()) {
        Map<?, ?> headers;
        try {
            headers = ManifestElement.parseBundleManifest(manifest.getContents(), null);
            fReadHeaders = headers;
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, e.getMessage(), e));
        } catch (BundleException e) {
            throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, e.getMessage(), e));
        }
        setActivator(getHeaderValue(headers, Constants.BUNDLE_ACTIVATOR));
        setBundleName(getHeaderValue(headers, Constants.BUNDLE_NAME));
        setBundleVendor(getHeaderValue(headers, Constants.BUNDLE_VENDOR));
        String version = getHeaderValue(headers, Constants.BUNDLE_VERSION);
        if (version != null) {
            setBundleVersion(new Version(version));
        }
        IJavaProject jp = JavaCore.create(project);
        if (jp.exists()) {
            setDefaultOutputFolder(jp.getOutputLocation().removeFirstSegments(1));
        }
        ManifestElement[] elements = parseHeader(headers, Constants.FRAGMENT_HOST);
        if (elements != null && elements.length > 0) {
            setHost(getBundleProjectService().newHost(elements[0].getValue(),
                    getRange(elements[0].getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE))));
        }
        String value = getHeaderValue(headers, Constants.BUNDLE_LOCALIZATION);
        if (value != null) {
            setLocalization(new Path(value));
        }
        elements = parseHeader(headers, Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
        if (elements != null && elements.length > 0) {
            String[] keys = new String[elements.length];
            for (int i = 0; i < elements.length; i++) {
                keys[i] = elements[i].getValue();
            }
            setExecutionEnvironments(keys);
        }
        IBuild build = getBuildModel(project);
        elements = parseHeader(headers, Constants.BUNDLE_CLASSPATH);
        IBundleClasspathEntry[] classpath = null;
        if (elements != null && elements.length > 0) {
            List<IBundleClasspathEntry> collect = new ArrayList<IBundleClasspathEntry>();
            for (int i = 0; i < elements.length; i++) {
                String libName = elements[i].getValue();
                IBundleClasspathEntry[] entries = getClasspathEntries(project, build, libName);
                if (entries != null) {
                    for (int j = 0; j < entries.length; j++) {
                        collect.add(entries[j]);
                    }
                }
            }
            classpath = collect.toArray(new IBundleClasspathEntry[collect.size()]);
        } else if (elements == null) {
            // default bundle classpath of '.'
            classpath = getClasspathEntries(project, build, "."); //$NON-NLS-1$
        }
        setBundleClasspath(classpath);
        elements = parseHeader(headers, Constants.BUNDLE_SYMBOLICNAME);
        if (elements != null && elements.length > 0) {
            setSymbolicName(elements[0].getValue());
            String directive = elements[0].getDirective(Constants.SINGLETON_DIRECTIVE);
            if (directive == null) {
                directive = elements[0].getAttribute(Constants.SINGLETON_DIRECTIVE);
            }
            setSingleton("true".equals(directive)); //$NON-NLS-1$
        }
        elements = parseHeader(headers, Constants.IMPORT_PACKAGE);
        if (elements != null) {
            if (elements.length > 0) {
                IPackageImportDescription[] imports = new IPackageImportDescription[elements.length];
                for (int i = 0; i < elements.length; i++) {
                    boolean optional = Constants.RESOLUTION_OPTIONAL
                            .equals(elements[i].getDirective(Constants.RESOLUTION_DIRECTIVE))
                            || "true".equals(elements[i].getAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE)); //$NON-NLS-1$
                    String pv = elements[i].getAttribute(ICoreConstants.PACKAGE_SPECIFICATION_VERSION);
                    if (pv == null) {
                        pv = elements[i].getAttribute(Constants.VERSION_ATTRIBUTE);
                    }
                    imports[i] = getBundleProjectService().newPackageImport(elements[i].getValue(),
                            getRange(pv), optional);
                }
                setPackageImports(imports);
            } else {
                // empty header - should be maintained
                setHeader(Constants.IMPORT_PACKAGE, ""); //$NON-NLS-1$
            }
        }
        elements = parseHeader(headers, Constants.EXPORT_PACKAGE);
        if (elements != null && elements.length > 0) {
            IPackageExportDescription[] exports = new IPackageExportDescription[elements.length];
            for (int i = 0; i < elements.length; i++) {
                ManifestElement exp = elements[i];
                String pv = exp.getAttribute(ICoreConstants.PACKAGE_SPECIFICATION_VERSION);
                if (pv == null) {
                    pv = exp.getAttribute(Constants.VERSION_ATTRIBUTE);
                }
                String directive = exp.getDirective(ICoreConstants.FRIENDS_DIRECTIVE);
                boolean internal = "true".equals(exp.getDirective(ICoreConstants.INTERNAL_DIRECTIVE)) //$NON-NLS-1$
                        || directive != null;
                String[] friends = null;
                if (directive != null) {
                    friends = ManifestElement.getArrayFromList(directive);
                }
                exports[i] = getBundleProjectService().newPackageExport(exp.getValue(), getVersion(pv),
                        !internal, friends);
            }
            setPackageExports(exports);
        }
        elements = parseHeader(headers, Constants.REQUIRE_BUNDLE);
        if (elements != null && elements.length > 0) {
            IRequiredBundleDescription[] req = new IRequiredBundleDescription[elements.length];
            for (int i = 0; i < elements.length; i++) {
                ManifestElement rb = elements[i];
                boolean reexport = Constants.VISIBILITY_REEXPORT
                        .equals(rb.getDirective(Constants.VISIBILITY_DIRECTIVE))
                        || "true".equals(rb.getAttribute(ICoreConstants.REPROVIDE_ATTRIBUTE)); //$NON-NLS-1$
                boolean optional = Constants.RESOLUTION_OPTIONAL
                        .equals(rb.getDirective(Constants.RESOLUTION_DIRECTIVE))
                        || "true".equals(rb.getAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE)); //$NON-NLS-1$
                req[i] = getBundleProjectService().newRequiredBundle(rb.getValue(),
                        getRange(rb.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE)), optional, reexport);
            }
            setRequiredBundles(req);
        }
        String lazy = getHeaderValue(headers, ICoreConstants.ECLIPSE_AUTOSTART);
        if (lazy == null) {
            lazy = getHeaderValue(headers, ICoreConstants.ECLIPSE_LAZYSTART);
            if (lazy == null) {
                setActivationPolicy(getHeaderValue(headers, Constants.BUNDLE_ACTIVATIONPOLICY));
            }
        }
        if ("true".equals(lazy)) { //$NON-NLS-1$
            setActivationPolicy(Constants.ACTIVATION_LAZY);
        }
        String latest = TargetPlatformHelper.getTargetVersionString();
        IPluginModelBase model = PluginRegistry.findModel(project);
        if (model != null) {
            IPluginBase base = model.getPluginBase();
            String tv = TargetPlatformHelper.getTargetVersionForSchemaVersion(base.getSchemaVersion());
            if (!tv.equals(latest)) {
                setTargetVersion(tv);
            }
        }
        if (build != null) {
            IBuildEntry entry = build.getEntry(IBuildEntry.BIN_INCLUDES);
            if (entry != null) {
                String[] tokens = entry.getTokens();
                if (tokens != null && tokens.length > 0) {
                    List<String> strings = new ArrayList<String>();
                    for (int i = 0; i < tokens.length; i++) {
                        strings.add(tokens[i]);
                    }
                    // remove the default entries
                    strings.remove("META-INF/"); //$NON-NLS-1$
                    String[] names = ProjectModifyOperation.getLibraryNames(this);
                    if (names != null) {
                        for (int i = 0; i < names.length; i++) {
                            strings.remove(names[i]);
                            // if the library is a folder, account for trailing slash - see bug 306991
                            IPath path = new Path(names[i]);
                            if (path.getFileExtension() == null) {
                                strings.remove(names[i] + "/"); //$NON-NLS-1$
                            }
                        }
                    }
                    // set left overs
                    if (!strings.isEmpty()) {
                        IPath[] paths = new IPath[strings.size()];
                        for (int i = 0; i < strings.size(); i++) {
                            paths[i] = new Path(strings.get(i));
                        }
                        setBinIncludes(paths);
                    }
                }
            }
        }
    }
}

From source file:org.eclipse.pde.internal.launching.launcher.LaunchArgumentsHelper.java

License:Open Source License

/**
 * Returns the path to the equinox launcher jar.  If the launcher is available
 * in the workspace, the packageName will be used to determine the expected output
 * location.//  ww  w .jav  a2s.co m
 * 
 * @param packageName name of the launcher package, typically {@link IPDEBuildConstants#BUNDLE_EQUINOX_LAUNCHER}
 * @return the path to the equinox launcher jar or <code>null</code> 
 * @throws CoreException
 */
private static String getEquinoxStartupPath(String packageName) throws CoreException {
    // See if PDE has the launcher in the workspace or target
    IPluginModelBase model = PluginRegistry.findModel(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER);
    if (model != null) {
        IResource resource = model.getUnderlyingResource();
        if (resource == null) {
            // Found in the target
            String installLocation = model.getInstallLocation();
            if (installLocation == null) {
                return null;
            }

            File bundleFile = new File(installLocation);
            if (!bundleFile.isDirectory()) {
                // The launcher bundle is usually jarred, just return the bundle root
                return installLocation;
            }

            // Unjarred bundle, search for the built jar at the root of the folder
            File[] files = bundleFile.listFiles(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.indexOf(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER) >= 0;
                }
            });
            for (int i = 0; i < files.length; i++) {
                if (files[i].isFile()) {
                    return files[i].getPath();
                }
            }

            // Source bundle from git://git.eclipse.org/gitroot/equinox/rt.equinox.framework.git
            File binFolder = new File(bundleFile, "bin"); //$NON-NLS-1$
            if (binFolder.isDirectory()) {
                return binFolder.getPath();
            }
            return null;
        }

        // Found in the workspace
        IProject project = resource.getProject();
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject jProject = JavaCore.create(project);
            IClasspathEntry[] entries = jProject.getRawClasspath();
            for (int i = 0; i < entries.length; i++) {
                int kind = entries[i].getEntryKind();
                if (kind == IClasspathEntry.CPE_SOURCE || kind == IClasspathEntry.CPE_LIBRARY) {
                    IPackageFragmentRoot[] roots = jProject.findPackageFragmentRoots(entries[i]);
                    for (int j = 0; j < roots.length; j++) {
                        if (roots[j].getPackageFragment(packageName).exists()) {
                            // if source folder, find the output folder
                            if (kind == IClasspathEntry.CPE_SOURCE) {
                                IPath path = entries[i].getOutputLocation();
                                if (path == null)
                                    path = jProject.getOutputLocation();
                                path = path.removeFirstSegments(1);
                                return project.getLocation().append(path).toOSString();
                            }
                            // else if is a library jar, then get the location of the jar itself
                            IResource jar = roots[j].getResource();
                            if (jar != null) {
                                return jar.getLocation().toOSString();
                            }
                        }
                    }
                }
            }
        }
    }

    // No PDE model, see if the launcher bundle is installed
    Bundle bundle = Platform.getBundle(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER);
    if (bundle != null) {
        try {
            URL url = FileLocator.resolve(bundle.getEntry("/")); //$NON-NLS-1$
            url = FileLocator.toFileURL(url);
            String path = url.getFile();
            if (path.startsWith("file:")) //$NON-NLS-1$
                path = path.substring(5);
            path = new File(path).getAbsolutePath();
            if (path.endsWith("!")) //$NON-NLS-1$
                path = path.substring(0, path.length() - 1);
            return path;
        } catch (IOException e) {
        }
    }
    return null;
}

From source file:org.eclipse.pde.internal.launching.launcher.LaunchArgumentsHelper.java

License:Open Source License

private static String getStartupJarPath() throws CoreException {
    IPluginModelBase model = PluginRegistry.findModel("org.eclipse.platform"); //$NON-NLS-1$
    if (model != null && model.getUnderlyingResource() != null) {
        IProject project = model.getUnderlyingResource().getProject();
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject jProject = JavaCore.create(project);
            IPackageFragmentRoot[] roots = jProject.getPackageFragmentRoots();
            for (int i = 0; i < roots.length; i++) {
                if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE
                        && roots[i].getPackageFragment("org.eclipse.core.launcher").exists()) { //$NON-NLS-1$
                    IPath path = jProject.getOutputLocation().removeFirstSegments(1);
                    return project.getLocation().append(path).toOSString();
                }//  ww  w . jav  a2 s .c o  m
            }
        }
        if (project.getFile("startup.jar").exists()) //$NON-NLS-1$
            return project.getFile("startup.jar").getLocation().toOSString(); //$NON-NLS-1$
    }
    File startupJar = new Path(TargetPlatform.getLocation()).append("startup.jar").toFile(); //$NON-NLS-1$

    // if something goes wrong with the preferences, fall back on the startup.jar 
    // in the running eclipse.  
    if (!startupJar.exists())
        startupJar = new Path(TargetPlatform.getDefaultLocation()).append("startup.jar").toFile(); //$NON-NLS-1$

    return startupJar.exists() ? startupJar.getAbsolutePath() : null;
}

From source file:org.eclipse.pde.internal.launching.launcher.LauncherUtils.java

License:Open Source License

private static String getTimeStamp(IProject project) {
    IJavaProject jp = JavaCore.create(project);
    try {/*from  www .ja va 2 s . c o  m*/
        long timeStamp = 0;
        IClasspathEntry[] entries = jp.getResolvedClasspath(true);
        for (int i = 0; i < entries.length; i++) {
            if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                File file;
                IPath location = entries[i].getOutputLocation();
                if (location == null)
                    location = jp.getOutputLocation();
                IResource res = project.getWorkspace().getRoot().findMember(location);
                IPath path = res == null ? null : res.getLocation();
                if (path == null)
                    continue;
                file = path.toFile();
                Stack<File> files = new Stack<File>();
                files.push(file);
                while (!files.isEmpty()) {
                    file = files.pop();
                    if (file.isDirectory()) {
                        File[] children = file.listFiles();
                        if (children != null) {
                            for (int j = 0; j < children.length; j++)
                                files.push(children[j]);
                        }
                    } else if (file.getName().endsWith(".class") && timeStamp < file.lastModified()) //$NON-NLS-1$
                        timeStamp = file.lastModified();
                }
            }
        }
        IFile[] otherFiles = new IFile[] { PDEProject.getManifest(project),
                PDEProject.getBuildProperties(project) };
        for (int i = 0; i < otherFiles.length; i++) {
            IFile file = otherFiles[i];
            if (file != null) {
                long fileTimeStamp = file.getRawLocation().toFile().lastModified();
                if (timeStamp < fileTimeStamp)
                    timeStamp = fileTimeStamp;
            }
        }
        return Long.toString(timeStamp);
    } catch (JavaModelException e) {
    }
    return "0"; //$NON-NLS-1$
}

From source file:org.eclipse.pde.internal.ui.properties.SelfHostingPropertyPage.java

License:Open Source License

private String[] getOutputFolders() {
    IProject project = (IProject) getElement().getAdapter(IProject.class);
    ArrayList<String> list = new ArrayList<String>();
    try {/*from  w  w w .  ja  v  a  2  s.co  m*/
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject jProject = JavaCore.create(project);
            list.add(jProject.getOutputLocation().toString());
            IClasspathEntry[] entries = jProject.getRawClasspath();
            for (int i = 0; i < entries.length; i++) {
                IClasspathEntry entry = entries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                        && entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    IPath path = entry.getOutputLocation();
                    if (path != null)
                        list.add(path.toString());
                }
            }
        }
    } catch (JavaModelException e) {
    } catch (CoreException e) {
    }
    return list.toArray(new String[list.size()]);
}

From source file:org.eclipse.qvt.declarative.execution.ui.launching.configuration.DeclarativeQVTMainTab.java

License:Open Source License

private static IFile getSourceFile(String executablePath) {
    try {/*  w  ww . j a  va 2 s  . com*/
        IFile executableFile = getFileFromURI(executablePath);
        IJavaProject javaProject = JavaCore.create(executableFile.getProject());
        IPath executableRelativePath = executableFile.getFullPath()
                .removeFirstSegments(javaProject.getOutputLocation().segmentCount());
        IPath sourceRelativePath = executableRelativePath.removeFileExtension().removeFileExtension()
                .addFileExtension("qvtr");
        for (IClasspathEntry classpathEntry : javaProject.getRawClasspath()) {
            if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath classPathPath = classpathEntry.getPath();
                IFolder classPathFolder = getWorkspaceRoot().getFolder(classPathPath);
                IFile searchedFile = classPathFolder.getFile(sourceRelativePath);
                if (searchedFile.exists()) {
                    return searchedFile;
                }
            }
        }
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:org.eclipse.sirius.editor.utils.WorkspaceClassLoading.java

License:Open Source License

private void computeURLs(IProject project, List<URL> uRLs) {
    final IJavaProject javaProject = JavaCore.create(project);
    try {/*from   ww w .  j  a v a2s  .  c  o  m*/
        for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                final IPath output = entry.getOutputLocation();
                if (output != null) {
                    IFile reference = ResourcesPlugin.getWorkspace().getRoot().getFile(output);
                    if (reference.exists()) {
                        URL url;
                        try {
                            url = reference.getLocation().toFile().toURI().toURL();
                            uRLs.add(url);
                        } catch (MalformedURLException e) {
                            /*
                             * We don't know how to handle this class path
                             * entry.
                             */
                        }
                    }

                }
            }
        }
        /*
         * Add the default output location to the classpath anyway since
         * source folders are not required to have their own
         */
        final IPath output = javaProject.getOutputLocation();
        if (output != null) {
            IFolder reference = ResourcesPlugin.getWorkspace().getRoot().getFolder(output);
            if (reference.exists() && reference.getLocation() != null) {
                URL url;
                File file = reference.getLocation().toFile();
                try {
                    if (file != null && file.exists()) {
                        url = file.toURI().toURL();
                        uRLs.add(url);
                    }
                } catch (MalformedURLException e) {
                    /*
                     * the given path does not map to a file which can
                     * actually be mapped to an url, ignore it.
                     */
                }
            }

        }
    } catch (JavaModelException e) {
    }
}