List of usage examples for org.eclipse.jdt.core IJavaProject getProject
IProject getProject();
IProject
on which this IJavaProject
was created. 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 {//from w w w . j av a2 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) { // no need to report errors } }
From source file:com.liferay.ide.project.core.PluginClasspathContainerInitializer.java
License:Open Source License
@Override public void initialize(IPath containerPath, IJavaProject project) throws CoreException { IClasspathContainer classpathContainer = null; int count = containerPath.segmentCount(); if (count != 2) { final String msg = "Invalid plugin classpath container should expecting 2 segments."; //$NON-NLS-1$ throw new CoreException(ProjectCore.createErrorStatus(msg)); }// w ww . j ava2s .c o m String root = containerPath.segment(0); if (!ID.equals(root)) { final String msg = "Invalid plugin classpath container, expecting container root "; //$NON-NLS-1$ throw new CoreException(ProjectCore.createErrorStatus(msg + ID)); } String finalSegment = containerPath.segment(1); IPath portalDir = ServerUtil.getPortalDir(project); if (portalDir == null) { return; } String javadocURL = null; IPath sourceLocation = null; try { ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(project.getProject()); if (liferayRuntime != null) { javadocURL = liferayRuntime.getJavadocURL(); sourceLocation = liferayRuntime.getSourceLocation(); } } catch (Exception e) { ProjectCore.logError(e); } classpathContainer = getCorrectContainer(containerPath, finalSegment, project, portalDir, javadocURL, sourceLocation); JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { classpathContainer }, 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 a v a2 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.SDKClasspathContainerInitializer.java
License:Open Source License
private IPath[] getSDKDependencies(IJavaProject project) { IPath[] dependencyJarPaths = null;/*from w w w. j a v a 2 s . co m*/ SDK sdk = SDKUtil.getSDKFromProjectDir(project.getProject().getLocation().toFile()); if (sdk != null) { dependencyJarPaths = sdk.getDependencyJarPaths(); } return dependencyJarPaths; }
From source file:com.liferay.ide.project.core.SDKClasspathContainerInitializer.java
License:Open Source License
@Override public void initialize(IPath containerPath, IJavaProject project) throws CoreException { IClasspathContainer classpathContainer = null; String root = containerPath.segment(0); if (!SDKClasspathContainer.ID.equals(root)) { final String msg = "Invalid plugin classpath container, expecting container root "; //$NON-NLS-1$ throw new CoreException(ProjectCore.createErrorStatus(msg + SDKClasspathContainer.ID)); }// w ww.j av a 2 s . c o m PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject()); if (bundle == null) { final String msg = "Invalid sdk properties setting."; throw new CoreException(ProjectCore.createErrorStatus(msg)); } IPath globalDir = bundle.getAppServerLibGlobalDir(); IPath portalDir = bundle.getAppServerPortalDir(); IPath bundleDir = bundle.getAppServerDir(); IPath[] bundleDependencyJars = bundle.getBundleDependencyJars(); IPath[] sdkDependencyJarPaths = getSDKDependencies(project); if (portalDir == null) { return; } classpathContainer = new SDKClasspathContainer(containerPath, project, portalDir, null, null, globalDir, bundleDir, bundleDependencyJars, sdkDependencyJarPaths); JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { classpathContainer }, null); }
From source file:com.liferay.ide.project.core.SDKClasspathContainerInitializer.java
License:Open Source License
@Override public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { final String key = SDKClasspathContainer.getDecorationManagerKey(project.getProject(), containerPath.toString());/*www . j av a 2 s.co 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; IPath portalGlobalDir = null; String javadocURL = null; IPath sourceLocation = null; IPath bundleDir = null; IPath[] bundleDependencyJarPaths = null; PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject()); boolean containerChanged = true; if (containerSuggestion instanceof SDKClasspathContainer) { portalDir = ((SDKClasspathContainer) containerSuggestion).getPortalDir(); bundleDir = ((SDKClasspathContainer) containerSuggestion).getBundleDir(); portalGlobalDir = ((SDKClasspathContainer) containerSuggestion).getPortalGlobalDir(); javadocURL = ((SDKClasspathContainer) containerSuggestion).getJavadocURL(); sourceLocation = ((SDKClasspathContainer) containerSuggestion).getSourceLocation(); bundleDependencyJarPaths = ((SDKClasspathContainer) containerSuggestion).getBundleLibDependencyPath(); if (bundle != null && bundle.getAppServerPortalDir().equals(portalDir)) { containerChanged = false; } } if (containerChanged == true) { if (bundle == null) { return; } portalDir = bundle.getAppServerPortalDir(); portalGlobalDir = bundle.getAppServerLibGlobalDir(); bundleDependencyJarPaths = bundle.getBundleDependencyJars(); } IPath[] sdkDependencyPaths = getSDKDependencies(project); if (portalDir != null && portalGlobalDir != null) { IClasspathContainer newContainer = new SDKClasspathContainer(containerPath, project, portalDir, javadocURL, sourceLocation, portalGlobalDir, bundleDir, bundleDependencyJarPaths, sdkDependencyPaths); JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { newContainer }, null); } }
From source file:com.liferay.ide.project.core.util.ProjectUtil.java
License:Open Source License
private static void fixExtProjectClasspathEntries(IProject project) { try {//ww w. j av a 2 s . c o m 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.ui.dialog.CustomProjectSelectionDialog.java
License:Open Source License
@Override protected boolean checkProject(IJavaProject javaProject) { if (projects == null) { return false; }/*from ww w . j a va2 s. co m*/ IProject project = javaProject.getProject(); if (projects.contains(project)) { return true; } else { return false; } }
From source file:com.liferay.ide.project.ui.dialog.LiferayProjectSelectionDialog.java
License:Open Source License
@Override protected boolean checkProject(IJavaProject project) { return ProjectUtil.isLiferayFacetedProject(project.getProject()); }
From source file:com.liferay.ide.project.ui.migration.OpenJavaProjectSelectionDialogAction.java
License:Open Source License
protected ISelection getSelectionProjects() { final JavaProjectSelectionDialog dialog = new JavaProjectSelectionDialog(shell); if (dialog.open() == Window.OK) { final Object[] selectedProjects = dialog.getResult(); if (selectedProjects != null) { List<IProject> projects = new ArrayList<>(); for (Object project : selectedProjects) { if (project instanceof IJavaProject) { IJavaProject p = (IJavaProject) project; projects.add(p.getProject()); }/*w ww . j a v a2s . co m*/ } return new StructuredSelection(projects.toArray(new IProject[0])); } } return null; }