1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4
* Copyright (C) Johannes Schmid 2010 <jhs@gnome.org>
6
* code-analyzer is free software: you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* code-analyzer is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
* See the GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include <libanjuta/anjuta-shell.h>
22
#include <libanjuta/anjuta-debug.h>
23
#include <libanjuta/interfaces/ianjuta-environment.h>
24
#include <libanjuta/interfaces/ianjuta-preferences.h>
25
#include <glib/gi18n.h>
29
#define ICON_FILE "code-analyzer.png"
31
#define BUILDER_FILE PACKAGE_DATA_DIR"/glade/code-analyzer.ui"
32
#define CLANG_PREFS_ROOT "clang_preferences"
33
#define PREF_SCHEMA "org.gnome.anjuta.code-analyzer"
35
#define PREF_ENABLED "clang-enable"
36
#define PREF_CC_PATH "clang-cc-path"
37
#define PREF_CXX_PATH "clang-cxx-path"
39
static gpointer parent_class;
42
code_analyzer_activate (AnjutaPlugin *plugin)
44
CodeAnalyzerPlugin *code_analyzer;
46
DEBUG_PRINT ("%s", "CodeAnalyzerPlugin: Activating CodeAnalyzerPlugin plugin ...");
47
code_analyzer = (CodeAnalyzerPlugin*) plugin;
53
code_analyzer_deactivate (AnjutaPlugin *plugin)
56
DEBUG_PRINT ("%s", "CodeAnalyzerPlugin: Dectivating CodeAnalyzerPlugin plugin ...");
62
code_analyzer_finalize (GObject *obj)
64
/* Finalization codes here */
65
G_OBJECT_CLASS (parent_class)->finalize (obj);
69
code_analyzer_dispose (GObject *obj)
71
/* Disposition codes */
72
G_OBJECT_CLASS (parent_class)->dispose (obj);
76
code_analyzer_instance_init (GObject *obj)
78
CodeAnalyzerPlugin *plugin = (CodeAnalyzerPlugin*)obj;
79
plugin->settings = g_settings_new (PREF_SCHEMA);
83
code_analyzer_class_init (GObjectClass *klass)
85
AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
87
parent_class = g_type_class_peek_parent (klass);
89
plugin_class->activate = code_analyzer_activate;
90
plugin_class->deactivate = code_analyzer_deactivate;
91
klass->finalize = code_analyzer_finalize;
92
klass->dispose = code_analyzer_dispose;
96
code_analyzer_get_cc_path (CodeAnalyzerPlugin* ca_plugin)
98
gchar* path = g_settings_get_string (ca_plugin->settings,
100
if (!g_file_test (path, G_FILE_TEST_IS_EXECUTABLE))
109
code_analyzer_get_cxx_path (CodeAnalyzerPlugin* ca_plugin)
111
gchar* path = g_settings_get_string (ca_plugin->settings,
113
if (!g_file_test (path, G_FILE_TEST_IS_EXECUTABLE))
122
/* IAnjutaEnvironment implementation */
124
ienvironment_override (IAnjutaEnvironment* env_iface,
125
gchar **dirp, gchar ***argvp, gchar ***envp,
128
CodeAnalyzerPlugin* ca_plugin = (CodeAnalyzerPlugin*) (env_iface);
129
gchar* command = *argvp[0];
131
if (!g_settings_get_boolean (ca_plugin->settings,
137
/* Check if this is a command we are interested in */
138
if (strcmp (command, "autogen.sh") ||
139
strcmp (command, "configure") ||
140
strcmp (command, "make"))
142
gchar** new_env = *envp;
144
gchar* cc = code_analyzer_get_cc_path (ca_plugin);
145
gchar* cxx = code_analyzer_get_cxx_path (ca_plugin);
146
gboolean found_cc = FALSE;
147
gboolean found_cxx = FALSE;
148
/* NULL termination */
151
/* Check if paths are correct */
155
*error = g_error_new (ianjuta_environment_error_quark (),
156
IANJUTA_ENVIRONMENT_CONFIG, "%s",
157
_("Couldn't find clang analyzer, please check "
158
"if it is installed and if the paths are configured "
159
"correctly in the preferences"));
165
for (env = new_env; env && *env != NULL; env++)
167
if (g_str_has_prefix (*env, "CC="))
170
*env = g_strdup_printf("CC=%s", cc);
173
else if (g_str_has_prefix (*env, "CXX="))
176
*env = g_strdup_printf("CXX=%s", cxx);
183
new_env = g_realloc (new_env, sizeof (gchar**) * (size + 1));
184
new_env[size - 1] = g_strdup_printf("CC=%s", cc);
185
new_env[size] = NULL;
190
new_env = g_realloc (new_env, sizeof (gchar**) * (size + 1));
191
new_env[size - 1] = g_strdup_printf("CXX=%s", cxx);
192
new_env[size] = NULL;
200
ienvironment_get_real_directory (IAnjutaEnvironment* env_iface, gchar *dir,
207
ienvironment_iface_init (IAnjutaEnvironmentIface* iface)
209
iface->override = ienvironment_override;
210
iface->get_real_directory = ienvironment_get_real_directory;
213
/* IAnjutaPreferences implementation
214
*---------------------------------------------------------------------------*/
217
ipreferences_merge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** e)
220
CodeAnalyzerPlugin* ca_plugin = (CodeAnalyzerPlugin*) (ipref);
221
/* Create the preferences page */
222
bxml = anjuta_util_builder_new (BUILDER_FILE, NULL);
225
anjuta_preferences_add_from_builder (prefs, bxml, ca_plugin->settings,
226
CLANG_PREFS_ROOT, _("CLang Analyzer"), ICON_FILE);
228
g_object_unref (bxml);
232
ipreferences_unmerge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** e)
234
anjuta_preferences_remove_page(prefs, _("CLang Analyzer"));
238
ipreferences_iface_init(IAnjutaPreferencesIface* iface)
240
iface->merge = ipreferences_merge;
241
iface->unmerge = ipreferences_unmerge;
245
ANJUTA_PLUGIN_BEGIN (CodeAnalyzerPlugin, code_analyzer);
246
ANJUTA_PLUGIN_ADD_INTERFACE(ienvironment, IANJUTA_TYPE_ENVIRONMENT);
247
ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences, IANJUTA_TYPE_PREFERENCES);
250
ANJUTA_SIMPLE_PLUGIN (CodeAnalyzerPlugin, code_analyzer);