Java Code Examples for org.eclipse.jdt.launching.JavaRuntime#computeUnresolvedRuntimeClasspath()

The following examples show how to use org.eclipse.jdt.launching.JavaRuntime#computeUnresolvedRuntimeClasspath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavadocStandardWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void collectReferencedElements(IJavaProject project, HashSet<JavadocLinkRef> result) throws CoreException {
	IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(project);
	for (int i= 0; i < unresolved.length; i++) {
		IRuntimeClasspathEntry curr= unresolved[i];
		if (curr.getType() == IRuntimeClasspathEntry.PROJECT) {
			result.add(new JavadocLinkRef(JavaCore.create((IProject) curr.getResource())));
		} else {
			IRuntimeClasspathEntry[] entries= JavaRuntime.resolveRuntimeClasspathEntry(curr, project);
			for (int k = 0; k < entries.length; k++) {
				IRuntimeClasspathEntry entry= entries[k];
				if (entry.getType() == IRuntimeClasspathEntry.PROJECT) {
					result.add(new JavadocLinkRef(JavaCore.create((IProject) entry.getResource())));
				} else if (entry.getType() == IRuntimeClasspathEntry.ARCHIVE) {
					IClasspathEntry classpathEntry= entry.getClasspathEntry();
					if (classpathEntry != null) {
						IPath containerPath= null;
						if (curr.getType() == IRuntimeClasspathEntry.CONTAINER) {
							containerPath= curr.getPath();
						}
						result.add(new JavadocLinkRef(containerPath, classpathEntry, project));
					}
				}
			}
		}
	}
}
 
