List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
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 w w. j a v a 2 s .c o m*/ 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 void fixExtProjectClasspathEntries(IProject project) { try {//w ww .j a v a2s. 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 ww w. j a v a2 s . c o m } catch (Exception e) { ProjectCore.logError(e); } } } } } } } } }
From source file:com.liferay.ide.project.ui.IvyUtil.java
License:Open Source License
public static IvyClasspathContainer addIvyLibrary(IProject project, IProgressMonitor monitor) { final String projectName = project.getName(); final IJavaProject javaProject = JavaCore.create(project); final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(javaProject, ISDKConstants.IVY_XML_FILE, true); final ClasspathSetup classpathSetup = new ClasspathSetup(); conf.setAdvancedProjectSpecific(false); conf.setClasspathSetup(classpathSetup); conf.setClassthProjectSpecific(false); conf.setConfs(Collections.singletonList("*")); //$NON-NLS-1$ conf.setMappingProjectSpecific(false); conf.setSettingsProjectSpecific(true); SDK sdk = SDKUtil.getSDK(project);/*w w w .j ava2 s . c o m*/ final SettingsSetup settingsSetup = new SettingsSetup(); if (sdk.getLocation().append(ISDKConstants.IVY_SETTINGS_XML_FILE).toFile().exists()) { StringBuilder builder = new StringBuilder(); builder.append("${"); //$NON-NLS-1$ builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR); builder.append(":"); //$NON-NLS-1$ builder.append(projectName); builder.append("}/"); //$NON-NLS-1$ builder.append(ISDKConstants.IVY_SETTINGS_XML_FILE); settingsSetup.setIvySettingsPath(builder.toString()); } StringBuilder builder = new StringBuilder(); builder.append("${"); //$NON-NLS-1$ builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR); builder.append(":"); //$NON-NLS-1$ builder.append(projectName); builder.append("}/.ivy"); //$NON-NLS-1$ settingsSetup.setIvyUserDir(builder.toString()); conf.setIvySettingsSetup(settingsSetup); final IPath path = conf.getPath(); final IClasspathAttribute[] atts = conf.getAttributes(); final IClasspathEntry ivyEntry = JavaCore.newContainerEntry(path, null, atts, false); final IVirtualComponent virtualComponent = ComponentCore.createComponent(project); try { IClasspathEntry[] entries = javaProject.getRawClasspath(); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(Arrays.asList(entries)); IPath runtimePath = getDefaultRuntimePath(virtualComponent, ivyEntry); // add the deployment assembly config to deploy ivy container to /WEB-INF/lib final IClasspathEntry cpeTagged = modifyDependencyPath(ivyEntry, runtimePath); newEntries.add(cpeTagged); entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]); javaProject.setRawClasspath(entries, javaProject.getOutputLocation(), monitor); IvyClasspathContainer ivycp = IvyClasspathContainerHelper.getContainer(path, javaProject); return ivycp; } catch (JavaModelException e) { ProjectUI.logError("Unable to add Ivy library container", e); //$NON-NLS-1$ } return null; }
From source file:com.liferay.ide.project.ui.wizard.NewPluginProjectWizard.java
License:Open Source License
private IvyClasspathContainer addIvyLibrary(IProject project, IProgressMonitor monitor) { final String projectName = project.getName(); final IJavaProject javaProject = JavaCore.create(project); final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(javaProject, ISDKConstants.IVY_XML_FILE, true); final ClasspathSetup classpathSetup = new ClasspathSetup(); conf.setAdvancedProjectSpecific(false); conf.setClasspathSetup(classpathSetup); conf.setClassthProjectSpecific(false); conf.setConfs(Collections.singletonList("*")); //$NON-NLS-1$ conf.setMappingProjectSpecific(false); conf.setSettingsProjectSpecific(true); SDK sdk = SDKUtil.getSDK(project);//from w w w . jav a 2 s.co m final SettingsSetup settingsSetup = new SettingsSetup(); if (sdk.getLocation().append(ISDKConstants.IVY_SETTINGS_XML_FILE).toFile().exists()) { StringBuilder builder = new StringBuilder(); builder.append("${"); //$NON-NLS-1$ builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR); builder.append(":"); //$NON-NLS-1$ builder.append(projectName); builder.append("}/"); //$NON-NLS-1$ builder.append(ISDKConstants.IVY_SETTINGS_XML_FILE); settingsSetup.setIvySettingsPath(builder.toString()); } StringBuilder builder = new StringBuilder(); builder.append("${"); //$NON-NLS-1$ builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR); builder.append(":"); //$NON-NLS-1$ builder.append(projectName); builder.append("}/.ivy"); //$NON-NLS-1$ settingsSetup.setIvyUserDir(builder.toString()); conf.setIvySettingsSetup(settingsSetup); final IPath path = IvyClasspathContainerConfAdapter.getPath(conf); final IClasspathAttribute[] atts = conf.getAttributes(); final IClasspathEntry ivyEntry = JavaCore.newContainerEntry(path, null, atts, false); final IVirtualComponent virtualComponent = ComponentCore.createComponent(project); try { IvyClasspathContainer ivycp = new IvyClasspathContainer(javaProject, path, new IClasspathEntry[0], new IClasspathAttribute[0]); JavaCore.setClasspathContainer(path, new IJavaProject[] { javaProject }, new IClasspathContainer[] { ivycp }, monitor); IClasspathEntry[] entries = javaProject.getRawClasspath(); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(Arrays.asList(entries)); IPath runtimePath = getDefaultRuntimePath(virtualComponent, ivyEntry); // add the deployment assembly config to deploy ivy container to /WEB-INF/lib final IClasspathEntry cpeTagged = modifyDependencyPath(ivyEntry, runtimePath); newEntries.add(cpeTagged); entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]); javaProject.setRawClasspath(entries, javaProject.getOutputLocation(), monitor); return ivycp; } catch (JavaModelException e) { ProjectUIPlugin.logError("Unable to add Ivy library container", e); //$NON-NLS-1$ } return null; }
From source file:com.liferay.ide.sdk.ui.SDKProjectRenameParticipant.java
License:Open Source License
@Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { final String newName = this.getArguments().getNewName(); return new Change() { @Override//from ww w .j a v a2 s . co m public String getName() { return "Update Ivy classpath entry"; //$NON-NLS-1$ } @Override public void initializeValidationData(IProgressMonitor pm) { System.out.println(); } @Override public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException { return new RefactoringStatus(); } @Override public Change perform(IProgressMonitor pm) throws CoreException { final RenameJavaProjectProcessor rjpp = (RenameJavaProjectProcessor) getProcessor(); final IJavaProject newJavaProject = (IJavaProject) rjpp.getNewElement(); final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration( newJavaProject, ISDKConstants.IVY_XML_FILE, true); IClasspathEntry oldEntry = null; for (IClasspathEntry cpEntry : newJavaProject.getRawClasspath()) { if (cpEntry.getPath().segment(0).equals(IvyClasspathContainer.CONTAINER_ID)) { oldEntry = cpEntry; break; } } IvyClasspathContainerConfAdapter.load(conf, oldEntry.getPath(), oldEntry.getExtraAttributes()); final String oldIvySettingsPath = conf.getIvySettingsSetup().getRawIvySettingsPath(); final String oldIvyUserDir = conf.getIvySettingsSetup().getRawIvyUserDir(); conf.setProject(newJavaProject); conf.getIvySettingsSetup().setIvySettingsPath(oldIvySettingsPath.replaceAll(oldName, newName)); conf.getIvySettingsSetup().setIvyUserDir(oldIvyUserDir.replaceAll(oldName, newName)); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry cpEntry : newJavaProject.getRawClasspath()) { if (!cpEntry.getPath().segment(0).equals(IvyClasspathContainer.CONTAINER_ID)) { newEntries.add(cpEntry); } } IPath newIvyPath = IvyClasspathContainerConfAdapter.getPath(conf); newJavaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), pm); IClasspathEntry ivyEntry = JavaCore.newContainerEntry(newIvyPath, null, oldEntry.getExtraAttributes(), false); IvyClasspathContainer ivycp = new IvyClasspathContainer(newJavaProject, newIvyPath, new IClasspathEntry[0], new IClasspathAttribute[0]); JavaCore.setClasspathContainer(newIvyPath, new IJavaProject[] { newJavaProject }, new IClasspathContainer[] { ivycp }, pm); IClasspathEntry[] entries = newJavaProject.getRawClasspath(); newEntries.add(ivyEntry); entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]); newJavaProject.setRawClasspath(entries, newJavaProject.getOutputLocation(), pm); JavaCore.getClasspathContainerInitializer(IvyClasspathContainer.CONTAINER_ID) .requestClasspathContainerUpdate(newIvyPath, newJavaProject, ivycp); ivycp.launchResolve(false, pm); return null; } @Override public Object getModifiedElement() { return null; } }; }
From source file:com.liferay.ide.server.remote.ModuleTraverser.java
License:Open Source License
private static IClasspathEntry getClasspathEntry(IJavaProject project, IPath sourcePath) throws JavaModelException { sourcePath = project.getPath().append(sourcePath); IClasspathEntry[] cp = project.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if (sourcePath.equals(cp[i].getPath())) return JavaCore.getResolvedClasspathEntry(cp[i]); }// w ww .ja v a 2 s . com return null; }
From source file:com.liferay.ide.server.remote.ModuleTraverser.java
License:Open Source License
private static Map getRawComponentClasspathDependencies(final IJavaProject javaProject) throws CoreException { if (javaProject == null) { return Collections.EMPTY_MAP; }// ww w . j a va 2 s . c o m final Map<IClasspathEntry, IClasspathAttribute> referencedRawEntries = new HashMap<IClasspathEntry, IClasspathAttribute>(); final IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; final IClasspathAttribute attrib = checkForComponentDependencyAttribute(entry, DEPENDECYATTRIBUTETYPE_CLASSPATH_COMPONENT_DEPENDENCY); if (attrib != null) { referencedRawEntries.put(entry, attrib); } } return referencedRawEntries; }
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 ww w.jav a2 s .c o m 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.applicationinsights.ui.config.AIProjConfigWizardDialog.java
License:Open Source License
private void configureAzureSDK(IJavaProject proj) { try {// w w w.j a va 2 s .c o m IClasspathEntry[] classpath = proj.getRawClasspath(); for (IClasspathEntry iClasspathEntry : classpath) { final IPath containerPath = iClasspathEntry.getPath(); if (containerPath.toString().contains(Messages.azureSDKcontainerID)) { return; } } List<IClasspathEntry> list = new ArrayList<IClasspathEntry>(java.util.Arrays.asList(classpath)); IClasspathAttribute[] attr = new IClasspathAttribute[1]; attr[0] = JavaCore.newClasspathAttribute(Messages.jstDep, "/WEB-INF/lib"); IClasspathEntry jarEntry = JavaCore.newContainerEntry( new Path(Messages.azureSDKcontainerID).append(getLatestSDKVersion()), null, attr, false); list.add(jarEntry); IClasspathEntry[] newClasspath = (IClasspathEntry[]) list.toArray(new IClasspathEntry[0]); proj.setRawClasspath(newClasspath, null); // Azure SDK configured - application insights configured for the first time for specific project Bundle bundle = Activator.getDefault().getBundle(); if (bundle != null) { PluginUtil.showBusy(true, getShell()); AppInsightsCustomEvent.create("Application Insights", bundle.getVersion().toString()); PluginUtil.showBusy(false, getShell()); } } catch (Exception e) { Activator.getDefault().log(e.getMessage(), e); } }