List of usage examples for org.eclipse.jdt.core IJavaProject getElementName
String getElementName();
From source file:org.ebayopensource.vjet.eclipse.core.ClassPathUtils.java
License:Open Source License
public static URL[] getProjectDependencyUrls(List<IJavaProject> javaProjectList, List<URL> currentUrlList, HashMap<String, String> projectMap) throws JavaModelException, MalformedURLException { List<URL> projectDependencyUrlList = currentUrlList; if (projectDependencyUrlList == null) { projectDependencyUrlList = new ArrayList<URL>(); }/*from w w w .j a v a 2s .c o m*/ for (IJavaProject project : javaProjectList) { if (projectMap.containsKey(project.getElementName()) == true) { continue; } else { projectMap.put(project.getElementName(), project.getElementName()); } // Add the dependencies to the URL list IClasspathEntry[] entries; entries = project.getResolvedClasspath(true); for (IClasspathEntry entry : entries) { IPath path = entry.getPath(); File f = path.toFile(); URL entryUrl; entryUrl = f.toURI().toURL(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: if (projectDependencyUrlList.contains(entryUrl) == false) { projectDependencyUrlList.add(entryUrl); } break; case IClasspathEntry.CPE_PROJECT: List<IJavaProject> subjavaProjectList = new ArrayList<IJavaProject>(); IResource subResource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); if (subResource == null) { // String projectName = entry.getPath().toString(); // String parentProjectName = project.getElementName(); // throw new EclipseProjectNotFoundException( // projectName, // MessageFormat // .format( // "The dependent project {0} of project {1} is not // available.\nPlease update your workspace to include // this project", // projectName, parentProjectName)); } if (subResource != null && subResource.getType() == IResource.PROJECT) { IProject subProject = (IProject) subResource; IJavaProject subJavaProject = JavaCore.create(subProject); if (subJavaProject != null && subJavaProject.exists()) { subjavaProjectList.add(subJavaProject); // Recursively call our selves to populate the // project // dependency's for the sub projects. getProjectDependencyUrls(subjavaProjectList, projectDependencyUrlList, projectMap); } } break; default: break; } } IPath path = project.getOutputLocation(); IPath projectResourceLocation = project.getResource().getLocation(); File projectFilePath = projectResourceLocation.append(path.removeFirstSegments(1)).toFile(); URL projectOutputUrl; projectOutputUrl = projectFilePath.toURI().toURL(); if (projectDependencyUrlList.contains(projectOutputUrl) == false) { projectDependencyUrlList.add(projectOutputUrl); } } URL[] arrayList = new URL[projectDependencyUrlList.size()]; URL[] returnURLArray = projectDependencyUrlList.toArray(arrayList); return returnURLArray; }
From source file:org.ebayopensource.vjet.eclipse.core.PiggyBackClassPathUtil.java
License:Open Source License
public static URL[] getProjectDependencyUrls_bak(List<IJavaProject> javaProjectList, List<URL> currentUrlList, HashMap<String, String> projectMap) throws JavaModelException, MalformedURLException { List<URL> projectDependencyUrlList = currentUrlList; if (projectDependencyUrlList == null) { projectDependencyUrlList = new ArrayList<URL>(); }/*from w w w . j ava 2 s .c o m*/ for (IJavaProject project : javaProjectList) { if (projectMap.containsKey(project.getElementName()) == true) { continue; } else { projectMap.put(project.getElementName(), project.getElementName()); } // Add the dependencies to the URL list // IClasspathEntry[] entries; // entries = project.getResolvedClasspath(true); IClasspathEntry[] entries2; entries2 = project.getRawClasspath(); for (IClasspathEntry entry : entries2) { IPath path = entry.getPath(); File f = path.toFile(); URL entryUrl; entryUrl = f.toURL(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_LIBRARY: addEntryToList(entry, projectDependencyUrlList); case IClasspathEntry.CPE_PROJECT: List<IJavaProject> subjavaProjectList = new ArrayList<IJavaProject>(); IResource subResource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); if (subResource == null) { String projectName = entry.getPath().toString(); String parentProjectName = project.getElementName(); } if (subResource != null && subResource.getType() == IResource.PROJECT) { IProject subProject = (IProject) subResource; IJavaProject subJavaProject = JavaCore.create(subProject); if (subJavaProject != null && subJavaProject.exists()) { subjavaProjectList.add(subJavaProject); // Recursively call our selves to populate the // project // dependency's for the sub projects. getProjectDependencyUrls_bak(subjavaProjectList, projectDependencyUrlList, projectMap); } } break; case IClasspathEntry.CPE_CONTAINER: if (!JavaRuntime.JRE_CONTAINER.equals(path.toOSString())) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); if (container != null) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { addEntryToList(entries[i], projectDependencyUrlList); } } } break; default: break; } } // // IPath path = project.getOutputLocation(); // IPath projectResourceLocation = // project.getResource().getLocation(); // File projectFilePath = projectResourceLocation.append( // path.removeFirstSegments(1)).toFile(); // URL projectOutputUrl; // projectOutputUrl = projectFilePath.toURL(); // // if (projectDependencyUrlList.contains(projectOutputUrl) == false) // { // projectDependencyUrlList.add(projectOutputUrl); // } } URL[] arrayList = new URL[projectDependencyUrlList.size()]; URL[] returnURLArray = projectDependencyUrlList.toArray(arrayList); return returnURLArray; }
From source file:org.ebayopensource.vjet.eclipse.core.PiggyBackClassPathUtil.java
License:Open Source License
public static List<IBuildpathEntry> fetchBuildEntryFromJavaProject(IJavaProject javaProject) { // Project entry List<IBuildpathEntry> vEntries = new ArrayList<IBuildpathEntry>(); List<String> duplicateChecker = new ArrayList<String>(); IClasspathEntry[] entries2;/* w ww . j ava2 s .co m*/ try { entries2 = javaProject.getRawClasspath(); } catch (JavaModelException e) { VjetPlugin.error("Failed to resolve Java prjoect classpath: " + javaProject.getElementName(), e, IStatus.WARNING); return Collections.emptyList(); } for (IClasspathEntry entry : entries2) { IPath path = entry.getPath(); String sPath = path.toString(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_LIBRARY: addEntryToVJETEntry(entry, vEntries, duplicateChecker); case IClasspathEntry.CPE_PROJECT: IResource subResource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); if (subResource != null && subResource.getType() == IResource.PROJECT) { addProjectEntry(entry.getPath(), vEntries, duplicateChecker); } break; case IClasspathEntry.CPE_CONTAINER: if (!JavaRuntime.JRE_CONTAINER.equals(path.segment(0))) { IClasspathContainer container; try { container = JavaCore.getClasspathContainer(path, javaProject); if (container != null) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { addEntryToVJETEntry(entries[i], vEntries, duplicateChecker); } } } catch (JavaModelException e) { VjetPlugin.error("Failed to resolve Java classpath container: " + sPath, e, IStatus.WARNING); } } break; default: break; } } return vEntries; }
From source file:org.eclipse.ajdt.internal.launching.LaunchConfigurationManagementUtils.java
License:Open Source License
/** * Update the aspect path for launch configurations relating to the given * project//from ww w.j av a2 s. c o m * * @param project - * the project * @param existingAspectPathEntries - * current aspect path * @param newAspectPathEntries - * new aspect path */ public static void updateAspectPaths(IJavaProject project, List existingAspectPathEntries, List newAspectPathEntries) { try { String projectName = project.getElementName(); List configs = getLaunchConfigsForProject(projectName); for (Iterator iter = configs.iterator(); iter.hasNext();) { ILaunchConfiguration configuration = (ILaunchConfiguration) iter.next(); IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(configuration); List entriesAsList = new ArrayList(Arrays.asList(entries)); for (Iterator iterator = existingAspectPathEntries.iterator(); iterator.hasNext();) { IClasspathEntry entryToRemove = ((CPListElement) iterator.next()).getClasspathEntry(); for (Iterator iterator2 = entriesAsList.iterator(); iterator2.hasNext();) { IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) iterator2.next(); if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) { if (entryToRemove.equals(entry.getClasspathEntry())) { iterator2.remove(); break; } } } } for (Iterator iterator = newAspectPathEntries.iterator(); iterator.hasNext();) { IClasspathEntry newEntry = ((CPListElement) iterator.next()).getClasspathEntry(); if (newEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { entriesAsList.add(new RuntimeClasspathEntry(newEntry)); } else { IClasspathContainer container = JavaCore.getClasspathContainer(newEntry.getPath(), project); if (container != null) { IClasspathEntry[] containerEntries = container.getClasspathEntries(); for (int i = 0; i < containerEntries.length; i++) { entriesAsList.add(new RuntimeClasspathEntry(containerEntries[i])); } } } } IRuntimeClasspathEntry[] updatedEntries = (IRuntimeClasspathEntry[]) entriesAsList .toArray(new IRuntimeClasspathEntry[0]); updateConfigurationClasspath(configuration, updatedEntries); } } catch (CoreException cEx) { AJLog.log(cEx.getMessage()); } }
From source file:org.eclipse.ajdt.internal.launching.LaunchConfigurationManagementUtils.java
License:Open Source License
/** * Update the outjar for launch configurations relating to the given * project/* ww w . ja v a 2s.co m*/ * * @param project - * the project * @param oldOutJar - * current output jar, or null if none exists * @param newOutJar - * new output jar or null if none exists */ public static void updateOutJar(IJavaProject project, IClasspathEntry oldOutJar, IClasspathEntry newOutJar) { try { String projectName = project.getElementName(); List configs = getLaunchConfigsForProject(projectName); for (Iterator iter = configs.iterator(); iter.hasNext();) { ILaunchConfiguration configuration = (ILaunchConfiguration) iter.next(); IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(configuration); List entriesAsList = new ArrayList(Arrays.asList(entries)); if (oldOutJar != null) { for (Iterator iterator2 = entriesAsList.iterator(); iterator2.hasNext();) { IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) iterator2.next(); if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) { if (oldOutJar.equals(entry.getClasspathEntry())) { iterator2.remove(); break; } } } } if (newOutJar != null) { entriesAsList.add(new RuntimeClasspathEntry(newOutJar)); } IRuntimeClasspathEntry[] updatedEntries = (IRuntimeClasspathEntry[]) entriesAsList .toArray(new IRuntimeClasspathEntry[0]); updateConfigurationClasspath(configuration, updatedEntries); } } catch (CoreException cEx) { AJLog.log(cEx.getMessage()); } }
From source file:org.eclipse.ajdt.internal.ui.ajdocexport.AJdocWizard.java
License:Open Source License
private void setAllJavadocLocations(IJavaProject[] projects, URL newURL) { Shell shell = getShell();//w ww.ja v a2 s .com Image image = shell == null ? null : shell.getDisplay().getSystemImage(SWT.ICON_QUESTION); String[] buttonlabels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL }; for (int j = 0; j < projects.length; j++) { IJavaProject iJavaProject = projects[j]; // AspectJ Extension - message String message = Messages.format(JavadocExportMessages.JavadocWizard_updatejavadoclocation_message, new String[] { iJavaProject.getElementName(), fDestination.toOSString() }); MessageDialog dialog = new MessageDialog(shell, JavadocExportMessages.JavadocWizard_updatejavadocdialog_label, image, message, 4, buttonlabels, 1); switch (dialog.open()) { case YES: JavaUI.setProjectJavadocLocation(iJavaProject, newURL); break; case YES_TO_ALL: for (int i = j; i < projects.length; i++) { iJavaProject = projects[i]; JavaUI.setProjectJavadocLocation(iJavaProject, newURL); j++; } break; case NO_TO_ALL: j = projects.length; break; case NO: default: break; } } }
From source file:org.eclipse.ajdt.internal.ui.refactoring.ITDRenameRefactoringProcessor.java
License:Open Source License
private RenameJavaElementDescriptor createDescriptor() { String project = null;/*from w w w.j av a2 s . c om*/ IJavaProject javaProject = itd.getJavaProject(); if (javaProject != null) project = javaProject.getElementName(); int flags = RefactoringDescriptor.STRUCTURAL_CHANGE; try { if (!Flags.isPrivate(itd.getFlags())) flags |= RefactoringDescriptor.MULTI_CHANGE; } catch (JavaModelException exception) { } final String description = Messages.format("Rename intertype declaration ''{0}''", BasicElementLabels.getJavaElementName(itd.getElementName())); final String header = Messages.format("Rename intertype declaration ''{0}'' to ''{1}''", new String[] { JavaElementLabels.getTextLabel(itd, JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName()) }); final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString(); // must start with an invalid refactoring ID since the constructor does a legality check.` final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory .createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD); ReflectionUtils.setPrivateField(RefactoringDescriptor.class, "fRefactoringId", descriptor, REFACTORING_ID); descriptor.setProject(project); descriptor.setDescription(description); descriptor.setComment(comment); descriptor.setFlags(flags); descriptor.setJavaElement(itd); descriptor.setNewName(getNewElementName()); descriptor.setUpdateReferences(updateReferences); return descriptor; }
From source file:org.eclipse.amp.amf.ide.LaunchConfigTab.java
License:Open Source License
private void handleProjectButtonSelected() { IJavaProject project = chooseJavaProject(); if (project == null) { return;/*from www.j a v a 2s.c o m*/ } String projectName = project.getElementName(); projText.setText(projectName); }
From source file:org.eclipse.andmore.internal.launch.junit.AndroidJUnitLaunchConfigurationTab.java
License:Open Source License
/** * Show a dialog that lists all main types *//*w w w. j av a 2 s.co m*/ private void handleSearchButtonSelected() { Shell shell = getShell(); IJavaProject javaProject = getJavaProject(); IType[] types = new IType[0]; boolean[] radioSetting = new boolean[2]; try { // fix for Eclipse bug 66922 Wrong radio behaviour when switching // remember the selected radio button radioSetting[0] = mTestRadioButton.getSelection(); radioSetting[1] = mTestContainerRadioButton.getSelection(); types = TestSearchEngine.findTests(getLaunchConfigurationDialog(), javaProject, getTestKind()); } catch (InterruptedException e) { setErrorMessage(e.getMessage()); return; } catch (InvocationTargetException e) { AndmoreAndroidPlugin.log(e.getTargetException(), "Error finding test types"); //$NON-NLS-1$ return; } finally { mTestRadioButton.setSelection(radioSetting[0]); mTestContainerRadioButton.setSelection(radioSetting[1]); } SelectionDialog dialog = new TestSelectionDialog(shell, types); dialog.setTitle(JUnitMessages.JUnitLaunchConfigurationTab_testdialog_title); dialog.setMessage(JUnitMessages.JUnitLaunchConfigurationTab_testdialog_message); if (dialog.open() == Window.CANCEL) { return; } Object[] results = dialog.getResult(); if ((results == null) || (results.length < 1)) { return; } IType type = (IType) results[0]; if (type != null) { mTestText.setText(type.getFullyQualifiedName('.')); javaProject = type.getJavaProject(); mProjText.setText(javaProject.getElementName()); } }
From source file:org.eclipse.buildship.core.workspace.internal.GradleClasspathContainerInitializer.java
License:Open Source License
/** * Looks up the {@link OmniEclipseProject} for the target project, takes all external Jar * dependencies and assigns them to the classpath container with id * {@link ClasspathDefinition#GRADLE_CLASSPATH_CONTAINER_ID}. *///from w w w . jav a2 s. c o m @Override public void initialize(final IPath containerPath, final IJavaProject project) throws CoreException { new Job("Initialize Gradle classpath for project '" + project.getElementName() + "'") { // todo (etst) review job creation @Override protected IStatus run(IProgressMonitor monitor) { try { internalInitialize(containerPath, project); return Status.OK_STATUS; } catch (Exception e) { // TODO (donat) add a marker describing the problem String message = String.format("Failed to initialize Gradle classpath for project %s.", project.getProject()); CorePlugin.logger().error(message, e); return new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, message, e); } } }.schedule(); }