/** * Copy the current immutable object with elements that replace the content of {@link ModuleConfiguration#getIncludePaths() includePaths}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of includePaths elements to set * @return A modified copy of {@code this} object */ public final ImmutableModuleConfiguration withIncludePaths(Iterable<? extends Path> elements) { if (this.includePaths == elements) return this; ImmutableList<Path> newValue = ImmutableList.copyOf(elements); return new ImmutableModuleConfiguration(this.name, newValue, this.protoFiles, this.generator, this.output, this.options); }
/** * This instance is equal to all instances of {@code ImmutableModuleConfiguration} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableModuleConfiguration && equalTo((ImmutableModuleConfiguration) another); }
/** * 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(); }
.build()); CommandLineParser parser = new DefaultParser(); ImmutableModuleConfiguration.Builder builder = ImmutableModuleConfiguration.builder(); builder.name("main"); try {
@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); }
/** * Copy the current immutable object with elements that replace the content of {@link ModuleConfiguration#getProtoFiles() protoFiles}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableModuleConfiguration withProtoFiles(String... elements) { ImmutableList<String> newValue = ImmutableList.copyOf(elements); return new ImmutableModuleConfiguration(this.name, this.includePaths, newValue, this.generator, this.output, this.options); }
@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); }
/** * Copy the current immutable object with elements that replace the content of {@link ModuleConfiguration#getProtoFiles() protoFiles}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of protoFiles elements to set * @return A modified copy of {@code this} object */ public final ImmutableModuleConfiguration withProtoFiles(Iterable<String> elements) { if (this.protoFiles == elements) return this; ImmutableList<String> newValue = ImmutableList.copyOf(elements); return new ImmutableModuleConfiguration(this.name, this.includePaths, newValue, this.generator, this.output, this.options); }
@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); }
/** * Copy the current immutable object with elements that replace the content of {@link ModuleConfiguration#getIncludePaths() includePaths}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableModuleConfiguration withIncludePaths(Path... elements) { ImmutableList<Path> newValue = ImmutableList.copyOf(elements); return new ImmutableModuleConfiguration(this.name, newValue, this.protoFiles, this.generator, this.output, this.options); }
/** * Copy the current immutable object by replacing the {@link ModuleConfiguration#getOptions() options} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param entries The entries to be added to the options map * @return A modified copy of {@code this} object */ public final ImmutableModuleConfiguration withOptions(Map<String, ? extends Object> entries) { if (this.options == entries) return this; ImmutableMap<String, Object> newValue = ImmutableMap.copyOf(entries); return new ImmutableModuleConfiguration(this.name, this.includePaths, this.protoFiles, this.generator, this.output, newValue); }
/** * Copy the current immutable object by setting a value for the {@link ModuleConfiguration#getName() name} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for name * @return A modified copy of the {@code this} object */ public final ImmutableModuleConfiguration withName(String value) { if (this.name.equals(value)) return this; String newValue = Preconditions.checkNotNull(value, "name"); return new ImmutableModuleConfiguration(newValue, this.includePaths, this.protoFiles, this.generator, this.output, this.options); }
/** * Copy the current immutable object by setting a value for the {@link ModuleConfiguration#getOutput() output} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for output * @return A modified copy of the {@code this} object */ public final ImmutableModuleConfiguration withOutput(String value) { if (this.output.equals(value)) return this; String newValue = Preconditions.checkNotNull(value, "output"); return new ImmutableModuleConfiguration(this.name, this.includePaths, this.protoFiles, this.generator, newValue, this.options); }
/** * Copy the current immutable object by setting a value for the {@link ModuleConfiguration#getGenerator() generator} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for generator * @return A modified copy of the {@code this} object */ public final ImmutableModuleConfiguration withGenerator(String value) { if (this.generator.equals(value)) return this; String newValue = Preconditions.checkNotNull(value, "generator"); return new ImmutableModuleConfiguration(this.name, this.includePaths, this.protoFiles, newValue, this.output, this.options); }
/** * Builds a new {@link ImmutableModuleConfiguration ImmutableModuleConfiguration}. * @return An immutable instance of ModuleConfiguration * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableModuleConfiguration build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableModuleConfiguration(name, includePaths.build(), protoFiles.build(), generator, output, options.build()); }