Skip to content

Commit 89537d9

Browse files
Removed deprecated file system driven code generation from the unit tests
1 parent ef1775c commit 89537d9

File tree

1 file changed

+0
-162
lines changed

1 file changed

+0
-162
lines changed

src/test/java/com/regnosys/rosetta/generator/python/PythonGeneratorTestUtils.java

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
package com.regnosys.rosetta.generator.python;
22

3-
import com.google.inject.Provider;
43
import com.regnosys.rosetta.rosetta.RosettaModel;
54
import com.regnosys.rosetta.tests.util.ModelHelper;
65
import jakarta.inject.Inject;
76
import org.apache.commons.io.FileUtils;
8-
import org.apache.maven.model.Model;
9-
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
10-
import org.eclipse.emf.common.util.URI;
11-
import org.eclipse.emf.ecore.resource.Resource;
127
import org.eclipse.emf.ecore.resource.ResourceSet;
13-
import org.eclipse.xtext.resource.XtextResourceSet;
14-
import org.eclipse.xtext.testing.util.ParseHelper;
158
import org.slf4j.Logger;
169
import org.slf4j.LoggerFactory;
1710

1811
import java.io.File;
19-
import java.io.FileReader;
2012
import java.io.IOException;
21-
import java.nio.charset.StandardCharsets;
22-
import java.nio.file.FileVisitOption;
23-
import java.nio.file.Files;
24-
import java.nio.file.Path;
25-
import java.nio.file.Paths;
2613
import java.util.*;
27-
import java.util.stream.Collectors;
28-
import java.util.stream.Stream;
2914

3015
import static org.junit.jupiter.api.Assertions.assertTrue;
3116

