List of usage examples for org.eclipse.jdt.internal.core JavaModelManager getUserLibraryManager
public static UserLibraryManager getUserLibraryManager()
From source file:net.rim.ejde.internal.util.ImportUtils.java
License:Open Source License
static protected IJavaProject internalCreateJavaProject(Project legacyProject, IProject project, int importType, String userLib, IPath REPath, IProgressMonitor monitor) throws CoreException { try {/* w ww . ja v a 2s. c om*/ if (legacyProject == null) throw new IllegalArgumentException( "Can't create Eclipse Java Project from undefind legacy project!"); _log.debug("Create IJavaProject [" + legacyProject.getDisplayName() + "]"); monitor.beginTask("Importing project " + legacyProject.getDisplayName(), 10); monitor.worked(1); if (project == null) return null; // create a IJavaProject IJavaProject eclipseJavaProject = JavaCore.create(project); // set project options initializeProjectOptions(eclipseJavaProject); monitor.worked(2); // get source folders, e.g. src and res IPath[] defaultSources = getCustomSourceFolders(legacyProject); // create classpath entries for source folders IClasspathEntry[] sourceFolderEntries = createSourceFolders(project, defaultSources); IClasspathEntry[] importedLibraries = resolveProjectImports(legacyProject, project); String[] dependencies = getDependsOnProjectNames(legacyProject); IClasspathEntry[] dependentProjects = resolveDependentProjects(dependencies); IClasspathEntry[] jreEntries = getREClasspathEntries(REPath); List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); addEntryToList(classpathEntries, sourceFolderEntries); addEntryToList(classpathEntries, importedLibraries); addEntryToList(classpathEntries, dependentProjects); addEntryToList(classpathEntries, jreEntries); classpathEntries = applyExclusionPatterns(project, legacyProject, classpathEntries); // add workspace imports as a user library if (!StringUtils.isBlank(userLib)) { UserLibrary library = JavaModelManager.getUserLibraryManager().getUserLibrary(userLib); if (null != library) { IPath path = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID).append(userLib); IClasspathEntry userLibEntry = JavaCore.newContainerEntry(path); if (!classpathEntries.contains(userLibEntry)) { classpathEntries.add(userLibEntry); } } } if (!eclipseJavaProject.isOpen()) { try { eclipseJavaProject.open(new NullProgressMonitor()); } catch (JavaModelException e) { _log.error(e.getMessage()); throw new CoreException(StatusFactory.createErrorStatus(e.getMessage())); } } setRawClassPath(eclipseJavaProject, classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()])); monitor.worked(2); // link or copy files if (importType == LegacyImportHelper.COPY_IMPORT) { copySourceFiles(legacyProject, eclipseJavaProject.getProject()); int AEPNumber = legacyProject.getNumEntries(); // Copy AEP source files as well. for (int i = 0; i < AEPNumber; i++) { copySourceFiles(legacyProject.getEntry(i), eclipseJavaProject.getProject()); } } else { /** * String: the package id, the container key. Set<File>: the files belonging to the package * */ ResourcesBuffer resourcesBuffer; resourcesBuffer = createProjectResourcesBuffer(legacyProject); createBulkLinks(eclipseJavaProject, resourcesBuffer, legacyProject); int AEPNumber = legacyProject.getNumEntries(); // link AEP source files as well. for (int i = 0; i < AEPNumber; i++) { resourcesBuffer = createProjectResourcesBuffer(legacyProject.getEntry(i)); createBulkLinks(eclipseJavaProject, resourcesBuffer, legacyProject.getEntry(i)); } } monitor.worked(6); return eclipseJavaProject; } finally { monitor.done(); } }
From source file:net.rim.ejde.internal.util.WorkspaceDependencyUtils.java
License:Open Source License
/** * Generates a valid name of the BlackBerry user library for the given <code>workspaceName</code>. * * @param workspaceName//from ww w . ja v a 2 s.c om * @return */ static public String generateBBLibName(String workspaceName) { UserLibraryManager userLibMgr = JavaModelManager.getUserLibraryManager(); UserLibrary rimLibs; String libName = BLACIBERRY_LIB_PREFIX + workspaceName; for (int i = 1; i < 100; i++) { rimLibs = userLibMgr.getUserLibrary(libName); if (rimLibs != null) { libName = BLACIBERRY_LIB_PREFIX + workspaceName + "_" + i; } else { return libName; } } return IConstants.EMPTY_STRING; }
From source file:net.rim.ejde.internal.util.WorkspaceDependencyUtils.java
License:Open Source License
/** * * @param classPathEntries/*from w w w .j a v a 2s.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:net.rim.ejde.internal.util.WorkspaceDependencyUtils.java
License:Open Source License
/** * *//*from w ww . j av a 2 s .co m*/ static public void removeUserLibrary(String userLibrary) { UserLibraryManager userLibMgr = JavaModelManager.getUserLibraryManager(); if (null != userLibrary) { userLibMgr.removeUserLibrary(userLibrary); } }
From source file:net.rim.ejde.internal.util.WorkspaceDependencyUtils.java
License:Open Source License
/** * *///from www.j a v a 2s . c om static public IClasspathEntry[] getClasspathEntriesForUserLibrary(String userLibrary) { IClasspathEntry[] result = null; UserLibraryManager userLibMgr = JavaModelManager.getUserLibraryManager(); UserLibrary rimLibs = userLibMgr.getUserLibrary(userLibrary); if (null == rimLibs) return new IClasspathEntry[] {}; result = rimLibs.getEntries(); if (0 < result.length) return result; return new IClasspathEntry[] {}; }
From source file:net.rim.ejde.internal.util.WorkspaceDependencyUtils.java
License:Open Source License
static public void addUserLibraryToProject(String userLibrary, IJavaProject iJavaProject, IProgressMonitor monitor) {/*from www . java 2s . c o m*/ UserLibrary library = JavaModelManager.getUserLibraryManager().getUserLibrary(userLibrary); if (null != library && null != iJavaProject) { UserLibraryClasspathContainer container = new UserLibraryClasspathContainer(userLibrary); IPath path = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID).append(userLibrary); try { JavaCore.setClasspathContainer(path, new IJavaProject[] { iJavaProject }, new IClasspathContainer[] { container }, null == monitor ? new NullProgressMonitor() : monitor instanceof SubProgressMonitor ? monitor : new SubProgressMonitor(monitor, 1)); } catch (Throwable e) { _log.error(e.getMessage(), e); } finally { monitor.done(); } } }
From source file:net.rim.ejde.internal.util.WorkspaceDependencyUtils.java
License:Open Source License
static public void addUserLibraryToProjects(String userLibrary, IJavaProject[] iJavaProjects, IProgressMonitor monitor) {//from ww w.jav a 2 s. c o m UserLibrary library = JavaModelManager.getUserLibraryManager().getUserLibrary(userLibrary); if (null != library && null != iJavaProjects && 0 < iJavaProjects.length) { UserLibraryClasspathContainer[] containers = new UserLibraryClasspathContainer[iJavaProjects.length]; IPath path; path = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID).append(userLibrary); for (int i = 0; i < iJavaProjects.length; i++) containers[i] = new UserLibraryClasspathContainer(userLibrary); try { JavaCore.setClasspathContainer(path, iJavaProjects, containers, null == monitor ? new NullProgressMonitor() : monitor instanceof SubProgressMonitor ? monitor : new SubProgressMonitor(monitor, 1)); } catch (Throwable e) { _log.error(e.getMessage(), e); } finally { monitor.done(); } } }
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.c o m // 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); } }
From source file:org.eclipse.jst.common.project.facet.core.libprov.user.UserLibraryProviderInstallOperationConfig.java
License:Open Source License
/** * Resolve the referenced user libraries into a collection of classpath entries that reference * physical libraries. /*from w w w . j av a 2 s . c om*/ * * @return the classpath entries contributed by the referenced user libraries */ public synchronized Collection<IClasspathEntry> resolve() { final List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); final UserLibraryManager userLibraryManager = JavaModelManager.getUserLibraryManager(); for (String libraryName : this.libraryNames) { final UserLibrary userLibrary = userLibraryManager.getUserLibrary(libraryName); if (userLibrary != null) { for (IClasspathEntry cpe : userLibrary.getEntries()) { entries.add(cpe); } } } return Collections.unmodifiableCollection(entries); }
From source file:org.eclipse.jst.common.project.facet.ui.libprov.user.internal.DownloadLibraryWizardMainPage.java
License:Open Source License
private static boolean isUserLibraryDefined(final String name) { final UserLibraryManager userLibraryManager = JavaModelManager.getUserLibraryManager(); return (userLibraryManager.getUserLibrary(name) != null); }