List of usage examples for org.eclipse.jdt.core IJavaProject exists
boolean exists();
From source file:kr.simula.formula.ide.launcher.FormulaInterpreterRunner.java
License:Apache License
protected static String[] computeBaseClassPath(IJavaProject myJavaProject) throws CoreException { if (!myJavaProject.exists()) return CharOperation.NO_STRINGS; return JavaRuntime.computeDefaultRuntimeClassPath(myJavaProject); }
From source file:lang.java.jdt.internal.JDT.java
License:Open Source License
public IValue isOnBuildPath(ISourceLocation loc) { IResource r = getResource(loc);/*from ww w.j a va 2 s .com*/ IJavaProject jp = JavaCore.create(r.getProject()); if (!jp.exists()) { throw new Throw(VF.string("Location is not in a Java project: " + loc), (ISourceLocation) null, null); } return VF.bool(jp.isOnClasspath(r)); }
From source file:net.atos.jdt.ast.validation.engine.project.ValidationProjectBuilder.java
License:Open Source License
@Override protected IProject[] build(final int kind, final Map<String, String> args, final IProgressMonitor monitor) throws CoreException { final Collection<ICompilationUnit> compilationUnits = new ArrayList<ICompilationUnit>(); monitor.setTaskName(ValidationEngineMessages.VALIDATING_SOURCE.value()); // If build kind is a full build, we get all the compilation units of // the project if (kind == IncrementalProjectBuilder.FULL_BUILD) { final IProject project = this.getProject(); final IJavaProject javaProject = JavaCore.create(project); if ((javaProject != null) && javaProject.exists()) { monitor.subTask(ValidationEngineMessages.RETRIEVING_CU.value()); compilationUnits.addAll(this.retrieveCompilationUnits(javaProject)); }/*from w w w. java 2 s. c om*/ } else if ((kind == IncrementalProjectBuilder.AUTO_BUILD) || (kind == IncrementalProjectBuilder.INCREMENTAL_BUILD)) { // If build is an incremental build, we retrieve the elements being // built and we gather the compilation units within final IResourceDelta delta = this.getDelta(this.getProject()); monitor.subTask(ValidationEngineMessages.RETRIEVING_CU.value()); delta.accept(new IResourceDeltaVisitor() { @Override public boolean visit(final IResourceDelta delta) throws CoreException { final IResource affectedResource = delta.getResource(); final IJavaElement affectedJavaResource = JavaCore.create(affectedResource); if (affectedJavaResource instanceof ICompilationUnit) { compilationUnits.add((ICompilationUnit) affectedJavaResource); } return true; } }); } new ASTValidationEngine(compilationUnits, this.getValidRepositories()).execute(monitor); return new IProject[0]; }
From source file:net.rim.ejde.internal.core.BasicClasspathElementChangedListener.java
License:Open Source License
/** * Checks if all source files are existing. If not, create them. * * @param javaProj//from w w w. j av a2 s . c o m */ private void checkSourceFolders(final IJavaProject javaProj) { if (javaProj == null) return; if (javaProj.exists()) { try { if (!javaProj.isOpen()) { javaProj.open(new NullProgressMonitor()); } IClasspathEntry[] entries = javaProj.getRawClasspath(); for (IClasspathEntry entry : entries) { if (IClasspathEntry.CPE_SOURCE == entry.getEntryKind()) { IPath path = entry.getPath(); final IPath folderPath = path.removeFirstSegments(1); if (!folderPath.isEmpty()) { Display.getDefault().asyncExec(new Runnable() { public void run() { try { ImportUtils.createFolders(javaProj.getProject(), folderPath, IResource.FORCE); } catch (CoreException e) { _log.error(e.getMessage()); } } }); } } } } catch (JavaModelException e) { _log.error("findProjectSources: Could not retrieve project sources:", e); //$NON-NLS-1$ } } }
From source file:net.rim.ejde.internal.sourcelookup.RIMSourcePathProvider.java
License:Open Source License
/** * Return the <code>IJavaProject</code> referenced in the specified configuration or <code>null</code> if none. * * @exception CoreException/*w w w . j a va 2 s. c o m*/ * if the referenced Java project does not exist */ private IJavaProject[] getJavaProjects(ILaunchConfiguration configuration) throws CoreException { Set<IProject> iProjects = LaunchUtils.getProjectsFromConfiguration(configuration); List<IJavaProject> javaProjects = new ArrayList<IJavaProject>(); for (Iterator<IProject> iterator = iProjects.iterator(); iterator.hasNext();) { IProject project = iterator.next(); if (NatureUtils.hasBBNature(project)) { IJavaProject javaProject = JavaCore.create(project); javaProjects.add(javaProject); if (javaProject != null && javaProject.getProject().exists() && !javaProject.getProject().isOpen()) { handldError("Project is closed.", IJavaLaunchConfigurationConstants.ERR_PROJECT_CLOSED, null); } if ((javaProject == null) || !javaProject.exists()) { handldError("Project was not found.", IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT, null); } } } return javaProjects.toArray(new IJavaProject[0]); }
From source file:net.rim.ejde.internal.util.ImportUtils.java
License:Open Source License
/** * resources already in a source folder don't need a link, otherwise they'll be duplicated in bin/! jars will be handled by * LIB type classpath// w w w. ja v a 2 s .co m * * @param filePth * : path to the file * @param packageResource * : the Eclipse resource representing the package segment * @return boolean */ static private boolean canIgnoreFile(IPath filePath, IJavaProject eclipseJavaProject) { if (null == filePath) { throw new IllegalArgumentException("Can't evaluate undefined path!"); } if (null == eclipseJavaProject || !eclipseJavaProject.exists()) { throw new IllegalArgumentException("Can't evaluate undefined Eclipse JDT project!"); } if (IConstants.JAR_EXTENSION.equalsIgnoreCase(filePath.getFileExtension())) return true; return false; }
From source file:net.rim.ejde.internal.util.ProjectUtils.java
License:Open Source License
/** * Locates all the source folders represented by type IPackageFragmentRoot.K_SOURCE for the given project. * * @param project/*from ww w . j a v a 2 s . c o m*/ * The IProject to search for source folders. * @return An IPackageFragmentRoot array containing each K_SOURCE fragment found for the given project. */ public static IPackageFragmentRoot[] getProjectSourceFolders(IProject project) { IJavaProject iJavaProject = JavaCore.create(project); ArrayList<IPackageFragmentRoot> sourceRoots = new ArrayList<IPackageFragmentRoot>(); if (iJavaProject.exists() && iJavaProject.isOpen()) { try { IPackageFragmentRoot[] roots = iJavaProject.getAllPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { if (IPackageFragmentRoot.K_SOURCE == root.getKind()) { sourceRoots.add(root); } } } catch (JavaModelException e) { logger.error("findProjectSources: Could not retrieve project sources:", e); //$NON-NLS-1$ return new IPackageFragmentRoot[0]; } } return sourceRoots.toArray(new IPackageFragmentRoot[sourceRoots.size()]); }
From source file:net.sf.eclipse.tomcat.TomcatBootstrap.java
License:Open Source License
private String[] addProjectToClasspath(String[] previouscp, IJavaProject project) throws CoreException { if ((project != null) && (project.exists() && project.isOpen())) { String[] projectcp = JavaRuntime.computeDefaultRuntimeClassPath(project); return StringUtil.concatUniq(projectcp, previouscp); } else {/*from ww w . jav a 2s . co m*/ return previouscp; } }
From source file:net.sf.j2s.ui.editors.J2SConfigEditor.java
License:Open Source License
/** * Saves the multi-page editor's document. *//*from w ww. j av a2 s .c om*/ public void doSave(IProgressMonitor monitor) { getEditor(1).doSave(monitor); IFile file = (IFile) getEditorInput().getAdapter(IFile.class); if (file != null) { IPath path = file.getFullPath(); if (path.segmentCount() == 2 && ".j2s".equals(path.segment(1))) { boolean b = false; if (getActivePage() == 0) { b = configPage.isCompilerEnabled(); } else { Properties props = new Properties(); StyledText textWidget = ((J2STextEditor) editor).getJ2SSourceViewer().getTextWidget(); byte[] bytes = textWidget.getText().getBytes(); try { props.load(new ByteArrayInputStream(bytes)); } catch (IOException e1) { e1.printStackTrace(); } String status = props.getProperty("j2s.compiler.status"); if ("enable".equals(status)) { b = true; } } if (!lastEnabled && b) { IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); String projectName = path.segment(0); if ((projectName == null) || (projectName.trim().length() < 1)) { return; } IJavaProject javaProject = javaModel.getJavaProject(projectName); if ((javaProject == null) || !javaProject.exists()) { return; } IProject project = javaProject.getProject(); try { project.build(IncrementalProjectBuilder.CLEAN_BUILD, monitor); } catch (CoreException e) { e.printStackTrace(); } } lastEnabled = b; } } }
From source file:net.sf.j2s.ui.launching.J2SClasspathOptionTab.java
License:Open Source License
public void createControl(Composite parent) { Font font = parent.getFont(); Composite comp = new Composite(parent, SWT.NONE); setControl(comp);// ww w . j a va 2 s. co m PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_CLASSPATH_TAB); GridLayout topLayout = new GridLayout(); comp.setLayout(topLayout); GridData gd; Label label = new Label(comp, SWT.NONE); label.setText(LauncherMessages.JavaClasspathTab_0); //$NON-NLS-1$ gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); label.setLayoutData(gd); configPage = new J2SConfigPage(comp, SWT.NONE); configPage.forClasspathTab(); configPage.getRestoreDefaultButton().addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { ILaunchConfigurationWorkingCopy configCopy = ((ILaunchConfigurationWorkingCopy) fLaunchConfiguration); try { String classpath = configCopy.getAttribute(IJ2SLauchingConfiguration.J2S_CLASS_PATH, (String) null); String abandonClasspath = configCopy .getAttribute(IJ2SLauchingConfiguration.J2S_ABANDON_CLASS_PATH, (String) null); if ((classpath == null || classpath.trim().length() == 0) && (abandonClasspath == null || abandonClasspath.trim().length() == 0)) { return; } configCopy.setAttribute(IJ2SLauchingConfiguration.J2S_CLASS_PATH, (String) null); configCopy.setAttribute(IJ2SLauchingConfiguration.J2S_ABANDON_CLASS_PATH, (String) null); IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); String projectName = fLaunchConfiguration .getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null); if ((projectName == null) || (projectName.trim().length() < 1)) { return; } IJavaProject javaProject = javaModel.getJavaProject(projectName); if ((javaProject == null) || !javaProject.exists()) { return; } IProject project = javaProject.getProject(); String prjFolder = project.getLocation().toOSString(); File workingDir = new File(prjFolder); File j2sFile = new File(workingDir, ".j2s"); configPage.initConfigPage(j2sFile); updateLaunchConfigurationDialog(); } catch (JavaModelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (CoreException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); configPage.addConfigModifiedListener(new IJ2SConfigModifiedListener() { public void configModified() { setDirty(true); updateLaunchConfigurationDialog(); } }); }