1 | |
|
2 | |
|
3 | |
package org.liquibase.maven.plugins; |
4 | |
|
5 | |
import liquibase.Liquibase; |
6 | |
import liquibase.database.Database; |
7 | |
import liquibase.exception.LiquibaseException; |
8 | |
import liquibase.resource.CompositeResourceAccessor; |
9 | |
import liquibase.resource.FileSystemResourceAccessor; |
10 | |
import liquibase.resource.ResourceAccessor; |
11 | |
|
12 | |
import org.apache.maven.plugin.MojoExecutionException; |
13 | |
import org.apache.maven.plugin.MojoFailureException; |
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | 8 | public abstract class AbstractLiquibaseChangeLogMojo extends AbstractLiquibaseMojo { |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
protected String changeLogFile; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
protected String contexts; |
37 | |
|
38 | |
@Override |
39 | |
protected void checkRequiredParametersAreSpecified() throws MojoFailureException { |
40 | 0 | super.checkRequiredParametersAreSpecified(); |
41 | |
|
42 | 0 | if (changeLogFile == null) { |
43 | 0 | throw new MojoFailureException("The changeLogFile must be specified."); |
44 | |
} |
45 | 0 | } |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
@Override |
54 | |
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException { |
55 | 0 | } |
56 | |
|
57 | |
@Override |
58 | |
protected void printSettings(String indent) { |
59 | 0 | super.printSettings(indent); |
60 | 0 | getLog().info(indent + "changeLogFile: " + changeLogFile); |
61 | 0 | getLog().info(indent + "context(s): " + contexts); |
62 | 0 | } |
63 | |
|
64 | |
@Override |
65 | |
protected ResourceAccessor getFileOpener(ClassLoader cl) { |
66 | 0 | ResourceAccessor mFO = new MavenResourceAccessor(cl); |
67 | 0 | ResourceAccessor fsFO = new FileSystemResourceAccessor(project.getBasedir().getAbsolutePath()); |
68 | 0 | return new CompositeResourceAccessor(mFO, fsFO); |
69 | |
} |
70 | |
|
71 | |
@Override |
72 | |
protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException { |
73 | |
try { |
74 | 0 | String changeLog = changeLogFile == null ? "" : changeLogFile.trim(); |
75 | 0 | return new Liquibase(changeLog, fo, db); |
76 | 0 | } catch (LiquibaseException ex) { |
77 | 0 | throw new MojoExecutionException("Error creating liquibase: " + ex.getMessage(), ex); |
78 | |
} |
79 | |
} |
80 | |
} |