Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
0ce0c3a5
Commit
0ce0c3a5
authored
Jul 17, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add failure analyzer for missing Liquibase changelog"
See gh-22320
parent
554a962a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
22 deletions
+38
-22
LiquibaseChangelogMissingFailureAnalyzer.java
...t/liquibase/LiquibaseChangelogMissingFailureAnalyzer.java
+13
-9
spring.factories
.../spring-boot/src/main/resources/META-INF/spring.factories
+1
-1
LiquibaseChangelogMissingFailureAnalyzerTests.java
...uibase/LiquibaseChangelogMissingFailureAnalyzerTests.java
+24
-12
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/
diagnostics/analyzer
/LiquibaseChangelogMissingFailureAnalyzer.java
→
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/
liquibase
/LiquibaseChangelogMissingFailureAnalyzer.java
View file @
0ce0c3a5
...
...
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
diagnostics
.
analyzer
;
package
org
.
springframework
.
boot
.
liquibase
;
import
java.io.FileNotFoundException
;
...
...
@@ -22,6 +22,7 @@ import liquibase.exception.ChangeLogParseException;
import
org.springframework.boot.diagnostics.AbstractFailureAnalyzer
;
import
org.springframework.boot.diagnostics.FailureAnalysis
;
import
org.springframework.util.StringUtils
;
/**
* An {@link AbstractFailureAnalyzer} that analyzes exceptions of type
...
...
@@ -33,20 +34,23 @@ class LiquibaseChangelogMissingFailureAnalyzer extends AbstractFailureAnalyzer<C
@Override
protected
FailureAnalysis
analyze
(
Throwable
rootFailure
,
ChangeLogParseException
cause
)
{
FileNotFoundException
exception
=
findCause
(
cause
,
FileNotFoundException
.
class
);
if
(
exception
!=
null
)
{
return
new
FailureAnalysis
(
getDescription
(
cause
),
"Make sure a Liquibase changelog is present at the configured path"
,
cause
);
FileNotFoundException
fileNotFound
=
findCause
(
cause
,
FileNotFoundException
.
class
);
if
(
fileNotFound
!=
null
)
{
String
changelogPath
=
extractChangelogPath
(
cause
);
if
(
StringUtils
.
hasText
(
changelogPath
))
{
return
new
FailureAnalysis
(
getDescription
(
changelogPath
),
"Make sure a Liquibase changelog is present at the configured path."
,
cause
);
}
}
return
null
;
}
private
String
getDescription
(
ChangeLogParseException
cause
)
{
return
"Liquibase failed to start because no changelog could be found at: "
+
extractChangelogPath
(
cause
);
}
private
String
extractChangelogPath
(
ChangeLogParseException
cause
)
{
return
cause
.
getMessage
().
substring
(
"Error parsing "
.
length
());
}
private
String
getDescription
(
String
changelogPath
)
{
return
"Liquibase failed to start because no changelog could be found at '"
+
changelogPath
+
"'."
;
}
}
spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories
View file @
0ce0c3a5
...
...
@@ -57,7 +57,7 @@ org.springframework.boot.diagnostics.analyzer.IncompatibleConfigurationFailureAn
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyNameFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyValueFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.PatternParseFailureAnalyzer,\
org.springframework.boot.
diagnostics.analyzer
.LiquibaseChangelogMissingFailureAnalyzer
org.springframework.boot.
liquibase
.LiquibaseChangelogMissingFailureAnalyzer
# FailureAnalysisReporters
org.springframework.boot.diagnostics.FailureAnalysisReporter=\
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/
diagnostics/analyzer/LiquibaseChangelogMissingFailureAnalyzerTest
.java
→
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/
liquibase/LiquibaseChangelogMissingFailureAnalyzerTests
.java
View file @
0ce0c3a5
...
...
@@ -14,12 +14,17 @@
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
diagnostics
.
analyzer
;
package
org
.
springframework
.
boot
.
liquibase
;
import
java.io.File
;
import
javax.sql.DataSource
;
import
liquibase.integration.spring.SpringLiquibase
;
import
org.junit.jupiter.api.AfterAll
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.boot.diagnostics.FailureAnalysis
;
...
...
@@ -35,15 +40,26 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Sebastiaan Fernandez
*/
class
LiquibaseChangelogMissingFailureAnalyzerTest
{
class
LiquibaseChangelogMissingFailureAnalyzerTests
{
@BeforeAll
static
void
configureDerbyLogLocation
(
@TempDir
File
temp
)
{
System
.
setProperty
(
"derby.stream.error.file"
,
new
File
(
temp
,
"derby.log"
).
getAbsolutePath
());
}
@AfterAll
static
void
clearDerbyLogLocation
(
@TempDir
File
temp
)
{
System
.
clearProperty
(
"derby.stream.error.file"
);
}
@Test
void
changelogParseExceptionDueToChangelogNotPresent
()
{
FailureAnalysis
analysis
=
performAnalysis
();
assertThat
(
analysis
.
getDescription
())
.
isEqualTo
(
"Liquibase failed to start because no changelog could be found at: "
+
"classpath:/db/changelog/db.changelog-master.yaml"
);
assertThat
(
analysis
.
getAction
()).
isEqualTo
(
"Make sure a Liquibase changelog is present at the configured path"
);
.
isEqualTo
(
"Liquibase failed to start because no changelog could be found at '"
+
"classpath:/db/changelog/db.changelog-master.yaml'."
);
assertThat
(
analysis
.
getAction
())
.
isEqualTo
(
"Make sure a Liquibase changelog is present at the configured path."
);
}
private
FailureAnalysis
performAnalysis
()
{
...
...
@@ -53,11 +69,8 @@ class LiquibaseChangelogMissingFailureAnalyzerTest {
}
private
BeanCreationException
createFailure
()
{
try
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
register
(
LiquibaseConfiguration
.
class
);
context
.
refresh
();
context
.
close
();
try
(
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
LiquibaseConfiguration
.
class
))
{
return
null
;
}
catch
(
BeanCreationException
ex
)
{
...
...
@@ -70,14 +83,13 @@ class LiquibaseChangelogMissingFailureAnalyzerTest {
@Bean
DataSource
dataSource
()
{
return
DataSourceBuilder
.
create
().
url
(
"jdbc:hsqldb:mem:
normal
"
).
username
(
"sa"
).
build
();
return
DataSourceBuilder
.
create
().
url
(
"jdbc:hsqldb:mem:
test
"
).
username
(
"sa"
).
build
();
}
@Bean
SpringLiquibase
springLiquibase
(
DataSource
dataSource
)
{
SpringLiquibase
liquibase
=
new
SpringLiquibase
();
liquibase
.
setChangeLog
(
"classpath:/db/changelog/db.changelog-master.yaml"
);
liquibase
.
setShouldRun
(
true
);
liquibase
.
setDataSource
(
dataSource
);
return
liquibase
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment