List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:org.ebayopensource.vjet.eclipse.core.PiggyBackClassPathUtil.java
License:Open Source License
public static List<IBuildpathEntry> fetchBuildEntryFromJavaProject(IJavaProject javaProject) { // Project entry List<IBuildpathEntry> vEntries = new ArrayList<IBuildpathEntry>(); List<String> duplicateChecker = new ArrayList<String>(); IClasspathEntry[] entries2;/*from w w w.j av a2 s . co m*/ try { entries2 = javaProject.getRawClasspath(); } catch (JavaModelException e) { VjetPlugin.error("Failed to resolve Java prjoect classpath: " + javaProject.getElementName(), e, IStatus.WARNING); return Collections.emptyList(); } for (IClasspathEntry entry : entries2) { IPath path = entry.getPath(); String sPath = path.toString(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_LIBRARY: addEntryToVJETEntry(entry, vEntries, duplicateChecker); case IClasspathEntry.CPE_PROJECT: IResource subResource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); if (subResource != null && subResource.getType() == IResource.PROJECT) { addProjectEntry(entry.getPath(), vEntries, duplicateChecker); } break; case IClasspathEntry.CPE_CONTAINER: if (!JavaRuntime.JRE_CONTAINER.equals(path.segment(0))) { IClasspathContainer container; try { container = JavaCore.getClasspathContainer(path, javaProject); if (container != null) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { addEntryToVJETEntry(entries[i], vEntries, duplicateChecker); } } } catch (JavaModelException e) { VjetPlugin.error("Failed to resolve Java classpath container: " + sPath, e, IStatus.WARNING); } } break; default: break; } } return vEntries; }
From source file:org.ebayopensource.vjet.eclipse.internal.launching.LauncherUtil.java
License:Open Source License
public static Set<String> getRawClasspath(IJavaProject javaProject) throws JavaModelException { Map<String, IJavaProject> transitiveClosureProjectList = new LinkedHashMap<String, IJavaProject>(); getTransitiveClosureProjectDependnecyList(javaProject, transitiveClosureProjectList); Set<String> jars = new LinkedHashSet<String>(); getProjectDependentJars(jars, javaProject.getRawClasspath()); for (IJavaProject project : transitiveClosureProjectList.values()) { getProjectDependentJars(jars, project.getRawClasspath()); }/*from w w w .j a va 2 s . c om*/ return jars; }
From source file:org.ebayopensource.vjet.eclipse.internal.launching.VjetInterpreterRunner.java
License:Open Source License
/** * Launches new jvm instance and runs within it interpreter. * // w w w .j a va2 s . c o m * @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.ui.actions.nature.java.JavaProjectAddVjoNaturePolicy.java
License:Open Source License
/** * get the dltk build path entries based on java project * //from w w w.j av a 2 s . co m * @param javaProject * @return */ private IBuildpathEntry[] buildBuildpathEntry(IJavaProject javaProject) { try { List<IBuildpathEntry> buildpathEntryList = new ArrayList<IBuildpathEntry>(); //create source dltk build path entries IClasspathEntry[] classPathEntries = javaProject.getRawClasspath(); for (int i = 0; i < classPathEntries.length; i++) { if (IClasspathEntry.CPE_SOURCE == classPathEntries[i].getEntryKind()) { IBuildpathEntry buildpathEntry = DLTKCore.newSourceEntry(classPathEntries[i].getPath()); buildpathEntryList.add(buildpathEntry); } } //create default interpreter build path entry IBuildpathEntry defaultInterpreterEntry = ScriptRuntime.getDefaultInterpreterContainerEntry(); buildpathEntryList.add(defaultInterpreterEntry); //create default SDK build path entry IBuildpathEntry defaultSdkEntry = VjetSdkRuntime.getDefaultSdkContainerEntry(); buildpathEntryList.add(defaultSdkEntry); //create build path entry for vjet jar buildpathEntryList.addAll(PiggyBackClassPathUtil.fetchBuildEntryFromJavaProject(javaProject)); return buildpathEntryList.toArray(new IBuildpathEntry[buildpathEntryList.size()]); } catch (Exception e) { e.printStackTrace(); return new IBuildpathEntry[0]; } }
From source file:org.eclim.plugin.jdt.project.JavaProjectManager.java
License:Open Source License
/** * Merge the supplied project's classpath with entries found in the specified * build file./*w ww. j a v a2 s.c om*/ * * @param project The project. * @param buildfile The path to the build file (pom.xml, ivy.xml, etc) * @return The classpath entries. */ protected IClasspathEntry[] mergeWithBuildfile(IJavaProject project, String buildfile) throws Exception { String filename = FileUtils.getBaseName(buildfile); Parser parser = PARSERS.get(filename); String var = parser.getClasspathVar(); Dependency[] dependencies = parser.parse(buildfile); IWorkspaceRoot root = project.getProject().getWorkspace().getRoot(); ArrayList<IClasspathEntry> results = new ArrayList<IClasspathEntry>(); // load the results with all the non library entries. IClasspathEntry[] entries = project.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY && entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE) { results.add(entry); } else { IPath path = entry.getPath(); String prefix = path != null ? path.segment(0) : null; if ((!var.equals(prefix)) || preserve(entry)) { results.add(entry); } } } // merge the dependencies with the classpath entires. for (int ii = 0; ii < dependencies.length; ii++) { IClasspathEntry match = null; for (int jj = 0; jj < entries.length; jj++) { if (entries[jj].getEntryKind() == IClasspathEntry.CPE_LIBRARY || entries[jj].getEntryKind() == IClasspathEntry.CPE_VARIABLE) { String path = entries[jj].getPath().toOSString(); String pattern = dependencies[ii].getName() + Dependency.VERSION_SEPARATOR; // exact match if (path.endsWith(dependencies[ii].toString())) { match = entries[jj]; results.add(entries[jj]); break; // different version match } else if (path.indexOf(pattern) != -1) { break; } } else if (entries[jj].getEntryKind() == IClasspathEntry.CPE_PROJECT) { String path = entries[jj].getPath().toOSString(); if (path.endsWith(dependencies[ii].getName())) { match = entries[jj]; break; } } } if (match == null) { IClasspathEntry entry = createEntry(root, project, dependencies[ii]); results.add(entry); } else { match = null; } } return (IClasspathEntry[]) results.toArray(new IClasspathEntry[results.size()]); }
From source file:org.eclipse.acceleo.internal.ide.ui.builders.AcceleoBuilder.java
License:Open Source License
/** * Computes the classpath for the given java project. * /* w ww . j a va 2 s . c o m*/ * @param javaProject * The Java project * @return The classpath entries */ private Set<AcceleoProjectClasspathEntry> computeProjectClassPath(IJavaProject javaProject) { Set<AcceleoProjectClasspathEntry> classpathEntries = new LinkedHashSet<AcceleoProjectClasspathEntry>(); // Compute the classpath of the acceleo project IClasspathEntry[] rawClasspath; try { rawClasspath = javaProject.getRawClasspath(); for (IClasspathEntry iClasspathEntry : rawClasspath) { int entryKind = iClasspathEntry.getEntryKind(); if (IClasspathEntry.CPE_SOURCE == entryKind) { // We have the source folders of the project. IPath inputFolderPath = iClasspathEntry.getPath(); IPath outputFolderPath = iClasspathEntry.getOutputLocation(); if (outputFolderPath == null) { outputFolderPath = javaProject.getOutputLocation(); } IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject(inputFolderPath.lastSegment()); if (!(project != null && project.exists() && project.equals(javaProject.getProject()))) { IContainer inputContainer = ResourcesPlugin.getWorkspace().getRoot() .getFolder(inputFolderPath); IContainer outputContainer = ResourcesPlugin.getWorkspace().getRoot() .getFolder(outputFolderPath); if (inputContainer != null && outputContainer != null) { File inputDirectory = inputContainer.getLocation().toFile(); File outputDirectory = outputContainer.getLocation().toFile(); AcceleoProjectClasspathEntry entry = new AcceleoProjectClasspathEntry(inputDirectory, outputDirectory); classpathEntries.add(entry); this.outputFolders.add(outputDirectory); } } } } } catch (JavaModelException e) { AcceleoUIActivator.log(e, true); } return classpathEntries; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Checks to see if an entry is already on the aspect path *//* w ww. j a v a2 s . c o m*/ public static boolean isOnAspectpath(IProject project, String path) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if ((cp[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) || (cp[i].getEntryKind() == IClasspathEntry.CPE_VARIABLE) || (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) || (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT)) { IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolvedClasspathEntry != null) { String entry = resolvedClasspathEntry.getPath().toPortableString(); if (entry.equals(path)) { if (isOnAspectpath(cp[i])) { return true; } } } } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Checks to see if an entry is already on the Inpath *///from ww w. jav a 2s. c o m public static boolean isOnInpath(IProject project, String jarPath) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if ((cp[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) || (cp[i].getEntryKind() == IClasspathEntry.CPE_VARIABLE) || (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) || (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT)) { IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolvedClasspathEntry != null) { String entry = resolvedClasspathEntry.getPath().toPortableString(); if (entry.equals(jarPath)) { if (isOnInpath(cp[i])) { return true; } } } } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Searches the raw classpath for entries whose paths contain * the strings in putOnPath.// www.java 2 s . c o m * * Then ensures that these classpath entries are on the aspect path */ public static void augmentAspectPath(IProject project, String[] putOnAspectPath) { if (putOnAspectPath.length == 0) { // nothing to do! return; } IJavaProject jp = JavaCore.create(project); List<IClasspathEntry> toPutOnAspectPath = new ArrayList<IClasspathEntry>(); try { IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { String path = cp[i].getPath().toPortableString(); for (int j = 0; j < putOnAspectPath.length; j++) { if (path.indexOf(putOnAspectPath[j]) != -1) { toPutOnAspectPath.add(cp[i]); } } } for (IClasspathEntry entry : toPutOnAspectPath) { if (!isOnAspectpath(entry)) { addToAspectPath(project, entry); } } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Firstly, add library to the Java build path if it's not there already, * then mark the entry as being on the aspect path * @param project//from w w w. ja v a2 s .c o m * @param path */ private static void addAttribute(IProject project, String jarPath, int eKind, IClasspathAttribute attribute) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); int cpIndex = getIndexInBuildPathEntry(cp, jarPath); if (cpIndex >= 0) { // already on classpath // add attribute to classpath entry // if it doesn't already exist IClasspathEntry pathAdd = cp[cpIndex]; // only add attribute if this element is not already on the path if (isAspectPathAttribute(attribute) ? !isOnAspectpath(pathAdd) : !isOnInpath(pathAdd)) { IClasspathAttribute[] attributes = pathAdd.getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length + 1]; System.arraycopy(attributes, 0, newattrib, 0, attributes.length); newattrib[attributes.length] = attribute; switch (pathAdd.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: pathAdd = JavaCore.newLibraryEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_VARIABLE: pathAdd = JavaCore.newVariableEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_CONTAINER: pathAdd = JavaCore.newContainerEntry(pathAdd.getPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_PROJECT: pathAdd = JavaCore.newProjectEntry(pathAdd.getPath(), pathAdd.getAccessRules(), true, newattrib, pathAdd.isExported()); break; } cp[cpIndex] = pathAdd; jp.setRawClasspath(cp, null); } } else { addEntryToJavaBuildPath(jp, attribute, jarPath, eKind); } } catch (JavaModelException e) { } }