View Javadoc
1   package org.apache.maven.shared.transfer.metadata.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.io.File;
23  import java.util.Map;
24  
25  import org.apache.maven.artifact.metadata.ArtifactMetadata;
26  import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
27  import org.eclipse.aether.metadata.AbstractMetadata;
28  import org.eclipse.aether.metadata.Metadata;
29  
30  /**
31   * A MetadataBridge for Maven 3.1 
32   * @author Robert Scholte
33   */
34  public class Maven31MetadataBridge extends AbstractMetadata implements Metadata
35  {
36      private ArtifactMetadata metadata;
37      
38      private File file;
39      
40      public Maven31MetadataBridge( ArtifactMetadata metadata )
41      {
42          this.metadata = metadata;
43      }
44  
45      @Override
46      public String getGroupId()
47      {
48          return emptify( metadata.getGroupId() );
49      }
50  
51      @Override
52      public String getArtifactId()
53      {
54          return metadata.storedInGroupDirectory() ? "" : emptify( metadata.getArtifactId() );
55      }
56  
57      @Override
58      public String getVersion()
59      {
60          return metadata.storedInArtifactVersionDirectory() ? emptify( metadata.getBaseVersion() ) : "";
61      }
62  
63      @Override
64      public String getType()
65      {
66          return metadata.getRemoteFilename();
67      }
68  
69      private String emptify( String string )
70      {
71          return ( string != null ) ? string : "";
72      }
73  
74      @Override
75      public File getFile()
76      {
77          return file;
78      }
79      
80      @Override
81      public Nature getNature()
82      {
83          if ( metadata instanceof RepositoryMetadata )
84          {
85              switch ( ( (RepositoryMetadata) metadata ).getNature() )
86              {
87                  case RepositoryMetadata.RELEASE_OR_SNAPSHOT:
88                      return Nature.RELEASE_OR_SNAPSHOT;
89                  case RepositoryMetadata.SNAPSHOT:
90                      return Nature.SNAPSHOT;
91                  default:
92                      return Nature.RELEASE;
93              }
94          }
95          else
96          {
97              return Nature.RELEASE;
98          }
99      }
100 
101     @Override
102     public Map<String, String> getProperties()
103     {
104         return copyProperties( null );
105     }
106 }