Skip to content

Commit

Permalink
support concurrent build in maven plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrwielgolaski-tomtom authored and filipelautert committed Aug 29, 2023
1 parent 5e30bb5 commit f00d611
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected AbstractIntegrationTest(String changelogDir, Database dbms) throws Exc
this.pathChangeLog = "changelogs/common/pathChangeLog.xml";
logger = Scope.getCurrentScope().getLog(getClass());

Scope.setScopeManager(new TestScopeManager());
Scope.setScopeManager(new TestScopeManager(Scope.getCurrentScope()));
}

private void openConnection() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
@SuppressWarnings("java:S2583")
public abstract class AbstractLiquibaseMojo extends AbstractMojo {

static {
// If maven is called with -T and a value larger than 1, it can get confused under heavy thread load
Scope.setScopeManager( new ThreadLocalScopeManager(null));
}

/**
* Suffix for fields that are representing a default value for a another field.
*/
Expand Down Expand Up @@ -709,8 +714,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getLog().warn("Liquibase NOT skipped because file " + skipOnFileExists + " does NOT exists");
}

// If maven is called with -T and a value larger than 1, it can get confused under heavy thread load
Scope.setScopeManager(new ThreadLocalScopeManager());
try {
Scope.child(setUpLogging(), () -> {

Expand Down
14 changes: 0 additions & 14 deletions liquibase-standard/src/main/java/liquibase/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,7 @@ public static Scope getCurrentScope() {
}

public static void setScopeManager(ScopeManager scopeManager) {
Scope currentScope = getCurrentScope();
if (currentScope == null) {
currentScope = new Scope();
}

try {
currentScope = scopeManager.init(currentScope);
} catch (Exception e) {
Scope.getCurrentScope().getLog(Scope.class).warning(e.getMessage(), e);
}
scopeManager.setCurrentScope(currentScope);

Scope.scopeManager = scopeManager;


}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public class ThreadLocalScopeManager extends ScopeManager {
private final ThreadLocal<Scope> threadLocalScopes = new ThreadLocal<>();

public ThreadLocalScopeManager() {
this.rootScope = Scope.getCurrentScope();
this(Scope.getCurrentScope());
}

public ThreadLocalScopeManager(Scope rootScope) {
this.rootScope = rootScope;
}

@Override
Expand All @@ -39,4 +43,4 @@ protected Scope init(Scope scope) throws Exception {
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public abstract class AbstractOutputWriterCommandStep extends AbstractHelperCommandStep implements CleanUpCommandStep {

private static OutputStreamWriter outputStreamWriter;
private OutputStreamWriter outputStreamWriter;

@Override
public List<Class<?>> providedDependencies() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public ZipResourceAccessor(Path file) throws FileNotFoundException {
try {
this.fileSystem = FileSystems.getFileSystem(finalUri);
} catch (FileSystemNotFoundException e) {
this.fileSystem = FileSystems.newFileSystem(finalUri, Collections.emptyMap(), Scope.getCurrentScope().getClassLoader());
try {
this.fileSystem = FileSystems.newFileSystem(finalUri, Collections.emptyMap(), Scope.getCurrentScope().getClassLoader());
} catch (FileSystemAlreadyExistsException ex) {
this.fileSystem = FileSystems.getFileSystem(finalUri);
}
}
} catch (Throwable e) {
throw new IllegalArgumentException(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class StandardChangeTest extends Specification {
@Shared resourceSupplier = new ResourceSupplier()

def setup() {
Scope.setScopeManager(new TestScopeManager());
Scope.setScopeManager(new TestScopeManager(Scope.getCurrentScope()));
}

def cleanup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

public class TestScopeManager extends SingletonScopeManager {

public TestScopeManager() {

public TestScopeManager(Scope scope) throws Exception {
setCurrentScope(init(scope));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
public abstract class AbstractAntTaskTest {

@BeforeClass
public static void setup() {
Scope.setScopeManager(new TestScopeManager());
public static void setup() throws Exception {
Scope.setScopeManager(new TestScopeManager(Scope.getCurrentScope()));
}

protected static void setProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class VerifyChangeClassesTest extends AbstractVerifyTest {


@BeforeClass
public static void setUpClass() {
Scope.setScopeManager(new TestScopeManager());
public static void setUpClass() throws Exception {
Scope.setScopeManager(new TestScopeManager(Scope.getCurrentScope()));
}

@Test
Expand Down

0 comments on commit f00d611

Please sign in to comment.