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

com.github.danielflower.mavenplugins.gitlog.renderers.Formatter Maven / Gradle / Ivy

Go to download

Generates a changelog based on commits to a git repository in text and HTML format showing the changes that are included in each version. A possible use of this is to include these changelogs when packaging your maven project so that you have an accurate list of commits that the current package includes.

There is a newer version: 1.9.1
Show newest version
package com.github.danielflower.mavenplugins.gitlog.renderers;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.maven.plugin.logging.Log;

public class Formatter {

	public static String NEW_LINE = String.format("%n");
	
	private static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss Z";

	private static DateFormat dateFormat = new SimpleDateFormat(DEFAULT_FORMAT);

	public static String formatDateTime() {
		return formatDateTime(new Date());
	}

	public static String formatDateTime(int secondsSinceEpoch) {
		Date date = new Date(secondsSinceEpoch * 1000L);
		return formatDateTime(date);
	}

	public static String formatDateTime(Date date) {
		return dateFormat.format(date);
	}

	public static void setFormat(String format, Log log) {
		try {
			dateFormat = new SimpleDateFormat(format);
		} catch (NullPointerException npe) {
			log.warn(String.format("Date format should not be null, using default: '%s'", DEFAULT_FORMAT));
			dateFormat = new SimpleDateFormat(DEFAULT_FORMAT);
		} catch (IllegalArgumentException iae) {
			log.warn(String.format("Invalid date format '%s', using default: '%s'", format, DEFAULT_FORMAT));
			dateFormat = new SimpleDateFormat(DEFAULT_FORMAT);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy