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

com.mooltiverse.oss.nyx.configuration.presets.Substitutions Maven / Gradle / Ivy

There is a newer version: 3.0.11
Show newest version
/*
 * Copyright 2020 Mooltiverse
 *
 * 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.
 */
package com.mooltiverse.oss.nyx.configuration.presets;

import com.mooltiverse.oss.nyx.entities.Substitution;

/**
 * This class provides reusable configuration chunks for substitutions.
 */
public class Substitutions {
    /**
     * The Cargo (Rust) version substitution configuration
     * that replaces the version number inside Cargo.toml files within the project.
     */
    public static final Substitution CARGO_VERSION = new Substitution() {
        {
            // Capture all Cargo.toml files in the project directory in any folder
            setFiles("**/Cargo.toml");
            // Capture any string like version = "SEMANTIC_VERSION", tolerating extra spaces and using single or double quotes for the version value
            setMatch("version(\\s)*=(\\s)*(\"|')?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?(\"|')?");
            // Replace with the current version
            setReplace("version = \"{{version}}\"");
        }
    };

    /**
     * The Composer (PHP) version substitution configuration
     * that replaces the version number inside composer.json files within the project.
     */
    public static final Substitution COMPOSER_VERSION = new Substitution() {
        {
            // Capture all composer.json files in the project directory in any folder
            setFiles("**/composer.json");
            // Capture any string like "version": "SEMANTIC_VERSION", tolerating extra spaces
            setMatch("\"version\"(\\s)*:(\\s)*\"(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?\"");
            // Replace with the current version
            setReplace("\"version\": \"{{version}}\"");
        }
    };

    /**
     * The Dart (Flutter) version substitution configuration
     * that replaces the version number inside pubspec.yaml files within the project.
     */
    public static final Substitution DART_VERSION = new Substitution() {
        {
            // Capture all pubspec.yaml files in the project directory in any folder
            setFiles("**/pubspec.yaml");
            // Capture any string like version = "SEMANTIC_VERSION", tolerating extra spaces and using single, double or no quotes for the the attribute name ("version") and the version value
            setMatch("(\"|')?version(\"|')?(\\s)*:(\\s)*(\"|')?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?(\"|')?");
            // Replace with the current version
            setReplace("version: \"{{version}}\"");
        }
    };

    /**
     * The Elixir version substitution configuration
     * that replaces the version number inside mix.exs files within the project.
     */
    public static final Substitution ELIXIR_VERSION = new Substitution() {
        {
            // Capture all mix.exs files in the project directory in any folder
            setFiles("**/mix.exs");
            // Capture any string like version: "SEMANTIC_VERSION", tolerating extra spaces
            setMatch("version(\\s)*:(\\s)*\"(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?\"");
            // Replace with the current version
            setReplace("version: \"{{version}}\"");
        }
    };

    /**
     * The Expo (React) version substitution configuration
     * that replaces the version number inside app.json and app.config.json files within the project.
     */
    public static final Substitution EXPO_VERSION = new Substitution() {
        {
            // Capture all app.json and app.config.json files in the project directory in any folder
            setFiles("**/{app,app.config}.json");
            // Capture any string like "version": "SEMANTIC_VERSION", tolerating extra spaces
            setMatch("\"version\"(\\s)*:(\\s)*\"(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?\"");
            // Replace with the current version
            setReplace("\"version\": \"{{version}}\"");
        }
    };

    /**
     * The Helm version substitution configuration
     * that replaces the version number inside Chart.yaml files within the project.
     */
    public static final Substitution HELM_VERSION = new Substitution() {
        {
            // Capture all Chart.yaml files in the project directory in any folder
            setFiles("**/Chart.yaml");
            // Capture any string like version = "SEMANTIC_VERSION", tolerating extra spaces and using single, double or no quotes for the the attribute name ("version") and the version value
            setMatch("(\"|')?version(\"|')?(\\s)*:(\\s)*(\"|')?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?(\"|')?");
            // Replace with the current version
            setReplace("version: \"{{version}}\"");
        }
    };

    /**
     * The Node version substitution configuration
     * that replaces the version number inside package.json files within the project.
     */
    public static final Substitution NODE_VERSION = new Substitution() {
        {
            // Capture all package.json files in the project directory in any folder
            setFiles("**/package.json");
            // Capture any string like "version": "SEMANTIC_VERSION", tolerating extra spaces
            setMatch("\"version\"(\\s)*:(\\s)*\"(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?\"");
            // Replace with the current version
            setReplace("\"version\": \"{{version}}\"");
        }
    };

    /**
     * The version substitution configuration that replaces the contents of any version.txt file within the project with the version number.
     */
    public static final Substitution TEXT_VERSION = new Substitution() {
        {
            // Capture all version.txt files in the project directory in any folder
            setFiles("**/version.txt");
            // Capture anything to replace the whole content
            setMatch("(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?");
            // Replace with the current version
            setReplace("{{version}}");
        }
    };

    /**
     * Default constructor is hidden on purpose.
     */
    public Substitutions() {
        super();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy