本文整理汇总了Java中org.eclipse.jdt.launching.JavaRuntime.getJavaProject方法的典型用法代码示例。如果您正苦于以下问题:Java JavaRuntime.getJavaProject方法的具体用法?Java JavaRuntime.getJavaProject怎么用?Java JavaRuntime.getJavaProject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.launching.JavaRuntime
的用法示例。
在下文中一共展示了JavaRuntime.getJavaProject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeUnresolvedClasspath
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
@Override
public IRuntimeClasspathEntry[] computeUnresolvedClasspath(final ILaunchConfiguration configuration)
throws CoreException {
boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
if(useDefault) {
IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
IRuntimeClasspathEntry jreEntry = JavaRuntime.computeJREEntry(configuration);
IRuntimeClasspathEntry projectEntry = JavaRuntime.newProjectRuntimeClasspathEntry(javaProject);
IRuntimeClasspathEntry mavenEntry = JavaRuntime.newRuntimeContainerClasspathEntry(new Path(
IClasspathManager.CONTAINER_ID), IRuntimeClasspathEntry.USER_CLASSES);
if(jreEntry == null) {
return new IRuntimeClasspathEntry[] {projectEntry, mavenEntry};
}
return new IRuntimeClasspathEntry[] {jreEntry, projectEntry, mavenEntry};
}
return recoverRuntimePath(configuration, IJavaLaunchConfigurationConstants.ATTR_CLASSPATH);
}
示例2: resolveClasspath0
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
IRuntimeClasspathEntry[] resolveClasspath0(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration,
IProgressMonitor monitor) throws CoreException {
int scope = getArtifactScope(configuration);
Set<IRuntimeClasspathEntry> all = new LinkedHashSet<>(entries.length);
for(IRuntimeClasspathEntry entry : entries) {
if(entry.getType() == IRuntimeClasspathEntry.CONTAINER
&& MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) {
addMavenClasspathEntries(all, entry, configuration, scope, monitor);
} else if(entry.getType() == IRuntimeClasspathEntry.PROJECT) {
IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
if(javaProject.getPath().equals(entry.getPath())) {
addProjectEntries(all, entry.getPath(), scope, THIS_PROJECT_CLASSIFIER, configuration, monitor);
} else {
addStandardClasspathEntries(all, entry, configuration);
}
} else {
addStandardClasspathEntries(all, entry, configuration);
}
}
return all.toArray(new IRuntimeClasspathEntry[all.size()]);
}
示例3: addMavenClasspathEntries
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
private void addMavenClasspathEntries(Set<IRuntimeClasspathEntry> resolved,
IRuntimeClasspathEntry runtimeClasspathEntry, ILaunchConfiguration configuration, int scope,
IProgressMonitor monitor) throws CoreException {
IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
MavenJdtPlugin plugin = MavenJdtPlugin.getDefault();
IClasspathManager buildpathManager = plugin.getBuildpathManager();
IClasspathEntry[] cp = buildpathManager.getClasspath(javaProject.getProject(), scope, false, monitor);
for(IClasspathEntry entry : cp) {
switch(entry.getEntryKind()) {
case IClasspathEntry.CPE_PROJECT:
addProjectEntries(resolved, entry.getPath(), scope, getArtifactClassifier(entry), configuration, monitor);
break;
case IClasspathEntry.CPE_LIBRARY:
resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()));
break;
// case IClasspathEntry.CPE_SOURCE:
// resolved.add(newSourceClasspathEntry(javaProject, cp[i]));
// break;
}
}
}
示例4: resolveClasspath
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
@Override
public IRuntimeClasspathEntry[] resolveClasspath(IRuntimeClasspathEntry[] entries,
ILaunchConfiguration configuration) throws CoreException {
IRuntimeClasspathEntry[] resolvedEntries = super.resolveClasspath(entries, configuration);
IJavaProject proj = JavaRuntime.getJavaProject(configuration);
if (proj == null) {
return resolvedEntries;
}
List<IRuntimeClasspathEntry> resolvedEntriesList =
new ArrayList<IRuntimeClasspathEntry>(Arrays.asList(resolvedEntries));
return resolvedEntriesList.toArray(new IRuntimeClasspathEntry[resolvedEntriesList.size()]);
}
示例5: isValid
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
@Override
public boolean isValid(ILaunchConfiguration config) {
try {
IJavaProject javaProject = JavaRuntime.getJavaProject(getCurrentLaunchConfiguration());
if (javaProject != null
&& !GWTNature.isGWTProject(javaProject.getProject())) {
setErrorMessage("Selected project does not have GWT enabled.");
return false;
}
} catch (CoreException e) {
GWTPluginLog.logError(e);
}
return super.isValid(config);
}
示例6: isValid
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
setErrorMessage(null);
setMessage(null);
if (!super.isValid(launchConfig)) {
return false;
}
IProject project;
try {
IJavaProject javaProject = JavaRuntime.getJavaProject(launchConfig);
if (javaProject == null) {
return false;
}
project = javaProject.getProject();
} catch (CoreException ce) {
// Thrown if the Java project does not exist, which is not of concern in
// this tab (the Main tab handles those error messages)
return false;
}
return true;
}
示例7: computeUnresolvedClasspath
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
@Override
public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException
{
boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
if (!useDefault)
{
// recover persisted classpath
return recoverRuntimePath(configuration, IJavaLaunchConfigurationConstants.ATTR_CLASSPATH);
}
Path lcp = new Path(LeJOSEV3LibContainer.ID+"/"+LeJOSEV3Util.LIBSUBDIR_EV3);
IJavaProject proj = JavaRuntime.getJavaProject(configuration);
if (proj == null)
{
IRuntimeClasspathEntry rte = JavaRuntime.newRuntimeContainerClasspathEntry(lcp, IRuntimeClasspathEntry.STANDARD_CLASSES);
return new IRuntimeClasspathEntry[] { rte };
}
return JavaRuntime.computeUnresolvedRuntimeClasspath(proj);
}
示例8: sameProjectOnly
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
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();
}
}
}
}
示例9: getOverallScope
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
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()));
}
}
示例10: getArtifactScope
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
protected int getArtifactScope(ILaunchConfiguration configuration) throws CoreException {
String typeid = configuration.getType().getAttribute("id"); //$NON-NLS-1$
if(JDT_JAVA_APPLICATION.equals(typeid) || "org.jboss.tools.servers.wildfly.swarm.core.serverLaunchConfig".equals(typeid)) {
IResource[] resources = configuration.getMappedResources();
// MNGECLIPSE-530: NPE starting openarchitecture workflow
if(resources == null || resources.length == 0) {
return IClasspathManager.CLASSPATH_RUNTIME;
}
// ECLIPSE-33: applications from test sources should use test scope
final Set<IPath> testSources = new HashSet<>();
IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
IMavenProjectFacade facade = projectManager.create(javaProject.getProject(), new NullProgressMonitor());
if(facade == null) {
return IClasspathManager.CLASSPATH_RUNTIME;
}
testSources.addAll(Arrays.asList(facade.getTestCompileSourceLocations()));
for(int i = 0; i < resources.length; i++ ) {
for(IPath testPath : testSources) {
if(testPath.isPrefixOf(resources[i].getProjectRelativePath())) {
return IClasspathManager.CLASSPATH_TEST;
}
}
}
return IClasspathManager.CLASSPATH_RUNTIME;
} else if(JDT_JUNIT_TEST.equals(typeid) || JDT_TESTNG_TEST.equals(typeid)) {
return IClasspathManager.CLASSPATH_TEST;
} else {
throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, 0, NLS.bind(
Messages.MavenRuntimeClasspathProvider_error_unsupported, typeid), null));
}
}
示例11: getJavaProject
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
/**
* @return the Java project, or null
*/
public static IJavaProject getJavaProject(
ILaunchConfiguration launchConfiguration) {
try {
return JavaRuntime.getJavaProject(launchConfiguration);
} catch (CoreException e) {
// When the attribute holding the Java project had an issue, assume no
// Java project
return null;
}
}
示例12: getProject
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
private IProject getProject(LaunchConfiguration launchConfig) {
if (launchConfig == null) {
return null;
}
ILaunch launch = launchConfig.getLaunch();
if (launch == null) {
return null;
}
ILaunchConfiguration lc = launch.getLaunchConfiguration();
if (lc == null) {
return null;
}
IJavaProject project;
try {
project = JavaRuntime.getJavaProject(lc);
} catch (CoreException e) {
return null;
}
if (project == null) {
return null;
}
return project.getProject();
}
示例13: setupLaunchConfiguration
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
@Override
public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor)
throws CoreException {
IServer server = ServerUtil.getServer(workingCopy);
if (server == null) {
return;
}
String projectName = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null);
if (projectName == null) {
projectName = server.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null);
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
}
IJavaProject proj = JavaRuntime.getJavaProject(workingCopy);
Collection<String> mainClasses = MainClassDetector.findMainClasses(proj, monitor);
if (mainClasses.isEmpty()) {
return;
}
if ( mainClasses.size() > 1) {
//TODO handle multiple Main classes
}
String mainClass = mainClasses.iterator().next();
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainClass);
StringBuilder vmArgs = new StringBuilder(DEVAULT_VM_ARGS);
int targetPort = 8080;
int portOffset = SocketUtil.detectPortOffset(targetPort);
if (portOffset > 0) {
targetPort += portOffset;
vmArgs.append(" -Dswarm.port.offset=").append(portOffset);
}
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs.toString());
final ControllableServerBehavior behavior = (ControllableServerBehavior)JBossServerBehaviorUtils.getControllableBehavior(server);
//TODO parse Main class AST to detect default context root?
if (behavior != null) {
//XXX seems weird/wrong
behavior.putSharedData("welcomePage", "http://localhost:"+targetPort+"/");
}
//if m2e project only
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, "org.jboss.tools.servers.wildfly.swarm.launchconfig.classpathProvider");
}
示例14: computeUnresolvedClasspath
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
@Override
public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration config)
throws CoreException {
IRuntimeClasspathEntry[] unresolvedClasspathEntries = super.computeUnresolvedClasspath(config);
IJavaProject proj = JavaRuntime.getJavaProject(config);
if (proj == null) {
return unresolvedClasspathEntries;
}
/*
* Figure out if we are supposed to be relying on the default classpath or not. The default
* classpath is the one that is generated for a launch configuration based on the launch
* configuration's project's build classpath.
*
* To determine whether or not to rely on the default classpath, we look at the
* ATTR_DEFAULT_CLASSPATH attribute of the launch configuration. This attribute is set whenever
* the user makes a change to the launch configuration classpath using the add/remove buttons.
* From this point on, Eclipse will respect the user's changes and will not replace their
* entries with the classpath that it computes.
*
* However, users can specify that they want to restore the behavior of having Eclipse compute
* the classpath by clicking on the "Restore Default Entries" button. This causes the
* ATTR_DEFAULT_ATTRIBUTE to be unset for a launch configuration.
*/
boolean useDefault =
config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
if (!useDefault) {
return unresolvedClasspathEntries;
}
if (!MavenUtils.hasMavenNature(proj.getProject())) {
return unresolvedClasspathEntries;
}
// Use a LinkedHashSet to prevent dupes
Set<IRuntimeClasspathEntry> classpath =
new LinkedHashSet<IRuntimeClasspathEntry>(unresolvedClasspathEntries.length);
classpath.addAll(Arrays.asList(unresolvedClasspathEntries));
// Add GWT dev jar
if (GWTNature.isGWTProject(proj.getProject())) {
addGwtDevjarIfPossible(proj, classpath);
}
IRuntimeClasspathEntry[] resolvedEntries =
classpath.toArray(new IRuntimeClasspathEntry[classpath.size()]);
return resolvedEntries;
}
示例15: computeUnresolvedClasspath
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
@Override
public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration config) throws CoreException {
IRuntimeClasspathEntry[] unresolvedClasspathEntries = super.computeUnresolvedClasspath(config);
IJavaProject proj = JavaRuntime.getJavaProject(config);
if (proj == null || !GWTNature.isGWTProject(proj.getProject())) {
// Only GWT projects require source folders to be computed
return unresolvedClasspathEntries;
}
/*
* Figure out if we are supposed to be relying on the default classpath or not. The default
* classpath is the one that is generated for a launch configuration based on the launch
* configuration's project's build classpath.
*
* To determine whether or not to rely on the default classpath, we look at the
* ATTR_DEFAULT_CLASSPATH attribute of the launch configuration. This attribute is set whenever
* the user makes a change to the launch configuration classpath using the add/remove buttons.
* From this point on, Eclipse will respect the user's changes and will not replace their
* entries with the classpath that it computes.
*
* However, users can specify that they want to restore the behavior of having Eclipse compute
* the classpath by clicking on the "Restore Default Entries" button. This causes the
* ATTR_DEFAULT_ATTRIBUTE to be unset for a launch configuration.
*/
boolean useDefault = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
if (!useDefault) {
return unresolvedClasspathEntries;
}
/*
* Compute the default classpath for the launch configuration. Note that all of the entries for
* the default classpath DO NOT appear under the 'default entries' section. This is because we
* are going to be adding the GWT-related source paths to the classpath, and we want to give
* users the opportunity to tweak them. If we add them to the 'default entries' section, they
* will be unable to tweak them.
*
* You might think that adding the source paths to the non-default section would cause Eclipse
* to think that the user actually modified the classpath, thereby causing the
* ATTR_DEFAULT_CLASSPATH attribute to be changed. This is not the case; this attribute is only
* changed based on UI interaction, so it is safe for us to add entries to the non-default
* section programmatically.
*/
ArrayList<IRuntimeClasspathEntry> defaultRuntimeClasspathEntries = new ArrayList<IRuntimeClasspathEntry>();
defaultRuntimeClasspathEntries.addAll(Arrays.asList(unresolvedClasspathEntries));
/*
* Now, record the source folder(s) of each of the transitively required projects.
*
* Make sure that the source paths come before the default classpath entries so users can
* override GWT functionality. They also must appear after any existing bootstrap entries (e.g.
* the JRE), since that's the order the JavaClasspathTab will expect them to be in when it goes
* to calculate whether or not the configured classpath = default.
*/
int srcPathsInsertionIndex = findIndexOfFirstUserEntry(defaultRuntimeClasspathEntries);
try {
defaultRuntimeClasspathEntries.addAll(
srcPathsInsertionIndex,
GWTProjectUtilities.getGWTSourceFolderPathsFromProjectAndDependencies(proj,
GWTJUnitLaunchDelegate.isJUnitLaunchConfig(config.getType())));
} catch (SdkException e) {
GWTPluginLog.logError(e);
}
return defaultRuntimeClasspathEntries.toArray(new IRuntimeClasspathEntry[defaultRuntimeClasspathEntries.size()]);
}