List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:com.legstar.eclipse.plugin.coxbgen.wizards.CoxbGenWizardPage.java
License:Open Source License
/** * Initially, try to set the target src dir as the first source directory of * the project containing the Xsd file. If that project is not a Java * project leave the field not initialized. * //from w ww .j av a 2 s . c o m * @param xsdFile the XML schema file from the workspace * @throws CoreException if project is invalid */ protected void initTargetSrcDir(final IFile xsdFile) throws CoreException { try { IJavaProject jproject = JavaCore.create(xsdFile.getProject()); if (jproject == null) { throwCoreException( NLS.bind(Messages.xsd_file_in_invalid_project_msg, xsdFile.getLocation().toOSString())); } IClasspathEntry[] cpe = jproject.getRawClasspath(); /* Find the first source location */ for (int i = 0; i < cpe.length; i++) { if (cpe[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { _targetSrcDirText.setText(cpe[i].getPath().toOSString()); break; } } } catch (JavaModelException e) { throwCoreException(e); } }
From source file:com.legstar.eclipse.plugin.coxbgen.wizards.CoxbGenWizardPage.java
License:Open Source License
/** * Check if a relative path name is a valid java source directory. Also sets * the target binary folder./*from w ww. j av a 2 s . c o m*/ * * @param relativePathName the path name * @return true if this is a valid java source folder */ protected boolean isJavaSrcDir(final String relativePathName) { IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(relativePathName)); if (resource != null) { IJavaProject jproject = JavaCore.create(resource.getProject()); if (jproject != null) { try { IClasspathEntry[] cpe = jproject.getRawClasspath(); /* Lookup the pathname */ for (int i = 0; i < cpe.length; i++) { if (cpe[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (relativePathName.equals(cpe[i].getPath().toOSString())) { if (cpe[i].getOutputLocation() != null) { _targetBinDirLabel.setText(cpe[i].getOutputLocation().toOSString()); } else { _targetBinDirLabel.setText(jproject.getOutputLocation().toOSString()); } return true; } } } } catch (JavaModelException e) { return false; } } } return false; }
From source file:com.legstar.eclipse.plugin.schemagen.wizards.JavaToXsdWizardPage.java
License:Open Source License
/** * Given classpath entries from a java project, populate a list of * collections./*from ww w . j a v a 2 s . co m*/ * * @param selectedPathElementsLocations the output path locations * @param classPathEntries the java project class path entries * @param javaProject the java project * @throws JavaModelException if invalid classpath */ private void addPathElements(final List<String> selectedPathElementsLocations, final IClasspathEntry[] classPathEntries, final IJavaProject javaProject) throws JavaModelException { IClasspathEntry jreEntry = JavaRuntime.getDefaultJREContainerEntry(); IPath projectPath = javaProject.getProject().getLocation(); for (int i = 0; i < classPathEntries.length; i++) { IClasspathEntry classpathEntry = classPathEntries[i]; String pathElementLocation = null; switch (classpathEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: pathElementLocation = classpathEntry.getPath().toOSString(); break; case IClasspathEntry.CPE_CONTAINER: /* No need for the default jre */ if (classpathEntry.equals(jreEntry)) { break; } /* Resolve container into class path entries */ IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(classpathEntry.getPath(), javaProject); addPathElements(selectedPathElementsLocations, classpathContainer.getClasspathEntries(), javaProject); break; case IClasspathEntry.CPE_VARIABLE: pathElementLocation = JavaCore.getResolvedVariablePath(classpathEntry.getPath()).toOSString(); break; case IClasspathEntry.CPE_SOURCE: /* * If source has no specific output, use the project default * one */ IPath outputLocation = classpathEntry.getOutputLocation(); if (outputLocation == null) { outputLocation = javaProject.getOutputLocation(); } pathElementLocation = projectPath.append(outputLocation.removeFirstSegments(1)).toOSString(); break; default: break; } if (pathElementLocation != null && !selectedPathElementsLocations.contains(pathElementLocation)) { selectedPathElementsLocations.add(pathElementLocation); } } }
From source file:com.liferay.ide.core.model.internal.GenericResourceBundlePathService.java
License:Open Source License
/** * @param project//from w w w . j av a 2 s. c o m * @return */ final List<Path> computeRoots(IProject project) { List<Path> roots = new ArrayList<Path>(); if (project != null) { IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project); for (IClasspathEntry iClasspathEntry : cpEntries) { if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) { IPath entryPath = WORKSPACE_ROOT.getFolder(iClasspathEntry.getPath()).getLocation(); String fullPath = entryPath.toOSString(); Path sapphirePath = new Path(fullPath); roots.add(sapphirePath); } } } return roots; }
From source file:com.liferay.ide.core.util.CoreUtil.java
License:Open Source License
public final static List<IFolder> getSourceFolders(final IJavaProject project) { final List<IFolder> folders = new ArrayList<IFolder>(); if (project != null) { final IClasspathEntry[] entries = project.readRawClasspath(); for (final IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().segmentCount() > 0) { IContainer container = null; if (entry.getPath().segmentCount() == 1) { container = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().segment(0)); } else { container = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath()); }//from w w w . j a v a2 s . c o m if (!folders.contains(container) && container instanceof IFolder) { folders.add((IFolder) container); } } } } return folders; }
From source file:com.liferay.ide.layouttpl.core.facet.LayoutTplPluginFacetInstall.java
License:Open Source License
protected void removeUnneededClasspathEntries() { IFacetedProjectWorkingCopy facetedProject = getFacetedProject(); IJavaProject javaProject = JavaCore.create(facetedProject.getProject()); try {/* w w w .ja v a 2 s .c o 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) { // no need to report errors } }
From source file:com.liferay.ide.portlet.core.model.internal.LocaleBundleValidationService.java
License:Open Source License
public Status compute() { final Element modelElement = context(Element.class); if (!modelElement.disposed() && modelElement instanceof SupportedLocales) { final IProject project = modelElement.adapt(IProject.class); final Portlet portlet = modelElement.nearest(Portlet.class); final IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot(); final IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project); if (cpEntries != null) { final String locale = modelElement.property(context(ValueProperty.class)).text(false); final Value<Path> resourceBundle = portlet.getResourceBundle(); if (locale == null) { return Status.createErrorStatus(Resources.localeMustNotEmpty); } else { final String bundleName = resourceBundle.text(); if (resourceBundle != null && bundleName != null) { final String localeString = PortletUtil.localeString(locale); final String ioFileName = PortletUtil.convertJavaToIoFileName(bundleName, RB_FILE_EXTENSION, localeString); for (IClasspathEntry iClasspathEntry : cpEntries) { if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) { IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation(); entryPath = entryPath.append(ioFileName); IFile resourceBundleFile = wroot.getFileForLocation(entryPath); if (resourceBundleFile != null && resourceBundleFile.exists()) { return Status.createOkStatus(); } else { return Status.createWarningStatus(Resources.bind( StringEscapeUtils.unescapeJava(Resources.noResourceBundle), new Object[] { locale, bundleName, localeString })); }/*from www . j a va 2 s . c o m*/ } } } } } } return Status.createOkStatus(); }
From source file:com.liferay.ide.portlet.core.util.PortletUtil.java
License:Open Source License
/** * this will convert the IO file name of the resource bundle to java package name * //from w w w . ja v a 2 s .c om * @param project * @param value * - the io file name * @return - the java package name of the resource bundle */ public static String convertIOToJavaFileName(IProject project, String value) { String rbIOFile = value.substring(value.lastIndexOf("/") + 1); //$NON-NLS-1$ IFile resourceBundleFile = null; IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot wroot = workspace.getRoot(); IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project); for (IClasspathEntry iClasspathEntry : cpEntries) { if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) { IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation(); entryPath = entryPath.append(rbIOFile); resourceBundleFile = wroot.getFileForLocation(entryPath); // System.out.println( "ResourceBundleValidationService.validate():" + resourceBundleFile ); if (resourceBundleFile != null && resourceBundleFile.exists()) { break; } } } String javaName = resourceBundleFile.getProjectRelativePath().toPortableString(); if (javaName.indexOf('.') != -1) { // Strip the extension javaName = value.substring(0, value.lastIndexOf('.')); // Replace all "/" by "." javaName = javaName.replace('/', '.'); } return javaName; }
From source file:com.liferay.ide.portlet.ui.editor.internal.AbstractResourceBundleActionHandler.java
License:Open Source License
/** * @param project//from ww w . ja v a 2 s . c o m * @param ioFileName * @return */ protected final boolean getFileFromClasspath(IProject project, String ioFileName) { IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project); for (IClasspathEntry iClasspathEntry : cpEntries) { if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) { IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation(); entryPath = entryPath.append(ioFileName); IFile resourceBundleFile = wroot.getFileForLocation(entryPath); if (resourceBundleFile != null && resourceBundleFile.exists()) { return true; } else { return false; } } } return false; }
From source file:com.liferay.ide.portlet.ui.editor.internal.AbstractResourceBundleActionHandler.java
License:Open Source License
/** * @param project//from w w w. j av a 2 s . c o m * @param ioFileName * @return */ protected final IFolder getResourceBundleFolderLocation(IProject project, String ioFileName) { IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project); for (IClasspathEntry iClasspathEntry : cpEntries) { if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) { IFolder srcFolder = wroot.getFolder(iClasspathEntry.getPath()); IPath rbSourcePath = srcFolder.getLocation(); rbSourcePath = rbSourcePath.append(ioFileName); IFile resourceBundleFile = wroot.getFileForLocation(rbSourcePath); if (resourceBundleFile != null) { return srcFolder; } } } return null; }