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.WriterFactory;
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 public String getRemoteFilename() {
53 return getFilename();
54 }
55
56 public String getLocalFilename(ArtifactRepository repository) {
57 return getFilename();
58 }
59
60 private String getFilename() {
61 return getArtifactId() + "-" + artifact.getVersion() + "-" + file.getName();
62 }
63
64 public void storeInLocalRepository(ArtifactRepository localRepository, ArtifactRepository remoteRepository)
65 throws RepositoryMetadataStoreException {
66 File destination = new File(
67 localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata(this, remoteRepository));
68
69 destination.getParentFile().mkdirs();
70
71 try (Writer writer = WriterFactory.newXmlWriter(destination)) {
72 new SiteXpp3Writer().write(writer, siteModel);
73 } catch (IOException e) {
74 throw new RepositoryMetadataStoreException("Error saving in local repository", e);
75 }
76 }
77
78 public String toString() {
79 return "site descriptor for " + artifact.getArtifactId() + " " + artifact.getVersion() + " " + file.getName();
80 }
81
82 public boolean storedInArtifactVersionDirectory() {
83 return true;
84 }
85
86 public String getBaseVersion() {
87 return artifact.getBaseVersion();
88 }
89
90 public Object getKey() {
91 return "site descriptor " + artifact.getGroupId() + ":" + artifact.getArtifactId() + " " + file.getName();
92 }
93
94 public void merge(ArtifactMetadata metadata) {
95 SiteDescriptorArtifactMetadata m = (SiteDescriptorArtifactMetadata) metadata;
96 if (!m.file.equals(file)) {
97 throw new IllegalStateException("Cannot add two different pieces of metadata for: " + getKey());
98 }
99 }
100
101 public void merge(org.apache.maven.repository.legacy.metadata.ArtifactMetadata metadata) {
102
103 }
104 }