List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:com.liferay.ide.project.core.PluginsSDKProjectRuntimeValidator.java
License:Open Source License
public void validate(IFacetedProject fproj) throws CoreException { final IProject proj = fproj.getProject(); if (ProjectUtil.isLiferayFacetedProject(proj)) { clearMarkers(proj);/*ww w .ja va 2s. c o m*/ if (SDKUtil.isSDKProject(fproj.getProject())) { IJavaProject javaProject = JavaCore.create(proj); for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) { return; } } if (fproj.getPrimaryRuntime() == null) { setMarker(proj, ProjectCore.LIFERAY_PROJECT_MARKER_TYPE, IMarker.SEVERITY_ERROR, MSG_PRIMARY_RUNTIME_NOT_SET, LOCATION_TARGETED_RUNTIMES, ID_PRIMARY_RUNTIME_NOT_SET); } else { if (!ServerUtil.isLiferayRuntime((BridgedRuntime) fproj.getPrimaryRuntime())) { setMarker(proj, ProjectCore.LIFERAY_PROJECT_MARKER_TYPE, IMarker.SEVERITY_ERROR, MSG_PRIMARY_RUNTIME_NOT_LIFERAY_RUNTIME, LOCATION_TARGETED_RUNTIMES, ID_PRIMARY_RUNTIME_NOT_LIFERAY_RUNTIME); } } } else if (!ProjectUtil.isMavenProject(proj)) { setMarker(proj, ProjectCore.LIFERAY_PROJECT_MARKER_TYPE, IMarker.SEVERITY_ERROR, Msgs.pluginSDKNotSet, LOCATION_TARGETED_SDK, ID_PLUGINS_SDK_NOT_SET); } } }
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());/* w ww. ja va 2 s . c om*/ 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.SDKProjectBuilder.java
License:Open Source License
protected IStatus updateClasspath(IProject project) throws CoreException { FlexibleProjectContainer container = J2EEComponentClasspathContainerUtils .getInstalledWebAppLibrariesContainer(project); if (container == null) { return Status.OK_STATUS; }/* www . jav a2 s.c o m*/ container.refresh(); container = J2EEComponentClasspathContainerUtils.getInstalledWebAppLibrariesContainer(project); IClasspathEntry[] webappEntries = container.getClasspathEntries(); for (IClasspathEntry entry2 : webappEntries) { if (entry2.getPath().lastSegment().equals(getProject().getName() + "-service.jar")) //$NON-NLS-1$ { ((ClasspathEntry) entry2).sourceAttachmentPath = getProject() .getFolder(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/service").getFullPath(); //$NON-NLS-1$ break; } } ClasspathContainerInitializer initializer = JavaCore .getClasspathContainerInitializer("org.eclipse.jst.j2ee.internal.web.container"); //$NON-NLS-1$ IJavaProject javaProject = JavaCore.create(project); initializer.requestClasspathContainerUpdate(container.getPath(), javaProject, container); return Status.OK_STATUS; }
From source file:com.liferay.ide.project.core.tests.ImportPluginsSDKProjectTests.java
License:Open Source License
private boolean isLiferayRuntimePluginClassPath(List<IClasspathEntry> entries, final String entryPath) { boolean retval = false; for (Iterator<IClasspathEntry> iterator = entries.iterator(); iterator.hasNext();) { IClasspathEntry entry = iterator.next(); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { for (String path : entry.getPath().segments()) { if (path.equals(entryPath)) { retval = true;//from ww w .j ava2 s . c o m break; } } } } return retval; }
From source file:com.liferay.ide.project.core.util.ClasspathUtil.java
License:Open Source License
public static boolean isPluginContainerEntry(final IClasspathEntry e) { return e != null && e.getEntryKind() == IClasspathEntry.CPE_CONTAINER && e.getPath().segment(0).equals(SDKClasspathContainer.ID); }
From source file:com.liferay.ide.project.core.util.ClasspathUtil.java
License:Open Source License
public static boolean hasNewLiferaySDKContainer(final IClasspathEntry[] entries) { boolean retVal = false; for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) { retVal = true;// www.j ava2 s . c o m break; } } return retVal; }
From source file:com.liferay.ide.project.core.util.ClasspathUtil.java
License:Open Source License
public static void updateRequestContainer(IProject project) throws CoreException { final IJavaProject javaProject = JavaCore.create(project); IPath containerPath = null;/*from www . ja v a2s . c om*/ final IClasspathEntry[] entries = javaProject.getRawClasspath(); for (final IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) { containerPath = entry.getPath(); break; } } } if (containerPath != null) { final IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(containerPath, javaProject); final String id = containerPath.segment(0); if (id.equals(SDKClasspathContainer.ID)) { ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(id); initializer.requestClasspathContainerUpdate(containerPath, javaProject, classpathContainer); } } }
From source file:com.liferay.ide.project.core.util.ProjectUtil.java
License:Open Source License
public static IProject createExistingProject(final ProjectRecord record, IRuntime runtime, String sdkLocation, IProgressMonitor monitor) throws CoreException { String projectName = record.getProjectName(); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(projectName); if (record.description == null) { // error case record.description = workspace.newProjectDescription(projectName); IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath()); // If it is under the root use the default location if (Platform.getLocation().isPrefixOf(locationPath)) { record.description.setLocation(null); } else {// w w w .j a v a 2s . c om record.description.setLocation(locationPath); } } else { record.description.setName(projectName); } monitor.beginTask(Msgs.importingProject, 100); project.create(record.description, new SubProgressMonitor(monitor, 30)); project.open(IResource.FORCE, new SubProgressMonitor(monitor, 70)); // need to check to see if we an ext project with source folders with incorrect parent attributes if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) { fixExtProjectClasspathEntries(project); } IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor); FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject); String pluginType = guessPluginType(fpwc); SDKPluginFacetUtil.configureProjectAsRuntimeProject(fpwc, runtime, pluginType, sdkLocation, record); fpwc.commitChanges(monitor); final IJavaProject javaProject = JavaCore.create(fProject.getProject()); ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().segment(0).equals(PluginClasspathContainerInitializer.ID)) { JavaCore.getClasspathContainerInitializer(PluginClasspathContainerInitializer.ID) .initialize(entry.getPath(), javaProject); break; } } monitor.done(); } }, monitor); return project; }
From source file:com.liferay.ide.project.core.util.ProjectUtil.java
License:Open Source License
public static IProject createExistingProject(final ProjectRecord record, final IPath sdkLocation, IProgressMonitor monitor) throws CoreException { String projectName = record.getProjectName(); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject(projectName); if (record.description == null) { // error case record.description = workspace.newProjectDescription(projectName); IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath()); // If it is under the root use the default location if (Platform.getLocation().isPrefixOf(locationPath)) { record.description.setLocation(null); } else {/* w ww. j a va 2 s. c om*/ record.description.setLocation(locationPath); } } else { record.description.setName(projectName); } project.create(record.description, new SubProgressMonitor(monitor, 30)); project.open(IResource.FORCE, new SubProgressMonitor(monitor, 70)); // need to check to see if we an ext project with source folders with incorrect parent attributes if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) { fixExtProjectClasspathEntries(project); } IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor); FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject); final String pluginType = guessPluginType(fpwc); SDKPluginFacetUtil.configureProjectAsSDKProject(fpwc, pluginType, sdkLocation.toPortableString(), record); fpwc.commitChanges(monitor); final IJavaProject javaProject = JavaCore.create(fProject.getProject()); ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { List<IClasspathEntry> rawClasspaths = new ArrayList<IClasspathEntry>(); IPath containerPath = null; for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) { containerPath = entry.getPath(); break; } if (!isLiferayRuntimePluginClassPath(entry)) { rawClasspaths.add(entry); } } if (containerPath != null) { JavaCore.getClasspathContainerInitializer(SDKClasspathContainer.ID).initialize(containerPath, javaProject); } else { javaProject.setRawClasspath(rawClasspaths.toArray(new IClasspathEntry[rawClasspaths.size()]), new NullProgressMonitor()); javaProject.setRawClasspath(rawClasspaths.toArray(new IClasspathEntry[rawClasspaths.size()]), new NullProgressMonitor()); IAccessRule[] accessRules = new IAccessRule[] {}; IClasspathAttribute[] attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute( IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, StringPool.EMPTY) }; IPath cpePath = new Path(SDKClasspathContainer.ID); ; IClasspathEntry newEntry = JavaCore.newContainerEntry(cpePath, accessRules, attributes, false); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getPath().equals(cpePath)) { return; } } IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[entries.length] = newEntry; javaProject.setRawClasspath(newEntries, monitor); } monitor.done(); final SDK sdk = SDKUtil.createSDKFromLocation(sdkLocation); SDKUtil.openAsProject(sdk); } }, monitor); return project; }
From source file:com.liferay.ide.project.core.util.ProjectUtil.java
License:Open Source License
private static boolean isLiferayRuntimePluginClassPath(IClasspathEntry entry) { boolean retval = false; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { for (String path : entry.getPath().segments()) { if (path.equals(PluginClasspathContainerInitializer.ID) || path.equals("com.liferay.studio.server.tomcat.runtimeClasspathProvider") || path.equals("com.liferay.ide.eclipse.server.tomcat.runtimeClasspathProvider")) { retval = true;/*from w w w . ja v a 2 s . c om*/ break; } } } return retval; }