View Javadoc

1   package org.apache.maven.jelly.tags.maven;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import java.text.SimpleDateFormat;
22  import java.util.Date;
23  import java.util.TimeZone;
24  
25  import org.apache.commons.jelly.MissingAttributeException;
26  import org.apache.commons.jelly.XMLOutput;
27  import org.apache.maven.jelly.tags.BaseTagSupport;
28  import org.apache.maven.project.Project;
29  
30  /** Create snapshot signature for non-release JARs and distributions.
31   *
32   * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
33   * @version $Id: SnapshotSignature.java 517014 2007-03-11 21:15:50Z ltheussl $
34   */
35  public class SnapshotSignature
36      extends BaseTagSupport
37  {
38      /** Maven project */
39      private Project project;
40  
41      /**
42       * Set the maven project object.
43       *
44       * @param project MavenSession project.
45       */
46      public void setProject( Project project )
47      {
48          this.project = project;
49      }
50  
51      /**
52       * Get the maven project object.
53       *
54       * @return MavenSession project.
55       */
56      public Project getProject()
57      {
58          return project;
59      }
60  
61      /**
62       * Process the tag. Create a variable in the current context of the format
63       * <code>${pom.artifactId}-yyyyMMdd.HHmmss</code>
64       *
65       * @param output used to send XML output to Jelly
66       * @throws MissingAttributeException if the project property is not set
67       */
68      public void doTag( XMLOutput output )
69          throws MissingAttributeException
70      {
71          checkAttribute( project, "project" );
72  
73          Date now = new Date();
74          SimpleDateFormat formatter = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
75          formatter.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
76          String snapshotVersion = formatter.format( now );
77          String snapshotSignature = getProject().getArtifactId() + "-" + snapshotVersion;
78  
79          context.setVariable( "snapshotSignature", snapshotSignature );
80  
81          // We want to straight version so that we can deploy a marker
82          // that will allow projects to flip between the 'SNAPSHOT'
83          // identifier and a real snapshot version identifier.
84          context.setVariable( "snapshotVersion", snapshotVersion );
85      }
86  }