Author: aadamchik Date: Mon Jan 15 07:15:04 2007 New Revision: 496366 URL: http://svn.apache.org/viewvc?view=rev&rev=496366 Log: a new "date" goal added to the build plugin to address the lack of timestamp in the Maven environment
Added: incubator/cayenne/main/trunk/other/maven-cayenne-build-plugin/src/main/java/org/apache/cayenne/maven/plugin/date/ incubator/cayenne/main/trunk/other/maven-cayenne-build-plugin/src/main/java/org/apache/cayenne/maven/plugin/date/DateMojo.java Added: incubator/cayenne/main/trunk/other/maven-cayenne-build-plugin/src/main/java/org/apache/cayenne/maven/plugin/date/DateMojo.java URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/maven-cayenne-build-plugin/src/main/java/org/apache/cayenne/maven/plugin/date/DateMojo.java?view=auto&rev=496366 ============================================================================== --- incubator/cayenne/main/trunk/other/maven-cayenne-build-plugin/src/main/java/org/apache/cayenne/maven/plugin/date/DateMojo.java (added) +++ incubator/cayenne/main/trunk/other/maven-cayenne-build-plugin/src/main/java/org/apache/cayenne/maven/plugin/date/DateMojo.java Mon Jan 15 07:15:04 2007 @@ -0,0 +1,60 @@ +/***************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.cayenne.maven.plugin.date; + +import java.text.Format; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; + +/** + * Exports the "project.build.date" and "project.build.time" properties to the + * environment. + * + * @author Andrus Adamchik + * @goal date + * @phase generate-resources + * @requiresProject + */ +public class DateMojo extends AbstractMojo { + + static final String BUILD_DATE_PROPERTY = "project.build.date"; + static final String BUILD_TIME_PROPERTY = "project.build.time"; + + static final String BUILD_DATE_FORMAT = "MMM dd yyyy"; + static final String BUILD_TIME_FORMAT = "HH:mm:ss"; + + public void execute() throws MojoExecutionException, MojoFailureException { + Format dateFormat = new SimpleDateFormat(BUILD_DATE_FORMAT); + Format timeFormat = new SimpleDateFormat(BUILD_TIME_FORMAT); + + // convert to GMT + Calendar calendar = Calendar.getInstance(); + int offset = calendar.get(Calendar.ZONE_OFFSET); + calendar.add(Calendar.MILLISECOND, -offset); + Date gmtTime = calendar.getTime(); + + System.setProperty(BUILD_DATE_PROPERTY, dateFormat.format(gmtTime)); + System.setProperty(BUILD_TIME_PROPERTY, timeFormat.format(gmtTime)); + } +}