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