private IJavaProject getJavaProject(ILaunchConfiguration configuration) { try { return JavaRuntime.getJavaProject(configuration); } catch (CoreException e) { return null; } }
private void sameProjectOnly(Collection<IPackageFragmentRoot> filtered, final ILaunchConfiguration configuration) throws CoreException { final IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); if (javaProject != null) { for (final Iterator<IPackageFragmentRoot> i = filtered.iterator(); i .hasNext();) { if (!javaProject.equals(i.next().getJavaProject())) { i.remove(); } } } }
public Set<IPackageFragmentRoot> getOverallScope( ILaunchConfiguration configuration) throws CoreException { final IJavaProject project = JavaRuntime.getJavaProject(configuration); if (project == null) { return Collections.emptySet(); } else { return ScopeUtils.filterJREEntries(Arrays.asList(project .getAllPackageFragmentRoots())); } }
public IRuntimeClasspathEntry[] computeWebcontextClassPath( ILaunchConfiguration configuration) throws CoreException { IJavaProject proj = JavaRuntime.getJavaProject(configuration); if (proj == null) { Plugin.logError("No project!"); return new IRuntimeClasspathEntry[0]; } List<IRuntimeClasspathEntry> entryList = RunJettyRunClasspathUtil.getProjectClasspathsForUserlibs(proj, false); return (IRuntimeClasspathEntry[]) entryList.toArray(new IRuntimeClasspathEntry[0]); }
public List<IRuntimeClasspathEntry> getDefaultScanList(ILaunchConfiguration configuration) throws CoreException { IJavaProject proj = JavaRuntime.getJavaProject(configuration); if (proj == null) { Plugin.logError("No project!"); return new ArrayList<IRuntimeClasspathEntry>(); } Set<String> locations = getScanLocations(configuration,proj); List<IRuntimeClasspathEntry> scanlist = new ArrayList<IRuntimeClasspathEntry>(); for(String location:locations){ scanlist.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(location))); } return scanlist; }
public Set<String> getCustomScanPathList(ILaunchConfiguration configuration) throws CoreException { IJavaProject proj = JavaRuntime.getJavaProject(configuration); if (proj == null) { Plugin.logError("No project!"); return new HashSet<String>(); } IRuntimeClasspathEntry[] customEntries = computeUnresolvedCustomClasspath(configuration, Plugin.ATTR_CUSTOM_SCAN_FOLDER); Set<String> locations = new HashSet<String>(); for(IRuntimeClasspathEntry entry:customEntries){ locations.add(entry.getLocation()); } return locations; }
/** * @see IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration) */ public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException { fSourceLocator.initializeDefaults(configuration); fJavaProject = JavaRuntime.getJavaProject(configuration); fIsFindAllSourceElements = configuration.getAttribute(ATTR_FIND_ALL_SOURCE_ELEMENTS, false); }
public Set<String> getAllScanPathList(ILaunchConfiguration configuration) throws CoreException { IJavaProject proj = JavaRuntime.getJavaProject(configuration); if (proj == null) { Plugin.logError("No project!"); return new HashSet<String>(); } Set<String> locations = getScanLocations(configuration,proj); locations.addAll(getCustomScanPathList(configuration)); return locations; } public Set<String> getCustomScanPathList(ILaunchConfiguration configuration)
/** * Performs default resolution for a container entry. * Delegates to the Java model. * @param entry the {@link IRuntimeClasspathEntry} to compute default container entries for * @param config the backing {@link ILaunchConfiguration} * @return the complete listing of default container entries or an empty list, never <code>null</code> * @throws CoreException if the computation encounters a problem */ private static IRuntimeClasspathEntry[] computeDefaultContainerEntries(IRuntimeClasspathEntry entry, ILaunchConfiguration config) throws CoreException { IJavaProject project = entry.getJavaProject(); if (project == null) { project = getJavaProject(config); } return computeDefaultContainerEntries(entry, project); }
/** * Performs default resolution for a container entry. Delegates to the Java model. * * @param entry * the {@link IRuntimeClasspathEntry} to compute default container entries for * @param config * the backing {@link ILaunchConfiguration} * @param excludeTestCode * if true, output folders corresponding to test sources and test dependencies are excluded * @return the complete listing of default container entries or an empty list, never <code>null</code> * @throws CoreException * if the computation encounters a problem */ private static IRuntimeClasspathEntry[] computeDefaultContainerEntries(IRuntimeClasspathEntry entry, ILaunchConfiguration config, boolean excludeTestCode) throws CoreException { IJavaProject project = entry.getJavaProject(); if (project == null) { project = getJavaProject(config); } return computeDefaultContainerEntries(entry, project, excludeTestCode); }
private IRuntimeClasspathEntry[] filterUnusedDependencies(ILaunchConfiguration configuration, IRuntimeClasspathEntry[] entriesToFilter) throws CoreException { // if the run configuration uses Java 9 then the library dependencies are already present in the // unresolved classpath. That is because the Java 9 support calculates the class/module path from // the result of IJavaProject.getResolvedClasspath(true). Unfortunately, the runtime entries don't // have the source set attribute, so we have to filter them base on entry paths. IJavaProject project = JavaRuntime.getJavaProject(configuration); IClasspathEntry[] classpath = project.getResolvedClasspath(true); LaunchConfigurationScope configurationScopes = LaunchConfigurationScope.from(configuration); Set<IPath> excludedPaths = Sets.newHashSet(); for (IClasspathEntry entry : classpath) { if (!configurationScopes.isEntryIncluded(entry)) { excludedPaths.add(entry.getPath()); } } List<IRuntimeClasspathEntry> result = new ArrayList<>(entriesToFilter.length); for (IRuntimeClasspathEntry entry : entriesToFilter) { if (!excludedPaths.contains(entry.getPath())) { result.add(entry); } } return result.toArray(new IRuntimeClasspathEntry[0]); }
public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException { boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_SOURCE_PATH, true); IRuntimeClasspathEntry[] entries = null; if (useDefault) { // the default source lookup path is the classpath of the associated project IJavaProject project = JavaRuntime.getJavaProject(configuration); entries = JavaRuntime.computeUnresolvedRuntimeClasspath(project); } else { // recover persisted source path entries = recoverRuntimePath(configuration, IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH); } return entries; } }
/** * Return the String representation of the default output directory of the * launch config's project or <code>null</code> if there is no configuration, no * project or some sort of problem. * @param config the {@link ILaunchConfiguration} * * @return the default output directory for the specified launch * configuration's project * @since 2.1 */ public static String getProjectOutputDirectory(ILaunchConfiguration config) { try { if (config != null) { IJavaProject javaProject = JavaRuntime.getJavaProject(config); if (javaProject != null) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath outputLocation = javaProject.getOutputLocation(); IResource resource = root.findMember(outputLocation); if (resource != null) { IPath path = resource.getFullPath(); if (path != null) { return path.makeRelative().toString(); } } } } } catch (CoreException ce) { } return null; }
public static IRuntimeClasspathEntry[] resolveClasspath(IRuntimeClasspathEntry[] entries,ILaunchConfiguration configuration ) throws CoreException { IJavaProject proj = JavaRuntime.getJavaProject(configuration); if (proj == null) { Plugin.logError("No project!"); return entries; } return resolvedProjectClasspath(entries,configuration,ProjectUtil.isMavenProject(proj.getProject())); }
/** * Get the default VMInstall name using the available info in the config, * using the JavaProject if available. * * @param configuration * Launch configuration to check * @return name of the VMInstall * @throws CoreException * thrown if there's a problem getting the VM name */ public static String getDefaultVMInstallName(ILaunchConfiguration configuration) throws CoreException { IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); IVMInstall vmInstall = null; if (javaProject != null) { vmInstall = JavaRuntime.getVMInstall(javaProject); } if (vmInstall != null) { return vmInstall.getName(); } return VMUtil.getDefaultVMInstallName(); }
@Override public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { // build project list if (monitor != null) { monitor.subTask(LaunchingMessages.AbstractJavaLaunchConfigurationDelegate_20); } fOrderedProjects = null; IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); if (javaProject != null) { fOrderedProjects = computeReferencedBuildOrder(new IProject[]{javaProject .getProject()}); } // do generic launch checks return super.preLaunchCheck(configuration, mode, monitor); }
@Override public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { // build project list if (monitor != null) { monitor.subTask(LaunchingMessages.AbstractJavaLaunchConfigurationDelegate_20); } fOrderedProjects = null; IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); if (javaProject != null) { fOrderedProjects = computeReferencedBuildOrder(new IProject[]{javaProject .getProject()}); } // do generic launch checks return super.preLaunchCheck(configuration, mode, monitor); }
/** * Returns the associated container or <code>null</code> if unavailable. * * @return classpath container or <code>null</code> * @throws CoreException if unable to retrieve container */ public IClasspathContainer getClasspathContainer() throws CoreException { ISourceLookupDirector director = getDirector(); if (director != null) { ILaunchConfiguration configuration = director.getLaunchConfiguration(); if (configuration != null) { IJavaProject project = JavaRuntime.getJavaProject(configuration); if (project != null) { return JavaCore.getClasspathContainer(getPath(), project); } } } return null; }
/** * Sets the default working directory */ protected void setDefaultWorkingDir() { try { ILaunchConfiguration config = getLaunchConfiguration(); if (config != null) { IJavaProject javaProject = JavaRuntime.getJavaProject(config); if (javaProject != null) { setDefaultWorkingDirectoryText("${workspace_loc:" + javaProject.getPath().makeRelative().toOSString() + "}"); //$NON-NLS-1$//$NON-NLS-2$ return; } } } catch (CoreException ce) {} setDefaultWorkingDirectoryText(System.getProperty("user.dir")); //$NON-NLS-1$ }
/** * Returns the associated container or <code>null</code> if unavailable. * * @return classpath container or <code>null</code> * @throws CoreException if unable to retrieve container */ public IClasspathContainer getClasspathContainer() throws CoreException { ISourceLookupDirector director = getDirector(); if (director != null) { ILaunchConfiguration configuration = director.getLaunchConfiguration(); if (configuration != null) { IJavaProject project = JavaRuntime.getJavaProject(configuration); if (project != null) { return JavaCore.getClasspathContainer(getPath(), project); } } } return null; }