EMMA Coverage Report (generated Thu Nov 26 15:54:18 CST 2009)
[all classes][org.eclipse.pde.api.tools.internal.natures]

COVERAGE SUMMARY FOR SOURCE FILE [ApiToolProjectNature.java]

nameclass, %method, %block, %line, %
ApiToolProjectNature.java100% (1/1)86%  (6/7)62%  (90/144)68%  (25.9/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ApiToolProjectNature100% (1/1)86%  (6/7)62%  (90/144)68%  (25.9/38)
getProject (): IProject 0%   (0/1)0%   (0/3)0%   (0/1)
removeFromBuildSpec (String): void 100% (1/1)26%  (15/57)36%  (3.9/11)
addToBuildSpec (String): void 100% (1/1)87%  (60/69)79%  (15/19)
ApiToolProjectNature (): void 100% (1/1)100% (3/3)100% (1/1)
configure (): void 100% (1/1)100% (4/4)100% (2/2)
deconfigure (): void 100% (1/1)100% (4/4)100% (2/2)
setProject (IProject): void 100% (1/1)100% (4/4)100% (2/2)

1/*******************************************************************************
2 * Copyright (c) 2007, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.pde.api.tools.internal.natures;
12 
13import org.eclipse.core.resources.ICommand;
14import org.eclipse.core.resources.IProject;
15import org.eclipse.core.resources.IProjectDescription;
16import org.eclipse.core.resources.IProjectNature;
17import org.eclipse.core.runtime.CoreException;
18import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
19 
20public class ApiToolProjectNature implements IProjectNature {
21        
22        IProject project;
23 
24        /**
25         * Add the Api plugin builder in the project build spec
26         */
27        public void configure() throws CoreException {
28                addToBuildSpec(ApiPlugin.BUILDER_ID);
29        }
30 
31        /**
32         * Remove the Api plugin builder from the project build spec
33         */
34        public void deconfigure() throws CoreException {
35                removeFromBuildSpec(ApiPlugin.BUILDER_ID);
36        }
37 
38        /**
39         * Retrieve the current project
40         * 
41         * @return the current project
42         */
43        public IProject getProject() {
44                return this.project;
45        }
46 
47        /**
48         * Sset the current project
49         */
50        public void setProject(IProject project) {
51                this.project = project;
52        }
53 
54        /**
55         * Adds a builder to the build spec for the given project.
56         */
57        protected void addToBuildSpec(String builderID) throws CoreException {
58                IProjectDescription description = this.project.getDescription();
59                ICommand[] oldBuildSpec = description.getBuildSpec();
60                int oldApiCommandIndex = -1;
61                int length = oldBuildSpec.length;
62                loop: for (int i = 0; i < length; ++i) {
63                        if (oldBuildSpec[i].getBuilderName().equals(builderID)) {
64                                oldApiCommandIndex = i;
65                                break loop;
66                        }
67                }
68                ICommand[] newCommands;
69 
70                ICommand newCommand = description.newCommand();
71                newCommand.setBuilderName(builderID);
72 
73                if (oldApiCommandIndex == -1) {
74                        // Add a API build spec after all existing builders
75                        newCommands = new ICommand[length + 1];
76                        System.arraycopy(oldBuildSpec, 0, newCommands, 0, length);
77                        newCommands[length] = newCommand;
78                } else {
79                        oldBuildSpec[oldApiCommandIndex] = newCommand;
80                        newCommands = oldBuildSpec;
81                }
82 
83                // Commit the spec change into the project
84                description.setBuildSpec(newCommands);
85                this.project.setDescription(description, null);
86        }
87        
88        /**
89         * Removes the given builder from the build spec for the given project.
90         */
91        protected void removeFromBuildSpec(String builderID) throws CoreException {
92                IProjectDescription description = this.project.getDescription();
93                ICommand[] commands = description.getBuildSpec();
94                for (int i = 0; i < commands.length; ++i) {
95                        if (commands[i].getBuilderName().equals(builderID)) {
96                                ICommand[] newCommands = new ICommand[commands.length - 1];
97                                System.arraycopy(commands, 0, newCommands, 0, i);
98                                System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
99                                description.setBuildSpec(newCommands);
100                                this.project.setDescription(description, null);
101                                return;
102                        }
103                }
104        }
105}

[all classes][org.eclipse.pde.api.tools.internal.natures]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov