List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getResource
IResource getResource();
From source file:org.hibernate.eclipse.console.test.project.LaunchConfigTestProject.java
License:Open Source License
protected void buildProject() throws JavaModelException, CoreException, IOException { super.buildProject(); IPackageFragmentRoot tst = createFolder(TEST_TMP_OUT_FOLDER); tst.getResource().refreshLocal(IResource.DEPTH_INFINITE, null); importLaunchConfigFileToProject(LAUNCH_TEST_FILE_0); importLaunchConfigFileToProject(LAUNCH_TEST_FILE_1); }
From source file:org.hibernate.eclipse.console.test.project.LaunchConfigTestProject2.java
License:Open Source License
@SuppressWarnings("unused") protected void buildProject() throws JavaModelException, CoreException, IOException { super.buildProject(); IPackageFragmentRoot tst = createFolder(TEST_TMP_OUT_FOLDER); tst.getResource().refreshLocal(IResource.DEPTH_INFINITE, null); tst = createFolder(TEST_TMP_OUT_FOLDER_ALL_EXPORTERS_EXTERNAL); tst.getResource().refreshLocal(IResource.DEPTH_INFINITE, null); tst = createFolder(TEST_TMP_OUT_FOLDER_ALL_EXPORTERS_INTERNAL); tst.getResource().refreshLocal(IResource.DEPTH_INFINITE, null); ////from w w w . ja v a2s. c om importFileToProject(LAUNCH_CODE_GEN_TEST_FILE_ALL_EXPORTERS_EXTERN); importFileToProject(LAUNCH_CODE_GEN_TEST_FILE_ALL_EXPORTERS_INTERN); importFileToProject(LAUNCH_CODE_GEN_TEST_FILE_EXTERN); importFileToProject(LAUNCH_CODE_GEN_TEST_FILE_INTERN); importFileToProject(LAUNCH_CONSOLE_CONFIG_TEST_FILE); importFileToProject(HIBERNATE_CONSOLE_PROPERTIES_FILE); long startCopyFiles = System.currentTimeMillis(); IPackageFragmentRoot sourcePackageFragment = createSourceFolder(); long startCopyLibs = System.currentTimeMillis(); final File libFolder = getFolder(RESOURCE_LIB_PATH); List<IPath> libs = copyLibs(libFolder); final File libFolderHibernatePlugin = getHibernatePluginFolder(HIBERNATE_PLUGIN_LIB_PATH); List<IPath> libsHibernatePlugin = copyLibs(libFolderHibernatePlugin); libs.addAll(libsHibernatePlugin); long startBuild = System.currentTimeMillis(); generateClassPath(libs, sourcePackageFragment); setupSourceTestFolder(); // tst = createFolder(META_INF_FOLDER); importFileToProject(META_INF_FOLDER + File.separator + PERSISTENCE_XML_FILE); // fullBuild(); }
From source file:org.hibernate.eclipse.console.test.project.LaunchConfigTestProject2.java
License:Open Source License
public boolean setupSourceTestFolder() throws IOException, CoreException { ArrayList<String> foldersList = new ArrayList<String>(); File srcFolder = null;//from w ww .j a va 2s.c o m try { srcFolder = getFolder(RESOURCE_SRC_PATH); } catch (IOException e) { // ignore } if (srcFolder == null) { return false; } FilesTransfer.collectFoldersWithFiles(srcFolder, FilesTransfer.filterFilesJava, FilesTransfer.filterFolders, foldersList); IPath base = Path.fromOSString(srcFolder.getPath()); for (int i = 0; i < foldersList.size(); i++) { String str = foldersList.get(i); IPath path = Path.fromOSString(str); path = path.makeRelativeTo(base); foldersList.set(i, path.toOSString()); } for (int i = 0; i < foldersList.size(); i++) { FilesTransfer.delete(new File(project.getLocation().append(SRC_FOLDER).toOSString())); final String pack = foldersList.get(i); srcFolder = getFolder(RESOURCE_SRC_PATH + pack); IPackageFragmentRoot sourcePackageFragment = createFolder(SRC_FOLDER + File.separator + pack); FilesTransfer.copyFolder(srcFolder, (IFolder) sourcePackageFragment.getResource()); } return true; }
From source file:org.hibernate.eclipse.jdt.ui.test.JPAMapTest.java
License:Open Source License
protected void createTestProject() throws JavaModelException, CoreException, IOException { project = new TestProject(PROJECT_NAME); File resourceFolder = getResourceItem(RESOURCE_PATH); if (!resourceFolder.exists()) { String out = NLS.bind(ConsoleTestMessages.MappingTestProject_folder_not_found, RESOURCE_PATH); throw new RuntimeException(out); }//from w ww . ja v a2 s. c o m IPackageFragmentRoot sourceFolder = project.createSourceFolder(); FilesTransfer.copyFolder(resourceFolder, (IFolder) sourceFolder.getResource()); File resourceFolderLib = getResourceItem(TESTRESOURCE_PATH); if (!resourceFolderLib.exists()) { String out = NLS.bind(ConsoleTestMessages.MappingTestProject_folder_not_found, RESOURCE_PATH); throw new RuntimeException(out); } List<IPath> libs = project.copyLibs2(resourceFolderLib.getAbsolutePath()); project.generateClassPath(libs, sourceFolder); }
From source file:org.jboss.tools.cdi.ui.wizard.BeansXMLAccess.java
License:Open Source License
public void validate() { if (check == null) { return;//ww w . j av a2s . c o m } IPackageFragmentRoot p = page.getPackageFragmentRoot(); if (p != null && p.getResource().exists()) { String typeName = page.getPackageText() + "." + page.getTypeName(); IProject project = p.getResource().getProject(); boolean b = isRegisteredInBeansXML(project, typeName); check.composite.setEnabled(!b && isEnabled); } else { check.composite.setEnabled(isEnabled); } }
From source file:org.jboss.tools.common.model.ui.editor.ModelObjectStorageEditorInput.java
License:Open Source License
IJarEntryResource findJarEntryFile() { XModelObject o = object;/*from ww w . j a v a 2s. com*/ JarEntryFile f = null; JarEntryResource current = null; String packageName = ""; List<String> parts = new ArrayList<String>(); List<XModelObject> os = new ArrayList<XModelObject>(); while (o != null && o.getFileType() != XModelObject.SYSTEM) { String part = o.getFileType() == XModelObject.FILE ? FileAnyImpl.toFileName(o) : o.getFileType() == XModelObject.FOLDER ? o.getAttributeValue(XModelObjectConstants.ATTR_NAME) : null; if (part != null) { parts.add(0, part); os.add(0, o); if (f == null) { f = new JarEntryFile(part) { public InputStream getContents() throws CoreException { return storage.getContents(); } }; current = f; } else { if (packageName.length() > 0) { packageName = part + "." + packageName; } else { packageName = part; } JarEntryDirectory d = new JarEntryDirectory(part); current.setParent(d); current = d; } } o = o.getParent(); } // if(!(o instanceof JarSystemImpl)) return null; String file = Paths.expand(o.get(XModelObjectConstants.ATTR_NAME_LOCATION), o.getModel().getProperties()); IProject p = EclipseResourceUtil.getProject(o); IJavaProject jp = EclipseResourceUtil.getJavaProject(p); if (jp == null) return null; IPackageFragmentRoot root = null; try { IPackageFragmentRoot[] rs = jp.getAllPackageFragmentRoots(); for (IPackageFragmentRoot r : rs) { if (r.getResource() != null && r.getResource().exists() && r.getResource().getLocation().toString().equals(file)) { root = r; } else if (r.getPath() != null && r.getPath().toString().equals(file)) { root = r; } } } catch (CoreException e) { ModelUIPlugin.getDefault().logError(e); } if (root == null) { root = jp.getPackageFragmentRoot(file); } if (root == null) { return null; } if (current != null && !"META-INF".equalsIgnoreCase(current.getName()) && packageName.length() > 0) { IPackageFragment pf = root.getPackageFragment(packageName); f.setParent(pf); } else { current.setParent(root); if (!(o instanceof JarSystemImpl)) { Object q = root; NonJavaResource nj = null; for (int i = 0; i < parts.size(); i++) { IResource ri = (IResource) os.get(i).getAdapter(IResource.class); if (ri == null) { return f; } nj = new NonJavaResource(q, ri); q = nj; } if (nj != null) { return nj; } } } return f; }
From source file:org.jboss.tools.common.ui.widget.editor.SwtFieldEditorFactory.java
License:Open Source License
/** * @param buttonName/*from ww w . j ava2 s. c om*/ * @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; }
From source file:org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit.java
License:Open Source License
@Override protected void validateProperties(List<IMessage> messages, IReporter reporter) { String configFile = this.hibernateProperties.getConfigurationFile(); if (configFile != null && configFile.length() > 0) { IPath path = new Path(configFile); try {/*from ww w . j av a2 s .com*/ IJavaProject jp = getJpaProject().getJavaProject(); IPackageFragmentRoot[] pfrs = jp.getPackageFragmentRoots(); for (int i = 0; i < pfrs.length; i++) { if (pfrs[i].isArchive()) continue; if (((IContainer) pfrs[i].getResource()).findMember(path) != null) { return; } } } catch (JavaModelException e) { HibernateJptPlugin.logException(e); } IJavaProject jProject = getJpaProject().getJavaProject(); IResource res = null; if (jProject != null) { try { IPackageFragmentRoot[] allPackageFragmentRoots = jProject.getAllPackageFragmentRoots(); for (IPackageFragmentRoot iPackageFragmentRoot : allPackageFragmentRoots) { if (!iPackageFragmentRoot.isArchive()) { IResource sourceFolder = iPackageFragmentRoot.getResource(); if (sourceFolder instanceof IContainer) { IContainer folder = (IContainer) sourceFolder; if ((res = folder.findMember(path)) != null) { break; } } } } } catch (JavaModelException e) { //ignore } } if (res != null) { int resType = res.getType(); if (resType != IResource.FILE) { Property prop = getProperty(BasicHibernateProperties.HIBERNATE_CONFIG_FILE); IMessage message = HibernateJpaValidationMessage.buildMessage(IMessage.HIGH_SEVERITY, NOT_A_FILE, new String[] { configFile }, getResource()); message.setLineNo(prop.getValidationTextRange().getLineNumber()); messages.add(message); } } else { Property prop = getProperty(BasicHibernateProperties.HIBERNATE_CONFIG_FILE); IMessage message = HibernateJpaValidationMessage.buildMessage(IMessage.HIGH_SEVERITY, CONFIG_FILE_NOT_FOUND, new String[] { configFile }, getResource()); message.setLineNo(prop.getValidationTextRange().getLineNumber()); messages.add(message); } } }
From source file:org.jboss.tools.hibernate.jpt.ui.internal.persistence.details.HibernatePropertiesComposite.java
License:Open Source License
private IPath getConfigurationFilePath() { String filePath = cfgFile.getText().trim(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IFile[] files = root.findFilesForLocation(new Path(filePath)); IPath path = null;//from w w w.j a v a2 s .c o m if (files != null && files.length > 0) { path = new Path(files[0].getProject().getName()).append(files[0].getProjectRelativePath()); filePath = path.toString(); } if (filePath.length() > 0) { IPackageFragmentRoot[] allPackageFragmentRoots = getSourcePackageFragmentRoots(); for (IPackageFragmentRoot iPackageFragmentRoot : allPackageFragmentRoots) { IResource sourceFolder = iPackageFragmentRoot.getResource(); if (sourceFolder instanceof IContainer) { IContainer folder = (IContainer) sourceFolder; if (folder.findMember(filePath) != null) { return folder.findMember(filePath).getFullPath(); } } } } return path; }
From source file:org.jboss.tools.hibernate.jpt.ui.internal.persistence.details.HibernatePropertiesComposite.java
License:Open Source License
private Runnable createSetupAction() { return new Runnable() { @Override// www .ja v a2 s. c om public void run() { IPath initialPath = getConfigurationFilePath(); int defaultChoice = 0; if (initialPath != null) { defaultChoice = 1; } MessageDialog dialog = createSetupDialog( HibernateConsoleMessages.ConsoleConfigurationMainTab_setup_configuration_file, HibernateConsoleMessages.ConsoleConfigurationMainTab_do_you_want_to_create_new_cfgxml, defaultChoice); int answer = dialog.open(); IPath cfgFile = null; if (answer == 0) { // create new cfgFile = handleConfigurationFileCreate(); } else if (answer == 1) { // use existing cfgFile = handleConfigurationFileBrowse(); } if (cfgFile != null) { HibernatePropertiesComposite.this.cfgFile.setText(makeClassPathRelative(cfgFile).toString()); } } protected IPath makeClassPathRelative(IPath cfgFile) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource res = root.findMember(cfgFile); if (res != null && res.exists() && res.getType() == IResource.FILE) { IPackageFragmentRoot[] allPackageFragmentRoots = getSourcePackageFragmentRoots(); for (IPackageFragmentRoot iPackageFragmentRoot : allPackageFragmentRoots) { if (iPackageFragmentRoot.getResource().getFullPath().isPrefixOf(cfgFile)) { cfgFile = cfgFile.removeFirstSegments( iPackageFragmentRoot.getResource().getFullPath().segmentCount()); return cfgFile; } } } return res.getLocation(); } private MessageDialog createSetupDialog(String title, String question, int defaultChoice) { return new MessageDialog(getShell(), title, null, question, MessageDialog.QUESTION, new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_create_new, HibernateConsoleMessages.ConsoleConfigurationMainTab_use_existing, IDialogConstants.CANCEL_LABEL }, defaultChoice); } private IPath handleConfigurationFileBrowse() { IPath[] paths = chooseFileEntries(); if (paths != null && paths.length == 1) { return paths[0]; } return null; } public IPath[] chooseFileEntries() { TypedElementSelectionValidator validator = new TypedElementSelectionValidator( new Class[] { IFile.class }, false); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource focus = getConfigurationFilePath() != null ? root.findMember(getConfigurationFilePath()) : null; ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider() { public Object[] getElements(Object element) { IPackageFragmentRoot[] sourcePackageFragmentRoots = getSourcePackageFragmentRoots(); IResource[] ress = new IResource[sourcePackageFragmentRoots.length]; for (int i = 0; i < sourcePackageFragmentRoots.length; i++) { ress[i] = sourcePackageFragmentRoots[i].getResource(); } return ress; } }); dialog.setValidator(validator); dialog.setAllowMultiple(false); dialog.setTitle(HibernateConsoleMessages.ConsoleConfigurationMainTab_select_hibernate_cfg_xml_file); dialog.setMessage( HibernateConsoleMessages.ConsoleConfigurationMainTab_choose_file_to_use_as_hibernate_cfg_xml); dialog.addFilter(new FileFilter( new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_cfg_xml }, null, true, false)); dialog.setInput(root); dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); dialog.setInitialSelection(focus); if (dialog.open() == Window.OK) { Object[] elements = dialog.getResult(); IPath[] res = new IPath[elements.length]; for (int i = 0; i < res.length; i++) { IResource elem = (IResource) elements[i]; res[i] = elem.getFullPath(); } return res; } return null; } private IPath handleConfigurationFileCreate() { NewConfigurationWizard wizard = new NewConfigurationWizard(); wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY); IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); WizardDialog wdialog = new WizardDialog(win.getShell(), wizard); wdialog.create(); IWizardPage configPage = wizard .getPage(HibernateConsoleMessages.ConsoleConfigurationMainTab_wizard_page); if (configPage != null && configPage instanceof NewConfigurationWizardPage) { ((NewConfigurationWizardPage) configPage).setCreateConsoleConfigurationVisible(false); } // This opens a dialog if (wdialog.open() == Window.OK) { WizardNewFileCreationPage createdFilePath = ((WizardNewFileCreationPage) wizard .getStartingPage()); if (createdFilePath != null) { // createNewFile() does not creates new file if it was created by wizard (OK was pressed) return createdFilePath.createNewFile().getFullPath(); } } return null; } }; }