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 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 writer.close();
87 writer = null;
88 }
89 catch ( IOException e )
90 {
91 throw new RepositoryMetadataStoreException( "Error saving in local repository", e );
92 }
93 finally
94 {
95 IOUtil.close( writer );
96 }
97 }
98
99 public String toString()
100 {
101 return "site descriptor for " + artifact.getArtifactId() + " " + artifact.getVersion() + " " + file.getName();
102 }
103
104 public boolean storedInArtifactVersionDirectory()
105 {
106 return true;
107 }
108
109 public String getBaseVersion()
110 {
111 return artifact.getBaseVersion();
112 }
113
114 public Object getKey()
115 {
116 return "site descriptor " + artifact.getGroupId() + ":" + artifact.getArtifactId() + " " + file.getName();
117 }
118
119 public void merge( ArtifactMetadata metadata )
120 {
121 SiteDescriptorArtifactMetadata m = (SiteDescriptorArtifactMetadata) metadata;
122 if ( !m.file.equals( file ) )
123 {
124 throw new IllegalStateException( "Cannot add two different pieces of metadata for: " + getKey() );
125 }
126 }
127
128 public void merge( org.apache.maven.repository.legacy.metadata.ArtifactMetadata metadata )
129 {
130
131 }
132 }