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

tech.jhipster.lite.module.domain.javabuildprofile.JHipsterModuleJavaBuildProfiles Maven / Gradle / Ivy

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

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import tech.jhipster.lite.module.domain.JHipsterModule.JHipsterModuleBuilder;
import tech.jhipster.lite.module.domain.javabuild.command.AddJavaBuildProfile;
import tech.jhipster.lite.module.domain.javabuild.command.JavaBuildCommand;
import tech.jhipster.lite.module.domain.javabuild.command.JavaBuildCommands;
import tech.jhipster.lite.module.domain.javabuildprofile.JHipsterModuleJavaBuildProfile.JHipsterModuleJavaBuildProfileBuilder;
import tech.jhipster.lite.module.domain.javadependency.JavaDependenciesVersions;
import tech.jhipster.lite.module.domain.javadependency.ProjectJavaDependencies;
import tech.jhipster.lite.shared.error.domain.Assert;

public final class JHipsterModuleJavaBuildProfiles {

  private final Collection profiles;

  private JHipsterModuleJavaBuildProfiles(JHipsterModuleJavaBuildProfilesBuilder builder) {
    this.profiles = builder.profiles.values().stream().map(JHipsterModuleJavaBuildProfileBuilder::build).toList();
  }

  public static JHipsterModuleJavaBuildProfilesBuilder builder(JHipsterModuleBuilder module) {
    return new JHipsterModuleJavaBuildProfilesBuilder(module);
  }

  public JavaBuildCommands buildChanges(JavaDependenciesVersions versions, ProjectJavaDependencies projectJavaDependencies) {
    Stream addProfileCommands = profiles.stream().map(toAddProfileCommands());
    Stream addPropertyCommands = profiles.stream().flatMap(toAddPropertyCommands());
    Stream mavenPluginCommands = profiles.stream().flatMap(toMavenPluginCommands(versions, projectJavaDependencies));
    Stream gradlePluginCommands = profiles.stream().flatMap(toGradlePluginCommands(versions));
    Stream javaDependenciesCommands = profiles
      .stream()
      .flatMap(toJavaDependenciesCommands(versions, projectJavaDependencies));

    Collection commands = Stream.of(
      addProfileCommands,
      addPropertyCommands,
      mavenPluginCommands,
      gradlePluginCommands,
      javaDependenciesCommands
    )
      .flatMap(Function.identity())
      .toList();

    return new JavaBuildCommands(commands);
  }

  private Function toAddProfileCommands() {
    return profile -> new AddJavaBuildProfile(profile.id(), profile.activation());
  }

  private Function> toAddPropertyCommands() {
    return profile -> profile.properties().buildChanges(profile.id());
  }

  private Function> toMavenPluginCommands(
    JavaDependenciesVersions versions,
    ProjectJavaDependencies projectJavaDependencies
  ) {
    return profile -> profile.mavenPlugins().buildChanges(versions, projectJavaDependencies, profile.id()).get().stream();
  }

  private Function> toGradlePluginCommands(JavaDependenciesVersions versions) {
    return profile -> profile.gradlePlugins().buildChanges(versions, profile.id()).get().stream();
  }

  private Function> toJavaDependenciesCommands(
    JavaDependenciesVersions versions,
    ProjectJavaDependencies projectJavaDependencies
  ) {
    return profile -> profile.javaDependencies().buildChanges(versions, projectJavaDependencies, profile.id()).get().stream();
  }

  public static final class JHipsterModuleJavaBuildProfilesBuilder {

    private final JHipsterModuleBuilder module;
    private final Map profiles = new HashMap<>();

    private JHipsterModuleJavaBuildProfilesBuilder(JHipsterModuleBuilder module) {
      Assert.notNull("module", module);

      this.module = module;
    }

    public JHipsterModuleJavaBuildProfileBuilder addProfile(BuildProfileId buildProfileId) {
      Assert.notNull("buildProfileId", buildProfileId);

      return profiles.computeIfAbsent(buildProfileId, id -> JHipsterModuleJavaBuildProfile.builder(this, buildProfileId));
    }

    public JHipsterModuleJavaBuildProfileBuilder addProfile(String buildProfileId) {
      return addProfile(new BuildProfileId(buildProfileId));
    }

    public JHipsterModuleBuilder and() {
      return module;
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy