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