List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:org.eclipse.jst.j2ee.internal.common.UpdateProjectClasspath.java
License:Open Source License
private void addSrcFolderToProject(String sourceFolder, String componentName, IProject jProject) { IJavaProject javaProject = JavaCore.create(jProject); try {/*from w w w . j a va2 s . com*/ IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); List oldEntriesList, classpathList; IClasspathEntry[] newEntries = getClasspathEntries(sourceFolder, componentName, jProject); /** * Warning clean-up 12/05/2005 */ //int oldSize = oldEntries.length; //int newSize = newEntries.length; classpathList = new ArrayList(); oldEntriesList = Arrays.asList(oldEntries); classpathList.addAll(oldEntriesList); for (int j = 0; j < newEntries.length; j++) { if (!oldEntriesList.contains(newEntries[j])) { classpathList.add(newEntries[j]); } } IClasspathEntry[] classpathEntries = (IClasspathEntry[]) classpathList .toArray(new IClasspathEntry[classpathList.size()]); javaProject.setRawClasspath(classpathEntries, null); } catch (JavaModelException e) { J2EEPlugin.logError(e); } }
From source file:org.eclipse.jst.j2ee.internal.J2EEComponentProjectMigrator.java
License:Open Source License
private void replaceDeployablesOutputIfNecessary(IProject proj) { IJavaProject jproj = JemProjectUtilities.getJavaProject(proj); final IClasspathEntry[] current; boolean deployablesFound = false; try {/*w w w. j av a 2 s. com*/ current = jproj.getRawClasspath(); List updatedList = new ArrayList(); IPath sourcePath = null; for (int i = 0; i < current.length; i++) { IClasspathEntry entry = current[i]; if ((entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) && (entry.getOutputLocation() != null && entry.getOutputLocation().toString().indexOf(OLD_DEPLOYABLES_PATH) != -1)) { sourcePath = entry.getPath(); updatedList.add(JavaCore.newSourceEntry(sourcePath)); deployablesFound = true; } else updatedList.add(entry); } if (deployablesFound) { IClasspathEntry[] updated = (IClasspathEntry[]) updatedList .toArray(new IClasspathEntry[updatedList.size()]); jproj.setRawClasspath(updated, null); jproj.save(null, true); } } catch (JavaModelException e) { J2EEUIPlugin.logError(e); } }
From source file:org.eclipse.jst.j2ee.internal.J2EEComponentProjectMigrator.java
License:Open Source License
private void removeOldWebContainerIfNecessary(IProject webProj) { IJavaProject jproj = JemProjectUtilities.getJavaProject(webProj); final IClasspathEntry[] current; try {//from w w w .j ava 2 s .co m current = jproj.getRawClasspath(); List updatedList = new ArrayList(); boolean useDefaultWebAppLibraries = J2EEComponentClasspathContainerUtils.getDefaultUseWebAppLibraries(); for (int i = 0; i < current.length; i++) { IClasspathEntry entry = current[i]; // the web container is added to the classpath if: // 1. they don't have an entry for WEB_LIB_CONTAINER AND // 2. they have an entry for WEB_LIB_PATH BUT // they do not have the preference checked to use the Web App classpath container if ((entry.getPath().toString().indexOf(WEB_LIB_CONTAINER) == -1) && ((entry.getPath().toString().indexOf(WEB_LIB_PATH) == -1) || !useDefaultWebAppLibraries)) updatedList.add(entry); } IClasspathEntry[] updated = (IClasspathEntry[]) updatedList .toArray(new IClasspathEntry[updatedList.size()]); jproj.setRawClasspath(updated, null); jproj.save(null, true); } catch (JavaModelException e) { J2EEUIPlugin.logError(e); } }
From source file:org.eclipse.jst.j2ee.internal.jca.operations.ConnectorComponentImportOperation.java
License:Open Source License
protected static void addToClasspath(List extraEntries, IJavaProject javaProject) throws JavaModelException { if (extraEntries.size() > 0) { IClasspathEntry[] javaClasspath = javaProject.getRawClasspath(); List nonDuplicateList = new ArrayList(); for (int i = 0; i < extraEntries.size(); i++) { IClasspathEntry extraEntry = (IClasspathEntry) extraEntries.get(i); boolean include = true; for (int j = 0; include && j < javaClasspath.length; j++) { if (extraEntry.equals(javaClasspath[j])) { include = false;/*www.j av a 2 s . c om*/ } } if (include) { nonDuplicateList.add(extraEntry); } } if (nonDuplicateList.size() > 0) { IClasspathEntry[] newJavaClasspath = new IClasspathEntry[javaClasspath.length + nonDuplicateList.size()]; System.arraycopy(javaClasspath, 0, newJavaClasspath, 0, javaClasspath.length); for (int j = 0; j < nonDuplicateList.size(); j++) { newJavaClasspath[javaClasspath.length + j] = (IClasspathEntry) nonDuplicateList.get(j); } javaProject.setRawClasspath(newJavaClasspath, new NullProgressMonitor()); } } }
From source file:org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities.java
License:Open Source License
/** * Append one IClasspathEntry to the build path of the passed project. If a classpath entry * having the same path as the parameter already exists, then does nothing. *///from ww w . j a v a 2 s. co m public static void appendJavaClassPath(IProject p, IClasspathEntry newEntry) throws JavaModelException { IJavaProject javaProject = JemProjectUtilities.getJavaProject(p); if (javaProject == null) return; IClasspathEntry[] classpath = javaProject.getRawClasspath(); List newPathList = new ArrayList(classpath.length); for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; // fix dup class path entry for .JETEmitter project // Skip the entry to be added if it already exists if (Platform.getOS().equals(Platform.OS_WIN32)) { if (!entry.getPath().toString().equalsIgnoreCase(newEntry.getPath().toString())) newPathList.add(entry); else return; } else { if (!entry.getPath().equals(newEntry.getPath())) newPathList.add(entry); else return; } } newPathList.add(newEntry); IClasspathEntry[] newClasspath = (IClasspathEntry[]) newPathList .toArray(new IClasspathEntry[newPathList.size()]); javaProject.setRawClasspath(newClasspath, new NullProgressMonitor()); }
From source file:org.eclipse.jst.j2ee.internal.project.WTPJETEmitter.java
License:Open Source License
/** * @param progressMonitor//www . j av a2 s . c o m * @param project * @param javaProject * @throws CoreException * @throws JavaModelException * @throws BackingStoreException */ protected void initializeJavaProject(IProgressMonitor progressMonitor, final IProject project, IJavaProject javaProject) throws CoreException, JavaModelException, BackingStoreException { progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETInitializingProject_message", //$NON-NLS-1$ new Object[] { project.getName() })); IClasspathEntry classpathEntry = JavaCore.newSourceEntry(new Path("/" + project.getName() + "/src")); //$NON-NLS-1$ //$NON-NLS-2$ //IClasspathEntry jreClasspathEntry = JavaCore.newVariableEntry(new Path(JavaRuntime.JRELIB_VARIABLE), new Path(JavaRuntime.JRESRC_VARIABLE), new Path(JavaRuntime.JRESRCROOT_VARIABLE)); IClasspathEntry jreClasspathEntry = JavaRuntime.getDefaultJREContainerEntry(); List classpath = new ArrayList(); classpath.add(classpathEntry); classpath.add(jreClasspathEntry); classpath.addAll(classpathEntries); IFolder sourceFolder = project.getFolder(new Path("src")); //$NON-NLS-1$ if (!sourceFolder.exists()) { sourceFolder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); } IFolder runtimeFolder = project.getFolder(new Path("runtime")); //$NON-NLS-1$ if (!runtimeFolder.exists()) { runtimeFolder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); } IClasspathEntry[] classpathEntryArray = (IClasspathEntry[]) classpath .toArray(new IClasspathEntry[classpath.size()]); javaProject.setRawClasspath(classpathEntryArray, new SubProgressMonitor(progressMonitor, 1)); javaProject.setOutputLocation(new Path("/" + project.getName() + "/runtime"), //$NON-NLS-1$//$NON-NLS-2$ new SubProgressMonitor(progressMonitor, 1)); // appended from previous implementation createClasspathEntries(project); IScopeContext context = new ProjectScope(project); IEclipsePreferences prefs = context.getNode(JavaCore.PLUGIN_ID); prefs.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.IGNORE); prefs.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); // set Java compiler compliance level to 1.5 prefs.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); prefs.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); prefs.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); prefs.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); prefs.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); // set Javadoc validation to the default ignore level prefs.put(JavaCore.COMPILER_PB_INVALID_JAVADOC, JavaCore.IGNORE); prefs.put(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS, JavaCore.DISABLED); prefs.put(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS__DEPRECATED_REF, JavaCore.DISABLED); prefs.put(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS__NOT_VISIBLE_REF, JavaCore.DISABLED); prefs.put(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS_VISIBILITY, JavaCore.PUBLIC); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAG_DESCRIPTION, JavaCore.COMPILER_PB_MISSING_JAVADOC_TAG_DESCRIPTION_RETURN_TAG); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS, JavaCore.IGNORE); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS_VISIBILITY, JavaCore.PUBLIC); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS_OVERRIDING, JavaCore.DISABLED); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS, JavaCore.IGNORE); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS_VISIBILITY, JavaCore.PUBLIC); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS_OVERRIDING, JavaCore.DISABLED); // store changed properties permanently prefs.flush(); }
From source file:org.eclipse.jst.j2ee.internal.ui.J2EEModuleDependenciesPropertyPage.java
License:Open Source License
@Override protected boolean saveReferenceChanges() { boolean subResult = super.saveReferenceChanges(); if (!subResult) { return subResult; }/*from ww w. j a v a2 s. c om*/ if (!shouldSaveClasspathEntires()) return true; Map<IPath, IClasspathEntry> modified = new HashMap<IPath, IClasspathEntry>(); Map<IPath, IClasspathEntry> originalMap = new HashMap<IPath, IClasspathEntry>(); for (IClasspathEntry originalEntry : originalClasspathEntries) { originalMap.put(originalEntry.getPath(), originalEntry); } for (ClasspathEntryProxy proxy : currentClasspathEntries) { IClasspathEntry currentEntry = proxy.entry; IPath path = currentEntry.getPath(); IClasspathEntry originalEntry = originalMap.remove(path); if (currentEntry.equals(originalEntry)) { //no change continue; } modified.put(path, currentEntry); } Map<IPath, IClasspathEntry> removed = originalMap; IJavaProject javaProject = JavaCore.create(rootComponent.getProject()); try { final IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : rawClasspath) { IPath path = entry.getPath(); if (removed.containsKey(path)) { //user removed entry IClasspathEntry newEntry = ClasspathDependencyUtil.modifyDependencyPath(entry, null); newClasspath.add(newEntry); } else if (modified.containsKey(path)) { //user changed path value IClasspathEntry newEntry = modified.get(path); IPath runtimePath = ClasspathDependencyUtil.getRuntimePath(newEntry); if (runtimePath.toString().length() == 0) { //prevent the user from specifying no path newEntry = ClasspathDependencyUtil.modifyDependencyPath(newEntry, new Path("/")); //$NON-NLS-1$ } newClasspath.add(newEntry); } else { //no change newClasspath.add(entry); } } javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[newClasspath.size()]), null); originalClasspathEntries.clear(); currentClasspathEntries.clear(); resetClasspathEntries(); } catch (JavaModelException e) { J2EEUIPlugin.logError(e); return false; } return true; }
From source file:org.eclipse.jst.j2ee.internal.web.operations.WebPropertiesUtil.java
License:Open Source License
/** * Synchonizies the class path and the lib directories to catch any changes from the last use * Creation date: (4/17/01 11:48:12 AM)/* ww w.ja va 2s .c o m*/ */ protected static void synch(IProject project, IProgressMonitor monitor) { IProgressMonitor localMonitor = monitor; try { if (localMonitor == null) { localMonitor = new NullProgressMonitor(); } localMonitor.beginTask(ProjectSupportResourceHandler.Sychronize_Class_Path_UI_, 4); //$NON-NLS-1$ = "Sychronize Class Path" IContainer lib_folder = getWebLibFolder(project); // Nothing to do if the lib folder does not exist. if (lib_folder == null || !lib_folder.isAccessible()) return; IJavaProject javaProject = JemProjectUtilities.getJavaProject(project); IPath lib_path = lib_folder.getProjectRelativePath(); IPath lib_full_path = lib_folder.getFullPath(); IClasspathEntry[] cp = javaProject.getRawClasspath(); boolean needsToBeModified = false; // Create a map of the lib projects in the current project Hashtable lib_jars = new Hashtable(); IResource[] children = lib_folder.members(); localMonitor.subTask(ProjectSupportResourceHandler.Catalog_Lib_Directory__UI_); //$NON-NLS-1$ = "Catalog Lib Directory:" for (int j = 0; j < children.length; j++) { IResource child = children[j]; // monitor.setTaskName(ResourceHandler.getString("Catalog_Lib_Directory__UI_") + // child); //$NON-NLS-1$ = "Catalog Lib Directory:" // Make sure it is a zip or a jar file if (child.getType() == IResource.FILE && (child.getFullPath().toString().toLowerCase().endsWith(IJ2EEModuleConstants.JAR_EXT) || child.getFullPath().toString().toLowerCase().endsWith(".zip"))) { //$NON-NLS-1$ lib_jars.put(child.getFullPath(), child); } } localMonitor.worked(1); localMonitor.subTask(ProjectSupportResourceHandler.Update_ClassPath__UI_); //$NON-NLS-1$ = "Update ClassPath:" // Loop through all the classpath dirs looking for ones that may have // been deleted Vector newClassPathVector = new Vector(); for (int j = 0; j < cp.length; j++) { // If it is a lib_path if (cp[j].getPath().toString().startsWith(lib_path.toString()) || cp[j].getPath().toString().startsWith(lib_full_path.toString())) { // It was already in the class path if (lib_jars.get(cp[j].getPath()) != null) { newClassPathVector.add(cp[j]); // Remove it from the hash table of paths to add back // monitor.setTaskName(ResourceHandler.getString("Catalog_Lib_Directory__UI_") // + cp[j].getPath()); //$NON-NLS-1$ = "Catalog Lib Directory:" lib_jars.remove(cp[j].getPath()); } else { // You have removed something form the class path you // will need to re-build // monitor.setTaskName(ResourceHandler.getString("Catalog_Lib_Directory_Remo_UI_") // + cp[j].getPath()); //$NON-NLS-1$ = "Catalog Lib Directory:Remove " needsToBeModified = true; } } else { localMonitor .subTask(ProjectSupportResourceHandler.Catalog_Lib_Directory__UI_ + cp[j].getPath()); //$NON-NLS-1$ = "Catalog Lib Directory:" newClassPathVector.add(cp[j]); } } localMonitor.worked(1); localMonitor.subTask(ProjectSupportResourceHandler.Update_ClassPath__UI_); //$NON-NLS-1$ = "Update ClassPath:" // Add any entries not already found Enumeration aenum = lib_jars.keys(); while (aenum.hasMoreElements()) { IPath path = (IPath) aenum.nextElement(); newClassPathVector.add(JavaCore.newLibraryEntry(path, null, null)); // You have added something form the class path you // will need to re-build // monitor.setTaskName(ResourceHandler.getString("23concat_UI_", (new Object[] { // path }))); //$NON-NLS-1$ = "Catalog Lib Directory:Add {0}" needsToBeModified = true; } localMonitor.worked(1); localMonitor.subTask(ProjectSupportResourceHandler.Set_ClassPath__UI_); //$NON-NLS-1$ = "Set ClassPath:" // Tansfer the vector to an array IClasspathEntry[] newClassPathArray = new IClasspathEntry[newClassPathVector.size()]; for (int j = 0; j < newClassPathArray.length; j++) { newClassPathArray[j] = (IClasspathEntry) newClassPathVector.get(j); } // Only change the class path if there has been a modification if (needsToBeModified) { try { javaProject.setRawClasspath(newClassPathArray, localMonitor); } catch (Exception e) { WebPlugin.logError(e); } } } catch (ClassCastException ex) { WebPlugin.logError(ex); } catch (CoreException ex) { WebPlugin.logError(ex); } finally { localMonitor.done(); } }
From source file:org.eclipse.jst.j2ee.project.facet.J2EEFacetInstallDelegate.java
License:Open Source License
protected static void addToClasspath(final IJavaProject jproj, final IClasspathEntry entry) throws CoreException { final IClasspathEntry[] existingEntries = jproj.getRawClasspath(); for (IClasspathEntry existingEntry : existingEntries) { if (existingEntry.getPath().equals(entry.getPath())) { // see bug 423742 return; }/*from w ww . j a va 2 s . c om*/ } final IClasspathEntry[] updated = new IClasspathEntry[existingEntries.length + 1]; System.arraycopy(existingEntries, 0, updated, 0, existingEntries.length); updated[existingEntries.length] = entry; jproj.setRawClasspath(updated, null); }
From source file:org.eclipse.jst.j2ee.project.facet.J2EEFacetRuntimeChangedDelegate.java
License:Open Source License
private void removeOnlyCPEntries(final IProject project, final IProjectFacetVersion fv, final IJavaProject jproj, final List cp, IRuntime oldRuntime) throws CoreException { IFacetedProject fproj = ProjectFacetsManager.create(project); IRuntime runtime = (oldRuntime != null) ? oldRuntime : fproj.getPrimaryRuntime(); if (runtime != null) { IClasspathProvider cpprov = (IClasspathProvider) runtime.getAdapter(IClasspathProvider.class); List cpentries = cpprov.getClasspathEntries(fv); boolean realCPChanged = false; if (cpentries != null) { for (Iterator itr = cpentries.iterator(); itr.hasNext();) { IClasspathEntry cpentry = (IClasspathEntry) itr.next(); IPath path = cpentry.getPath(); boolean contains = cp.contains(cpentry); if (contains) { for (Iterator itr2 = cp.iterator(); itr2.hasNext();) { final IClasspathEntry realEntry = (IClasspathEntry) itr2.next(); if (realEntry.getPath().equals(path)) { itr2.remove(); realCPChanged = true; break; }//from w w w . j ava2 s . c om } } } } if (realCPChanged) { IClasspathEntry[] newcp = (IClasspathEntry[]) cp.toArray(new IClasspathEntry[cp.size()]); jproj.setRawClasspath(newcp, null); } } }