View Javadoc

1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    *      http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  package gr.abiss.mvn.plugins.jstools;
15  
16  import java.io.File;
17  import java.io.FileInputStream;
18  import java.io.FileNotFoundException;
19  import java.io.FileOutputStream;
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.io.OutputStream;
23  import java.nio.channels.FileChannel;
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.Locale;
27  import org.apache.commons.io.IOUtils;
28  import org.apache.maven.reporting.MavenReportException;
29  import org.codehaus.plexus.archiver.ArchiverException;
30  import org.codehaus.plexus.archiver.UnArchiver;
31  import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
32  import org.mozilla.javascript.tools.shell.Main;
33  
34  /***
35   * Goal to generate an unit testing report based on ECMAUnit (<strong>not available yet</strong>)
36   * 
37   * @goal ecmaunit
38   * @version $Id$
39   * @author manos
40   * 
41   */
42  public class EcmaUnitMojo extends AbstractBaseJstoolsReport {
43  
44  	/***
45  	 * A path pointing to a the desired ECMAUnit directory (e.g.
46  	 * /home/username/stuff/ecmaunit). If no value is provided the
47  	 * plugin wil use its own internal version.
48  	 * 
49  	 * @parameter
50  	 */
51  	private String ecmaunitHome;
52  
53  	/***
54  	 * Generate an ECMAUnit based unit tests page
55  	 * @see gr.abiss.mvn.plugins.jstools.AbstractBaseJstoolsReport#doGenerateReport(java.util.Locale)
56  	 */
57  	public void doGenerateReport(Locale defaultLocale) throws MavenReportException {
58  		
59  	}
60  
61  	/***
62  	 * Setup the plugin's internal ECMAUnit version if no other is provided
63  	 * 
64  	 * @param defaultLocale
65  	 * @throws MavenReportException
66  	 */
67  	protected void setUp(Locale defaultLocale) throws MavenReportException {
68  		if (this.ecmaunitHome == null || this.ecmaunitHome.trim().length() == 0) {
69  			String ecmaunitDistFilename = this.getBundle(defaultLocale).getString(
70  					"jsdoc.dist.filename");
71  			this.ecmaunitHome = this.buildDir + "/ecmaunit_run/" + ecmaunitDistFilename;
72  			String ecmaunitJar = this.baseDir + "/target/" + ecmaunitDistFilename
73  					+ ".zip";
74  			// copy the internal jsdoc distribution archive to target/
75  			try {
76  				InputStream input = this.getClass().getResourceAsStream(
77  						"/" + ecmaunitDistFilename + ".zip");
78  				OutputStream output = new FileOutputStream(ecmaunitJar);
79  				IOUtils.copy(input, output);
80  				input.close();
81  				output.close();
82  			} catch (FileNotFoundException fe) {
83  				throw new MavenReportException("Cannot find "
84  						+ ecmaunitDistFilename + ".zip" + " in classpath", fe);
85  			} catch (IOException ioe) {
86  				throw new MavenReportException("Error copying "
87  						+ ecmaunitDistFilename + ".zip" + " to target dir", ioe);
88  			}
89  			// unpack the ecmaunit distribution archive
90  			File jarFile = new File(ecmaunitJar);
91  			try {
92  				UnArchiver unArchiver = this.archiverManager
93  						.getUnArchiver(jarFile);
94  				unArchiver.setSourceFile(jarFile);
95  				File destDir = new File(this.buildDir+"/site").getParentFile();
96  				destDir.mkdirs();
97  				unArchiver.setDestDirectory(destDir);
98  				unArchiver.extract();
99  			} catch (NoSuchArchiverException ae) {
100 				throw new MavenReportException("Unknown archiver type", ae);
101 			} catch (ArchiverException ae) {
102 				throw new MavenReportException("Error unpacking " + jarFile
103 						+ ": " + ae.toString(), ae);
104 			}
105 		}
106 	}
107 
108 	/***
109 	 * @see org.apache.maven.reporting.AbstractMavenReport#isExternalReport()
110 	 */
111 	public boolean isExternalReport() {
112 		return false;
113 	}
114 
115 	/***
116 	 * @see gr.abiss.mvn.plugins.jstools.AbstractBaseJstoolsReport#getBundleKey()
117 	 */
118 	public String getBundleKey() {
119 		return "ecmaunit";
120 	}
121 
122 
123 	/***
124 	 * Does nothing
125 	 * @see gr.abiss.mvn.plugins.jstools.AbstractBaseJstoolsReport#tearDown(java.util.Locale)
126 	 */
127 	protected void tearDown(Locale defaultLocale) throws MavenReportException {
128 		// do nothing
129 		
130 	}
131 }