Class PersistenceUtils
- java.lang.Object
-
- net.ssehub.easy.producer.core.persistence.PersistenceUtils
-
public class PersistenceUtils extends java.lang.ObjectStatic utility functions related to the persistence layer.- Author:
- El-Sharkawy
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,Configuration>CONFIGURATIONSprivate static java.lang.StringDEBUG_FILES_EXTENSIONprivate static booleandefaultModelsLoadedstatic java.lang.StringINSTANTIATOR_CONTROLLER_MULTIPLENotification by the instantiator controller: No multiple instantiated files message.private static EASyLoggerFactory.EASyLoggerLOGGER
-
Constructor Summary
Constructors Constructor Description PersistenceUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddImport(PLPInfo plp, PLPInfo predecessor, boolean considerVIL)static voidaddLocation(Configuration config, ProgressObserver observer)private static voidaddScriptImportToPLP(PLPInfo plp, PLPInfo predecessor)Adds a new import to the main build script of aPLPInfo.static voidcloseProject(java.io.File projectFolder)Closes a project, i.e., removes its configuration from the internal cache.static voidcreateInstantiatePredecessorScript(PLPInfo plp, PLPInfo... parentPLPs)Creates a (new) build script inside plp.static voidcreateIVMLProject(java.lang.String projectName, Version version, java.lang.String storagePath)Creates a new IVML project.static VersiondefaultVersion()Creates a newVersion, which should be used for the creation of new EASy config files (variability models, build scripts, and templates).static ConfigurationgetConfiguration(java.io.File projectFolder)Returns the (cached) configuration for the given project (in terms of aprojectFolder).private static ConfigurationgetDefaultModelsConfiguration(java.io.File folder, java.util.Map<Configuration.PathKind,java.io.File> alternativePaths)Creates a configuration for loading default models.static java.io.FilegetLocationFile(java.io.File projectFolder, Configuration.PathKind kind)Returns the specified location within the givenprojectFolder.static java.lang.StringivmlFileLocation(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.static java.lang.StringivmlFileLocation(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.static voidloadDefaultModels(java.lang.ClassLoader loader, ProgressObserver observer, java.util.Map<Configuration.PathKind,java.io.File> alternativePaths)Loads the default models if existent.static voidloadDefaultModels(ProgressObserver observer)Loads the default models if existent using the class loader of this class.static voidloadDefaultModels(ProgressObserver observer, java.util.Map<Configuration.PathKind,java.io.File> alternativePaths)Loads the default models if existent using the class loader of this class.static <M extends IModel>
MloadModel(ModelManagement<M> modelManagement, java.io.File modelFile)Loads anIModelfrom a file, i.e.static ModelloadModel(PathEnvironment pathEnv, java.lang.String location, ModelType type)Loads a specific model.static PLPInfoloadRootPLPInfo(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.static java.lang.StringmodelFileLocation(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.static java.lang.StringmodelFileLocation(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.static voidrefreshModels(PLPInfo plp)(Re-)Loads all variability models of the specifiedPLPInfofrom the file system.static java.lang.StringstorageFileLocation(java.lang.String storagePath)This method locates the configuration file for non ivml information within the given storage path.static java.lang.StringvilFileLocation(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.static java.lang.StringvilFileLocation(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.static voidwriteIVMLProject(Project project, java.lang.String storagePath)Writes the IVML Variability model of thePersistentProjectto the file system.static voidwriteIVMLProject(Project project, java.lang.String storagePath, boolean debug)Writes the IVML Variability model of thePersistentProjectto the file system.static voidwriteVILScript(Script buildScript, java.lang.String storagePath)Writes the IVML Variability model of thePersistentProjectto the file system.
-
-
-
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
-
LOGGER
private static final EASyLoggerFactory.EASyLogger LOGGER
-
CONFIGURATIONS
private static final java.util.Map<java.lang.String,Configuration> CONFIGURATIONS
-
defaultModelsLoaded
private static boolean defaultModelsLoaded
-
-
Method Detail
-
getConfiguration
public static final Configuration getConfiguration(java.io.File projectFolder)
Returns the (cached) configuration for the given project (in terms of aprojectFolder).- 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
-
addLocation
public static final void addLocation(Configuration config, ProgressObserver observer) throws ModelManagementException
- Parameters:
config- the configuration to use for obtaining the foldersobserver- observer a progress observer, may beProgressObserver.NO_OBSERVER- Throws:
ModelManagementException- - in case that the available information may become inconsistent due to the new location (if more than one exception is created, the last one will be returned)
-
getLocationFile
public static final java.io.File getLocationFile(java.io.File projectFolder, Configuration.PathKind kind)Returns the specified location within the givenprojectFolder.- Parameters:
projectFolder- the folder of the EASy projectkind- 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/savedstoragePath- 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/savedstoragePath- 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/savedprojectVersion- The version of the ivml project which should be read/saved, can benull.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/savedprojectVersion- The version of the VIL build script project which should be read/saved, can benull.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/savedprojectVersion- The version of the model which should be read/saved, can benull.folder- The location (top level folder) of the configuration filesmodelType- EitherConfiguration.PathKind.IVMLorConfiguration.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/savedprojectVersion- The version of the model project which should be read/saved, can benull.storagePath- The location (top level folder) of the configuration filesextension- 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 relativelocation- the location containing the datatype- 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 relativemodelLocation- the location to load the information fromprojectLocation- 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 thePersistentProjectto the file system.- Parameters:
project- The IVMLProjectwhich 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 thePersistentProjectto the file system.- Parameters:
project- The IVMLProjectwhich 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 thePersistentProjectto the file system.- Parameters:
buildScript- The VIL build script project which should be savedstoragePath- 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 PersistenceExceptionCreates 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 newVersion, which should be used for the creation of new EASy config files (variability models, build scripts, and templates).- Returns:
- A new version instance.
-
loadModel
public static <M extends IModel> M loadModel(ModelManagement<M> modelManagement, java.io.File modelFile) throws ModelManagementException
Loads anIModelfrom a file, i.e. a IVML project, a VIL script, or a VTL template. This also adds the the parent folder of the file toModelManagement.locations().- Type Parameters:
M- The type handled by the givenModelManagement, i.e.Project,Script, orTemplate- Parameters:
modelManagement- AModelManagement, i.e.VarModel.INSTANCE,BuildModel.INSTANCE, orTemplateModel.INSTANCE. Please be aware of that the correct model is used in respect to the desired file, which should be loaded by the model.modelFile- The model file which should be loaded, must be of the type of the usedModelManagement.- Returns:
- The loaded (and parsed) model.
- Throws:
ModelManagementException- In case of any error during loading the file.
-
refreshModels
public static void refreshModels(PLPInfo plp)
(Re-)Loads all variability models of the specifiedPLPInfofrom the file system.- Parameters:
plp- APLPInfocontaining 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)
-
addScriptImportToPLP
private static void addScriptImportToPLP(PLPInfo plp, PLPInfo predecessor)
Adds a new import to the main build script of aPLPInfo.- 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 observeralternativePaths- for loading the models (seeConfiguration, 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 fromobserver- the progress observeralternativePaths- for loading the models (seeConfiguration, 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 modelsalternativePaths- for loading the models (seeConfiguration, may be null)- Returns:
- the configuration
-
-