@@ -36,38 +21,8 @@ public class PythonGeneratorTestUtils {
3621
@Inject
3722
private ModelHelper modelHelper;
3823
@Inject
39-
private Provider<XtextResourceSet> resourceSetProvider;
40-
@Inject
41-
private ParseHelper<RosettaModel> parseHelper;
42-
@Inject
4324
private PythonCodeGenerator generator;
4425

45-
public Properties getProperties() throws Exception {
46-
MavenXpp3Reader reader = new MavenXpp3Reader();
47-
Model model = reader.read(new FileReader("pom.xml"));
48-
return model.getProperties();
49-
}
50-
51-
public String getProperty(String property) throws Exception {
52-
MavenXpp3Reader reader = new MavenXpp3Reader();
53-
Model model = reader.read(new FileReader("pom.xml"));
54-
return model.getProperties().getProperty(property);
55-
}
56-
57-
public String getPropertyOrMessage(String propertyName) {
58-
// Check if property exists
59-
String property = null;
60-
try {
61-
property = getProperty(propertyName);
62-
if (property == null || property.isEmpty()) {
63-
LOGGER.error("Property:{} does not exist or is empty", propertyName);
64-
}
65-
} catch (Exception e) {
66-
LOGGER.error("Exception when getting property:{} exception:{}", propertyName, e.getMessage());
67-
}
68-
return property;
69-
}
70-
7126
public void cleanFolder(String folderPath) {
7227
File folder = new File(folderPath + File.separator + "src");
7328
if (folder.exists() && folder.isDirectory()) {
@@ -81,18 +36,6 @@ public void cleanFolder(String folderPath) {
8136
}
8237
}
8338

84-
public void writeFiles(String pythonTgtPath, Map<String, ? extends CharSequence> generatedFiles)
85-
throws IOException {
86-
for (Map.Entry<String, ? extends CharSequence> entry : generatedFiles.entrySet()) {
87-
String filePath = entry.getKey();
88-
String fileContents = entry.getValue().toString();
89-
Path outputPath = Path.of(pythonTgtPath + File.separator + filePath);
90-
Files.createDirectories(outputPath.getParent());
91-
Files.write(outputPath, fileContents.getBytes(StandardCharsets.UTF_8));
92-
}
93-
LOGGER.info("Write Files ... wrote: {}", generatedFiles.size());
94-
}
95-
9639
public Map<String, CharSequence> generatePythonFromRosettaModel(RosettaModel m, ResourceSet resourceSet) {
9740
String version = m.getVersion();
9841
Map<String, CharSequence> result = new HashMap<>();
@@ -102,111 +45,6 @@ public Map<String, CharSequence> generatePythonFromRosettaModel(RosettaModel m,
10245
return result;
10346
}
10447

105-
public List<Path> getFileList(String dslSourceDir, String suffix) throws Exception {
106-
LOGGER.info("getFileList ... looking for files with suffix {} in {}", suffix, dslSourceDir);
107-
108-
if (dslSourceDir == null) {
109-
throw new Exception("Initialization failure: source dsl path not specified");
110-
}
111-
112-
if (suffix == null) {
113-
throw new Exception("Initialization failure: extension not specified");
114-
}
115-
116-
Path sourcePath = Paths.get(dslSourceDir);
117-
if (!Files.exists(sourcePath)) {
118-
throw new Exception("Unable to generate Python from non-existent source directory: " + dslSourceDir);
119-
}
120-
121-
List<Path> result = new ArrayList<>();
122-
File directory = new File(dslSourceDir);
123-
if (directory.isDirectory()) {
124-
File[] files = directory.listFiles(file -> file.isFile() && file.getName().endsWith(suffix));
125-
if (files != null) {
126-
for (File file : files) {
127-
result.add(file.toPath());
128-
}
129-
}
130-
}
131-
LOGGER.info("getFileList ... found {} files in {}", result.size(), dslSourceDir);
132-
return result;
133-
}
134-
135-
public List<Path> getFileListWithRecursion(String dslSourceDir, String suffix) throws Exception {
136-
LOGGER.info("getFileListWithRecursion ... looking for files with suffix {} in {}", suffix, dslSourceDir);
137-
138-
if (dslSourceDir == null) {
139-
throw new Exception("Initialization failure: source dsl path not specified");
140-
}
141-
142-
if (suffix == null) {
143-
throw new Exception("Initialization failure: extension not specified");
144-
}
145-
146-
Path sourcePath = Paths.get(dslSourceDir);
147-
if (!Files.exists(sourcePath)) {
148-
throw new Exception("Unable to generate Python from non-existent source directory: " + dslSourceDir);
149-
}
150-
151-
List<Path> result = new ArrayList<>();
152-
153-
try (Stream<Path> stream = Files.walk(sourcePath, FileVisitOption.FOLLOW_LINKS)) {
154-
result.addAll(
155-
stream
156-
.filter(path -> Files.isRegularFile(path) && path.toString().endsWith(suffix))
157-
.collect(Collectors.toList()));
158-
} catch (IOException e) {
159-
throw e;
160-
}
161-
LOGGER.info("getFileListWithRecursion ... found {} files in {}", result.size(), dslSourceDir);
162-
return result;
163-
}
164-
165-
public void generatePythonFromDSLFiles(List<Path> dslFilePathList, String outputPath) throws Exception {
166-
LOGGER.info("generatePythonFromDSLFiles ... generating Python from {} rosetta files", dslFilePathList.size());
167-
XtextResourceSet resourceSet = resourceSetProvider.get();
168-
// Assuming parseHelper.parse is what is meant by 'parse' in the Xtend file,
169-
// but Xtend had 'extension ParseHelper', so 'parse' calls ParseHelper.parse.
170-
parseHelper.parse(ModelHelper.commonTestTypes, resourceSet);
171-
172-
resourceSet.getResource(URI.createURI("classpath:/model/basictypes.rosetta"), true);
173-
resourceSet.getResource(URI.createURI("classpath:/model/annotations.rosetta"), true);
174-
175-
List<Resource> resources = dslFilePathList.stream()
176-
.map(it -> resourceSet.getResource(URI.createURI(it.toString()), true))
177-
.collect(Collectors.toList());
178-
179-
LOGGER.info("generatePythonFromDSLFiles ... converted to resources");
180-
181-
List<RosettaModel> rosettaModels = resources.stream()
182-
.flatMap(r -> r.getContents().stream())
183-
.filter(RosettaModel.class::isInstance)
184-
.map(RosettaModel.class::cast)
185-
.collect(Collectors.toList());
186-
187-
LOGGER.info("generatePythonFromDSLFiles ... created {} rosetta models", rosettaModels.size());
188-
189-
if (rosettaModels.isEmpty()) {
190-
return;
191-
}
192-
193-
RosettaModel m = rosettaModels.get(0);
194-
String version = m.getVersion();
195-
Map<String, CharSequence> generatedFiles = new HashMap<>();
196-
197-
generator.beforeAllGenerate(resourceSet, rosettaModels, version);
198-
for (RosettaModel model : rosettaModels) {
199-
LOGGER.info("generatePythonFromDSLFiles ... processing model: {}", model.getName());
200-
Map<String, CharSequence> python = generatePythonFromRosettaModel(model, resourceSet);
201-
generatedFiles.putAll(python);
202-
}
203-
generatedFiles.putAll(generator.afterAllGenerate(resourceSet, rosettaModels, version));
204-
205-
cleanFolder(outputPath);
206-
writeFiles(outputPath, generatedFiles);
207-
LOGGER.info("generatePythonFromDSLFiles ... done");
208-
}
209-
21048
public Map<String, CharSequence> generatePythonFromString(String modelContent) throws Exception {
21149
// model.parseRosettaWithNoErrors in Xtend ->
21250
// modelHelper.parseRosettaWithNoErrors(modelContent)

0 commit comments

Comments
 (0)