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