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

io.camunda.application.commons.configuration.WorkingDirectoryConfiguration Maven / Gradle / Ivy

There is a newer version: 8.7.0-alpha1
Show newest version
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Camunda License 1.0. You may not use this file
 * except in compliance with the Camunda License 1.0.
 */
package io.camunda.application.commons.configuration;

import io.camunda.application.Profile;
import io.camunda.zeebe.broker.Loggers;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;

@Configuration(proxyBeanMethods = false)
@org.springframework.context.annotation.Profile(value = {"broker", "restore"})
public record WorkingDirectoryConfiguration(Environment environment) {

  @Bean
  public WorkingDirectory workingDirectory() {
    final Path workingDirectory;

    if (shouldUseTemporaryFolder()) {
      Loggers.SYSTEM_LOGGER.info(
          "Started with development/test mode; data will be deleted on shutdown");

      try {
        workingDirectory = Files.createTempDirectory("zeebe").toAbsolutePath().normalize();
      } catch (final IOException e) {
        throw new UncheckedIOException("Failed to start with temporary directory", e);
      }

      return new WorkingDirectory(workingDirectory, true);
    }

    workingDirectory =
        Path.of(environment.getProperty("basedir", ".")).toAbsolutePath().normalize();
    return new WorkingDirectory(workingDirectory, false);
  }

  private boolean shouldUseTemporaryFolder() {
    return environment.acceptsProfiles(
        Profiles.of(Profile.DEVELOPMENT.getId(), Profile.TEST.getId()));
  }

  public record WorkingDirectory(Path path, boolean isTemporary) {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy