use of net.morimekta.providence.config.ProvidenceConfig in project providence by morimekta.
the class FormatUtils method collectConfigIncludes.
public static void collectConfigIncludes(File rc, Map<String, File> includes) throws IOException {
if (!rc.exists()) {
return;
}
rc = rc.getCanonicalFile();
if (!rc.isFile()) {
throw new ProvidenceConfigException("Rc file is not a file " + rc.getPath());
}
try {
SimpleTypeRegistry registry = new SimpleTypeRegistry();
registry.registerRecursively(ProvidenceTools.kDescriptor);
ProvidenceConfig loader = new ProvidenceConfig(registry);
ProvidenceTools config = loader.getConfig(rc);
if (config.hasIncludes()) {
File basePath = rc.getParentFile();
if (config.hasIncludesBasePath()) {
String base = config.getIncludesBasePath();
if (base.charAt(0) == '~') {
base = System.getenv("HOME") + base.substring(1);
}
basePath = new File(base);
if (!basePath.exists() || !basePath.isDirectory()) {
throw new ProvidenceConfigException("Includes Base path in " + rc.getPath() + " is not a directory: " + basePath);
}
}
for (String path : config.getIncludes()) {
File include = new File(basePath, path);
collectIncludes(include, includes);
}
}
} catch (SerializerException e) {
System.err.println("Config error: " + e.getMessage());
System.err.println(e.asString());
System.err.println();
throw new ArgumentException(e, "Exception when parsing " + rc.getCanonicalFile());
}
}
use of net.morimekta.providence.config.ProvidenceConfig in project providence by morimekta.
the class CommonOptions method getConfig.
public ProvidenceTools getConfig() throws ProvidenceConfigException {
SimpleTypeRegistry registry = new SimpleTypeRegistry();
registry.registerRecursively(ProvidenceTools.kDescriptor);
ProvidenceConfig loader = new ProvidenceConfig(registry);
ProvidenceTools config = ProvidenceTools.builder().setGeneratorPaths(ImmutableList.of()).build();
if (rc.isFile()) {
config = loader.getConfig(rc, config);
}
return config;
}
use of net.morimekta.providence.config.ProvidenceConfig in project providence by morimekta.
the class CommandBase method execute.
@Override
public void execute(ConfigOptions options) throws IOException {
Map<String, File> includeMap = FormatUtils.getIncludeMap(options.getRc(), options.getIncludes());
Set<File> rootSet = includeMap.values().stream().map(File::getParentFile).collect(Collectors.toSet());
TypeLoader loader = new TypeLoader(rootSet);
for (File file : includeMap.values()) {
loader.load(file);
}
execute(new ProvidenceConfig(loader.getProgramRegistry(), null, options.isStrict()));
}
use of net.morimekta.providence.config.ProvidenceConfig in project providence by morimekta.
the class ProvidenceConfigUtilTest method setUp.
@Before
public void setUp() throws IOException {
declaration = Declaration.withDeclConst(ConstType.builder().setName("Name").setType("i32").setValue("44").build());
SimpleTypeRegistry registry = new SimpleTypeRegistry();
registry.registerRecursively(Service.kDescriptor);
copyResourceTo("/net/morimekta/providence/config/files/base_service.cfg", tmp.getRoot());
copyResourceTo("/net/morimekta/providence/config/files/stage_db.cfg", tmp.getRoot());
File cfg = copyResourceTo("/net/morimekta/providence/config/files/stage.cfg", tmp.getRoot());
service = new ProvidenceConfig(registry).getConfig(cfg);
}
Aggregations