EMMA Coverage Report (generated Mon Mar 20 21:34:30 PST 2006)
[all classes][com.moesol.doc]

COVERAGE SUMMARY FOR SOURCE FILE [ExamplesXmlTask.java]

nameclass, %method, %block, %line, %
ExamplesXmlTask.java0%   (0/1)0%   (0/10)0%   (0/206)0%   (0/52)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ExamplesXmlTask0%   (0/1)0%   (0/10)0%   (0/206)0%   (0/52)
ExamplesXmlTask (): void 0%   (0/1)0%   (0/13)0%   (0/3)
addFileset (FileSet): void 0%   (0/1)0%   (0/6)0%   (0/2)
doFiles (OutputStream, File, String []): void 0%   (0/1)0%   (0/9)0%   (0/3)
doFilesets (OutputStream): void 0%   (0/1)0%   (0/32)0%   (0/6)
execute (): void 0%   (0/1)0%   (0/50)0%   (0/16)
needsGeneration (): boolean 0%   (0/1)0%   (0/35)0%   (0/7)
needsGeneration (File): boolean 0%   (0/1)0%   (0/15)0%   (0/3)
needsGeneration (File, String []): boolean 0%   (0/1)0%   (0/24)0%   (0/5)
setTofile (File): void 0%   (0/1)0%   (0/4)0%   (0/2)
validateAttributes (): void 0%   (0/1)0%   (0/18)0%   (0/5)

1/*
2 * $Id: ExamplesXmlTask.java,v 1.2 2005/08/05 20:23:02 adamp Exp $
3 *
4 * (c) Copyright, Moebius Solutions, Inc., 2004
5 *
6 *                       All Rights Reserved
7 *
8 * This material may be reproduced by or for the U. S. Government
9 * pursuant to the copyright license under the clause at
10 * DFARS 252.227-7014 (OCT 2001).
11 */
12package com.moesol.doc;
13 
14import java.io.File;
15import java.io.FileOutputStream;
16import java.io.IOException;
17import java.io.OutputStream;
18import java.util.ArrayList;
19import java.util.List;
20 
21import org.apache.tools.ant.BuildException;
22import org.apache.tools.ant.DirectoryScanner;
23import org.apache.tools.ant.Task;
24import org.apache.tools.ant.types.FileSet;
25 
26/**
27 * @author Hastings
28 */
29public class ExamplesXmlTask extends Task {
30        private List filesets = new ArrayList();
31        private File m_toFile;
32        private ExamplesXmlBuilder m_builder = new ExamplesXmlBuilder();
33 
34        public void addFileset(FileSet set) {
35                filesets.add(set);
36        }
37        public void setTofile(File f) {
38                m_toFile = f;
39        }
40        public void execute() throws BuildException {
41                validateAttributes();
42                if (!needsGeneration()) {
43                        return;
44                }
45                
46                try {
47                        FileOutputStream tofile = new FileOutputStream(m_toFile);
48                        try {
49                                m_builder.setOut(tofile);
50                                m_builder.startRoot();
51                                doFilesets(tofile);
52                        } finally {
53                                m_builder.endRoot();
54                                m_builder.setOut(null);
55                                tofile.close();
56                        }
57                } catch (IOException e) {
58                        throw new BuildException("Failed to xml'ize", e, getLocation());
59                }
60        }
61 
62        protected void validateAttributes() throws BuildException {
63        if (filesets.size() == 0) {
64            throw new BuildException("Specify at least one source ");
65        }
66        if (m_toFile == null) {
67            throw new BuildException("Specify a destination");
68        }
69        }
70        private boolean needsGeneration() {
71                for (int i = 0; i < filesets.size(); i++) {
72                        FileSet fs = (FileSet)filesets.get(i);
73                        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
74                        ds.scan();
75                        if (needsGeneration(fs.getDir(getProject()), ds.getIncludedFiles())) {
76                                return true;
77                        }
78                }
79                return false;
80        }
81        private boolean needsGeneration(File dir, String[] includedFiles) {
82                for (int i = 0; i < includedFiles.length; i++) {
83                        File full_path = new File(dir, includedFiles[i]);
84                        if (needsGeneration(full_path)) {
85                                return true;
86                        }
87                }
88                return false;
89        }
90        private boolean needsGeneration(File full_path) {
91                if (  !m_toFile.exists() 
92                        || m_toFile.lastModified() < full_path.lastModified()) {
93                        return true;
94                }
95                return false;
96        }
97        
98        private void doFilesets(OutputStream tofile) throws IOException {
99                for (int i = 0; i < filesets.size(); i++) {
100                        FileSet fs = (FileSet)filesets.get(i);
101                        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
102                        ds.scan();
103                        doFiles(tofile, fs.getDir(getProject()), ds.getIncludedFiles());
104                }
105        }
106        
107        private void doFiles(OutputStream tofile, File dir, String[] files) throws IOException {
108                m_builder.setDir(dir);
109                m_builder.doFiles(files);
110        }
111}

[all classes][com.moesol.doc]
EMMA 2.0.5312 (C) Vladimir Roubtsov