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