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

io.knowledgelinks.cicd.semantic.versioning.api.SemanticVersioningApiBuilder Maven / Gradle / Ivy

package io.knowledgelinks.cicd.semantic.versioning.api;

/*-
 * #%L
 * Semantic Versioning
 * %%
 * Copyright (C) 2022 - 2023 Knowledgelinks
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.util.Map;
import io.knowledgelinks.cicd.semantic.versioning.config.Configuration;
import io.knowledgelinks.cicd.semantic.versioning.exceptions.SemanticVersioningException;
import io.knowledgelinks.cicd.semantic.versioning.formatters.VersionFormatter;
import io.knowledgelinks.cicd.semantic.versioning.formatters.VersionFormatterFactory;
import io.knowledgelinks.cicd.semantic.versioning.parsers.VersionParser;
import io.knowledgelinks.cicd.semantic.versioning.parsers.VersionParserFactory;

public class SemanticVersioningApiBuilder {
  private Configuration config;

  private Map configMap;

  private VersionFormatter versionFormatter;

  private VersionParser versionParser;

  private VersionFormatterFactory versionFormatterFactory;

  private VersionParserFactory versionParserFactory;

  private BuildInfo buildInfo;

  private String branchName = null;

  private int majorVersion = -1;

  private int minorVersion = -1;

  private int buildNumber = -1;

  private String repositoryUrl = null;

  private String workingDirectory;



  public SemanticVersioningApiBuilder setConfig(Configuration config) {
    this.config = config;
    return this;
  }

  public SemanticVersioningApiBuilder setConfigMap(Map configMap) {
    this.configMap = configMap;
    return this;
  }

  public SemanticVersioningApiBuilder setVersionFormatter(VersionFormatter versionFormatter) {
    this.versionFormatter = versionFormatter;
    return this;
  }

  public SemanticVersioningApiBuilder setVersionParser(VersionParser versionParser) {
    this.versionParser = versionParser;
    return this;
  }

  public SemanticVersioningApiBuilder setBuildInfo(BuildInfo buildInfo) {
    this.buildInfo = buildInfo;
    return this;
  }

  public SemanticVersioningApiBuilder setRepositoryUrl(String repositoryUrl) {
    this.repositoryUrl = repositoryUrl;
    return this;
  }

  public SemanticVersioningApiBuilder setWorkingDirectory(String workingDirectory) {
    this.workingDirectory =
        (workingDirectory != null && !workingDirectory.isEmpty()) ? workingDirectory : null;
    return this;
  }

  public SemanticVersioningApi build() throws SemanticVersioningException {
    SemanticVersioningApi api = new SemanticVersioningApi();
    if (config == null) {
      config = new Configuration(configMap);
    }
    if (workingDirectory != null) {
      config.setWorkingDirectory(workingDirectory);
    }
    versionFormatterFactory = new VersionFormatterFactory(config);
    if (versionFormatter == null) {
      versionFormatter = versionFormatterFactory.get();
    }
    versionParserFactory = new VersionParserFactory(config);
    if (versionParser == null) {
      versionParser = versionParserFactory.get();
    }
    if (buildInfo == null) {
      buildInfo = new BuildInfoBuilder(config).setConfigMap(configMap).setBranchName(branchName)
          .setRepsoitoryUrl(repositoryUrl).setBuildNumber(buildNumber).setMajorVersion(majorVersion)
          .setMinorVersion(minorVersion).build();

    }
    api.setConfig(config);
    api.setVersionFormatter(versionFormatter);
    api.setVersionFormatterFactory(versionFormatterFactory);
    api.setVersionParser(versionParser);
    api.setVersionParserFactory(versionParserFactory);
    api.setBuildInfo(buildInfo);

    return api;
  }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy