[anjuta/newproject] Implement removing of group and add corresponding tests



commit 4a0ca8a21753e938d4718c4638cd0956f6719708
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Wed Oct 13 20:57:38 2010 +0200

    Implement removing of group and add corresponding tests

 libanjuta/anjuta-project.c        |   13 ++++
 libanjuta/anjuta-project.h        |    1 +
 plugins/am-project/am-node.c      |    5 ++
 plugins/am-project/am-node.h      |    1 +
 plugins/am-project/am-writer.c    |   39 ++++++++++---
 plugins/am-project/tests/group.at |  111 +++++++++++++++++++++++++++++++++++++
 6 files changed, 162 insertions(+), 8 deletions(-)
---
diff --git a/libanjuta/anjuta-project.c b/libanjuta/anjuta-project.c
index f4d098b..6cf9fa5 100644
--- a/libanjuta/anjuta-project.c
+++ b/libanjuta/anjuta-project.c
@@ -65,6 +65,19 @@ anjuta_project_node_parent(AnjutaProjectNode *node)
 }
 
 AnjutaProjectNode *
+anjuta_project_node_root (AnjutaProjectNode *node)
+{
+	g_return_val_if_fail (node != NULL, NULL);
+
+	while (node->parent != NULL)
+	{
+		node = node->parent;
+	}
+
+	return node;
+}
+
+AnjutaProjectNode *
 anjuta_project_node_first_child(AnjutaProjectNode *node)
 {
 	g_return_val_if_fail (node != NULL, NULL);
diff --git a/libanjuta/anjuta-project.h b/libanjuta/anjuta-project.h
index 19cf3ed..db4ca72 100644
--- a/libanjuta/anjuta-project.h
+++ b/libanjuta/anjuta-project.h
@@ -177,6 +177,7 @@ GType      anjuta_project_node_get_type (void) G_GNUC_CONST;
 
 
 
+AnjutaProjectNode *anjuta_project_node_root (AnjutaProjectNode *node);
 AnjutaProjectNode *anjuta_project_node_parent (AnjutaProjectNode *node);
 AnjutaProjectNode *anjuta_project_node_first_child (AnjutaProjectNode *node);
 AnjutaProjectNode *anjuta_project_node_last_child (AnjutaProjectNode *node);
diff --git a/plugins/am-project/am-node.c b/plugins/am-project/am-node.c
index ba3b116..048ef81 100644
--- a/plugins/am-project/am-node.c
+++ b/plugins/am-project/am-node.c
@@ -159,6 +159,11 @@ amp_root_set_configure (AnjutaProjectNode *node, GFile *configure)
 	return root->configure_file;
 }
 
+gboolean
+amp_root_update_configure (AnjutaAmRootNode *group, AnjutaToken *token)
+{
+	return anjuta_token_file_update (group->configure_file, token);
+}
 
 /* GObjet implementation
  *---------------------------------------------------------------------------*/
diff --git a/plugins/am-project/am-node.h b/plugins/am-project/am-node.h
index 3acdcb6..ec3f202 100644
--- a/plugins/am-project/am-node.h
+++ b/plugins/am-project/am-node.h
@@ -47,6 +47,7 @@ AnjutaProjectNode* amp_root_new (GFile *file, GError **error);
 void amp_root_free (AnjutaAmRootNode *node);
 void amp_root_clear (AnjutaAmRootNode *node);
 AnjutaTokenFile* amp_root_set_configure (AnjutaProjectNode *node, GFile *configure);
+gboolean amp_root_update_configure (AnjutaAmRootNode *group, AnjutaToken *token);
 
 AnjutaProjectNode* amp_module_new (AnjutaToken *token, GError **error);
 void amp_module_free (AnjutaAmModuleNode *node);
