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.liferay.ide.portlet.ui.editor.internal.ResourceBundleJumpActionHandler.java
License:Open Source License
@Override protected boolean computeEnablementState() { final Element element = getModelElement(); IProject project = element.adapt(IProject.class); final ValueProperty property = (ValueProperty) property().definition(); final String text = element.property(property).text(true); boolean isEnabled = super.computeEnablementState(); if (isEnabled && text != null) { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IWorkspaceRoot wroot = workspace.getRoot(); final IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project); String ioFileName = PortletUtil.convertJavaToIoFileName(text, RB_FILE_EXTENSION); 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; }// w ww .j av a 2 s . c o m } } } return false; }
From source file:com.liferay.ide.portlet.ui.editor.internal.ResourceBundleJumpActionHandler.java
License:Open Source License
@Override protected Object run(Presentation context) { final Element element = getModelElement(); final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); final ValueProperty property = (ValueProperty) property().definition(); final IProject project = element.adapt(IProject.class); final Value<Path> value = element.property(property); final String text = value.text(false); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IWorkspaceRoot wroot = workspace.getRoot(); final IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project); String ioFileName = PortletUtil.convertJavaToIoFileName(text, RB_FILE_EXTENSION); 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()) { if (window != null) { final IWorkbenchPage page = window.getActivePage(); IEditorDescriptor editorDescriptor = null; try { editorDescriptor = IDE.getEditorDescriptor(resourceBundleFile.getName()); } catch (PartInitException e) { // No editor was found for this file type. }//from w w w. jav a 2s .c o m if (editorDescriptor != null) { try { IDE.openEditor(page, resourceBundleFile, editorDescriptor.getId(), true); } catch (PartInitException e) { PortletUIPlugin.logError(e); } } } } } } return null; }
From source file:com.liferay.ide.project.core.BaseValidator.java
License:Open Source License
protected IPath[] getSourceEntries(IJavaProject javaProject) { List<IPath> paths = new ArrayList<IPath>(); try {/*from w w w . j a va2 s.c o m*/ final IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : classpathEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { paths.add(entry.getPath()); } } } catch (JavaModelException e) { ProjectCore.logError("Error resolving classpath.", e); } return paths.toArray(new IPath[0]); }
From source file:com.liferay.ide.project.core.facet.ExtPluginFacetInstall.java
License:Open Source License
@Override public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) throws CoreException { super.execute(project, fv, config, monitor); IDataModel model = (IDataModel) config; IDataModel masterModel = (IDataModel) model.getProperty(FacetInstallDataModelProvider.MASTER_PROJECT_DM); if (masterModel != null && masterModel.getBooleanProperty(CREATE_PROJECT_OPERATION)) { /*//from w w w . j a v a 2 s . com // get the template zip for portlets and extract into the project SDK sdk = getSDK(); String extName = this.masterModel.getStringProperty( EXT_NAME ); // FIX IDE-450 if( extName.endsWith( ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX ) ) { extName = extName.substring( 0, extName.indexOf( ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX ) ); } // END FIX IDE-450 String displayName = this.masterModel.getStringProperty( DISPLAY_NAME ); Map<String, String> appServerProperties = ServerUtil.configureAppServerProperties( project ); IPath newExtPath = sdk.createNewExtProject( extName, displayName, appServerProperties ); IPath tempInstallPath = newExtPath.append( extName + ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX ); processNewFiles( tempInstallPath ); // cleanup ext temp files FileUtil.deleteDir( installPath.toFile(), true ); */ // IDE-1122 SDK creating project has been moved to Class NewPluginProjectWizard String extName = this.masterModel.getStringProperty(EXT_NAME); IPath projectTempPath = (IPath) masterModel.getProperty(PROJECT_TEMP_PATH); processNewFiles(projectTempPath.append(extName + ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)); FileUtil.deleteDir(projectTempPath.toFile(), true); // End IDE-1122 try { this.project.refreshLocal(IResource.DEPTH_INFINITE, monitor); } catch (Exception e) { ProjectCore.logError(e); } IFolder webappRoot = this.project.getFolder(ISDKConstants.DEFAULT_DOCROOT_FOLDER); deleteFolder(webappRoot.getFolder("WEB-INF/src")); //$NON-NLS-1$ deleteFolder(webappRoot.getFolder("WEB-INF/classes")); //$NON-NLS-1$ } if (shouldSetupExtClasspath()) { IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> existingRawClasspath = Arrays.asList(javaProject.getRawClasspath()); List<IClasspathEntry> newRawClasspath = new ArrayList<IClasspathEntry>(); // first lets add all new source folders for (int i = 0; i < IPluginFacetConstants.EXT_PLUGIN_SDK_SOURCE_FOLDERS.length; i++) { IPath sourcePath = this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_SDK_SOURCE_FOLDERS[i]) .getFullPath(); IPath outputPath = this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_SDK_OUTPUT_FOLDERS[i]) .getFullPath(); IClasspathAttribute[] attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute("owner.project.facets", "liferay.ext") }; //$NON-NLS-1$ //$NON-NLS-2$ IClasspathEntry sourceEntry = JavaCore.newSourceEntry(sourcePath, new IPath[0], new IPath[0], outputPath, attributes); newRawClasspath.add(sourceEntry); } // next add all previous classpath entries except for source folders for (IClasspathEntry entry : existingRawClasspath) { if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { newRawClasspath.add(entry); } } javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]), this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_DEFAULT_OUTPUT_FOLDER).getFullPath(), null); ProjectUtil.fixExtProjectSrcFolderLinks(this.project); // fixTilesDefExtFile(); } //IDE-1239 need to make sure and delete docroot/WEB-INF/ext-web/docroot/WEB-INF/lib removeUnneededFolders(this.project); }
From source file:com.liferay.ide.project.core.util.ProjectUtil.java
License:Open Source License
private static void fixExtProjectClasspathEntries(IProject project) { try {// w w w. j a va 2s.com boolean fixedAttr = false; IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { IClasspathEntry newEntry = null; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { List<IClasspathAttribute> newAttrs = new ArrayList<IClasspathAttribute>(); IClasspathAttribute[] attrs = entry.getExtraAttributes(); if (!CoreUtil.isNullOrEmpty(attrs)) { for (IClasspathAttribute attr : attrs) { IClasspathAttribute newAttr = null; if ("owner.project.facets".equals(attr.getName()) && //$NON-NLS-1$ "liferay.plugin".equals(attr.getValue())) //$NON-NLS-1$ { newAttr = JavaCore.newClasspathAttribute(attr.getName(), "liferay.ext"); //$NON-NLS-1$ fixedAttr = true; } else { newAttr = attr; } newAttrs.add(newAttr); } newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), newAttrs.toArray(new IClasspathAttribute[0])); } } if (newEntry == null) { newEntry = entry; } newEntries.add(newEntry); } if (fixedAttr) { IProgressMonitor monitor = new NullProgressMonitor(); javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), monitor); try { javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor); } catch (Exception e) { ProjectCore.logError(e); } } fixExtProjectSrcFolderLinks(project); } catch (Exception ex) { ProjectCore.logError("Exception trying to fix Ext project classpath entries.", ex); //$NON-NLS-1$ } }
From source file:com.liferay.ide.project.core.util.ProjectUtil.java
License:Open Source License
/** IDE-270 */ public static void fixExtProjectSrcFolderLinks(IProject extProject) throws JavaModelException { if (extProject != null) { IJavaProject javaProject = JavaCore.create(extProject); if (javaProject != null) { final IVirtualComponent c = ComponentCore.createComponent(extProject, false); if (c != null) { final IVirtualFolder jsrc = c.getRootFolder().getFolder("/WEB-INF/classes"); //$NON-NLS-1$ if (jsrc != null) { final IClasspathEntry[] cp = javaProject.getRawClasspath(); for (int i = 0; i < cp.length; i++) { final IClasspathEntry cpe = cp[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (cpe.getPath().removeFirstSegments(1).segmentCount() > 0) { try { IFolder srcFolder = ResourcesPlugin.getWorkspace().getRoot() .getFolder(cpe.getPath()); IVirtualResource[] virtualResource = ComponentCore .createResources(srcFolder); // create link for source folder only when it is not mapped if (virtualResource.length == 0) { jsrc.createLink(cpe.getPath().removeFirstSegments(1), 0, null); }/* w w w.ja v a2 s . co m*/ } catch (Exception e) { ProjectCore.logError(e); } } } } } } } } }
From source file:com.liferay.ide.server.remote.ModuleTraverser.java
License:Open Source License
private static boolean isValid(final IClasspathEntry entry, final IClasspathAttribute attrib, boolean isWebApp, final IProject project) { int kind = entry.getEntryKind(); boolean isClassFolder = isClassFolderEntry(entry); if (kind == IClasspathEntry.CPE_PROJECT || kind == IClasspathEntry.CPE_SOURCE) { return false; }/*w ww. j a v a 2 s .c o m*/ String runtimePath = getRuntimePath(attrib, isWebApp, isClassFolder); if (!isWebApp) { if (!runtimePath.equals("../") && !runtimePath.equals("/")) { //$NON-NLS-1$//$NON-NLS-2$ return false; } if (isClassFolder && !runtimePath.equals("/")) { //$NON-NLS-1$ return false; } } else { if (runtimePath != null && !runtimePath.equals("/WEB-INF/lib") //$NON-NLS-1$ && !runtimePath.equals("/WEB-INF/classes") //$NON-NLS-1$ && !runtimePath.equals("../")) { //$NON-NLS-1$ return false; } if (isClassFolder && !runtimePath.equals("/WEB-INF/classes")) { //$NON-NLS-1$ return false; } } return true; }
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 . jav a 2 s .c om 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.javapkgbuild.Tasks.java
License:MIT License
private static String getClassPathType(IClasspathEntry cp) { switch (cp.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: return "con"; case IClasspathEntry.CPE_LIBRARY: return "lib"; case IClasspathEntry.CPE_PROJECT: return "proj"; case IClasspathEntry.CPE_SOURCE: return "src"; case IClasspathEntry.CPE_VARIABLE: return "var"; default:// ww w . j av a 2s .c o m return "unexpected"; } }
From source file:com.mountainminds.eclemma.core.ScopeUtils.java
License:Open Source License
/** * Remove all JRE runtime entries from the given set * // w w w .j a v a2 s . 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; }