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

de.smartics.maven.plugin.buildmetadata.common.Constant Maven / Gradle / Ivy

/*
 * Copyright 2006-2019 smartics, Kronseder & Reiner GmbH
 *
 * 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 de.smartics.maven.plugin.buildmetadata.common;

import org.codehaus.plexus.util.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * Constants used in this package.
 */
public final class Constant {
  // ********************************* Fields *********************************

  // --- constants ------------------------------------------------------------

  // ... sections .............................................................

  /**
   * The name of the SCM section.
   * 

* The value of this constant is {@value}. *

*/ public static final String SECTION_BUILD_SCM = "build.scm"; /** * The name of the artifact section. *

* The value of this constant is {@value}. *

*/ public static final String SECTION_ARTIFACT = "build.artifact"; /** * The name of the build date section. *

* The value of this constant is {@value}. *

*/ public static final String SECTION_BUILD_DATE = "build.timeAndDate"; /** * The name of the runtime build section. *

* The value of this constant is {@value}. *

*/ public static final String SECTION_BUILD_RUNTIME = "build.runtime"; /** * The name of the Java build section. *

* The value of this constant is {@value}. *

*/ public static final String SECTION_BUILD_JAVA = "build.java"; /** * The name of the Maven build section. *

* The value of this constant is {@value}. *

*/ public static final String SECTION_BUILD_MAVEN = "build.maven"; /** * The name of the miscellaneous build section. *

* The value of this constant is {@value}. *

*/ public static final String SECTION_BUILD_MISC = "build.misc"; /** * The name of the project section. *

* The value of this constant is {@value}. *

*/ public static final String SECTION_PROJECT = "project"; // ... build property names ................................................. /** * The name of the project property that stores the URL to the SCM server. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_SCM_URL = "build.scmRevision.url"; /** * The name of the project property that stores the revision number provided * by the SCM. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_SCM_REVISION_ID = "build.scmRevision.id"; /** * The name of the project property that stores the date the revision number * was set. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_SCM_REVISION_DATE = "build.scmRevision.date"; /** * The name of the project property that stores the information if the local * sources are modified. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_SCM_LOCALLY_MODIFIED = "build.scmLocallyModified"; /** * The name of the project property that stores the files that are locally * modified. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_SCM_LOCALLY_MODIFIED_FILES = "build.scmLocallyModified.files"; /** * The name of the project property that stores the formatted build date. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_BUILD_DATE = "build.date"; /** * The name of the project property that stores the build timestamp. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_BUILD_TIMESTAMP = "build.timestamp.millis"; /** * The name of the project property that stores the custom format of the build * timestamp. *

* The value of this constant is {@value}. *

* * @since 1.7 */ public static final String PROP_NAME_BUILD_TIMESTAMP_CUSTOM = "build.timestamp.custom"; /** * The name of the project property that stores the pattern of the build date. * This way it is easy for the reading client to parse the build date. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_BUILD_DATE_PATTERN = "build.date.pattern"; /** * The name of the project property that stores the pattern of the timestamp * date. *

* The value of this constant is {@value}. *

* * @since 1.7 */ public static final String PROP_NAME_BUILD_TIMESTAMP_PATTERN = "build.timestamp.pattern"; /** * The name of the project property that stores the group ID as read from the * POM. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_GROUP_ID = "build.groupId"; /** * The name of the project property that stores the artifact ID as read from * the POM. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_ARTIFACT_ID = "build.artifactId"; /** * The name of the project property that stores the version as read from the * POM. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_VERSION = "build.version"; /** * The name of the project property that stores the major version number * determined from the version specified in the POM. *

* The value of this constant is {@value}. *

* * @since 1.7 */ public static final String PROP_NAME_VERSION_MAJOR = "build.version.major"; /** * The name of the project property that stores the minor version number * determined from the version specified in the POM. *

* The value of this constant is {@value}. *

* * @since 1.7 */ public static final String PROP_NAME_VERSION_MINOR = "build.version.minor"; /** * The name of the project property that stores the micro or incremental * version number determined from the version specified in the POM. *

* The value of this constant is {@value}. *

* * @since 1.7 */ public static final String PROP_NAME_VERSION_MICRO = "build.version.micro"; /** * The name of the project property that stores the build number part * determined from the version specified in the POM. *

* The value of this constant is {@value}. *

* * @since 1.7 */ public static final String PROP_NAME_VERSION_BUILDNUMBER = "build.version.buildNumber"; /** * The name of the project property that stores the qualifier part determined * from the version specified in the POM. *

* The value of this constant is {@value}. *

* * @since 1.7 */ public static final String PROP_NAME_VERSION_QUALIFIER = "build.version.qualifier"; /** * The name of the project property that stores the full version that may * include the version, the build date, the build number and the revision * number. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_FULL_VERSION = "build.version.full"; /** * The name of the project property that stores the build year. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_BUILD_YEAR = "build.year"; /** * The name of the project property that stores the duration of the build in * milliseconds. The duration is taken at the end of the build when the last * plugin is run. The plugin cannot guarantee that there is no work done * afterwards. The install and deploy phase are not measured since the plugin * is running in the verify phase. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_BUILD_DURATION = "build.duration"; /** * The name of the project property that stores the copyright year. The * copyright year is either the inception year (if inception and build year * are the same) or the period starting with the inception year and ending * with the build year. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_COPYRIGHT_YEAR = "build.copyright.year"; /** * The default pattern for the (locale independent) build date. *

* The value of this constant is {@value}. *

*/ public static final String DEFAULT_DATE_PATTERN = "dd.MM.yyyy"; /** * The default pattern for the (locale independent) timestamp. *

* The value of this constant is {@value}. *

* * @since 1.7 */ public static final String DEFAULT_TIMESTAMP_PATTERN = "yyyyMMdd.HHmmss"; /** * The name of the project property that stores the build user. This is the * person or system that run the build. It is either a configured value or the * value of the system property user.name. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_BUILD_USER = "build.user"; /** * The name of the property that stores the name of the host the build has * been run on. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_HOSTNAME = "build.host.name"; /** * The name of the property that stores the name of the operating system the * build has been run on. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_OS_NAME = "build.os.name"; /** * The name of the property that stores the architecture of the operating * system the build has been run on. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_OS_ARCH = "build.os.arch"; /** * The name of the property that stores the version of the operating system * the build has been run on. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_OS_VERSION = "build.os.version"; /** * The name of the property that stores the name of Java runtime being * executed for the build. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_JAVA_RUNTIME_NAME = "build.java.runtime.name"; /** * The name of the property that stores the version of Java runtime being * executed for the build. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_JAVA_RUNTIME_VERSION = "build.java.runtime.version"; /** * The name of the property that stores the name of the vendor of Java being * executed for the build. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_JAVA_VENDOR = "build.java.vendor"; /** * The name of the property that stores the name of the Java VM being executed * for the build. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_JAVA_VM = "build.java.vm"; /** * The name of the property that stores the name of the Java compiler being * executed for the build. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_JAVA_COMPILER = "build.java.compiler"; /** * The name of the property that stores the target version for the Java source * files. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_JAVA_COMPILER_SOURCE = "build.runtime.java.compiler.source"; /** * The name of the property that stores the target version for the Java class * files. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_JAVA_COMPILER_TARGET = "build.runtime.java.compiler.target"; /** * The name of the property that stores the version of Maven being executed * for the build. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_MAVEN_VERSION = "build.maven.version"; /** * The name of the property that stores the goals given on the command line * for the build. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_MAVEN_GOALS = "build.maven.execution.goals"; /** * The name of the property that stores the command line to start the build. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_MAVEN_CMDLINE = "build.maven.execution.cmdline"; /** * The name of the property that stores the Maven opts set in the environment. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_MAVEN_OPTS = "build.maven.execution.opts"; /** * The name of the property that stores the Java opts set in the environment. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_JAVA_OPTS = "build.maven.execution.java.opts"; /** * The name of the property that flags if the artifact is build within the * project that is the execution root. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_MAVEN_IS_EXECUTION_ROOT = "build.maven.execution.isRoot"; /** * The name of the property that contains the name of the execution project. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_MAVEN_EXECUTION_PROJECT = "build.maven.execution.project"; /** * The name of the property that contains the name of the filters being * registered for the build. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_MAVEN_FILTERS = "build.maven.execution.filters"; /** * The prefix used to provide execution properties to the build properties * file. *

* The value of this constant is {@value}. *

*/ public static final String MAVEN_EXECUTION_PROPERTIES_PREFIX = "execution.property"; /** * The name of the property that contains names of active profiles during the * build. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_MAVEN_ACTIVE_PROFILES = "build.maven.execution.profiles.active"; /** * The prefix used to provide active profile information of the build. *

* The value of this constant is {@value}. *

*/ public static final String MAVEN_ACTIVE_PROFILE_PREFIX = "build.maven.execution.profile.active"; /** * The name of the property that stores URL of the project homepage. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_PROJECT_HOMEPAGE = "project.page.home.url"; /** * The name of the property that stores URL to a page useful for operations * teams. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_PROJECT_OPS = "project.page.ops.url"; /** * The name of the property that stores a value to categorize the project. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_PROJECT_CATEGORY = "project.category"; /** * The name of the property that stores a value to further categorize the * project. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_PROJECT_SUBCATEGORY = "project.subcategory"; /** * The name of the property that stores a comma separated list of tags to * categorize the project. *

* The value of this constant is {@value}. *

*/ public static final String PROP_NAME_PROJECT_TAGS = "project.tags"; /** * List of properties, organized in sections, relevant to the build report. * The order of properties in this list determines the order of the properties * listed in the report. */ public static final List
REPORT_PROPERTIES; /** * The set of standard keys known to be rendered in sections. This list allows * to render properties within a separate section that have not yet been * rendered. */ public static final Set STANDARD_PROPERTIES; // --- members -------------------------------------------------------------- // ****************************** Initializer ******************************* static { final List
sections = new ArrayList
(); final Section scm = new Section(SECTION_BUILD_SCM, PROP_NAME_SCM_REVISION_ID, PROP_NAME_SCM_REVISION_DATE, PROP_NAME_SCM_URL, PROP_NAME_SCM_LOCALLY_MODIFIED_FILES); sections.add(scm); final Section artifact = new Section(SECTION_ARTIFACT, PROP_NAME_GROUP_ID, PROP_NAME_ARTIFACT_ID, PROP_NAME_VERSION, PROP_NAME_FULL_VERSION, PROP_NAME_VERSION_MAJOR, PROP_NAME_VERSION_MINOR, PROP_NAME_VERSION_MICRO, PROP_NAME_VERSION_BUILDNUMBER, PROP_NAME_VERSION_QUALIFIER); sections.add(artifact); final Section dateAndVersion = new Section(SECTION_BUILD_DATE, PROP_NAME_BUILD_DATE, PROP_NAME_BUILD_TIMESTAMP, PROP_NAME_BUILD_YEAR, PROP_NAME_COPYRIGHT_YEAR, DEFAULT_DATE_PATTERN); sections.add(dateAndVersion); final Section buildRuntime = new Section(SECTION_BUILD_RUNTIME, PROP_NAME_HOSTNAME, PROP_NAME_OS_NAME, PROP_NAME_OS_ARCH, PROP_NAME_OS_VERSION, PROP_NAME_BUILD_USER); sections.add(buildRuntime); final Section buildJava = new Section(SECTION_BUILD_JAVA, PROP_NAME_JAVA_VENDOR, PROP_NAME_JAVA_RUNTIME_NAME, PROP_NAME_JAVA_RUNTIME_VERSION, PROP_NAME_JAVA_VM, PROP_NAME_JAVA_COMPILER, PROP_NAME_JAVA_COMPILER_SOURCE, PROP_NAME_JAVA_COMPILER_TARGET, PROP_NAME_JAVA_OPTS); sections.add(buildJava); final Section buildMaven = new Section(SECTION_BUILD_MAVEN, PROP_NAME_MAVEN_VERSION, PROP_NAME_MAVEN_CMDLINE, PROP_NAME_MAVEN_GOALS, PROP_NAME_MAVEN_OPTS, PROP_NAME_MAVEN_EXECUTION_PROJECT, PROP_NAME_MAVEN_IS_EXECUTION_ROOT, PROP_NAME_MAVEN_FILTERS, PROP_NAME_MAVEN_ACTIVE_PROFILES); sections.add(buildMaven); final Section project = new Section(SECTION_PROJECT, PROP_NAME_PROJECT_HOMEPAGE, PROP_NAME_PROJECT_OPS, PROP_NAME_PROJECT_CATEGORY, PROP_NAME_PROJECT_SUBCATEGORY, PROP_NAME_PROJECT_TAGS); sections.add(project); final Set properties = new HashSet( Arrays.asList(new String[] {PROP_NAME_SCM_REVISION_ID, PROP_NAME_SCM_REVISION_DATE, PROP_NAME_SCM_URL, PROP_NAME_SCM_LOCALLY_MODIFIED_FILES, PROP_NAME_BUILD_DATE, PROP_NAME_BUILD_TIMESTAMP, PROP_NAME_BUILD_YEAR, PROP_NAME_COPYRIGHT_YEAR, DEFAULT_DATE_PATTERN, PROP_NAME_GROUP_ID, PROP_NAME_ARTIFACT_ID, PROP_NAME_VERSION, PROP_NAME_FULL_VERSION, PROP_NAME_HOSTNAME, PROP_NAME_OS_NAME, PROP_NAME_OS_ARCH, PROP_NAME_OS_VERSION, PROP_NAME_BUILD_USER, PROP_NAME_JAVA_VENDOR, PROP_NAME_JAVA_RUNTIME_NAME, PROP_NAME_JAVA_RUNTIME_VERSION, PROP_NAME_JAVA_VM, PROP_NAME_JAVA_COMPILER, PROP_NAME_JAVA_COMPILER_SOURCE, PROP_NAME_JAVA_COMPILER_TARGET, PROP_NAME_JAVA_OPTS, PROP_NAME_MAVEN_VERSION, PROP_NAME_MAVEN_CMDLINE, PROP_NAME_MAVEN_GOALS, PROP_NAME_MAVEN_OPTS, PROP_NAME_MAVEN_EXECUTION_PROJECT, PROP_NAME_MAVEN_IS_EXECUTION_ROOT, PROP_NAME_MAVEN_FILTERS, PROP_NAME_MAVEN_ACTIVE_PROFILES, PROP_NAME_PROJECT_HOMEPAGE, PROP_NAME_PROJECT_OPS})); STANDARD_PROPERTIES = Collections.unmodifiableSet(properties); REPORT_PROPERTIES = Collections.unmodifiableList(sections); } // ****************************** Constructors ****************************** /** * Constant pattern. */ private Constant() {} // ****************************** Inner Classes ***************************** /** * The section allows to group build meta data properties. */ public static final class Section { /** * The resource key to access the title of the section. */ private final String titleKey; /** * The build meta data properties to be displayed in this section. */ private final List properties; /** * Default constructor. * * @param titleKey the resource key to access the title of the section. * @param properties the build meta data properties to be displayed in this * section. */ private Section(final String titleKey, final String... properties) { this.titleKey = titleKey; this.properties = Arrays.asList(properties); } /** * Returns the resource key to access the title of the section. * * @return the resource key to access the title of the section. */ public String getTitleKey() { return titleKey; } /** * Returns the build meta data properties to be displayed in this section. * * @return the build meta data properties to be displayed in this section. */ public List getProperties() { return properties; } } // ********************************* Methods ******************************** // --- init ----------------------------------------------------------------- // --- get&set -------------------------------------------------------------- // --- business ------------------------------------------------------------- /** * Checks if the given property is rejected from being displayed in the misc * section of a report. * * @param name the name of the property to check. * @return true if the property is to be rendered in a misc * section, false otherwise. */ public static boolean isIntendedForMiscSection(final String name) { return !name.startsWith(MAVEN_ACTIVE_PROFILE_PREFIX); } /** * Calculates the non standard properties relevant for the misc section. * * @param buildMetaDataProperties the build meta data. * @param userProperties the list of a system properties or environment * variables to be selected by the user to include into the build meta * data properties. * @return the non standard properties. */ public static Properties calcNonStandardProperties( final Properties buildMetaDataProperties, final List userProperties) { final SortedProperties nonStandardProperties = new SortedProperties(); final Set selectedProperties = createSelectedPropertiesExcludeMiscSection(userProperties); for (final Map.Entry entry : buildMetaDataProperties .entrySet()) { final String key = String.valueOf(entry.getKey()); if (!Constant.STANDARD_PROPERTIES.contains(key) && !selectedProperties.contains(key)) { nonStandardProperties.put(key, entry.getValue()); } } return nonStandardProperties; } private static Set createSelectedPropertiesExcludeMiscSection( final List userProperties) { final Set selectedProperties = new HashSet(); if (userProperties != null) { for (final Property property : userProperties) { if (isNotTargetedForMiscSection(property.getSection())) { selectedProperties.add(property.getName()); } } } return selectedProperties; } private static boolean isNotTargetedForMiscSection(final String section) { return SECTION_BUILD_SCM.equals(section) || SECTION_BUILD_DATE.equals(section) || SECTION_BUILD_RUNTIME.equals(section) || SECTION_BUILD_JAVA.equals(section) || SECTION_BUILD_MAVEN.equals(section); } /** * Prettifies a multi value string that contains brackets. It simply removes * the brackets. * * @param string the string to prettify. * @return the prettified string. */ public static String prettify(final String string) { final String trimmed = string.trim(); final int end = trimmed.length() - 1; if (trimmed.charAt(0) == '[' && trimmed.charAt(end) == ']') { return trimmed.substring(1, end); } return trimmed; } /** * Prettifies a value string that contains brackets. It simply removes the * brackets. * * @param value the object whose string representation is to be prettified. * @return the prettified string. */ public static String prettifyFilesValue(final Object value) { if (value == null) { return null; } String string = String.valueOf(value); if (StringUtils.isNotBlank(string)) { string = string.replace(']', ' '); string = string.replace('[', ','); if (string.indexOf(0) == ',') { return string.substring(1); } } return string; } // --- object basics -------------------------------------------------------- }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy