List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:com.google.gdt.eclipse.designer.smartgwt.model.widgets.VersionTest.java
License:Open Source License
/** * Some users try to use old version of SmartGWT, but tell us that they use new version. We should * check version and fail with good message. * <p>//from w w w .j av a 2 s .c om * http://fogbugz.instantiations.com/fogbugz/default.asp?48002 */ @DisposeProjectAfter public void test_oldVersion() throws Exception { dontUseSharedGWTState(); // replace SmartGWT jar, use old version { IClasspathEntry[] entries = m_javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getPath().toString().endsWith("smartgwt.jar")) { entries = (IClasspathEntry[]) ArrayUtils.remove(entries, i); break; } } m_javaProject.setRawClasspath(entries, null); waitForAutoBuild(); // add jar for version 2.1 m_testProject.addExternalJar(SmartGwtTests.LOCATION_OLD + "/smartgwt.jar"); } // try to parse, failure expected try { parseJavaInfo("// filler filler filler filler filler", "public class Test implements EntryPoint {", " public void onModuleLoad() {", " RootPanel.get();", " }", "}"); fail(); } catch (DesignerException e) { assertEquals(IExceptionConstants.INCORRECT_VERSION, e.getCode()); } }
From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectCopyToProvider.java
License:Open Source License
private IClasspathEntry[] collectClasspathEntries(ManagedApi[] apis) throws CoreException { // remove duplication by using the jar name as the key Map<String, IClasspathEntry> jarmap = new HashMap<String, IClasspathEntry>(); for (ManagedApi api : apis) { IClasspathEntry[] classpathEntries = api.getClasspathEntries(); for (IClasspathEntry entry : classpathEntries) { jarmap.put(entry.getPath().lastSegment(), entry); }//from ww w .j a v a2 s.c om } return jarmap.values().toArray(new IClasspathEntry[jarmap.size()]); }
From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectCopyToProvider.java
License:Open Source License
private void copyJarFiles(final ManagedApi[] apis, final IFolder targetFolder) throws CoreException { final IClasspathEntry[] classpathEntries = collectClasspathEntries(apis); Job copyApiJob = new Job("Copy jar files for added APIs") { @Override/*from w w w .ja va 2s . c o m*/ protected IStatus run(IProgressMonitor monitor) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); for (IClasspathEntry entry : classpathEntries) { IFile sourceFile = workspaceRoot.getFile(entry.getPath()); IFile destFile = getTargetFile(targetFolder, entry); try { if (destFile.exists()) { continue; } if (sourceFile != null) { ResourceUtils.createFile(destFile.getFullPath(), sourceFile.getContents(true)); } } catch (CoreException e) { ManagedApiLogger.log(ManagedApiLogger.ERROR, MessageFormat .format("CoreException while copying file {0} to {1}", sourceFile, destFile)); } } return Status.OK_STATUS; } }; copyApiJob.setSystem(true); copyApiJob.setRule(targetFolder); copyApiJob.schedule(); }
From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectCopyToProvider.java
License:Open Source License
private IFile getTargetFile(IFolder targetFolder, IClasspathEntry entry) { IFile destFile = targetFolder.getFile(entry.getPath().lastSegment()); return destFile; }
From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectCopyToProvider.java
License:Open Source License
private void removeJarFiles(ManagedApi[] oldApis, ManagedApi[] newApis, IFolder targetFolder) throws CoreException { final Set<IFile> removalSet = new HashSet<IFile>(); IClasspathEntry[] oldClasspathEntries = collectClasspathEntries(oldApis); for (IClasspathEntry entry : oldClasspathEntries) { if (!entry.getPath().toString().contains(ManagedApiPlugin.DEPENDENCIES_FOLDER_NAME)) { removalSet.add(getTargetFile(targetFolder, entry)); }// ww w .j a v a 2 s.co m } IClasspathEntry[] newClasspathEntries = collectClasspathEntries(newApis); for (IClasspathEntry entry : newClasspathEntries) { removalSet.remove(getTargetFile(targetFolder, entry)); } Job deleteApiJob = new Job("Delete jars for removed APIs") { @Override protected IStatus run(IProgressMonitor monitor) { for (IFile file : removalSet) { try { if (file.exists()) { file.delete(true, new NullProgressMonitor()); } } catch (CoreException e) { ManagedApiLogger.log(ManagedApiLogger.ERROR, MessageFormat.format("CoreException while deleting file {0}", file)); } } return Status.OK_STATUS; } }; deleteApiJob.setSystem(true); deleteApiJob.setRule(targetFolder); deleteApiJob.schedule(); }
From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectImpl.java
License:Open Source License
public static String getAndroidSdk(IProject androidProject) throws JavaModelException { if (androidProject == null) { return null; }/*from w w w. j a v a2s. c o m*/ IJavaProject androidJavaProject = JavaCore.create(androidProject); List<IClasspathEntry> rawClasspathList = new ArrayList<IClasspathEntry>(); rawClasspathList.addAll(Arrays.asList(androidJavaProject.getRawClasspath())); for (IClasspathEntry e : rawClasspathList) { if (e.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { continue; } IClasspathContainer c = JavaCore.getClasspathContainer(e.getPath(), androidJavaProject); if (c.getDescription().contains(ANDROID_2_CLASSPATH_CONTAINER)) { return ANDROID2_ENVIRONMENT; } else if (c.getDescription().contains(ANDROID_3_CLASSPATH_CONTAINER) || c.getDescription().contains(ANDROID_4_CLASSPATH_CONTAINER)) { return ANDROID3_ENVIRONMENT; } } return null; }
From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectImpl.java
License:Open Source License
public ManagedApi[] getManagedApis() { List<ManagedApi> installedApis = new ArrayList<ManagedApi>(); if (eProject != null) { IJavaProject project = eProject.getJavaProject(); if (project != null) { try { IClasspathEntry[] rawClasspath = project.getRawClasspath(); for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (ManagedApiPlugin.API_CONTAINER_PATH.isPrefixOf(entry.getPath())) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); if (container instanceof ManagedApiContainer) { ManagedApiContainer managedApiContainer = (ManagedApiContainer) container; installedApis.add(managedApiContainer.getManagedApi()); }// w w w .j a va 2 s . com } } } } catch (JavaModelException e) { ManagedApiLogger.warn(e, "Error reading classpath"); } } } return installedApis.toArray(new ManagedApi[installedApis.size()]); }
From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectImpl.java
License:Open Source License
private void removeManagedApiClasspathEntries() { Job writeRawClasspathJob = new Job("Remove managed api entries from classpath") { @Override/*from w w w. j av a 2 s .c om*/ protected IStatus run(IProgressMonitor monitor) { IStatus returnStatus = Status.OK_STATUS; IClasspathEntry[] initialRawClasspath; try { initialRawClasspath = eProject.getJavaProject().getRawClasspath(); List<IClasspathEntry> rawClasspathList = new ArrayList<IClasspathEntry>( initialRawClasspath.length); for (IClasspathEntry entry : initialRawClasspath) { String basePath = entry.getPath().segment(0); if (!(basePath.equals(ManagedApiPlugin.API_CONTAINER_PATH_ID))) { rawClasspathList.add(entry); } } IClasspathEntry[] newRawClasspath = rawClasspathList .toArray(new IClasspathEntry[rawClasspathList.size()]); eProject.setRawClasspath(newRawClasspath, new NullProgressMonitor()); } catch (JavaModelException e) { ManagedApiLogger.error(e, "Caught JavaModelException trying to rewrite raw classpath"); returnStatus = new Status(IStatus.ERROR, ManagedApiPlugin.PLUGIN_ID, "Failure while rewriting raw classpath."); } return returnStatus; } }; writeRawClasspathJob.setSystem(true); writeRawClasspathJob.setRule(eProject.getProject().getParent()); writeRawClasspathJob.schedule(); }
From source file:com.google.gdt.eclipse.managedapis.platform.ManagedApiContainer.java
License:Open Source License
/** * For a project and a ClassPathContainer, this method identifies and returns * the ManagedApi instance associated with the project. */// ww w .j a va2s .c om public static ManagedApi getManagedApiForClassPathContainer(ManagedApiProject managedApiProject, ClassPathContainer classPathContainer) { IClasspathEntry icpe = classPathContainer.getClasspathEntry(); String localPath = icpe.getPath().removeFirstSegments(1).toString(); return managedApiProject != null ? managedApiProject.findManagedApi(localPath) : null; }
From source file:com.google.gdt.eclipse.managedapis.platform.ManagedApiContainer.java
License:Open Source License
/** * Determines whether the provided element is in fact the ClassPathContainer * correlated to a ManagedApiConstainer. */// w w w .j av a 2 s.com public static boolean isManagedApiContainer(Object element) { boolean isMatch = false; if (element instanceof ClassPathContainer) { ClassPathContainer cpc = (ClassPathContainer) element; IClasspathEntry icpe = cpc.getClasspathEntry(); isMatch = (ManagedApiPlugin.API_CONTAINER_PATH_ID.equals(icpe.getPath().segment(0))); } return isMatch; }