[anjuta/newproject] pm: Implement adding and removing package
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/newproject] pm: Implement adding and removing package
- Date: Sun, 31 Oct 2010 11:49:36 +0000 (UTC)
commit e5cd1227043a454ce138037516f31e8d23be2877
Author: Sébastien Granjoux <seb sfo free fr>
Date: Sun Oct 31 12:42:22 2010 +0100
pm: Implement adding and removing package
plugins/am-project/ac-writer.c | 129 ++++++++++++++++++++++++++++++-
plugins/am-project/ac-writer.h | 3 +
plugins/am-project/am-node.c | 13 +++
plugins/am-project/am-node.h | 3 +
plugins/am-project/am-project-private.h | 1 +
plugins/am-project/am-project.c | 14 ++++
plugins/am-project/projectparser.c | 19 +++++
plugins/am-project/tests/Makefile.am | 3 +-
plugins/am-project/tests/package.at | 105 +++++++++++++++++++++++++
plugins/am-project/tests/testsuite.at | 1 +
10 files changed, 289 insertions(+), 2 deletions(-)
---
diff --git a/plugins/am-project/ac-writer.c b/plugins/am-project/ac-writer.c
index c63586b..ef2ddb4 100644
--- a/plugins/am-project/ac-writer.c
+++ b/plugins/am-project/ac-writer.c
@@ -267,7 +267,7 @@ amp_module_create_token (AmpProject *project, AnjutaAmModuleNode *module, GErro
AnjutaProjectNode *sibling;
gchar *relative_name;
- /* Get parent target */
+ /* Get root node */
root = ANJUTA_AM_ROOT_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (module)));
if ((root == NULL) || (anjuta_project_node_get_node_type (root) != ANJUTA_PROJECT_ROOT)) return FALSE;
@@ -328,3 +328,130 @@ amp_module_delete_token (AmpProject *project, AnjutaAmModuleNode *module, GErro
return TRUE;
}
+
+/* Package objects
+ *---------------------------------------------------------------------------*/
+
+gboolean
+amp_package_create_token (AmpProject *project, AnjutaAmPackageNode *package, GError **error)
+{
+ AnjutaAmModuleNode *module;
+ AnjutaAmRootNode *root;
+ gboolean after;
+ AnjutaToken *token;
+ AnjutaToken *prev;
+ AnjutaProjectNode *sibling;
+ AnjutaToken *args;
+
+
+ /* Get parent module */
+ module = ANJUTA_AM_MODULE_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (package)));
+ if ((module == NULL) || (anjuta_project_node_get_node_type (module) != ANJUTA_PROJECT_MODULE)) return FALSE;
+
+ /* Get root node */
+ root = ANJUTA_AM_ROOT_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (module)));
+ if ((root == NULL) || (anjuta_project_node_get_node_type (root) != ANJUTA_PROJECT_ROOT)) return FALSE;
+
+
+ /* Add in configure.ac */
+ /* Find a sibling if possible */
+ if (package->base.prev != NULL)
+ {
+ prev = ANJUTA_AM_PACKAGE_NODE (package->base.prev)->token;
+ after = TRUE;
+ args = anjuta_token_list (prev);
+ }
+ else if (package->base.next != NULL)
+ {
+ prev = ANJUTA_AM_PACKAGE_NODE (package->base.next)->token;
+ after = FALSE;
+ args = anjuta_token_list (prev);
+ }
+ else
+ {
+ prev = NULL;
+ args = NULL;
+ }
+
+ /* Check if a valid source variable is already defined */
+ if (args == NULL)
+ {
+ args = amp_module_get_token (module);
+ }
+
+ if (args != NULL)
+ {
+ AnjutaTokenStyle *style;
+ gchar *name;
+
+ name = anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (package));
+ style = anjuta_token_style_new_from_base (project->ac_space_list);
+ //anjuta_token_style_update (style, args);
+
+ token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, name);
+ g_free (name);
+
+ if (after)
+ {
+ anjuta_token_insert_word_after (args, prev, token);
+ }
+ else
+ {
+ anjuta_token_insert_word_before (args, prev, token);
+ }
+
+ /* Try to use the same style than the current target list */
+ anjuta_token_style_format (style, args);
+ anjuta_token_style_free (style);
+
+ amp_root_update_configure (root, token);
+
+ amp_package_add_token (package, token);
+ }
+
+ return TRUE;
+}
+
+gboolean
+amp_package_delete_token (AmpProject *project, AnjutaAmPackageNode *package, GError **error)
+{
+ AnjutaProjectNode *root;
+ AnjutaProjectNode *module;
+ AnjutaToken *token;
+
+ /* Get parent module */
+ module = anjuta_project_node_parent (ANJUTA_PROJECT_NODE (package));
+ if ((module == NULL) || (anjuta_project_node_get_node_type (module) != ANJUTA_PROJECT_MODULE))
+ {
+ return FALSE;
+ }
+ /* Get root */
+ root = anjuta_project_node_parent (ANJUTA_PROJECT_NODE (module));
+ if ((root == NULL) || (anjuta_project_node_get_node_type (root) != ANJUTA_PROJECT_ROOT))
+ {
+ return FALSE;
+ }
+
+ token = amp_package_get_token (package);
+ g_message ("amp_module_delete_token %p", package);
+ if (token != NULL)
+ {
+ AnjutaToken *args;
+ AnjutaTokenStyle *style;
+
+ args = anjuta_token_list (token);
+
+ /* Try to use the same style than the current target list */
+ style = anjuta_token_style_new_from_base (project->ac_space_list);
+ anjuta_token_style_update (style, args);
+
+ anjuta_token_remove_word (token);
+
+ anjuta_token_style_format (style, args);
+ anjuta_token_style_free (style);
+
+ amp_root_update_configure (ANJUTA_AM_ROOT_NODE (root), args);
+ }
+
+ return TRUE;
+}
diff --git a/plugins/am-project/ac-writer.h b/plugins/am-project/ac-writer.h
index aa6afb3..67cd9bf 100644
--- a/plugins/am-project/ac-writer.h
+++ b/plugins/am-project/ac-writer.h
@@ -34,6 +34,9 @@ gboolean amp_project_update_ac_property (AmpProject *project, AnjutaProjectPrope
gboolean amp_module_create_token (AmpProject *project, AnjutaAmModuleNode *module, GError **error);
gboolean amp_module_delete_token (AmpProject *project, AnjutaAmModuleNode *module, GError **error);
+gboolean amp_package_create_token (AmpProject *project, AnjutaAmPackageNode *package, GError **error);
+gboolean amp_package_delete_token (AmpProject *project, AnjutaAmPackageNode *package, GError **error);
+
G_END_DECLS
#endif /* _AC_WRITER_H_ */
diff --git a/plugins/am-project/am-node.c b/plugins/am-project/am-node.c
index 432d9ce..0fd28ac 100644
--- a/plugins/am-project/am-node.c
+++ b/plugins/am-project/am-node.c
@@ -425,6 +425,19 @@ amp_package_set_version (AnjutaAmPackageNode *node, const gchar *compare, const
node->version = version != NULL ? g_strconcat (compare, version, NULL) : NULL;
}
+AnjutaToken *
+amp_package_get_token (AnjutaAmPackageNode *node)
+{
+ return node->token;
+}
+
+void
+amp_package_add_token (AnjutaAmPackageNode *node, AnjutaToken *token)
+{
+ node->token = token;
+}
+
+
/* GObjet implementation
*---------------------------------------------------------------------------*/
diff --git a/plugins/am-project/am-node.h b/plugins/am-project/am-node.h
index bbc6354..df45166 100644
--- a/plugins/am-project/am-node.h
+++ b/plugins/am-project/am-node.h
@@ -59,6 +59,9 @@ void amp_module_add_token (AnjutaAmModuleNode *group, AnjutaToken *token);
AnjutaProjectNode* amp_package_new (const gchar *name, GError **error);
void amp_package_free (AnjutaAmPackageNode *node);
void amp_package_set_version (AnjutaAmPackageNode *node, const gchar *compare, const gchar *version);
+AnjutaToken *amp_package_get_token (AnjutaAmPackageNode *node);
+void amp_package_add_token (AnjutaAmPackageNode *node, AnjutaToken *token);
+
void amp_group_add_token (AnjutaAmGroupNode *group, AnjutaToken *token, AmpGroupTokenCategory category);
GList * amp_group_get_token (AnjutaAmGroupNode *group, AmpGroupTokenCategory category);
diff --git a/plugins/am-project/am-project-private.h b/plugins/am-project/am-project-private.h
index 5d0d241..7c12614 100644
--- a/plugins/am-project/am-project-private.h
+++ b/plugins/am-project/am-project-private.h
@@ -115,6 +115,7 @@ GType anjuta_am_package_node_get_type (void) G_GNUC_CONST;
struct _AnjutaAmPackageNode {
AnjutaProjectNode base;
gchar *version;
+ AnjutaToken *token;
};
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index bfaaac1..3b1ba51 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -841,6 +841,7 @@ amp_project_load_module (AmpProject *project, AnjutaToken *module_token)
else
{
package = amp_package_new (value, NULL);
+ amp_package_add_token (package, item);
anjuta_project_node_append (module, package);
anjuta_project_node_set_state ((AnjutaProjectNode *)package, ANJUTA_PROJECT_INCOMPLETE);
g_free (value);
@@ -2363,6 +2364,11 @@ iproject_add_node_before (IAnjutaProject *obj, AnjutaProjectNode *parent, Anjuta
anjuta_project_node_insert_before (parent, sibling, node);
amp_module_create_token (AMP_PROJECT (obj), node, NULL);
break;
+ case ANJUTA_PROJECT_PACKAGE:
+ node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
+ anjuta_project_node_insert_before (parent, sibling, node);
+ amp_package_create_token (AMP_PROJECT (obj), node, NULL);
+ break;
default:
node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
anjuta_project_node_insert_before (parent, sibling, node);
@@ -2407,6 +2413,11 @@ iproject_add_node_after (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaP
anjuta_project_node_insert_after (parent, sibling, node);
amp_module_create_token (AMP_PROJECT (obj), node, NULL);
break;
+ case ANJUTA_PROJECT_PACKAGE:
+ node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
+ anjuta_project_node_insert_before (parent, sibling, node);
+ amp_package_create_token (AMP_PROJECT (obj), node, NULL);
+ break;
default:
node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
anjuta_project_node_insert_after (parent, sibling, node);
@@ -2438,6 +2449,9 @@ iproject_remove_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err
case ANJUTA_PROJECT_MODULE:
amp_module_delete_token (AMP_PROJECT (obj), node, NULL);
break;
+ case ANJUTA_PROJECT_PACKAGE:
+ amp_package_delete_token (AMP_PROJECT (obj), node, NULL);
+ break;
default:
break;
}
diff --git a/plugins/am-project/projectparser.c b/plugins/am-project/projectparser.c
index 0a933f2..6d675e3 100644
--- a/plugins/am-project/projectparser.c
+++ b/plugins/am-project/projectparser.c
@@ -579,6 +579,25 @@ main(int argc, char *argv[])
child = ianjuta_project_add_node_before (project, node, NULL, ANJUTA_PROJECT_MODULE, NULL, command[3], &error);
}
}
+ else if (g_ascii_strcasecmp (command[1], "package") == 0)
+ {
+ if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "before") == 0))
+ {
+ sibling = get_node (project, root, command[5]);
+ child = ianjuta_project_add_node_before (project, node, sibling, ANJUTA_PROJECT_PACKAGE, NULL, command[3], &error);
+ command += 2;
+ }
+ else if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "after") == 0))
+ {
+ sibling = get_node (project, root, command[5]);
+ child = ianjuta_project_add_node_after (project, node, sibling, ANJUTA_PROJECT_PACKAGE, NULL, command[3], &error);
+ command += 2;
+ }
+ else
+ {
+ child = ianjuta_project_add_node_before (project, node, NULL, ANJUTA_PROJECT_PACKAGE, NULL, command[3], &error);
+ }
+ }
else
{
fprintf (stderr, "Error: unknown command %s\n", *command);
diff --git a/plugins/am-project/tests/Makefile.am b/plugins/am-project/tests/Makefile.am
index 67c298e..59b6e84 100644
--- a/plugins/am-project/tests/Makefile.am
+++ b/plugins/am-project/tests/Makefile.am
@@ -25,7 +25,8 @@ TESTSUITE_AT = \
$(srcdir)/include.at \
$(srcdir)/variable.at \
$(srcdir)/properties.at \
- $(srcdir)/module.at
+ $(srcdir)/module.at \
+ $(srcdir)/package.at
TESTSUITE = $(srcdir)/testsuite
diff --git a/plugins/am-project/tests/package.at b/plugins/am-project/tests/package.at
new file mode 100644
index 0000000..f459b06
--- /dev/null
+++ b/plugins/am-project/tests/package.at
@@ -0,0 +1,105 @@
+AT_SETUP([Add package])
+AS_MKDIR_P([empty])
+AT_DATA([empty/configure.ac],
+[[PKG_CHECK_MODULES(MODULE1,)
+AC_CONFIG_FILES(Makefile)
+]])
+AT_DATA([empty/Makefile.am],
+[[]])
+
+
+
+AT_DATA([expect],
+[[ MODULE (): MODULE1
+ PACKAGE (): package1
+ GROUP (): empty1
+]])
+AT_DATA([reference.ac],
+[[PKG_CHECK_MODULES(MODULE1,
+package1)
+AC_CONFIG_FILES(Makefile)
+]])
+AT_PARSER_CHECK([load empty \
+ move empty1 \
+ add package 0 package1 \
+ list \
+ save])
+AT_CHECK([[sed 's/^\(\s*\w\+\s*(\)[0-9:]\+\()\)/\1\2/' output | diff - expect]])
+AT_CHECK([diff -b empty1/configure.ac reference.ac])
+AT_PARSER_CHECK([load empty1 \
+ list])
+AT_CHECK([[sed 's/^\(\s*\w\+\s*(\)[0-9:]\+\()\)/\1\2/' output | diff - expect]])
+
+
+
+AT_DATA([expect],
+[[ MODULE (): MODULE1
+ PACKAGE (): package1
+ PACKAGE (): package2
+ GROUP (): empty2
+]])
+AT_DATA([reference.ac],
+[[PKG_CHECK_MODULES(MODULE1,
+package1
+package2)
+AC_CONFIG_FILES(Makefile)
+]])
+AT_PARSER_CHECK([load empty1 \
+ move empty2 \
+ add package 0 package2 after 0:1\
+ list \
+ save])
+AT_CHECK([[sed 's/^\(\s*\w\+\s*(\)[0-9:]\+\()\)/\1\2/' output | diff - expect]])
+AT_CHECK([diff -b empty2/configure.ac reference.ac])
+AT_PARSER_CHECK([load empty2 \
+ list])
+AT_CHECK([[sed 's/^\(\s*\w\+\s*(\)[0-9:]\+\()\)/\1\2/' output | diff - expect]])
+
+
+
+AT_DATA([expect],
+[[ MODULE (): MODULE1
+ PACKAGE (): package2
+ GROUP (): empty3
+]])
+AT_DATA([reference.ac],
+[[PKG_CHECK_MODULES(MODULE1,
+package2)
+AC_CONFIG_FILES(Makefile)
+]])
+AT_PARSER_CHECK([load empty2 \
+ move empty3 \
+ remove 0:0 \
+ list \
+ save])
+AT_CHECK([[sed 's/^\(\s*\w\+\s*(\)[0-9:]\+\()\)/\1\2/' output | diff - expect]])
+AT_CHECK([diff -b empty3/configure.ac reference.ac])
+AT_PARSER_CHECK([load empty3 \
+ list])
+AT_CHECK([[sed 's/^\(\s*\w\+\s*(\)[0-9:]\+\()\)/\1\2/' output | diff - expect]])
+
+
+
+AT_DATA([expect],
+[[ MODULE (): MODULE1
+ GROUP (): empty4
+]])
+AT_DATA([reference.ac],
+[[PKG_CHECK_MODULES(MODULE1,
+)
+AC_CONFIG_FILES(Makefile)
+]])
+AT_PARSER_CHECK([load empty3 \
+ move empty4 \
+ remove 0:0 \
+ list \
+ save])
+AT_CHECK([[sed 's/^\(\s*\w\+\s*(\)[0-9:]\+\()\)/\1\2/' output | diff - expect]])
+AT_CHECK([diff -b empty4/configure.ac reference.ac])
+AT_PARSER_CHECK([load empty4 \
+ list])
+AT_CHECK([[sed 's/^\(\s*\w\+\s*(\)[0-9:]\+\()\)/\1\2/' output | diff - expect]])
+
+
+
+AT_CLEANUP
diff --git a/plugins/am-project/tests/testsuite.at b/plugins/am-project/tests/testsuite.at
index 5ef2bcf..eef2513 100644
--- a/plugins/am-project/tests/testsuite.at
+++ b/plugins/am-project/tests/testsuite.at
@@ -9,3 +9,4 @@ m4_include([include.at])
m4_include([variable.at])
m4_include([properties.at])
m4_include([module.at])
+m4_include([package.at])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]