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.text.SimpleDateFormat;
27 import java.util.List;
30 * RepositoryScanStatistics - extension to the RepositoryContentStatistics model.
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 private SimpleDateFormat df = new SimpleDateFormat();
45 public void triggerStart()
47 startTimestamp = System.currentTimeMillis();
50 public void triggerFinished()
52 long finished = System.currentTimeMillis();
53 setDuration( finished - startTimestamp );
54 setWhenGathered( new java.util.Date( finished ) );
57 public void increaseFileCount()
59 long count = getTotalFileCount();
60 setTotalFileCount( ++count );
63 public void increaseNewFileCount()
65 long count = getNewFileCount();
66 setNewFileCount( ++count );
69 public void setKnownConsumers( List<String> consumers )
71 knownConsumers = consumers;
74 public void setInvalidConsumers( List<String> consumers )
76 invalidConsumers = consumers;
79 public String toDump( ManagedRepositoryConfiguration repo )
81 StringBuffer buf = new StringBuffer();
83 buf.append( "\n.\\ Scan of " ).append( this.getRepositoryId() );
84 buf.append( " \\.__________________________________________" );
86 buf.append( "\n Repository Dir : " ).append( repo.getLocation() );
87 buf.append( "\n Repository Name : " ).append( repo.getName() );
88 buf.append( "\n Repository Layout : " ).append( repo.getLayout() );
90 buf.append( "\n Known Consumers : " );
91 if ( CollectionUtils.isNotEmpty( knownConsumers ) )
93 buf.append( "(" ).append( knownConsumers.size() ).append( " configured)" );
94 for ( String id : knownConsumers )
96 buf.append( "\n " ).append( id );
101 buf.append( "<none>" );
104 buf.append( "\n Invalid Consumers : " );
105 if ( CollectionUtils.isNotEmpty( invalidConsumers ) )
107 buf.append( "(" ).append( invalidConsumers.size() ).append( " configured)" );
108 for ( String id : invalidConsumers )
110 buf.append( "\n " ).append( id );
115 buf.append( "<none>" );
118 buf.append( "\n Duration : " );
119 buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( this.getDuration() ) );
120 buf.append( "\n When Gathered : " );
121 if ( this.getWhenGathered() == null )
123 buf.append( "<null>" );
127 buf.append( df.format( this.getWhenGathered() ) );
130 buf.append( "\n Total File Count : " ).append( this.getTotalFileCount() );
132 long averageMsPerFile = 0;
134 if ( getTotalFileCount() != 0 )
136 averageMsPerFile = ( this.getDuration() / this.getTotalFileCount() );
139 buf.append( "\n Avg Time Per File : " );
140 buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( averageMsPerFile ) );
141 buf.append( "\n______________________________________________________________" );
143 return buf.toString();