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.io.IOException;
024
025 import org.eclipse.core.resources.IProject;
026 import org.eclipse.core.runtime.CoreException;
027 import org.eclipse.jdt.core.IJavaProject;
028 import org.eclipse.jdt.core.JavaCore;
029 import org.granite.builder.properties.GraniteProperties;
030 import org.granite.builder.properties.GranitePropertiesLoader;
031 import org.granite.builder.util.ProjectUtil;
032
033 /**
034 * @author Franck WOLFF
035 */
036 public class GraniteBuilderContext {
037
038 private final IJavaProject javaProject;
039 private GraniteProperties properties = null;
040
041 public GraniteBuilderContext(IProject project) throws CoreException {
042 this.javaProject = JavaCore.create(project);
043 if (javaProject == null)
044 throw new CoreException(ProjectUtil.createErrorStatus("Not a Java Project: " + project, null));
045 }
046
047 public IJavaProject getJavaProject() {
048 return javaProject;
049 }
050
051 public GraniteProperties getProperties() throws CoreException {
052 if (GranitePropertiesLoader.isOutdated(javaProject.getProject(), properties)) {
053 try {
054 properties = GranitePropertiesLoader.load(javaProject.getProject());
055 } catch (IOException e) {
056 throw new CoreException(
057 ProjectUtil.createErrorStatus("Could not load Granite properties for: " + javaProject.getProject(),
058 e
059 ));
060 }
061 }
062 return properties;
063 }
064 }