List of usage examples for org.eclipse.jdt.core IJavaProject exists
boolean exists();
From source file:org.fusesource.ide.camel.editor.globalconfiguration.beans.BeanConfigUtil.java
License:Open Source License
public IJavaProject getJavaProject(IProject project) { if (project != null) { IJavaProject jproject = JavaCore.create(project); if (jproject.exists()) { return jproject; }/* ww w . ja v a 2s .c om*/ } return null; }
From source file:org.fusesource.ide.camel.editor.propertysheet.PropertiesUtils.java
License:Open Source License
public static IStatus validatePackageName(String text, IJavaProject project) { if (project == null || !project.exists()) { return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3); }/*from ww w.jav a 2s . c o m*/ return JavaConventionsUtil.validatePackageName(text, project); }
From source file:org.fusesource.ide.camel.model.service.core.util.CamelComponentUtils.java
License:Open Source License
private static String getComponentClassFromJar(IProject project, String scheme) { IJavaProject jpr = JavaCore.create(project); if (jpr.exists()) { try {//from w w w . j a va2 s. c o m IClasspathEntry[] resolvedClasspath = jpr.getResolvedClasspath(true); return getComponentClassFromClasspath(scheme, resolvedClasspath); } catch (JavaModelException ex) { CamelModelServiceCoreActivator.pluginLog().logError(ex); } } return null; }
From source file:org.fusesource.ide.camel.model.service.core.util.CamelComponentUtils.java
License:Open Source License
/** * returns the component class for the given scheme * * @param scheme//from ww w.j av a2 s . co m * @param project * @return the class or null if not found */ protected static String getComponentJSon(String scheme, IProject project) { IJavaProject jpr = JavaCore.create(project); if (jpr.exists()) { try { IClasspathEntry[] resolvedClasspath = jpr.getResolvedClasspath(true); return getComponentJSONFromClasspath(scheme, resolvedClasspath); } catch (JavaModelException ex) { CamelModelServiceCoreActivator.pluginLog().logError(ex); } } return null; }
From source file:org.grails.ide.eclipse.editor.groovy.elements.GrailsWorkspaceCore.java
License:Open Source License
public GrailsProject create(IProject project) { IJavaProject jProj = JavaCore.create(project); return jProj != null && jProj.exists() ? create(jProj) : null; }
From source file:org.grails.ide.eclipse.editor.gsp.translation.GSPTranslation.java
License:Open Source License
/** * Originally from ReconcileStepForJava. Creates an ICompilationUnit from the contents of the JSP document. * /* www .j a v a 2 s . c o m*/ * @return an ICompilationUnit from the contents of the JSP document */ private ICompilationUnit createCompilationUnit() throws JavaModelException { IPackageFragment packageFragment = null; IJavaElement je = getJavaProject(); if (je == null || !je.exists()) return null; switch (je.getElementType()) { case IJavaElement.PACKAGE_FRAGMENT: je = je.getParent(); // fall through case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) je; packageFragment = packageFragmentRoot.getPackageFragment(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH); break; case IJavaElement.JAVA_PROJECT: IJavaProject jProject = (IJavaProject) je; if (!jProject.exists()) { if (DEBUG) { System.out.println( "** Abort create working copy: cannot create working copy: JSP is not in a Java project"); //$NON-NLS-1$ } return null; } packageFragmentRoot = null; IPackageFragmentRoot[] packageFragmentRoots = jProject.getPackageFragmentRoots(); int i = 0; while (i < packageFragmentRoots.length) { if (!packageFragmentRoots[i].isArchive() && !packageFragmentRoots[i].isExternal()) { packageFragmentRoot = packageFragmentRoots[i]; break; } i++; } if (packageFragmentRoot == null) { if (DEBUG) { System.out.println( "** Abort create working copy: cannot create working copy: JSP is not in a Java project with source package fragment root"); //$NON-NLS-1$ } return null; } packageFragment = packageFragmentRoot.getPackageFragment(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH); break; default: return null; } // GRAILS CHANGE // create compilation unit with .groovy instead of .java file extension ICompilationUnit cu = packageFragment.getCompilationUnit(getClassname() + ".groovy") //$NON-NLS-1$ .getWorkingCopy(getWorkingCopyOwner(), getProgressMonitor()); // ICompilationUnit cu = packageFragment.getCompilationUnit(getClassname() + ".java").getWorkingCopy(getWorkingCopyOwner(), getProgressMonitor()); //$NON-NLS-1$ setContents(cu); // GRAILS CHANGE // need extra call to makeConsistent // https://issuetracker.springsource.com/browse/STS-3091#comment-79054 cu.makeConsistent(getProgressMonitor()); if (DEBUG) { System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); //$NON-NLS-1$ System.out.println("(+) JSPTranslation [" + this + "] finished creating CompilationUnit: " + cu); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); //$NON-NLS-1$ } return cu; }
From source file:org.grails.ide.eclipse.editor.gsp.translation.internal.GSPTranslator.java
License:Open Source License
/** * @param type/* w w w .j a v a 2 s.c o m*/ * @return */ private boolean isTypeFound(String rawTypeValue, List errorTypeNames) { IFile file = getFile(); if (file == null) return true; IProject project = file.getProject(); IJavaProject p = JavaCore.create(project); if (p.exists()) { String types[] = new String[3]; if (rawTypeValue.indexOf('<') > 0) { // JSR 14 : Generics are being used, parse them out try { StringTokenizer toker = new StringTokenizer(rawTypeValue); // generic types[0] = toker.nextToken("<"); //$NON-NLS-1$ // type 1 or key types[1] = toker.nextToken(",>"); //$NON-NLS-1$ // type 2 or value types[2] = toker.nextToken(",>"); //$NON-NLS-1$ } catch (NoSuchElementException e) { // StringTokenizer failure with unsupported syntax } } else { types[0] = rawTypeValue; } for (int i = 0; i < types.length; i++) { if (types[i] != null) { // remove any array suffixes if (types[i].indexOf('[') > 0) { types[i] = types[i].substring(0, types[i].indexOf('[')); //$NON-NLS-1$ } // remove any "extends" prefixes (JSR 14) if (types[i].indexOf("extends") > 0) { types[i] = StringUtils.strip(types[i].substring(types[i].indexOf("extends"))); //$NON-NLS-1$ } addNameToListIfTypeNotFound(p, types[i], errorTypeNames); } } } return errorTypeNames.isEmpty(); }
From source file:org.grails.ide.eclipse.ui.internal.launch.GrailsLaunchMainTab.java
License:Open Source License
/** * Return the IJavaProject corresponding to the project name in the project name text field, or null if the text * does not match a project name.// w w w. j av a 2s.co m */ protected IJavaProject getJavaProject() { String projectName = fProjText.getText().trim(); if (projectName == null || projectName.length() < 1) { setErrorMessage("No project selected"); return null; } IJavaProject javaProject = getJavaModel().getJavaProject(projectName); if (!javaProject.exists()) { setErrorMessage("Project " + projectName + " doesn't exist"); return null; } if (!javaProject.exists()) { setErrorMessage("Project " + projectName + " isn't open"); return null; } setErrorMessage(null); return javaProject; }
From source file:org.grails.ide.eclipse.ui.internal.launch.GrailsLaunchMainTab.java
License:Open Source License
/** * Maps the config to associated java resource * //from w ww . j a va 2 s. c om * @param config */ protected void mapResources(ILaunchConfigurationWorkingCopy config) { try { // CONTEXTLAUNCHING IJavaProject javaProject = getJavaProject(); if (javaProject != null && javaProject.exists() && javaProject.isOpen()) { JavaMigrationDelegate.updateResourceMapping(config); } } catch (CoreException ce) { setErrorMessage(ce.getStatus().getMessage()); } }
From source file:org.gw4e.eclipse.test.fwk.ProjectHelper.java
License:Open Source License
public static IJavaProject getOrCreateSimpleGW4EProject(String name, boolean createModel, boolean generate) throws CoreException, InvocationTargetException, InterruptedException, TimeoutException { long start = System.currentTimeMillis(); boolean autoBuilding = ResourceManager.isAutoBuilding(); ResourceManager.setAutoBuilding(false); try {/*from w w w . ja v a 2s . c o m*/ IJavaProject p = getProject(name); if (p == null || !p.exists()) { p = createProject(name); } GraphWalkerContextManager.configureProject(p.getProject()); Job job = new WorkspaceJob("GW4E Set Nature Job") { @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { try { IJavaProject p = getProject(name); GW4ENature.setGW4ENature(p.getProject()); return Status.CANCEL_STATUS; } catch (Throwable e) { return Status.CANCEL_STATUS; } } }; job.setRule(ResourceManager.getWorkspaceRoot()); job.setUser(true); job.schedule(); job.join(); Waiter.waitUntil(new ICondition() { @Override public boolean checkCondition() throws Exception { IJavaProject p = getProject(name); IFolder folder = p.getProject().getFolder("src/test/resources"); return folder != null && folder.exists(); } @Override public String getFailureMessage() { return "src/test/resources" + " does not exists"; } }); if (createModel) { p = getProject(name); SimpleTemplate provider = new SimpleTemplate(); IFolder folder = p.getProject().getFolder("src/test/resources"); String[] resources = provider.getResources(); for (String resource : resources) { try { IFile file = provider.create(folder, resource, null, new NullProgressMonitor()); provider.addCreatedResources(file); } catch (IOException e) { e.printStackTrace(); } } Display.getDefault().syncExec(() -> provider.openInEditor(PlatformUI.getWorkbench())); Waiter.waitUntil(new ICondition() { IFile f; @Override public boolean checkCondition() throws Exception { IJavaProject p = getProject(name); f = (IFile) ResourceManager.getResource( p.getProject().getFullPath().append("src/test/resources/Simple.json").toString()); return f != null && f.exists(); } @Override public String getFailureMessage() { return "File " + f + " not found"; } }); if (generate) { IFile f = (IFile) ResourceManager.getResource( p.getProject().getFullPath().append("src/test/resources/Simple.json").toString()); IWorkbenchWindow iww = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); AbstractPostConversion converter = GraphWalkerContextManager.getDefaultGraphConversion(f, false); ClassExtension ce = converter.getContext().getClassExtension(); ce.setGenerateRunFunctionalTest(true); ce.setStartElementForJunitTest("start_app"); ConversionRunnable runnable = converter.createConversionRunnable(iww); runnable.run(new NullProgressMonitor()); Waiter.waitUntil(new ICondition() { IFile interf; @Override public boolean checkCondition() throws Exception { IJavaProject p = getProject(name); interf = (IFile) ResourceManager.getResource(p.getProject().getFullPath() .append("target/generated-test-sources/Simple.java").toString()); return interf != null && interf.exists(); } @Override public String getFailureMessage() { return "File " + interf + " not found"; } }); Waiter.waitUntil(new ICondition() { IFile impl; @Override public boolean checkCondition() throws Exception { IJavaProject p = getProject(name); impl = (IFile) ResourceManager.getResource(p.getProject().getFullPath() .append("src/test/java/SimpleImpl.java").toString()); return impl != null && impl.exists(); } @Override public String getFailureMessage() { return "File " + impl + " not found"; } }); } } ResourceManager.setAutoBuilding(true); waitBuild(); p = getProject(name); return p; } finally { ResourceManager.setAutoBuilding(autoBuilding); long end = System.currentTimeMillis(); System.out.println("TIME = " + ((end - start) / 1000)); } }