1 package org.andromda.maven.plugin.cartridge.site;
2
3 import java.io.File;
4 import org.apache.commons.io.FileUtils;
5 import org.apache.commons.io.FilenameUtils;
6 import org.apache.maven.plugin.AbstractMojo;
7 import org.apache.maven.plugin.MojoExecutionException;
8 import org.codehaus.plexus.archiver.ArchiverException;
9 import org.codehaus.plexus.archiver.UnArchiver;
10 import org.codehaus.plexus.archiver.manager.ArchiverManager;
11 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
12
13
14
15
16
17
18
19
20 public abstract class AbstractSiteMojo
21 extends AbstractMojo
22 {
23
24
25
26
27
28
29
30 protected ArchiverManager archiverManager;
31
32
33
34
35
36
37
38
39
40 public void copyFile(File sourceFile, File destFile)
41 throws MojoExecutionException
42 {
43 try
44 {
45 this.getLog().info("Copying " + sourceFile.getAbsolutePath() + " to " + destFile.getAbsolutePath());
46 FileUtils.copyFile(sourceFile, destFile);
47 }
48 catch (Exception e)
49 {
50 throw new MojoExecutionException("Error copying file from " + sourceFile + " to " + destFile, e);
51 }
52 }
53
54
55
56
57
58
59
60
61 protected void unpack(File file, File location)
62 throws MojoExecutionException
63 {
64 final String archiveExt = FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase();
65 try
66 {
67 location.mkdirs();
68 UnArchiver unArchiver;
69 unArchiver = archiverManager.getUnArchiver(archiveExt);
70 unArchiver.setSourceFile(file);
71 unArchiver.setDestDirectory(location);
72 unArchiver.extract();
73 }
74 catch (NoSuchArchiverException e)
75 {
76 throw new MojoExecutionException("Unknown archiver type", e);
77 }
78 catch (ArchiverException e)
79 {
80 e.printStackTrace();
81 throw new MojoExecutionException("Error unpacking file: " +
82 file + " to: " + location + "\r\n" + e.toString(), e);
83 }
84 catch (Exception e)
85 {
86 e.printStackTrace();
87 throw new MojoExecutionException("Error unpacking file: " +
88 file.getAbsolutePath() + " to: " + location + "\r\n" + e.toString(), e);
89 }
90 }
91 }