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
9
* Red Hat - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.linuxtools.internal.rpm.rpmlint.builder;
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;
19
public class RpmlintNature implements IProjectNature {
22
* ID of this project nature
24
public static final String NATURE_ID = "org.eclipse.linuxtools.rpm.rpmlint.rpmlintNature"; //$NON-NLS-1$
26
private IProject project;
29
* @see org.eclipse.core.resources.IProjectNature#configure()
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)) {
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);
49
* @see org.eclipse.core.resources.IProjectNature#deconfigure()
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());
69
* @see org.eclipse.core.resources.IProjectNature#getProject()
71
public IProject getProject() {
76
* @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
78
public void setProject(IProject project) {
79
this.project = project;