Class ProjectLauncher

All Implemented Interfaces:
Constants, Registry, Report, Reporter, Closeable, AutoCloseable, Iterable<String>
Direct Known Subclasses:
JUnitLauncher

public abstract class ProjectLauncher extends Processor
A Project Launcher is a base class to be extended by launchers. Launchers are JARs that launch a framework and install a number of bundles and then run the framework. A launcher jar must specify a Launcher-Class manifest header. This class is instantiated and cast to a LauncherPlugin. This plug in is then asked to provide a ProjectLauncher. This project launcher is then used by the project to run the code. Launchers must extend this class.
  • Field Details

  • Constructor Details

  • Method Details

    • validate

      protected void validate()
      Validate some settings
    • updateFromProject

      protected void updateFromProject() throws Exception
      Collect all the aspect from the project and set the local fields from them. Should be called after constructor has been called.
      Throws:
      Exception
    • getRunframework

      private int getRunframework(String property)
    • addClasspath

      public void addClasspath(Container container) throws Exception
      Throws:
      Exception
    • addClasspath

      protected void addClasspath(Container container, List<String> pathlist) throws Exception
      Throws:
      Exception
    • addClasspath

      protected void addClasspath(Collection<Container> path) throws Exception
      Throws:
      Exception
    • addRunBundle

      public void addRunBundle(String path)
    • getRunBundles

      public Collection<String> getRunBundles()
    • addRunVM

      public void addRunVM(String arg)
    • addRunProgramArgs

      public void addRunProgramArgs(String arg)
    • getRunpath

      public List<String> getRunpath()
    • getClasspath

      public Collection<String> getClasspath()
    • getRunVM

      public Collection<String> getRunVM()
    • getRunProgramArgs

      public Collection<String> getRunProgramArgs()
    • getRunProperties

      public Map<String,String> getRunProperties()
    • getStorageDir

      public File getStorageDir()
    • getMainTypeName

      public abstract String getMainTypeName()
    • update

      public void update() throws Exception
      Throws:
      Exception
    • onUpdate

      public void onUpdate(Runnable update)
    • getJavaExecutable

      public String getJavaExecutable(String java)
      Overrides:
      getJavaExecutable in class Processor
    • launch

      public int launch() throws Exception
      Throws:
      Exception
    • start

      public int start(ClassLoader parent) throws Exception
      Throws:
      Exception
    • invoke

      protected int invoke(Class<?> main, String[] args) throws Exception
      Throws:
      Exception
    • cleanup

      public void cleanup()
      Is called after the process exists. Can you be used to cleanup the properties file.
    • reportResult

      protected void reportResult(int result)
    • setTimeout

      public void setTimeout(long timeout, TimeUnit unit)
    • getTimeout

      public long getTimeout()
    • cancel

      public void cancel() throws Exception
      Throws:
      Exception
    • getSystemPackages

      public Map<String,? extends Map<String,String>> getSystemPackages()
    • getSystemCapabilities

      public String getSystemCapabilities()
    • getSystemCapabilitiesParameters

      public Parameters getSystemCapabilitiesParameters()
    • setKeep

      public void setKeep(boolean keep)
    • isKeep

      public boolean isKeep()
    • setTrace

      public void setTrace(boolean level)
      Overrides:
      setTrace in class Processor
    • getTrace

      public boolean getTrace()
    • prepare

      public void prepare() throws Exception
      Should be called when all the changes to the launchers are set. Will calculate whatever is necessary for the launcher.
      Throws:
      Exception
    • getProject

      public Project getProject()
    • addActivator

      public boolean addActivator(String e)
    • getActivators

      public Collection<String> getActivators()
    • getRunFramework

      public int getRunFramework()
      Either NONE or SERVICES to indicate how the remote end launches. NONE means it should not use the classpath to run a framework. This likely requires some dummy framework support. SERVICES means it should load the framework from the claspath.
    • setRunFramework

      public void setRunFramework(int n)
    • addDefault

      public void addDefault(String defaultSpec) throws Exception
      Add the specification for a set of bundles the runpath if it does not already is included. This can be used by subclasses to ensure the proper jars are on the classpath.
      Parameters:
      defaultSpec - The default spec for default jars
      Throws:
      Exception
    • executable

      public Jar executable() throws Exception
      Create a self executable.
      Throws:
      Exception
    • getCwd

      public File getCwd()
    • setCwd

      public void setCwd(File cwd)
    • getRunJdb

      public String getRunJdb()
    • getRunEnv

      public Map<String,String> getRunEnv()
    • registerForNotifications

      public void registerForNotifications(ProjectLauncher.NotificationListener listener)
    • getNotificationListeners

      public Set<ProjectLauncher.NotificationListener> getNotificationListeners()
    • setStreams

      public void setStreams(Appendable out, Appendable err)
      Set the stderr and stdout streams for the output process. The debugged process must append its output (i.e. write operation in the process under debug) to the given appendables.
      Parameters:
      out - std out
      err - std err
    • write

      public void write(String text) throws Exception
      Write text to the debugged process as if it came from stdin.
      Parameters:
      text - the text to write
      Throws:
      Exception
    • getRunSessions

      public List<? extends RunSession> getRunSessions() throws Exception
      Get the run sessions. If this return null, then launch on this object should be used, otherwise each returned object provides a remote session.
      Throws:
      Exception
    • calculatedProperties

      public void calculatedProperties(Map<String,String> properties) throws Exception
      Utility to calculate the final framework properties from settings
      Throws:
      Exception
    • setupStartlevels

      private void setupStartlevels(Map<String,String> properties) throws Exception
      Calculate the start level properties. This code is matched to the aQute.lib class StartLevelRuntimeHandler that handles the runtime details.

      The -runbundles instruction can carry a `startlevel` attribute. If any bundle has this start level attribute we control the startlevel process. If no bundle has this attribute, then the start level handling is not doing anything. The remaining section assumes that there is at least 1 bundle with a set startlevel attribute.

      The StartLevelRuntimeHandler#LAUNCH_STARTLEVEL_DEFAULT is then set to the maximum startlevel + 1. This signals that the StartLevelRuntimeHandler class handles the runtime aspects.

      The Constants.RUNSTARTLEVEL_BEGIN controls the beginning start level of the framework after the framework itself is started. The user can set this or else it is set to the maxmum startlevel+2.

      During runtime, the handler must be created with StartLevelRuntimeHandler#create(aQute.lib.startlevel.Trace, Map) before the framework is created since it may change the properties. I.e. the properties given to the FrameworkFactory must be the same object as given to the create method. One thing is that it will set the Constants.RUNSTARTLEVEL_BEGIN to ensure that all bundles are installed at level 1.

      After the framework is created, the runtime handler StartLevelRuntimeHandler#beforeStart(org.osgi.framework.launch.Framework) must be called. This will prepare that bundles will get their proper start level when installed.

      After the set of bundles is installed, the StartLevelRuntimeHandler#afterStart() is called to raise the start level to the desired level. Either the set Constants.RUNSTARTLEVEL_BEGIN or the maximum level + 2.

      Throws:
      Exception
    • liveCoding

      public ProjectLauncher.LiveCoding liveCoding(Executor executor, ScheduledExecutorService scheduledExecutor) throws Exception
      Throws:
      Exception
    • isRunFrameworkRestart

      public boolean isRunFrameworkRestart()
    • renderArguments

      public static String renderArguments(Collection<String> arguments)
    • renderArguments

      public static String renderArguments(Collection<String> arguments, boolean isWin32)
    • renderArguments

      public static String renderArguments(String[] arguments)
    • renderArguments

      public static String renderArguments(String[] arguments, boolean isWin32)