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