1 package org.andromda.maven.plugin.cartridge;
2
3 import java.io.File;
4 import java.io.IOException;
5 import org.andromda.core.common.ExceptionUtils;
6 import org.andromda.maven.plugin.AndroMDAMojo;
7 import org.apache.commons.io.FilenameUtils;
8 import org.apache.maven.plugin.MojoExecutionException;
9 import org.apache.maven.plugin.MojoFailureException;
10 import org.codehaus.plexus.archiver.Archiver;
11 import org.codehaus.plexus.archiver.ArchiverException;
12
13
14
15
16
17
18
19
20
21
22
23
24 public class CartridgeTestUpdaterMojo
25 extends AbstractCartridgeTestMojo
26 {
27
28
29
30 public void execute() throws MojoExecutionException, MojoFailureException
31 {
32 try
33 {
34 this.getLog().info("-----------------------------------------------------------------------------");
35 this.getLog().info(" A n d r o M D A C a r t r i d g e T e s t S u i t e U p d a t e r ");
36 this.getLog().info("-----------------------------------------------------------------------------");
37
38
39 this.changeScopeForTestDependencies();
40
41
42 final AndroMDAMojo andromdaMojo = new AndroMDAMojo();
43 andromdaMojo.setConfigurationUri(this.configurationUri);
44 andromdaMojo.setProject(this.project);
45 andromdaMojo.setSettings(this.settings);
46 andromdaMojo.setPropertyFiles(this.propertyFiles);
47 andromdaMojo.execute();
48
49
50 this.pack(this.actualDirectory, this.expectedOutputArchive);
51
52 }
53 catch (final Throwable throwable)
54 {
55 if (throwable instanceof MojoExecutionException && !this.testFailureIgnore)
56 {
57 throw (MojoExecutionException)throwable;
58 }
59 else if (this.testFailureIgnore)
60 {
61 this.getLog().error("An error occurred while updating cartridge archive '"
62 + this.project.getArtifactId() + '\'', ExceptionUtils.getRootCause(throwable));
63 }
64 else
65 {
66 throw new MojoExecutionException("An error occurred while updating cartridge archive '"
67 + this.project.getArtifactId() + '\'', ExceptionUtils.getRootCause(throwable));
68 }
69 }
70
71 }
72
73
74
75
76
77
78
79
80 protected void pack(final File location,
81 final File file) throws MojoExecutionException
82 {
83 final String archiveExt = FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase();
84 try
85 {
86 final Archiver archiver;
87 archiver = this.archiverManager.getArchiver(archiveExt);
88 archiver.setDestFile(file);
89 archiver.addDirectory(location);
90 archiver.createArchive();
91 }
92 catch (Throwable throwable)
93 {
94 if (this.testFailureIgnore)
95 {
96 this.getLog().error(this.project.getArtifactId() + "Error packing directory: " + location + "to: " + file, throwable);
97 }
98 else if (throwable instanceof IOException || throwable instanceof ArchiverException)
99 {
100 throw new MojoExecutionException("Error packing directory: " + location + "to: " + file, throwable);
101 }
102 }
103 }
104
105 }