Skip to content

Commit

Permalink
Fix bug and log exceptions otherwise swallowed
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Dec 13, 2023
1 parent 30fe7b6 commit 6b01e4f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.rewrite.parsers;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.openrewrite.ExecutionContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.rewrite.test.util;

import lombok.extern.slf4j.Slf4j;
import org.openrewrite.ExecutionContext;
import org.openrewrite.InMemoryExecutionContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
Expand All @@ -34,6 +35,7 @@
/**
* @author Fabian Krüger
*/
@Slf4j
public class ParserExecutionHelper {

public ParallelParsingResult parseParallel(Path baseDir) {
Expand Down Expand Up @@ -87,23 +89,35 @@ public RewriteProjectParsingResult parseWithComparingParser(Path baseDir, Parser
ExecutionContext executionContext) {
RewriteMavenProjectParser comparingParser = new ComparingParserFactory()
.createComparingParser(parserProperties);
if (executionContext != null) {
return comparingParser.parse(baseDir, executionContext);
try {
if (executionContext != null) {
return comparingParser.parse(baseDir, executionContext);
}
else {
return comparingParser.parse(baseDir);
}
}
else {
return comparingParser.parse(baseDir);
catch (Exception e) {
log.error("Failure while parsing with %s".formatted(RewriteMavenProjectParser.class.getName()), e);
throw new RuntimeException(e);
}
}

public RewriteProjectParsingResult parseWithRewriteProjectParser(Path baseDir, ParserProperties parserProperties) {
AtomicReference<RewriteProjectParsingResult> atomicRef = new AtomicReference<>();
new ApplicationContextRunner().withUserConfiguration(SbmSupportRewriteConfiguration.class)
.withBean("parser-org.springframework.parsers.rewrite.ParserProperties", ParserProperties.class,
.withBean("parser-org.springframework.rewrite.parsers.ParserProperties", ParserProperties.class,
() -> parserProperties)
.run(appCtx -> {
RewriteProjectParser sut = appCtx.getBean(RewriteProjectParser.class);
RewriteProjectParsingResult testedParserResult = sut.parse(baseDir);
atomicRef.set(testedParserResult);
try {
RewriteProjectParser sut = appCtx.getBean(RewriteProjectParser.class);
RewriteProjectParsingResult testedParserResult = sut.parse(baseDir);
atomicRef.set(testedParserResult);
}
catch (Exception e) {
log.error("Failure while parsing with %s".formatted(RewriteProjectParser.class.getName()), e);
throw new RuntimeException(e);
}
});
return atomicRef.get();
}
Expand Down

0 comments on commit 6b01e4f

Please sign in to comment.