Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static FlamingockMetadata getPreviewPipeline(String stageName, Trio<Class
changeInfo.getOrder(),
changeInfo.getAuthor(),
trio.getFirst().getName(),
null,
PreviewConstructor.getDefault(),
new PreviewMethod("apply", getParameterTypes(trio.getSecond())),
rollback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public static PreviewPipeline getPreviewPipeline(String stageName, Trio<Class<?>
changeInfo.getOrder(),
changeInfo.getAuthor(),
trio.getFirst().getName(),
null,
PreviewConstructor.getDefault(),
new PreviewMethod("apply", getParameterTypes(trio.getSecond())),
rollback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void shouldConvertToAndFromAuditEntryWithTxType() {
assertEquals(original.getTaskId(), converted.getTaskId());
assertEquals(original.getAuthor(), converted.getAuthor());
assertEquals(original.getState(), converted.getState());
assertEquals(original.getSourceFile(), converted.getSourceFile());
}

@Test
Expand Down Expand Up @@ -129,6 +130,7 @@ void shouldConvertToAndFromAuditEntryWithTargetSystemId() {
assertEquals(original.getTaskId(), converted.getTaskId());
assertEquals(original.getAuthor(), converted.getAuthor());
assertEquals(original.getState(), converted.getState());
assertEquals(original.getSourceFile(), converted.getSourceFile());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static FlamingockMetadata getPreviewPipeline(String stageName, Trio<Class
changeInfo.getOrder(),
changeInfo.getAuthor(),
trio.getFirst().getName(),
null,
PreviewConstructor.getDefault(),
new PreviewMethod("apply", getParameterTypes(trio.getSecond())),
rollback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ public AbstractPreviewTask(String id,
String order,
String author,
String source,
String sourceFile,
boolean runAlways,
Boolean transactional,
boolean system,
TargetSystemDescriptor targetSystem,
RecoveryDescriptor recovery,
boolean legacy) {
super(id, order, author, source, runAlways, transactional, system, targetSystem, recovery, legacy);
super(id, order, author, source, sourceFile, runAlways, transactional, system, targetSystem, recovery, legacy);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public CodePreviewChange(String id,
String order,
String author,
String sourceClassPath,
String sourceFile,
PreviewConstructor previewConstructor,
PreviewMethod applyPreviewMethod,
PreviewMethod rollbackPreviewMethod,
Expand All @@ -45,7 +46,7 @@ public CodePreviewChange(String id,
TargetSystemDescriptor targetSystem,
RecoveryDescriptor recovery,
boolean legacy) {
super(id, order, author, sourceClassPath, runAlways, transactional, system, targetSystem, recovery, legacy);
super(id, order, author, sourceClassPath, sourceFile, runAlways, transactional, system, targetSystem, recovery, legacy);
this.previewConstructor = previewConstructor;
this.applyPreviewMethod = applyPreviewMethod;
this.rollbackPreviewMethod = rollbackPreviewMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TemplatePreviewChange(String fileName,
Object steps,
TargetSystemDescriptor targetSystem,
RecoveryDescriptor recovery) {
super(id, order, author, templateName, runAlways, transactional, system, targetSystem, recovery, false);
super(id, order, author, templateName, fileName, runAlways, transactional, system, targetSystem, recovery, false);
this.fileName = fileName;
this.profiles = profiles;
this.configuration = configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private CodePreviewChange getCodePreviewChange() {
order,
author,
sourceClassPath,
null,
constructor,
applyMethod,
rollbackMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public abstract class AbstractTaskDescriptor implements TaskDescriptor {

protected String source;

protected String sourceFile;

protected boolean runAlways;

protected Boolean transactionalFlag;
Expand All @@ -47,6 +49,7 @@ public AbstractTaskDescriptor(String id,
String order,
String author,
String source,
String sourceFile,
boolean runAlways,
Boolean transactionalFlag,
boolean system,
Expand All @@ -57,6 +60,7 @@ public AbstractTaskDescriptor(String id,
this.order = order;
this.author = author;
this.source = source;
this.sourceFile = sourceFile;
this.runAlways = runAlways;
this.transactionalFlag = transactionalFlag;
this.system = system;
Expand Down Expand Up @@ -85,6 +89,11 @@ public String getSource() {
return source;
}

@Override
public String getSourceFile() {
return sourceFile;
}

@Override
public boolean isRunAlways() {
return runAlways;
Expand Down Expand Up @@ -131,6 +140,10 @@ public void setSource(String source) {
this.source = source;
}

public void setSourceFile(String sourceFile) {
this.sourceFile = sourceFile;
}

public void setRunAlways(boolean runAlways) {
this.runAlways = runAlways;
}
Expand Down Expand Up @@ -174,6 +187,7 @@ public int hashCode() {
public String toString() {
return new StringJoiner(", ", AbstractTaskDescriptor.class.getSimpleName() + "[", "]")
.add("source=" + source)
.add("sourceFile=" + sourceFile)
.add("sourceClass=" + getSource())
.add("sourceName='" + getSource() + "'")
.add("id='" + getId() + "'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public interface TaskDescriptor extends Comparable<TaskDescriptor> {

String getSource();

String getSourceFile();

Optional<String> getOrder();

TargetSystemDescriptor getTargetSystem();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2026 Flamingock (https://www.flamingock.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.flamingock.internal.common.core.preview.builder;

import io.flamingock.internal.common.core.preview.CodePreviewChange;
import io.flamingock.internal.common.core.preview.PreviewConstructor;
import io.flamingock.internal.common.core.preview.PreviewMethod;
import io.flamingock.internal.common.core.task.RecoveryDescriptor;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertNull;

class CodePreviewTaskBuilderTest {

@Test
void shouldBuildNullSourceFileForCodeChanges() {
CodePreviewChange preview = CodePreviewTaskBuilder.instance()
.setId("test-id")
.setOrder("001")
.setAuthor("author")
.setSourceClassPath("io.flamingock.TestChange")
.setConstructor(PreviewConstructor.getDefault())
.setApplyMethod(new PreviewMethod("apply", Collections.emptyList()))
.setRollbackMethod(null)
.setRunAlways(false)
.setTransactionalFlag(true)
.setSystem(false)
.setRecovery(RecoveryDescriptor.getDefault())
.build();

assertNull(preview.getSourceFile());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void shouldPreserveNullTransactionalFromYaml() {
.build();

assertEquals(Optional.empty(), preview.getTransactionalFlag());
assertEquals("_0001__test.yaml", preview.getSourceFile());
}

@Test
Expand All @@ -56,6 +57,7 @@ void shouldPreserveExplicitTrueTransactional() {
.build();

assertEquals(Optional.of(true), preview.getTransactionalFlag());
assertEquals("_0001__test.yaml", preview.getSourceFile());
}

@Test
Expand All @@ -71,5 +73,6 @@ void shouldPreserveExplicitFalseTransactional() {
.build();

assertEquals(Optional.of(false), preview.getTransactionalFlag());
assertEquals("_0001__test.yaml", preview.getSourceFile());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AbstractTaskDescriptorTest {

private static AbstractTaskDescriptor createDescriptor(Boolean transactional) {
return new AbstractTaskDescriptor(
"test-id", "001", "author", "source",
"test-id", "001", "author", "source", "sourceFile",
false, transactional, false,
null, null, false
) {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public AuditEntry toAuditEntry() {
getChangeType(),
loadedChange.getSource(),
runtimeContext.getMethodExecutor(),
null, //TODO: set sourceFile
loadedChange.getSourceFile(),
runtimeContext.getDuration(),
stageExecutionContext.getHostname(),
stageExecutionContext.getMetadata(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public String getSource() {
return loadedChange.getSource();
}

@Override
public String getSourceFile() {
return loadedChange.getSourceFile();
}

@Override
public Optional<String> getOrder() {
return loadedChange.getOrder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ public AbstractLoadedTask(String id,
String order,
String author,
String implementationSourceName,
String sourceFile,
boolean runAlways,
Boolean transactionalFlag,
boolean transactional,
boolean system,
TargetSystemDescriptor targetSystem,
RecoveryDescriptor recovery,
boolean legacy) {
super(id, order, author, implementationSourceName, runAlways, transactionalFlag, system, targetSystem, recovery, legacy);
super(id, order, author, implementationSourceName, sourceFile, runAlways, transactionalFlag, system, targetSystem, recovery, legacy);
this.transactional = transactional;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public abstract class AbstractReflectionLoadedTask extends AbstractLoadedTask {
/**
* The source file name where this change is defined.
*
* <p>This represents the original source of the change definition:</p>
* <p>This represents the original source of the change definition when available:</p>
* <ul>
* <li><b>Template-based:</b> The YAML/JSON template file name (e.g., "create-users.yaml")</li>
* <li><b>Code-based:</b> The Java class name containing the {@code @Change} annotation</li>
* <li><b>Code-based:</b> {@code null} for now</li>
* </ul>
*
* <p>Note: This may differ from the {@link #implementationClass} in template-based scenarios
Expand Down Expand Up @@ -103,15 +103,15 @@ public AbstractReflectionLoadedTask(String fileName,
TargetSystemDescriptor targetSystem,
RecoveryDescriptor recovery,
boolean legacy) {
super(id, order, author, implementationClass.getName(), runAlways, transactionalFlag, transactional, system, targetSystem, recovery, legacy);
super(id, order, author, implementationClass.getName(), fileName, runAlways, transactionalFlag, transactional, system, targetSystem, recovery, legacy);
this.fileName = fileName;
this.implementationClass = implementationClass;
}

/**
* Returns the source file name where this change is defined.
*
* @return the file name (template file for template-based, class name for code-based)
* @return the file name for template-based changes, or {@code null} when unavailable
* @see #fileName
*/
public String getFileName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class CodeLoadedChange extends AbstractLoadedChange {
String order,
String author,
Class<?> changeClass,
String sourceFile,
Constructor<?> constructor,
Method applyMethod,
Optional<Method> rollbackMethod,
Expand All @@ -42,7 +43,7 @@ public class CodeLoadedChange extends AbstractLoadedChange {
TargetSystemDescriptor targetSystem,
RecoveryDescriptor recovery,
boolean legacy) {
super(changeClass.getSimpleName(), id, order, author, changeClass, constructor, runAlways, transactionalFlag, transactional, systemTask, targetSystem, recovery, legacy);
super(sourceFile, id, order, author, changeClass, constructor, runAlways, transactionalFlag, transactional, systemTask, targetSystem, recovery, legacy);
this.applyMethod = applyMethod;
this.rollbackMethod = rollbackMethod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class CodeLoadedTaskBuilder implements LoadedTaskBuilder<CodeLoadedChange
private Optional<Method> rollbackMethod;
private boolean isRunAlways;
private Boolean transactionalFlag;
private String sourceFile;
private boolean isSystem;
private TargetSystemDescriptor targetSystem;
private RecoveryDescriptor recovery;
Expand Down Expand Up @@ -78,6 +79,7 @@ private CodeLoadedTaskBuilder setPreview(CodePreviewChange preview) {
setOrder(preview.getOrder().orElse(null));
setAuthor(preview.getAuthor());
setChangeClassName(preview.getSource());
setSourceFile(preview.getSourceFile());
setConstructor(getConstructorFromPreview(preview));
setApplyMethod(getApplyMethodFromPreview(preview));
setRollbackMethod(getRollbackMethodFromPreview(preview));
Expand Down Expand Up @@ -151,6 +153,11 @@ public CodeLoadedTaskBuilder setTransactionalFlag(Boolean transactionalFlag) {
return this;
}

public CodeLoadedTaskBuilder setSourceFile(String sourceFile) {
this.sourceFile = sourceFile;
return this;
}

public CodeLoadedTaskBuilder setSystem(boolean system) {
this.isSystem = system;
return this;
Expand Down Expand Up @@ -183,6 +190,7 @@ public CodeLoadedChange build() {
order,
author,
changeClass,
sourceFile,
constructor,
applyMethod,
rollbackMethod,
Expand All @@ -202,6 +210,7 @@ private void setFromFlamingockChangeAnnotation(Class<?> sourceClass, Change anno
setOrder(ChangeOrderExtractor.extractOrderFromClassName(changeId, sourceClass.getName()));
setAuthor(annotation.author());
setChangeClassName(sourceClass.getName());
setSourceFile(null);
setConstructor(getConstructor(sourceClass));
setApplyMethod(getApplyMethodFromAnnotation(sourceClass));
setRollbackMethod(getRollbackMethodFromAnnotation(sourceClass));
Expand Down
Loading
Loading