List of usage examples for org.eclipse.jdt.core JavaCore newContainerEntry
public static IClasspathEntry newContainerEntry(IPath containerPath, boolean isExported)
CPE_CONTAINER
for the given path. From source file:bndtools.wizards.project.NewBndProjectWizardPageOne.java
License:Open Source License
@Override public IClasspathEntry[] getDefaultClasspathEntries() { IClasspathEntry[] entries = super.getDefaultClasspathEntries(); List<IClasspathEntry> result = new ArrayList<IClasspathEntry>(entries.length + 2); result.addAll(Arrays.asList(entries)); // Add the Bnd classpath container entry IPath bndContainerPath = BndtoolsConstants.BND_CLASSPATH_ID; IClasspathEntry bndContainerEntry = JavaCore.newContainerEntry(bndContainerPath, false); result.add(bndContainerEntry);/* w w w.j av a2 s .c om*/ return result.toArray(new IClasspathEntry[0]); }
From source file:com.android.ide.eclipse.adt.internal.project.LibraryClasspathContainerInitializer.java
License:Open Source License
private static IClasspathContainer allocateContainer(IJavaProject javaProject, List<IClasspathEntry> entries, IPath id, String description) { if (AdtPlugin.getDefault() == null) { // This is totally weird, but I've seen it happen! return null; }/* w w w . j a v a2 s . com*/ // First check that the project has a library-type container. try { IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); final IClasspathEntry[] oldRawClasspath = rawClasspath; boolean foundContainer = false; for (IClasspathEntry entry : rawClasspath) { // get the entry and kind final int kind = entry.getEntryKind(); if (kind == IClasspathEntry.CPE_CONTAINER) { String path = entry.getPath().toString(); String idString = id.toString(); if (idString.equals(path)) { foundContainer = true; break; } } } // if there isn't any, add it. if (foundContainer == false) { // add the android container to the array rawClasspath = ProjectHelper.addEntryToClasspath(rawClasspath, JavaCore.newContainerEntry(id, true /*isExported*/)); } // set the new list of entries to the project if (rawClasspath != oldRawClasspath) { javaProject.setRawClasspath(rawClasspath, new NullProgressMonitor()); } } catch (JavaModelException e) { // This really shouldn't happen, but if it does, simply return null (the calling // method will fails as well) return null; } return new AndroidClasspathContainer(entries.toArray(new IClasspathEntry[entries.size()]), id, description, IClasspathContainer.K_APPLICATION); }
From source file:com.android.ide.eclipse.auidt.internal.project.LibraryClasspathContainerInitializer.java
License:Open Source License
private static IClasspathContainer allocateLibraryContainer(IJavaProject javaProject) { final IProject iProject = javaProject.getProject(); AdtPlugin plugin = AdtPlugin.getDefault(); if (plugin == null) { // This is totally weird, but I've seen it happen! return null; }/*from w w w . ja v a2s . c o m*/ // First check that the project has a library-type container. try { IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); IClasspathEntry[] oldRawClasspath = rawClasspath; boolean foundLibrariesContainer = false; for (IClasspathEntry entry : rawClasspath) { // get the entry and kind int kind = entry.getEntryKind(); if (kind == IClasspathEntry.CPE_CONTAINER) { String path = entry.getPath().toString(); if (AdtConstants.CONTAINER_LIBRARIES.equals(path)) { foundLibrariesContainer = true; break; } } } // if there isn't any, add it. if (foundLibrariesContainer == false) { // add the android container to the array rawClasspath = ProjectHelper.addEntryToClasspath(rawClasspath, JavaCore .newContainerEntry(new Path(AdtConstants.CONTAINER_LIBRARIES), true /*isExported*/)); } // set the new list of entries to the project if (rawClasspath != oldRawClasspath) { javaProject.setRawClasspath(rawClasspath, new NullProgressMonitor()); } } catch (JavaModelException e) { // This really shouldn't happen, but if it does, simply return null (the calling // method will fails as well) return null; } // check if the project has a valid target. ProjectState state = Sdk.getProjectState(iProject); if (state == null) { // getProjectState should already have logged an error. Just bail out. return null; } /* * At this point we're going to gather a list of all that need to go in the * dependency container. * - Library project outputs (direct and indirect) * - Java project output (those can be indirectly referenced through library projects * or other other Java projects) * - Jar files: * + inside this project's libs/ * + inside the library projects' libs/ * + inside the referenced Java projects' classpath */ List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); // list of java project dependencies and jar files that will be built while // going through the library projects. Set<File> jarFiles = new HashSet<File>(); Set<IProject> refProjects = new HashSet<IProject>(); // process all the libraries List<IProject> libProjects = state.getFullLibraryProjects(); for (IProject libProject : libProjects) { // get the project output IFolder outputFolder = BaseProjectHelper.getAndroidOutputFolder(libProject); if (outputFolder != null) { // can happen when closing/deleting a library) IFile jarIFile = outputFolder.getFile(libProject.getName().toLowerCase() + AdtConstants.DOT_JAR); // get the source folder for the library project List<IPath> srcs = BaseProjectHelper.getSourceClasspaths(libProject); // find the first non-derived source folder. IPath sourceFolder = null; for (IPath src : srcs) { IFolder srcFolder = workspaceRoot.getFolder(src); if (srcFolder.isDerived() == false) { sourceFolder = src; break; } } // we can directly add a CPE for this jar as there's no risk of a duplicate. IClasspathEntry entry = JavaCore.newLibraryEntry(jarIFile.getLocation(), sourceFolder, // source attachment path null, // default source attachment root path. true /*isExported*/); entries.add(entry); // process all of the library project's dependencies getDependencyListFromClasspath(libProject, refProjects, jarFiles, true); // and the content of its libs folder. getJarListFromLibsFolder(libProject, jarFiles); } } // now process this projects' referenced projects only. processReferencedProjects(iProject, refProjects, jarFiles); // and the content of its libs folder getJarListFromLibsFolder(iProject, jarFiles); // annotations support for older version of android if (state.getTarget() != null && state.getTarget().getVersion().getApiLevel() <= 15) { File annotationsJar = new File(Sdk.getCurrent().getSdkLocation(), SdkConstants.FD_TOOLS + File.separator + SdkConstants.FD_SUPPORT + File.separator + SdkConstants.FN_ANNOTATIONS_JAR); jarFiles.add(annotationsJar); } // now add a classpath entry for each Java project (this is a set so dups are already // removed) for (IProject p : refProjects) { entries.add(JavaCore.newProjectEntry(p.getFullPath(), true /*isExported*/)); } // and process the jar files list, but first sanitize it to remove dups. JarListSanitizer sanitizer = new JarListSanitizer( iProject.getFolder(SdkConstants.FD_OUTPUT).getLocation().toFile(), new AndroidPrintStream(iProject, null /*prefix*/, AdtPlugin.getOutStream())); String errorMessage = null; try { List<File> sanitizedList = sanitizer.sanitize(jarFiles); for (File jarFile : sanitizedList) { if (jarFile instanceof CPEFile) { CPEFile cpeFile = (CPEFile) jarFile; IClasspathEntry e = cpeFile.getClasspathEntry(); entries.add(JavaCore.newLibraryEntry(e.getPath(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), e.getAccessRules(), e.getExtraAttributes(), true /*isExported*/)); } else { String jarPath = jarFile.getAbsolutePath(); IPath sourceAttachmentPath = null; IClasspathAttribute javaDocAttribute = null; File jarProperties = new File(jarPath + DOT_PROPERTIES); if (jarProperties.isFile()) { Properties p = new Properties(); InputStream is = null; try { p.load(is = new FileInputStream(jarProperties)); String value = p.getProperty(ATTR_SRC); if (value != null) { File srcPath = getFile(jarFile, value); if (srcPath.exists()) { sourceAttachmentPath = new Path(srcPath.getAbsolutePath()); } } value = p.getProperty(ATTR_DOC); if (value != null) { File docPath = getFile(jarFile, value); if (docPath.exists()) { try { javaDocAttribute = JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docPath.toURI().toURL().toString()); } catch (MalformedURLException e) { AdtPlugin.log(e, "Failed to process 'doc' attribute for %s", jarProperties.getAbsolutePath()); } } } } catch (FileNotFoundException e) { // shouldn't happen since we check upfront } catch (IOException e) { AdtPlugin.log(e, "Failed to read %s", jarProperties.getAbsolutePath()); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // ignore } } } } if (javaDocAttribute != null) { entries.add(JavaCore.newLibraryEntry(new Path(jarPath), sourceAttachmentPath, null /*sourceAttachmentRootPath*/, new IAccessRule[0], new IClasspathAttribute[] { javaDocAttribute }, true /*isExported*/)); } else { entries.add(JavaCore.newLibraryEntry(new Path(jarPath), sourceAttachmentPath, null /*sourceAttachmentRootPath*/, true /*isExported*/)); } } } } catch (DifferentLibException e) { errorMessage = e.getMessage(); AdtPlugin.printErrorToConsole(iProject, (Object[]) e.getDetails()); } catch (Sha1Exception e) { errorMessage = e.getMessage(); } processError(iProject, errorMessage, AdtConstants.MARKER_DEPENDENCY, true /*outputToConsole*/); return new AndroidClasspathContainer(entries.toArray(new IClasspathEntry[entries.size()]), new Path(AdtConstants.CONTAINER_LIBRARIES), "Android Dependencies", IClasspathContainer.K_APPLICATION); }
From source file:com.legstar.eclipse.plugin.common.wizards.AbstractWizardPage.java
License:Open Source License
/** * The target Java project needs a container library on its classpath. * This assumes a classpath initializer did define the library * container and all what is left to do is to update the project with yet * another classpath entry./*from ww w.ja v a 2s.co m*/ * * @param jproject the target java project * @param libraryName the name of the container library * @throws JavaModelException if seting up classpath fails */ public void setupContainerLibrary(final IJavaProject jproject, final String libraryName) throws JavaModelException { IClasspathEntry varEntry = JavaCore.newContainerEntry(new Path(libraryName), false); java.util.List<IClasspathEntry> sourceEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : jproject.getRawClasspath()) { sourceEntries.add(entry); } sourceEntries.add(varEntry); IClasspathEntry[] entries = (IClasspathEntry[]) sourceEntries .toArray(new IClasspathEntry[sourceEntries.size()]); jproject.setRawClasspath(entries, null); }
From source file:com.windowtester.codegen.util.BuildPathUtil.java
License:Open Source License
/** * Validate if the project has required libraries in build path. I the case if not it will add them to it. * /* ww w. j a va 2s.c o m*/ * @return the status of the validation */ public static IStatus validateDependencies(IJavaProject targetProject, boolean addDefault, boolean isRcpApplication) { Status status = new Status(IStatus.OK, CodeGenPlugin.getPluginId(), IStatus.OK, "Project has all libraires", null); boolean addJUnitJar = checkToAddEntry(targetProject, JUNIT_CLASS); boolean addCommonRuntimeJar = checkToAddEntry(targetProject, COMMON_UI_TEST_CASE_NAME); boolean addSwtRuntimeJar = checkToAddEntry(targetProject, SWT_UI_TEST_CASE_NAME); boolean addSwingRuntimeJar = checkToAddEntry(targetProject, SWING_UI_TEST_CASE_NAME); boolean addJFaceJar = checkToAddEntry(targetProject, JFACE_CLASS); // boolean addCommonDebug = checkToAddEntry(targetProject, LOGGER_CLASS); // boolean addCommonCore = checkToAddEntry(targetProject, COMMON_CORE_PRODUCTS_CLASS); boolean addCoreRuntime = checkToAddEntry(targetProject, CORE_RUNTIME_PLATFORM_CLASS); // boolean addCommonUtil = checkToAddEntry(targetProject, ECLIPSE_PLUGIN_UTILS_CLASS); boolean addOsgiRuntime = checkToAddEntry(targetProject, OSGI_RUNTIME_PATH_CLASS); boolean addOsgi = checkToAddEntry(targetProject, OSGI_NLS_CLASS); // test if there is a need to move forward if (!addJUnitJar && !addCommonRuntimeJar && !addSwtRuntimeJar && !addSwingRuntimeJar && !addJFaceJar && !addCoreRuntime && !addOsgiRuntime && !addOsgi) { return status; } if (addDefault) { try { if (isRcpApplication) { if (addJUnitJar) BuildPathUtil.addPluginDependency(targetProject, JUNIT_BUNDLE); if (addCommonRuntimeJar) BuildPathUtil.addPluginDependency(targetProject, RUNTIME_DEP_RUNTIME_COMMON); if (addSwtRuntimeJar) BuildPathUtil.addPluginDependency(targetProject, RUNTIME_DEP_RUNTIME_SWT); if (addSwingRuntimeJar) BuildPathUtil.addPluginDependency(targetProject, RUNTIME_DEP_RUNTIME_SWING); if (addJFaceJar) BuildPathUtil.addPluginDependency(targetProject, JFACE_BUNDLE); if (addCoreRuntime) BuildPathUtil.addPluginDependency(targetProject, CORE_RUNTIME_BUNDLE); } else { // add the WindowTester classpath container addToClasspath(targetProject, JavaCore.newContainerEntry(new Path(CLASSPATH_CONTAINER_ID), false)); // add the appropriate JUnit container/library depending upon platform /* $codepro.preprocessor.if version >= 3.2 $ */ addToClasspath(targetProject, JavaCore.newContainerEntry(JUNIT3_PATH, false)); /* $codepro.preprocessor.elseif version < 3.2 $ addRuntimeJarToBuildPath(targetProject, JUNIT_BUNDLE, JUNIT_VAR_NAME, "junit.jar"); $codepro.preprocessor.endif $ */ } return status; } catch (CoreException e) { return e.getStatus(); } } return new Status(IStatus.WARNING, CodeGenPlugin.getPluginId(), IStatus.WARNING, "Some required libraries are missing.", null); }
From source file:com.windowtester.codegen.util.BuildPathUtil.java
License:Open Source License
public static IClasspathEntry getRuntimeContainerEntry(IJavaProject targetProject) throws JavaModelException { // add WindowTester Runtime Classpath container and give it to handle all dependencies IClasspathEntry entry = JavaCore.newContainerEntry(new Path(CLASSPATH_CONTAINER_ID), false); IClasspathEntry[] entries = BuildPathUtil.getRuntimeClasspathEntries(targetProject); JavaCore.setClasspathContainer(entry.getPath(), new IJavaProject[] { targetProject }, new IClasspathContainer[] { new RuntimeClasspathContainer(entries, entry.getPath()) }, null); return entry; }
From source file:egovframework.hdev.imp.ide.wizards.operation.NewDeviceAPIHybridProjectCreationOperation.java
License:Apache License
/** * ? /*from w w w . jav a2 s . c o m*/ */ protected void configureAndroidClasspath(IProgressMonitor monitor) throws CoreException { List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.add(JavaCore.newContainerEntry(ResourceConstants.ANDROID_FRAMEWORK, true)); entries.add(JavaCore.newContainerEntry(ResourceConstants.ANDROID_LIBRARIES, true)); IClasspathEntry[] classpathEntrys = (IClasspathEntry[]) entries .toArray(new IClasspathEntry[entries.size()]); DeviceAPIIdeUtils.assignClasspathEntryToJavaProject(getDeviceapiProject(), classpathEntrys, true); }
From source file:fede.workspace.eclipse.java.JavaProjectManager.java
License:Apache License
/** * Creates an empty Java project associated with the eclipse project * corresponding to the item.//from w ww.ja v a2 s .co m * * Automatically creates a source directory and default ouptut location. * * @param item * the item * @param monitor * the monitor * @param project * the project * @param cxt * the cxt * @param defaultSourceFolder * the default source folder * @param defaultClassFolder * the default class folder * * @return the created java project * * @throws CoreException * the core exception */ public static IJavaProject createJavaProject(IProject project, Item item, IProgressMonitor monitor, ContextVariable cxt, Variable defaultSourceFolder, Variable defaultClassFolder) throws CoreException { /* * Create empty project if needed */ if (project == null) { return null; } if (!project.exists()) { project.create(monitor); } project.open(monitor); IJavaProject javaProject = JavaCore.create(project); /* * Add Java nature and initialize classpath */ IProjectDescription description = project.getDescription(); List<String> natures = new ArrayList<String>(Arrays.asList(description.getNatureIds())); if (!description.hasNature(JavaCore.NATURE_ID)) { IClasspathEntry[] classpath = null; String sourceFolder = defaultSourceFolder.compute(cxt, item); String classFolder = defaultClassFolder.compute(cxt, item); if (sourceFolder != null && classFolder != null) { IFolder sources = project.getFolder(sourceFolder); if (!sources.exists()) { sources.create(false, true, monitor); } IFolder output = project.getFolder(classFolder); if (!output.exists()) { output.create(false, true, monitor); } } natures.add(JavaCore.NATURE_ID); description.setNatureIds(natures.toArray(new String[natures.size()])); project.setDescription(description, monitor); if (sourceFolder != null && classFolder != null) { IFolder sources = project.getFolder(sourceFolder); IFolder output = project.getFolder(classFolder); classpath = new IClasspathEntry[] { JavaCore.newSourceEntry(sources.getFullPath()), JavaCore.newContainerEntry(new Path(JavaRuntime.JRE_CONTAINER), false), ItemDependenciesClasspathEntry.CLASSPATH_ENTRY }; javaProject.setRawClasspath(classpath, output.getFullPath(), monitor); } else { classpath = new IClasspathEntry[] { JavaCore.newContainerEntry(new Path(JavaRuntime.JRE_CONTAINER), false), ItemDependenciesClasspathEntry.CLASSPATH_ENTRY }; javaProject.setRawClasspath(classpath, monitor); } } return javaProject; }
From source file:me.gladwell.eclipse.m2e.android.configuration.classpath.MarkAndroidClasspathContainerNotExportedConfigurer.java
License:Open Source License
public void configure(Project project) { IClasspathEntry oldEntry = findContainerMatching(project.getClasspath(), AdtConstants.CONTAINER_PRIVATE_LIBRARIES); if (oldEntry != null) { IClasspathEntry newEntry = JavaCore.newContainerEntry(oldEntry.getPath(), false); project.getClasspath().removeEntry(oldEntry.getPath()); project.getClasspath().addEntry(newEntry); } else {/* w ww .j a va 2 s . c o m*/ // TODO log warning here } }
From source file:me.gladwell.eclipse.m2e.android.configuration.classpath.MarkMavenClasspathContianerExportedConfigurer.java
License:Open Source License
public void configure(Project project) { IClasspathEntry oldEntry = findContainerMatching(project.getClasspath(), IClasspathManager.CONTAINER_ID); IClasspathEntry newEntry = JavaCore.newContainerEntry(oldEntry.getPath(), true); project.getClasspath().removeEntry(oldEntry.getPath()); project.getClasspath().addEntry(newEntry); }