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