org.dbmaintain.script.repository.impl
Class ArchiveScriptLocation

java.lang.Object
  extended by org.dbmaintain.script.repository.ScriptLocation
      extended by org.dbmaintain.script.repository.impl.ArchiveScriptLocation

public class ArchiveScriptLocation
extends ScriptLocation

Script container that reads all scripts from a jar file

Author:
Filip Neven, Tim Ducheyne

Field Summary
 
Fields inherited from class org.dbmaintain.script.repository.ScriptLocation
baseLineRevision, ignoreCarriageReturnsWhenCalculatingCheckSum, LOCATION_PROPERTIES_FILENAME, patchQualifiers, postProcessingScriptDirName, qualifierRegexp, registeredQualifiers, scriptEncoding, scriptFactory, scriptFileExtensions, scriptIndexRegexp, scriptLocationName, scripts, targetDatabaseRegexp
 
Constructor Summary
ArchiveScriptLocation(File jarLocation, String defaultScriptEncoding, String defaultPostProcessingScriptDirName, Set<Qualifier> defaultRegisteredQualifiers, Set<Qualifier> defaultPatchQualifiers, String defaultScriptIndexRegexp, String defaultQualifierRegexp, String defaultTargetDatabaseRegexp, Set<String> defaultScriptFileExtensions, ScriptIndexes baseLineRevision, boolean ignoreCarriageReturnsWhenCalculatingCheckSum)
          Creates a new instance based on the contents of the given jar file
ArchiveScriptLocation(SortedSet<Script> scripts, String scriptEncoding, String postProcessingScriptDirName, Set<Qualifier> registeredQualifiers, Set<Qualifier> patchQualifiers, String scriptIndexRegexp, String qualifierRegexp, String targetDatabaseRegexp, Set<String> scriptFileExtensions, ScriptIndexes baseLineRevision, boolean ignoreCarriageReturnsWhenCalculatingCheckSum)
          Creates a new instance of the ArchiveScriptLocation, while there is no jar file available yet.
 
Method Summary
protected  void assertValidScriptLocation(File jarFile)
          Asserts that the script archive exists
protected  JarFile createJarFile(File jarFile)
           
protected  Properties getCustomProperties(File scriptLocation)
           
protected  File getJarFileWithoutSubPath(File jarFile)
          Gets jar file with the sub-path stripped off E.g. dir/my_archive.jar!
protected  Properties getJarProperties()
           
protected  String getJarSubPath(File jarFile)
          Gets the optional sub path in the jar file.
protected  Reader getPropertiesAsFile(Properties properties)
           
protected  SortedSet<Script> loadScripts(File scriptLocation)
          Initializes the scripts from the given jar file
protected  SortedSet<Script> loadScriptsFromJar(JarFile jarFile, String subPath)
           
protected  String toQualifiersPropertyValue(Set<Qualifier> qualifiers)
           
protected  void writeJarEntry(JarOutputStream jarOutputStream, String name, long timestamp, Reader entryContentReader)
          Writes the entry with the given name and content to the given JarOutputStream
 void writeToJarFile(File jarFile)
          Creates the jar containing the scripts and stores it in the file with the given file name
 
Methods inherited from class org.dbmaintain.script.repository.ScriptLocation
assertValidScriptExtensions, createQualifiers, createScript, createScriptFactory, getLocationName, getPatchQualifiers, getPostProcessingScriptDirName, getQualifierRegexp, getRegisteredQualifiers, getScriptEncoding, getScriptFileExtensions, getScripts, getTargetDatabaseRegexp, isScriptFileName, overrideValuesWithCustomConfiguration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArchiveScriptLocation

public ArchiveScriptLocation(SortedSet<Script> scripts,
                             String scriptEncoding,
                             String postProcessingScriptDirName,
                             Set<Qualifier> registeredQualifiers,
                             Set<Qualifier> patchQualifiers,
                             String scriptIndexRegexp,
                             String qualifierRegexp,
                             String targetDatabaseRegexp,
                             Set<String> scriptFileExtensions,
                             ScriptIndexes baseLineRevision,
                             boolean ignoreCarriageReturnsWhenCalculatingCheckSum)
Creates a new instance of the ArchiveScriptLocation, while there is no jar file available yet. This constructor can be used to initialize the container while the scripts are still on the file system, and to write the jar file afterwards.

