List of usage examples for org.eclipse.jdt.core IJavaProject exists
boolean exists();
From source file:org.fusesource.ide.branding.wizards.NewCamelTestWizardPageOne.java
License:Open Source License
/** * Initialized the page with the current selection * /* www . j a v a2s . co m*/ * @param selection * The selection */ public void init(IStructuredSelection selection) { IJavaElement elem = getInitialJavaElement(selection); IJavaProject jproject = elem.getJavaProject(); IPackageFragmentRoot testRoot = null; if (selection != null && !selection.isEmpty()) { Object selectedElement = selection.getFirstElement(); IFile ifile = null; if (selectedElement instanceof IFile) { ifile = (IFile) selectedElement; } else if (selectedElement instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) selectedElement; ifile = (IFile) adaptable.getAdapter(IFile.class); } if (ifile != null) { setXmlFileUnderTest(ifile); } // now we determine the container for the test classes if (jproject != null && jproject.exists()) { try { IPackageFragmentRoot[] roots = jproject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { if (roots[i].getPath().toFile().getPath() .contains(String.format("src%stest%sjava", File.separator, File.separator))) { testRoot = roots[i]; break; } else if (roots[i].getPath().toFile().getPath() .contains(String.format("src%stest%sscala", File.separator, File.separator))) { testRoot = roots[i]; // we will prefer the src/test/java folder, so we don't break here and search for it } } } } catch (Exception ex) { Activator.getLogger().error(ex); } } } if (elem != null) { initContainerPage(elem); // if we found a suitable test class container then we set it here if (testRoot != null) { // set the container correctly setPackageFragmentRoot(testRoot, true); } IJavaProject project = elem.getJavaProject(); resourceContainer = project.getProject(); // evaluate the enclosing type IPackageFragment pack = (IPackageFragment) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT); if (pack != null) { setPackageFragment(pack, true); } else { File testFolderFile = project.getProject().getParent().getRawLocation() .append(getPackageFragmentRoot().getPath().makeRelative()).toFile(); File f = getBasePackage(testFolderFile); if (f != null && testRoot != null) { IPath p = new Path(f.getPath()); p = p.makeRelativeTo(project.getProject().getParent().getRawLocation() .append(getPackageFragmentRoot().getPath().makeRelative())); String name = ""; StringTokenizer strTok = new StringTokenizer(p.toOSString(), File.separator); while (strTok.hasMoreTokens()) { String tok = strTok.nextToken(); if (name.trim().length() > 0) { name += "."; } name += tok; } try { IPackageFragment pf = testRoot.createPackageFragment(name, true, new NullProgressMonitor()); setPackageFragment(pf, true); } catch (Exception ex) { Activator.getLogger().error(ex); } } } if (fXmlFileUnderTest == null) { try { // if we have no file selected yet, lets see if there's a // single one available List<IFile> files = ResourceModelUtils.filter(resourceContainer, new org.fusesource.ide.foundation.core.util.Filter<IFile>() { @Override public boolean matches(IFile file) { if (Objects.equal(file.getFileExtension(), "xml")) { return camelXmlMatcher.matches(file); } return false; } }); if (files.size() == 1) { setXmlFileUnderTest(files.get(0)); } } catch (Exception e) { Activator.getLogger().error("Failed to search for Camel XML files: " + e, e); } } } setJUnit4(true, true); updateStatus(getStatusList()); }
From source file:org.fusesource.ide.branding.wizards.NewCamelTestWizardPageOne.java
License:Open Source License
private IType resolveClassNameToType(IJavaProject jproject, IPackageFragment pack, String classToTestName) throws JavaModelException { if (!jproject.exists()) { return null; }//from ww w .j av a 2 s .c o m IType type = jproject.findType(classToTestName); // search in current package if (type == null && pack != null && !pack.isDefaultPackage()) { type = jproject.findType(pack.getElementName(), classToTestName); } // search in java.lang if (type == null) { type = jproject.findType("java.lang", classToTestName); //$NON-NLS-1$ } return type; }
From source file:org.fusesource.ide.branding.wizards.NewCamelTestWizardPageOne.java
License:Open Source License
private void updateBuildPathMessage() { if (fLink == null || fLink.isDisposed()) { return;//from w w w. j a v a2 s .co m } String message = null; IPackageFragmentRoot root = getPackageFragmentRoot(); if (root != null) { IJavaProject project = root.getJavaProject(); if (project.exists()) { if (isJUnit4()) { if (!JUnitStubUtility.is50OrHigher(project)) { message = WizardMessages.NewCamelTestWizardPageOne_linkedtext_java5required; } } } } fLink.setVisible(message != null); fImage.setVisible(message != null); if (message != null) { fLink.setText(message); } }
From source file:org.fusesource.ide.branding.wizards.NewCamelTestWizardPageOne.java
License:Open Source License
/** * The method is called when the container has changed to validate if the * project is suited for the JUnit test class. Clients can override to * modify or remove that validation.//from www . j ava2s .co m * * @return the status of the validation */ protected IStatus validateIfJUnitProject() { JUnitStatus status = new JUnitStatus(); IPackageFragmentRoot root = getPackageFragmentRoot(); if (root != null) { try { IJavaProject project = root.getJavaProject(); if (project.exists()) { if (isJUnit4()) { if (!JUnitStubUtility.is50OrHigher(project)) { status.setError(WizardMessages.NewCamelTestWizardPageOne_error_java5required); return status; } if (project.findType(JUnitCorePlugin.JUNIT4_ANNOTATION_NAME) == null) { status.setWarning(WizardMessages.NewCamelTestWizardPageOne__error_junit4NotOnbuildpath); return status; } } else { if (project.findType(JUnitCorePlugin.TEST_SUPERCLASS_NAME) == null) { status.setWarning(WizardMessages.NewCamelTestWizardPageOne_error_junitNotOnbuildpath); return status; } } } } catch (JavaModelException e) { } } return status; }
From source file:org.fusesource.ide.camel.editor.globalconfiguration.beans.BeanConfigUtil.java
License:Open Source License
public String handleNoArgMethodBrowse(IProject project, String className, Shell shell) { if (project != null) { IJavaProject jproject = JavaCore.create(project); if (jproject.exists()) { try { return openNoArgMethodDialog(jproject, className, shell); } catch (JavaModelException e) { CamelEditorUIActivator.pluginLog().logError(e); }//from ww w .j av a 2s . c o m } } return null; }
From source file:org.fusesource.ide.camel.editor.globalconfiguration.beans.BeanConfigUtil.java
License:Open Source License
public String handlePublicNoArgMethodBrowse(IProject project, String className, Shell shell) { if (project != null) { IJavaProject jproject = JavaCore.create(project); if (jproject.exists()) { try { return openPublicNoArgMethodDialog(jproject, className, shell); } catch (JavaModelException e) { CamelEditorUIActivator.pluginLog().logError(e); }// w w w. j a v a2 s. c om } } return null; }
From source file:org.fusesource.ide.camel.editor.globalconfiguration.beans.BeanConfigUtil.java
License:Open Source License
public String handleVoidPublicNoArgMethodBrowse(IProject project, String className, Shell shell) { if (project != null) { IJavaProject jproject = JavaCore.create(project); if (jproject.exists()) { try { return openVoidPublicNoArgMethodDialog(jproject, className, shell); } catch (JavaModelException e) { CamelEditorUIActivator.pluginLog().logError(e); }// ww w . j a v a2 s . co m } } return null; }
From source file:org.fusesource.ide.camel.editor.globalconfiguration.beans.BeanConfigUtil.java
License:Open Source License
public String handleMethodBrowse(IProject project, String className, Shell shell) { if (project != null) { IJavaProject jproject = JavaCore.create(project); if (jproject.exists()) { try { return openMethodDialog(jproject, className, shell); } catch (JavaModelException e) { CamelEditorUIActivator.pluginLog().logError(e); }// w w w . j a v a 2 s.c o m } } return null; }
From source file:org.fusesource.ide.camel.editor.globalconfiguration.beans.BeanConfigUtil.java
License:Open Source License
public String handlePublicOrStaticMethodBrowse(IProject project, String className, Shell shell) { if (project != null) { IJavaProject jproject = JavaCore.create(project); if (jproject.exists()) { try { return openStaticOrPublicMethodDialog(jproject, className, shell); } catch (JavaModelException e) { CamelEditorUIActivator.pluginLog().logError(e); }//www . j av a2s.co m } } return null; }
From source file:org.fusesource.ide.camel.editor.globalconfiguration.beans.BeanConfigUtil.java
License:Open Source License
public String handlePublicAndStaticMethodBrowse(IProject project, String className, Shell shell) { if (project != null) { IJavaProject jproject = JavaCore.create(project); if (jproject.exists()) { try { return openStaticAndPublicMethodDialog(jproject, className, shell); } catch (JavaModelException e) { CamelEditorUIActivator.pluginLog().logError(e); }/* www .ja v a 2 s. c om*/ } } return null; }