1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.exceptions;
17
18 import java.io.BufferedOutputStream;
19 import java.io.File;
20 import java.io.FileOutputStream;
21 import java.io.IOException;
22 import java.io.OutputStream;
23 import java.util.Properties;
24
25 import org.apache.commons.io.IOUtils;
26 import org.apache.maven.archiver.MavenArchiveConfiguration;
27 import org.apache.maven.archiver.MavenArchiver;
28 import org.apache.maven.plugin.MojoExecutionException;
29 import org.apache.maven.plugin.MojoFailureException;
30 import org.apache.maven.project.DefaultMavenProjectHelper;
31 import org.apache.maven.project.MavenProjectHelper;
32 import org.codehaus.plexus.archiver.jar.JarArchiver;
33
34 import de.smartics.maven.io.MojoIoUtils;
35
36
37
38
39
40
41
42
43
44 public class ExportSdocCodeMojo extends AbstractSdocCodeMojo
45 {
46
47
48
49
50
51
52
53
54
55
56
57
58
59 private JarArchiver sdocJarArchiver;
60
61
62
63
64
65
66
67
68 private final MavenArchiveConfiguration archive =
69 new MavenArchiveConfiguration();
70
71
72
73
74
75
76
77
78 private boolean attach;
79
80
81
82
83
84
85
86 private String classifier;
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 @Override
104 protected void handleGeneratedDocuments() throws MojoExecutionException,
105 MojoFailureException
106 {
107 addMetaData();
108 attachArtifact();
109 }
110
111 private void addMetaData() throws MojoExecutionException
112 {
113 final File metaInfDir = new File(output, "META-INF");
114 MojoIoUtils.provideMojoDirectory(metaInfDir);
115
116 final Properties properties = new Properties();
117 properties.setProperty("res.type", "instances");
118 properties.setProperty("res.export.groupId", project.getGroupId());
119 properties.setProperty("res.export.artifactId", project.getArtifactId());
120 properties.setProperty("res.export.version", project.getVersion());
121 properties.setProperty("res.namespace",
122 "http://www.smartics.de/project/process/implementation/appcode");
123 properties.setProperty("res.instances", "process/implementation/appcode");
124
125 final File propertiesFile =
126 new File(metaInfDir, "projectdoc-resource.properties");
127 OutputStream out = null;
128 try
129 {
130 out = new BufferedOutputStream(new FileOutputStream(propertiesFile));
131 properties.store(out,
132 "Export of document instances for projectdoc enabled projects.");
133 }
134 catch (final IOException e)
135 {
136 throw new MojoExecutionException(
137 "Cannot create properties file for sdoc export.", e);
138 }
139 finally
140 {
141 IOUtils.closeQuietly(out);
142 }
143
144 }
145
146 private void attachArtifact() throws MojoExecutionException
147 {
148 final String finalName =
149 project.getBuild().getFinalName() + '-' + classifier + ".jar";
150 final File sdocJarFile =
151 new File(project.getBuild().getDirectory(), finalName);
152 final MavenProjectHelper helper = new DefaultMavenProjectHelper();
153 final MavenArchiver clientArchiver = new MavenArchiver();
154 clientArchiver.setArchiver(sdocJarArchiver);
155 clientArchiver.setOutputFile(sdocJarFile);
156
157 try
158 {
159 clientArchiver.getArchiver().addDirectory(output);
160 clientArchiver.createArchive(project, archive);
161 if (this.attach)
162 {
163 helper.attachArtifact(project, sdocJarFile, classifier);
164 }
165 }
166 catch (final Exception e)
167 {
168 throw new MojoExecutionException(
169 "There was a problem creating the sdoc archive: " + e.getMessage(), e);
170 }
171 }
172
173
174
175 }