All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.jhipster.lite.module.domain.buildproperties.JHipsterModuleBuildProperties Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package tech.jhipster.lite.module.domain.buildproperties;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
import tech.jhipster.lite.module.domain.javabuild.command.JavaBuildCommand;
import tech.jhipster.lite.module.domain.javabuild.command.JavaBuildCommands;
import tech.jhipster.lite.module.domain.javabuild.command.SetBuildProperty;
import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileId;
import tech.jhipster.lite.shared.collection.domain.JHipsterCollections;
import tech.jhipster.lite.shared.error.domain.Assert;

public final class JHipsterModuleBuildProperties {

  private final Map properties;

  private JHipsterModuleBuildProperties(JHipsterModuleBuildPropertiesBuilder builder) {
    properties = JHipsterCollections.immutable(builder.properties);
  }

  public static  JHipsterModuleBuildPropertiesBuilder builder(T parent) {
    return new JHipsterModuleBuildPropertiesBuilder<>(parent);
  }

  public JavaBuildCommands buildChanges() {
    return new JavaBuildCommands(
      properties
        .entrySet()
        .stream()
        .map(property -> new SetBuildProperty(new BuildProperty(property.getKey(), property.getValue())))
        .toList()
    );
  }

  public Stream buildChanges(BuildProfileId buildProfile) {
    return properties
      .entrySet()
      .stream()
      .map(property -> new SetBuildProperty(new BuildProperty(property.getKey(), property.getValue()), buildProfile));
  }

  public static final class JHipsterModuleBuildPropertiesBuilder {

    private final T parent;
    private final Map properties = new HashMap<>();

    private JHipsterModuleBuildPropertiesBuilder(T parent) {
      Assert.notNull("parent", parent);

      this.parent = parent;
    }

    public JHipsterModuleBuildPropertiesBuilder set(PropertyKey key, PropertyValue value) {
      Assert.notNull("key", key);
      Assert.notNull("value", value);

      this.properties.put(key, value);

      return this;
    }

    public T and() {
      return parent;
    }

    public JHipsterModuleBuildProperties build() {
      return new JHipsterModuleBuildProperties(this);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy