Class Generator

java.lang.Object
de.uni_hildesheim.sse.easy.loader.AbstractLoader
de.uni_hildesheim.sse.easy.loader.Generator

public class Generator extends AbstractLoader
Provides generator factilities for static loading.
Author:
Holger Eichelberger, Patrik Pastuschek
  • Field Details

    • RUNTIME_CLASSES

      private static final Class<?>[] RUNTIME_CLASSES
    • exclusionSelector

      private static IExclusionSelector exclusionSelector
    • verbose

      private static boolean verbose
    • data

      private List<BundleInfo> data
    • urls

      private List<URL> urls
    • urlBundleMapping

      private Map<URL,BundleInfo> urlBundleMapping
    • checkedBundles

      private List<BundleInfo> checkedBundles
    • checkedClasspaths

      private List<String> checkedClasspaths
    • eclipseURIPath

      private String eclipseURIPath
    • binFolder

      private File binFolder
    • libsFolder

      private File libsFolder
  • Constructor Details

    • Generator

      protected Generator(File base, File pluginPath, File eclipsePath, File binFolder, File libsFolder)
      Creates the generator instance.
      Parameters:
      base - basefile.
      pluginPath - Folder of the easy Plugins.
      eclipsePath - Folder of the eclipse Plugins.
      binFolder - Where to find the compiled classes, relative to basePath
      libsFolder - Where to find special libs.
  • Method Details

    • isEclipseBundle

      private boolean isEclipseBundle(URL bundleURL)
      Checks whether the given url belongs to an Eclipse bundle/plug-in.
      Parameters:
      bundleURL - The url/path of a jar file.
      Returns:
      true if it belongs to Eclipse.
    • setExclusionSelector

      public static void setExclusionSelector(IExclusionSelector selector)
      Defines the exclusion selector.
      Parameters:
      selector - the selector instance (may be null to ignore)
    • getFeatureFilesFromDir

      public static List<File> getFeatureFilesFromDir(File file)
      Returns all files that are called feature.xml, even in subfolders.
      Parameters:
      file - The basefile.
      Returns:
      A list of all files.
    • filesToFeature

      public static List<Feature> filesToFeature(List<File> files)
      Transforms a list of files into a list of Features.
      Parameters:
      files - A list of the files to use.
      Returns:
      A list of features. Can be empty if no (valid) files were given.
    • getFeatureFromListByName

      public static Feature getFeatureFromListByName(List<Feature> features, String name)
      Returns (if possible) the feature with given symbolic name.
      Parameters:
      features - A list of features from which to extract.
      name - The symbolic name of the feature.
      Returns:
      The feature (or null).
    • autoGenerate

      public static List<BundleInfo> autoGenerate(List<File> mainFeature, List<File> allFeatures, boolean forceBuild, String pluginPath, String eclipsePath, String targetDir, String baseDir, String binFolder, String libsFolder)
      Wrapps the generation into one single method for easier access.
      Parameters:
      mainFeature - The file or path where the main feature(s) are.
      allFeatures - The file or path where other features are.
      forceBuild - False will interrupt the build if problem occur.
      pluginPath - The path of the plugins. Defines the bootstrap base.
      eclipsePath - the path of the eclipse plugins.
      targetDir - the target for the generated jars.
      baseDir - The baseDir for the bootstrap.
      binFolder - Where to find the compiled classes, relative to basePath
      libsFolder - Where to find special required libs.
      Returns:
      The list of generated Bundles.
    • deleteFolder

      private static void deleteFolder(File folder, boolean deleteFolder)
      Deletes the content of a folder.
      Parameters:
      folder - The folder to delete.
      deleteFolder - If true also the folder itself will be deleted.
    • generate

      public static List<BundleInfo> generate(List<Feature> features, List<Feature> additionalFeatures, boolean forceBuild, String pluginPath, String eclipsePath, String target, String baseDir, String binFolder, String libsFolder)
      Gathers Bundles for a list of features, depending on version restrictions.
      Parameters:
      features - A list of features for the build.
      additionalFeatures - A list of features that could be used by the main features.
      forceBuild - if true, ignore missing plugins and version issues.
      pluginPath - the path of the plugins. Defines the bootstrap base.
      eclipsePath - the path to the eclipse plugins.
      target - the target for the generated jars.
      baseDir - The baseDir for the bootstrap. Will be used if eclipsePath and/or pluginPath do not exist.
      binFolder - Where to find the compiled classes, relative to basePath
      libsFolder - Where to find the special libs required for the build.
      Returns:
      List<BundleInfo> a list containing all needed Bundles.
    • unnamed

      private static List<BundleInfo> unnamed(Generator gen, List<Feature> features, List<Feature> additionalFeatures, boolean forceBuild)
      ...
      Parameters:
      gen - ...
      features - ...
      additionalFeatures - ...
      forceBuild - ...
      Returns:
      A list of BundleInfos.
    • subGenerate

      private static void subGenerate(List<BundleInfo> bundles)
      .
      Parameters:
      bundles - .
    • collectFeatures

      private static List<Feature> collectFeatures(List<Feature> features, List<Feature> additionalFeatures)
      Collects all required features.
      Parameters:
      features - A list of features.
      additionalFeatures - A list of additional Features that maybe required by the main features.
      Returns:
      Map<String, EasyDependency> a map with all required dependencies.
    • collectDependencies

      private static Map<String,EasyDependency> collectDependencies(List<Feature> features, List<Feature> additionalFeatures)
      Collects all required dependencies for a list of features.
      Parameters:
      features - A list of features.
      additionalFeatures - A list of additional Features that maybe required by the main features.
      Returns:
      Map<String, EasyDependency> a map with all required dependencies.
    • addRuntimeClass

      private static void addRuntimeClass(Class<?> cls, List<Class<?>> rtClasses)
      Adds a runtime class for being packed with the generated jars.
      Parameters:
      cls - the class to be packed (including nested classes)
      rtClasses - the classes to be loaded (modified as a side effect)
    • main

      public static void main(String[] args)
      Executes the generator.
      Parameters:
      args - ignored
    • generateJarFiles

      protected void generateJarFiles(File targetDir, boolean bundle)
      Generates the JAR files for static loading.
      Parameters:
      targetDir - the target dire where to put the final jar files to
      bundle - whether libraries shall be bundled or not
    • handleJar

      private void handleJar(InputStream is, JarOutputStream os, Set<String> done, Set<String> exclude, Generator.UnbundleInfo unbundle) throws IOException
      Copies the entries of an entire JAR in is to the target JAR in os without duplicating entries. Considers irrelevantInJar(String) in order to filter out irrelevant entries.
      Parameters:
      is - the input JAR as stream
      os - the output JAR as stream
      done - already processed entries to avoid duplicates
      exclude - JAR entries not to be added (in addition to irrelevantInJar(String))
      unbundle - information about unbundling the current stream is
      Throws:
      IOException - in case that reading from or writing to a JAR stream fails
    • produceStartupList

      private void produceStartupList(JarOutputStream os) throws IOException
      Produces the JAR entry containing the EASy startup list to be read and interpreted at loading time.
      Parameters:
      os - the output stream
      Throws:
      IOException - in case of problems writing to os
    • addRuntimeLoaderClasses

      private void addRuntimeLoaderClasses(JarOutputStream os) throws IOException
      Adds the classes needed for runtime loading to os.
      Parameters:
      os - the JAR output stream
      Throws:
      IOException - in case that reading the class file or writing to os fails
    • handleJarWritingException

      private void handleJarWritingException(String name, IOException ex, InputStream is) throws IOException
      Handles an exception thrown while writing to a Jar file.
      Parameters:
      name - the name of the entry being written
      ex - the exception thrown
      is - the input stream the program is reading from (may be null)
      Throws:
      IOException - ex if ex is not just logged as a warning
    • notifyMapping

      protected void notifyMapping(URL url, BundleInfo info)
      Description copied from class: AbstractLoader
      Is called by AbstractLoader.collectBootstrapData(BundleInfo, List, List, Object) to notify about mapping a URL to the given bundle info.
      Overrides:
      notifyMapping in class AbstractLoader
      Parameters:
      url - the URL of the bundle JAR
      info - the related bundle information object
    • irrelevantInJar

      protected boolean irrelevantInJar(String name)
      Description copied from class: AbstractLoader
      Returns whether the name of a certain JAR entry is irrelevant for a standalone execution.
      Overrides:
      irrelevantInJar in class AbstractLoader
      Parameters:
      name - the name
      Returns:
      true if the name (and potential overlapping names) is irrelevant, false if relevant
    • logEntryName

      private void logEntryName(String name)
      Logs a JAR entry name.
      Parameters:
      name - the entry name
    • setVerbose

      public static void setVerbose(boolean verb)
      Sets the verbose flag.
      Parameters:
      verb - the verbose flag