List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY
int CPE_LIBRARY
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.
Click Source Link
From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyClasspathContainerSerializer.java
License:Apache License
private IClasspathEntry readCpEntry(Node cpEntryNode) throws IOException { NamedNodeMap attributes = cpEntryNode.getAttributes(); int kind = Integer.parseInt(getMandatoryAttribute(attributes, KIND, CPENTRY)); IPath path = new Path(getMandatoryAttribute(attributes, PATH, CPENTRY)); String source = getAttribute(attributes, SOURCE); IPath sourcePath = null;// www. j av a 2s . com if (source != null) { sourcePath = new Path(source); } IClasspathAttribute[] cpAttrs = null; IAccessRule[] accessRules = null; NodeList children = cpEntryNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node item = children.item(i); if (item.getNodeName().equals(CPATTRS)) { cpAttrs = readCpAttr(item); } else if (item.getNodeName().equals(ACCESS_RULES)) { accessRules = readAccessRules(item); } } IClasspathEntry entry; switch (kind) { case IClasspathEntry.CPE_PROJECT: entry = JavaCore.newProjectEntry(path, accessRules, true, cpAttrs, true); break; case IClasspathEntry.CPE_LIBRARY: IPath sources = ivyAttachementManager.getSourceAttachment(path, sourcePath); IPath sourcesRoot = ivyAttachementManager.getSourceAttachmentRoot(path, sourcePath); entry = JavaCore.newLibraryEntry(path, sources, sourcesRoot, accessRules, cpAttrs, false); break; default: return null; } return entry; }
From source file:org.apache.ivyde.internal.eclipse.IvyDERuntimeClasspathEntryResolver.java
License:Apache License
private static IRuntimeClasspathEntry[] computeDefaultContainerEntries(IvyClasspathContainerImpl ivycp, IRuntimeClasspathEntry entry) throws CoreException { IClasspathEntry[] cpes;//from ww w . ja v a2 s . co m if (ivycp.getClasspathEntries() == null || ivycp.getConf().getInheritedAdvancedSetup().isResolveBeforeLaunch()) { ClasspathEntriesResolver resolver = new ClasspathEntriesResolver(ivycp, false); ResolveRequest request = new ResolveRequest(resolver, ivycp.getState()); request.setForceFailOnError(true); request.setInWorkspace(ivycp.getConf().getInheritedClasspathSetup().isResolveInWorkspace()); request.setTransitive(ivycp.getConf().getInheritedClasspathSetup().isTransitiveResolve()); IvyResolveJob resolveJob = IvyPlugin.getDefault().getIvyResolveJob(); IStatus status = resolveJob.launchRequest(request, new NullProgressMonitor()); if (status.getCode() != IStatus.OK) { throw new CoreException(status); } cpes = resolver.getClasspathEntries(); } else { cpes = ivycp.getClasspathEntries(); } List resolved = new ArrayList(cpes.length); List projects = new ArrayList(); for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = cpes[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(cpe.getPath().segment(0)); IJavaProject jp = JavaCore.create(p); if (!projects.contains(jp)) { projects.add(jp); IRuntimeClasspathEntry classpath = JavaRuntime.newProjectRuntimeClasspathEntry(jp); resolved.add(classpath); IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspathEntry(classpath, jp); for (int j = 0; j < entries.length; j++) { IRuntimeClasspathEntry e = entries[j]; if (!resolved.contains(e)) { resolved.add(entries[j]); } } } } else if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IRuntimeClasspathEntry e = JavaRuntime.newArchiveRuntimeClasspathEntry(cpe.getPath()); if (!resolved.contains(e)) { resolved.add(e); } } } // set classpath property IRuntimeClasspathEntry[] result = new IRuntimeClasspathEntry[resolved.size()]; for (int i = 0; i < result.length; i++) { result[i] = (IRuntimeClasspathEntry) resolved.get(i); result[i].setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); } return result; }
From source file:org.bonitasoft.studio.common.repository.Repository.java
License:Open Source License
@Override public URLClassLoader createProjectClassloader() { final List<URL> jars = new ArrayList<URL>(); try {//from w ww.ja v a 2s . c om if (!classpathExists()) { initClasspath(getProject()); } //Synchronize with build jobs Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, NULL_PROGRESS_MONITOR); Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_BUILD, NULL_PROGRESS_MONITOR); IProject project = getProject(); String workspacePath = project.getLocation().toFile().getParent(); String outputPath = workspacePath + getJavaProject().getOutputLocation().toString(); jars.add(new File(outputPath).toURI().toURL()); for (IClasspathEntry entry : getJavaProject().getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { File jar = entry.getPath().toFile(); if (!jar.exists()) { // jar location relative to project jar = new File(workspacePath + File.separator + jar); } jars.add(jar.toURI().toURL()); } } } catch (Exception e) { BonitaStudioLog.error(e); } return new NonLockingJarFileClassLoader(getName() + "_URLClassLoader", jars.toArray(new URL[jars.size()]), BusinessArchive.class.getClassLoader()); }
From source file:org.bonitasoft.studio.repository.test.TestExtensionProject.java
License:Open Source License
public void testExtensionProjectClasspathDoesNotContainAbsoluteFile() throws JavaModelException { for (IClasspathEntry entry : RepositoryManager.getInstance().getCurrentRepository().getJavaProject() .getRawClasspath()) {//from w ww .j a va2 s . c o m if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { File file = new File(entry.getPath().toString()); if (file.exists() && file.isAbsolute() && !Platform.inDevelopmentMode()) { fail("Classpath should not contain absolute entry: " + entry.getPath().toString()); } } } }
From source file:org.caesarj.ui.util.ProjectProperties.java
License:Open Source License
/** * Initializes the ProjectProperties object. * //from w ww.j a va2 s . com * @param project * @throws JavaModelException * @throws CoreException */ public void refresh() throws JavaModelException, CoreException { classPath = new StringBuffer(); inPath = new StringBuffer(); sourceFiles = new ArrayList(); javaProject = JavaCore.create(project); String projectLocalPrefix = File.separator + project.getName(); /* * get paths */ this.projectLocation = project.getLocation().removeLastSegments(1).toOSString(); this.outputPath = javaProject.getOutputLocation().toOSString(); this.sourcePaths = new ArrayList<String>(); /* * get source files */ IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(false); for (int i = 0; i < classPathEntries.length; i++) { if (classPathEntries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { // 1st segment of the path has to be removed because it is added // again by findMember ending in duplicated first segment in the path getAllSourceFiles(project.findMember(classPathEntries[i].getPath().removeFirstSegments(1)), this.sourceFiles); if (!this.sourcePaths.contains(classPathEntries[i].getPath().toOSString())) { this.sourcePaths.add(classPathEntries[i].getPath().toOSString()); } } else if (classPathEntries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (this.classPath.length() > 0) { this.classPath.append(File.pathSeparator); } String cp = classPathEntries[i].getPath().toOSString(); if (cp.startsWith(projectLocalPrefix)) { cp = this.projectLocation + classPathEntries[i].getPath().toOSString(); } // add the lib to inPath if specified in the .classpath file // as an inpath resource for (IClasspathAttribute attr : classPathEntries[i].getExtraAttributes()) { if (attr.getName().equals("inpath") && attr.getValue().equals("true")) { if (this.inPath.length() > 0) { this.inPath.append(File.pathSeparator); } this.inPath.append(cp); break; } } this.classPath.append(cp); } } // IFile inpathFile = project.getFile("inpath.properties"); // if(inpathFile != null) { // Properties inpathProp = new Properties(); // try { // inpathProp.load(inpathFile.getContents()); // for(Object prop : inpathProp.keySet()) { // if(inPath.length() > 0) { // inPath.append(File.pathSeparator); // } // inPath.append(this.projectLocation).append(projectLocalPrefix).append(File.separator).append(inpathProp.get(prop)); // } // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } }
From source file:org.checkthread.plugin.eclipse.CheckThreadRunner.java
License:Open Source License
private static void loadDirFromProject(HashMap<IProject, Boolean> projectSearchMap, boolean isrecursed, IProject project, ArrayList<IPath> srcDirList, ArrayList<URI> targetFileList, ArrayList<URI> classPathList) { // if we already searched this project if (projectSearchMap.get(project) != null) { return;/*from ww w .j av a 2 s. c o m*/ // we haven't searched this project yet } else { // add to cache projectSearchMap.put(project, true); } // recursive traverse referenced projects // stopping condition: project already searched try { IProject[] projectList = project.getReferencedProjects(); for (IProject p : projectList) { loadDirFromProject(projectSearchMap, true, p, srcDirList, targetFileList, classPathList); } } catch (Exception e) { e.printStackTrace(); } IJavaProject javaProject = JavaCore.create(project); IPath defaultOutputLocationRelative = null; try { defaultOutputLocationRelative = javaProject.getOutputLocation(); } catch (Exception e) { e.printStackTrace(); return; } sLogger.info("DEFAULT OUTPUT LOCATION RELATIVE: " + defaultOutputLocationRelative); IPath projectLocationAbsolute = project.getLocation(); sLogger.info("PROJECT LOCATION: " + projectLocationAbsolute); // Make path absolute IPath defaultOutputLocationAbsolute = projectLocationAbsolute .append(defaultOutputLocationRelative.removeFirstSegments(1)); sLogger.info("DEFAULT OUTPUT LOCATION ABSOLUTE: " + defaultOutputLocationAbsolute); // Work around, stomp over target java files. Instead, just give the // root directory sLogger.info("WORKAROUND: IGNORE CHANGED CLASS FILES< RECHECK EVERYTHING"); if (!isrecursed) { URI uri = defaultOutputLocationAbsolute.toFile().toURI(); if (uri != null) { targetFileList.add(uri); } } // Add to input URI cURI = defaultOutputLocationAbsolute.toFile().toURI(); if (cURI != null) { classPathList.add(cURI); } // Loop through classpath entries and get src directory list IClasspathEntry[] rawClassPathList = null; try { rawClassPathList = javaProject.getRawClasspath(); } catch (JavaModelException e) { e.printStackTrace(); } if (rawClassPathList != null) { for (IClasspathEntry classPathEntry : rawClassPathList) { switch (classPathEntry.getEntryKind()) { // Source Directory case IClasspathEntry.CPE_SOURCE: { if (!isrecursed) { IPath p = classPathEntry.getPath().removeFirstSegments(1); if (p != null) { srcDirList.add(p); sLogger.info("CPE_SOURCE: " + p); } } break; } // external libraries used case IClasspathEntry.CPE_LIBRARY: { File file = classPathEntry.getPath().toFile(); IPath p; // The entry may be a relative path to the project root // or it could be an absolute path to a library. if (file.isFile() || file.isDirectory()) { p = classPathEntry.getPath(); } else { p = projectLocationAbsolute.append(classPathEntry.getPath().removeFirstSegments(1)); } URI uri = p.toFile().toURI(); if (uri != null) { classPathList.add(uri); } sLogger.info("CPE_LIBRARY: " + uri); break; } // ignore case IClasspathEntry.CPE_CONTAINER: sLogger.info("CPE_CONTAINER: " + classPathEntry); break; //ignore case IClasspathEntry.CPE_PROJECT: sLogger.info("CPE_PROJECT: " + classPathEntry); break; } } } }
From source file:org.cloudfoundry.ide.eclipse.internal.server.core.CloudUtil.java
License:Open Source License
public static String getFramework(IProject project) { if (project != null) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); if (javaProject != null) { if (CloudFoundryProjectUtil.hasNature(project, DeploymentConstants.GRAILS_NATURE)) { return CloudApplication.GRAILS; }/* w w w . j a v a2 s. co m*/ // in case user has Grails projects without the nature // attached if (project.isAccessible() && project.getFolder("grails-app").exists() && project.getFile("application.properties").exists()) { return CloudApplication.GRAILS; } IClasspathEntry[] entries; boolean foundSpringLibrary = false; try { entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (isLiftLibrary(entry)) { return DeploymentConstants.LIFT; } if (isSpringLibrary(entry)) { foundSpringLibrary = true; } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { for (IClasspathEntry childEntry : container.getClasspathEntries()) { if (isLiftLibrary(childEntry)) { return DeploymentConstants.LIFT; } if (isSpringLibrary(childEntry)) { foundSpringLibrary = true; } } } } } } catch (JavaModelException e) { CloudFoundryPlugin.logError(new Status(IStatus.WARNING, CloudFoundryPlugin.PLUGIN_ID, "Unexpected error during auto detection of application type", e)); } if (CloudFoundryProjectUtil.isSpringProject(project)) { return CloudApplication.SPRING; } if (foundSpringLibrary) { return CloudApplication.SPRING; } } } return null; }
From source file:org.cloudfoundry.ide.eclipse.internal.server.ui.wizards.CloudFoundryApplicationWizardPage.java
License:Open Source License
private static String getFramework(ApplicationModule module) { if (module != null && module.getLocalModule() != null) { IProject project = module.getLocalModule().getProject(); if (project != null) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); if (javaProject != null) { if (CloudFoundryProjectUtil.hasNature(project, GRAILS_NATURE)) { return CloudApplication.GRAILS; }//from ww w.j a v a 2 s . c om // in case user has Grails projects without the nature // attached if (project.isAccessible() && project.getFolder("grails-app").exists() && project.getFile("application.properties").exists()) { return CloudApplication.GRAILS; } IClasspathEntry[] entries; boolean foundSpringLibrary = false; try { entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (isLiftLibrary(entry)) { return LIFT; } if (isSpringLibrary(entry)) { foundSpringLibrary = true; } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { for (IClasspathEntry childEntry : container.getClasspathEntries()) { if (isLiftLibrary(childEntry)) { return LIFT; } if (isSpringLibrary(childEntry)) { foundSpringLibrary = true; } } } } } } catch (JavaModelException e) { CloudFoundryServerUiPlugin.getDefault().getLog() .log(new Status(IStatus.WARNING, CloudFoundryServerUiPlugin.PLUGIN_ID, "Unexpected error during auto detection of application type", e)); } if (CloudFoundryProjectUtil.isSpringProject(project)) { return CloudApplication.SPRING; } if (foundSpringLibrary) { return CloudApplication.SPRING; } } } } return CloudApplication.JAVA_WEB; }
From source file:org.cloudfoundry.ide.eclipse.server.core.internal.application.JavaWebApplicationDelegate.java
License:Open Source License
/** * Attempts to determine the framework based on the contents and nature of * the project. Returns null if no framework was determined. * @param project/*from w w w . j a va2 s. c om*/ * @return Framework type or null if framework was not determined. * @deprecated kept for reference as to how application type was being * determined from a Java project for legacy v1 CF servers. v2 Servers no * longer require a framework for an application, as frameworks have been * replaced with buildpacks. */ protected String getFramework(IProject project) { if (project != null) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); if (javaProject != null) { if (CloudFoundryProjectUtil.hasNature(project, CloudFoundryConstants.GRAILS_NATURE)) { return CloudFoundryConstants.GRAILS; } // in case user has Grails projects without the nature // attached if (project.isAccessible() && project.getFolder("grails-app").exists() //$NON-NLS-1$ && project.getFile("application.properties").exists()) { //$NON-NLS-1$ return CloudFoundryConstants.GRAILS; } IClasspathEntry[] entries; boolean foundSpringLibrary = false; try { entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (isLiftLibrary(entry)) { return CloudFoundryConstants.LIFT; } if (isSpringLibrary(entry)) { foundSpringLibrary = true; } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { for (IClasspathEntry childEntry : container.getClasspathEntries()) { if (isLiftLibrary(childEntry)) { return CloudFoundryConstants.LIFT; } if (isSpringLibrary(childEntry)) { foundSpringLibrary = true; } } } } } } catch (JavaModelException e) { // Log the error but don't throw it again as there may be // other ways to detect the framework CloudFoundryPlugin.log(new Status(IStatus.WARNING, CloudFoundryPlugin.PLUGIN_ID, "Unexpected error during auto detection of application type", e)); //$NON-NLS-1$ } if (CloudFoundryProjectUtil.isSpringProject(project)) { return CloudFoundryConstants.SPRING; } if (foundSpringLibrary) { return CloudFoundryConstants.SPRING; } } } return null; }
From source file:org.cloudfoundry.ide.eclipse.server.core.internal.CloudFoundryProjectUtil.java
License:Open Source License
private static boolean hasBootDependencies(IClasspathEntry e) { if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = e.getPath();/*from w w w . j a v a2 s . c om*/ String name = path.lastSegment(); return name.endsWith(".jar") && name.startsWith("spring-boot"); //$NON-NLS-1$ //$NON-NLS-2$ } return false; }