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