Coverage Report - org.apache.maven.shared.jar.identification.exposers.TimestampExposer
 
Classes in this File Line Coverage Branch Coverage Complexity
TimestampExposer
0%
0/24
0%
0/8
5
 
 1  
 package org.apache.maven.shared.jar.identification.exposers;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.commons.collections.Bag;
 23  
 import org.apache.commons.collections.bag.HashBag;
 24  
 import org.apache.maven.shared.jar.JarAnalyzer;
 25  
 import org.apache.maven.shared.jar.identification.JarIdentification;
 26  
 import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
 27  
 import org.codehaus.plexus.util.StringUtils;
 28  
 
 29  
 import java.text.SimpleDateFormat;
 30  
 import java.util.Date;
 31  
 import java.util.Iterator;
 32  
 import java.util.List;
 33  
 import java.util.Locale;
 34  
 import java.util.jar.JarEntry;
 35  
 
 36  
 /**
 37  
  * Exposer that examines a a JAR and uses the most recent timestamp as a potential version.
 38  
  *
 39  
  * @plexus.component role="org.apache.maven.shared.jar.identification.JarIdentificationExposer" role-hint="timestamp"
 40  
  */
 41  0
 public class TimestampExposer
 42  
     implements JarIdentificationExposer
 43  
 {
 44  
     public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
 45  
     {
 46  0
         List entries = jarAnalyzer.getEntries();
 47  0
         SimpleDateFormat tsformat = new SimpleDateFormat( "yyyyMMdd", Locale.US ); //$NON-NLS-1$
 48  0
         Bag timestamps = new HashBag();
 49  0
         Iterator it = entries.iterator();
 50  0
         while ( it.hasNext() )
 51  
         {
 52  0
             JarEntry entry = (JarEntry) it.next();
 53  0
             long time = entry.getTime();
 54  0
             String timestamp = tsformat.format( new Date( time ) );
 55  0
             timestamps.add( timestamp );
 56  0
         }
 57  
 
 58  0
         it = timestamps.iterator();
 59  0
         String ts = "";
 60  0
         int tsmax = 0;
 61  0
         while ( it.hasNext() )
 62  
         {
 63  0
             String timestamp = (String) it.next();
 64  0
             int count = timestamps.getCount( timestamp );
 65  0
             if ( count > tsmax )
 66  
             {
 67  0
                 ts = timestamp;
 68  0
                 tsmax = count;
 69  
             }
 70  0
         }
 71  
 
 72  0
         if ( StringUtils.isNotEmpty( ts ) )
 73  
         {
 74  0
             identification.addVersion( ts );
 75  
         }
 76  0
     }
 77  
 }