EMMA Coverage Report (generated Wed Dec 16 17:19:59 CET 2009)
[all classes][org.sourceforge.xradar.ant]

COVERAGE SUMMARY FOR SOURCE FILE [RadarLoaderTask.java]

nameclass, %method, %block, %line, %
RadarLoaderTask.java0%   (0/1)0%   (0/10)0%   (0/151)0%   (0/42)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RadarLoaderTask0%   (0/1)0%   (0/10)0%   (0/151)0%   (0/42)
RadarLoaderTask (): void 0%   (0/1)0%   (0/3)0%   (0/1)
execute (): void 0%   (0/1)0%   (0/9)0%   (0/4)
extracting (URL): void 0%   (0/1)0%   (0/38)0%   (0/10)
getResource (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getTarget (): String 0%   (0/1)0%   (0/3)0%   (0/1)
main (String []): void 0%   (0/1)0%   (0/13)0%   (0/5)
registerURLResolver (): void 0%   (0/1)0%   (0/19)0%   (0/6)
setResource (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
setTarget (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
validate (): URL 0%   (0/1)0%   (0/55)0%   (0/10)

1/**
2 * BSD-style license; for more info see http://xradar.sourceforge.net/license.html
3 */
4package org.sourceforge.xradar.ant;
5 
6import java.io.File;
7import java.io.FileNotFoundException;
8import java.io.FileOutputStream;
9import java.io.IOException;
10import java.net.MalformedURLException;
11import java.net.URL;
12 
13import org.apache.tools.ant.BuildException;
14import org.sourceforge.xradar.resolver.XRadarStreamHandlerFactory;
15 
16/**
17 * 
18 * @author Romain PELISSE, belaran@gmail.com
19 *
20 */
21public class RadarLoaderTask extends AbstractXRadarAntTask {
22 
23        private String resource;
24        private String target;
25 
26        /**
27         * @return the resourceName
28         */
29        public String getResource() {
30                return resource;
31        }
32 
33        /**
34         * @param resource the resourceName to set
35         */
36        public void setResource(String resource) {
37                this.resource = resource;
38        }
39 
40        @Override
41        public void execute() throws BuildException {
42                // Registering the new resolver to handle xradar protocol
43                registerURLResolver();
44                URL resourceURL = validate();
45                // Extracting the resource from the URL provided
46                extracting(resourceURL);
47        }
48 
49        private void extracting(URL resourceURL) {
50                LoaderHelper helper = new LoaderHelper(super.isOnline());
51                try {
52                        helper.extractFrom(resourceURL.openStream(), new FileOutputStream(new File(target)));
53                } catch (FileNotFoundException e) {
54                        throw new BuildException(e);
55                } catch (IOException e) {
56                        throw new BuildException(e);
57                } catch (Exception e) {
58                        throw new BuildException(e);
59                }
60        }
61 
62        private void registerURLResolver() {
63                // FIXME: This exception catching is ugly !!!!!!
64                // FIXME: Should be moved inside AbstractProcess
65 
66                try
67                {
68                        // Adding to JVM our own URL resolver to resolve
69                        // the 'xradar' protocol in stylesheet
70                        URL.setURLStreamHandlerFactory(new XRadarStreamHandlerFactory());
71                }
72                catch ( java.lang.Error e)
73                {
74                        //FIXME: this so ugly, it actually requires an other fixme !
75                        // Only if we run into this error we should not take care of the exception
76                        if ( ! "class java.lang.Error".equals(e.getClass()) &&
77                                 ! "factory already defined".equals(e.getMessage())        )
78                        {
79                                throw e;
80                        }
81                }
82 
83        }
84 
85        private URL validate() throws BuildException {
86                if ( this.resource == null || "".equals(this.resource) )
87                        throw new BuildException("resourceName is a required attribute");
88                if ( this.target == null || "".equals(this.target) )
89                        throw new BuildException("target is a required attribute");
90                else
91                {
92                        File file = new File(this.target);
93                        if ( file.exists() && ! file.canWrite() )
94                                throw new BuildException("target attribute value must be a writable.");
95                }
96                try {
97                        return new URL(this.resource);
98                } catch (MalformedURLException e){
99                        throw new BuildException(e);
100                }
101        }
102 
103        /**
104         * Very small test...
105         * @param args
106         */
107        public static void main(String[] args) {
108                RadarLoaderTask task = new RadarLoaderTask();
109                task.setResource("xradar://resources/tools.xml");
110                task.setTarget("target/tools.xml");
111                task.execute();
112        }
113 
114        /**
115         * @return the target
116         */
117        public String getTarget() {
118                return target;
119        }
120 
121        /**
122         * @param target the target to set
123         */
124        public void setTarget(String target) {
125                this.target = target;
126        }
127 
128}

[all classes][org.sourceforge.xradar.ant]
EMMA 2.0.5312 (C) Vladimir Roubtsov