List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot K_BINARY
int K_BINARY
To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_BINARY.
Click Source Link
From source file:fr.obeo.ariadne.ide.connector.java.internal.explorer.JavaExplorer.java
License:Open Source License
/** * Explores the given package located in the given classpath entry of the currently analyzed Java project * in order to extract Ariadne concept./*from ww w . j a va2 s. com*/ * * @param classpathEntry * The classpath entry * @param iPackageFragment * The package * @param monitor * The progress monitor */ private void explorePackage(ClasspathEntry classpathEntry, IPackageFragment iPackageFragment, IProgressMonitor monitor) { try { // Find or create matching types container TypesContainer typesContainer = null; List<TypesContainer> typesContainers = classpathEntry.getTypesContainers(); for (TypesContainer aTypesContainer : typesContainers) { if (aTypesContainer.getName().equals(iPackageFragment.getElementName())) { typesContainer = aTypesContainer; break; } } if (typesContainer == null) { typesContainer = CodeFactory.eINSTANCE.createTypesContainer(); typesContainer.setName(iPackageFragment.getElementName()); classpathEntry.getTypesContainers().add(typesContainer); } String attachedJavadoc = iPackageFragment.getAttachedJavadoc(monitor); typesContainer.setDescription(attachedJavadoc); if (iPackageFragment.getKind() == IPackageFragmentRoot.K_BINARY) { IClassFile[] classFiles = iPackageFragment.getClassFiles(); for (IClassFile iClassFile : classFiles) { this.exploreType(iClassFile.getType(), typesContainer, monitor); } } else if (iPackageFragment.getKind() == IPackageFragmentRoot.K_SOURCE) { ICompilationUnit[] compilationUnits = iPackageFragment.getCompilationUnits(); for (ICompilationUnit iCompilationUnit : compilationUnits) { IType[] allTypes = iCompilationUnit.getAllTypes(); for (IType iType : allTypes) { Type type = this.exploreType(iType, typesContainer, monitor); IResource resource = iType.getResource(); IProject project = resource.getProject(); if (RepositoryProvider.isShared(project)) { RepositoryProvider provider = RepositoryProvider.getProvider(project); IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider(); IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(resource, IFileHistoryProvider.NONE, monitor); IFileRevision[] fileRevisions = fileHistory.getFileRevisions(); for (IFileRevision iFileRevision : fileRevisions) { String identifier = iFileRevision.getContentIdentifier(); List<Repository> repositories = this.ariadneProject.getRepositories(); for (Repository repository : repositories) { List<Commit> commits = repository.getCommits(); for (Commit commit : commits) { if (commit.getId().equals(identifier)) { // Link the commit to the type created List<ResourceChange> resourceChanges = commit.getResourceChanges(); for (ResourceChange resourceChange : resourceChanges) { if (resourceChange.getPath() .equals(iFileRevision.getURI().toString()) || resourceChange.getPath() .endsWith(resource.getFullPath().toString())) { resourceChange.setVersionedElement(type); } } } } } } } } } } } catch (JavaModelException e) { e.printStackTrace(); } }
From source file:net.officefloor.eclipse.classpath.ClasspathUtil.java
License:Open Source License
/** * Opens the class path resource./*from w ww . j a v a 2 s.c o m*/ * * @param resourcePath * Path to the resource on the class path. * @param editor * {@link AbstractOfficeFloorEditor} opening the resource. */ public static void openClasspathResource(String resourcePath, AbstractOfficeFloorEditor<?, ?> editor) { // Extensions final String CLASS_EXTENSION = ".class"; final String SOURCE_EXTENSION = ".java"; try { // Obtain the package and resource name int index = resourcePath.lastIndexOf('/'); String packageName = (index < 0 ? "" : resourcePath.substring(0, index)).replace('/', '.'); String resourceName = (index < 0 ? resourcePath : resourcePath.substring(index + 1)); // +1 // to // skip // separator // Obtain the java project IJavaProject project = JavaCore.create(ProjectConfigurationContext.getProject(editor.getEditorInput())); // Iterate over the fragment roots searching for the file for (IPackageFragmentRoot root : project.getAllPackageFragmentRoots()) { // Attempt to obtain the package IPackageFragment packageFragment = root.getPackageFragment(packageName); if (!packageFragment.exists()) { continue; // must have package } // Handle if a java or class file if (JavaCore.isJavaLikeFileName(resourceName) || resourceName.endsWith(CLASS_EXTENSION)) { // Handle based on kind of fragment root int rootKind = root.getKind(); switch (rootKind) { case IPackageFragmentRoot.K_BINARY: // Binary, so ensure extension is class if (resourceName.endsWith(SOURCE_EXTENSION)) { resourceName = resourceName.replace(SOURCE_EXTENSION, CLASS_EXTENSION); } // Attempt to obtain and open the class file IClassFile classFile = packageFragment.getClassFile(resourceName); if (classFile != null) { openEditor(editor, classFile); return; // opened } break; case IPackageFragmentRoot.K_SOURCE: // Source, so ensure extension is java if (resourceName.endsWith(CLASS_EXTENSION)) { resourceName = resourceName.replace(CLASS_EXTENSION, SOURCE_EXTENSION); } // Attempt to obtain the compilation unit (source file) ICompilationUnit sourceFile = packageFragment.getCompilationUnit(resourceName); if (sourceFile != null) { openEditor(editor, sourceFile); return; // opened } break; default: throw new IllegalStateException("Unknown package fragment root kind: " + rootKind); } } else { // Not java file, so open as resource for (Object nonJavaResource : packageFragment.getNonJavaResources()) { // Should only be opening files if (nonJavaResource instanceof IFile) { IFile file = (IFile) nonJavaResource; // Determine if the file looking for if (resourceName.equals(file.getName())) { // Found file to open, so open openEditor(editor, file); return; } } else { // Unknown resource type throw new IllegalStateException( "Unkown resource type: " + nonJavaResource.getClass().getName()); } } } } // Unable to open as could not find MessageDialog.openWarning(editor.getEditorSite().getShell(), "Open", "Could not find: " + resourcePath); } catch (Throwable ex) { // Failed to open file MessageDialog.openInformation(editor.getEditorSite().getShell(), "Open", "Failed to open '" + resourcePath + "': " + ex.getMessage()); } }
From source file:net.sf.spindle.core.util.eclipse.JarEntryFileUtil.java
License:Mozilla Public License
private static IPackageFragmentRoot getPackageFragmentRoot(IJavaProject project, JarEntryFile entry, boolean includeOtherProjects) throws CoreException { String path = getJarPath(entry); IPackageFragmentRoot[] roots = includeOtherProjects ? project.getAllPackageFragmentRoots() : project.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() != IPackageFragmentRoot.K_BINARY) continue; if (((JarPackageFragmentRoot) roots[i]).getJar().getName().equals(path)) { return roots[i]; }//from w ww . j a v a 2 s . c om } return null; }
From source file:net.sourceforge.metrics.calculators.RMartinCouplings.java
License:Open Source License
private void addPackagesInScope(IJavaProject project, List<IPackageFragment> scope) throws JavaModelException { IPackageFragment[] packages = project.getPackageFragments(); for (IPackageFragment package1 : packages) { if (package1.getKind() != IPackageFragmentRoot.K_BINARY) { scope.add(package1); }//from w w w . j av a 2s. co m } }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
/** * Adds a library/folder that already exists in the project to the * classpath. Only added if it is not already on the classpath. * * @param javaProject//w w w . j a v a 2 s . c o m * The project to add add the classpath entry to. * @param libraryPath * The path to add to the classpath. * @param isExported TODO * @throws JavaModelException */ public static void addLibraryToClasspath(final IJavaProject javaProject, final IPath libraryPath, boolean isExported) throws JavaModelException { boolean alreadyExists = includesClasspathEntry(javaProject, libraryPath.lastSegment()); if (alreadyExists) { return; } addClassPathEntry(javaProject, new ClasspathEntry(IPackageFragmentRoot.K_BINARY, IClasspathEntry.CPE_CONTAINER, libraryPath, ClasspathEntry.INCLUDE_ALL, // inclusion patterns ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, null, null, // specific output folder true, // exported ClasspathEntry.NO_ACCESS_RULES, false, // no access rules to // combine ClasspathEntry.NO_EXTRA_ATTRIBUTES)); }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static String toContentKind(String contentStr) { int content = 0; if (contentStr.equals("SOURCE")) { //$NON-NLS-1$ content = IPackageFragmentRoot.K_SOURCE; } else if (contentStr.equals("BINARY")) { //$NON-NLS-1$ content = IPackageFragmentRoot.K_BINARY; }/* w w w. j a va2 s . c o m*/ return new Integer(content).toString(); }
From source file:org.eclipse.ajdt.internal.launching.LaunchConfigurationClasspathUtils.java
License:Open Source License
/** * @param project//from w ww . jav a 2 s.c om * @return */ private static IRuntimeClasspathEntry getOutJar(IProject project) { String outjar = AspectJCorePreferences.getProjectOutJar(project); if (outjar == null || outjar.equals("")) { //$NON-NLS-1$ return null; } org.eclipse.jdt.core.IClasspathEntry entry = new org.eclipse.jdt.internal.core.ClasspathEntry( IPackageFragmentRoot.K_BINARY, // content kind org.eclipse.jdt.core.IClasspathEntry.CPE_LIBRARY, // entry kind new Path(project.getName() + '/' + outjar).makeAbsolute(), // path new IPath[] {}, // inclusion patterns new IPath[] {}, // exclusion patterns null, // src attachment path null, // src attachment root path null, // output location false, // is exported ? null, //accessRules false, //combine access rules? new IClasspathAttribute[0] // extra attributes? ); return new RuntimeClasspathEntry(entry); }
From source file:org.eclipse.ajdt.internal.ui.AspectJProjectPropertiesPage.java
License:Open Source License
private boolean commit() { // ignore changes to .classpath that occur during commits thisProject.getWorkspace().removeResourceChangeListener(fListener); // update the output jar try {/*from ww w. j a va 2 s.c o m*/ String oldOutJar = AspectJCorePreferences.getProjectOutJar(thisProject); IClasspathEntry oldEntry = null; if (oldOutJar != null && !oldOutJar.equals("")) { //$NON-NLS-1$ oldEntry = new org.eclipse.jdt.internal.core.ClasspathEntry(IPackageFragmentRoot.K_BINARY, // content kind IClasspathEntry.CPE_LIBRARY, // entry kind new Path(thisProject.getName() + '/' + oldOutJar).makeAbsolute(), // path new IPath[] {}, // inclusion patterns new IPath[] {}, // exclusion patterns null, // src attachment path null, // src attachment root path null, // output location false, // is exported ? null, //accessRules false, //combine access rules? new IClasspathAttribute[0] // extra attributes? ); } String outJar = outputJarEditor.getStringValue(); IClasspathEntry newEntry = null; if (outJar != null && !outJar.equals("")) { //$NON-NLS-1$ newEntry = new org.eclipse.jdt.internal.core.ClasspathEntry(IPackageFragmentRoot.K_BINARY, // content kind IClasspathEntry.CPE_LIBRARY, // entry kind new Path(thisProject.getName() + '/' + outJar).makeAbsolute(), // path new IPath[] {}, // inclusion patterns new IPath[] {}, // exclusion patterns null, // src attachment path null, // src attachment root path null, // output location false, // is exported ? null, //accessRules false, //combine access rules? new IClasspathAttribute[0] // extra attributes? ); } if (checkIfOnInpath(thisProject, outJar) || checkIfOnAspectpath(thisProject, outJar)) { MessageDialog.openInformation(getShell(), UIMessages.buildpathwarning_title, UIMessages.buildConfig_invalidOutjar); outputJarEditor.setStringValue(oldOutJar); } else { LaunchConfigurationManagementUtils.updateOutJar(JavaCore.create(thisProject), oldEntry, newEntry); AspectJCorePreferences.setProjectOutJar(thisProject, outputJarEditor.getStringValue()); } if (fInPathBlock != null && fInPathBlock.hasChangesInDialog()) { new ConfigurePathBlockJob(fInPathBlock).schedule(); getSettings().put(INDEX, fInPathBlock.getPageIndex()); // set the inpath's output folder // we should only be setting the out path if it is different // from the default // probably should do more checking on this, but hold off for now. AspectJCorePreferences.setProjectInpathOutFolder(getProject(), fInPathBlock.getOutputFolder()); } if (fAspectPathBlock != null && fAspectPathBlock.hasChangesInDialog()) { new ConfigurePathBlockJob(fAspectPathBlock).schedule(); getSettings().put(INDEX, fAspectPathBlock.getPageIndex()); } AJDTUtils.refreshPackageExplorer(); initializeTimeStamps(); return true; } finally { // now we care about resource changes again thisProject.getWorkspace().addResourceChangeListener(fListener); } }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java
License:Open Source License
private void exportResource(IProgressMonitor progressMonitor, IPackageFragmentRoot pkgRoot, boolean isInJavaProject, IResource resource, IPath destinationPath, boolean isInOutputFolder) { // Handle case where META-INF/MANIFEST.MF is part of the exported files if (fJarPackage.areClassFilesExported() && destinationPath.toString().equals("META-INF/MANIFEST.MF")) {//$NON-NLS-1$ if (fJarPackage.isManifestGenerated()) addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_didNotAddManifestToJar, resource.getFullPath()), null); return;/*from w w w . j av a 2s.co m*/ } boolean isNonJavaResource = !isInJavaProject || pkgRoot == null; boolean isInClassFolder = false; try { isInClassFolder = pkgRoot != null && !pkgRoot.isArchive() && pkgRoot.getKind() == IPackageFragmentRoot.K_BINARY; } catch (JavaModelException ex) { addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_cantGetRootKind, resource.getFullPath()), ex); } if ((fJarPackage.areClassFilesExported() && ((isNonJavaResource || (pkgRoot != null && !isJavaFile(resource) && !isClassFile(resource))) || isInClassFolder && isClassFile(resource))) || (fJarPackage.areJavaFilesExported() && (isNonJavaResource || (pkgRoot != null && !isClassFile(resource)) || (isInClassFolder && isClassFile(resource) && !fJarPackage.areClassFilesExported())))) { try { progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); fJarWriter.write((IFile) resource, destinationPath); } catch (CoreException ex) { Throwable realEx = ex.getStatus().getException(); if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$ addWarning(ex.getMessage(), realEx); else addToStatus(ex); } } }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarManifestWizardPage.java
License:Open Source License
/** * Creates a selection dialog that lists all packages under the given package * fragment root./*from w ww. j a va 2 s .c om*/ * The caller is responsible for opening the dialog with <code>Window.open</code>, * and subsequently extracting the selected packages (of type * <code>IPackageFragment</code>) via <code>SelectionDialog.getResult</code>. * * @param packageFragments the package fragments * @return a new selection dialog */ protected SelectionDialog createPackageDialog(Set packageFragments) { List packages = new ArrayList(packageFragments.size()); for (Iterator iter = packageFragments.iterator(); iter.hasNext();) { IPackageFragment fragment = (IPackageFragment) iter.next(); boolean containsJavaElements = false; int kind; try { kind = fragment.getKind(); containsJavaElements = fragment.getChildren().length > 0; } catch (JavaModelException ex) { ExceptionHandler.handle(ex, getContainer().getShell(), JarPackagerMessages.JarManifestWizardPage_error_jarPackageWizardError_title, Messages.format( JarPackagerMessages.JarManifestWizardPage_error_jarPackageWizardError_message, fragment.getElementName())); continue; } if (kind != IPackageFragmentRoot.K_BINARY && containsJavaElements) packages.add(fragment); } StandardJavaElementContentProvider cp = new StandardJavaElementContentProvider() { public boolean hasChildren(Object element) { // prevent the + from being shown in front of packages return !(element instanceof IPackageFragment) && super.hasChildren(element); } }; ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getContainer().getShell(), new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), cp); dialog.setDoubleClickSelects(false); dialog.setInput(JavaCore.create(JavaPlugin.getWorkspace().getRoot())); dialog.addFilter(new EmptyInnerPackageFilter()); dialog.addFilter(new LibraryFilter()); dialog.addFilter(new SealPackagesFilter(packages)); dialog.setValidator(new ISelectionStatusValidator() { public IStatus validate(Object[] selection) { StatusInfo res = new StatusInfo(); for (int i = 0; i < selection.length; i++) { if (!(selection[i] instanceof IPackageFragment)) { res.setError(JarPackagerMessages.JarManifestWizardPage_error_mustContainPackages); return res; } } res.setOK(); return res; } }); return dialog; }