List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER
int CPE_CONTAINER
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.
Click Source Link
From source file:org.eclipse.jst.ws.jaxrs.core.jaxrslibraryconfiguration.internal.JAXRSLibraryConfigurationHelper.java
License:Open Source License
/** * @param cpEntry/*from w w w.ja v a2s . com*/ * @return boolean indicating that the classpath entry is a JAXRS Libary * Classpath Container */ public static boolean isJAXRSLibraryContainer(IClasspathEntry cpEntry) { if (cpEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) return false; IPath path = cpEntry.getPath(); return path != null && path.segmentCount() == 2 && JAXRS_LIBRARY_CP_CONTAINER_ID.equals(path.segment(0)); }
From source file:org.eclipse.m2e.jdt.internal.BuildPathManager.java
License:Open Source License
public static IClasspathContainer getMaven2ClasspathContainer(IJavaProject project) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) { return JavaCore.getClasspathContainer(entry.getPath(), project); }/* w w w .j a v a 2s . co m*/ } return null; }
From source file:org.eclipse.m2e.jdt.internal.ClasspathEntryDescriptor.java
License:Open Source License
public IClasspathEntry toClasspathEntry() { Map<String, String> attributes = new LinkedHashMap<String, String>(this.attributes); if (artifactKey != null) { attributes.put(IClasspathManager.GROUP_ID_ATTRIBUTE, artifactKey.getGroupId()); attributes.put(IClasspathManager.ARTIFACT_ID_ATTRIBUTE, artifactKey.getArtifactId()); attributes.put(IClasspathManager.VERSION_ATTRIBUTE, artifactKey.getVersion()); if (artifactKey.getClassifier() != null) { attributes.put(IClasspathManager.CLASSIFIER_ATTRIBUTE, artifactKey.getClassifier()); }//w w w . j a va 2s . c o m } if (scope != null) { attributes.put(IClasspathManager.SCOPE_ATTRIBUTE, scope); } IClasspathAttribute[] attributesArray = new IClasspathAttribute[attributes.size()]; int attributeIndex = 0; for (Map.Entry<String, String> attribute : attributes.entrySet()) { attributesArray[attributeIndex++] = JavaCore.newClasspathAttribute(attribute.getKey(), attribute.getValue()); } IAccessRule[] accessRulesArray = accessRules.toArray(new IAccessRule[accessRules.size()]); IClasspathEntry entry; switch (entryKind) { case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(path, // accessRulesArray, // attributesArray, // exported); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(path, // sourceAttachmentPath, // sourceAttachmentRootPath, // accessRulesArray, // attributesArray, // exported); break; case IClasspathEntry.CPE_SOURCE: entry = JavaCore.newSourceEntry(path, // getInclusionPatterns(), // getExclusionPatterns(), // outputLocation, // attributesArray); break; case IClasspathEntry.CPE_PROJECT: entry = JavaCore.newProjectEntry(path, // accessRulesArray, // combineAccessRules, // attributesArray, // exported); break; default: throw new IllegalArgumentException("Unsupported IClasspathEntry kind=" + entryKind); //$NON-NLS-1$ } return entry; }
From source file:org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider.java
License:Open Source License
protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier, ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(path.segment(0)); IMavenProjectFacade projectFacade = projectManager.create(project, monitor); if (projectFacade == null) { return;//from ww w. j av a 2 s . co m } ResolverConfiguration configuration = projectFacade.getResolverConfiguration(); if (configuration == null) { return; } IJavaProject javaProject = JavaCore.create(project); boolean projectResolved = false; for (IClasspathEntry entry : javaProject.getRawClasspath()) { IRuntimeClasspathEntry rce = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (!projectResolved) { IMavenClassifierManager mavenClassifierManager = MavenJdtPlugin.getDefault() .getMavenClassifierManager(); IClassifierClasspathProvider classifierClasspathProvider = mavenClassifierManager .getClassifierClasspathProvider(projectFacade, classifier); if (IClasspathManager.CLASSPATH_TEST == scope) { classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor); } else { classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor); } projectResolved = true; } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null && !MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) { switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: rce = JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.USER_CLASSES, javaProject); break; // case IClasspathContainer.K_DEFAULT_SYSTEM: // unresolved.add(JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.STANDARD_CLASSES, javaProject)); // break; // case IClasspathContainer.K_SYSTEM: // unresolved.add(JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.BOOTSTRAP_CLASSES, javaProject)); // break; } } break; case IClasspathEntry.CPE_LIBRARY: rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); break; case IClasspathEntry.CPE_VARIABLE: if (!JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) { rce = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath()); } break; case IClasspathEntry.CPE_PROJECT: IProject res = root.getProject(entry.getPath().segment(0)); if (res != null) { IJavaProject otherProject = JavaCore.create(res); if (otherProject != null) { rce = JavaRuntime.newDefaultProjectClasspathEntry(otherProject); } } break; default: break; } if (rce != null) { addStandardClasspathEntries(resolved, rce, launchConfiguration); } } }
From source file:org.eclipse.m2e.wtp.tests.AbstractWTPTestCase.java
License:Open Source License
protected static IClasspathContainer getWebLibClasspathContainer(IJavaProject project) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && "org.eclipse.jst.j2ee.internal.web.container".equals(entry.getPath().segment(0))) { return JavaCore.getClasspathContainer(entry.getPath(), project); }/*w w w .ja va 2 s. c om*/ } return null; }
From source file:org.eclipse.m2e.wtp.WTPProjectsUtil.java
License:Open Source License
public static void updateContainerAttributes(IProject project, IClasspathAttribute attributeToAdd, String attributeToDelete, IProgressMonitor monitor) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) return;// w ww . j a v a 2 s. com IClasspathEntry[] cp = javaProject.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if (IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind() && MavenClasspathHelpers.isMaven2ClasspathContainer(cp[i].getPath())) { LinkedHashMap<String, IClasspathAttribute> attrs = new LinkedHashMap<String, IClasspathAttribute>(); for (IClasspathAttribute attr : cp[i].getExtraAttributes()) { if (!attr.getName().equals(attributeToDelete)) { attrs.put(attr.getName(), attr); } } attrs.put(attributeToAdd.getName(), attributeToAdd); IClasspathAttribute[] newAttrs = attrs.values().toArray(new IClasspathAttribute[attrs.size()]); cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newAttrs, cp[i].isExported()); break; } } javaProject.setRawClasspath(cp, monitor); }
From source file:org.eclipse.objectteams.otdt.core.ext.OTREContainer.java
License:Open Source License
private static boolean isOTREAlreadyInClasspath(IClasspathEntry[] classpath) { for (int idx = 0; classpath != null && idx < classpath.length; idx++) { IClasspathEntry entry = classpath[idx]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && (entry.getPath().equals(OTRE_CONTAINER_PATH))) return true; }//from w w w .j a va 2s.c om return false; }
From source file:org.eclipse.pde.internal.core.builders.BundleErrorReporter.java
License:Open Source License
private void validateRequiredExecutionEnvironment() { int sev = CompilerFlags.getFlag(fProject, CompilerFlags.P_INCOMPATIBLE_ENV); if (sev == CompilerFlags.IGNORE) return;/* ww w . j a va 2s . c om*/ BundleDescription desc = fModel.getBundleDescription(); if (desc == null) return; // if we aren't a java project, let's not check for a BREE try { if (!fProject.hasNature(JavaCore.NATURE_ID)) return; } catch (CoreException e) { return; } String[] bundleEnvs = desc.getExecutionEnvironments(); if (bundleEnvs == null || bundleEnvs.length == 0) { // No EE specified IJavaProject javaProject = JavaCore.create(fProject); // See if the project has an EE classpath entry if (javaProject.exists()) { try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath currentPath = entries[i].getPath(); if (JavaRuntime.newDefaultJREContainerPath().matchingFirstSegments(currentPath) > 0) { String eeId = JavaRuntime.getExecutionEnvironmentId(currentPath); if (eeId != null) { IMarker marker = report( PDECoreMessages.BundleErrorReporter_noExecutionEnvironmentSet, 1, sev, PDEMarkerFactory.M_EXECUTION_ENVIRONMENT_NOT_SET, PDEMarkerFactory.CAT_EE); addMarkerAttribute(marker, "ee_id", eeId); //$NON-NLS-1$ return; } } } } } catch (JavaModelException e) { PDECore.log(e); } } // If no EE classpath entry, get a matching EE for the project JRE (or the default JRE) IExecutionEnvironment[] systemEnvs = JavaRuntime.getExecutionEnvironmentsManager() .getExecutionEnvironments(); IVMInstall vm = JavaRuntime.getDefaultVMInstall(); if (javaProject.exists()) { try { vm = JavaRuntime.getVMInstall(javaProject); } catch (CoreException e) { PDECore.log(e); } } if (vm != null) { for (int i = 0; i < systemEnvs.length; i++) { // Get strictly compatible EE for the default VM if (systemEnvs[i].isStrictlyCompatible(vm)) { IMarker marker = report(PDECoreMessages.BundleErrorReporter_noExecutionEnvironmentSet, 1, sev, PDEMarkerFactory.M_EXECUTION_ENVIRONMENT_NOT_SET, PDEMarkerFactory.CAT_EE); addMarkerAttribute(marker, "ee_id", systemEnvs[i].getId()); //$NON-NLS-1$ break; } } } return; } IHeader header = getHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); if (header == null) return; IExecutionEnvironment env = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(bundleEnvs[0]); if (env != null) { IJavaProject jproject = JavaCore.create(fProject); IClasspathEntry[] entries; try { entries = jproject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() != IClasspathEntry.CPE_CONTAINER) continue; IPath currentPath = entries[i].getPath(); if (JavaRuntime.newDefaultJREContainerPath().matchingFirstSegments(currentPath) == 0) continue; IPath validPath = JavaRuntime.newJREContainerPath(env); if (!validPath.equals(currentPath)) { // Check if the user is using a perfect match JRE IVMInstall vm = JavaRuntime.getVMInstall(currentPath); if (vm == null || !env.isStrictlyCompatible(vm)) { report(NLS.bind(PDECoreMessages.BundleErrorReporter_reqExecEnv_conflict, bundleEnvs[0]), getLine(header, bundleEnvs[0]), sev, PDEMarkerFactory.M_MISMATCHED_EXEC_ENV, PDEMarkerFactory.CAT_EE); } } } } catch (JavaModelException e) { } } IExecutionEnvironment[] systemEnvs = JavaRuntime.getExecutionEnvironmentsManager() .getExecutionEnvironments(); for (int i = 0; i < bundleEnvs.length; i++) { boolean found = false; for (int j = 0; j < systemEnvs.length; j++) { if (bundleEnvs[i].equals(systemEnvs[j].getId())) { found = true; break; } } if (!found) { report(NLS.bind(PDECoreMessages.BundleErrorReporter_reqExecEnv_unknown, bundleEnvs[i]), getLine(header, bundleEnvs[i]), sev, PDEMarkerFactory.M_UNKNOW_EXEC_ENV, PDEMarkerFactory.CAT_EE); break; } } }
From source file:org.eclipse.pde.internal.core.project.ProjectModifyOperation.java
License:Open Source License
/** * Creates or modifies a project based on the given description. * /*from w ww . ja va2 s .co m*/ * @param monitor progress monitor or <code>null</code> * @param description project description * @throws CoreException if project creation fails */ public void execute(IProgressMonitor monitor, IBundleProjectDescription description) throws CoreException { // retrieve current description of the project to detect differences IProject project = description.getProject(); IBundleProjectService service = (IBundleProjectService) PDECore.getDefault() .acquireService(IBundleProjectService.class.getName()); IBundleProjectDescription before = service.getDescription(project); boolean considerRoot = !project.exists(); String taskName = null; boolean jpExisted = false; if (project.exists()) { taskName = Messages.ProjectModifyOperation_0; jpExisted = before.hasNature(JavaCore.NATURE_ID); } else { taskName = Messages.ProjectModifyOperation_1; // new bundle projects get Java and Plug-in natures if (description.getNatureIds().length == 0) { description .setNatureIds(new String[] { IBundleProjectDescription.PLUGIN_NATURE, JavaCore.NATURE_ID }); } } boolean becomeBundle = !before.hasNature(IBundleProjectDescription.PLUGIN_NATURE) && description.hasNature(IBundleProjectDescription.PLUGIN_NATURE); // set default values when migrating from Java project to bundle project if (jpExisted && becomeBundle) { if (description.getExecutionEnvironments() == null) { // use EE from Java project when unspecified in the description, and a bundle nature is being added IJavaProject jp = JavaCore.create(project); if (jp.exists()) { IClasspathEntry[] classpath = jp.getRawClasspath(); for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String id = JavaRuntime.getExecutionEnvironmentId(entry.getPath()); if (id != null) { description.setExecutionEnvironments(new String[] { id }); break; } } } } } } // other default values when becoming a bundle if (becomeBundle) { // set default values for where unspecified if (description.getBundleVersion() == null) { description.setBundleVersion(new Version(1, 0, 0, "qualifier")); //$NON-NLS-1$ } } SubMonitor sub = SubMonitor.convert(monitor, taskName, 6); // create and open project createProject(description); // set bundle root for new projects if (considerRoot) { IFolder folder = null; IPath root = description.getBundleRoot(); if (root != null && !root.isEmpty()) { folder = project.getFolder(root); CoreUtility.createFolder(folder); } PDEProject.setBundleRoot(project, folder); } sub.worked(1); configureNatures(description); sub.worked(1); if (project.hasNature(JavaCore.NATURE_ID)) { configureJavaProject(description, before, jpExisted); } sub.worked(1); configureManifest(description, before); sub.worked(1); configureBuildPropertiesFile(description, before); sub.worked(1); // project settings for Equinox, Extension Registry, Automated dependency policy, // manifest editor launch shortcuts and export wizard IEclipsePreferences pref = new ProjectScope(project).getNode(PDECore.PLUGIN_ID); if (pref != null) { // best guess for automated dependency management: Equinox + Extensions = use required bundle if (description.isEquinox() && description.isExtensionRegistry()) { pref.remove(ICoreConstants.RESOLVE_WITH_REQUIRE_BUNDLE); // i.e. use required bundle } else { pref.putBoolean(ICoreConstants.RESOLVE_WITH_REQUIRE_BUNDLE, false); } if (description.isExtensionRegistry()) { pref.remove(ICoreConstants.EXTENSIONS_PROPERTY); // i.e. support extensions } else { pref.putBoolean(ICoreConstants.EXTENSIONS_PROPERTY, false); } if (description.isEquinox()) { pref.remove(ICoreConstants.EQUINOX_PROPERTY); // i.e. using Equinox } else { pref.putBoolean(ICoreConstants.EQUINOX_PROPERTY, false); } String[] shorts = description.getLaunchShortcuts(); if (shorts == null || shorts.length == 0) { pref.remove(ICoreConstants.MANIFEST_LAUNCH_SHORTCUTS); // use defaults } else { StringBuffer value = new StringBuffer(); for (int i = 0; i < shorts.length; i++) { if (i > 0) { value.append(','); } value.append(shorts[i]); } pref.put(ICoreConstants.MANIFEST_LAUNCH_SHORTCUTS, value.toString()); } if (description.getExportWizardId() == null) { pref.remove(ICoreConstants.MANIFEST_EXPORT_WIZARD); } else { pref.put(ICoreConstants.MANIFEST_EXPORT_WIZARD, description.getExportWizardId()); } try { pref.flush(); } catch (BackingStoreException e) { throw new CoreException( new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.ProjectModifyOperation_2, e)); } } if (fModel.isDirty()) { fModel.save(); } sub.worked(1); sub.done(); if (monitor != null) { monitor.done(); } }
From source file:org.eclipse.pde.internal.core.project.ProjectModifyOperation.java
License:Open Source License
/** * Configures the build path and output location of the described Java project. * If the Java project existed before this operation, new build path entries are * added for the bundle class path, if required, but we don't change the exiting * build path.//from ww w . ja va 2s.c o m * * @param description desired project description * @param before state before the operation * @param existed whether the Java project existed before the operation */ private void configureJavaProject(IBundleProjectDescription description, IBundleProjectDescription before, boolean existed) throws CoreException { IProject project = description.getProject(); IJavaProject javaProject = JavaCore.create(project); // create source folders as required IBundleClasspathEntry[] bces = description.getBundleClasspath(); if (bces != null && bces.length > 0) { for (int i = 0; i < bces.length; i++) { IPath folder = bces[i].getSourcePath(); if (folder != null) { CoreUtility.createFolder(project.getFolder(folder)); } } } // Set default output folder if (description.getDefaultOutputFolder() != null) { IPath path = project.getFullPath().append(description.getDefaultOutputFolder()); javaProject.setOutputLocation(path, null); } // merge the class path if the project existed before IBundleClasspathEntry[] prev = before.getBundleClasspath(); if (!isEqual(bces, prev)) { if (existed) { // add entries not already present IClasspathEntry[] entries = getSourceFolderEntries(javaProject, description); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); List<IClasspathEntry> add = new ArrayList<IClasspathEntry>(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; boolean present = false; for (int j = 0; j < rawClasspath.length; j++) { IClasspathEntry existingEntry = rawClasspath[j]; if (existingEntry.getEntryKind() == entry.getEntryKind()) { if (existingEntry.getPath().equals(entry.getPath())) { present = true; break; } } } if (!present) { add.add(entry); } } // check if the 'required plug-ins' container is present boolean addRequired = false; if (description.hasNature(IBundleProjectDescription.PLUGIN_NATURE)) { addRequired = true; for (int i = 0; i < rawClasspath.length; i++) { IClasspathEntry cpe = rawClasspath[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (PDECore.REQUIRED_PLUGINS_CONTAINER_PATH.equals(cpe.getPath())) { addRequired = false; break; } } } } if (addRequired) { add.add(ClasspathComputer.createContainerEntry()); } if (!add.isEmpty()) { List<IClasspathEntry> all = new ArrayList<IClasspathEntry>(); for (int i = 0; i < rawClasspath.length; i++) { all.add(rawClasspath[i]); } all.addAll(add); javaProject.setRawClasspath(all.toArray(new IClasspathEntry[all.size()]), null); } } else { IClasspathEntry[] entries = getClassPathEntries(javaProject, description); javaProject.setRawClasspath(entries, null); } } }