List of usage examples for org.eclipse.jdt.core IJavaProject exists
boolean exists();
From source file:org.ebayopensource.vjet.eclipse.internal.launching.VjetInterpreterRunner.java
License:Open Source License
/** * Launches new jvm instance and runs within it interpreter. * //from www . j a va 2 s .c om * @param config * launch configuration * @param launch * the result of launching a debug session. * @throws CoreException * if an error occurred when running interpreter * @see {@link ILaunch} * @see {@link } */ public void doRunImpl(InterpreterConfig config, ILaunch launch) throws CoreException { IScriptProject proj = AbstractScriptLaunchConfigurationDelegate .getScriptProject(launch.getLaunchConfiguration()); // do not cross boundary to java sdk - looks like we are tied to Java // IDE here IJavaProject myJavaProject = JavaCore.create(proj.getProject()); IVMInstall vmInstall = myJavaProject.exists() ? JavaRuntime.getVMInstall(myJavaProject) : JavaRuntime.getDefaultVMInstall(); if (vmInstall == null) { throw new CoreException( new Status(IStatus.ERROR, VjetPlugin.PLUGIN_ID, IStatus.ERROR, "No VMInstall", null)); } IVMRunner vmRunner = vmInstall.getVMRunner(m_mode); if (vmRunner == null) { throw new CoreException( new Status(IStatus.ERROR, VjetPlugin.PLUGIN_ID, IStatus.ERROR, "No VMRunner", null)); } IWorkspaceRoot workspaceRoot = proj.getProject().getWorkspace().getRoot(); // prepare js source search path String sourceSearchPath = null; // sourceSearchPath = prepareSourceSearchPath(proj, myJavaProject, // workspaceRoot, sourceSearchPath); // prepare java runtime class path String[] clzPath = VjoRunnerInfo.getClassPath(); if (DEBUG_LAUNCH) { for (String path : clzPath) { System.out.println(path); } } String[] jarPaths = null; if (myJavaProject.exists()) { // add this project's dependent jars (include those from all // dependent projects) // so the dependented javascript can be loaded from those jar files jarPaths = getJarPaths(myJavaProject); } else { jarPaths = getJarPaths(proj); } if (jarPaths.length > 0) { String[] newClzPath = new String[clzPath.length + jarPaths.length]; System.arraycopy(clzPath, 0, newClzPath, 0, clzPath.length); System.arraycopy(jarPaths, 0, newClzPath, clzPath.length, jarPaths.length); clzPath = newClzPath; } VMRunnerConfiguration vmConfig = new VMRunnerConfiguration(VjoRunnerInfo.getClassName(), clzPath); IPath scriptFilePath = config.getScriptFilePath(); if (scriptFilePath == null) { throw new CoreException(new Status(IStatus.ERROR, VjetPlugin.PLUGIN_ID, IStatus.ERROR, "Script File name is not specified...", null)); } else if (!proj.exists() && !myJavaProject.exists()) { throw new CoreException(new Status(IStatus.ERROR, VjetPlugin.PLUGIN_ID, IStatus.ERROR, "Must run js from a VJET or JAVA project!", null)); } // find vjo class String jsFile = scriptFilePath.toFile().getAbsolutePath(); String vjoClz = ""; if (!jsFile.endsWith(".js")) { // do nothing } else { // get vjo class name String sourceRoot = null; if (proj.exists()) {// get vjo class name from script project IModelElement[] children = proj.getChildren(); for (IModelElement elem : children) { if (elem instanceof IProjectFragment) { IProjectFragment melem = (IProjectFragment) elem; if (!melem.isReadOnly()) { String absolutePath = proj.getProject().getLocation().toFile().getAbsolutePath(); String srcDir = absolutePath.substring(0, absolutePath.indexOf(proj.getProject().getName())) + melem.getPath(); srcDir = srcDir.replace("/", "\\"); srcDir = srcDir.replace("\\\\", "\\"); if (jsFile.startsWith(srcDir)) { sourceRoot = srcDir; break; } } } } } if (StringUtils.isBlankOrEmpty(sourceRoot) && myJavaProject.exists()) {// get vjo class name from java // project IClasspathEntry[] classpathEntries = myJavaProject.getRawClasspath(); for (IClasspathEntry entry : classpathEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { String path = getSourceFile(entry, workspaceRoot).getAbsolutePath(); if (jsFile.startsWith(path)) { sourceRoot = path; break; } } } } if (sourceRoot != null) { String vjoFile = jsFile.substring(sourceRoot.length() + 1); int suffixIndex = vjoFile.indexOf("."); if (suffixIndex > 0) { vjoFile = vjoFile.substring(0, suffixIndex); } vjoClz = vjoFile.replace("/", "."); vjoClz = vjoClz.replace("\\", "."); } } ILaunchConfiguration launchConf = launch.getLaunchConfiguration(); String args = launchConf.getAttribute(ScriptLaunchConfigurationConstants.ATTR_SCRIPT_ARGUMENTS, "").trim(); Map env = launchConf.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) new HashMap()); List<String> loadJSList = launchConf.getAttribute( org.ebayopensource.vjet.eclipse.launching.ILaunchConstants.ATTR_INCLUDE_PATH, new ArrayList<String>()); if (loadJSList.size() > 0) { StringBuilder loadJSStr = new StringBuilder(); for (String js : loadJSList) { //int kind = Integer.parseInt(js.substring(0, 1)); String path = js.substring(1); loadJSStr.append(path).append(JsRunner.LIST_SEPERATOR); } env.put(JsRunner.LOAD_JS_KEY, loadJSStr.toString()); } List<String> pArgs = new ArrayList<String>(); if (vjoClz == "" && jsFile.indexOf("htm") != -1) { env.put("type", "html"); } addEnvOptions(env, pArgs); // add env options pArgs.add(scriptFilePath.toFile().getAbsolutePath()); pArgs.add(vjoClz); // pArgs.add(findMainFunc(vjoClz, proj.getProject().getName())); // add script arguments as line pArgs.add(new ArgsNormalizer(args).normalize()); vmConfig.setProgramArguments(pArgs.toArray(new String[] {})); List<String> vmArgs = new ArrayList<String>(4); if (sourceSearchPath != null) { vmArgs.add("-Djava.source.path=" + sourceSearchPath); } IFileStore s = org.eclipse.core.filesystem.EFS.getStore(proj.getProject().getProject().getLocationURI()); File f = s.toLocalFile(0, null); if (m_mode.equals(ILaunchManager.DEBUG_MODE)) { vmArgs.add("-DVJETDebugHost=" + config.getProperty(DbgpConstants.HOST_PROP)); vmArgs.add("-DVJETDebugPort=" + config.getProperty(DbgpConstants.PORT_PROP)); vmArgs.add("-DVJETDebugSessionID=" + config.getProperty(DbgpConstants.SESSION_ID_PROP)); vmArgs.add("-DVJETProjectPath=" + f.getAbsolutePath()); } // org.eclipse.jdt.launching.PROJECT_ATTR String javaprojectprop = "org.eclipse.jdt.launching.PROJECT_ATTR"; String projectName = myJavaProject.getProject().getName(); ILaunchConfigurationWorkingCopy copy = launch.getLaunchConfiguration().getWorkingCopy(); copy.setAttribute(javaprojectprop, projectName); copy.doSave(); setupProxySrcLocator(launch, copy); vmConfig.setVMArguments(vmArgs.toArray(new String[vmArgs.size()])); // ILaunch launchr = new Launch(launch.ge, m_mode, null); // // ISourceLookupDirector sourceLocator = new JavaSourceLookupDirector(); // sourceLocator // .setSourcePathComputer(DebugPlugin.getDefault().getLaunchManager() // .getSourcePathComputer( // "org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer")); //$NON-NLS-1$ // sourceLocator.initializeDefaults(launchConf); // // launch.setSourceLocator(sourceLocator); vmRunner.run(vmConfig, launch, null); IDebugTarget[] debugTargets = launch.getDebugTargets(); if (debugTargets.length > 0) { VjetLaunchingPlugin.getDefault().getLog() .log(new Status( IStatus.INFO, VjetPlugin.PLUGIN_ID, IStatus.INFO, "!USAGE_TRACKING: NAME=" + VjetPlugin.PLUGIN_ID + ".debug; ACCESS_TIME=" + new Date().toString() + ";", null)); } else { VjetLaunchingPlugin.getDefault().getLog() .log(new Status( IStatus.INFO, VjetPlugin.PLUGIN_ID, IStatus.INFO, "!USAGE_TRACKING: NAME=" + VjetPlugin.PLUGIN_ID + ".run; ACCESS_TIME=" + new Date().toString() + ";", null)); } // for (int a = 0; a < debugTargets.length; a++) { // // launch.addDebugTarget(debugTargets[a]); // } // // IProcess[] processes = launch.getProcesses(); // for (int a = 0; a < processes.length; a++) { // launch.addProcess(processes[a]); // } }
From source file:org.ebayopensource.vjet.eclipse.internal.launching.VjetInterpreterRunner.java
License:Open Source License
private String prepareSourceSearchPath(IScriptProject proj, IJavaProject myJavaProject, IWorkspaceRoot workspaceRoot, String sourceSearchPath) throws ModelException, JavaModelException { if (!myJavaProject.exists()) { sourceSearchPath = getSourceSearchPath(proj); } else {// ww w. j a va 2 s . co m sourceSearchPath = getSourceSearchPath(myJavaProject, workspaceRoot); } return sourceSearchPath; }
From source file:org.eclim.plugin.jdt.preference.OptionHandler.java
License:Open Source License
@Override public Map<String, String> getValues(IProject project) throws Exception { IJavaProject javaProject = JavaCore.create(project); if (!javaProject.exists()) { throw new IllegalArgumentException(Services.getMessage("project.not.found", project.getName())); }/*www . j a va 2 s. c o m*/ @SuppressWarnings("unchecked") Map<String, String> coreOptions = javaProject.getOptions(true); Map<String, String> options = new Hashtable<String, String>(); options.putAll(coreOptions); options.putAll(getUIValues(project)); URL javadoc = JavaUI.getProjectJavadocLocation(javaProject); options.put(PROJECT_JAVADOC, javadoc != null ? javadoc.toString() : ""); return options; }
From source file:org.eclim.plugin.jdt.preference.OptionHandler.java
License:Open Source License
@Override public void setOption(IProject project, String name, String value) throws Exception { IJavaProject javaProject = JavaCore.create(project); if (!javaProject.exists()) { throw new IllegalArgumentException(Services.getMessage("project.not.found", project.getName())); }//from w w w .ja va 2s . c o m @SuppressWarnings("unchecked") Map<String, String> global = javaProject.getOptions(true); @SuppressWarnings("unchecked") Map<String, String> options = javaProject.getOptions(false); Object current = global.get(name); if (current == null || !current.equals(value)) { if (name.equals(JavaCore.COMPILER_SOURCE)) { JavaUtils.setCompilerSourceCompliance(javaProject, value); } else if (name.equals(PROJECT_JAVADOC)) { if (value != null && value.trim().length() == 0) { value = null; } try { JavaUI.setProjectJavadocLocation(javaProject, value != null ? new URL(value) : null); } catch (MalformedURLException mue) { throw new IllegalArgumentException( PROJECT_JAVADOC + ": Invalid javadoc url: " + mue.getMessage()); } } else if (name.startsWith(JavaUI.ID_PLUGIN)) { Preferences.getInstance().setPreference(JavaUI.ID_PLUGIN, project, name, value); } else { options.put(name, value); javaProject.setOptions(options); } } }
From source file:org.eclim.plugin.jdt.util.JavaUtils.java
License:Open Source License
/** * Gets a java project from the supplied IProject. * * @param project The IProject./* w ww .ja v a 2s . co m*/ * @return The java project. */ public static IJavaProject getJavaProject(IProject project) throws Exception { if (ProjectUtils.getPath(project) == null) { throw new IllegalArgumentException(Services.getMessage("project.location.null", project.getName())); } if (!project.hasNature(PluginResources.NATURE)) { throw new IllegalArgumentException(Services.getMessage("project.missing.nature", project.getName(), ProjectNatureFactory.getAliasForNature(PluginResources.NATURE))); } IJavaProject javaProject = JavaCore.create(project); if (javaProject == null || !javaProject.exists()) { throw new IllegalArgumentException(Services.getMessage("project.not.found", project)); } return javaProject; }
From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java
License:Open Source License
/** * Find the java element corresponding to the handle. We know that it exists in * as a class file in a binary folder, but it may actually be * a source file in a different project//ww w. j a v a 2s. c om */ private IJavaElement findElementInBinaryFolder(HandleInfo handleInfo, IClassFile classFile) throws JavaModelException { IJavaElement candidate = classFile; // we have a class file that is not in a jar. // can we find this as a source file in some project? IPath path = classFile.getPath(); IJavaProject otherProject = JavaCore.create(project).getJavaModel().getJavaProject(path.segment(0)); ITypeRoot typeRoot = classFile; if (otherProject.exists()) { IType type = otherProject.findType(handleInfo.sourceTypeQualName()); typeRoot = type.getTypeRoot(); if (typeRoot instanceof ICompilationUnit) { AJCompilationUnit newUnit = CompilationUnitTools .convertToAJCompilationUnit((ICompilationUnit) typeRoot); typeRoot = newUnit != null ? newUnit : typeRoot; } } if (handleInfo.isType) { switch (typeRoot.getElementType()) { case IJavaElement.CLASS_FILE: candidate = ((IClassFile) typeRoot).getType(); break; case IJavaElement.COMPILATION_UNIT: candidate = CompilationUnitTools.findType((ICompilationUnit) typeRoot, classFile.getType().getElementName(), true); break; default: // shouldn't happen break; } } else if (!handleInfo.isFile && !handleInfo.isType) { // program element will exist only if coming from aspect path IProgramElement ipe = getProgramElement(handleInfo.origAJHandle); if (ipe != IHierarchy.NO_STRUCTURE) { candidate = typeRoot.getElementAt(offsetFromLine(typeRoot, ipe.getSourceLocation())); } else { String newHandle = typeRoot.getHandleIdentifier() + handleInfo.restHandle; candidate = AspectJCore.create(newHandle); } } return candidate; }
From source file:org.eclipse.ajdt.internal.buildpath.AJBuildPathAction.java
License:Open Source License
private static IFile getCandidate(IAdaptable element) throws JavaModelException { IResource resource = (IResource) element.getAdapter(IResource.class); if (!(resource instanceof IFile) || !ArchiveFileFilter.isArchivePath(resource.getFullPath(), true)) return null; IJavaProject project = JavaCore.create(resource.getProject()); if (project != null && project.exists() && (project.findPackageFragmentRoot(resource.getFullPath()) == null)) return (IFile) resource; return null;//from ww w . jav a2s . com }
From source file:org.eclipse.ajdt.internal.launching.AspectJMainTab.java
License:Open Source License
/** * Show a dialog that lists all main types *//* www . j a v a2s. c o m*/ protected void handleSearchButtonSelected() { IJavaProject project = getJavaProject(); IJavaElement[] elements = null; if ((project == null) || !project.exists()) { IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); if (model != null) { try { elements = model.getJavaProjects(); } //end try catch (JavaModelException e) { JDIDebugUIPlugin.log(e); } } //end if } //end if else { elements = new IJavaElement[] { project }; } //end else if (elements == null) { elements = new IJavaElement[] {}; } //end if int constraints = IJavaSearchScope.SOURCES; if (fSearchExternalJarsCheckButton.getSelection()) { constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; constraints |= IJavaSearchScope.SYSTEM_LIBRARIES; } //end if IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints); // AspectJ Change Begin AJMainMethodSearchEngine engine = new AJMainMethodSearchEngine(); // AspectJ Change End IType[] types = null; try { // AspectJ Change Begin types = engine.searchMainMethodsIncludingAspects(getLaunchConfigurationDialog(), searchScope, fConsiderInheritedMainButton.getSelection()); // AspectJ Change End } //end try catch (InvocationTargetException e) { setErrorMessage(e.getMessage()); return; } //end catch catch (InterruptedException e) { setErrorMessage(e.getMessage()); return; } //end catch SelectionDialog dialog = null; // AspectJ Change Begin dialog = new AJMainTypeSelectionDialog(getShell(), types); // AspectJ Change End dialog.setTitle(LauncherMessages.JavaMainTab_Choose_Main_Type_11); dialog.setMessage(LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12); if (dialog.open() == Window.CANCEL) { return; } //end if Object[] results = dialog.getResult(); IType type = (IType) results[0]; if (type != null) { fMainText.setText(type.getFullyQualifiedName()); fProjText.setText(type.getJavaProject().getElementName()); } //end if }
From source file:org.eclipse.ajdt.internal.ui.ajdocexport.AJdocOptionsManager.java
License:Open Source License
private boolean isValidProject(IJavaProject project) throws JavaModelException { if (project != null && project.exists() && project.isOpen()) { return true; }// w w w .ja v a 2 s.c o m return false; }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.StandardJavaElementContentProvider.java
License:Open Source License
private Object[] getResources(IFolder folder) { try {// w w w.j a v a2 s . co m IResource[] members = folder.members(); IJavaProject javaProject = JavaCore.create(folder.getProject()); if (javaProject == null || !javaProject.exists()) return members; boolean isFolderOnClasspath = javaProject.isOnClasspath(folder); List nonJavaResources = new ArrayList(); // Can be on classpath but as a member of non-java resource folder for (int i = 0; i < members.length; i++) { IResource member = members[i]; // A resource can also be a java element // in the case of exclusion and inclusion filters. // We therefore exclude Java elements from the list // of non-Java resources. if (isFolderOnClasspath) { if (javaProject.findPackageFragmentRoot(member.getFullPath()) == null) { nonJavaResources.add(member); } } else if (!javaProject.isOnClasspath(member)) { nonJavaResources.add(member); } } return nonJavaResources.toArray(); } catch (CoreException e) { return NO_CHILDREN; } }