diff --git a/plugins/am-project/am-writer.c b/plugins/am-project/am-writer.c
index 1c99adb..967af91 100644
--- a/plugins/am-project/am-writer.c
+++ b/plugins/am-project/am-writer.c
@@ -234,6 +234,7 @@ amp_group_create_token (AmpProject  *project, AnjutaAmGroupNode *group, GError *
 		gchar *relative_make;
 		gchar *ext;
 		AnjutaToken *prev = NULL;
+		AnjutaToken *token;
 
 		if (sibling)
 		{
@@ -251,13 +252,9 @@ amp_group_create_token (AmpProject  *project, AnjutaAmGroupNode *group, GError *
 		{
 			*ext = '\0';
 		}
-		//token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED,  relative_make);
-		amp_project_write_config_file (project, list, after, prev, relative_make);
+		token = amp_project_write_config_file (project, list, after, prev, relative_make);
+		amp_group_add_token (group, token, AM_GROUP_TOKEN_CONFIGURE);
 		g_free (relative_make);
-		
-		//style = anjuta_token_style_new (NULL," ","\n",NULL,0);
-		//anjuta_token_add_word (prev_token, token, style);
-		//anjuta_token_style_free (style);
 	}
 
 	/* Add in Makefile.am */
@@ -275,8 +272,10 @@ amp_group_create_token (AmpProject  *project, AnjutaAmGroupNode *group, GError *
 		}
 
 		list = anjuta_token_insert_token_list (FALSE, pos,
-		    	ANJUTA_TOKEN_SPACE, "\n");
-		list = anjuta_token_insert_token_list (FALSE, list,
+		                                       ANJUTA_TOKEN_EOL, "\n",
+		                                       NULL);
+		amp_group_update_makefile (parent, list);	
+		list = anjuta_token_insert_token_list (FALSE, pos,
 	    		AM_TOKEN_SUBDIRS, "SUBDIRS",
 		    	ANJUTA_TOKEN_SPACE, " ",
 		    	ANJUTA_TOKEN_OPERATOR, "=",
@@ -335,6 +334,7 @@ amp_group_delete_token (AmpProject  *project, AnjutaAmGroupNode *group, GError *
 {
 	GList *item;
 	AnjutaProjectNode *parent;
+	AnjutaProjectNode *root;
 
 	/* Get parent target */
 	parent =  anjuta_project_node_parent (ANJUTA_PROJECT_NODE (group));
@@ -360,6 +360,29 @@ amp_group_delete_token (AmpProject  *project, AnjutaAmGroupNode *group, GError *
 		amp_group_update_makefile (ANJUTA_AM_GROUP_NODE (parent), args);
 	}
 
+	/* Remove from configure file */
+	root = anjuta_project_node_root (ANJUTA_PROJECT_NODE (group));
+
+	for (item = amp_group_get_token (group, AM_GROUP_TOKEN_CONFIGURE); item != NULL; item = g_list_next (item))
+	{
+		AnjutaToken *token = (AnjutaToken *)item->data;
+		AnjutaToken *args;
+		AnjutaTokenStyle *style;
+
+		args = anjuta_token_list (token);
+
+		/* Try to use the same style than the current group 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/tests/group.at b/plugins/am-project/tests/group.at
index 26d6d69..47ef59a 100644
--- a/plugins/am-project/tests/group.at
+++ b/plugins/am-project/tests/group.at
@@ -6,31 +6,142 @@ AT_DATA([empty/configure.ac],
 AT_DATA([empty/Makefile.am],
 [[
 ]])
+
+
+
 AT_DATA([expect],
 [[    GROUP (0): empty1
         GROUP (0:0): group1
 ]])
+AT_DATA([reference.am],
+[[
+SUBDIRS = \
+	group1
+]])
+AT_DATA([reference.ac],
+[[AC_CONFIG_FILES(Makefile
+group1/Makefile)
+]])
 AT_PARSER_CHECK([load empty \
 		 move empty1 \
 		 add group 0 group1 \
 		 list \
 		 save])
 AT_CHECK([diff output expect])
+AT_CHECK([diff -b empty1/configure.ac reference.ac])
+AT_CHECK([diff -b empty1/Makefile.am reference.am])
 AT_PARSER_CHECK([load empty1 \
 		 list])
 AT_CHECK([diff output expect])
+
+
+
 AT_DATA([expect],
 [[    GROUP (0): empty2
         GROUP (0:0): group1
 	GROUP (0:1): group2
 ]])
+AT_DATA([reference.am],
+[[
+SUBDIRS = \
+	group1 \
+	group2
+]])
+AT_DATA([reference.ac],
+[[AC_CONFIG_FILES(Makefile
+group1/Makefile
+group2/Makefile)
+]])
 AT_PARSER_CHECK([load empty1 \
 		 move empty2 \
 		 add group 0 group2 after 0:0\
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty2/configure.ac reference.ac])
+AT_CHECK([diff -b empty2/Makefile.am reference.am])
+AT_PARSER_CHECK([load empty2 \
+		 list])
+AT_CHECK([diff -b output expect])
+
+
+
+AT_DATA([expect],
+[[    GROUP (0): empty3
+        GROUP (0:0): group2
+]])
+AT_DATA([reference.am],
+[[
+SUBDIRS = \
+	group2
+]])
+AT_DATA([reference.ac],
+[[AC_CONFIG_FILES(Makefile
+group2/Makefile)
+]])
 AT_PARSER_CHECK([load empty2 \
+		 move empty3 \
+		 remove 0:0\
+		 list \
+		 save])
+AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty3/configure.ac reference.ac])
+AT_CHECK([diff -b empty3/Makefile.am reference.am])
+AT_PARSER_CHECK([load empty3 \
+		 list])
+AT_CHECK([diff -b output expect])
+
+
+
+AT_DATA([expect],
+[[    GROUP (0): empty4
+]])
+AT_DATA([reference.am],
+[[
+SUBDIRS = \ 
+
+]])
+AT_DATA([reference.ac],
+[[AC_CONFIG_FILES(Makefile)
+]])
+AT_PARSER_CHECK([load empty3 \
+		 move empty4 \
+		 remove 0:0\
+		 list \
+		 save])
+AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty4/configure.ac reference.ac])
+AT_CHECK([diff -b empty4/Makefile.am reference.am])
+AT_PARSER_CHECK([load empty4 \
 		 list])
 AT_CHECK([diff -b output expect])
+
+
+
+AT_DATA([expect],
+[[    GROUP (0): empty1
+        GROUP (0:0): group1
+]])
+AT_DATA([reference.am],
+[[
+SUBDIRS = \
+	group1
+]])
+AT_DATA([reference.ac],
+[[AC_CONFIG_FILES(Makefile
+group1/Makefile)
+]])
+AT_PARSER_CHECK([load empty \
+		 move empty1 \
+		 add group 0 group1 \
+		 list \
+		 save])
+AT_CHECK([diff output expect])
+AT_CHECK([diff -b empty1/configure.ac reference.ac])
+AT_CHECK([diff -b empty1/Makefile.am reference.am])
+AT_PARSER_CHECK([load empty1 \
+		 list])
+AT_CHECK([diff output expect])
+
+
 AT_CLEANUP



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]