| 1 |
|
package liquibase.precondition; |
| 2 |
|
|
| 3 |
|
import java.util.HashMap; |
| 4 |
|
import java.util.Map; |
| 5 |
|
import java.util.SortedSet; |
| 6 |
|
import java.util.TreeSet; |
| 7 |
|
|
| 8 |
|
import liquibase.changelog.ChangeSet; |
| 9 |
|
import liquibase.changelog.DatabaseChangeLog; |
| 10 |
|
import liquibase.database.Database; |
| 11 |
|
import liquibase.exception.CustomPreconditionErrorException; |
| 12 |
|
import liquibase.exception.CustomPreconditionFailedException; |
| 13 |
|
import liquibase.exception.PreconditionErrorException; |
| 14 |
|
import liquibase.exception.PreconditionFailedException; |
| 15 |
|
import liquibase.exception.ValidationErrors; |
| 16 |
|
import liquibase.exception.Warnings; |
| 17 |
|
import liquibase.precondition.core.ErrorPrecondition; |
| 18 |
|
import liquibase.precondition.core.FailedPrecondition; |
| 19 |
|
import liquibase.util.ObjectUtil; |
| 20 |
|
|
|
|
|
| 6.2% |
Uncovered Elements: 30 (32) |
Complexity: 14 |
Complexity Density: 0.61 |
|
| 21 |
|
public class CustomPreconditionWrapper implements Precondition { |
| 22 |
|
|
| 23 |
|
private String className; |
| 24 |
|
private ClassLoader classLoader; |
| 25 |
|
|
| 26 |
|
private SortedSet<String> params = new TreeSet<String>(); |
| 27 |
|
private Map<String, String> paramValues = new HashMap<String, String>(); |
| 28 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 29 |
0
|
public String getClassName() {... |
| 30 |
0
|
return className; |
| 31 |
|
} |
| 32 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 33 |
0
|
public void setClassName(String className) {... |
| 34 |
0
|
this.className = className; |
| 35 |
|
} |
| 36 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 37 |
0
|
public ClassLoader getClassLoader() {... |
| 38 |
0
|
return classLoader; |
| 39 |
|
} |
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 41 |
0
|
public void setClassLoader(ClassLoader classLoader) {... |
| 42 |
0
|
this.classLoader = classLoader; |
| 43 |
|
} |
| 44 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 45 |
0
|
public void setParam(String name, String value) {... |
| 46 |
0
|
this.params.add(name); |
| 47 |
0
|
this.paramValues.put(name, value); |
| 48 |
|
} |
| 49 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 50 |
0
|
@Override... |
| 51 |
|
public Warnings warn(Database database) { |
| 52 |
0
|
return new Warnings(); |
| 53 |
|
} |
| 54 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 55 |
0
|
@Override... |
| 56 |
|
public ValidationErrors validate(Database database) { |
| 57 |
0
|
return new ValidationErrors(); |
| 58 |
|
} |
| 59 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 6 |
Complexity Density: 0.43 |
|
| 60 |
0
|
@Override... |
| 61 |
|
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) |
| 62 |
|
throws PreconditionFailedException, PreconditionErrorException { |
| 63 |
0
|
CustomPrecondition customPrecondition; |
| 64 |
0
|
try { |
| 65 |
|
|
| 66 |
0
|
try { |
| 67 |
0
|
customPrecondition = (CustomPrecondition) Class.forName(className, true, classLoader).newInstance(); |
| 68 |
|
} catch (ClassCastException e) { |
| 69 |
0
|
customPrecondition = (CustomPrecondition) Class.forName(className).newInstance(); |
| 70 |
|
} |
| 71 |
|
} catch (Exception e) { |
| 72 |
0
|
throw new PreconditionFailedException("Could not open custom precondition class " + className, changeLog, |
| 73 |
|
this); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
0
|
for (String param : params) { |
| 77 |
0
|
try { |
| 78 |
0
|
ObjectUtil.setProperty(customPrecondition, param, paramValues.get(param)); |
| 79 |
|
} catch (Exception e) { |
| 80 |
0
|
throw new PreconditionFailedException("Error setting parameter " + param + " on custom precondition " |
| 81 |
|
+ className, changeLog, this); |
| 82 |
|
} |
| 83 |
|
} |
| 84 |
|
|
| 85 |
0
|
try { |
| 86 |
0
|
customPrecondition.check(database); |
| 87 |
|
} catch (CustomPreconditionFailedException e) { |
| 88 |
0
|
throw new PreconditionFailedException(new FailedPrecondition("Custom Precondition Failed: " |
| 89 |
|
+ e.getMessage(), changeLog, this)); |
| 90 |
|
} catch (CustomPreconditionErrorException e) { |
| 91 |
0
|
throw new PreconditionErrorException(new ErrorPrecondition(e, changeLog, this)); |
| 92 |
|
} |
| 93 |
|
} |
| 94 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 95 |
8
|
@Override... |
| 96 |
|
public String getName() { |
| 97 |
8
|
return "customPrecondition"; |
| 98 |
|
} |
| 99 |
|
} |