Class PersistenceUtils


  • public class PersistenceUtils
    extends java.lang.Object
    Static utility functions related to the persistence layer.
    Author:
    El-Sharkawy
    • Field Detail

      • INSTANTIATOR_CONTROLLER_MULTIPLE

        public static final java.lang.String INSTANTIATOR_CONTROLLER_MULTIPLE
        Notification by the instantiator controller: No multiple instantiated files message.
        See Also:
        Constant Field Values
      • DEBUG_FILES_EXTENSION

        private static final java.lang.String DEBUG_FILES_EXTENSION
        See Also:
        Constant Field Values
      • CONFIGURATIONS

        private static final java.util.Map<java.lang.String,​Configuration> CONFIGURATIONS
      • defaultModelsLoaded

        private static boolean defaultModelsLoaded
    • Constructor Detail

      • PersistenceUtils

        public PersistenceUtils()
    • Method Detail

      • getConfiguration

        public static final Configuration getConfiguration​(java.io.File projectFolder)
        Returns the (cached) configuration for the given project (in terms of a projectFolder).
        Parameters:
        projectFolder - the project folder representing the project
        Returns:
        the configuration of the project
      • closeProject

        public static final void closeProject​(java.io.File projectFolder)
        Closes a project, i.e., removes its configuration from the internal cache.
        Parameters:
        projectFolder - the project folder representing the project
      • getLocationFile

        public static final java.io.File getLocationFile​(java.io.File projectFolder,
                                                         Configuration.PathKind kind)
        Returns the specified location within the given projectFolder.
        Parameters:
        projectFolder - the folder of the EASy project
        kind - the path kind
        Returns:
        the configuration location as a subpath of projectFolder
      • storageFileLocation

        public static final java.lang.String storageFileLocation​(java.lang.String storagePath)
        This method locates the configuration file for non ivml information within the given storage path.
        Parameters:
        storagePath - The storage path, where the configuration file should be placed.
        Returns:
        The absolute path of the configuration file within the give folder path.
      • ivmlFileLocation

        public static final java.lang.String ivmlFileLocation​(Project project,
                                                              java.lang.String storagePath)
        This method locates the project file for the ivml variability model for a specific ivml project within the given storage path.
        Parameters:
        project - The ivml project which should be read/saved
        storagePath - The location (top level folder) of the configuration files
        Returns:
        The absolute path for the file to be written/read.
      • vilFileLocation

        public static final java.lang.String vilFileLocation​(Script buildScript,
                                                             java.lang.String storagePath)
        This method locates the project file for the VIL variability model for a specific EASy project within the given storage path.
        Parameters:
        buildScript - The VIL build script project which should be read/saved
        storagePath - The location (top level folder) of the configuration files
        Returns:
        The absolute path for the file to be written/read.
      • ivmlFileLocation

        public static final java.lang.String ivmlFileLocation​(java.lang.String projectName,
                                                              java.lang.String projectVersion,
                                                              java.lang.String storagePath)
        This method locates the project file for the ivml variability model for a specific ivml project within the given storage path.
        Parameters:
        projectName - The qualified name of the ivml project which should be read/saved
        projectVersion - The version of the ivml project which should be read/saved, can be null.
        storagePath - The location (top level folder) of the configuration files
        Returns:
        The absolute path for the file to be written/read.
      • vilFileLocation

        public static final java.lang.String vilFileLocation​(java.lang.String projectName,
                                                             java.lang.String projectVersion,
                                                             java.lang.String storagePath)
        This method locates the project file for the VIL build script model for a specific EASy project within the given storage path.
        Parameters:
        projectName - The qualified name of the VIL build script project which should be read/saved
        projectVersion - The version of the VIL build script project which should be read/saved, can be null.
        storagePath - The location (top level folder) of the configuration files
        Returns:
        The absolute path for the file to be written/read.
      • modelFileLocation

        public static final java.lang.String modelFileLocation​(java.lang.String projectName,
                                                               java.lang.String projectVersion,
                                                               java.lang.String folder,
                                                               Configuration.PathKind modelType)
        This method locates the file for a IVML/VIL model for a specific EASy project within the given folder.
        Parameters:
        projectName - The qualified name of the model which should be read/saved
        projectVersion - The version of the model which should be read/saved, can be null.
        folder - The location (top level folder) of the configuration files
        modelType - Either Configuration.PathKind.IVML or Configuration.PathKind.VIL
        Returns:
        The absolute path for the file to be written/read.
      • modelFileLocation

        public static final java.lang.String modelFileLocation​(java.lang.String projectName,
                                                               java.lang.String projectVersion,
                                                               java.lang.String storagePath,
                                                               java.lang.String extension)
        This method locates the project file for the ivml/vil model for a specific EASy project within the given storage path.
        Parameters:
        projectName - The qualified name of the model project which should be read/saved
        projectVersion - The version of the model project which should be read/saved, can be null.
        storagePath - The location (top level folder) of the configuration files
        extension - The file extension (".ivml" for IVML files, or ".vil")
        Returns:
        The absolute path for the file to be written/read.
      • loadModel

        public static final Model loadModel​(PathEnvironment pathEnv,
                                            java.lang.String location,
                                            ModelType type)
                                     throws PersistenceException
        Loads a specific model.
        Parameters:
        pathEnv - the path environment for making absolute paths relative
        location - the location containing the data
        type - the type of the model
        Returns:
        the model
        Throws:
        PersistenceException - in case of reading errors
      • loadRootPLPInfo

        public static final PLPInfo loadRootPLPInfo​(PathEnvironment pathEnv,
                                                    java.lang.String modelLocation,
                                                    java.io.File projectLocation)
        Loads the information of the root product line project from the configuration at the given location.
        Parameters:
        pathEnv - the environment for making locations absolute and relative
        modelLocation - the location to load the information from
        projectLocation - an optional location where the related PLP is (in case of temporary loading, this enables relocation)
        Returns:
        the product line project information
      • writeIVMLProject

        public static void writeIVMLProject​(Project project,
                                            java.lang.String storagePath)
                                     throws PersistenceException
        Writes the IVML Variability model of the PersistentProject to the file system.
        Parameters:
        project - The IVML Project which should be saved.
        storagePath - The folder, where the file should be saved.
        Throws:
        PersistenceException - If the file cannot be written to the file system.
      • writeIVMLProject

        public static void writeIVMLProject​(Project project,
                                            java.lang.String storagePath,
                                            boolean debug)
                                     throws PersistenceException
        Writes the IVML Variability model of the PersistentProject to the file system.
        Parameters:
        project - The IVML Project which should be saved.
        storagePath - The folder, where the file should be saved.
        debug - If true The String "_debug" will be added to the file's name.
        Throws:
        PersistenceException - If the file cannot be written to the file system.
      • writeVILScript

        public static void writeVILScript​(Script buildScript,
                                          java.lang.String storagePath)
                                   throws PersistenceException
        Writes the IVML Variability model of the PersistentProject to the file system.
        Parameters:
        buildScript - The VIL build script project which should be saved
        storagePath - The folder, where the file should be saved.
        Throws:
        PersistenceException - If the file cannot be written to the file system.
      • createIVMLProject

        public static void createIVMLProject​(java.lang.String projectName,
                                             Version version,
                                             java.lang.String storagePath)
                                      throws PersistenceException
        Creates a new IVML project.
        Parameters:
        projectName - Name of the project.
        version - Version of the project.
        storagePath - The folder, where the file should be saved.
        Throws:
        PersistenceException - If the file cannot be written to the file system.
      • defaultVersion

        public static final Version defaultVersion()
        Creates a new Version, which should be used for the creation of new EASy config files (variability models, build scripts, and templates).
        Returns:
        A new version instance.
      • refreshModels

        public static void refreshModels​(PLPInfo plp)
        (Re-)Loads all variability models of the specified PLPInfo from the file system.
        Parameters:
        plp - A PLPInfo containing saved models which should be (re-) loaded from the file system
      • createInstantiatePredecessorScript

        public static void createInstantiatePredecessorScript​(PLPInfo plp,
                                                              PLPInfo... parentPLPs)
        Creates a (new) build script inside plp. This build script will only call build script from all predecessor projects and will instantiate their stuff into plp.
        In this case, this method tries to add a "instantiate all predecessors" call to the main rule.
        Parameters:
        plp - The newly created Project where a new main build script shall be created.
        parentPLPs - Predecessor projects which shall be instantiated into the newly created project.
      • addImport

        public static final void addImport​(PLPInfo plp,
                                           PLPInfo predecessor,
                                           boolean considerVIL)
        Adds an import to the Project and to the Script of a given PLPInfo to the Project and Script of a predecessor project.
        Parameters:
        plp - the product line project to add the import to
        predecessor - A predecessor project of plp, where the Project and the Script should be included.
        considerVIL - true if the parent project has also a build script which should be considered, false otherwise
      • addScriptImportToPLP

        private static void addScriptImportToPLP​(PLPInfo plp,
                                                 PLPInfo predecessor)
        Adds a new import to the main build script of a PLPInfo.
        Parameters:
        plp - The plp where the import shall be added to the main build script.
        predecessor - The predecessor project which shall be imported.
      • loadDefaultModels

        public static void loadDefaultModels​(ProgressObserver observer)
        Loads the default models if existent using the class loader of this class.
        Parameters:
        observer - the progress observer
      • loadDefaultModels

        public static void loadDefaultModels​(ProgressObserver observer,
                                             java.util.Map<Configuration.PathKind,​java.io.File> alternativePaths)
        Loads the default models if existent using the class loader of this class.
        Parameters:
        observer - the progress observer
        alternativePaths - for loading the models (see Configuration, may be null)
      • loadDefaultModels

        public static void loadDefaultModels​(java.lang.ClassLoader loader,
                                             ProgressObserver observer,
                                             java.util.Map<Configuration.PathKind,​java.io.File> alternativePaths)
        Loads the default models if existent.
        Parameters:
        loader - the loader to take the resources from
        observer - the progress observer
        alternativePaths - for loading the models (see Configuration, may be null)
      • getDefaultModelsConfiguration

        private static Configuration getDefaultModelsConfiguration​(java.io.File folder,
                                                                   java.util.Map<Configuration.PathKind,​java.io.File> alternativePaths)
        Creates a configuration for loading default models.
        Parameters:
        folder - the folder with the models
        alternativePaths - for loading the models (see Configuration, may be null)
        Returns:
        the configuration