|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ChangeLogParserFactory | Line # 13 | 21 | 0% | 11 | 1 | 97% |
0.969697
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (19) | |||
| Result | |||
|
0.72727275
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.testNestedChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.testNestedChangeLog
|
1 PASS | |
|
0.57575756
|
liquibase.parser.ChangeLogParserFactoryTest.reset
liquibase.parser.ChangeLogParserFactoryTest.reset
|
1 PASS | |
|
0.57575756
|
liquibase.changelog.ChangeLogParserFactoryTest.reset
liquibase.changelog.ChangeLogParserFactoryTest.reset
|
1 PASS | |
|
0.5151515
|
liquibase.parser.ChangeLogParserFactoryTest.getExtensionParser
liquibase.parser.ChangeLogParserFactoryTest.getExtensionParser
|
1 PASS | |
|
0.4848485
|
liquibase.changelog.ChangeLogParserFactoryTest.getParser_byFile
liquibase.changelog.ChangeLogParserFactoryTest.getParser_byFile
|
1 PASS | |
|
0.4848485
|
liquibase.changelog.ChangeLogParserFactoryTest.getParser_noneMatching
liquibase.changelog.ChangeLogParserFactoryTest.getParser_noneMatching
|
1 PASS | |
|
0.4848485
|
liquibase.changelog.ChangeLogParserFactoryTest.getParser_byExtension
liquibase.changelog.ChangeLogParserFactoryTest.getParser_byExtension
|
1 PASS | |
|
0.3939394
|
liquibase.changelog.ChangeLogParserFactoryTest.unregister_instance
liquibase.changelog.ChangeLogParserFactoryTest.unregister_instance
|
1 PASS | |
|
0.3939394
|
liquibase.parser.ChangeLogParserFactoryTest.unregister_instance
liquibase.parser.ChangeLogParserFactoryTest.unregister_instance
|
1 PASS | |
|
0.3030303
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.doubleNestedRelativeChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.doubleNestedRelativeChangeLog
|
1 PASS | |
|
0.3030303
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.nestedRelativeChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.nestedRelativeChangeLog
|
1 PASS | |
|
0.3030303
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.doubleNestedChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.doubleNestedChangeLog
|
1 PASS | |
|
0.3030303
|
liquibase.parser.ChangeLogParserFactoryTest.getParsers
liquibase.parser.ChangeLogParserFactoryTest.getParsers
|
1 PASS | |
|
0.27272728
|
liquibase.changelog.ChangeLogParserFactoryTest.register
liquibase.changelog.ChangeLogParserFactoryTest.register
|
1 PASS | |
|
0.27272728
|
liquibase.parser.ChangeLogParserFactoryTest.register
liquibase.parser.ChangeLogParserFactoryTest.register
|
1 PASS | |
|
0.18181819
|
liquibase.parser.ChangeLogParserFactoryTest.builtInGeneratorsAreFound
liquibase.parser.ChangeLogParserFactoryTest.builtInGeneratorsAreFound
|
1 PASS | |
|
0.18181819
|
liquibase.changelog.ChangeLogParserFactoryTest.builtInGeneratorsAreFound
liquibase.changelog.ChangeLogParserFactoryTest.builtInGeneratorsAreFound
|
1 PASS | |
|
0.121212125
|
liquibase.changelog.ChangeLogParserFactoryTest.getInstance
liquibase.changelog.ChangeLogParserFactoryTest.getInstance
|
1 PASS | |
|
0.121212125
|
liquibase.parser.ChangeLogParserFactoryTest.getInstance
liquibase.parser.ChangeLogParserFactoryTest.getInstance
|
1 PASS | |
| 1 | package liquibase.parser; | |
| 2 | ||
| 3 | import java.util.ArrayList; | |
| 4 | import java.util.Collections; | |
| 5 | import java.util.Comparator; | |
| 6 | import java.util.List; | |
| 7 | ||
| 8 | import liquibase.exception.LiquibaseException; | |
| 9 | import liquibase.exception.UnexpectedLiquibaseException; | |
| 10 | import liquibase.resource.ResourceAccessor; | |
| 11 | import liquibase.servicelocator.ServiceLocator; | |
| 12 | ||
| 13 | public class ChangeLogParserFactory { | |
| 14 | ||
| 15 | private static ChangeLogParserFactory instance; | |
| 16 | ||
| 17 | private List<ChangeLogParser> parsers; | |
| 18 | private Comparator<ChangeLogParser> changelogParserComparator; | |
| 19 | ||
| 20 | 17 |
public static void reset() { |
| 21 | 17 | instance = new ChangeLogParserFactory(); |
| 22 | } | |
| 23 | ||
| 24 | 43 |
public static ChangeLogParserFactory getInstance() { |
| 25 | 43 | if (instance == null) { |
| 26 | 1 | instance = new ChangeLogParserFactory(); |
| 27 | } | |
| 28 | 43 | return instance; |
| 29 | } | |
| 30 | ||
| 31 | 18 |
private ChangeLogParserFactory() { |
| 32 | 18 | Class<? extends ChangeLogParser>[] classes; |
| 33 | 18 | changelogParserComparator = new Comparator<ChangeLogParser>() { |
| 34 | 66 |
@Override |
| 35 | public int compare(ChangeLogParser o1, ChangeLogParser o2) { | |
| 36 | 66 | return Integer.valueOf(o2.getPriority()).compareTo(o1.getPriority()); |
| 37 | } | |
| 38 | }; | |
| 39 | ||
| 40 | 18 | parsers = new ArrayList<ChangeLogParser>(); |
| 41 | 18 | try { |
| 42 | 18 | classes = ServiceLocator.getInstance().findClasses(ChangeLogParser.class); |
| 43 | ||
| 44 | 18 | for (Class<? extends ChangeLogParser> clazz : classes) { |
| 45 | 54 | register((ChangeLogParser) clazz.getConstructor().newInstance()); |
| 46 | } | |
| 47 | } catch (Exception e) { | |
| 48 | 0 | throw new UnexpectedLiquibaseException(e); |
| 49 | } | |
| 50 | ||
| 51 | } | |
| 52 | ||
| 53 | 20 |
public List<ChangeLogParser> getParsers() { |
| 54 | 20 | return parsers; |
| 55 | } | |
| 56 | ||
| 57 | 13 |
public ChangeLogParser getParser(String fileNameOrExtension, ResourceAccessor resourceAccessor) |
| 58 | throws LiquibaseException { | |
| 59 | 13 | for (ChangeLogParser parser : parsers) { |
| 60 | 22 | if (parser.supports(fileNameOrExtension, resourceAccessor)) { |
| 61 | 12 | return parser; |
| 62 | } | |
| 63 | } | |
| 64 | ||
| 65 | 1 | throw new LiquibaseException("Cannot find parser that supports " + fileNameOrExtension); |
| 66 | } | |
| 67 | ||
| 68 | 68 |
public void register(ChangeLogParser changeLogParser) { |
| 69 | 68 | parsers.add(changeLogParser); |
| 70 | 68 | Collections.sort(parsers, changelogParserComparator); |
| 71 | } | |
| 72 | ||
| 73 | 3 |
public void unregister(ChangeLogParser changeLogParser) { |
| 74 | 3 | parsers.remove(changeLogParser); |
| 75 | } | |
| 76 | } | |
|
||||||||||||