Class CobiGenUtils


  • public class CobiGenUtils
    extends Object
    Utilities class for CobiGen related operations. For instance, it creates a new CobiGen instance and registers all the plug-ins
    • Constructor Summary

      Constructors 
      Constructor Description
      CobiGenUtils()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addJarsToClassLoader​(String allJars)
      Adds a jar file into the current class loader
      File extractArtificialPom​(Path rootCLIPath)
      Extracts an artificial POM which defines all the CobiGen plug-ins that are needed
      List<Class<?>> getTemplates()  
      File getTemplatesJar​(boolean isSource)
      Tries to find the templates jar.
      List<Class<?>> getUtilClasses()
      getter for templates utils classes
      static Object getValidCobiGenInput​(com.devonfw.cobigen.api.CobiGen cg, File inputFile, Boolean isJavaInput)
      Processes the given input file to be converted into a valid CobiGen input.
      com.devonfw.cobigen.api.CobiGen initializeCobiGen()
      Registers CobiGen plug-ins and instantiates CobiGen
      static Object process​(com.devonfw.cobigen.api.InputInterpreter inputInterpreter, File file, ClassLoader cl)
      Processes the given file to be converted into any CobiGen valid input format
      void registerPlugins()
      Registers the given different CobiGen plug-ins by building an artificial POM extracted next to the CLI location and then adding the needed URLs to the class loader.
      static List<com.devonfw.cobigen.api.to.IncrementTo> retainAllIncrements​(List<com.devonfw.cobigen.api.to.IncrementTo> currentList, List<com.devonfw.cobigen.api.to.IncrementTo> listToIntersect)
      For Increments Returns a list that retains only the elements in this list that are contained in the specified collection (optional operation).
      static List<com.devonfw.cobigen.api.to.TemplateTo> retainAllTemplates​(List<com.devonfw.cobigen.api.to.TemplateTo> currentList, List<com.devonfw.cobigen.api.to.TemplateTo> listToIntersect)
      For Templates Returns a list that retains only the elements in this list that are contained in the specified collection (optional operation).
    • Constructor Detail

      • CobiGenUtils

        public CobiGenUtils()
    • Method Detail

      • getUtilClasses

        public List<Class<?>> getUtilClasses()
        getter for templates utils classes
        Returns:
        list of UtilClasses
      • initializeCobiGen

        public com.devonfw.cobigen.api.CobiGen initializeCobiGen()
        Registers CobiGen plug-ins and instantiates CobiGen
        Returns:
        object of CobiGen
      • getTemplates

        public List<Class<?>> getTemplates()
        Returns:
        list of all classes, which have been defined in the template configuration folder from a jar
      • registerPlugins

        public void registerPlugins()
        Registers the given different CobiGen plug-ins by building an artificial POM extracted next to the CLI location and then adding the needed URLs to the class loader.
      • extractArtificialPom

        public File extractArtificialPom​(Path rootCLIPath)
        Extracts an artificial POM which defines all the CobiGen plug-ins that are needed
        Parameters:
        rootCLIPath - path where the artificial POM will be extracted to
        Returns:
        the extracted POM file
      • addJarsToClassLoader

        public void addJarsToClassLoader​(String allJars)
        Adds a jar file into the current class loader
        Parameters:
        allJars - file to load
      • getTemplatesJar

        public File getTemplatesJar​(boolean isSource)
        Tries to find the templates jar. If it was not found, it will download it and then return it.
        Parameters:
        isSource - true if we want to get source jar file path
        Returns:
        the jar file of the templates
      • retainAllIncrements

        public static List<com.devonfw.cobigen.api.to.IncrementTo> retainAllIncrements​(List<com.devonfw.cobigen.api.to.IncrementTo> currentList,
                                                                                       List<com.devonfw.cobigen.api.to.IncrementTo> listToIntersect)
        For Increments Returns a list that retains only the elements in this list that are contained in the specified collection (optional operation). In other words, the resultant list removes from this list all of its elements that are not contained in the specified collection.
        Parameters:
        currentList - list containing elements to be retained in this list
        listToIntersect - second list to be used for the intersection
        Returns:
        resultant list containing increments that are in both lists
      • retainAllTemplates

        public static List<com.devonfw.cobigen.api.to.TemplateTo> retainAllTemplates​(List<com.devonfw.cobigen.api.to.TemplateTo> currentList,
                                                                                     List<com.devonfw.cobigen.api.to.TemplateTo> listToIntersect)
        For Templates Returns a list that retains only the elements in this list that are contained in the specified collection (optional operation). In other words, the resultant list removes from this list all of its elements that are not contained in the specified collection.
        Parameters:
        currentList - list containing elements to be retained in this list
        listToIntersect - second list to be used for the intersection
        Returns:
        resultant list containing increments that are in both lists
      • getValidCobiGenInput

        public static Object getValidCobiGenInput​(com.devonfw.cobigen.api.CobiGen cg,
                                                  File inputFile,
                                                  Boolean isJavaInput)
                                           throws com.devonfw.cobigen.api.exception.InputReaderException
        Processes the given input file to be converted into a valid CobiGen input. Also if the input is Java, will create the needed class loader
        Parameters:
        cg - CobiGen instance
        inputFile - user's input file
        isJavaInput - true if input is Java code
        Returns:
        valid cobiGen input
        Throws:
        com.devonfw.cobigen.api.exception.InputReaderException - throws InputReaderException when the input file could not be converted to a valid CobiGen input
      • process

        public static Object process​(com.devonfw.cobigen.api.InputInterpreter inputInterpreter,
                                     File file,
                                     ClassLoader cl)
                              throws com.devonfw.cobigen.api.exception.InputReaderException
        Processes the given file to be converted into any CobiGen valid input format
        Parameters:
        file - File converted into any CobiGen valid input format
        cl - ClassLoader to be used, when considering Java-related inputs
        inputInterpreter - parse cobiGen compliant input from the file
        Returns:
        a CobiGen valid input
        Throws:
        com.devonfw.cobigen.api.exception.InputReaderException - if the input retrieval did not result in a valid CobiGen input