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.openquark.cal.eclipse.embedded.EmbeddedClasspathVariableInitializer.java
License:Open Source License
/** * Attempt to update the project's build classpath with all of the Quark Binaries * library./*from w w w . j a v a2s .c o m*/ * * Borrowed from AspectJUIPlugin.addAjrtToBuildPath() * * TODO ADE A warning: this method will only work if you already have the Quark user * library set up. Setting it up requires the proper installation of Quark * (including car-jars). Quark is not currently installed this way by default, * but it should be at some point. * * I created this method to help with the creation of the videos. * * In order for this method to work, the QUARK_LIB user library needs to be created. It * needs to contain the following references: * * (External jars) * xmlParserAPIs.jar * asm-all-3.0.jar * commons-collections-3.1.jar * xercesImpl.jar * antlr.jar * icu4j.jar * log4j.jar * * (plugins) * org.openquark.util plugin * org.openquark.cal.platform pluign * com.businessobjects.lang.cal.libraries plugin * * (Car-jars) * cal.libraries.test.car.jar * cal.platform.car.jar * cal.platform.test.car.jar * cal.libraries.car.jar * * * @param project */ public static void addQuarkLibraryToBuildPath(IProject project) { IJavaProject javaProject = JavaCore.create(project); try { IClasspathEntry[] originalCP = javaProject.getRawClasspath(); // check to see if classpath entry already exists for (final IClasspathEntry classpathEntry : originalCP) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (classpathEntry.getPath().toString().equals(QUARK_LIB)) { // found return; } } } IClasspathEntry quarkLIB = JavaCore.newContainerEntry(new Path(QUARK_LIB)); // Update the raw classpath with the new embeddedrtCP entry. int originalCPLength = originalCP.length; IClasspathEntry[] newCP = new IClasspathEntry[originalCPLength + 1]; System.arraycopy(originalCP, 0, newCP, 0, originalCPLength); newCP[originalCPLength] = quarkLIB; javaProject.setRawClasspath(newCP, new NullProgressMonitor()); } catch (JavaModelException e) { } }
From source file:org.org.eclipse.dws.core.internal.jobs.UpdateJavadocAndSourcesJob.java
License:Open Source License
/** * Update sources.//from w ww . j av a2s .c o m * * @param project * the project * @param packageFragmentRoot * the package fragment root * @param file * the file * @param monitor * the monitor */ @SuppressWarnings("restriction") private void updateSources(IJavaProject project, IPackageFragmentRoot packageFragmentRoot, File file, IProgressMonitor monitor) { try { logger.info("updating source attachment of " + packageFragmentRoot.getElementName() + " with " + file); IClasspathEntry rawClasspathEntry = packageFragmentRoot.getRawClasspathEntry(); IPath containerPath = null; if (rawClasspathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { containerPath = rawClasspathEntry.getPath(); rawClasspathEntry = handleContainerEntry(containerPath, project, packageFragmentRoot.getPath()); } CPListElement cpElem = CPListElement.createFromExisting(rawClasspathEntry, project); String loc = file.getAbsolutePath(); cpElem.setAttribute(CPListElement.SOURCEATTACHMENT, Path.fromOSString(loc).makeAbsolute()); IClasspathEntry newEntry = cpElem.getClasspathEntry(); String[] changedAttributes = { CPListElement.SOURCEATTACHMENT }; BuildPathSupport.modifyClasspathEntry(null, newEntry, changedAttributes, project, containerPath, true, monitor); } catch (JavaModelException e) { throw new MavenRepositoryInteractionException( "Impossible to attach source jar:" + file.getAbsolutePath(), e); } catch (CoreException e) { throw new MavenRepositoryInteractionException( "Impossible to attach source jar:" + file.getAbsolutePath(), e); } }
From source file:org.org.eclipse.dws.core.internal.jobs.UpdateJavadocAndSourcesJob.java
License:Open Source License
/** * Update javadoc.//ww w . j a va 2 s . c o m * * @param project * the project * @param packageFragmentRoot * the package fragment root * @param file * the file * @param monitor * the monitor * * @throws CoreException * the core exception */ @SuppressWarnings("restriction") private void updateJavadoc(IJavaProject project, IPackageFragmentRoot packageFragmentRoot, File file, IProgressMonitor monitor) throws CoreException { try { logger.info("updating javadoc location of " + packageFragmentRoot.getElementName() + " with " + file); IClasspathEntry rawClasspathEntry = packageFragmentRoot.getRawClasspathEntry(); IPath containerPath = null; if (rawClasspathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { containerPath = rawClasspathEntry.getPath(); rawClasspathEntry = handleContainerEntry(containerPath, project, packageFragmentRoot.getPath()); } CPListElement cpElem = CPListElement.createFromExisting(rawClasspathEntry, project); String loc = "jar:file:/" + file.getAbsolutePath() + "!/"; cpElem.setAttribute(CPListElement.JAVADOC, loc); IClasspathEntry newEntry = cpElem.getClasspathEntry(); String[] changedAttributes = { CPListElement.JAVADOC }; BuildPathSupport.modifyClasspathEntry(null, newEntry, changedAttributes, project, containerPath, true, monitor); } catch (JavaModelException e) { throw new MavenRepositoryInteractionException( "Impossible to set javadoc location:" + file.getAbsolutePath(), e); } catch (CoreException e) { throw new MavenRepositoryInteractionException( "Impossible to set javadoc location:" + file.getAbsolutePath(), e); } }
From source file:org.org.eclipse.dws.ui.internal.wizards.pages.LookupJavadocAndSourcesForLibrariesInClasspathPage.java
License:Open Source License
/** * Misses javadoc./* ww w.j a va2 s . c om*/ * * @param packageFragmentRoot * the package fragment root * * @return true, if successful * * @throws JavaModelException * the java model exception */ private boolean missesJavadoc(IPackageFragmentRoot packageFragmentRoot) throws JavaModelException { int entryKind = packageFragmentRoot.getRawClasspathEntry().getEntryKind(); boolean missesJavadoc = false; if (entryKind == IClasspathEntry.CPE_LIBRARY || entryKind == IClasspathEntry.CPE_VARIABLE) { missesJavadoc = JavaUI.getLibraryJavadocLocation(packageFragmentRoot.getRawClasspathEntry()) == null; } if (entryKind == IClasspathEntry.CPE_CONTAINER) { missesJavadoc = JavaUI.getJavadocLocation(packageFragmentRoot.getPrimaryElement(), false) == null; } return missesJavadoc; }
From source file:org.python.pydev.editor.codecompletion.revisited.javaintegration.JavaProjectModulesManager.java
License:Open Source License
/** * This method passes through all the java packages and calls the filter callback passed * on each package found.//from w w w.j a v a 2 s. c o m * * If true is returned on the callback, the children of each package (classes) will also be visited, * otherwise, they'll be skipped. */ private void filterJavaPackages(IFilter filter) { IClasspathEntry[] rawClasspath; try { rawClasspath = this.javaProject.getRawClasspath(); FastStringBuffer buffer = new FastStringBuffer(); for (IClasspathEntry entry : rawClasspath) { int entryKind = entry.getEntryKind(); IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(entry); if (entryKind != IClasspathEntry.CPE_CONTAINER) { //ignore if it's in the system classpath... IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(resolvedClasspathEntry); //get the package roots for (IPackageFragmentRoot root : roots) { IJavaElement[] children = root.getChildren(); //get the actual packages for (IJavaElement child : children) { IPackageFragment childPackage = (IPackageFragment) child; String elementName = childPackage.getElementName(); //and if the java package is 'accepted' if (filter.accept(elementName, root, childPackage)) { buffer.clear(); buffer.append(elementName); int packageNameLen = buffer.length(); if (packageNameLen > 0) { buffer.append('.'); packageNameLen++; } //traverse its classes for (IJavaElement class_ : childPackage.getChildren()) { buffer.append(FullRepIterable.getFirstPart(class_.getElementName())); filter.accept(buffer.toString(), root, class_); buffer.setCount(packageNameLen); //leave only the package part for the next append } } } } } } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.python.pydev.editor.codecompletion.revisited.javaintegration.JavaProjectModulesManager.java
License:Open Source License
/** * @param dontSearchInit: not applicable for this method (ignored) * @return the module that corresponds to the passed name. *///from w w w . j av a 2 s . c om public IModule getModuleInDirectManager(String name, IPythonNature nature, boolean dontSearchInit) { if (DEBUG_GET_MODULE) { System.out.println("Trying to get module in java project modules manager: " + name); } if (name.startsWith(".")) { //this happens when looking for a relative import return null; } try { IJavaElement javaElement = this.javaProject.findType(name); if (javaElement == null) { javaElement = this.javaProject.findElement(new Path(name.replace('.', '/'))); } if (DEBUG_GET_MODULE) { System.out.println("Found: " + javaElement); } if (javaElement != null) { //now, there's a catch here, we'll find any class in the project classpath, even if it's in the //global classpath (e.g.: rt.jar), and this shouldn't be treated in this project modules manager //(that's treated in the Jython system manager) IJavaElement ancestor = javaElement.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (ancestor instanceof IPackageFragmentRoot) { IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) ancestor; IClasspathEntry rawClasspathEntry = packageFragmentRoot.getRawClasspathEntry(); if (rawClasspathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { return null; } } return new JavaModuleInProject(name, this.javaProject); } } catch (Exception e) { throw new RuntimeException(e); } return null; }
From source file:org.robovm.eclipse.internal.NewProjectWizard.java
License:Open Source License
@Override public boolean performFinish() { try {//from www . ja va 2 s .com page2.performFinish(new NullProgressMonitor()); IJavaProject javaProject = page2.getJavaProject(); IProject project = javaProject.getProject(); // TODO create selection screen for the template type String templateName = getTemplateName(); Templater templater = new Templater(RoboVMPlugin.getConsoleLogger(), templateName); File projectRoot = project.getLocation().toFile(); customizeTemplate(templater); templater.buildProject(projectRoot); page1.storePreferences(project); IClasspathEntry[] oldClasspath = javaProject.getRawClasspath(); List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>(); String rootSrc = javaProject.getPath().append("src").toString(); for (IClasspathEntry entry : oldClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().toString().equals("org.eclipse.jdt.launching.JRE_CONTAINER")) { newClasspath.add(JavaCore.newContainerEntry(new Path(RoboVMClasspathContainer.ID))); } else if (entry.getPath().toString().startsWith(rootSrc)) { // Cannot have nested classpath entries. newClasspath.add(JavaCore.newSourceEntry(javaProject.getPath().append("src/main/java"))); } else { newClasspath.add(entry); } } newClasspath = customizeClasspath(newClasspath); javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[newClasspath.size()]), new NullProgressMonitor()); RoboVMNature.configureNatures(project, new NullProgressMonitor()); project.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (Exception e) { RoboVMPlugin.log(e); return false; } OpenJavaPerspectiveAction action = new OpenJavaPerspectiveAction(); action.run(); return true; }
From source file:org.robovm.eclipse.RoboVMPlugin.java
License:Open Source License
public static boolean isRoboVMIOSProject(IProject project) throws CoreException { if (!isRoboVMProject(project)) { return false; }//from ww w . ja v a 2s .c o m IJavaProject javaProject = JavaCore.create(project); for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().toString().equals(RoboVMCocoaTouchClasspathContainer.ID)) { return true; } } return false; }
From source file:org.savara.tools.scenario.designer.simulate.ScenarioSimulationLauncher.java
License:Apache License
/** * This method derives the classpath required to run the * ScenarioTester utility./*from ww w .java2s .c o m*/ * * @param configuration The launch configuation * @return The list of classpath entries */ public String[] getClasspath(ILaunchConfiguration configuration) { String[] ret = null; java.util.Vector<String> classpathEntries = new java.util.Vector<String>(); // Add classpath entry for current Java project String projnames = null; try { projnames = configuration.getAttribute(ScenarioSimulationLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); String[] projname = projnames.split(","); java.util.List<String> outputPaths = new java.util.Vector<String>(); for (int n = 0; n < projname.length; n++) { try { if (logger.isLoggable(Level.FINE)) { logger.fine("Building classpath for project: " + projname[n]); } IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projname[n]); IJavaProject jproject = JavaCore.create(project); // Add output location IPath outputLocation = jproject.getOutputLocation(); IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputLocation); String path = folder.getLocation().toString(); outputPaths.add(path); // Add other libraries to the classpath IClasspathEntry[] curclspath = jproject.getRawClasspath(); for (int i = 0; curclspath != null && i < curclspath.length; i++) { if (curclspath[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(curclspath[i].getPath()); if (file.exists()) { // Library is within the workspace classpathEntries.add(file.getLocation().toString()); } else { // Assume library is external to workspace classpathEntries.add(curclspath[i].getPath().toString()); } } else if (curclspath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // Container's not currently handled - but // problem need to retrieve from project and // iterate over container entries } } } catch (Exception e) { // TODO: report error } } if (outputPaths.size() == 1) { classpathEntries.add(outputPaths.get(0)); } else if (outputPaths.size() > 0) { // Need to merge output folders into one location java.io.File dir = new java.io.File( System.getProperty("java.io.tmpdir") + java.io.File.separatorChar + "savara" + java.io.File.separatorChar + "simulation" + System.currentTimeMillis()); dir.deleteOnExit(); dir.mkdirs(); classpathEntries.add(dir.getAbsolutePath()); for (String path : outputPaths) { copy(new java.io.File(path), dir); } } } catch (Exception ex) { ex.printStackTrace(); } java.util.List<Bundle> bundles = getBundles(); for (Bundle b : bundles) { buildClassPath(b, classpathEntries); } ret = new String[classpathEntries.size()]; classpathEntries.copyInto(ret); if (logger.isLoggable(Level.FINEST)) { logger.finest("Scenario Simulation Classpath:"); for (int i = 0; i < ret.length; i++) { logger.finest(" [" + i + "] " + ret[i]); } } return (ret); }
From source file:org.scribble.lang.eclipse.JavaCodeGenerator.java
License:Apache License
/** * This method generates the Java code associated with the supplied * resource, containing a Scribble Language Model, into the containing * Java project.//from w w w.j a v a 2 s . co m * * @param res The resource */ public void generate(IResource res) { // Get Java project IJavaProject jproject = JavaCore.create(res.getProject()); if (jproject != null && res instanceof IFile) { // Get language model Journal j = new Journal() { public void error(String arg0, Map<String, Serializable> arg1) { report(arg0); } public void info(String arg0, Map<String, Serializable> arg1) { report(arg0); } public void warning(String arg0, Map<String, Serializable> arg1) { report(arg0); } protected void report(String mesg) { System.out.println(">> " + mesg); } }; //ANTLRLanguageParser parser=new ANTLRLanguageParser(); LanguageModel model = null; try { java.io.InputStream is = ((IFile) res).getContents(); model = m_parser.parse(is, j); is.close(); } catch (Exception e) { e.printStackTrace(); } if (model != null) { Generator generator = new Generator(); IFolder srcFolder = null; boolean f_containerRegistered = false; String serviceComponent = null; try { IClasspathEntry[] curclspath = jproject.getRawClasspath(); for (int i = 0; curclspath != null && i < curclspath.length; i++) { if (curclspath[i].getEntryKind() == IClasspathEntry.CPE_SOURCE && srcFolder == null) { srcFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(curclspath[i].getPath()); } else if (curclspath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER && curclspath[i].getPath().toString().equals(SLClasspathContainer.CONTAINER_PATH)) { f_containerRegistered = true; } } // Check if container needs to be added to classpath if (f_containerRegistered == false) { int len = jproject.getRawClasspath().length; IClasspathEntry[] entries = new IClasspathEntry[len + 2]; for (int i = 0; i < len; i++) { entries[i] = jproject.getRawClasspath()[i]; } entries[len] = JavaCore.newContainerEntry(new Path(SLClasspathContainer.CONTAINER_PATH)); entries[len + 1] = JavaCore.newContainerEntry(new Path(JUNIT4_PATH)); jproject.setRawClasspath(entries, new org.eclipse.core.runtime.NullProgressMonitor()); } } catch (Exception e) { e.printStackTrace(); } for (Actor actor : model.getLocalActors()) { Projector projector = new LanguageProjectorImpl(); LanguageModel local = projector.project(model, actor.getName(), j); if (srcFolder != null) { try { // Write scribble language generated Java code IPath path = new Path( local.getDeclaration().getFullName().replace('.', java.io.File.separatorChar) + "_" + actor.getName() + ".java"); IFile file = srcFolder.getFile(path); IFolder parent = (IFolder) file.getParent(); create(parent); String processText = generator.generateProcess(local, actor); java.io.InputStream is = new java.io.ByteArrayInputStream(processText.getBytes()); if (file.exists()) { file.delete(true, new org.eclipse.core.runtime.NullProgressMonitor()); } file.create(is, true, new org.eclipse.core.runtime.NullProgressMonitor()); file.setDerived(true, new org.eclipse.core.runtime.NullProgressMonitor()); is.close(); // Create the factory class path = new Path( local.getDeclaration().getFullName().replace('.', java.io.File.separatorChar) + "_" + actor.getName() + "_factory.java"); file = srcFolder.getFile(path); String processFactoryText = generator.generateProcessFactory(local, actor); is = new java.io.ByteArrayInputStream(processFactoryText.getBytes()); if (file.exists()) { file.delete(true, new org.eclipse.core.runtime.NullProgressMonitor()); } file.create(is, true, new org.eclipse.core.runtime.NullProgressMonitor()); file.setDerived(true, new org.eclipse.core.runtime.NullProgressMonitor()); is.close(); // Create the test class path = new Path( local.getDeclaration().getFullName().replace('.', java.io.File.separatorChar) + "_" + actor.getName() + "_test.java"); file = srcFolder.getFile(path); if (file.exists() == false) { String processTestText = generator.generateProcessTest(local, actor); is = new java.io.ByteArrayInputStream(processTestText.getBytes()); if (file.exists()) { file.delete(true, new org.eclipse.core.runtime.NullProgressMonitor()); } file.create(is, true, new org.eclipse.core.runtime.NullProgressMonitor()); is.close(); } } catch (Exception e) { e.printStackTrace(); } } // Check if manifest exists IFile manifestFile = res.getProject().getFile("META-INF/MANIFEST.MF"); if (manifestFile.exists()) { try { // Generate OSGi descriptor String osgiDescriptorFileName = "OSGI-INF/" + model.getDeclaration().getLocalName() + "-" + actor.getName() + ".xml"; IFile osgiDescriptorFile = res.getProject().getFile(osgiDescriptorFileName); IFolder parent = (IFolder) osgiDescriptorFile.getParent(); create(parent); String osgiDescriptorText = generator.generateOSGiDescriptor(local, actor); java.io.InputStream is = new java.io.ByteArrayInputStream( osgiDescriptorText.getBytes()); if (osgiDescriptorFile.exists()) { osgiDescriptorFile.delete(true, new org.eclipse.core.runtime.NullProgressMonitor()); } osgiDescriptorFile.create(is, true, new org.eclipse.core.runtime.NullProgressMonitor()); osgiDescriptorFile.setDerived(true, new org.eclipse.core.runtime.NullProgressMonitor()); is.close(); if (serviceComponent == null) { serviceComponent = osgiDescriptorFileName; } else { serviceComponent += ", " + osgiDescriptorFileName; } } catch (Exception e) { e.printStackTrace(); } } } // Check if manifest exists IFile manifestFile = res.getProject().getFile("META-INF/MANIFEST.MF"); if (manifestFile.exists()) { // Update dependencies based on the model java.util.jar.Manifest manifest = new java.util.jar.Manifest(); try { java.io.InputStream is = manifestFile.getContents(); manifest.read(is); is.close(); generator.generateManifest(model, manifest, serviceComponent); java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream(); manifest.write(os); os.close(); byte[] b = os.toByteArray(); // Write back the new manifest is = new java.io.ByteArrayInputStream(b); manifestFile.setContents(is, true, true, new org.eclipse.core.runtime.NullProgressMonitor()); is.close(); } catch (Exception e) { e.printStackTrace(); } } } } }