Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 61a99071daa971b3881bd8dadc66c361b10b8e5e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*******************************************************************************
 * Copyright (c) 2018 Willink Transformations and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 *
 * Contributors:
 *   E.D.Willink - Initial API and implementation based on org.eclipse.xtext.ui.XtextProjectHelper
 *******************************************************************************/
package org.eclipse.qvtd.xtext.qvtbase.ui;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;

/**
 */
public class QVTdProjectHelper {

	public static final String NATURE_ID = "org.eclipse.qvtd.xtext.qvtbase.ui.qvtdnature"; //$NON-NLS-1$
	public static final String BUILDER_ID = "org.eclipse.qvtd.xtext.qvtbase.ui.qvtdbuilder"; //$NON-NLS-1$

	private static final Logger log = LoggerFactory.getLogger(QVTdProjectHelper.class);

	public static boolean hasNature(IProject project) {
		try {
			if (project.isAccessible()) {
				return project.hasNature(NATURE_ID);
			}
		} catch (CoreException e) {
			log.error(e.getMessage(), e);
		}
		return false;
	}

	public static boolean hasBuilder(IProject project) {
		if (project.isAccessible()) {
			try {
				for (ICommand command : project.getDescription().getBuildSpec()) {
					if (BUILDER_ID.equals(command.getBuilderName())) {
						return true;
					}
				}
			} catch (CoreException e) {
				log.error("Can't build due to an exception.", e);
			}
		}
		return false;
	}

}

Back to the top