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 [CompilePluginCodeJob.java]

nameclass, %method, %block, %line, %
CompilePluginCodeJob.java0%   (0/1)0%   (0/11)0%   (0/263)0%   (0/70)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CompilePluginCodeJob0%   (0/1)0%   (0/11)0%   (0/263)0%   (0/70)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
CompilePluginCodeJob (AbstractCodeGenerationWorkflowRunConfiguration): void 0%   (0/1)0%   (0/6)0%   (0/3)
buildProject (IProgressMonitor, IProject): void 0%   (0/1)0%   (0/13)0%   (0/4)
checkForErrors (IProject): void 0%   (0/1)0%   (0/76)0%   (0/19)
createDescription (IProject, IProgressMonitor): void 0%   (0/1)0%   (0/48)0%   (0/12)
execute (IProgressMonitor): void 0%   (0/1)0%   (0/44)0%   (0/11)
getName (): String 0%   (0/1)0%   (0/2)0%   (0/1)
refreshPluginInWorkspace (IProgressMonitor, IProject): void 0%   (0/1)0%   (0/13)0%   (0/4)
rollback (IProgressMonitor): void 0%   (0/1)0%   (0/1)0%   (0/1)
setClasspath (IProject): void 0%   (0/1)0%   (0/13)0%   (0/5)
setProjectToJavaProject (IProject): void 0%   (0/1)0%   (0/39)0%   (0/9)

