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.che.plugin.maven.server.classpath.OutputPathTest.java
License:Open Source License
@Test public void testTestSourceClasspathEntryShouldHaveOutputLocationPath() throws Exception { String pom = "<groupId>test</groupId>" + "<artifactId>testOutputLocation</artifactId>" + "<version>42</version>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.12</version>" + " </dependency>" + "</dependencies>"; createTestProject("test", pom); IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test"); mavenWorkspace.update(Collections.singletonList(test)); mavenWorkspace.waitForUpdate();//from w w w. j av a 2 s. co m JavaProject javaProject = (JavaProject) JavaCore.create(test); IClasspathEntry[] classpath = javaProject.getResolvedClasspath(); IClasspathEntry srcMainJava = null; for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().toOSString().endsWith("src/test/java")) { srcMainJava = entry; break; } } assertThat(srcMainJava).isNotNull(); assertThat(srcMainJava.getOutputLocation()).isNotNull(); assertThat(srcMainJava.getOutputLocation().toOSString()).endsWith("target/test-classes"); }
From source file:org.eclipse.che.plugin.maven.server.classpath.OutputPathTest.java
License:Open Source License
@Test public void testTestSourceClasspathEntryShouldHaveCustomOutputLocationPath() throws Exception { String pom = "<groupId>test</groupId>" + "<artifactId>testOutputLocation</artifactId>" + "<version>42</version>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.12</version>" + " </dependency>" + "</dependencies>" + "<build>" + " <testOutputDirectory>test/test-classes</testOutputDirectory>" + "</build>"; createTestProject("test", pom); IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test"); mavenWorkspace.update(Collections.singletonList(test)); mavenWorkspace.waitForUpdate();// w ww. j a v a 2s . co m JavaProject javaProject = (JavaProject) JavaCore.create(test); IClasspathEntry[] classpath = javaProject.getResolvedClasspath(); IClasspathEntry srcMainJava = null; for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().toOSString().endsWith("src/test/java")) { srcMainJava = entry; break; } } assertThat(srcMainJava).isNotNull(); assertThat(srcMainJava.getOutputLocation()).isNotNull(); assertThat(srcMainJava.getOutputLocation().toOSString()).endsWith("test/test-classes"); }
From source file:org.eclipse.che.plugin.maven.server.core.classpath.ClasspathEntryHelper.java
License:Open Source License
public IClasspathEntry toClasspathEntry() { Map<String, String> attributes = new HashMap<String, String>(this.attributes); if (artifactKey != null) { attributes.put(ClasspathManager.GROUP_ID_ATTRIBUTE, artifactKey.getGroupId()); attributes.put(ClasspathManager.ARTIFACT_ID_ATTRIBUTE, artifactKey.getArtifactId()); attributes.put(ClasspathManager.VERSION_ATTRIBUTE, artifactKey.getVersion()); attributes.put(ClasspathManager.PACKAGING_ATTRIBUTE, artifactKey.getPackaging()); if (artifactKey.getClassifier() != null) { attributes.put(ClasspathManager.CLASSIFIER_ATTRIBUTE, artifactKey.getClassifier()); }// www.j a v a2s . c om } 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 (kind) { case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(path, // accessRulesArray, // attributesArray, // exported); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(path, // sourcePath, // sourceRootPath, // 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; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.newVariableEntry(path, // sourcePath, // sourceRootPath, // accessRulesArray, // attributesArray, // exported); break; default: throw new IllegalArgumentException("Unsupported IClasspathEntry kind=" + kind); //$NON-NLS-1$ } return entry; }
From source file:org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper.java
License:Open Source License
public ClasspathEntryHelper addSourceEntry(IPath path) { ClasspathEntryHelper helper = new ClasspathEntryHelper(path, IClasspathEntry.CPE_SOURCE); ClasspathEntryHelper oldHelper = defaultEntries.get(path); if (oldHelper != null) { oldHelper.getClasspathAttribute().forEach(helper::setClasspathAttribute); }//from ww w . j av a2s. com addEntryHelper(helper); return helper; }
From source file:org.eclipse.che.plugin.testing.classpath.maven.server.MavenTestClasspathProviderTest.java
License:Open Source License
private ClasspathEntry source(String fullPath) { ClasspathEntry cp = new ClasspathEntry(); cp.external = false;/* w w w. j av a 2 s . com*/ cp.fullPath = fullPath; cp.fileSystemPath = null; cp.kind = IClasspathEntry.CPE_SOURCE; cp.resolvedEntries = Collections.emptyList(); return cp; }
From source file:org.eclipse.dltk.freemarker.core.util.ClassUtils.java
License:Open Source License
/** * Add URL form the JavaProject./*w ww. j a va2 s .c o m*/ * * @param javaProject * @param urls * @param root * @param rootLocation * @param javaProjectsAlreadyDone * @throws JavaModelException * @throws CoreException */ private static void addPath(IJavaProject javaProject, List<URL> urls, IWorkspaceRoot root, IPath rootLocation, List<IJavaProject> javaProjectsAlreadyDone) throws JavaModelException, CoreException { if (javaProjectsAlreadyDone.contains(javaProject)) return; javaProjectsAlreadyDone.add(javaProject); String projectName = javaProject.getElementName(); IClasspathEntry javacp[] = javaProject.getResolvedClasspath(true); // Add bin folder IPath outputLocation = javaProject.getOutputLocation(); addPath(urls, rootLocation.append(outputLocation)); // Loop for .classpath IClasspathEntry entry = null; IPath entryPath = null; for (int i = 0; i < javacp.length; i++) { // load bin folder of referenced projects into classpath entry = javacp[i]; entryPath = entry.getPath(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: // add jars if (projectName.equals(entryPath.segment(0))) { // Jar belongs to the Java Project, add base dir addPath(urls, rootLocation.append(entryPath)); } else { // External Jar (ex : C:/Program Files/xxx.jar) addPath(urls, entryPath); } break; case IClasspathEntry.CPE_SOURCE: // add the source folders of the project addPath(urls, rootLocation.append(entryPath)); break; case IClasspathEntry.CPE_PROJECT: // add bin folder from referenced project IProject referencedProject = root.getProject(entryPath.segment(0)); if (referencedProject != null && referencedProject.exists() && referencedProject.hasNature(JavaCore.NATURE_ID)) { IJavaProject referencedJavaProject = JavaCore.create(referencedProject); addPath(referencedJavaProject, urls, root, rootLocation, javaProjectsAlreadyDone); } break; default: addPath(urls, entryPath); break; } } }
From source file:org.eclipse.e4.tools.ui.designer.session.JavaHelper.java
License:Open Source License
/** * Get output folders.<br>//from w w w .j a v a2 s. co m * * @param project * @return a List of IFolders */ public static List<IFolder> getOutputFolders(IJavaProject project) throws CoreException { List<IFolder> folders = new UniqueEList<IFolder>(); if (project == null || project.exists() == false) { return folders; } // Default Output Location IFolder folder = findFolder(project.getOutputLocation()); if (folder != null) { folders.add(folder); } // Lookup in source folders for (IClasspathEntry entry : project.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IFolder innerFolder = findFolder(entry.getOutputLocation()); if (innerFolder != null) { folders.add(innerFolder); } } } return folders; }
From source file:org.eclipse.e4.tools.ui.designer.session.JavaHelper.java
License:Open Source License
/** * Get source folders.<br>//from w w w. j a v a 2s . co m * * @param project * @return a List of IFolders */ public static List<IFolder> getSourceFolders(IJavaProject project) throws CoreException { List<IFolder> folders = new UniqueEList<IFolder>(); if (project == null || project.exists() == false) { return folders; } // Lookup in source folders for (IClasspathEntry entry : project.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IFolder innerFolder = findFolder(entry.getPath()); if (innerFolder != null) { folders.add(innerFolder); } } } return folders; }
From source file:org.eclipse.e4.xwt.tools.ui.designer.jdt.ProjectHelper.java
License:Open Source License
protected static boolean containsJar(IJavaProject javaProject, IClasspathEntry entry, String jarName) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: IClasspathEntry resolvedEntry = JavaCore.getJavaCore().getResolvedClasspathEntry(entry); IPath resolvedPath = resolvedEntry.getPath(); String string = resolvedPath.toString(); if (string.indexOf(jarName) != -1) { return true; }/*from ww w. j a va2 s. c o m*/ break; case IClasspathEntry.CPE_CONTAINER: try { IPath path = entry.getPath(); IClasspathContainer classpathContainer = JavaCore.getJavaCore().getClasspathContainer(path, javaProject); if (classpathContainer != null) { classpathContainer.getClasspathEntries(); IClasspathEntry[] oldclasspath = classpathContainer.getClasspathEntries(); for (int i = 0; i < oldclasspath.length; i++) { if (containsJar(javaProject, oldclasspath[i], jarName)) { return true; } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_LIBRARY: IPath path = entry.getPath(); String value = path.toString(); if (value.indexOf(jarName) != -1) { return true; } } return false; }
From source file:org.eclipse.e4.xwt.ui.utils.LibraryBuilder.java
License:Open Source License
private void configureSourceBuildEntry(IBuildModel bmodel, String oldPath, String newPath) throws CoreException { IBuild build = bmodel.getBuild();/*from w ww.j a va2s. c o m*/ IBuildEntry entry = build .getEntry(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX + (oldPath != null ? oldPath : newPath)); try { if (newPath != null) { if (entry == null) { IJavaProject jproject = JavaCore.create(project); ArrayList tokens = new ArrayList(); IClasspathEntry[] entries = jproject.getRawClasspath(); for (int i = 0; i < entries.length; i++) if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) tokens.add( entries[i].getPath().removeFirstSegments(1).addTrailingSeparator().toString()); if (tokens.size() == 0) return; entry = bmodel.getFactory() .createEntry(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX + newPath); for (int i = 0; i < tokens.size(); i++) entry.addToken((String) tokens.get(i)); build.add(entry); } else entry.setName(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX + newPath); } else if (entry != null && newPath == null) build.remove(entry); } catch (JavaModelException e) { } }