List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
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 w w w.j a va 2 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;//from w ww .j a v a 2 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;/* w ww .j a v a 2 s . c o m*/ 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 ava2 s. com 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 {/*ww w. j ava 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 www . j a v a 2s . c om break; } } } return retval; }
From source file:com.liferay.ide.project.core.util.ProjectUtil.java
License:Open Source License
private static void fixExtProjectClasspathEntries(IProject project) { try {//from ww w .j a va2 s . c om 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); }/*from w ww .j a va 2s. com*/ } 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; }/*from ww w . j av 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; }