Example usage for org.eclipse.jdt.internal.core UserLibraryManager setUserLibrary

List of usage examples for org.eclipse.jdt.internal.core UserLibraryManager setUserLibrary

Introduction

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

Prototype

public void setUserLibrary(String libName, IClasspathEntry[] entries, boolean isSystemLibrary) 

Source Link

Usage

From source file:net.rim.ejde.internal.util.WorkspaceDependencyUtils.java

License:Open Source License

/**
 *
 * @param classPathEntries/*from   ww  w  .jav  a2  s  .c  om*/
 * @param userLibrary
 * @throws CoreException
 *
 */
static public void storeDependenciesAsUserLibrary(IClasspathEntry[] classPathEntries, String userLibrary)
        throws CoreException {
    if (classPathEntries == null || classPathEntries.length == 0) {
        return;
    }
    UserLibraryManager userLibMgr = JavaModelManager.getUserLibraryManager();
    UserLibrary rimLibs = userLibMgr.getUserLibrary(userLibrary);

    boolean isSysLib = false;

    if (rimLibs != null) {
        // this should not happen
        throw new CoreException(StatusFactory.createErrorStatus("BlackBerry user library already exist."));
    }

    String classpathEntriesSequence = "";

    for (IClasspathEntry classpathEntry : classPathEntries) {
        classpathEntriesSequence = "<" + classpathEntry.toString() + ">";
    }

    _log.debug("Storing User-Library [" + userLibrary + "] as [" + classpathEntriesSequence + "]");

    userLibMgr.setUserLibrary(userLibrary, classPathEntries, isSysLib);
}

From source file:org.eclipse.jst.common.project.facet.core.libprov.user.internal.DownloadableLibrary.java

License:Open Source License

public void download(final File destFolder, final String localLibraryName, final IProgressMonitor monitor)

        throws CoreException, InterruptedException

{
    try {/*w  w w  .  j a  v  a  2  s.  com*/
        // Create the directory where the downloaded archive will be written to
        // and where the exploded library will reside.

        destFolder.mkdirs();

        // Make sure that destination folder is empty and clear it out if necessary.

        for (File f : destFolder.listFiles()) {
            delete(f);
        }

        // Define the temporary download file.

        final File destFile = new File(destFolder, "download.zip"); //$NON-NLS-1$

        // Perform the download.

        download(new URL(this.url), destFile, monitor);

        // Unzip the downloaded file.

        unzip(destFile, destFolder, monitor);

        // Delete the original downloaded file.

        destFile.delete();

        // Configure the user library.

        final List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
        final IPath destFolderPath = new Path(destFolder.getPath());

        for (File jarFile : findAllJarFiles(destFolder)) {
            final IPath jarPath = new Path(jarFile.getPath());
            final IPath relativeJarPath = jarPath.makeRelativeTo(destFolderPath);

            if (!shouldInclude(relativeJarPath)) {
                continue;
            }

            IPath sourceArchivePath = null;
            String javadocArchivePath = null;

            final DownloadableLibraryComponentAttributes attachment = getComponentAttributes(relativeJarPath);

            if (attachment != null) {
                final String sourceArchivePathString = attachment.getSourceArchivePath();

                if (sourceArchivePathString != null) {
                    sourceArchivePath = destFolderPath.append(sourceArchivePathString);
                }

                javadocArchivePath = attachment.getJavadocArchivePath();

                if (javadocArchivePath != null) {
                    final int separator = javadocArchivePath.indexOf('!');
                    final IPath pathInArchive;

                    if (separator == -1) {
                        pathInArchive = null;
                    } else {
                        pathInArchive = new Path(javadocArchivePath.substring(separator + 1));
                        javadocArchivePath = javadocArchivePath.substring(0, separator);
                    }

                    final IPath p = destFolderPath.append(javadocArchivePath);

                    if (pathInArchive != null || p.toFile().isFile()) {
                        javadocArchivePath = "jar:file:/" + p.toPortableString() + "!/"; //$NON-NLS-1$ //$NON-NLS-2$

                        if (javadocArchivePath != null) {
                            javadocArchivePath = javadocArchivePath + pathInArchive.toPortableString() + "/"; //$NON-NLS-1$
                        }
                    } else {
                        javadocArchivePath = "file:/" + p.toPortableString() + "/"; //$NON-NLS-1$ //$NON-NLS-2$
                    }
                }
            }

            final IClasspathEntry cpe = newLibraryEntry(jarPath, sourceArchivePath, javadocArchivePath);
            entries.add(cpe);
        }

        final IClasspathEntry[] entriesArray = entries.toArray(new IClasspathEntry[entries.size()]);

        final UserLibraryManager userLibraryManager = JavaModelManager.getUserLibraryManager();
        userLibraryManager.setUserLibrary(localLibraryName, entriesArray, false);
    } catch (IOException e) {
        final IStatus st = new Status(IStatus.ERROR, PLUGIN_ID, Resources.failedWhileDownloading, e);
        throw new CoreException(st);
    }
}