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