View Javadoc
1   package org.apache.maven.repository.internal;
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 java.util.Collection;
23  import java.util.Collections;
24  import java.util.Date;
25  import java.util.LinkedHashMap;
26  import java.util.Map;
27  
28  import org.eclipse.aether.RepositorySystemSession;
29  import org.eclipse.aether.artifact.Artifact;
30  import org.eclipse.aether.impl.MetadataGenerator;
31  import org.eclipse.aether.installation.InstallRequest;
32  import org.eclipse.aether.metadata.Metadata;
33  import org.eclipse.aether.util.ConfigUtils;
34  
35  /**
36   * @author Benjamin Bentmann
37   */
38  class LocalSnapshotMetadataGenerator
39      implements MetadataGenerator
40  {
41  
42      private Map<Object, LocalSnapshotMetadata> snapshots;
43  
44      private final boolean legacyFormat;
45  
46      private final Date timestamp;
47  
48      LocalSnapshotMetadataGenerator( RepositorySystemSession session, InstallRequest request )
49      {
50          legacyFormat = ConfigUtils.getBoolean( session.getConfigProperties(), false, "maven.metadata.legacy" );
51  
52          timestamp = (Date) ConfigUtils.getObject( session, new Date(), "maven.startTime" );
53  
54          snapshots = new LinkedHashMap<>();
55      }
56  
57      public Collection<? extends Metadata> prepare( Collection<? extends Artifact> artifacts )
58      {
59          for ( Artifact artifact : artifacts )
60          {
61              if ( artifact.isSnapshot() )
62              {
63                  Object key = LocalSnapshotMetadata.getKey( artifact );
64                  LocalSnapshotMetadata snapshotMetadata = snapshots.get( key );
65                  if ( snapshotMetadata == null )
66                  {
67                      snapshotMetadata = new LocalSnapshotMetadata( artifact, legacyFormat, timestamp );
68                      snapshots.put( key, snapshotMetadata );
69                  }
70                  snapshotMetadata.bind( artifact );
71              }
72          }
73  
74          return Collections.emptyList();
75      }
76  
77      public Artifact transformArtifact( Artifact artifact )
78      {
79          return artifact;
80      }
81  
82      public Collection<? extends Metadata> finish( Collection<? extends Artifact> artifacts )
83      {
84          return snapshots.values();
85      }
86  
87  }