001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2007-2010 ADEQUATE SYSTEMS SARL
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.builder;
022
023 import java.util.HashMap;
024 import java.util.Map;
025
026 import org.eclipse.core.resources.IProject;
027 import org.eclipse.core.resources.IncrementalProjectBuilder;
028 import org.eclipse.core.runtime.CoreException;
029 import org.eclipse.core.runtime.IProgressMonitor;
030 import org.eclipse.core.runtime.IStatus;
031 import org.eclipse.core.runtime.Status;
032 import org.eclipse.core.runtime.jobs.Job;
033 import org.granite.builder.util.ProjectUtil;
034
035 /**
036 * @author Franck WOLFF
037 */
038 public class GraniteRebuildJob extends Job {
039
040 public static final String RESET_KEY = "reset";
041
042 private final IProject project;
043 private final boolean reset;
044
045 public GraniteRebuildJob(IProject project) {
046 this(project, false);
047 }
048
049 public GraniteRebuildJob(IProject project, boolean reset) {
050 super("Granite Rebuild Job");
051 this.project = project;
052 this.reset = reset;
053 }
054
055 @Override
056 protected IStatus run(IProgressMonitor monitor) {
057 Map<String, Object> args = new HashMap<String, Object>();
058 if (reset)
059 args.put(RESET_KEY, Boolean.TRUE);
060 try {
061 project.build(IncrementalProjectBuilder.FULL_BUILD, GraniteBuilder.GRANITE_BUILDER_ID, args, monitor);
062 } catch (CoreException e) {
063 return ProjectUtil.createErrorStatus("Granite Rebuild Failed", e);
064 }
065 return Status.OK_STATUS;
066 }
067 }