Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c1e0ac2aa5e84fde1f1743dc6295342dc0b4b86d (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*******************************************************************************
 * Copyright (c) 2004, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig2;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.scannerconfig.IExternalScannerInfoProvider;
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
import org.eclipse.cdt.make.core.scannerconfig.InfoContext;
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile.Action;
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile.BuildOutputProvider;
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile.ScannerInfoCollector;
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile.ScannerInfoConsoleParser;
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile.ScannerInfoProvider;
import org.eclipse.core.resources.IProject;

/**
 * Instantiated scanner config profile
 * 
 * @author vhirsl
 */
public class SCProfileInstance {
	private IProject project;
	private ScannerConfigProfile profile;
	private IScannerInfoCollector collector;
	private InfoContext context;
	/**
	 * 
	 */
	public SCProfileInstance(IProject project, ScannerConfigProfile profile) {
		this(project, new InfoContext(project), profile);
	}

	public SCProfileInstance(IProject project, InfoContext context, ScannerConfigProfile profile) {
		this.project = project;
		this.profile = profile;
		this.context = context;
	}

	/**
	 * 
	 */
	private void instantiateCollector() {
		// create collector object
		collector = createScannerInfoCollector();
        if (collector != null) {
        	// call collector.setProject(project) if class supports it
        	Class clazz = collector.getClass();
        	try {
//				Method setProjectMethod = clazz.getMethod("setProject", new Class[] {IProject.class});//$NON-NLS-1$
//				setProjectMethod.invoke(collector, new Object[] {project});
        		Object[] args = null;
				Method setMethod = null;
				if(context != null){
					try {
						setMethod = clazz.getMethod("setInfoContext", new Class[] {InfoContext.class});//$NON-NLS-1$
						args = new Object[]{context};
					} catch(NoSuchMethodException e) {
					}
				}
				
				if(setMethod == null){
					try {
						setMethod = clazz.getMethod("setProject", new Class[] {IProject.class});//$NON-NLS-1$
						args = new Object[]{project};
					} catch(NoSuchMethodException e) {
					}
				}
				if(setMethod != null)
					setMethod.invoke(collector, args);

			} catch (SecurityException e) {
				MakeCorePlugin.log(e);
//			} catch (NoSuchMethodException e) {
			} catch (IllegalArgumentException e) {
			} catch (IllegalAccessException e) {
			} catch (InvocationTargetException e) {
				MakeCorePlugin.log(e.getCause());
			}
        }
		// all other objects are created on request
	}

	/**
	 * @return
	 */
	public ScannerConfigProfile getProfile() {
		return profile;
	}

	/**
	 * @return a single scannerInfoCollector object
	 */
	public IScannerInfoCollector getScannerInfoCollector() {
		if (collector == null) {
			instantiateCollector();
		}
		return collector;
	}
	
	public IScannerInfoCollector createScannerInfoCollector() {
		ScannerInfoCollector collector = profile.getScannerInfoCollectorElement();
		if (collector != null) {
			return (IScannerInfoCollector) collector.createScannerInfoCollector();
		}
		return null;
	}
	
	/**
	 * @return Creates new buildOutputProvider user object.
	 */
	public IExternalScannerInfoProvider createBuildOutputProvider() {
        BuildOutputProvider bop = profile.getBuildOutputProviderElement();
        if (bop != null) {
    		Action action = bop.getAction();
    		if (action != null) {
    			return (IExternalScannerInfoProvider) action.createExternalScannerInfoProvider();
    		}
        }
		return null; 
	}
	/**
	 * @return Creates new buildOutputParser user object.
	 */
	public IScannerInfoConsoleParser createBuildOutputParser() {
        BuildOutputProvider bop = profile.getBuildOutputProviderElement();
        if (bop != null) {
    		ScannerInfoConsoleParser parserElement = bop.getScannerInfoConsoleParser();
    		if (parserElement != null) {
    			return (IScannerInfoConsoleParser) parserElement.createScannerInfoConsoleParser();
    		}
        }
		return null;
	}
	/**
	 * @return Creates new externalSIProvider user object.
	 */
	public IExternalScannerInfoProvider createExternalScannerInfoProvider(String providerId) {
		ScannerInfoProvider provider = profile.getScannerInfoProviderElement(providerId);
		if (provider != null) {
			return (IExternalScannerInfoProvider) provider.getAction().createExternalScannerInfoProvider();
		}
		return null;
	}
	/**
	 * @return Creates new esiProviderOutputParser user object.
	 */
	public IScannerInfoConsoleParser createExternalScannerInfoParser(String providerId) {
		ScannerInfoProvider provider = profile.getScannerInfoProviderElement(providerId);
		if (provider != null) {
			return (IScannerInfoConsoleParser) provider.getScannerInfoConsoleParser().createScannerInfoConsoleParser();
		}
		return null;
	}
}

Back to the top