~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to rpm/org.eclipse.linuxtools.rpm.rpmlint/src/org/eclipse/linuxtools/internal/rpm/rpmlint/builder/RpmlintNature.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2009 Red Hat, Inc.
 
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
 *     Red Hat - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.linuxtools.internal.rpm.rpmlint.builder;
 
12
 
 
13
import org.eclipse.core.resources.ICommand;
 
14
import org.eclipse.core.resources.IProject;
 
15
import org.eclipse.core.resources.IProjectDescription;
 
16
import org.eclipse.core.resources.IProjectNature;
 
17
import org.eclipse.core.runtime.CoreException;
 
18
 
 
19
public class RpmlintNature implements IProjectNature {
 
20
 
 
21
        /**
 
22
         * ID of this project nature
 
23
         */
 
24
        public static final String NATURE_ID = "org.eclipse.linuxtools.rpm.rpmlint.rpmlintNature"; //$NON-NLS-1$
 
25
 
 
26
        private IProject project;
 
27
 
 
28
        /**  
 
29
         * @see org.eclipse.core.resources.IProjectNature#configure()
 
30
         */
 
31
        public void configure() throws CoreException {
 
32
                IProjectDescription desc = project.getDescription();
 
33
                ICommand[] commands = desc.getBuildSpec();
 
34
                for (ICommand command : commands) {
 
35
                        if (command.getBuilderName().equals(RpmlintBuilder.BUILDER_ID)) {
 
36
                                return;
 
37
                        }
 
38
                }
 
39
                ICommand[] newCommands = new ICommand[commands.length + 1];
 
40
                System.arraycopy(commands, 0, newCommands, 0, commands.length);
 
41
                ICommand command = desc.newCommand();
 
42
                command.setBuilderName(RpmlintBuilder.BUILDER_ID);
 
43
                newCommands[newCommands.length - 1] = command;
 
44
                desc.setBuildSpec(newCommands);
 
45
                project.setDescription(desc, null);
 
46
        }
 
47
 
 
48
        /**
 
49
         * @see org.eclipse.core.resources.IProjectNature#deconfigure()
 
50
         */
 
51
        public void deconfigure() throws CoreException {
 
52
                IProjectDescription description = getProject().getDescription();
 
53
                ICommand[] commands = description.getBuildSpec();
 
54
                for (int i = 0; i < commands.length; ++i) {
 
55
                        if (commands[i].getBuilderName().equals(RpmlintBuilder.BUILDER_ID)) {
 
56
                                ICommand[] newCommands = new ICommand[commands.length - 1];
 
57
                                System.arraycopy(commands, 0, newCommands, 0, i);
 
58
                                System.arraycopy(commands, i + 1, newCommands, i,
 
59
                                                commands.length - i - 1);
 
60
                                description.setBuildSpec(newCommands);
 
61
                                // Remove rpmlint marks on all specfiles into the project.
 
62
                                project.accept(new RpmlintMarkerRemoveVisitor());
 
63
                                return;
 
64
                        }
 
65
                }
 
66
        }
 
67
 
 
68
        /**
 
69
         * @see org.eclipse.core.resources.IProjectNature#getProject()
 
70
         */
 
71
        public IProject getProject() {
 
72
                return project;
 
73
        }
 
74
 
 
75
        /**
 
76
         * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
 
77
         */
 
78
        public void setProject(IProject project) {
 
79
                this.project = project;
 
80
        }
 
81
 
 
82
}