Search in sources :

Example 11 with ProjectLauncher

use of aQute.bnd.build.ProjectLauncher in project bndtools by bndtools.

the class AbstractOSGiLaunchDelegate method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, final ILaunch launch, IProgressMonitor monitor) throws CoreException {
    // Register listener to clean up temp files on exit of launched JVM
    final ProjectLauncher launcher = getProjectLauncher();
    IDebugEventSetListener listener = new IDebugEventSetListener() {

        @Override
        public void handleDebugEvents(DebugEvent[] events) {
            for (DebugEvent event : events) {
                if (event.getKind() == DebugEvent.TERMINATE) {
                    Object source = event.getSource();
                    if (source instanceof IProcess) {
                        ILaunch processLaunch = ((IProcess) source).getLaunch();
                        if (processLaunch == launch) {
                            // Not interested in any further events =>
                            // unregister this listener
                            DebugPlugin.getDefault().removeDebugEventListener(this);
                            // *may* cause LinkageErrors.
                            try {
                                launcher.cleanup();
                            } catch (Throwable t) {
                                logger.logError("Error cleaning launcher temporary files", t);
                            }
                            LaunchUtils.endRun((Run) launcher.getProject());
                        }
                    }
                }
            }
        }
    };
    DebugPlugin.getDefault().addDebugEventListener(listener);
    // Now actually launch
    super.launch(configuration, mode, launch, monitor);
}
Also used : IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) DebugEvent(org.eclipse.debug.core.DebugEvent) ILaunch(org.eclipse.debug.core.ILaunch) ProjectLauncher(aQute.bnd.build.ProjectLauncher) IProcess(org.eclipse.debug.core.model.IProcess)

Example 12 with ProjectLauncher

use of aQute.bnd.build.ProjectLauncher in project bnd by bndtools.

the class LauncherTest method testTimeoutActivator.

public static void testTimeoutActivator() throws Exception {
    Project project = getProject();
    project.clear();
    ProjectLauncher l = project.getProjectLauncher();
    l.setTimeout(100, TimeUnit.MILLISECONDS);
    l.setTrace(false);
    assertEquals(ProjectLauncher.TIMEDOUT, l.launch());
}
Also used : Project(aQute.bnd.build.Project) ProjectLauncher(aQute.bnd.build.ProjectLauncher)

Example 13 with ProjectLauncher

use of aQute.bnd.build.ProjectLauncher in project bnd by bndtools.

the class LauncherTest method testNoReferences.

public static void testNoReferences() throws Exception {
    Project project = getProject();
    project.setProperty("-runnoreferences", true + "");
    ProjectLauncher l = project.getProjectLauncher();
    l.setTrace(true);
    l.getRunProperties().put("test.cmd", "noreference");
    assertEquals(15, l.launch());
}
Also used : Project(aQute.bnd.build.Project) ProjectLauncher(aQute.bnd.build.ProjectLauncher)

Example 14 with ProjectLauncher

use of aQute.bnd.build.ProjectLauncher in project bnd by bndtools.

the class LauncherTest method testCleanup.

/**
	 * Tests if the properties are cleaned up. This requires some knowledge of
	 * the launcher unfortunately. It is also not sure if the file is not just
	 * deleted by the onExit ...
	 * 
	 * @throws Exception
	 */
public static void testCleanup() throws Exception {
    Project project = getProject();
    File target = project.getTarget();
    IO.deleteWithException(target);
    project.clear();
    assertNoProperties(target);
    final ProjectLauncher l = project.getProjectLauncher();
    l.setTrace(true);
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(1000);
                l.cancel();
            } catch (Exception e) {
            // Ignore
            }
        }
    };
    t.start();
    l.getRunProperties().put("test.cmd", "timeout");
    l.launch();
    assertNoProperties(target);
}
Also used : Project(aQute.bnd.build.Project) ProjectLauncher(aQute.bnd.build.ProjectLauncher) File(java.io.File) IOException(java.io.IOException)

Example 15 with ProjectLauncher

use of aQute.bnd.build.ProjectLauncher in project bnd by bndtools.

the class LauncherTest method testSpaces.

/**
	 * Try launching a workspace with spaces
	 */
public static void testSpaces() throws Exception {
    File f = new File("t m p");
    try {
        File cnf = new File(f, "cnf");
        File demo = new File(f, "demo");
        IO.copy(IO.getFile("../cnf"), IO.getFile(f, "cnf"));
        IO.copy(IO.getFile("../demo"), IO.getFile(f, "demo"));
        IO.copy(IO.getFile("../biz.aQute.launcher"), IO.getFile(f, "biz.aQute.launcher"));
        IO.copy(IO.getFile("../biz.aQute.junit"), IO.getFile(f, "biz.aQute.junit"));
        Workspace ws = Workspace.getWorkspace(f);
        Project p = ws.getProject("demo");
        p.setTrace(true);
        p.build();
        try {
            ProjectLauncher l = p.getProjectLauncher();
            l.setTrace(true);
            l.getRunProperties().put("test.cmd", "exit");
            assertEquals(42, l.launch());
        } finally {
            p.close();
            ws.close();
        }
    } finally {
        IO.delete(f);
    }
}
Also used : Project(aQute.bnd.build.Project) ProjectLauncher(aQute.bnd.build.ProjectLauncher) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Aggregations

ProjectLauncher (aQute.bnd.build.ProjectLauncher)18 Project (aQute.bnd.build.Project)15 Jar (aQute.bnd.osgi.Jar)3 File (java.io.File)3 ProjectTester (aQute.bnd.build.ProjectTester)1 Run (aQute.bnd.build.Run)1 RunSession (aQute.bnd.build.RunSession)1 Workspace (aQute.bnd.build.Workspace)1 Processor (aQute.bnd.osgi.Processor)1 Resource (aQute.bnd.osgi.Resource)1 LaunchStatusHandler (bndtools.launch.ui.internal.LaunchStatusHandler)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Callable (java.util.concurrent.Callable)1 Manifest (java.util.jar.Manifest)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1