Example 2
Source File: FatJarPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IPath[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
	IRuntimeClasspathEntry[] entries= JavaRuntime.computeUnresolvedRuntimeClasspath(configuration);
	entries= JavaRuntime.resolveRuntimeClasspath(entries, configuration);

	ArrayList<IPath> userEntries= new ArrayList<IPath>(entries.length);
	for (int i= 0; i < entries.length; i++) {
		if (entries[i].getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {

			String location= entries[i].getLocation();
			if (location != null) {
				IPath entry= Path.fromOSString(location);
				if (!userEntries.contains(entry)) {
					userEntries.add(entry);
				}
			}
		}
	}
	return userEntries.toArray(new IPath[userEntries.size()]);
}
 
Example 3
Source File: FatJarAntExporter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IPath[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
	IRuntimeClasspathEntry[] entries= JavaRuntime.computeUnresolvedRuntimeClasspath(configuration);
	entries= JavaRuntime.resolveRuntimeClasspath(entries, configuration);

	ArrayList<IPath> userEntries= new ArrayList<IPath>(entries.length);
	for (int i= 0; i < entries.length; i++) {
		if (entries[i].getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {

			String location= entries[i].getLocation();
			if (location != null) {
				IPath entry= Path.fromOSString(location);
				if (!userEntries.contains(entry)) {
					userEntries.add(entry);
				}
			}
		}
	}
	return userEntries.toArray(new IPath[userEntries.size()]);
}
 
Example 4
Source File: AbstractSARLLaunchConfigurationDelegate.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Compute the class path for the given launch configuration.
 *
 * @param configuration the configuration that provides the classpath.
 * @param configAccessor the accessor to the SRE configuration.
 * @param projectAccessor the accessor to the Java project.
 * @return the filtered entries.
 * @throws CoreException if impossible to get the classpath.
 */
public static IRuntimeClasspathEntry[] computeUnresolvedSARLRuntimeClasspath(ILaunchConfiguration configuration,
		ILaunchConfigurationAccessor configAccessor,
		IJavaProjectAccessor projectAccessor) throws CoreException {
	// Get the classpath from the configuration.
	final IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(configuration);
	//
	final List<IRuntimeClasspathEntry> filteredEntries = new ArrayList<>();
	List<IRuntimeClasspathEntry> sreClasspathEntries = null;
	// Filtering the entries by replacing the "SARL Libraries" with the SARL runtime environment.
	for (final IRuntimeClasspathEntry entry : entries) {
		if (entry.getPath().equals(SARLClasspathContainerInitializer.CONTAINER_ID)) {
			if (sreClasspathEntries == null) {
				sreClasspathEntries = getSREClasspathEntries(configuration, configAccessor, projectAccessor);
			}
			filteredEntries.addAll(sreClasspathEntries);
		} else {
			filteredEntries.add(entry);
		}
	}
	return filteredEntries.toArray(new IRuntimeClasspathEntry[filteredEntries.size()]);
}
 
Example 5
Source File: FixedFatJarExportPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
protected IPath[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
	IRuntimeClasspathEntry[] entries= JavaRuntime.computeUnresolvedRuntimeClasspath(configuration);
	entries= JavaRuntime.resolveRuntimeClasspath(entries, configuration);

	boolean isModularConfig= JavaRuntime.isModularConfiguration(configuration);
	ArrayList<IPath> userEntries= new ArrayList<>(entries.length);
	for (int i= 0; i < entries.length; i++) {
		int classPathProperty= entries[i].getClasspathProperty();
		if ((!isModularConfig && classPathProperty == IRuntimeClasspathEntry.USER_CLASSES)
				|| (isModularConfig && (classPathProperty == IRuntimeClasspathEntry.CLASS_PATH || classPathProperty == IRuntimeClasspathEntry.MODULE_PATH))) {

			String location= entries[i].getLocation();
			if (location != null) {
				IPath entry= Path.fromOSString(location);
				if (!userEntries.contains(entry)) {
					userEntries.add(entry);
				}
			}
		}
	}
	return userEntries.toArray(new IPath[userEntries.size()]);
}
 
Example 6
Source File: ResolveClasspathsHandler.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Compute runtime classpath of a java project.
 *
 * @param javaProject java project
 * @param excludeTestCode whether to exclude the test code and test dependencies
 * @param mappedResources the associated resources with the application
 * @return class path
 * @throws CoreException
 *             CoreException
 */
private static String[][] computeClassPath(IJavaProject javaProject, String mainType, boolean excludeTestCode, List<IResource> mappedResources)
        throws CoreException {
    if (javaProject == null) {
        throw new IllegalArgumentException("javaProject is null");
    }

    ILaunchConfiguration launchConfig = new JavaApplicationLaunchConfiguration(javaProject.getProject(), mainType, excludeTestCode, mappedResources);
    IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(launchConfig);
    IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveRuntimeClasspath(unresolved, launchConfig);
    Set<String> classpaths = new LinkedHashSet<>();
    Set<String> modulepaths = new LinkedHashSet<>();
    for (IRuntimeClasspathEntry entry : resolved) {
        String location = entry.getLocation();
        if (location != null) {
            if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES
                    || entry.getClasspathProperty() == IRuntimeClasspathEntry.CLASS_PATH) {
                classpaths.add(location);
            } else if (entry.getClasspathProperty() == IRuntimeClasspathEntry.MODULE_PATH) {
                modulepaths.add(location);
            }
        }
    }

    return new String[][] {
        modulepaths.toArray(new String[modulepaths.size()]),
        classpaths.toArray(new String[classpaths.size()])
    };
}
 
Example 7
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 4 votes vote down vote up
private static ISourceContainer[] getSourceContainers(IJavaProject project, Set<IRuntimeClasspathEntry> calculated) {
    if (project == null || !project.exists()) {
        return new ISourceContainer[0];
    }

    try {
        IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(project);
        List<IRuntimeClasspathEntry> resolved = new ArrayList<>();
        for (IRuntimeClasspathEntry entry : unresolved) {
            for (IRuntimeClasspathEntry resolvedEntry : JavaRuntime.resolveRuntimeClasspathEntry(entry, project)) {
                if (!calculated.contains(resolvedEntry)) {
                    calculated.add(resolvedEntry);
                    resolved.add(resolvedEntry);
                }
            }
        }
        Set<ISourceContainer> containers = new LinkedHashSet<>();
        containers.addAll(Arrays.asList(
                JavaRuntime.getSourceContainers(resolved.toArray(new IRuntimeClasspathEntry[0]))));

        // Due to a known jdt java 9 support bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=525840,
        // it would miss some JRE libraries source containers when the debugger is running on JDK9.
        // As a workaround, recompute the possible source containers for JDK9 jrt-fs.jar libraries.
        IRuntimeClasspathEntry jrtFs = resolved.stream().filter(entry -> {
            return entry.getType() == IRuntimeClasspathEntry.ARCHIVE && entry.getPath().lastSegment().equals("jrt-fs.jar");
        }).findFirst().orElse(null);
        if (jrtFs != null && project.isOpen()) {
            IPackageFragmentRoot[] allRoots = project.getPackageFragmentRoots();
            for (IPackageFragmentRoot root : allRoots) {
                if (root.getPath().equals(jrtFs.getPath()) && isSourceAttachmentEqual(root, jrtFs)) {
                    containers.add(new PackageFragmentRootSourceContainer(root));
                }
            }
        }

        return containers.toArray(new ISourceContainer[0]);
    } catch (CoreException ex) {
     // do nothing.
    }

    return new ISourceContainer[0];
}