1 package com.soebes.maven.extensions.metadata;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Map;
23 import java.util.concurrent.ConcurrentHashMap;
24
25 import org.eclipse.aether.RepositoryEvent;
26 import org.eclipse.aether.metadata.Metadata;
27
28 import com.soebes.maven.extensions.TimePlusSize;
29
30
31
32
33 public abstract class AbstractMetadataTimer
34 {
35 private Map<String, TimePlusSize> timerEvents;
36
37 public AbstractMetadataTimer()
38 {
39 this.timerEvents = new ConcurrentHashMap<>();
40 }
41
42 protected String getArtifactId( Metadata artifact )
43 {
44 StringBuilder sb = new StringBuilder( 128 );
45 sb.append( artifact.getGroupId() )
46 .append( ":" ).append( artifact.getArtifactId() )
47 .append( ":" ).append( artifact.getVersion() )
48 .append( ':' ).append( artifact.getType() )
49 .append( ':' ).append( artifact.getNature() );
50
51 return sb.toString();
52 }
53
54 protected Map<String, TimePlusSize> getTimerEvents()
55 {
56 return timerEvents;
57 }
58
59 public void start( RepositoryEvent event )
60 {
61 String metadataId = getArtifactId( event.getMetadata() );
62 TimePlusSize systemTime = new TimePlusSize();
63 systemTime.start();
64 getTimerEvents().put( metadataId, systemTime );
65 }
66
67 public void stop( RepositoryEvent event )
68 {
69 String metadataId = getArtifactId( event.getMetadata() );
70 if ( !getTimerEvents().containsKey( metadataId ) )
71 {
72 throw new IllegalArgumentException( "Unknown metadataId (" + metadataId + ")" );
73 }
74 getTimerEvents().get( metadataId ).stop();
75
76 long size = 0;
77 if ( event.getMetadata().getFile() != null )
78 {
79 size = event.getMetadata().getFile().length();
80 }
81 getTimerEvents().get( metadataId ).setSize( size );
82 }
83
84 }