1 package org.apache.maven.archiva.repository.scanner;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.commons.collections.CollectionUtils;
23 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
24 import org.apache.maven.archiva.model.RepositoryContentStatistics;
26 import java.util.List;
29 * RepositoryScanStatistics - extension to the RepositoryContentStatistics model.
31 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
34 public class RepositoryScanStatistics
35 extends RepositoryContentStatistics
37 private transient List<String> knownConsumers;
39 private transient List<String> invalidConsumers;
41 private transient long startTimestamp;
43 public void triggerStart()
45 startTimestamp = System.currentTimeMillis();
48 public void triggerFinished()
50 long finished = System.currentTimeMillis();
51 setDuration( finished - startTimestamp );
52 setWhenGathered( new java.util.Date( finished ) );
55 public void increaseFileCount()
57 long count = getTotalFileCount();
58 setTotalFileCount( ++count );
61 public void increaseNewFileCount()
63 long count = getNewFileCount();
64 setNewFileCount( ++count );
67 public void setKnownConsumers( List<String> consumers )
69 knownConsumers = consumers;
72 public void setInvalidConsumers( List<String> consumers )
74 invalidConsumers = consumers;
77 public String toDump( ManagedRepositoryConfiguration repo )
79 java.text.SimpleDateFormat df = new java.text.SimpleDateFormat();
80 StringBuffer buf = new StringBuffer();
82 buf.append( "\n.\\ Scan of " ).append( this.getRepositoryId() );
83 buf.append( " \\.__________________________________________" );
85 buf.append( "\n Repository Dir : " ).append( repo.getLocation() );
86 buf.append( "\n Repository Name : " ).append( repo.getName() );
87 buf.append( "\n Repository Layout : " ).append( repo.getLayout() );
89 buf.append( "\n Known Consumers : " );
90 if ( CollectionUtils.isNotEmpty( knownConsumers ) )
92 buf.append( "(" ).append( knownConsumers.size() ).append( " configured)" );
93 for ( String id : knownConsumers )
95 buf.append( "\n " ).append( id );
100 buf.append( "<none>" );
103 buf.append( "\n Invalid Consumers : " );
104 if ( CollectionUtils.isNotEmpty( invalidConsumers ) )
106 buf.append( "(" ).append( invalidConsumers.size() ).append( " configured)" );
107 for ( String id : invalidConsumers )
109 buf.append( "\n " ).append( id );
114 buf.append( "<none>" );
117 buf.append( "\n Duration : " );
118 buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( this.getDuration() ) );
119 buf.append( "\n When Gathered : " );
120 if ( this.getWhenGathered() == null )
122 buf.append( "<null>" );
126 buf.append( df.format( this.getWhenGathered() ) );
129 buf.append( "\n Total File Count : " ).append( this.getTotalFileCount() );
131 long averageMsPerFile = 0;
133 if ( getTotalFileCount() != 0 )
135 averageMsPerFile = ( this.getDuration() / this.getTotalFileCount() );
138 buf.append( "\n Avg Time Per File : " );
139 buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( averageMsPerFile ) );
140 buf.append( "\n______________________________________________________________" );
142 return buf.toString();