use of org.eclipse.jdt.launching.IRuntimeClasspathEntry in project jop by jop-devel.
the class JOPizer method createJOPizeLaunchConfiguration.
private ILaunchConfiguration createJOPizeLaunchConfiguration(String programArguments) throws CoreException {
String configName = "JOPize";
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
for (ILaunchConfiguration config : configs) {
if (config.getName().equals(configName)) {
config.delete();
break;
}
}
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, configName);
IVMInstall defaultVMInstall = JavaRuntime.getDefaultVMInstall();
Map attributes = workingCopy.getAttributes();
attributes.put(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "com.jopdesign.build.JOPizer");
attributes.put(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArguments);
IPreferenceStore prefs = JOPUIPlugin.getDefault().getPreferenceStore();
String jopHome = prefs.getString(IJOPLaunchConfigurationConstants.ATTR_JOP_HOME);
IPath jopTools = new Path(jopHome).append(new Path("java/tools/dist/lib/jop-tools.jar"));
IRuntimeClasspathEntry jopToolsEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(jopTools);
jopToolsEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
IPath jopClasses = new Path(jopHome).append(new Path("java/target/dist/lib/classes.zip"));
IRuntimeClasspathEntry jopClassesEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(jopClasses);
jopClassesEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
// IClasspathEntry jreEntry = JavaRuntime.getDefaultJREContainerEntry();
List<String> classpath = new ArrayList<String>();
classpath.add(jopToolsEntry.getMemento());
classpath.add(jopClassesEntry.getMemento());
// classpath.add(jreEntry.get)
attributes.put(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath);
attributes.put(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
attributes.put(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "-Dmgci=false");
workingCopy.setAttributes(attributes);
System.err.printf("> %s%n", workingCopy.toString());
return workingCopy;
}
use of org.eclipse.jdt.launching.IRuntimeClasspathEntry in project sling by apache.
the class JVMDebuggerConnection method connectInDebugMode.
boolean connectInDebugMode(ILaunch launch, IServer iServer, IProgressMonitor monitor) throws CoreException {
long start = System.currentTimeMillis();
this.launch = launch;
boolean success = false;
IVMConnector connector = null;
connector = JavaRuntime.getVMConnector(IJavaLaunchConfigurationConstants.ID_SOCKET_ATTACH_VM_CONNECTOR);
if (connector == null) {
connector = JavaRuntime.getDefaultVMConnector();
}
if (connector == null) {
throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "Could not get jvm connctor"));
}
ISlingLaunchpadServer launchpadServer = (ISlingLaunchpadServer) iServer.loadAdapter(SlingLaunchpadServer.class, monitor);
ISlingLaunchpadConfiguration configuration = launchpadServer.getConfiguration();
int debugPort = configuration.getDebugPort();
if (debugPort <= 0) {
throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "debug port not configured"));
}
Map<String, String> connectMap = new HashMap<>();
connectMap.put("hostname", iServer.getHost());
connectMap.put("port", String.valueOf(debugPort));
// Map argMap = null;//configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, (Map)null);
int connectTimeout = JavaRuntime.getPreferences().getInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
//$NON-NLS-1$
connectMap.put("timeout", Integer.toString(connectTimeout));
// set the default source locator if required
@SuppressWarnings("restriction") ISourceLookupDirector sourceLocator = new JavaSourceLookupDirector();
sourceLocator.setSourcePathComputer(DebugPlugin.getDefault().getLaunchManager().getSourcePathComputer(//$NON-NLS-1$
"org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer"));
List<IRuntimeClasspathEntry> classpathEntries = new ArrayList<>();
// 1. add java projects first
for (IJavaProject javaProject : ProjectHelper.getAllJavaProjects()) {
classpathEntries.add(JavaRuntime.newProjectRuntimeClasspathEntry(javaProject));
}
// 2. add the other modules deployed on server
// 5/30
ProgressUtils.advance(monitor, 5);
// 30 - 5 - 1
int workTicksForReferences = 24;
SourceReferenceResolver resolver = Activator.getDefault().getSourceReferenceResolver();
if (resolver != null && configuration.resolveSourcesInDebugMode()) {
try {
List<SourceReference> references = osgiClient.findSourceReferences();
SubMonitor subMonitor = SubMonitor.convert(monitor, "Resolving source references", workTicksForReferences).setWorkRemaining(references.size());
for (SourceReference reference : references) {
try {
subMonitor.setTaskName("Resolving source reference: " + reference);
IRuntimeClasspathEntry classpathEntry = resolver.resolve(reference);
if (classpathEntry != null) {
classpathEntries.add(classpathEntry);
}
ProgressUtils.advance(subMonitor, 1);
} catch (CoreException e) {
// don't fail the debug launch for artifact resolution errors
Activator.getDefault().getPluginLogger().warn("Failed resolving source reference", e);
}
}
// 29/30
subMonitor.done();
} catch (OsgiClientException e1) {
throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, e1.getMessage(), e1));
}
} else {
monitor.worked(workTicksForReferences);
}
// 3. add the JRE entry
classpathEntries.add(JavaRuntime.computeJREEntry(launch.getLaunchConfiguration()));
IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(classpathEntries.toArray(new IRuntimeClasspathEntry[0]), launch.getLaunchConfiguration());
sourceLocator.setSourceContainers(JavaRuntime.getSourceContainers(resolved));
sourceLocator.initializeParticipants();
launch.setSourceLocator(sourceLocator);
// connect to remote VM
try {
// 30/30
connector.connect(connectMap, monitor, launch);
success = true;
long elapsedMillis = System.currentTimeMillis() - start;
Activator.getDefault().getPluginLogger().tracePerformance("Debug connection to {0}", elapsedMillis, iServer.getName());
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "could not establish debug connection to " + iServer.getHost() + " : " + debugPort, e));
}
return success;
}
use of org.eclipse.jdt.launching.IRuntimeClasspathEntry in project sling by apache.
the class MavenSourceReferenceResolver method resolve.
@Override
public IRuntimeClasspathEntry resolve(SourceReference reference) throws CoreException {
if (reference == null || reference.getType() != SourceReference.Type.MAVEN) {
return null;
}
MavenSourceReference sr = (MavenSourceReference) reference;
List<ArtifactRepository> repos = MavenPlugin.getMaven().getArtifactRepositories();
Artifact jarArtifact = MavenPlugin.getMaven().resolve(sr.getGroupId(), sr.getArtifactId(), sr.getVersion(), "jar", "", repos, new NullProgressMonitor());
Artifact sourcesArtifact = MavenPlugin.getMaven().resolve(sr.getGroupId(), sr.getArtifactId(), sr.getVersion(), "jar", "sources", repos, new NullProgressMonitor());
IPath jarPath = Path.fromOSString(jarArtifact.getFile().getAbsolutePath());
IPath sourcePath = Path.fromOSString(sourcesArtifact.getFile().getAbsolutePath());
IRuntimeClasspathEntry mavenEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(jarPath);
mavenEntry.setSourceAttachmentPath(sourcePath);
return mavenEntry;
}
use of org.eclipse.jdt.launching.IRuntimeClasspathEntry in project bndtools by bndtools.
the class BndContainerRuntimeClasspathEntryResolver method resolveRuntimeClasspathEntry.
@Override
public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entryToResolve, IJavaProject entryProject) throws CoreException {
if (entryToResolve == null || entryProject == null) {
return new IRuntimeClasspathEntry[0];
}
final List<IRuntimeClasspathEntry> resolvedRuntimeClasspathEntries = new ArrayList<>();
final IClasspathContainer container = JavaCore.getClasspathContainer(entryToResolve.getPath(), entryProject);
if (container == null) {
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Could not resolve Bnd classpath container", null));
}
final IClasspathEntry[] classpathEntries = container.getClasspathEntries();
List<IJavaProject> projects = resolvingProjects.get();
Integer count = resolvingCount.get();
if (projects == null) {
projects = new ArrayList<>();
resolvingProjects.set(projects);
count = 0;
}
int intCount = count.intValue();
intCount++;
resolvingCount.set(intCount);
try {
for (IClasspathEntry classpathEntry : classpathEntries) {
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(classpathEntry.getPath().segment(0));
final IJavaProject javaProject = JavaCore.create(project);
if (!projects.contains(javaProject)) {
projects.add(javaProject);
final IRuntimeClasspathEntry2 defaultProjectClasspathEntry = (IRuntimeClasspathEntry2) JavaRuntime.newDefaultProjectClasspathEntry(javaProject);
final IRuntimeClasspathEntry[] projectRuntimeClasspathEntries = defaultProjectClasspathEntry.getRuntimeClasspathEntries(null);
for (IRuntimeClasspathEntry projectRuntimeClasspathEntry : projectRuntimeClasspathEntries) {
// instead of resolving all output locations we simply just return the project runtime classpath entry itself
if (projectRuntimeClasspathEntry.getType() == IRuntimeClasspathEntry.PROJECT) {
IResource resource = projectRuntimeClasspathEntry.getResource();
if (resource instanceof IProject) {
resolvedRuntimeClasspathEntries.add(projectRuntimeClasspathEntry);
}
} else {
IRuntimeClasspathEntry[] resolvedEntries = JavaRuntime.resolveRuntimeClasspathEntry(projectRuntimeClasspathEntry, javaProject);
for (IRuntimeClasspathEntry resolvedEntry : resolvedEntries) {
resolvedRuntimeClasspathEntries.add(resolvedEntry);
}
}
}
}
} else {
final IRuntimeClasspathEntry runtimeClasspathEntry = new RuntimeClasspathEntry(classpathEntry);
if (!resolvedRuntimeClasspathEntries.contains(runtimeClasspathEntry)) {
resolvedRuntimeClasspathEntries.add(runtimeClasspathEntry);
}
}
}
} finally {
intCount--;
if (intCount == 0) {
resolvingProjects.set(null);
resolvingCount.set(null);
} else {
resolvingCount.set(intCount);
}
}
for (IRuntimeClasspathEntry resolvedRuntimeClasspathEntry : resolvedRuntimeClasspathEntries) {
resolvedRuntimeClasspathEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
}
return resolvedRuntimeClasspathEntries.toArray(new IRuntimeClasspathEntry[0]);
}
Aggregations