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  
24  import org.apache.maven.artifact.metadata.ArtifactMetadata;
25  import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
26  import org.sonatype.aether.metadata.Metadata;
27  
28  /**
29   * A MetadataBridge for Maven 3.0
30   * 
31   * @author Robert Scholte
32   *
33   */
34  public class Maven30MetadataBridge implements Metadata
35  {
36      private ArtifactMetadata metadata;
37      
38      private File file;
39  
40      public Maven30MetadataBridge( 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 Maven30MetadataBridge setFile( File file )
82      {
83          this.file = file;
84          return this;
85      }
86  
87      @Override
88      public Nature getNature()
89      {
90          if ( metadata instanceof RepositoryMetadata )
91          {
92              switch ( ( (RepositoryMetadata) metadata ).getNature() )
93              {
94                  case RepositoryMetadata.RELEASE_OR_SNAPSHOT:
95                      return Nature.RELEASE_OR_SNAPSHOT;
96                  case RepositoryMetadata.SNAPSHOT:
97                      return Nature.SNAPSHOT;
98                  default:
99                      return Nature.RELEASE;
100             }
101         }
102         else
103         {
104             return Nature.RELEASE;
105         }
106     }
107 }