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