Parameters:
scripts - The scripts contained in the container, not null
scriptEncoding - Encoding used to read the contents of the script, not null
postProcessingScriptDirName - The directory name that contains post processing scripts, may be null
registeredQualifiers - the registered qualifiers, not null
patchQualifiers - The qualifiers that indicate that this script is a patch script, not null
scriptIndexRegexp - The regexp that identifies the script index in the filename, not null
qualifierRegexp - The regexp that identifies a qualifier in the filename, not null
targetDatabaseRegexp - The regexp that indicates the target database in the filename, not null
scriptFileExtensions - The script file extensions
baseLineRevision - The baseline revision. If set, all scripts with a lower revision will be ignored
ignoreCarriageReturnsWhenCalculatingCheckSum - If true, carriage return chars will be ignored when calculating check sums

ArchiveScriptLocation

public ArchiveScriptLocation(File jarLocation,
                             String defaultScriptEncoding,
                             String defaultPostProcessingScriptDirName,
                             Set<Qualifier> defaultRegisteredQualifiers,
                             Set<Qualifier> defaultPatchQualifiers,
                             String defaultScriptIndexRegexp,
                             String defaultQualifierRegexp,
                             String defaultTargetDatabaseRegexp,
                             Set<String> defaultScriptFileExtensions,
                             ScriptIndexes baseLineRevision,
                             boolean ignoreCarriageReturnsWhenCalculatingCheckSum)
Creates a new instance based on the contents of the given jar file

Parameters:
jarLocation - the jar file
defaultScriptEncoding - the default script encoding
defaultPostProcessingScriptDirName - the default postprocessing dir name
defaultRegisteredQualifiers - the default registered (allowed) qualifiers
defaultPatchQualifiers - the default patch qualifiers
defaultScriptIndexRegexp - the default script index regexp
defaultQualifierRegexp - the default qualifier regexp
defaultTargetDatabaseRegexp - the default target database regexp
defaultScriptFileExtensions - the default script file extensions
baseLineRevision - The baseline revision. If set, all scripts with a lower revision will be ignored
ignoreCarriageReturnsWhenCalculatingCheckSum - If true, carriage return chars will be ignored when calculating check sums
Method Detail

assertValidScriptLocation

protected void assertValidScriptLocation(File jarFile)
Asserts that the script archive exists

Specified by:
assertValidScriptLocation in class ScriptLocation
Parameters:
jarFile - The location to validate, not null

loadScripts

protected SortedSet<Script> loadScripts(File scriptLocation)
Initializes the scripts from the given jar file

Specified by:
loadScripts in class ScriptLocation
Returns:
The scripts, as loaded from the jar

loadScriptsFromJar

protected SortedSet<Script> loadScriptsFromJar(JarFile jarFile,
                                               String subPath)

toQualifiersPropertyValue

protected String toQualifiersPropertyValue(Set<Qualifier> qualifiers)

getCustomProperties

protected Properties getCustomProperties(File scriptLocation)
Overrides:
getCustomProperties in class ScriptLocation
Parameters:
scriptLocation - The location of the jar file, not null
Returns:
The properties as a properties map

getPropertiesAsFile

protected Reader getPropertiesAsFile(Properties properties)
                              throws IOException
Parameters:
properties - A properties map
Returns:
The given properties as a reader to a properties file
Throws:
IOException - if a problem occurs opening the reader

writeToJarFile

public void writeToJarFile(File jarFile)
Creates the jar containing the scripts and stores it in the file with the given file name

Parameters:
jarFile - Path where the jar file is stored

getJarProperties

protected Properties getJarProperties()
Returns:
The jar location's configuration as a Properties object

writeJarEntry

protected void writeJarEntry(JarOutputStream jarOutputStream,
                             String name,
                             long timestamp,
                             Reader entryContentReader)
                      throws IOException
Writes the entry with the given name and content to the given JarOutputStream

Parameters:
jarOutputStream - OutputStream to the jar file
name - Name of the jar file entry
timestamp - Last modification date of the entry
entryContentReader - Reader giving access to the content of the jar entry
Throws:
IOException - In case of disk IO problems

createJarFile

protected JarFile createJarFile(File jarFile)

getJarSubPath

protected String getJarSubPath(File jarFile)
Gets the optional sub path in the jar file. E.g. dir/my_archive.jar!subpath/bla => returns subpath/bla/

Parameters:
jarFile - The jar file, not null
Returns:
the sub-path ending with /, null if there is no sub-path

getJarFileWithoutSubPath

protected File getJarFileWithoutSubPath(File jarFile)
Gets jar file with the sub-path stripped off E.g. dir/my_archive.jar!subpath/bla => returns dir/my_archive.jar

Parameters:
jarFile - The jar file, not null
Returns:
the jar file without sub-path, not null


Copyright © 2011. All Rights Reserved.