use of net.morimekta.providence.tools.common.ProvidenceTools 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.tools.common.ProvidenceTools in project providence by morimekta.
the class GeneratorOptions method currentJarDirectory.
public File currentJarDirectory() {
try {
ProvidenceTools config = getConfig();
List<File> paths = new ArrayList<>();
URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
if ("file".equals(url.getProtocol())) {
String path = url.getPath();
if (path.endsWith(".jar")) {
return new File(path).getParentFile();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of net.morimekta.providence.tools.common.ProvidenceTools in project providence by morimekta.
the class GeneratorOptions method getFactories.
public Map<String, GeneratorFactory> getFactories() {
try {
FactoryLoader<GeneratorFactory> loader = new FactoryLoader<>(GeneratorFactory.MANIFEST_PROPERTY);
Map<String, GeneratorFactory> factories = new TreeMap<>();
factories.put("json", new JsonGeneratorFactory());
File currentDir = currentJarDirectory();
if (currentDir != null) {
File generators = new File(currentDir, "generator");
if (generators.isDirectory()) {
addToMap(factories, loader.getFactories(generators));
}
}
{
ProvidenceTools config = getConfig();
if (config.hasGeneratorPaths()) {
for (String path : config.getGeneratorPaths()) {
addToMap(factories, loader.getFactories(new File(path)));
}
}
}
for (File extra : extraGenerators) {
GeneratorFactory factory = loader.getFactory(extra);
factories.put(factory.generatorName(), factory);
}
return factories;
} catch (ProvidenceConfigException e) {
throw new UncheckedProvidenceConfigException(e);
}
}
Aggregations