List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:org.eclipse.jst.server.jetty.core.internal.wst.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 a v a2 s. c om*/ String runtimePath = getRuntimePath(attrib, isWebApp, isClassFolder); if (!isWebApp) { if (!runtimePath.equals("../") && !runtimePath.equals("/")) { return false; } if (isClassFolder && !runtimePath.equals("/")) { return false; } } else { if (runtimePath != null && !runtimePath.equals("/WEB-INF/lib") && !runtimePath.equals("/WEB-INF/classes") && !runtimePath.equals("../")) { return false; } if (isClassFolder && !runtimePath.equals("/WEB-INF/classes")) { return false; } } return true; }
From source file:org.eclipse.jst.servlet.ui.internal.navigator.CompressedJavaLibraries.java
License:Open Source License
public Object[] getChildren(ITreeContentProvider delegateContentProvider) { List classpathContainers = new ArrayList(); Object[] delegateChildren = delegateContentProvider.getChildren(compressedProject.getProject()); for (int i = 0; i < delegateChildren.length; i++) { if (delegateChildren[i] instanceof IPackageFragmentRoot) { try { IClasspathEntry rawClasspathEntry = ((IPackageFragmentRoot) delegateChildren[i]) .getRawClasspathEntry(); if (rawClasspathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && rawClasspathEntry.getEntryKind() != IClasspathEntry.CPE_SOURCE) classpathContainers.add(delegateChildren[i]); } catch (JavaModelException e) { }/*from w w w . ja va2 s .c om*/ } else if (!(delegateChildren[i] instanceof IJavaElement) && !(delegateChildren[i] instanceof IResource)) { classpathContainers.add(delegateChildren[i]); } } return classpathContainers.toArray(); }
From source file:org.eclipse.jst.ws.internal.axis.consumption.ui.util.ClasspathUtils.java
License:Open Source License
private String[] classpathEntry2String(IClasspathEntry entry, IProject project) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: { return new String[] { path2String(entry.getPath()) }; }//from w ww.java 2 s. co m case IClasspathEntry.CPE_PROJECT: { return getClasspath(ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()), true); } case IClasspathEntry.CPE_SOURCE: { IPath path = entry.getPath(); if (path.segment(0).equals(project.getName())) path = path.removeFirstSegments(1); return new String[] { path2String(project.getLocation().addTrailingSeparator().append(path)) }; } case IClasspathEntry.CPE_VARIABLE: { return classpathEntry2String(JavaCore.getResolvedClasspathEntry(entry), project); } default: { return new String[] { path2String(entry.getPath()) }; } } }
From source file:org.eclipse.m2e.jdt.internal.ClasspathDescriptor.java
License:Open Source License
public ClasspathEntryDescriptor addSourceEntry(IPath sourcePath, IPath outputLocation, IPath[] inclusion, IPath[] exclusion, boolean generated) { // IWorkspaceRoot workspaceRoot = project.getProject().getWorkspace().getRoot(); ////from w w w . j a v a 2 s. c o m // Util.createFolder(workspaceRoot.getFolder(sourcePath), generated); ClasspathEntryDescriptor descriptor = new ClasspathEntryDescriptor(IClasspathEntry.CPE_SOURCE, sourcePath); descriptor.setOutputLocation(outputLocation); descriptor.setInclusionPatterns(inclusion); descriptor.setExclusionPatterns(exclusion); if (generated) { descriptor.setClasspathAttribute(IClasspathAttribute.OPTIONAL, "true"); //$NON-NLS-1$ } addEntryDescriptor(descriptor); return descriptor; }
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()); }/*from www . 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.JavaProjectConversionParticipant.java
License:Open Source License
private void configureBuildSourceDirectories(Model model, IJavaProject javaProject) throws CoreException { IClasspathEntry[] entries = javaProject.getRawClasspath(); Set<String> sources = new LinkedHashSet<String>(); Set<String> potentialTestSources = new LinkedHashSet<String>(); Set<String> potentialResourceDirectories = new LinkedHashSet<String>(); Set<String> potentialTestResourceDirectories = new LinkedHashSet<String>(); IPath projectPath = javaProject.getPath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entries[i].getPath().makeRelativeTo(projectPath); if (path.isAbsolute()) { //We only support paths relative to the project root, so we skip this one continue; }// w ww .j a v a 2s .co m String portablePath = path.toPortableString(); boolean isPotentialTestSource = isPotentialTestSource(path); boolean isResource = false; if (isPotentialTestSource) { if (DEFAULT_TEST_RESOURCES.equals(portablePath)) { isResource = potentialTestResourceDirectories.add(portablePath); } else { potentialTestSources.add(portablePath); } } else { if (DEFAULT_RESOURCES.equals(portablePath)) { isResource = potentialResourceDirectories.add(portablePath); } else { sources.add(portablePath); } } if (!isResource) { //For source folders not already flagged as resource folder, check if // they contain non-java sources, so we can add them as resources too boolean hasNonJavaResources = false; IFolder folder = javaProject.getProject().getFolder(path); if (folder.isAccessible()) { NonJavaResourceVisitor nonJavaResourceVisitor = new NonJavaResourceVisitor(); try { folder.accept(nonJavaResourceVisitor); } catch (NonJavaResourceFoundException ex) { //Expected hasNonJavaResources = true; } catch (CoreException ex) { //385666 ResourceException is thrown in Helios if (ex.getCause() instanceof NonJavaResourceFoundException) { hasNonJavaResources = true; } else { log.error("An error occured while analysing {} : {}", folder, ex.getMessage()); } } } if (hasNonJavaResources) { if (isPotentialTestSource) { potentialTestResourceDirectories.add(portablePath); } else { potentialResourceDirectories.add(portablePath); } } } } } Build build = getOrCreateBuild(model); if (!sources.isEmpty()) { if (sources.size() > 1) { //We don't know how to handle multiple sources, i.e. how to map to a resource or test source directory //That should be dealt by setting the build-helper-plugin config (http://mojo.codehaus.org/build-helper-maven-plugin/usage.html) log.warn("{} has multiple source entries, this is not supported yet", model.getArtifactId()); //$NON-NLS-1$ } String sourceDirectory = sources.iterator().next(); if (!DEFAULT_JAVA_SOURCE.equals(sourceDirectory)) { build.setSourceDirectory(sourceDirectory); } for (String resourceDirectory : potentialResourceDirectories) { if (!DEFAULT_RESOURCES.equals(resourceDirectory) || potentialResourceDirectories.size() > 1) { build.addResource(createResource(resourceDirectory)); } } } if (!potentialTestSources.isEmpty()) { if (potentialTestSources.size() > 1) { log.warn("{} has multiple test source entries, this is not supported yet", model.getArtifactId()); //$NON-NLS-1$ } String testSourceDirectory = potentialTestSources.iterator().next(); if (!DEFAULT_JAVA_TEST_SOURCE.equals(testSourceDirectory)) { build.setTestSourceDirectory(testSourceDirectory); } for (String resourceDirectory : potentialTestResourceDirectories) { if (!DEFAULT_TEST_RESOURCES.equals(resourceDirectory) || potentialTestResourceDirectories.size() > 1) { build.addTestResource(createResource(resourceDirectory)); } } } //Ensure we don't attach a new empty build definition to the model if (build.getSourceDirectory() != null || build.getTestSourceDirectory() != null || !build.getResources().isEmpty() || !build.getTestResources().isEmpty()) { model.setBuild(build); } }
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;/* w w w . ja va 2s .c om*/ } 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.tests.ProjectConfigurationManagerTest.java
License:Open Source License
public void test447460MultipleUpdateConfiguration() throws Exception { // the project import already performs a configuration !!! IProject project = importProject("projects/447460_MultipleUpdateConfiguration/pom.xml"); IJavaProject javaProject = JavaCore.create(project); // check whether everything has been imported correctly List<IClasspathEntry> cpEntries = filterClasspath(javaProject.getRawClasspath(), IClasspathEntry.CPE_SOURCE); assertNotNull(cpEntries);/*w w w . ja v a 2 s . c o m*/ assertEquals("Invalid number of classpath entries", 4, cpEntries.size()); for (IClasspathEntry cpEntry : cpEntries) { String[] path = cpEntry.getPath().segments(); if ("java".equals(path[path.length - 1])) { // sources IPath[] exclusions = cpEntry.getExclusionPatterns(); assertNotNull(exclusions); assertEquals("Classpath source entry isn't supposed to contain any exclusion pattern.", 0, exclusions.length); } else { // resources IPath[] exclusions = cpEntry.getExclusionPatterns(); assertNotNull(exclusions); assertEquals("Classpath resource entry contains more or less than one exclusion pattern.", 1, exclusions.length); assertEquals("Exclusion pattern is supposed to be '**' !", new Path("**"), exclusions[0]); } } }
From source file:org.eclipse.m2e.wtp.AbstractProjectConfiguratorDelegate.java
License:Open Source License
/** * Checks the maven source folders are correctly added to the project classpath *///w ww .j av a2s. co m private boolean checkJavaConfiguration(IProject project, IPath[] sourceRoots, IPath[] resourceRoots) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return false; } IClasspathEntry[] cpEntries = javaProject.getRawClasspath(); if (cpEntries == null) { return false; } Set<IPath> currentPaths = new HashSet<IPath>(); for (IClasspathEntry entry : cpEntries) { if (IClasspathEntry.CPE_SOURCE == entry.getEntryKind()) { currentPaths.add(entry.getPath().makeRelativeTo(project.getFullPath())); } } for (IPath mavenSource : sourceRoots) { if (mavenSource != null && !mavenSource.isEmpty()) { IFolder sourceFolder = project.getFolder(mavenSource); if (sourceFolder.exists() && !currentPaths.contains(mavenSource)) { return false; } } } for (IPath mavenSource : resourceRoots) { if (mavenSource != null && !mavenSource.isEmpty()) { IFolder resourceFolder = project.getFolder(mavenSource); if (resourceFolder.exists() && !currentPaths.contains(mavenSource)) { return false; } } } return true; }
From source file:org.eclipse.m2e.wtp.internal.conversion.AppClientProjectConverter.java
License:Open Source License
private String getMainClass(IProject project) { //Get Main attribute from existing MANIFEST.MF IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return null; }//from w w w. j a v a 2 s . c o m IFile manifest = null; IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IClasspathEntry[] classpath; try { classpath = javaProject.getRawClasspath(); for (IClasspathEntry cpe : classpath) { if (IClasspathEntry.CPE_SOURCE == cpe.getEntryKind()) { IFile sourceManifest = root.getFile(cpe.getPath().append("META-INF/MANIFEST.MF")); if (sourceManifest.exists()) { manifest = sourceManifest; break; } } } } catch (JavaModelException ex) { // TODO proper logging ex.printStackTrace(); } if (manifest == null) { return null; } InputStream is = null; try { is = manifest.getContents(); Manifest mf = new Manifest(is); Attributes mainAttributes = mf.getMainAttributes(); return mainAttributes.getValue(MAIN_CLASS); } catch (Exception ex) { ex.printStackTrace();//TODO proper logging } finally { IOUtil.close(is); } return null; }