Search in sources :

Example 1 with IRuntimeClasspathEntry

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) IVMInstall(org.eclipse.jdt.launching.IVMInstall) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Map(java.util.Map)

Example 2 with IRuntimeClasspathEntry

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;
}
Also used : HashMap(java.util.HashMap) JavaSourceLookupDirector(org.eclipse.jdt.internal.launching.JavaSourceLookupDirector) ISourceLookupDirector(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector) ArrayList(java.util.ArrayList) SourceReferenceResolver(org.apache.sling.ide.eclipse.core.launch.SourceReferenceResolver) IVMConnector(org.eclipse.jdt.launching.IVMConnector) SourceReference(org.apache.sling.ide.osgi.SourceReference) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) ISlingLaunchpadServer(org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) SubMonitor(org.eclipse.core.runtime.SubMonitor) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) ISlingLaunchpadConfiguration(org.apache.sling.ide.eclipse.core.ISlingLaunchpadConfiguration) ISlingLaunchpadServer(org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer)

Example 3 with IRuntimeClasspathEntry

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) MavenSourceReference(org.apache.sling.ide.osgi.MavenSourceReference) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry)

Example 4 with IRuntimeClasspathEntry

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]);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) RuntimeClasspathEntry(org.eclipse.jdt.internal.launching.RuntimeClasspathEntry) ArrayList(java.util.ArrayList) IRuntimeClasspathEntry2(org.eclipse.jdt.launching.IRuntimeClasspathEntry2) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

IRuntimeClasspathEntry (org.eclipse.jdt.launching.IRuntimeClasspathEntry)4 ArrayList (java.util.ArrayList)3 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 ISlingLaunchpadConfiguration (org.apache.sling.ide.eclipse.core.ISlingLaunchpadConfiguration)1 ISlingLaunchpadServer (org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer)1 SourceReferenceResolver (org.apache.sling.ide.eclipse.core.launch.SourceReferenceResolver)1 MavenSourceReference (org.apache.sling.ide.osgi.MavenSourceReference)1 OsgiClientException (org.apache.sling.ide.osgi.OsgiClientException)1 SourceReference (org.apache.sling.ide.osgi.SourceReference)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1