List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:com.liferay.ide.portlet.ui.editor.internal.AbstractResourceBundleActionHandler.java
License:Open Source License
/** * @param project//w w w . jav a 2 s. c om * @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; }
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; }//from w w w . j ava 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. }/* ww w . ja v a 2 s .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 v a 2s. co 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.library.PluginLibraryInstallOperation.java
License:Open Source License
@Override public void execute(LibraryProviderOperationConfig config, IProgressMonitor monitor) throws CoreException { IFacetedProjectBase facetedProject = config.getFacetedProject(); IProject project = facetedProject.getProject(); IJavaProject javaProject = JavaCore.create(project); IPath containerPath = getClasspathContainerPath(); // IDE-413 check to make sure that the containerPath doesn't already existing. IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getPath().equals(containerPath)) { return; }//from w w w. ja v a 2s . c o m } IAccessRule[] accessRules = new IAccessRule[] {}; IClasspathAttribute[] attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute( IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, StringPool.EMPTY) }; IClasspathEntry newEntry = JavaCore.newContainerEntry(containerPath, accessRules, attributes, false); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[entries.length] = newEntry; javaProject.setRawClasspath(newEntries, monitor); }
From source file:com.liferay.ide.project.core.PluginClasspathContainer.java
License:Open Source License
protected IClasspathEntry findSuggestedEntry(IPath jarPath, IClasspathEntry[] suggestedEntries) { // compare jarPath to an existing entry if (jarPath != null && (!CoreUtil.isNullOrEmpty(jarPath.toString())) && (!CoreUtil.isNullOrEmpty(suggestedEntries))) { int matchLength = jarPath.segmentCount(); for (IClasspathEntry suggestedEntry : suggestedEntries) { IPath suggestedPath = suggestedEntry.getPath(); IPath pathToMatch = suggestedPath.removeFirstSegments(suggestedPath.segmentCount() - matchLength) .setDevice(null).makeAbsolute(); if (jarPath.equals(pathToMatch)) { return suggestedEntry; }//from ww w . ja va2 s .c om } } return null; }
From source file:com.liferay.ide.project.core.PluginClasspathContainerInitializer.java
License:Open Source License
@Override public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { final String key = PluginClasspathContainer.getDecorationManagerKey(project.getProject(), containerPath.toString());//w w w . j ava 2 s . c o m final IClasspathEntry[] entries = containerSuggestion.getClasspathEntries(); cpDecorations.clearAllDecorations(key); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; final IPath srcpath = entry.getSourceAttachmentPath(); final IPath srcrootpath = entry.getSourceAttachmentRootPath(); final IClasspathAttribute[] attrs = entry.getExtraAttributes(); if (srcpath != null || attrs.length > 0) { final String eid = entry.getPath().toString(); final ClasspathDecorations dec = new ClasspathDecorations(); dec.setSourceAttachmentPath(srcpath); dec.setSourceAttachmentRootPath(srcrootpath); dec.setExtraAttributes(attrs); cpDecorations.setDecorations(key, eid, dec); } } cpDecorations.save(); IPath portalDir = null; String javadocURL = null; IPath sourceLocation = null; if (containerSuggestion instanceof PluginClasspathContainer) { portalDir = ((PluginClasspathContainer) containerSuggestion).getPortalDir(); javadocURL = ((PluginClasspathContainer) containerSuggestion).getJavadocURL(); sourceLocation = ((PluginClasspathContainer) containerSuggestion).getSourceLocation(); } else { portalDir = ServerUtil.getPortalDir(project); try { ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(project.getProject()); if (liferayRuntime != null) { javadocURL = liferayRuntime.getJavadocURL(); sourceLocation = liferayRuntime.getSourceLocation(); } } catch (Exception e) { ProjectCore.logError(e); } } if (portalDir != null) { IClasspathContainer newContainer = getCorrectContainer(containerPath, containerPath.segment(1), project, portalDir, javadocURL, sourceLocation); JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { newContainer }, null); } }
From source file:com.liferay.ide.project.core.PluginPackageResourceListener.java
License:Open Source License
protected void processRequiredDeploymentContexts(Properties props, IProject project) { final IVirtualComponent rootComponent = ComponentCore.createComponent(project); if (rootComponent == null) { return;//w w w . ja v a 2 s. c om } final List<IVirtualReference> removeRefs = new ArrayList<IVirtualReference>(); final IClasspathContainer webAppLibrariesContainer = J2EEComponentClasspathContainerUtils .getInstalledWebAppLibrariesContainer(project); if (webAppLibrariesContainer == null) { return; } IClasspathEntry[] existingEntries = webAppLibrariesContainer.getClasspathEntries(); for (IClasspathEntry entry : existingEntries) { IPath path = entry.getPath(); String archiveName = path.lastSegment(); if (archiveName.endsWith("-service.jar")) //$NON-NLS-1$ { IFile file = getWorkspaceFile(path); if (file.exists() && ProjectUtil.isLiferayFacetedProject(file.getProject())) { for (IVirtualReference ref : rootComponent.getReferences()) { if (archiveName.equals(ref.getArchiveName())) { removeRefs.add(ref); } } } } } final List<IVirtualReference> addRefs = new ArrayList<IVirtualReference>(); String requiredDeploymenContexts = props.getProperty("required-deployment-contexts"); //$NON-NLS-1$ if (requiredDeploymenContexts != null) { String[] contexts = requiredDeploymenContexts.split(StringPool.COMMA); if (!CoreUtil.isNullOrEmpty(contexts)) { for (String context : contexts) { IVirtualReference ref = processContext(rootComponent, context); if (ref != null) { addRefs.add(ref); } } } } new WorkspaceJob("Update virtual component.") //$NON-NLS-1$ { @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { updateVirtualComponent(rootComponent, removeRefs, addRefs); updateWebClasspathContainer(rootComponent, addRefs); return Status.OK_STATUS; } }.schedule(); }
From source file:com.liferay.ide.project.core.PluginPackageResourceListener.java
License:Open Source License
protected void processPropertiesFile(IFile pluginPackagePropertiesFile) throws CoreException { IProject project = pluginPackagePropertiesFile.getProject(); IJavaProject javaProject = JavaCore.create(project); IPath containerPath = null;//from w w w. java2 s . c o m IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().segment(0).equals(PluginClasspathContainerInitializer.ID) || entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) { containerPath = entry.getPath(); break; } } } if (containerPath != null) { IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(containerPath, javaProject); final String id = containerPath.segment(0); if (id.equals(PluginClasspathContainerInitializer.ID) || id.equals(SDKClasspathContainer.ID)) { ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(id); initializer.requestClasspathContainerUpdate(containerPath, javaProject, classpathContainer); } } Properties props = new Properties(); InputStream contents = null; try { contents = pluginPackagePropertiesFile.getContents(); props.load(contents); // processPortalDependencyTlds(props, pluginPackagePropertiesFile.getProject()); processRequiredDeploymentContexts(props, pluginPackagePropertiesFile.getProject()); } catch (Exception e) { ProjectCore.logError(e); } finally { if (contents != null) { try { contents.close(); } catch (IOException e) { // ignore, this is best effort } } } }
From source file:com.liferay.ide.project.core.PluginPackageResourceListener.java
License:Open Source License
protected void updateWebClasspathContainer(IVirtualComponent rootComponent, List<IVirtualReference> addRefs) throws CoreException { IProject project = rootComponent.getProject(); IJavaProject javaProject = JavaCore.create(project); FlexibleProjectContainer container = J2EEComponentClasspathContainerUtils .getInstalledWebAppLibrariesContainer(project); // If the container is present, refresh it if (container == null) { return;//from w ww . j ava 2s . c om } container.refresh(); // need to regrab this to get newest container container = J2EEComponentClasspathContainerUtils.getInstalledWebAppLibrariesContainer(project); if (container == null) { return; } IClasspathEntry[] webappEntries = container.getClasspathEntries(); for (IClasspathEntry entry : webappEntries) { String archiveName = entry.getPath().lastSegment(); for (IVirtualReference ref : addRefs) { if (ref.getArchiveName().equals(archiveName)) { IFile referencedFile = (IFile) ref.getReferencedComponent().getAdapter(IFile.class); IProject referencedFileProject = referencedFile.getProject(); // IDE-110 IDE-648 ((ClasspathEntry) entry).sourceAttachmentPath = referencedFileProject .getFolder(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/service").getFullPath(); //$NON-NLS-1$ } } } ClasspathContainerInitializer initializer = JavaCore .getClasspathContainerInitializer("org.eclipse.jst.j2ee.internal.web.container"); //$NON-NLS-1$ initializer.requestClasspathContainerUpdate(container.getPath(), javaProject, container); }