1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.site.descriptor;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.io.Writer;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.metadata.AbstractArtifactMetadata;
27 import org.apache.maven.artifact.metadata.ArtifactMetadata;
28 import org.apache.maven.artifact.repository.ArtifactRepository;
29 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException;
30 import org.apache.maven.doxia.site.SiteModel;
31 import org.apache.maven.doxia.site.io.xpp3.SiteXpp3Writer;
32 import org.codehaus.plexus.util.xml.XmlStreamWriter;
33
34
35
36
37
38
39
40 public class SiteDescriptorArtifactMetadata extends AbstractArtifactMetadata {
41 private final SiteModel siteModel;
42
43 private final File file;
44
45 public SiteDescriptorArtifactMetadata(Artifact artifact, SiteModel siteModel, File file) {
46 super(artifact);
47
48 this.file = file;
49 this.siteModel = siteModel;
50 }
51
52 @Override
53 public String getRemoteFilename() {
54 return getFilename();
55 }
56
57 @Override
58 public String getLocalFilename(ArtifactRepository repository) {
59 return getFilename();
60 }
61
62 private String getFilename() {
63 return getArtifactId() + "-" + artifact.getVersion() + "-" + file.getName();
64 }
65
66 @Override
67 public void storeInLocalRepository(ArtifactRepository localRepository, ArtifactRepository remoteRepository)
68 throws RepositoryMetadataStoreException {
69 File destination = new File(
70 localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata(this, remoteRepository));
71
72 if (!destination.getParentFile().mkdirs()) {
73 throw new RepositoryMetadataStoreException(
74 "Could not create artifact directory " + destination + " in local repository");
75 }
76
77 try (Writer writer = new XmlStreamWriter(destination)) {
78 new SiteXpp3Writer().write(writer, siteModel);
79 } catch (IOException e) {
80 throw new RepositoryMetadataStoreException("Error saving in local repository", e);
81 }
82 }
83
84 @Override
85 public String toString() {
86 return "site descriptor for " + artifact.getArtifactId() + " " + artifact.getVersion() + " " + file.getName();
87 }
88
89 @Override
90 public boolean storedInArtifactVersionDirectory() {
91 return true;
92 }
93
94 @Override
95 public String getBaseVersion() {
96 return artifact.getBaseVersion();
97 }
98
99 @Override
100 public Object getKey() {
101 return "site descriptor " + artifact.getGroupId() + ":" + artifact.getArtifactId() + " " + file.getName();
102 }
103
104 @Override
105 public void merge(ArtifactMetadata metadata) {
106 SiteDescriptorArtifactMetadata m = (SiteDescriptorArtifactMetadata) metadata;
107 if (!m.file.equals(file)) {
108 throw new IllegalStateException("Cannot add two different pieces of metadata for: " + getKey());
109 }
110 }
111
112 @Override
113 public void merge(org.apache.maven.repository.legacy.metadata.ArtifactMetadata metadata) {
114
115 }
116 }