List of usage examples for org.eclipse.jdt.core IJavaProject getPackageFragmentRoots
IPackageFragmentRoot[] getPackageFragmentRoots() throws JavaModelException;
From source file:org.gw4e.eclipse.fwk.project.GW4EProject.java
License:Open Source License
public void assertHasSourceFolders(String[] folders) throws JavaModelException { IProject project = getRoot().getProject(this.projectName); IJavaProject jproject = JavaCore.create(project); IPackageFragmentRoot[] pkgs = jproject.getPackageFragmentRoots(); for (int i = 0; i < folders.length; i++) { String folder = folders[i]; boolean found = false; for (int j = 0; j < pkgs.length; j++) { IPackageFragmentRoot pkg = pkgs[j]; IPath path = new Path("/").append(this.projectName).append(folder); if (pkg.getPath().toString().equalsIgnoreCase(path.toString())) { found = true;//from w ww .j a va 2 s. co m } ; } assertTrue("Expected folder: " + folder, found); } }
From source file:org.hibernate.eclipse.jdt.ui.wizards.NewHibernateMappingFileWizard.java
License:Open Source License
@Override public boolean performFinish() { boolean res = true; if (page0.getSelection().isEmpty()) { final IFile file = cPage.createNewFile(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { doFinish(file, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done();//from w w w . jav a 2 s . co m } } }; try { getContainer().run(true, false, op); } catch (InterruptedException e) { res = false; } catch (InvocationTargetException e) { Throwable realException = e.getTargetException(); HibernateConsolePlugin.getDefault().showError(getShell(), HibernateConsoleMessages.NewReverseEngineeringFileWizard_error, realException); res = false; } cleanUpGenFolders(); } else { if (previewPage.getChange() == null) { Map<IJavaProject, IPath> places2Gen = getPlaces2Gen(); previewPage.setPlaces2Gen(places2Gen); } previewPage.performFinish(); // refresh Set<IJavaProject> projs = previewPage.getJavaProjects(); for (IJavaProject proj : projs) { try { IPackageFragmentRoot[] pfRoots = proj.getPackageFragmentRoots(); for (int i = 0; i < pfRoots.length; i++) { IResource container = pfRoots[i].getResource(); if (container != null && container.getType() != IResource.FILE) { container.refreshLocal(IResource.DEPTH_INFINITE, null); } } } catch (JavaModelException e) { HibernateConsolePlugin.getDefault().log(e); } catch (CoreException e) { HibernateConsolePlugin.getDefault().log(e); } } cleanUpGenFolders(); } return res; }
From source file:org.isoe.fwk.deployer.M2Handler.java
License:Open Source License
private void genJavaCodeSnippet(String packag1, String[] classNames_, String[] interfaceNames, String packag2, String className2, String interfaceName2) {// GenModel domainGenModel) { IPackageFragmentRoot srcFolder = null; IFile manifestFile = null;// w ww.ja v a 2 s.co m try { IJavaProject javaProject_ = JavaCore.create(project); if (javaProject_ == null) throw new RuntimeException("project is not a java project"); IPackageFragmentRoot[] roots = javaProject_.getPackageFragmentRoots(); for (int i = 0; i < roots.length && srcFolder == null; i++) if (!roots[i].isReadOnly()) srcFolder = roots[i]; manifestFile = project.getFile(JarFile.MANIFEST_NAME); if (srcFolder == null) throw new RuntimeException("Writable project root not found in the generated project"); if (!(manifestFile != null && manifestFile.exists())) throw new RuntimeException("Manifest was not generated"); runtimeWorkspaceSetup.getReadyToStartAsBundle(project); for (int k = 0; k < classNames_.length; k++) { generateClass(packag1, classNames_[k], interfaceNames[k], srcFolder); generateInterface(packag1, interfaceNames[k], srcFolder); } String[] exportedPackages = { packag1 }; runtimeWorkspaceSetup.exportPackages(project, exportedPackages); generateClass(packag2, className2, packag1 + "." + interfaceNames[0], srcFolder); generateInterface(packag2, interfaceName2, srcFolder); String[] exportedPackages2 = { packag2 }; runtimeWorkspaceSetup.exportPackages(project, exportedPackages2); runtimeWorkspaceSetup.removeExportJava(project); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("error in" + "fixInstanceClasses " + e.getMessage()); } }
From source file:org.isoe.fwk.megamodel.deploy.EmfHandler.java
License:Open Source License
private void fixInstanceClasses_(GenModel domainGenModel) { final Set<String> allInstanceClassNames = new HashSet<String>(); for (GenPackage nextPackage : domainGenModel.getGenPackages()) { for (GenClassifier nextGenClassifier : nextPackage.getGenClassifiers()) { if (nextGenClassifier.getEcoreClassifier() .eIsSet(EcorePackage.Literals.ECLASSIFIER__INSTANCE_CLASS_NAME)) { allInstanceClassNames.add(nextGenClassifier.getEcoreClassifier().getInstanceClassName()); }//from w ww . ja v a 2 s. c o m } } if (allInstanceClassNames.isEmpty()) return; IPackageFragmentRoot theRoot = null; IFile manifestFile = null; try { String pluginID = domainGenModel.getModelPluginID(); IProject pluginProject = getTargetProject(); IJavaProject javaProject = JavaCore.create(pluginProject); if (javaProject == null) throw new RuntimeException("Generated EMF model project is not a java project"); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length && theRoot == null; i++) if (!roots[i].isReadOnly()) theRoot = roots[i]; manifestFile = pluginProject.getFile(JarFile.MANIFEST_NAME); if (theRoot == null) throw new RuntimeException("Writable project root not found in the generated project"); if (!(manifestFile != null && manifestFile.exists())) throw new RuntimeException("Manifest was not generated"); Manifest manifest = new Manifest(manifestFile.getContents()); Attributes attributes = manifest.getMainAttributes(); StringBuffer exportedPackages = new StringBuffer(attributes.getValue(Constants.EXPORT_PACKAGE)); for (String instanceClassName : allInstanceClassNames) generateUserInterface(instanceClassName, theRoot, exportedPackages); attributes.putValue(Constants.EXPORT_PACKAGE, exportedPackages.toString()); ByteArrayOutputStream contents = new ByteArrayOutputStream(); manifest.write(contents); manifestFile.setContents(new ByteArrayInputStream(contents.toByteArray()), true, true, new NullProgressMonitor()); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("error in" + "fixInstanceClasses " + e.getMessage()); } }
From source file:org.jboss.ide.eclipse.as.wtp.core.vcf.OutputFoldersVirtualComponent.java
License:Open Source License
public static IPackageFragmentRoot[] getSourceContainers(IProject project) { IJavaProject jProject = JavaCore.create(project); if (jProject == null) return new IPackageFragmentRoot[0]; List<IPackageFragmentRoot> list = new ArrayList<IPackageFragmentRoot>(); IPackageFragmentRoot[] roots;//from w ww. j a va2s .c om try { roots = jProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() != IPackageFragmentRoot.K_SOURCE) continue; list.add(roots[i]); } } catch (JavaModelException jme) { } return list.toArray(new IPackageFragmentRoot[list.size()]); }
From source file:org.jboss.mapper.eclipse.internal.util.JavaUtil.java
License:Open Source License
/** * Returns the first resource folder in the project. If the project is a * maven project, the first resource folder configured will be used. * * @param project the Java project//w ww .ja v a2 s.c o m * * @return the resource root; may be null. */ public static IResource getFirstResourceRoot(IJavaProject project) { if (project == null) { return null; } try { IResource sourceRoot = null; for (IPackageFragmentRoot frag : project.getPackageFragmentRoots()) { if (frag.getKind() == IPackageFragmentRoot.K_SOURCE) { sourceRoot = frag.getUnderlyingResource(); break; } } return sourceRoot; } catch (JavaModelException e) { return null; } }
From source file:org.jboss.mapper.eclipse.internal.util.JavaUtil.java
License:Open Source License
/** * @param project//from w w w . j a v a 2 s . c o m * @return the root package for the supplied project */ public static IPackageFragmentRoot getFirstJavaSourceRoot(IJavaProject project) { if (project == null) { return null; } try { IPackageFragmentRoot sourceRoot = null; for (IPackageFragmentRoot frag : project.getPackageFragmentRoots()) { if (frag.getKind() == IPackageFragmentRoot.K_SOURCE) { sourceRoot = frag; break; } } return sourceRoot; } catch (JavaModelException e) { return null; } }
From source file:org.jboss.tools.batch.core.itest.PreferredPackageManagerTest.java
License:Open Source License
public void testPreferredPackageManager() throws JavaModelException { BatchArtifactType type = BatchArtifactType.BATCHLET; IBatchProject batchProject = BatchCorePlugin.getBatchProject(project, true); IJavaProject javaProject = EclipseUtil.getJavaProject(project); javaProject.getPackageFragmentRoots()[0].createPackageFragment("batch.artifact", true, new NullProgressMonitor()); PreferredPackageManager.savePreferredPackage(batchProject, type, TEST_PACKAGE_NAME); IPackageFragment suggestedPackageName = PreferredPackageManager.getPackageSuggestion(batchProject, type); assertEquals("Unexpected suggested package name", TEST_PACKAGE_NAME, suggestedPackageName.getPath().toString()); }
From source file:org.jboss.tools.common.model.util.EclipseResourceUtil.java
License:Open Source License
public static Set<IFolder> getSourceFolders(IProject project) { Set<IFolder> folders = new HashSet<IFolder>(); IPackageFragmentRoot[] roots;//w ww. ja v a2 s .c om try { // From source folders IJavaProject javaProject = EclipseUtil.getJavaProject(project); if (javaProject != null) { roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { IResource source = roots[i].getCorrespondingResource(); if (source instanceof IFolder) { folders.add((IFolder) source); } } } } } catch (JavaModelException e) { ModelPlugin.getDefault().logError(e); } return folders; }
From source file:org.jboss.tools.common.ui.widget.editor.SwtFieldEditorFactory.java
License:Open Source License
/** * @param buttonName//from w w w .j a v a 2 s . c o m * @return */ public ButtonFieldEditor.ButtonPressedAction createSelectSourceFolderAction(String buttonName, final String initPath) { ButtonFieldEditor.ButtonPressedAction action = new ButtonFieldEditor.ButtonPressedAction(buttonName) { private String inerInitPath; /* * (non-Javadoc) * @see org.eclipse.jface.action.Action#run() */ @Override public void run() { final ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog( Display.getCurrent().getActiveShell(), new JavaElementLabelProvider(), new JavaSourceContentProvider()); dialog.setInput(ResourcesPlugin.getWorkspace()); String path = inerInitPath != null ? inerInitPath : initPath; IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path); if (resource != null) { IProject project = resource.getProject(); if (project != null && project.isOpen()) { IJavaProject javaProject = EclipseUtil.getJavaProject(project); try { IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE && roots[i].getResource().equals(resource)) { dialog.setInitialSelection(roots[i]); break; } } } catch (JavaModelException e) { CommonUIPlugin.getDefault().logError(e); } } } dialog.setValidator(new ISelectionStatusValidator() { public IStatus validate(Object[] selection) { if (selection.length > 0) { if (selection[0] instanceof IPackageFragmentRoot) { return new Status(IStatus.OK, CommonUIPlugin.PLUGIN_ID, IStatus.OK, null, null); } } return new Status(IStatus.ERROR, CommonUIPlugin.PLUGIN_ID, IStatus.ERROR, null, null); } }); dialog.setAllowMultiple(false); dialog.setTitle(CommonUIMessages.SELECT_WORKSPACE_FOLDER_DIALOG_TITLE); dialog.setMessage(CommonUIMessages.SELECT_WORKSPACE_FOLDER_DIALOG_MESSAGE); if (dialog.open() == Window.OK) { IPackageFragmentRoot pack = (IPackageFragmentRoot) dialog.getFirstResult(); IPath newPath = pack.getResource().getFullPath(); String value = newPath.toString(); inerInitPath = value; getFieldEditor().setValue(value); } } }; return action; }