| 1 | /** |
| 2 | * BSD-style license; for more info see http://xradar.sourceforge.net/license.html |
| 3 | */ |
| 4 | package org.sourceforge.xradar.statics; |
| 5 | |
| 6 | import java.io.File; |
| 7 | import java.io.FileWriter; |
| 8 | import java.io.IOException; |
| 9 | import java.io.PrintWriter; |
| 10 | import java.util.logging.Level; |
| 11 | import java.util.logging.Logger; |
| 12 | |
| 13 | import jdepend.xmlui.JDepend; |
| 14 | |
| 15 | import org.sourceforge.xradar.XRadarException; |
| 16 | |
| 17 | /** |
| 18 | * <p>Create the backbone file for xradar. Basicly, an XML file that |
| 19 | * depicts the package/classes structure for the project.</p> |
| 20 | * |
| 21 | * <p>For the moment, XRadar depends on JDepend to do this, but |
| 22 | * at some point we may change this implementation to a custom |
| 23 | * backbone file.</p> |
| 24 | * |
| 25 | * @author Romain PELISSE, belaran@gmail.com |
| 26 | * @author Nicolas DORDET, |
| 27 | * |
| 28 | */ |
| 29 | public class MergeFileBackboneCreator { |
| 30 | |
| 31 | /** |
| 32 | * <p>check if the classes are presents |
| 33 | * if there are in the right directory, run jdepend |
| 34 | * if not, exit.</p> |
| 35 | * |
| 36 | * @param classDirectory |
| 37 | * @throws XRadarException |
| 38 | */ |
| 39 | public static boolean createBackBoneFile(File classes, File reportFile) throws XRadarException |
| 40 | { |
| 41 | Logger logger = Logger.getLogger(MergeFileBackboneCreator.class.getSimpleName()); |
| 42 | boolean status = true; |
| 43 | if (classes.exists()) |
| 44 | { |
| 45 | logger.log(Level.INFO,"Supplied directory classes," + classes.getAbsolutePath() + " have been found"); |
| 46 | // using jdepend as an API |
| 47 | JDepend jdepend = new JDepend(); |
| 48 | try |
| 49 | { |
| 50 | jdepend.addDirectory(classes.getAbsolutePath()); // jdepend.addDirectory(name) TODO: Explore this 'addDirectory to have a multiproject support ? |
| 51 | jdepend.setWriter(new PrintWriter( new FileWriter(reportFile))); |
| 52 | } |
| 53 | catch (IOException e) |
| 54 | { |
| 55 | throw new XRadarException("Unable to run JDepend :",e); |
| 56 | } |
| 57 | logger.log(Level.INFO,"JDepend Analyze starting ..."); |
| 58 | jdepend.analyze(); |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | logger.log(Level.INFO,"Classes have not been found in " + classes + ", xradar will not do the audit"); |
| 63 | logger.log(Level.INFO,"make a mvn compile in order to have .class file or change classDirectory parameter"); |
| 64 | status = false; |
| 65 | } |
| 66 | return status; |
| 67 | } |
| 68 | } |