1package de.uka.ipd.sdq.codegen.simucontroller.workflow.jobs;
2 
3import org.eclipse.core.internal.events.BuildCommand;
4import org.eclipse.core.resources.ICommand;
5import org.eclipse.core.resources.IMarker;
6import org.eclipse.core.resources.IProject;
7import org.eclipse.core.resources.IProjectDescription;
8import org.eclipse.core.resources.IResource;
9import org.eclipse.core.resources.IncrementalProjectBuilder;
10import org.eclipse.core.resources.ResourcesPlugin;
11import org.eclipse.core.runtime.CoreException;
12import org.eclipse.core.runtime.IPath;
13import org.eclipse.core.runtime.IProgressMonitor;
14import org.eclipse.jdt.core.IClasspathEntry;
15import org.eclipse.jdt.core.IJavaProject;
16import org.eclipse.jdt.core.JavaCore;
17import org.eclipse.jdt.core.JavaModelException;
18import org.eclipse.jdt.launching.JavaRuntime;
19import org.eclipse.pde.core.plugin.PluginRegistry;
20import org.eclipse.pde.internal.core.ClasspathComputer;
21import org.eclipse.pde.internal.core.natures.PDE;
22 
23import de.uka.ipd.sdq.workflow.IJob;
24import de.uka.ipd.sdq.workflow.exceptions.JobFailedException;
25import de.uka.ipd.sdq.workflow.pcm.configurations.AbstractCodeGenerationWorkflowRunConfiguration;
26import de.uka.ipd.sdq.workflow.pcm.jobs.CreatePluginProjectJob;
27 
28@SuppressWarnings("restriction")
29public class CompilePluginCodeJob implements IJob {
30 
31        private AbstractCodeGenerationWorkflowRunConfiguration configuration;
32 
33        public CompilePluginCodeJob(
34                        AbstractCodeGenerationWorkflowRunConfiguration configuration) {
35                super();
36 
37                this.configuration = configuration;
38        }
39 
40        public void execute(IProgressMonitor monitor) throws JobFailedException {
41                assert (this.configuration != null);
42 
43                IProject project = CreatePluginProjectJob.getProject(this.configuration
44                                .getStoragePluginID());
45                assert (project != null);
46 
47                // create description
48                createDescription(project, monitor);
49 
50                // create JavaProject
51                setProjectToJavaProject(project);
52 
53                // set Plug-In class path
54                setClasspath(project);
55 
56                refreshPluginInWorkspace(monitor, project);
57                
58                buildProject(monitor, project);
59                
60                checkForErrors(project);
61        }
62 
63        /* (non-Javadoc)
64         * @See org.eclipse.pde.internal.ui.wizards.plugin.ClasspathComputer.setClasspath(IProject)
65         */
66        private void setClasspath(IProject project) throws JobFailedException {
67                try {
68                        ClasspathComputer.setClasspath(project, PluginRegistry
69                                        .findModel(project));
70                } catch (CoreException e) {
71                        throw new JobFailedException("Failed to set JDT classpath",e);
72                }
73        }
74 
75        /**
76         * Create the Java-Project from IProject and set "src", "bin" folder to
77         * classpath
78         */
79        private void setProjectToJavaProject(IProject project)
80                        throws JobFailedException {
81                // create class path entry
82                IJavaProject javaProject = JavaCore.create(project);
83                IPath srcPath = javaProject.getPath().append("src");
84                IPath binPath = javaProject.getPath().append("bin");
85                IClasspathEntry[] buildPath = { JavaCore.newSourceEntry(srcPath),
86                                JavaRuntime.getDefaultJREContainerEntry() };
87                try {
88                        javaProject.setRawClasspath(buildPath, binPath, null);
89                } catch (JavaModelException e) {
90                        throw new JobFailedException("Failed setting up JDT project",e);
91                }
92        }
93 
94        /**
95         * Create a project description and set the JavaCore.NATURE_ID and
96         * PDE.PLUGIN_NATURE
97         */
98        private void createDescription(IProject project, IProgressMonitor monitor)
99                        throws JobFailedException {
100                IProjectDescription description = ResourcesPlugin.getWorkspace()
101                                .newProjectDescription(project.getName());
102                description.setNatureIds(new String[] { JavaCore.NATURE_ID,
103                                PDE.PLUGIN_NATURE });
104                description.setLocation(null);
105                // set java builders
106                ICommand command = description.newCommand();
107                command.setBuilderName(JavaCore.BUILDER_ID);
108                description.setBuildSpec(new BuildCommand[] { (BuildCommand) command });
109                try {
110                        project.setDescription(description, monitor);
111                } catch (CoreException e) {
112                        throw new JobFailedException("Failed setting Java and PDE nature and builders",e);
113                }
114        }
115 
116        /**
117         * @param monitor
118         * @param project
119         * @throws JobFailedException
120         */
121        private void buildProject(IProgressMonitor monitor, IProject project)
122                        throws JobFailedException {
123                try {
124                        project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
125                } catch (Exception e) {
126                        throw new JobFailedException("Building plugin project failed", e);
127                }
128        }
129 
130        /**
131         * @param monitor
132         * @param project
133         * @throws JobFailedException
134         */
135        private void refreshPluginInWorkspace(IProgressMonitor monitor,
136                        IProject project) throws JobFailedException {
137                try {
138                        project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
139                } catch (Exception e) {
140                        throw new JobFailedException("Refreshing plugin project failed", e);
141                }
142        }
143 
144        /**
145         * @param project
146         * @throws JobFailedException
147         */
148        private void checkForErrors(IProject project) throws JobFailedException {
149                try {
150                        if (project.findMarkers(IMarker.PROBLEM, true,
151                                        IResource.DEPTH_INFINITE).length > 0) {
152                                boolean failed = false;
153                                IMarker[] markers = project.findMarkers(IMarker.PROBLEM, true,
154                                                IResource.DEPTH_INFINITE);
155                                String errorList = "";
156                                for (IMarker marker : markers) {
157                                        if (((Integer) marker.getAttribute(IMarker.SEVERITY)) == IMarker.SEVERITY_ERROR) {
158                                                errorList += marker.getAttribute(IMarker.MESSAGE)
159                                                                + "\n";
160                                                failed = true;
161                                        }
162                                }
163                                if (failed)
164                                        throw new JobFailedException(
165                                                        "Unable to build the simulation plugin. Failure Messages: "
166                                                                        + errorList);
167                        }
168                } catch (CoreException e) {
169                        throw new JobFailedException(
170                                        "Compile Plugin failed. Error finding project markers.", e);
171                }
172        }
173 
174        public String getName() {
175                return "Compile Plugin Code";
176        }
177 
178        public void rollback(IProgressMonitor monitor) {
179                // do nothing
180        }
181}

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