1 package net.sf.mavenhist.maven2.plugin; 2 3 import net.sf.mavenhist.persistency.IPersistency; 4 import net.sf.mavenhist.persistency.PersistencyException; 5 6 import org.apache.commons.lang.builder.ReflectionToStringBuilder; 7 import org.apache.maven.plugin.MojoExecutionException; 8 9 /** 10 * Generates needed object to use the historisation. e.g. setting up the db 11 * tables. 12 * 13 * @goal initialise-historisation 14 */ 15 public class InitialiseHistorisationMojo extends AbstractHistorisationMojo { 16 17 /** 18 * Executes the mojo. Creates all needed db infrastructure to run the historisation of values 19 * successful. 20 * 21 * @throws MojoExecutionException initialisation of db failed. 22 */ 23 public void execute() throws MojoExecutionException { 24 getLog().debug( 25 "Historisation initialisation executed with these settings: " 26 + ReflectionToStringBuilder.reflectionToString(this)); 27 initialise(); 28 getLog().info("Historisation initialisation successful. Persistency store ready to use."); 29 } 30 31 /** 32 * Initializes the database and wraps all possibly occuring exceptions. 33 * 34 * @throws MojoExecutionException if something failed during the initialisation. 35 */ 36 private void initialise() throws MojoExecutionException { 37 try { 38 IPersistency persistable = getCurrentPersistency(); 39 persistable.initializeMetricsDataBase(); 40 } catch (ClassNotFoundException e) { 41 throwPersistencyLoadingException(e); 42 } catch (InstantiationException e) { 43 throwPersistencyLoadingException(e); 44 } catch (IllegalAccessException e) { 45 throwPersistencyLoadingException(e); 46 } catch (PersistencyException e) { 47 throwPersistencyLoadingException(e); 48 } 49 } 50 }