CommandLineParser parser = new DefaultParser(); ImmutableModuleConfiguration.Builder builder = ImmutableModuleConfiguration.builder(); builder.name("main"); try { CommandLine cmd = parser.parse(options, args); builder.generator(generator); } else { LOGGER.error("Generator is not set."); builder.output(output); } else { LOGGER.error("Output directory is not set."); builder.putOptions(CompilerModule.TEMPLATES_OPTION, templates); builder.putOptions(CompilerModule.EXTENSIONS_OPTION, cmd.getOptionValue(EXTENSIONS)); includePaths.add(Paths.get(".")); builder.includePaths(includePaths); List<String> protoFiles = cmd.getArgList(); builder.protoFiles(protoFiles); } catch (ParseException e) { if (LOGGER.isDebugEnabled()) { ModuleConfiguration configuration = builder.build();
@Override public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); ProtostuffCompiler compiler = new ProtostuffCompiler(); final Path sourcePath = getSourcePath(); String output = computeSourceOutputDir(target); Set<String> allTemplates = new LinkedHashSet<>(); if (template != null) { allTemplates.add(template); } if (templates != null) { allTemplates.addAll(templates); } List<String> protoFiles = findProtoFiles(sourcePath); ModuleConfiguration moduleConfiguration = ImmutableModuleConfiguration.builder() .name("java") .includePaths(singletonList(sourcePath)) .generator(CompilerModule.ST4_COMPILER) .putOptions(CompilerModule.TEMPLATES_OPTION, allTemplates) .putOptions(CompilerModule.EXTENSIONS_OPTION, extensions) .output(output) .addAllProtoFiles(protoFiles) .build(); compiler.compile(moduleConfiguration); addGeneratedSourcesToProject(output); }
/** * Fill a builder with attribute values from the provided {@code ModuleConfiguration} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(ModuleConfiguration instance) { Preconditions.checkNotNull(instance, "instance"); name(instance.getName()); addAllIncludePaths(instance.getIncludePaths()); addAllProtoFiles(instance.getProtoFiles()); generator(instance.getGenerator()); output(instance.getOutput()); putAllOptions(instance.getOptions()); return this; }
@Override public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); ProtostuffCompiler compiler = new ProtostuffCompiler(); final Path sourcePath = getSourcePath(); String output = computeSourceOutputDir(target); List<String> protoFiles = findProtoFiles(sourcePath); ModuleConfiguration moduleConfiguration = ImmutableModuleConfiguration.builder() .name("java") .includePaths(singletonList(sourcePath)) .generator("java") .output(output) .protoFiles(protoFiles) .build(); compiler.compile(moduleConfiguration); addGeneratedSourcesToProject(output); }
/** * Creates an immutable copy of a {@link ModuleConfiguration} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable ModuleConfiguration instance */ public static ImmutableModuleConfiguration copyOf(ModuleConfiguration instance) { if (instance instanceof ImmutableModuleConfiguration) { return (ImmutableModuleConfiguration) instance; } return ImmutableModuleConfiguration.builder() .from(instance) .build(); }
@Override public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); ProtostuffCompiler compiler = new ProtostuffCompiler(); final Path sourcePath = getSourcePath(); List<String> protoFiles = findProtoFiles(sourcePath); ModuleConfiguration moduleConfiguration = ImmutableModuleConfiguration.builder() .name("html") .includePaths(singletonList(sourcePath)) .generator(CompilerModule.HTML_COMPILER) .output(target.getAbsolutePath()) .putOptions(HtmlGenerator.PAGES, pages) .addAllProtoFiles(protoFiles) .build(); compiler.compile(moduleConfiguration); }
/** * Sets or replaces all elements for {@link ModuleConfiguration#getProtoFiles() protoFiles} list. * @param elements An iterable of protoFiles elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder protoFiles(Iterable<String> elements) { this.protoFiles = ImmutableList.builder(); return addAllProtoFiles(elements); }
/** * Creates a builder for {@link ImmutableModuleConfiguration ImmutableModuleConfiguration}. * @return A new ImmutableModuleConfiguration builder */ public static ImmutableModuleConfiguration.Builder builder() { return new ImmutableModuleConfiguration.Builder(); }