List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:com.liferay.ide.theme.core.facet.ThemePluginFacetInstall.java
License:Open Source License
protected void removeUnneededClasspathEntries() { IFacetedProjectWorkingCopy facetedProject = getFacetedProject(); IJavaProject javaProject = JavaCore.create(facetedProject.getProject()); try {/*from w w w .j a v a2s . co m*/ IClasspathEntry[] existingClasspath = javaProject.getRawClasspath(); List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : existingClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { continue; } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String path = entry.getPath().toPortableString(); if (path.contains("org.eclipse.jdt.launching.JRE_CONTAINER") || //$NON-NLS-1$ path.contains("org.eclipse.jst.j2ee.internal.web.container") || //$NON-NLS-1$ path.contains("org.eclipse.jst.j2ee.internal.module.container")) //$NON-NLS-1$ { continue; } } newClasspath.add(entry); } javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[0]), null); IResource sourceFolder = javaProject.getProject() .findMember(IPluginFacetConstants.PORTLET_PLUGIN_SDK_SOURCE_FOLDER); if (sourceFolder.exists()) { sourceFolder.delete(true, null); } } catch (Exception e) { } }
From source file:com.microsoft.applicationinsights.ui.config.AIProjConfigWizardDialog.java
License:Open Source License
private void configureAzureSDK(IJavaProject proj) { try {//from w w w .ja v a 2 s . co m IClasspathEntry[] classpath = proj.getRawClasspath(); for (IClasspathEntry iClasspathEntry : classpath) { final IPath containerPath = iClasspathEntry.getPath(); if (containerPath.toString().contains(Messages.azureSDKcontainerID)) { return; } } List<IClasspathEntry> list = new ArrayList<IClasspathEntry>(java.util.Arrays.asList(classpath)); IClasspathAttribute[] attr = new IClasspathAttribute[1]; attr[0] = JavaCore.newClasspathAttribute(Messages.jstDep, "/WEB-INF/lib"); IClasspathEntry jarEntry = JavaCore.newContainerEntry( new Path(Messages.azureSDKcontainerID).append(getLatestSDKVersion()), null, attr, false); list.add(jarEntry); IClasspathEntry[] newClasspath = (IClasspathEntry[]) list.toArray(new IClasspathEntry[0]); proj.setRawClasspath(newClasspath, null); // Azure SDK configured - application insights configured for the first time for specific project Bundle bundle = Activator.getDefault().getBundle(); if (bundle != null) { PluginUtil.showBusy(true, getShell()); AppInsightsCustomEvent.create("Application Insights", bundle.getVersion().toString()); PluginUtil.showBusy(false, getShell()); } } catch (Exception e) { Activator.getDefault().log(e.getMessage(), e); } }
From source file:com.microsoft.azure.hdinsight.projects.CreateProjectUtil.java
License:Open Source License
private static void createResourceStructForLocalRunScalaProject(IFolder sourceRootFolder, String rootPath, IProject project) throws CoreException { copyFileTo(Scala_Local_Run_Sample, rootPath); final IFolder dataFolder = sourceRootFolder.getParent().getFolder(new Path("data")); if (!dataFolder.exists()) { dataFolder.create(false, true, null); }//from www .j a v a 2 s . c o m copyFileTo(Scala_Local_Run_Sample_Data, dataFolder.getLocation().toFile().getAbsolutePath()); IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); IPath dataPath = javaProject.getPath().append("data"); IClasspathEntry dataEntry = JavaCore.newSourceEntry(dataPath, null); newEntries[entries.length] = JavaCore.newSourceEntry(dataEntry.getPath()); javaProject.setRawClasspath(newEntries, null); }
From source file:com.microsoft.azuretools.wasdkjava.ui.classpath.ClasspathContainerPage.java
License:Open Source License
@Override public void setSelection(IClasspathEntry selEntry) { if (selEntry != null) { curVersion = selEntry.getPath().segment(1); }/* www. ja v a 2 s . c o m*/ }
From source file:com.microsoft.javapkgbuild.Tasks.java
License:MIT License
public static void exportReferences(String projectName, String outputFileName) throws JavaModelException { try {/* w ww. ja va2s . com*/ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = workspaceRoot.getProject(projectName); IJavaProject javaProject = JavaCore.create(project); DocumentBuilderFactory xFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = xFactory.newDocumentBuilder(); Document doc = builder.newDocument(); Element mainRoot = doc.createElement("classpath"); mainRoot.setAttribute("projectName", projectName); doc.appendChild(mainRoot); IClasspathEntry[] classPathList = javaProject.getResolvedClasspath(true); for (IClasspathEntry cp : classPathList) { Element cpNode = doc.createElement("classpathentry"); cpNode.setAttribute("path", cp.getPath().toOSString()); cpNode.setAttribute("kind", getClassPathType(cp)); cpNode.setAttribute("exported", Boolean.toString(cp.isExported())); IPath sourceFolder = cp.getSourceAttachmentPath(); if (cp.getEntryKind() == IClasspathEntry.CPE_LIBRARY && sourceFolder != null) cpNode.setAttribute("sourcepath", sourceFolder.toOSString()); mainRoot.appendChild(cpNode); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(doc); FileOutputStream fos = new FileOutputStream(outputFileName); StreamResult outFile = new StreamResult(fos); transformer.transform(source, outFile); fos.close(); System.out.println("Output file is: " + outputFileName); } catch (Exception e) { e.printStackTrace(System.err); } }
From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java
License:Open Source License
private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) { try {/*from ww w. j av a 2 s .co m*/ IClasspathEntry rawEntry = root.getRawClasspathEntry(); if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { IClasspathEntry entry = getClasspathEntry(root); if (entry.getReferencingEntry() != null) { return false; // not the variable entry itself, but a referenced entry } IPath path = rawEntry.getPath().makeRelative(); if (getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED)) { int segements = path.segmentCount(); if (segements > 0) { fBuffer.append(path.segment(segements - 1)); if (segements > 1) { int offset = fBuffer.length(); fBuffer.append(CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); } } else { fBuffer.append(path.toString()); } } else { fBuffer.append(path.toString()); } int offset = fBuffer.length(); fBuffer.append(CONCAT_STRING); if (root.isExternal()) fBuffer.append(root.getPath().toOSString()); else fBuffer.append(root.getPath().makeRelative().toString()); return true; } } catch (JavaModelException e) { // problems with class path, ignore (bug 202792) return false; } return false; }
From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java
License:Open Source License
private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) { IPath path;//from w ww . j ava 2s. c o m IClasspathEntry classpathEntry = null; try { classpathEntry = getClasspathEntry(root); IPath rawPath = classpathEntry.getPath(); if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute()) path = rawPath; else path = root.getPath(); } catch (JavaModelException e) { path = root.getPath(); } if (getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED)) { int segements = path.segmentCount(); if (segements > 0) { fBuffer.append(path.segment(segements - 1)); int offset = fBuffer.length(); if (segements > 1 || path.getDevice() != null) { fBuffer.append(CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); } if (classpathEntry != null) { IClasspathEntry referencingEntry = classpathEntry.getReferencingEntry(); if (referencingEntry != null) { fBuffer.append(" (from "); fBuffer.append(Name.CLASS_PATH.toString()); fBuffer.append(" of "); fBuffer.append(referencingEntry.getPath().lastSegment()); fBuffer.append(")"); } } } else { fBuffer.append(path.toOSString()); } } else { fBuffer.append(path.toOSString()); } }
From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java
License:Open Source License
private void appendInternalArchiveLabel(IPackageFragmentRoot root, long flags) { IResource resource = root.getResource(); boolean rootQualified = getFlag(flags, ROOT_QUALIFIED); if (rootQualified) { fBuffer.append(root.getPath().makeRelative().toString()); } else {//from w w w .j a v a 2s . c om fBuffer.append(root.getElementName()); int offset = fBuffer.length(); boolean referencedPostQualified = getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED); if (referencedPostQualified && isReferenced(root)) { fBuffer.append(CONCAT_STRING); fBuffer.append(resource.getParent().getFullPath().makeRelative().toString()); } else if (getFlag(flags, ROOT_POST_QUALIFIED)) { fBuffer.append(CONCAT_STRING); fBuffer.append(root.getParent().getPath().makeRelative().toString()); } if (referencedPostQualified) { try { IClasspathEntry referencingEntry = getClasspathEntry(root).getReferencingEntry(); if (referencingEntry != null) { fBuffer.append(" (from "); fBuffer.append(Name.CLASS_PATH.toString()); fBuffer.append(" of "); fBuffer.append(referencingEntry.getPath().lastSegment()); fBuffer.append(")"); } } catch (JavaModelException e) { // ignore } } } }
From source file:com.motorola.studio.android.common.utilities.EclipseUtils.java
License:Apache License
/** * Verifies if a given libPath is already available on the project classpath. * @param javaProject /* ww w.j a v a2 s. c o m*/ * @param libPath * @return true if present, false otherwise */ public static boolean isLibOnClasspath(IJavaProject javaProject, IPath libPath) { try { IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : rawClasspath) { if (classpathEntry.getPath().equals(libPath)) { return true; } } } catch (JavaModelException e) { return false; } return false; }
From source file:com.mountainminds.eclemma.core.ScopeUtils.java
License:Open Source License
/** * Remove all JRE runtime entries from the given set * //from w w w . j a v a2s . c o m * @param scope * set to filter * @return filtered set without JRE runtime entries */ public static Set<IPackageFragmentRoot> filterJREEntries(Collection<IPackageFragmentRoot> scope) throws JavaModelException { final Set<IPackageFragmentRoot> filtered = new HashSet<IPackageFragmentRoot>(); for (final IPackageFragmentRoot root : scope) { final IClasspathEntry entry = root.getRawClasspathEntry(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: filtered.add(root); break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), root.getJavaProject()); if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) { filtered.add(root); } break; } } return filtered; }