List of usage examples for org.eclipse.jdt.core IJavaProject findPackageFragmentRoots
IPackageFragmentRoot[] findPackageFragmentRoots(IClasspathEntry entry);
From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java
License:Open Source License
public static CPListElement create(Object parent, IClasspathEntry curr, boolean newElement, IJavaProject project) { IPath path = curr.getPath();//from w ww. jav a2 s . c o m IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // get the resource IResource res = null; boolean isMissing = false; IPath linkTarget = null; switch (curr.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: try { isMissing = project != null && (JavaCore.getClasspathContainer(path, project) == null); } catch (JavaModelException e) { isMissing = true; } break; case IClasspathEntry.CPE_VARIABLE: IPath resolvedPath = JavaCore.getResolvedVariablePath(path); isMissing = root.findMember(resolvedPath) == null && !resolvedPath.toFile().exists(); break; case IClasspathEntry.CPE_LIBRARY: res = root.findMember(path); if (res == null) { if (!ArchiveFileFilter.isArchivePath(path, true)) { if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK() && root.getProject(path.segment(0)).exists()) { res = root.getFolder(path); } } IPath rawPath = path; if (project != null) { IPackageFragmentRoot[] roots = project.findPackageFragmentRoots(curr); if (roots.length == 1) rawPath = roots[0].getPath(); } isMissing = !rawPath.toFile().exists(); // look for external JARs and folders } else if (res.isLinked()) { linkTarget = res.getLocation(); } break; case IClasspathEntry.CPE_SOURCE: path = path.removeTrailingSeparator(); res = root.findMember(path); if (res == null) { if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) { res = root.getFolder(path); } isMissing = true; } else if (res.isLinked()) { linkTarget = res.getLocation(); } break; case IClasspathEntry.CPE_PROJECT: res = root.findMember(path); isMissing = (res == null); break; } CPListElement elem = new CPListElement(parent, project, curr.getEntryKind(), path, newElement, res, linkTarget); elem.setExported(curr.isExported()); elem.setAttribute(SOURCEATTACHMENT, curr.getSourceAttachmentPath()); elem.setAttribute(OUTPUT, curr.getOutputLocation()); elem.setAttribute(EXCLUSION, curr.getExclusionPatterns()); elem.setAttribute(INCLUSION, curr.getInclusionPatterns()); elem.setAttribute(ACCESSRULES, curr.getAccessRules()); elem.setAttribute(COMBINE_ACCESSRULES, new Boolean(curr.combineAccessRules())); IClasspathAttribute[] extraAttributes = curr.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; CPListElementAttribute attribElem = elem.findAttributeElement(attrib.getName()); if (attribElem == null) { elem.createAttributeElement(attrib.getName(), attrib.getValue(), false); } else { attribElem.setValue(attrib.getValue()); } } elem.setIsMissing(isMissing); return elem; }
From source file:br.ufal.cideei.handlers.DoAnalysisOnClassPath.java
License:Open Source License
/** * Configures the classpath, sets up the transformers, load (jimplify) classes and run the packs. * // ww w. jav a2 s. c om * @param javaProject * @param entry * @param libs */ private void addPacks(IJavaProject javaProject, IClasspathEntry entry, String libs) { /* * if the classpath entry is "", then JDT will complain about it. */ String classPath; if (entry.getPath().toOSString().equals(File.separator + javaProject.getElementName())) { classPath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); } else { classPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath()).getLocation() .toOSString(); } SootManager.configure(classPath + File.pathSeparator + libs); System.out.println(classPath); IFeatureExtracter extracter = CIDEFeatureExtracterFactory.getInstance().getExtracter(); IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { IJavaElement[] children = null; try { children = packageFragmentRoot.getChildren(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (IJavaElement child : children) { IPackageFragment packageFragment = (IPackageFragment) child; ICompilationUnit[] compilationUnits = null; try { compilationUnits = packageFragment.getCompilationUnits(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (ICompilationUnit compilationUnit : compilationUnits) { String fragmentName = packageFragment.getElementName(); String compilationName = compilationUnit.getElementName(); StringBuilder qualifiedNameStrBuilder = new StringBuilder(fragmentName); // If it's the default package: if (qualifiedNameStrBuilder.length() == 0) { // Remove ".java" suffix qualifiedNameStrBuilder.append(compilationName.substring(0, compilationName.length() - 5)); } else { // Remove ".java" suffix qualifiedNameStrBuilder.append(".") .append(compilationName.substring(0, compilationName.length() - 5)); } // This goes into Soot loadAndSupport SootManager.loadAndSupport(qualifiedNameStrBuilder.toString()); } } } Scene.v().loadNecessaryClasses(); AlloyConfigurationCheck alloyConfigurationCheck = null; // #ifdef FEATUREMODEL //@ try { //@ String absolutePath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); //@ alloyConfigurationCheck = new AlloyConfigurationCheck(absolutePath + File.separator + "fm.als"); //@ } catch (CannotReadAlloyFileException e) { //@ e.printStackTrace(); //@ return; //@ } // #endif addPacks(classPath, extracter, alloyConfigurationCheck); SootManager.runPacks(extracter); }
From source file:br.ufal.cideei.handlers.DoFeatureObliviousAnalysisOnClassPath.java
License:Open Source License
private void addPacks(IJavaProject javaProject, IClasspathEntry entry, String libs) { /*//from ww w . jav a 2s. c o m * if the classpath entry is "", then JDT will complain about it. */ String classPath; if (entry.getPath().toOSString().equals(File.separator + javaProject.getElementName())) { classPath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); } else { classPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath()).getLocation() .toOSString(); } SootManager.configure(classPath + File.pathSeparator + libs); IFeatureExtracter extracter = CIDEFeatureExtracterFactory.getInstance().getExtracter(); IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { IJavaElement[] children = null; try { children = packageFragmentRoot.getChildren(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (IJavaElement child : children) { IPackageFragment packageFragment = (IPackageFragment) child; ICompilationUnit[] compilationUnits = null; try { compilationUnits = packageFragment.getCompilationUnits(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (ICompilationUnit compilationUnit : compilationUnits) { String fragmentName = packageFragment.getElementName(); String compilationName = compilationUnit.getElementName(); StringBuilder qualifiedNameStrBuilder = new StringBuilder(fragmentName); // If it's the default package: if (qualifiedNameStrBuilder.length() == 0) { // Remove ".java" suffix qualifiedNameStrBuilder.append(compilationName.substring(0, compilationName.length() - 5)); } else { // Remove ".java" suffix qualifiedNameStrBuilder.append(".") .append(compilationName.substring(0, compilationName.length() - 5)); } // This goes into Soot loadAndSupport SootManager.loadAndSupport(qualifiedNameStrBuilder.toString()); } } } Scene.v().loadNecessaryClasses(); AlloyConfigurationCheck alloyConfigurationCheck = null; // #ifdef FEATUREMODEL //@ try { //@ String absolutePath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); //@ alloyConfigurationCheck = new AlloyConfigurationCheck(absolutePath + File.separator + "fm.als"); //@ } catch (CannotReadAlloyFileException e) { //@ e.printStackTrace(); //@ return; //@ } // #endif addPacks(classPath, extracter, alloyConfigurationCheck); SootManager.runPacks(extracter); }
From source file:com.google.appengine.eclipse.webtools.facet.AbstractJpaFacetHelper.java
License:Open Source License
private static void copyJpaLibraryToWebInf(IJavaProject javaProject) throws CoreException, FileNotFoundException { IProject project = javaProject.getProject(); if (!WebAppUtilities.hasManagedWarOut(project)) { // Nothing to do if project war directory is not managed return;// w w w . j a v a2 s .c om } // Get WEB-INF/lib folder (create if it doesn't exist) IFolder webInfLibFolder = WebAppUtilities.getWebInfLib(project); ResourceUtils.createFolderStructure(project, webInfLibFolder.getProjectRelativePath()); // Copy jars to WEB-INF/lib List<IClasspathEntry> cpes = ClasspathUtil.getClasspathEntries(project, ProjectFacetsManager.getProjectFacet(FACET_JPT_JPA)); for (IClasspathEntry cpe : cpes) { for (IPackageFragmentRoot fragment : javaProject.findPackageFragmentRoots(cpe)) { File srcFile = fragment.getPath().toFile(); IFile destFile = webInfLibFolder.getFile(srcFile.getName()); if (!destFile.exists()) { destFile.create(new FileInputStream(srcFile), true, null); } } } }
From source file:com.iw.plugins.spindle.ui.widgets.TypeChooserWidget.java
License:Mozilla Public License
public void configure(final IJavaProject project, final IRunnableContext context) { try {//from w w w . j a v a2 s. c om final boolean baseIsInterface = fHierarchyRoot.isInterface(); fSearchResults = new ArrayList(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IJavaSearchScope scope = null; try { // we want to rip out the JRE entry as there's no chance of finding a tapestry class there. ArrayList roots = new ArrayList(); IClasspathEntry[] classpath = project.getRawClasspath(); for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath cpPath = classpath[i].getPath(); if (JavaRuntime.JRE_CONTAINER.equals(cpPath.segment(0))) continue; } roots.add(project.findPackageFragmentRoots(classpath[i])); } scope = SearchEngine.createJavaSearchScope( (IJavaElement[]) roots.toArray(new IJavaElement[roots.size()]), true); } catch (JavaModelException e1) { scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, true); } ISearchPattern pattern = SearchEngine.createSearchPattern("*", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, true); SearchEngine engine = new SearchEngine(); IJavaSearchResultCollector collector = new IJavaSearchResultCollector() { public void aboutToStart() { } public void accept(IResource resource, int start, int end, IJavaElement enclosingElement, int accuracy) throws CoreException { if (accuracy != EXACT_MATCH) return; if (enclosingElement.getElementType() != IJavaElement.TYPE) return; IType type = (IType) enclosingElement; System.out.println(type.getFullyQualifiedName()); if (baseIsInterface) { if (!CoreUtils.implementsInterface(type, fHierarchyRoot.getElementName())) return; } else { if (!CoreUtils.extendsType(type, fHierarchyRoot)) return; } System.out.println(type.getFullyQualifiedName()); fSearchResults.add(type); } public void done() { } public IProgressMonitor getProgressMonitor() { return monitor; } }; try { engine.search(ResourcesPlugin.getWorkspace(), pattern, scope, collector); } catch (JavaModelException e) { UIPlugin.log(e); } } }; context.run(false, true, runnable); } catch (InvocationTargetException e) { UIPlugin.log(e); } catch (InterruptedException e) { //do nothing; } catch (JavaModelException e) { UIPlugin.log(e); } }
From source file:com.iw.plugins.spindle.wizards.project.ApplicationWizardPage.java
License:Mozilla Public License
public void createApplicationResource(IJavaProject project, IProgressMonitor monitor) throws InterruptedException, CoreException { project.open(monitor);// www .j a v a 2 s . c o m NewProjectUtils.fixClasspath(project, monitor); String appname = fApplicationNameDialog.getTextValue(); IClasspathEntry srcEntry = fContainerDialogField.getClasspathEntry(); IPackageFragmentRoot root = project.findPackageFragmentRoots(srcEntry)[0]; String packageName = fPackageDialogField.getTextValue(); applicationPackage = root.createPackageFragment(packageName, true, monitor); String engineClass = MessageUtil.getString("TapestryEngine.defaultEngine"); application = ApplicationFactory.createApplication(root, applicationPackage, appname, engineClass, monitor); IPackageFragment homePageFragment = root .createPackageFragment(applicationPackage.getElementName() + ".pages", true, monitor); PageFactory.createPage(root, homePageFragment, "Home", "net.sf.tapestry.html.BasePage", monitor); ITapestryProject tproject = TapestryPlugin.getDefault().addTapestryProjectNatureTo(project, monitor); tproject.setProjectStorage(application); tproject.getModelManager().getReadOnlyModel(application); }
From source file:com.iw.plugins.spindle.wizards.project.ApplicationWizardPage.java
License:Mozilla Public License
public void createServletType(IJavaProject project, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, CoreException { if (fGenerateServletClass.getCheckBoxValue()) { IClasspathEntry srcEntry = fContainerDialogField.getClasspathEntry(); IPackageFragmentRoot root = project.findPackageFragmentRoots(srcEntry)[0]; String packageName = fServletPackageDialog.getTextValue(); IPackageFragment pack = root.createPackageFragment(packageName, true, monitor); String servletClass = fServletClassDialog.getTextValue(); IType servletSuperclass = project.findType("net.sf.tapestry.ApplicationServlet"); generatedServletType = ApplicationClassFactory.createClass(root, pack, servletClass, servletSuperclass, null, monitor);// w ww .ja v a 2 s . com populateMethodSource(generatedServletType, monitor); } }
From source file:com.iw.plugins.spindle.wizards.project.LibraryWizardPage.java
License:Mozilla Public License
public void createLibraryResource(IJavaProject project, IProgressMonitor monitor) throws InterruptedException, CoreException { project.open(monitor);// w ww . j a va 2 s . c om NewProjectUtils.fixClasspath(project, monitor); IClasspathEntry srcEntry = fContainerDialogField.getClasspathEntry(); IPackageFragmentRoot root = project.findPackageFragmentRoots(srcEntry)[0]; String packageName = fPackageDialogField.getTextValue(); IPackageFragment pack = root.createPackageFragment(packageName, true, monitor); String libname = fLibraryNameDialog.getTextValue(); library = LibraryFactory.createLibrary(root, pack, libname, monitor); ITapestryProject tproject = TapestryPlugin.getDefault().addTapestryProjectNatureTo(project, monitor); tproject.setProjectStorage(library); tproject.getModelManager().getReadOnlyModel(library); }
From source file:com.siteview.mde.internal.core.builders.SourceEntryErrorReporter.java
License:Open Source License
public void initialize(ArrayList sourceEntries, ArrayList outputEntries, IClasspathEntry[] cpes, IProject project) {// w ww . j a v a 2s.co m fProject = project; IPath defaultOutputLocation = null; IJavaProject javaProject = JavaCore.create(fProject); try { defaultOutputLocation = javaProject.getOutputLocation(); } catch (JavaModelException e) { } List pluginLibraryNames = new ArrayList(1); IMonitorModelBase pluginModel = MonitorRegistry.findModel(fProject); if (pluginModel != null) { IMonitorLibrary[] pluginLibraries = pluginModel.getMonitorBase().getLibraries(); for (int i = 0; i < pluginLibraries.length; i++) { pluginLibraryNames.add(pluginLibraries[i].getName()); } } if (!pluginLibraryNames.contains(".")) { //$NON-NLS-1$ pluginLibraryNames.add("."); //$NON-NLS-1$) } for (int i = 0; i < cpes.length; i++) { if (cpes[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = getPath(cpes[i]); if (sourcePath == null) continue; IPath outputLocation = cpes[i].getOutputLocation(); if (outputLocation == null) outputLocation = defaultOutputLocation; IPath outputPath = getPath(outputLocation); OutputFolder outputFolder = (OutputFolder) fOutputFolderMap.get(outputPath); if (outputFolder == null) { outputFolder = new OutputFolder(outputPath); } SourceFolder sourceFolder = (SourceFolder) fSourceFolderMap.get(sourcePath); if (sourceFolder == null) { sourceFolder = new SourceFolder(sourcePath, outputFolder); } outputFolder.addSourceFolder(sourceFolder); fOutputFolderMap.put(outputPath, outputFolder); fSourceFolderMap.put(sourcePath, sourceFolder); } else if (cpes[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IClasspathEntry entry = cpes[i]; IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry); IPath outputPath = null; if (roots.length == 1) { // should only be one entry for a library if (!roots[0].isArchive()) { outputPath = getPath(entry); OutputFolder outputFolder = new OutputFolder(outputPath, true); fOutputFolderMap.put(outputPath, outputFolder); } } } } for (Iterator iterator = sourceEntries.iterator(); iterator.hasNext();) { IBuildEntry sourceEntry = (IBuildEntry) iterator.next(); String libName = sourceEntry.getName().substring(PROPERTY_SOURCE_PREFIX.length()); if (!pluginLibraryNames.contains(libName)) { prepareError(sourceEntry.getName(), null, NLS.bind(MDECoreMessages.SourceEntryErrorReporter_MissingLibrary, libName), MDEMarkerFactory.B_REMOVAL, fSrcLibSeverity, MDEMarkerFactory.CAT_OTHER); } String[] tokens = sourceEntry.getTokens(); for (int i = 0; i < tokens.length; i++) { IPath path = new Path(tokens[i]).addTrailingSeparator(); SourceFolder sourceFolder = (SourceFolder) fSourceFolderMap.get(path); if (sourceFolder == null) { sourceFolder = new SourceFolder(path, null); fSourceFolderMap.put(path, sourceFolder); } sourceFolder.setToken(tokens[i]); sourceFolder.addLib(libName); } } for (Iterator iterator = outputEntries.iterator(); iterator.hasNext();) { IBuildEntry outputEntry = (IBuildEntry) iterator.next(); String libName = outputEntry.getName().substring(PROPERTY_OUTPUT_PREFIX.length()); if (!pluginLibraryNames.contains(libName)) { prepareError(outputEntry.getName(), null, NLS.bind(MDECoreMessages.SourceEntryErrorReporter_MissingLibrary, libName), MDEMarkerFactory.B_REMOVAL, fOututLibSeverity, MDEMarkerFactory.CAT_OTHER); } String[] tokens = outputEntry.getTokens(); for (int i = 0; i < tokens.length; i++) { IPath path = new Path(tokens[i]).addTrailingSeparator(); if (path.segmentCount() == 1 && path.segment(0).equals(".")) { //$NON-NLS-1$ // translate "." to root path path = Path.ROOT; } OutputFolder outputFolder = (OutputFolder) fOutputFolderMap.get(path); if (outputFolder == null) { outputFolder = new OutputFolder(path); fOutputFolderMap.put(path, outputFolder); } outputFolder.setToken(tokens[i]); outputFolder.addLib(libName); } } }
From source file:com.siteview.mde.internal.launching.launcher.LaunchArgumentsHelper.java
License:Open Source License
private static String getEquinoxStartupPath(String packageName) throws CoreException { IMonitorModelBase model = MonitorRegistry.findModel(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER); if (model != null) { IResource resource = model.getUnderlyingResource(); // found in the target if (resource == null) return model.getInstallLocation(); // find it in the workspace IProject project = resource.getProject(); if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject jProject = JavaCore.create(project); IClasspathEntry[] entries = jProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { int kind = entries[i].getEntryKind(); if (kind == IClasspathEntry.CPE_SOURCE || kind == IClasspathEntry.CPE_LIBRARY) { IPackageFragmentRoot[] roots = jProject.findPackageFragmentRoots(entries[i]); for (int j = 0; j < roots.length; j++) { if (roots[j].getPackageFragment(packageName).exists()) { // if source folder, find the output folder if (kind == IClasspathEntry.CPE_SOURCE) { IPath path = entries[i].getOutputLocation(); if (path == null) path = jProject.getOutputLocation(); path = path.removeFirstSegments(1); return project.getLocation().append(path).toOSString(); }/* w ww . j a v a 2 s . co m*/ // else if is a library jar, then get the location of the jar itself IResource jar = roots[j].getResource(); if (jar != null) { return jar.getLocation().toOSString(); } } } } } } } Bundle bundle = Platform.getBundle(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER); if (bundle != null) { try { URL url = FileLocator.resolve(bundle.getEntry("/")); //$NON-NLS-1$ url = FileLocator.toFileURL(url); String path = url.getFile(); if (path.startsWith("file:")) //$NON-NLS-1$ path = path.substring(5); path = new File(path).getAbsolutePath(); if (path.endsWith("!")) //$NON-NLS-1$ path = path.substring(0, path.length() - 1); return path; } catch (IOException e) { } } return null; }