Skip to content

Commit

Permalink
Replace File.separator with "/" for cross-platform path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
salamafazlul committed Apr 8, 2024
1 parent 61d251a commit bbc21c4
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class ToolConstants {
public static final String MD_EXTENSION = ".md";
public static final String CONSTRAINTS_LIB_IMPORT = "ballerina/constraint";
public static final String ELEMENT = "Element";
public static final String RESOURCE_PATH_SEPERATOR = "/";

public enum TokenPosition {
BEGIN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void populateDatatypeContext() {
continue;
}
DatatypeTemplateContext context = new DatatypeTemplateContext();
String typeName = CommonUtil.getSplitTokenAt(datatypeDefn.getDefinition().getUrl(), "/", ToolConstants.TokenPosition.END);
String typeName = CommonUtil.getSplitTokenAt(datatypeDefn.getDefinition().getUrl(), ToolConstants.RESOURCE_PATH_SEPERATOR, ToolConstants.TokenPosition.END);
context.setName(GeneratorUtils.getInstance().getUniqueIdentifierFromId(typeName));
context.setBaseDataType(datatypeDefn.getDefinition().getType());
DataTypeDefinitionAnnotation annotation = new DataTypeDefinitionAnnotation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void populateResourceTemplateContexts(FHIRImplementationGuide ig) {
resourceDefinitionAnnotation.setName(GeneratorUtils.getInstance().resolveSpecialCharacters(structureDefinition.getName()));
DataTypesRegistry.getInstance().addDataType(GeneratorUtils.getInstance().resolveSpecialCharacters(structureDefinition.getName()));
resourceDefinitionAnnotation.setBaseType(CommonUtil.getSplitTokenAt(structureDefinition
.getBaseDefinition(), File.separator, ToolConstants.TokenPosition.END));
.getBaseDefinition(), ToolConstants.RESOURCE_PATH_SEPERATOR, ToolConstants.TokenPosition.END));
resourceDefinitionAnnotation.setProfile(this.resourceTemplateContextInstance.getProfile());
resourceDefinitionAnnotation.setElements(new HashMap<>());
this.resourceTemplateContextInstance.setResourceDefinitionAnnotation(resourceDefinitionAnnotation);
Expand Down Expand Up @@ -281,7 +281,7 @@ private Element populateElement(String rootName, String name, ElementDefinition.
List<CanonicalType> profiles = type.getProfile();
if (!profiles.isEmpty()) {
for (CanonicalType profile : profiles) {
String profileType = CommonUtil.getSplitTokenAt(profile.getValue(), "/", ToolConstants.TokenPosition.END);
String profileType = CommonUtil.getSplitTokenAt(profile.getValue(), ToolConstants.RESOURCE_PATH_SEPERATOR, ToolConstants.TokenPosition.END);
profileType = GeneratorUtils.getInstance().getUniqueIdentifierFromId(profileType);
if (datatypeTemplateContextMap.containsKey(profile.getValue())) {
element.addProfile(profile.getValue(), profileType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void generate(ToolContext toolContext, Map<String, Object> generatorPrope
if (!datatypeContexts.isEmpty()) {
String filePath = CommonUtil.generateFilePath(packagePath, "", "datatypes.bal");
this.getTemplateEngine().generateOutputAsFile(ToolConstants.TEMPLATE_PATH +
File.separator + "fhir_extended_datatypes.vm", templateContext, "", filePath);
ToolConstants.RESOURCE_PATH_SEPERATOR + "fhir_extended_datatypes.vm", templateContext, "", filePath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,22 @@ private void generatePackageEssentials(BallerinaPackageGenToolConfig toolConfig)
String packagePath = (String) this.packageProperties.get("packagePath");
String filePath = CommonUtil.generateFilePath(packagePath, "Ballerina"
+ ToolConstants.TOML_EXTENSION, "");
this.getTemplateEngine().generateOutputAsFile(ToolConstants.TEMPLATE_PATH + File.separator + "ballerina_toml.vm",
this.getTemplateEngine().generateOutputAsFile(ToolConstants.TEMPLATE_PATH + ToolConstants.RESOURCE_PATH_SEPERATOR + "ballerina_toml.vm",
this.createTemplateContextForBallerinaToml(toolConfig), "", filePath);

filePath = CommonUtil.generateFilePath(packagePath, "Package"
+ ToolConstants.MD_EXTENSION, "");
this.getTemplateEngine().generateOutputAsFile(ToolConstants.TEMPLATE_PATH + File.separator + "package.vm",
this.getTemplateEngine().generateOutputAsFile(ToolConstants.TEMPLATE_PATH + ToolConstants.RESOURCE_PATH_SEPERATOR + "package.vm",
this.createTemplateContextForPackageMD(toolConfig), "", filePath);

filePath = CommonUtil.generateFilePath(packagePath, "initializer"
+ ToolConstants.BAL_EXTENSION, "");
this.getTemplateEngine().generateOutputAsFile(ToolConstants.TEMPLATE_PATH + File.separator + "initializer.vm",
this.getTemplateEngine().generateOutputAsFile(ToolConstants.TEMPLATE_PATH + ToolConstants.RESOURCE_PATH_SEPERATOR + "initializer.vm",
this.createTemplateContextForInitializer(), "", filePath);

filePath = CommonUtil.generateFilePath(packagePath, "variables"
+ ToolConstants.BAL_EXTENSION, "");
this.getTemplateEngine().generateOutputAsFile(ToolConstants.TEMPLATE_PATH + File.separator + "variables.vm",
this.getTemplateEngine().generateOutputAsFile(ToolConstants.TEMPLATE_PATH + ToolConstants.RESOURCE_PATH_SEPERATOR + "variables.vm",
this.createTemplateContextForVariables(), "", filePath);
} catch (CodeGenException e) {
throw new CodeGenException("Error occurred while generating template artifacts for ballerina package ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void generateFHIRResources()
+ ToolConstants.BAL_EXTENSION, "");

this.getTemplateEngine().generateOutputAsFile(ToolConstants.TEMPLATE_PATH +
File.separator + "fhir_resource.vm", this.createTemplateContextForResourceSkeletons(
ToolConstants.RESOURCE_PATH_SEPERATOR + "fhir_resource.vm", this.createTemplateContextForResourceSkeletons(
resourceTemplateContext, this.packageTemplateContext), "", filePath);
}
} catch (CodeGenException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class BallerinaProjectConstants {
public static final String BASE_PACKAGE_IMPORT_SUFFIX = "ballerinax/health.fhir.";
public static final String SERVICE_PACKAGE_IMPORT_SUFFIX = "ballerinax/health.fhir";
public static final String INTERNATIONAL_PACKAGE_IMPORT_SUFFIX = "ballerinax/health.fhir.r4.international401";
public static final String RESOURCE_PATH_SEPERATOR = "/";

public class PrintStrings {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public MetaGenerator(String targetDir) throws CodeGenException {
public void generate(ToolContext toolContext, Map<String, Object> generatorProperties) throws CodeGenException {
String directoryPath = generatorProperties.get("projectAPIPath") + File.separator;
this.getTemplateEngine().generateOutputAsFile(BallerinaProjectConstants.RESOURCE_PATH_TEMPLATES +
File.separator + "packageMd.vm", createTemplateContextForMeta(generatorProperties), directoryPath,
BallerinaProjectConstants.RESOURCE_PATH_SEPERATOR + "packageMd.vm", createTemplateContextForMeta(generatorProperties), directoryPath,
"Package.md");
this.getTemplateEngine().generateOutputAsFile(BallerinaProjectConstants.RESOURCE_PATH_TEMPLATES +
File.separator + "gitignore.vm", createTemplateContextForMeta(generatorProperties), directoryPath,
BallerinaProjectConstants.RESOURCE_PATH_SEPERATOR + "gitignore.vm", createTemplateContextForMeta(generatorProperties), directoryPath,
".gitignore");
this.getTemplateEngine().generateOutputAsFile(BallerinaProjectConstants.RESOURCE_PATH_TEMPLATES +
File.separator + "apiConfig.vm", createTemplateContextForMeta(generatorProperties), directoryPath,
BallerinaProjectConstants.RESOURCE_PATH_SEPERATOR + "apiConfig.vm", createTemplateContextForMeta(generatorProperties), directoryPath,
"api_config.bal");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ServiceGenerator(String targetDir) throws CodeGenException {
public void generate(ToolContext toolContext, Map<String, Object> generatorProperties) throws CodeGenException {
String directoryPath = generatorProperties.get("projectAPIPath") + File.separator;
this.getTemplateEngine().generateOutputAsFile(BallerinaProjectConstants.RESOURCE_PATH_TEMPLATES +
File.separator + "balService.vm", createTemplateContextForBalService(
BallerinaProjectConstants.RESOURCE_PATH_SEPERATOR + "balService.vm", createTemplateContextForBalService(
generatorProperties), directoryPath, "service.bal");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public TomlGenerator(String targetDir) throws CodeGenException {
public void generate(ToolContext toolContext, Map<String, Object> generatorProperties) throws CodeGenException {
String directoryPath = generatorProperties.get("projectAPIPath") + File.separator;
this.getTemplateEngine().generateOutputAsFile(BallerinaProjectConstants.RESOURCE_PATH_TEMPLATES
+ File.separator + "ballerinaToml.vm",
+ BallerinaProjectConstants.RESOURCE_PATH_SEPERATOR + "ballerinaToml.vm",
createTemplateContextForToml(generatorProperties), directoryPath, "Ballerina.toml");
}

Expand Down

0 comments on commit bbc21c4

Please sign in to comment.