List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:org.eclipse.virgo.ide.pde.core.internal.Helper.java
License:Open Source License
/** * Gets the output location of the project. Either returns the global output location or the first output location * found for a source folder./* w w w. j ava 2 s .c o m*/ * * @return * @throws CoreException */ /* package */ static IPath getOutputLocation(IProject project) throws CoreException { IJavaProject jp = (IJavaProject) project.getNature(JavaCore.NATURE_ID); IPath outputLocation = jp.getOutputLocation(); if (outputLocation == null) { IClasspathEntry[] entries = jp.getRawClasspath(); for (IClasspathEntry iClasspathEntry : entries) { if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { outputLocation = iClasspathEntry.getOutputLocation(); if (outputLocation != null) { break; } } } } if (outputLocation == null) { throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, Messages.Helper_BinFolderError)); } return outputLocation; }
From source file:org.eclipse.virgo.ide.ui.editors.BundleLibrarySection.java
License:Open Source License
private void configureSourceBuildEntry(IBuildModel bmodel, String oldPath, String newPath) throws CoreException { IBuild build = bmodel.getBuild();//from w ww . j a v a 2 s . c om IBuildEntry entry = build.getEntry(PROPERTY_SOURCE_PREFIX + (oldPath != null ? oldPath : newPath)); try { if (newPath != null) { if (entry == null) { IProject project = ((IModel) getPage().getModel()).getUnderlyingResource().getProject(); IJavaProject jproject = JavaCore.create(project); ArrayList tokens = new ArrayList(); IClasspathEntry[] entries = jproject.getRawClasspath(); for (IClasspathEntry element : entries) { if (element.getEntryKind() == IClasspathEntry.CPE_SOURCE) { tokens.add(element.getPath().removeFirstSegments(1).addTrailingSeparator().toString()); } } if (tokens.size() == 0) { return; } entry = bmodel.getFactory().createEntry(PROPERTY_SOURCE_PREFIX + newPath); for (int i = 0; i < tokens.size(); i++) { entry.addToken((String) tokens.get(i)); } build.add(entry); } else { entry.setName(PROPERTY_SOURCE_PREFIX + newPath); } } else if (entry != null && newPath == null) { build.remove(entry); } } catch (JavaModelException e) { } }
From source file:org.eclipse.vjet.eclipse.internal.launching.VjetInterpreterRunner.java
License:Open Source License
/** * Launches new jvm instance and runs within it interpreter. * //from w ww. j a va 2 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(); absolutePath = absolutePath.replace("//", "/"); absolutePath = absolutePath.replace("\\", "/"); 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.eclipse.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.eclipse.vjet.eclipse.javalaunch.utils.EclipseResourceUtils.java
License:Open Source License
public static boolean isResourceInSourceLocation(IResource resource) { boolean resourceIsInSourceLocation = false; IProject resourceProject = resource.getProject(); IJavaProject javaProject = JavaCore.create(resourceProject); if (javaProject != null || JavaProject.hasJavaNature(resourceProject) == false) { // IPath outputPath = null; IPath sourcePath = null;/*from www . jav a2s . c o m*/ try { IClasspathEntry[] classPathEntries = javaProject.getRawClasspath(); List<IClasspathEntry> sourceEntries = getClasspathEntry(IClasspathEntry.CPE_SOURCE, classPathEntries); for (IClasspathEntry entry : sourceEntries) { sourcePath = entry.getPath(); resourceIsInSourceLocation = isResourceInClasspathEntry(resource, sourcePath); if (resourceIsInSourceLocation == true) break; } } catch (JavaModelException e) { // Swallow this exception. This just means we could not find // the class path definition, and hence does not have an output // location. resourceIsInSourceLocation = false; } } return resourceIsInSourceLocation; }
From source file:org.eclipse.vjet.eclipse.javalaunch.utils.EclipseResourceUtils.java
License:Open Source License
/** * Given a set of classpath entries, popullate the list of source paths. * @param sourcePaths - The list to be populated * @param workspaceRoot - Workspace root, passed in. * @param classPathEntries/*from ww w. j a v a 2s . c o m*/ */ public static void getProjectSourcePaths(List<File> sourcePaths, IWorkspaceRoot workspaceRoot, IClasspathEntry[] classPathEntries) { if (classPathEntries != null) { for (IClasspathEntry classPathEntry : classPathEntries) { if (classPathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { File sourceFile; if (classPathEntry.getPath().segmentCount() == 1) { IProject project = workspaceRoot.getProject(classPathEntry.getPath().lastSegment()); sourceFile = project.getLocation().toFile(); } else { IFile sourceIFile = workspaceRoot.getFile(classPathEntry.getPath()); sourceFile = sourceIFile.getLocation().toFile(); } assert (sourceFile.exists()); sourcePaths.add(sourceFile); } } } }
From source file:org.eclipse.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 ava2 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(VjetSdkRuntime.getJsSdkContainerEntry()); 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.eclipse.wb.internal.core.utils.jdt.core.CodeUtils.java
License:Open Source License
/** * Adds {@link IContainer}'s for all source directories of given {@link IJavaProject} and its * required projects.//w w w . ja v a2 s . co m */ private static void addSourceContainers(List<IContainer> containers, Set<IJavaProject> visitedProjects, IJavaProject javaProject, boolean includeRequiredProjects) throws Exception { // check for existence if (!javaProject.exists()) { return; } // check for recursion if (visitedProjects.contains(javaProject)) { return; } visitedProjects.add(javaProject); // prepare information IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = javaProject.getProject(); // add source folders for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IContainer container = (IContainer) root.findMember(entry.getPath()); if (container != null) { containers.add(container); } } } // source folders of required projects if (includeRequiredProjects) { for (String requiredProjectName : javaProject.getRequiredProjectNames()) { addSourceContainers(containers, visitedProjects, requiredProjectName); } } // source folders for fragments if (includeRequiredProjects) { Object model = ReflectivePDE.findModel(project); if (model != null) { BundleDescription bundleDescription = ReflectivePDE.getPluginModelBundleDescription(model); if (bundleDescription != null) { BundleDescription[] fragments = bundleDescription.getFragments(); for (BundleDescription fragment : fragments) { String fragmentProjectName = fragment.getSymbolicName(); addSourceContainers(containers, visitedProjects, fragmentProjectName); } } } } }
From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java
License:Open Source License
/** * Adds absolute locations (in file system) of output folders for given and required projects. *//*from w w w. ja v a 2 s . co m*/ public static void addOutputLocations(Set<IProject> visitedProjects, List<String> locations, IProject project) throws Exception { // may be not exists if (!project.exists()) { return; } // check for recursion if (visitedProjects.contains(project)) { return; } visitedProjects.add(project); // add output folders for IJavaProject { IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { // default output location { IPath outputPath = javaProject.getOutputLocation(); addAbsoluteLocation(locations, outputPath); } // source folder specific output locations for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = entry.getOutputLocation(); addAbsoluteLocation(locations, outputPath); } } } } // process required projects IProject[] referencedProjects = project.getReferencedProjects(); for (IProject referencedProject : referencedProjects) { addOutputLocations(visitedProjects, locations, referencedProject); } }
From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java
License:Open Source License
/** * Adds absolute locations (in file system) of source folders for given and required projects. *//*from w w w .j ava 2s . c o m*/ public static void addSourceLocations(Set<IProject> visitedProjects, List<String> locations, IProject project) throws Exception { // may be not exists if (!project.exists()) { return; } // check for recursion if (visitedProjects.contains(project)) { return; } visitedProjects.add(project); // add source folders for IJavaProject { IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath entryPath = entry.getPath(); addAbsoluteLocation(locations, entryPath); } } } } // process required projects IProject[] referencedProjects = project.getReferencedProjects(); for (IProject referencedProject : referencedProjects) { addSourceLocations(visitedProjects, locations, referencedProject); } }
From source file:org.eclipse.wb.tests.designer.core.PdeProjectConversionUtils.java
License:Open Source License
private void loadClasspathEntries(IProject project, IProgressMonitor monitor) { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] currentClassPath = new IClasspathEntry[0]; List<String> sources = Lists.newArrayList(); List<String> libraries = Lists.newArrayList(); try {/*from www . ja v a 2s. co m*/ currentClassPath = javaProject.getRawClasspath(); } catch (JavaModelException e) { } for (int i = 0; i < currentClassPath.length; i++) { int contentType = currentClassPath[i].getEntryKind(); if (contentType == IClasspathEntry.CPE_SOURCE) { String relativePath = getRelativePath(currentClassPath[i], project); if (relativePath.equals("")) { //$NON-NLS-1$ sources.add("."); //$NON-NLS-1$ } else { sources.add(relativePath + "/"); //$NON-NLS-1$ } } else if (contentType == IClasspathEntry.CPE_LIBRARY) { String path = getRelativePath(currentClassPath[i], project); if (path.length() > 0) { libraries.add(path); } else { libraries.add("."); //$NON-NLS-1$ } } } fSrcEntries = sources.toArray(new String[sources.size()]); fLibEntries = libraries.toArray(new String[libraries.size()]); // IClasspathEntry[] classPath = new IClasspathEntry[currentClassPath.length + 1]; System.arraycopy(currentClassPath, 0, classPath, 0, currentClassPath.length); try { classPath[classPath.length - 1] = createContainerEntry(); javaProject.setRawClasspath(classPath, monitor); } catch (Throwable e) { } }