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      public Maven31MetadataBridge( ArtifactMetadata metadata )
39      {
40          this.metadata = metadata;
41      }
42  
43      @Override
44      public String getGroupId()
45      {
46          return emptify( metadata.getGroupId() );
47      }
48  
49      @Override
50      public String getArtifactId()
51      {
52          return metadata.storedInGroupDirectory() ? "" : emptify( metadata.getArtifactId() );
53      }
54  
55      @Override
56      public String getVersion()
57      {
58          return metadata.storedInArtifactVersionDirectory() ? emptify( metadata.getBaseVersion() ) : "";
59      }
60  
61      @Override
62      public String getType()
63      {
64          return metadata.getRemoteFilename();
65      }
66  
67      private String emptify( String string )
68      {
69          return ( string != null ) ? string : "";
70      }
71  
72      @Override
73      public File getFile()
74      {
75          return null;
76      }
77      
78      @Override
79      public Nature getNature()
80      {
81          if ( metadata instanceof RepositoryMetadata )
82          {
83              switch ( ( (RepositoryMetadata) metadata ).getNature() )
84              {
85                  case RepositoryMetadata.RELEASE_OR_SNAPSHOT:
86                      return Nature.RELEASE_OR_SNAPSHOT;
87                  case RepositoryMetadata.SNAPSHOT:
88                      return Nature.SNAPSHOT;
89                  default:
90                      return Nature.RELEASE;
91              }
92          }
93          else
94          {
95              return Nature.RELEASE;
96          }
97      }
98  
99      @Override
100     public Map<String, String> getProperties()
101     {
102         return copyProperties( null );
103     }
104 }