use of org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException in project yangtools by opendaylight.
the class YangToSourcesProcessor method generateSources.
/**
* Call generate on every generator from plugin configuration.
*/
private Set<File> generateSources(final ContextHolder context, final Collection<GeneratorTaskFactory> generators, final YangParserConfiguration parserConfig) throws MojoFailureException {
final Builder<File> allFiles = ImmutableSet.builder();
for (GeneratorTaskFactory factory : generators) {
if (!parserConfig.equals(factory.parserConfig())) {
continue;
}
final Stopwatch sw = Stopwatch.createStarted();
final GeneratorTask<?> task = factory.createTask(project, context);
LOG.debug("{} Task {} initialized in {}", LOG_PREFIX, task, sw);
final Collection<File> files;
try {
files = task.execute(buildContext);
} catch (FileGeneratorException | IOException e) {
throw new MojoFailureException(LOG_PREFIX + " Generator " + factory + " failed", e);
}
LOG.debug("{} Sources generated by {}: {}", LOG_PREFIX, factory.generatorName(), files);
final int fileCount;
if (files != null) {
fileCount = files.size();
allFiles.addAll(files);
} else {
fileCount = 0;
}
LOG.info("{} Sources generated by {}: {} in {}", LOG_PREFIX, factory.generatorName(), fileCount, sw);
}
return allFiles.build();
}
use of org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException in project yangtools by opendaylight.
the class YangToSourcesProcessor method instantiateGenerators.
private List<GeneratorTaskFactory> instantiateGenerators() throws MojoExecutionException, MojoFailureException {
final List<GeneratorTaskFactory> generators = new ArrayList<>(codeGeneratorArgs.size());
for (CodeGeneratorArg arg : codeGeneratorArgs) {
generators.add(CodeGeneratorTaskFactory.create(arg));
LOG.info("{} Code generator instantiated from {}", LOG_PREFIX, arg.getCodeGeneratorClass());
}
// Search for available FileGenerator implementations
final Map<String, FileGeneratorFactory> factories = Maps.uniqueIndex(ServiceLoader.load(FileGeneratorFactory.class), FileGeneratorFactory::getIdentifier);
// Assign instantiate FileGenerators with appropriate configurate
for (Entry<String, FileGeneratorFactory> entry : factories.entrySet()) {
final String id = entry.getKey();
FileGeneratorArg arg = fileGeneratorArgs.get(id);
if (arg == null) {
LOG.debug("{} No configuration for {}, using empty", LOG_PREFIX, id);
arg = new FileGeneratorArg(id);
}
try {
generators.add(FileGeneratorTaskFactory.of(entry.getValue(), arg));
} catch (FileGeneratorException e) {
throw new MojoExecutionException("File generator " + id + " failed", e);
}
LOG.info("{} Code generator {} instantiated", LOG_PREFIX, id);
}
return generators;
}
use of org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException in project yangtools by opendaylight.
the class FileGeneratorTask method transientDirectory.
private File transientDirectory(final GeneratedFileType fileType) throws FileGeneratorException {
final File ret;
if (GeneratedFileType.SOURCE.equals(fileType)) {
ret = transientDirectory("generated-sources");
project.addCompileSourceRoot(ret.toString());
} else if (GeneratedFileType.RESOURCE.equals(fileType)) {
ret = transientDirectory("generated-resources");
project.addResource(createResouce(ret));
} else {
throw new FileGeneratorException("Unknown generated file type " + fileType);
}
return ret;
}
Aggregations