Skip to content

Fix for resolve paths in cli #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -21,6 +21,7 @@
import org.contextmapper.dsl.standalone.ContextMapperStandaloneSetup;
import org.contextmapper.dsl.standalone.StandaloneContextMapperAPI;
import org.eclipse.xtext.generator.IGenerator2;
import org.contextmapper.dsl.cml.CMLImportResolver;

import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -51,7 +52,12 @@ public void run(String[] args) {

if (doesOutputDirExist(this.outputDir)) {
StandaloneContextMapperAPI cmAPI = ContextMapperStandaloneSetup.getStandaloneAPI();
CMLResource cmlResource = cmAPI.loadCML(inputPath);
File inputFile = new File(inputPath).getAbsoluteFile();
CMLResource cmlResource = cmAPI.loadCML(inputFile);

// Ensure imports are resolved before generation
new CMLImportResolver().resolveImportedResources(cmlResource);

cmAPI.callGenerator(cmlResource, getGenerator(cmd), this.outputDir);
System.out.println("Generated into '" + this.outputDir + "'.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ void run_WhenCalledWithContextMapParam_ThenGenerateContextMapFiles() {
assertThat(new File("build/test-out/test_ContextMap.svg").exists()).isTrue();
}

@Test
void run_WhenCalledWithFileContainingImports_ThenGenerateFilesWithImportedContexts() throws IOException {
// given
final GenerateCommand command = spy(new GenerateCommand());
new File("build/test-out").mkdir();

// when
command.run(new String[]{"-i", "src/test/resources/test-with-imports.cml", "-g", "context-map", "-o", "build/test-out"});

// then
assertThat(outContent.toString()).contains("Generated into 'build/test-out'.");
assertThat(new File("build/test-out/test-with-imports_ContextMap.gv").exists()).isTrue();
assertThat(new File("build/test-out/test-with-imports_ContextMap.png").exists()).isTrue();
assertThat(new File("build/test-out/test-with-imports_ContextMap.svg").exists()).isTrue();
}

@Test
void run_WhenCalledWithGenericParam_ThenGenerateGenericOutput() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,17 @@ void run_WhenWithInvalidCMLFile_ThenPrintError() {
assertThat(outContent.toString()).contains("ERROR in null on line 2:mismatched input '<EOF>' expecting RULE_CLOSE");
}

@Test
void run_WhenWithFileContainingImports_ThenValidateWithoutErrors() {
// given
final ValidateCommand command = spy(new ValidateCommand());

// when
command.run(new String[]{"-i src/test/resources/test-with-imports.cml"});

// then
verify(command).printValidationMessages(any(), any());
assertThat(outContent.toString()).contains("The CML file 'src/test/resources/test-with-imports.cml' has been validated without errors.");
}

}
3 changes: 3 additions & 0 deletions src/test/resources/other-contexts.cml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Simple bounded contexts */
BoundedContext anotherContext
BoundedContext yetAnotherContext
8 changes: 8 additions & 0 deletions src/test/resources/test-with-imports.cml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Import other contexts */
import "./other-contexts.cml"

/* Define a simple context map */
ContextMap SimpleMap {
contains anotherContext
contains yetAnotherContext
}
Loading