1 package org.apache.maven.artifact.repository.metadata;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.maven.artifact.metadata.ArtifactMetadata;
25 import org.apache.maven.artifact.repository.ArtifactRepository;
26 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
27 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
28 import org.codehaus.plexus.util.FileUtils;
29 import org.sonatype.aether.RepositoryException;
30 import org.sonatype.aether.metadata.MergeableMetadata;
31
32
33
34
35
36
37
38 public final class MetadataBridge
39 implements MergeableMetadata
40 {
41
42 private ArtifactMetadata metadata;
43
44 private boolean merged;
45
46 public MetadataBridge( ArtifactMetadata metadata )
47 {
48 this.metadata = metadata;
49 }
50
51 public void merge( File current, File result )
52 throws RepositoryException
53 {
54 try
55 {
56 if ( current.exists() )
57 {
58 FileUtils.copyFile( current, result );
59 }
60 ArtifactRepository localRepo = new MetadataRepository( result );
61 metadata.storeInLocalRepository( localRepo, localRepo );
62 merged = true;
63 }
64 catch ( Exception e )
65 {
66 throw new RepositoryException( e.getMessage(), e );
67 }
68 }
69
70 public boolean isMerged()
71 {
72 return merged;
73 }
74
75 public String getGroupId()
76 {
77 return emptify( metadata.getGroupId() );
78 }
79
80 public String getArtifactId()
81 {
82 return metadata.storedInGroupDirectory() ? "" : emptify( metadata.getArtifactId() );
83 }
84
85 public String getVersion()
86 {
87 return metadata.storedInArtifactVersionDirectory() ? emptify( metadata.getBaseVersion() ) : "";
88 }
89
90 public String getType()
91 {
92 return metadata.getRemoteFilename();
93 }
94
95 private String emptify( String string )
96 {
97 return ( string != null ) ? string : "";
98 }
99
100 public File getFile()
101 {
102 return null;
103 }
104
105 public MetadataBridge setFile( File file )
106 {
107 return this;
108 }
109
110 public Nature getNature()
111 {
112 if ( metadata instanceof RepositoryMetadata )
113 {
114 switch ( ( (RepositoryMetadata) metadata ).getNature() )
115 {
116 case RepositoryMetadata.RELEASE_OR_SNAPSHOT:
117 return Nature.RELEASE_OR_SNAPSHOT;
118 case RepositoryMetadata.SNAPSHOT:
119 return Nature.SNAPSHOT;
120 default:
121 return Nature.RELEASE;
122 }
123 }
124 else
125 {
126 return Nature.RELEASE;
127 }
128 }
129
130 @SuppressWarnings( "deprecation" )
131 static class MetadataRepository
132 extends DefaultArtifactRepository
133 {
134
135 private File metadataFile;
136
137 public MetadataRepository( File metadataFile )
138 {
139 super( "local", "", null );
140 this.metadataFile = metadataFile;
141 }
142
143 @Override
144 public String getBasedir()
145 {
146 return metadataFile.getParent();
147 }
148
149 @Override
150 public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
151 {
152 return metadataFile.getName();
153 }
154
155 }
156
157 }