EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.codegen.simucontroller.workflow.jobs]

COVERAGE SUMMARY FOR SOURCE FILE [BuildPluginJarJob.java]

nameclass, %method, %block, %line, %
BuildPluginJarJob.java0%   (0/4)0%   (0/15)0%   (0/202)0%   (0/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BuildPluginJarJob0%   (0/1)0%   (0/9)0%   (0/155)0%   (0/34)
BuildPluginJarJob (AbstractCodeGenerationWorkflowRunConfiguration): void 0%   (0/1)0%   (0/9)0%   (0/4)
addCompiledClasses (URI, JarBuilder): void 0%   (0/1)0%   (0/15)0%   (0/3)
addMetadataFiles (URI, JarBuilder): void 0%   (0/1)0%   (0/12)0%   (0/2)
addModelFiles (URI, JarBuilder): void 0%   (0/1)0%   (0/15)0%   (0/3)
execute (IProgressMonitor): void 0%   (0/1)0%   (0/72)0%   (0/12)
getName (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getResult (): byte [] 0%   (0/1)0%   (0/3)0%   (0/1)
loadBundle (String): byte [] 0%   (0/1)0%   (0/26)0%   (0/7)
rollback (IProgressMonitor): void 0%   (0/1)0%   (0/1)0%   (0/1)
     
class BuildPluginJarJob$10%   (0/1)0%   (0/2)0%   (0/27)0%   (0/3)
BuildPluginJarJob$1 (BuildPluginJarJob): void 0%   (0/1)0%   (0/6)0%   (0/2)
accept (File): boolean 0%   (0/1)0%   (0/21)0%   (0/1)
     
class BuildPluginJarJob$20%   (0/1)0%   (0/2)0%   (0/10)0%   (0/3)
BuildPluginJarJob$2 (BuildPluginJarJob): void 0%   (0/1)0%   (0/6)0%   (0/2)
accept (File, String): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
     
class BuildPluginJarJob$30%   (0/1)0%   (0/2)0%   (0/10)0%   (0/3)
BuildPluginJarJob$3 (BuildPluginJarJob): void 0%   (0/1)0%   (0/6)0%   (0/2)
accept (File, String): boolean 0%   (0/1)0%   (0/4)0%   (0/1)

1package de.uka.ipd.sdq.codegen.simucontroller.workflow.jobs;
2 
3import java.io.File;
4import java.io.FileFilter;
5import java.io.FileInputStream;
6import java.io.FilenameFilter;
7import java.io.IOException;
8import java.net.URI;
9 
10import org.eclipse.core.runtime.IProgressMonitor;
11 
12import de.uka.ipd.sdq.workflow.IJobWithResult;
13import de.uka.ipd.sdq.workflow.exceptions.JobFailedException;
14import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException;
15import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException;
16import de.uka.ipd.sdq.workflow.pcm.configurations.AbstractCodeGenerationWorkflowRunConfiguration;
17import de.uka.ipd.sdq.workflow.pcm.jobs.CreatePluginProjectJob;
18import edu.rice.cs.util.jar.JarBuilder;
19 
20public class BuildPluginJarJob implements IJobWithResult<byte[]> {
21 
22        private byte[] result = null;
23        private AbstractCodeGenerationWorkflowRunConfiguration configuration;
24 
25        public BuildPluginJarJob(AbstractCodeGenerationWorkflowRunConfiguration configuration){
26                super();
27                
28                this.configuration = configuration;
29        }
30        
31        public byte[] getResult() {
32                return result;
33        }
34 
35        public void execute(IProgressMonitor monitor) throws JobFailedException, UserCanceledException {
36                URI location = null;
37                try {
38                        location = CreatePluginProjectJob.getProject(this.configuration.getStoragePluginID()).getLocationURI();
39                        String jarLocation = new File(location).getAbsolutePath() + File.separator + "simucominstance.jar";
40                        JarBuilder builder = new JarBuilder(new File(jarLocation));
41                        addCompiledClasses(location, builder);
42                        addMetadataFiles(location, builder);
43                        addModelFiles(location, builder);
44                        builder.close();
45                        this.result = loadBundle(new File(location).getAbsolutePath() + File.separator + "simucominstance.jar");
46                } catch (IOException e) {
47                        throw new JobFailedException("Compile Plugin failed. Error creating JAR archive.", e);
48                }
49        }
50 
51        /**
52         * @param location
53         * @param builder
54         */
55        private void addMetadataFiles(URI location, JarBuilder builder) {
56                builder.addDirectoryRecursive(new File(location),"",new FileFilter(){
57                        public boolean accept(File pathname) {
58                                return pathname.getName().toUpperCase().contains("META-INF") || pathname.getName().toUpperCase().contains("MANIFEST") || pathname.getName().contains("plugin.xml");
59                        }
60                });
61        }
62 
63    /**
64     * @param location
65     * @param builder
66     */
67    private void addModelFiles(URI location, JarBuilder builder) {
68        builder.addDirectoryRecursive(new File(location).listFiles(new FilenameFilter() {
69            public boolean accept(File dir, String name) {
70                return name.equals("model");
71            }
72        })[0], "model");
73    }
74        
75        /**
76         * @param location
77         * @param builder
78         */
79        private void addCompiledClasses(URI location, JarBuilder builder) {
80                builder.addDirectoryRecursive(new File(location).listFiles(new FilenameFilter(){
81                        public boolean accept(File dir, String name) {
82                                return name.contains("bin");
83                        }
84                })[0], "");
85        }
86 
87        public String getName() {
88                return "Building simulation plugin JAR archive";
89        }
90 
91        public void rollback(IProgressMonitor monitor) throws RollbackFailedException {
92        }
93 
94        private byte[] loadBundle(String location) throws IOException {
95                byte[] result = null;
96                File bundleFile = new File(location);
97                result = new byte[(int) bundleFile.length()];
98                FileInputStream fis = new FileInputStream(bundleFile);
99                fis.read(result);
100                fis.close();
101                return result;
102        }
103        
104}

[all classes][de.uka.ipd.sdq.codegen.simucontroller.workflow.jobs]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov