Index: /main/trunk/greenstone2/bin/script/activate.pl
===================================================================
--- /main/trunk/greenstone2/bin/script/activate.pl	(revision 30512)
+++ /main/trunk/greenstone2/bin/script/activate.pl	(revision 30513)
@@ -43,8 +43,8 @@
     unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
 	
-	# Adding cpan in, adds in its auto subfolder which conflicts with ActivePerl on Windows
-	# The auto folder has been moved into a perl-5.8 folder, and this will now be included 
-	# only if the current version of perl is 5.8 (and not ActivePerl).
-	my $perl_dir;
+    # Adding cpan in, adds in its auto subfolder which conflicts with ActivePerl on Windows
+    # The auto folder has been moved into a perl-5.8 folder, and this will now be included 
+    # only if the current version of perl is 5.8 (and not ActivePerl).
+    my $perl_dir;
 
     # Note: $] encodes the version number of perl
@@ -69,7 +69,7 @@
 	$perl_dir = "perl-5.8";
     }
-
+    
     #if ($ENV{'GSDLOS'} !~ /^windows$/i) {
-		# Use push to put this on the end, so an existing XML::Parser will be used by default
+    # Use push to put this on the end, so an existing XML::Parser will be used by default
 		if (-d "$ENV{'GSDLHOME'}/perllib/cpan/$perl_dir-mt" && $Config{usethreads}){
 			push (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/$perl_dir-mt");
@@ -112,29 +112,29 @@
 
 sub print_task_msg {
-	my ($task_msg, $verbosity_setting) = @_;
-	
-	$verbosity_setting = $default_verbosity unless $verbosity_setting;
-	#$verbosity_setting = 1 unless defined $verbosity;
-	if($verbosity_setting >= 1) {
-		print STDERR "\n";
-		print STDERR "************************\n";
-		print STDERR "* $task_msg\n";
-		print STDERR "************************\n";
-	}
+    my ($task_msg, $verbosity_setting) = @_;
+    
+    $verbosity_setting = $default_verbosity unless $verbosity_setting;
+    #$verbosity_setting = 1 unless defined $verbosity;
+    if($verbosity_setting >= 1) {
+	print STDERR "\n";
+	print STDERR "************************\n";
+	print STDERR "* $task_msg\n";
+	print STDERR "************************\n";
+    }
 }
 
 # Prints messages if the verbosity is right. Does not add new lines.
 sub print_msg {
-	my ($msg, $min_verbosity, $verbosity_setting) = @_;
-	
-	# only display error messages if the current 
-	# verbosity setting >= the minimum verbosity level
-	# needed for that message to be displayed.
-	
-	$verbosity_setting = $default_verbosity unless defined $verbosity_setting;
-	$min_verbosity = 1 unless defined $min_verbosity;
-	if($verbosity_setting >= $min_verbosity) { # by default display all 1 messages
-		print STDERR "$msg";
-	}
+    my ($msg, $min_verbosity, $verbosity_setting) = @_;
+    
+    # only display error messages if the current 
+    # verbosity setting >= the minimum verbosity level
+    # needed for that message to be displayed.
+	
+    $verbosity_setting = $default_verbosity unless defined $verbosity_setting;
+    $min_verbosity = 1 unless defined $min_verbosity;
+    if($verbosity_setting >= $min_verbosity) { # by default display all 1 messages
+	print STDERR "$msg";
+    }
 }
 
@@ -143,131 +143,131 @@
 # and is-persistent (is-persistent only implemented for GS2).
 sub config {
-	my ($library_url, $command, $check_message_against_regex, $site, $expected_error_code, $silent) = @_; 
-			# Gatherer.java's configGS3Server doesn't use the site variable
-			# so we don't have to either
-	
-	# for GS2, getting the HTTP status isn't enough, we need to read the output
-	# since this is what CollectionManager.config() stipulates.
-	# Using LWP::UserAgent::get($url) for this	
-	
-	if(!defined $library_url) {
-		return 0;
+    my ($library_url, $command, $check_message_against_regex, $site, $expected_error_code, $silent) = @_; 
+    # Gatherer.java's configGS3Server doesn't use the site variable
+    # so we don't have to either
+    
+    # for GS2, getting the HTTP status isn't enough, we need to read the output
+    # since this is what CollectionManager.config() stipulates.
+    # Using LWP::UserAgent::get($url) for this	
+    
+    if(!defined $library_url) {
+	return 0;
+    }
+    else {
+	$ua->timeout(5); # set LWP useragent to 5s max timeout for testing the URL
+	# Need to set this, else it takes I don't know how long to timeout 
+	# http://www.perlmonks.org/?node_id=618534
+	
+	# http://search.cpan.org/~gaas/libwww-perl-6.04/lib/LWP/UserAgent.pm
+	# use LWP::UserAgent's get($url) since it returns an HTTP::Response code
+	
+	my $response_obj = $ua->get( $library_url.$command);
+	
+	# $response_obj->content stores the content and $response_obj->code the HTTP response code
+	my $response_code = $response_obj->code();
+	
+	if(LWP::Simple::is_success($response_code)) {# $response_code eq RC_OK) { # LWP::Simple::is_success($response_code)
+	    &print_msg("*** Command $library_url$command\n", 3);
+	    &print_msg("*** HTTP Response Status: $response_code - Complete.", 3);
+	    
+	    # check the page content is as expected
+	    my $response_content = $response_obj->content;
+	    my $resultstr = $response_content;
+	    $resultstr =~ s@.*gs_content\"\>@@s;		
+	    $resultstr =~ s@</div>.*@@s;
+	    
+	    if($response_content =~ m/$check_message_against_regex/) {
+		&print_msg(" Response as expected.\n", 3);
+		&print_msg("@@@@@@ Got result:\n$resultstr\n", 4);
+		return 1;
+	    } else {
+		# if we expect the collection to be inactive, then we'd be in silent mode: if so,
+		# don't print out the "ping did not succeed" response, but print out any other messages
+		
+		# So we only suppress the ping col "did not succeed" response if we're in silent mode
+		# But if any message other than ping "did not succeed" is returned, we always print it
+		if($response_content !~ m/did not succeed/ || !$silent) {
+		    &print_msg("\n\tBUT: command $library_url$command response UNEXPECTED.\n", 3);
+		    &print_msg("*** Got message:\n$response_content.\n", 4);
+		    &print_msg("*** Got result:\n$resultstr\n", 3);
+		}
+		return 0; # ping on a collection may "not succeed."
+	    }
+	} 
+	elsif(LWP::Simple::is_error($response_code)) { # method exported by LWP::Simple, along with HTTP::Status constants
+	    # check the page content is as expected
+	    if(defined $expected_error_code && $response_code == $expected_error_code) {
+		&print_msg(" Response status $response_code as expected.\n", 3);
+	    } else {
+		&print_msg("*** Command $library_url$command\n");
+		&print_msg("*** Unexpected error. HTTP Response Status: $response_code - Failed.\n");
+	    }
+	    return 0; # return false, since the response_code was an error, expected or not
 	}
 	else {
-		$ua->timeout(5); # set LWP useragent to 5s max timeout for testing the URL
-			# Need to set this, else it takes I don't know how long to timeout 
-			# http://www.perlmonks.org/?node_id=618534
-		
-		# http://search.cpan.org/~gaas/libwww-perl-6.04/lib/LWP/UserAgent.pm
-		# use LWP::UserAgent's get($url) since it returns an HTTP::Response code
-		
-		my $response_obj = $ua->get( $library_url.$command);
-		
-		# $response_obj->content stores the content and $response_obj->code the HTTP response code
-		my $response_code = $response_obj->code();
-		
-		if(LWP::Simple::is_success($response_code)) {# $response_code eq RC_OK) { # LWP::Simple::is_success($response_code)
-			&print_msg("*** Command $library_url$command\n", 3);
-			&print_msg("*** HTTP Response Status: $response_code - Complete.", 3);
-			
-			# check the page content is as expected
-			my $response_content = $response_obj->content;
-			my $resultstr = $response_content;
-			$resultstr =~ s@.*gs_content\"\>@@s;		
-			$resultstr =~ s@</div>.*@@s;
-			
-			if($response_content =~ m/$check_message_against_regex/) {
-				&print_msg(" Response as expected.\n", 3);
-				&print_msg("@@@@@@ Got result:\n$resultstr\n", 4);
-				return 1;
-			} else {
-			    # if we expect the collection to be inactive, then we'd be in silent mode: if so,
-			    # don't print out the "ping did not succeed" response, but print out any other messages
-
-			    # So we only suppress the ping col "did not succeed" response if we're in silent mode
-			    # But if any message other than ping "did not succeed" is returned, we always print it
-			    if($response_content !~ m/did not succeed/ || !$silent) {
-				&print_msg("\n\tBUT: command $library_url$command response UNEXPECTED.\n", 3);
-				&print_msg("*** Got message:\n$response_content.\n", 4);
-				&print_msg("*** Got result:\n$resultstr\n", 3);
-			    }
-			    return 0; # ping on a collection may "not succeed."
-			}
-		} 
-		elsif(LWP::Simple::is_error($response_code)) { # method exported by LWP::Simple, along with HTTP::Status constants
-		    # check the page content is as expected
-		    if(defined $expected_error_code && $response_code == $expected_error_code) {
-			&print_msg(" Response status $response_code as expected.\n", 3);
-		    } else {
-			&print_msg("*** Command $library_url$command\n");
-			&print_msg("*** Unexpected error. HTTP Response Status: $response_code - Failed.\n");
-		    }
-		    return 0; # return false, since the response_code was an error, expected or not
-		}
-		else {
-		    &print_msg("*** Command $library_url$command\n");
-		    &print_msg("*** Unexpected error. HTTP Response Status: $response_code - Failed.\n");
-		    return 0;
-		}
-	}	
+	    &print_msg("*** Command $library_url$command\n");
+	    &print_msg("*** Unexpected error. HTTP Response Status: $response_code - Failed.\n");
+	    return 0;
+	}
+    }	
 }
 
 sub deactivate_collection {
-	my ($library_url, $gs_mode, $qualified_collection, $site) = @_;	
-	
-	if($gs_mode eq "gs2") {
-		my $DEACTIVATE_COMMAND = "?a=config&cmd=release-collection&c=";
-		my $check_message_against_regex = q/configured release-collection/;
-		config($library_url, $DEACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex);
-	}
-	elsif ($gs_mode eq "gs3") {
-		my $DEACTIVATE_COMMAND = "?a=s&sa=d&st=collection&sn=";
-		my $check_message_against_regex = "collection: $qualified_collection deactivated";
-		config($library_url, $DEACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex, $site);
-	}	
+    my ($library_url, $gs_mode, $qualified_collection, $site) = @_;	
+    
+    if($gs_mode eq "gs2") {
+	my $DEACTIVATE_COMMAND = "?a=config&cmd=release-collection&c=";
+	my $check_message_against_regex = q/configured release-collection/;
+	config($library_url, $DEACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex);
+    }
+    elsif ($gs_mode eq "gs3") {
+	my $DEACTIVATE_COMMAND = "?a=s&sa=d&st=collection&sn=";
+	my $check_message_against_regex = "collection: $qualified_collection deactivated";
+	config($library_url, $DEACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex, $site);
+    }	
 }
 
 sub activate_collection {
-	my ($library_url, $gs_mode, $qualified_collection, $site) = @_;	
-	
-	if($gs_mode eq "gs2") {
-		my $ACTIVATE_COMMAND = "?a=config&cmd=add-collection&c=";
-		my $check_message_against_regex = q/configured add-collection/;
-		config($library_url, $ACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex);
-	}
-	elsif ($gs_mode eq "gs3") {
-		my $ACTIVATE_COMMAND = "?a=s&sa=a&st=collection&sn=";
-		my $check_message_against_regex = "collection: $qualified_collection activated";
-		config($library_url, $ACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex, $site);
-	}	
+    my ($library_url, $gs_mode, $qualified_collection, $site) = @_;	
+    
+    if($gs_mode eq "gs2") {
+	my $ACTIVATE_COMMAND = "?a=config&cmd=add-collection&c=";
+	my $check_message_against_regex = q/configured add-collection/;
+	config($library_url, $ACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex);
+    }
+    elsif ($gs_mode eq "gs3") {
+	my $ACTIVATE_COMMAND = "?a=s&sa=a&st=collection&sn=";
+	my $check_message_against_regex = "collection: $qualified_collection activated";
+	config($library_url, $ACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex, $site);
+    }	
 }
 
 sub ping {
-	my ($library_url, $command, $gs_mode, $site, $silent) = @_;
-
-	# If the GS server is not running, we *expect* to see a "500" status code.
-	# If the GS server is running, then "Ping" ... "succeeded" is expected on success. 
-	# When pinging an inactive collection, it will say it did "not succeed". This is
-	# a message of interest to return.
-	my $check_responsemsg_against_regex = q/(succeeded)/;
-	my $expected_error_code = 500;
-	
-	&print_msg("*** COMMAND WAS: |$command|***\n", 4);
-	
-	return config($library_url, $command, $check_responsemsg_against_regex, $site, $expected_error_code, $silent);
+    my ($library_url, $command, $gs_mode, $site, $silent) = @_;
+    
+    # If the GS server is not running, we *expect* to see a "500" status code.
+    # If the GS server is running, then "Ping" ... "succeeded" is expected on success. 
+    # When pinging an inactive collection, it will say it did "not succeed". This is
+    # a message of interest to return.
+    my $check_responsemsg_against_regex = q/(succeeded)/;
+    my $expected_error_code = 500;
+    
+    &print_msg("*** COMMAND WAS: |$command|***\n", 4);
+    
+    return config($library_url, $command, $check_responsemsg_against_regex, $site, $expected_error_code, $silent);
 }
 
 # send a pingaction to the GS library. General server-level ping.
 sub ping_library {
-	my ($library_url, $gs_mode, $site) = @_;
-	
-	my $command = "";
-	if($gs_mode eq "gs2") {		
-		$command = "?a=ping";		
-	}
-	elsif ($gs_mode eq "gs3") {		
-		$command = "?a=s&sa=ping";
-	}
-	return &ping($library_url, $command, $gs_mode, $site);
+    my ($library_url, $gs_mode, $site) = @_;
+    
+    my $command = "";
+    if($gs_mode eq "gs2") {		
+	$command = "?a=ping";		
+    }
+    elsif ($gs_mode eq "gs3") {		
+	$command = "?a=s&sa=ping";
+    }
+    return &ping($library_url, $command, $gs_mode, $site);
 }
 
@@ -275,14 +275,14 @@
 # send a pingaction to a collection in GS library to check if it's active
 sub ping_library_collection {
-	my ($library_url, $gs_mode, $qualified_collection, $site, $silent) = @_;
-	
-	my $command = "";
-	if($gs_mode eq "gs2") {		
-		$command = "?a=ping&c=$qualified_collection";
-	}
-	elsif ($gs_mode eq "gs3") {		
-		$command = "?a=s&sa=ping&st=collection&sn=$qualified_collection";		
-	}
-	return &ping($library_url, $command, $gs_mode, $site, $silent);
+    my ($library_url, $gs_mode, $qualified_collection, $site, $silent) = @_;
+    
+    my $command = "";
+    if($gs_mode eq "gs2") {		
+	$command = "?a=ping&c=$qualified_collection";
+    }
+    elsif ($gs_mode eq "gs3") {		
+	$command = "?a=s&sa=ping&st=collection&sn=$qualified_collection";		
+    }
+    return &ping($library_url, $command, $gs_mode, $site, $silent);
 }
 
@@ -290,126 +290,126 @@
 # this is only for GS2, since the GS3 server is always persistent
 sub is_persistent {
-	my ($library_url, $gs_mode) = @_;
-	
-	if($gs_mode eq "gs3") { # GS3 server is always persistent
-		return 1;
-	}
-	
-	my $command = "?a=is-persistent";	
-	my $check_responsemsg_against_regex = q/true/;	# isPersistent: true versus isPersistent: false 	
-	return config($library_url, $command, $check_responsemsg_against_regex);
-}
-	
+    my ($library_url, $gs_mode) = @_;
+    
+    if($gs_mode eq "gs3") { # GS3 server is always persistent
+	return 1;
+    }
+    
+    my $command = "?a=is-persistent";	
+    my $check_responsemsg_against_regex = q/true/;	# isPersistent: true versus isPersistent: false 	
+    return config($library_url, $command, $check_responsemsg_against_regex);
+}
+
 sub get_library_URL {
-	my ($gs_mode, $lib_name) = @_; # gs_mode can be gs3 or gs2, lib_name is the custom servlet name
-	
-	# If we get here, we are dealing with a server included with GS.
-	# For GS3, we ask ant for the library URL.
-	# For GS2, we derive the URL from the llssite.cfg file.
-	
-	my $url = undef;	
-	
-	if($gs_mode eq "gs2") {		
-		my $llssite_cfg = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "llssite.cfg");
+    my ($gs_mode, $lib_name) = @_; # gs_mode can be gs3 or gs2, lib_name is the custom servlet name
+    
+    # If we get here, we are dealing with a server included with GS.
+    # For GS3, we ask ant for the library URL.
+    # For GS2, we derive the URL from the llssite.cfg file.
+    
+    my $url = undef;	
+    
+    if($gs_mode eq "gs2") {		
+	my $llssite_cfg = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "llssite.cfg");
+	
+	if(-f $llssite_cfg) {
+	    # check llssite.cfg for line with url property
+	    # for server.exe also need to use portnumber and enterlib properties			
+	    
+	    # Read in the entire contents of the file in one hit
+	    if (!open (FIN, $llssite_cfg)) {
+		&print_msg("activate.pl::get_library_URL failed to open $llssite_cfg ($!)\n");
+		return undef;
+	    }
+	    
+	    my $contents;
+	    sysread(FIN, $contents, -s FIN);			
+	    close(FIN);
+	    
+	    my @lines = split(/[\n\r]+/, $contents); # split on carriage-returns and/or linefeeds
+	    my $enterlib = "";
+	    my $portnumber = ""; # will remain empty (implicit port 80) unless it's specifically been assigned
+	    
+	    foreach my $line (@lines) {				
+		if($line =~ m/^url=(.*)$/) {
+		    $url = $1;					
+		} elsif($line =~ m/^enterlib=(.*)$/) {
+		    $enterlib = $1;					
+		} elsif($line =~ m/^portnumber=(.*)$/) {
+		    $portnumber = $1;					
+		}	
+	    }
+	    
+	    if(!$url) {
+		return undef;
+	    }
+	    elsif($url eq "URL_pending") { # library is not running
+		# do not process url=URL_pending in the file, since for server.exe 
+		# this just means the Enter Library button hasn't been pressed yet				
+		$url = undef;
+	    }
+	    else { 
+		# In the case of server.exe, need to do extra work to get the proper URL
+		# But first, need to know whether we're indeed dealing with server.exe:
 		
-		if(-f $llssite_cfg) {
-			# check llssite.cfg for line with url property
-			# for server.exe also need to use portnumber and enterlib properties			
-			
-			# Read in the entire contents of the file in one hit
-			if (!open (FIN, $llssite_cfg)) {
-				&print_msg("activate.pl::get_library_URL failed to open $llssite_cfg ($!)\n");
-				return undef;
-			}
-			
-			my $contents;
-			sysread(FIN, $contents, -s FIN);			
-			close(FIN);
-			
-			my @lines = split(/[\n\r]+/, $contents); # split on carriage-returns and/or linefeeds
-			my $enterlib = "";
-			my $portnumber = ""; # will remain empty (implicit port 80) unless it's specifically been assigned
-			
-			foreach my $line (@lines) {				
-				if($line =~ m/^url=(.*)$/) {
-					$url = $1;					
-				} elsif($line =~ m/^enterlib=(.*)$/) {
-					$enterlib = $1;					
-				} elsif($line =~ m/^portnumber=(.*)$/) {
-					$portnumber = $1;					
-				}	
-			}
-			
-			if(!$url) {
-				return undef;
-			}
-			elsif($url eq "URL_pending") { # library is not running
-				# do not process url=URL_pending in the file, since for server.exe 
-				# this just means the Enter Library button hasn't been pressed yet				
-				$url = undef;
-			}
-			else { 
-				# In the case of server.exe, need to do extra work to get the proper URL
-				# But first, need to know whether we're indeed dealing with server.exe:
+		# compare the URL's domain to the full URL
+		# E.g. for http://localhost:8383/greenstone3/cgi-bin, the domain is localhost:8383
+		my $uri = URI->new( $url );
+		my $host = $uri->host;
+		#print STDERR "@@@@@ host: $host\n";
+		if($url =~ m/http:\/\/$host(\/)?$/) {
+		    #if($url !~ m/http:\/\/$host:$portnumber(\/)?/ || $url =~ m/http:\/\/$host(\/)?$/) {
+		    # (if the URL does not contain the portnumber, OR if the port is implicitly 80 and)					
+		    # If the domain with http:// prefix is completely the same as the URL, assume server.exe
+		    # then the actual URL is the result of suffixing the port and enterlib properties in llssite.cfg
+		    $url = $url.":".$portnumber.$enterlib;			
+		} # else, apache web server			
 				
-				# compare the URL's domain to the full URL
-				# E.g. for http://localhost:8383/greenstone3/cgi-bin, the domain is localhost:8383
-				my $uri = URI->new( $url );
-				my $host = $uri->host;
-				#print STDERR "@@@@@ host: $host\n";
-				if($url =~ m/http:\/\/$host(\/)?$/) {
-					#if($url !~ m/http:\/\/$host:$portnumber(\/)?/ || $url =~ m/http:\/\/$host(\/)?$/) {
-					# (if the URL does not contain the portnumber, OR if the port is implicitly 80 and)					
-					# If the domain with http:// prefix is completely the same as the URL, assume server.exe
-					# then the actual URL is the result of suffixing the port and enterlib properties in llssite.cfg
-					$url = $url.":".$portnumber.$enterlib;			
-				} # else, apache web server			
-				
-			}			
-		}
-	} elsif($gs_mode eq "gs3") {
-		# Either check build.properties for tomcat.server, tomcat.port and app.name (and default servlet name).
-		# app.name is stored in app.path by build.xml. Need to move app.name in build.properties from build.xml
-		
-		# Or, run the new target get-default-servlet-url
-		# the output can look like:
-		#
-		# Buildfile: build.xml
-		# 	[echo] os.name: Windows Vista
-		#
-		# get-default-servlet-url:
-		#	[echo] http://localhost:8383/greenstone3/library
-		# BUILD SUCCESSFUL
-		# Total time: 0 seconds
-		
-		#my $output = qx/ant get-default-servlet-url/; # backtick operator, to get STDOUT (else 2>&1)
-			# see http://stackoverflow.com/questions/799968/whats-the-difference-between-perls-backticks-system-and-exec
-		
-	        # The get-default-servlet-url ant target can be run from anywhere by specifying the
-	        # location of GS3's ant build.xml buildfile. Activate.pl can be run from anywhere for GS3
-	        # GSDL3SRCHOME will be set for GS3 by gs3-setup.sh, a step that would have been necessary
-	        # to run the activate.pl script in the first place
-		my $perl_command = "ant -buildfile \"$ENV{'GSDL3SRCHOME'}/build.xml\" get-default-servlet-url";
-		
-		if (open(PIN, "$perl_command |")) {
-			while (defined (my $perl_output_line = <PIN>)) {
-				if($perl_output_line =~ m@http:\/\/(\S*)@) { # grab all the non-whitespace chars
-					$url="http://".$1;
-				}
-			}
-			close(PIN);
-		} else {
-			&print_msg("activate.pl::get_library_URL: Failed to run $perl_command to work out library URL for $gs_mode\n");
-		}
-		if(defined $lib_name) {
-		    # replace the servlet_name portion of the url found, with the given library_name
-		    $url =~ s@/[^/]*$@/$lib_name@;
-		}
-	}
-	
-	# either the url is still undef or it is now set
-	#print STDERR "\n@@@@@ final URL:|$url|\n" if $url;		
-	#print STDERR "\n@@@@@ URL still undef\n" if !$url;
-	return $url;
+	    }			
+	}
+    } elsif($gs_mode eq "gs3") {
+	# Either check build.properties for tomcat.server, tomcat.port and app.name (and default servlet name).
+	# app.name is stored in app.path by build.xml. Need to move app.name in build.properties from build.xml
+	
+	# Or, run the new target get-default-servlet-url
+	# the output can look like:
+	#
+	# Buildfile: build.xml
+	# 	[echo] os.name: Windows Vista
+	#
+	# get-default-servlet-url:
+	#	[echo] http://localhost:8383/greenstone3/library
+	# BUILD SUCCESSFUL
+	# Total time: 0 seconds
+	
+	#my $output = qx/ant get-default-servlet-url/; # backtick operator, to get STDOUT (else 2>&1)
+	# see http://stackoverflow.com/questions/799968/whats-the-difference-between-perls-backticks-system-and-exec
+	
+	# The get-default-servlet-url ant target can be run from anywhere by specifying the
+	# location of GS3's ant build.xml buildfile. Activate.pl can be run from anywhere for GS3
+	# GSDL3SRCHOME will be set for GS3 by gs3-setup.sh, a step that would have been necessary
+	# to run the activate.pl script in the first place
+	my $perl_command = "ant -buildfile \"$ENV{'GSDL3SRCHOME'}/build.xml\" get-default-servlet-url";
+	
+	if (open(PIN, "$perl_command |")) {
+	    while (defined (my $perl_output_line = <PIN>)) {
+		if($perl_output_line =~ m@http:\/\/(\S*)@) { # grab all the non-whitespace chars
+		    $url="http://".$1;
+		}
+	    }
+	    close(PIN);
+	} else {
+	    &print_msg("activate.pl::get_library_URL: Failed to run $perl_command to work out library URL for $gs_mode\n");
+	}
+	if(defined $lib_name) {
+	    # replace the servlet_name portion of the url found, with the given library_name
+	    $url =~ s@/[^/]*$@/$lib_name@;
+	}
+    }
+    
+    # either the url is still undef or it is now set
+    #print STDERR "\n@@@@@ final URL:|$url|\n" if $url;		
+    #print STDERR "\n@@@@@ URL still undef\n" if !$url;
+    return $url;
 }
 
@@ -421,46 +421,46 @@
 # and http://www.perlmonks.org/?node_id=618534
 sub is_URL_active {
-	my $url = shift(@_); # gs3 or gs2 URL	
-	
-	my $status = 0;
-	if(defined $url) {
-		$ua->timeout(10); # set LWP useragent to 5s max timeout for testing the URL
-			# Need to set this, else it takes I don't know how long to timeout 
-			# http://www.perlmonks.org/?node_id=618534
-		
-		$status = LWP::Simple::head($url); # returns empty list of headers if it fails
-				# LWP::Simple::get($url) is more intensive, so don't need to do that
-		#print STDERR "**** $url is alive.\n" if $status;
-	}
-	return $status;
+    my $url = shift(@_); # gs3 or gs2 URL	
+    
+    my $status = 0;
+    if(defined $url) {
+	$ua->timeout(10); # set LWP useragent to 5s max timeout for testing the URL
+	# Need to set this, else it takes I don't know how long to timeout 
+	# http://www.perlmonks.org/?node_id=618534
+	
+	$status = LWP::Simple::head($url); # returns empty list of headers if it fails
+	# LWP::Simple::get($url) is more intensive, so don't need to do that
+	#print STDERR "**** $url is alive.\n" if $status;
+    }
+    return $status;
 }
 
 # Pinging seems to always return true, so this method doesn't work
 sub pingHost {
-	my $url = shift(@_); # gs3 or gs2 URL
-	
-	my $status = 0;
-	if(defined $url) {
-		# Get just the domain. "http://localhost/gsdl?uq=332033495" becomes "localhost"
-		# "http://localhost/greenstone/cgi-bin/library.cgi" becomes "localhost" too	
-		
-		#my $host = $url;		
-		#$host =~ s@^http:\/\/(www.)?@@;		
-		#$host =~ s@\/.*@@;
-		#print STDERR "**** HOST: $host\n";
-		
-		# More robust way
-		# http://stackoverflow.com/questions/827024/how-do-i-extract-the-domain-out-of-an-url
-		my $uri = URI->new( $url );
-		my $host = $uri->host; 
-		
-		# Ping the host. http://perldoc.perl.org/Net/Ping.html	
-		my $p = Net::Ping->new();		
-		$status = $p->ping($host); # || 0. Appears to set to undef rather than 0
-		print STDERR "**** $host is alive.\n" if $status; #print "$host is alive.\n" if $p->ping($host);
-		$p->close();		
-	} 
-	# return whether pinging was a success or failure
-	return $status;
+    my $url = shift(@_); # gs3 or gs2 URL
+    
+    my $status = 0;
+    if(defined $url) {
+	# Get just the domain. "http://localhost/gsdl?uq=332033495" becomes "localhost"
+	# "http://localhost/greenstone/cgi-bin/library.cgi" becomes "localhost" too	
+	
+	#my $host = $url;		
+	#$host =~ s@^http:\/\/(www.)?@@;		
+	#$host =~ s@\/.*@@;
+	#print STDERR "**** HOST: $host\n";
+	
+	# More robust way
+	# http://stackoverflow.com/questions/827024/how-do-i-extract-the-domain-out-of-an-url
+	my $uri = URI->new( $url );
+	my $host = $uri->host; 
+	
+	# Ping the host. http://perldoc.perl.org/Net/Ping.html	
+	my $p = Net::Ping->new();		
+	$status = $p->ping($host); # || 0. Appears to set to undef rather than 0
+	print STDERR "**** $host is alive.\n" if $status; #print "$host is alive.\n" if $p->ping($host);
+	$p->close();		
+    } 
+    # return whether pinging was a success or failure
+    return $status;
 }
 
@@ -478,87 +478,87 @@
 
     if (($argc==0)  || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
-		my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
-
-
-		print STDERR "\n";
-		print STDERR "Usage: $progname [-collectdir c -builddir b -indexdir i -site s -skipactivation -removeold -keepold -verbosity v\n";
-		print STDERR "\t-library_url URL -library_name n] <[colgroup/]collection>\n";
-		print STDERR "\n";
-
-		exit(-1);
-    }
-	
-	# get the collection details
+	my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
+	
+	
+	print STDERR "\n";
+	print STDERR "Usage: $progname [-collectdir c -builddir b -indexdir i -site s -skipactivation -removeold -keepold -verbosity v\n";
+	print STDERR "\t-library_url URL -library_name n] <[colgroup/]collection>\n";
+	print STDERR "\n";
+	
+	exit(-1);
+    }
+	
+    # get the collection details
     my $qualified_collection = pop @argv; # qualified collection
-	
+    
     my $collect_dir = undef; #"collect"; # can't be "collect" when only -site is provided for GS3
     my $build_dir = undef;
-	my $index_dir = undef;
-	my $site = undef;
-	
-	# if run from server (java code), it will handle deactivation and activation to prevent open file handles when java launches this script and exits:
-	my $skipactivation = 0;
-	my $removeold = 0;
-	my $keepold = 0;
-	my $incremental = 0; # used by solr
-
-	my $library_url = $ENV{'GSDL_LIBRARY_URL'} || undef; # to be specified on the cmdline if not using a GS-included web server
-        # the GSDL_LIBRARY_URL env var is useful when running cmdline buildcol.pl in the linux package manager versions of GS3
-	
+    my $index_dir = undef;
+    my $site = undef;
+    
+    # if run from server (java code), it will handle deactivation and activation to prevent open file handles when java launches this script and exits:
+    my $skipactivation = 0;
+    my $removeold = 0;
+    my $keepold = 0;
+    my $incremental = 0; # used by solr
+    
+    my $library_url = $ENV{'GSDL_LIBRARY_URL'} || undef; # to be specified on the cmdline if not using a GS-included web server
+    # the GSDL_LIBRARY_URL env var is useful when running cmdline buildcol.pl in the linux package manager versions of GS3
+    
     my $library_name = undef;
-
+    
     while (my $arg = shift @argv) {
-		if ($arg eq "-collectdir") {
-			$collect_dir = shift @argv;
-		}
-		elsif ($arg eq "-builddir") {
-			$build_dir = shift @argv;
-		}
-		elsif ($arg eq "-indexdir") {
-			$index_dir = shift @argv;
-		}
-		elsif ($arg eq "-site") {
-			$site = shift @argv;
-		}
-		elsif ($arg eq "-skipactivation") {
-			$skipactivation = 1;
-		}
-		elsif ($arg eq "-removeold") {
-			$removeold = 1;
-		}
-		elsif ($arg eq "-keepold") {
-			$keepold = 1;
-		}
-		elsif ($arg eq "-incremental") {
-			$incremental = 1;
-		}
-		elsif ($arg eq "-library_url") {
-			$library_url = shift @argv;
-		}
-		elsif ($arg eq "-library_name") {
-			$library_name = shift @argv;
-		}
-		elsif ($arg eq "-verbosity") { 
-			$default_verbosity = shift @argv; # global variable
-			
-			# ensure we're working with ints not strings (int context not str context), in case verbosity=0
-			# http://stackoverflow.com/questions/288900/how-can-i-convert-a-string-to-a-number-in-perl
-			$default_verbosity = int($default_verbosity || 0); ### is this the best way?
-		}
-    }
-	
-	# work out the building and index dirs
-	my $collection_dir = &util::resolve_collection_dir($collect_dir, $qualified_collection, $site);
-	$build_dir = &FileUtils::filenameConcatenate($collection_dir, "building") unless (defined $build_dir);
-	$index_dir = &FileUtils::filenameConcatenate($collection_dir, "index") unless (defined $index_dir);
-	
-	&print_task_msg("Running  Collection  Activation  Stage");
+	if ($arg eq "-collectdir") {
+	    $collect_dir = shift @argv;
+	}
+	elsif ($arg eq "-builddir") {
+	    $build_dir = shift @argv;
+	}
+	elsif ($arg eq "-indexdir") {
+	    $index_dir = shift @argv;
+	}
+	elsif ($arg eq "-site") {
+	    $site = shift @argv;
+	}
+	elsif ($arg eq "-skipactivation") {
+	    $skipactivation = 1;
+	}
+	elsif ($arg eq "-removeold") {
+	    $removeold = 1;
+	}
+	elsif ($arg eq "-keepold") {
+	    $keepold = 1;
+	}
+	elsif ($arg eq "-incremental") {
+	    $incremental = 1;
+	}
+	elsif ($arg eq "-library_url") {
+	    $library_url = shift @argv;
+	}
+	elsif ($arg eq "-library_name") {
+	    $library_name = shift @argv;
+	}
+	elsif ($arg eq "-verbosity") { 
+	    $default_verbosity = shift @argv; # global variable
+	    
+	    # ensure we're working with ints not strings (int context not str context), in case verbosity=0
+	    # http://stackoverflow.com/questions/288900/how-can-i-convert-a-string-to-a-number-in-perl
+	    $default_verbosity = int($default_verbosity || 0); ### is this the best way?
+	}
+    }
+    
+    # work out the building and index dirs
+    my $collection_dir = &util::resolve_collection_dir($collect_dir, $qualified_collection, $site);
+    $build_dir = &FileUtils::filenameConcatenate($collection_dir, "building") unless (defined $build_dir);
+    $index_dir = &FileUtils::filenameConcatenate($collection_dir, "index") unless (defined $index_dir);
+    
+    &print_task_msg("Running  Collection  Activation  Stage");
     
     # get and check the collection name
     if ((&colcfg::use_collection($site, $qualified_collection, $collect_dir)) eq "") {
-		&print_msg("Unable to use collection \"$qualified_collection\" within \"$collect_dir\"\n");
-		exit -1;
-    }
-	
+	&print_msg("Unable to use collection \"$qualified_collection\" within \"$collect_dir\"\n");
+	exit -1;
+    }
+    
     # Read in the collection configuration file.
     # Beware: Only if $site is specified in the cmdline does collectionConfig.xml get 
@@ -570,20 +570,20 @@
     my $collect_cfg_filename = &colcfg::get_collect_cfg_name(STDERR, $gs_mode);
     my $collectcfg = &colcfg::read_collection_cfg ($collect_cfg_filename,$gs_mode);
-
+    
     # look for build.cfg/buildConfig.xml
     my $build_cfg_filename ="";	
-	
+    
     if ($gs_mode eq "gs2") {
-		$build_cfg_filename = &FileUtils::filenameConcatenate($build_dir,"build.cfg");
+	$build_cfg_filename = &FileUtils::filenameConcatenate($build_dir,"build.cfg");
     } else {
-		$build_cfg_filename = &FileUtils::filenameConcatenate($build_dir, "buildConfig.xml");
-		# gs_mode is GS3. Set the site now if this was not specified as cmdline argument
-		#$site = "localsite" unless defined $site;
-    }
-	
+	$build_cfg_filename = &FileUtils::filenameConcatenate($build_dir, "buildConfig.xml");
+	# gs_mode is GS3. Set the site now if this was not specified as cmdline argument
+	#$site = "localsite" unless defined $site;
+    }
+    
     # We need to know the buildtype for Solr.
     # Any change of indexers is already detected and handled by the calling code (buildcol or 
     # full-rebuild), so that at this stage the config file's buildtype reflects the actual buildtype.
-
+    
     # From buildcol.pl we use searchtype for determining buildtype, but for old versions, use buildtype
     my $buildtype;
@@ -607,54 +607,54 @@
     }
     
-	# Now the logic in GLI's CollectionManager.java	(processComplete() 
-	# and installCollection()) and Gatherer.configGS3Server().
-
-	# 1. Get library URL
-	
-	# For web servers that are external to a Greenstone installation, 
-	# the user can pass in their web server's library URL.
-	# For web servers included with GS (like tomcat for GS3 and server.exe 
-	# and apache for GS2), we work out the library URL:
-	if(!$library_url) { 
-		$library_url = &get_library_URL($gs_mode, $library_name); # returns undef if no server is running
-	}
-	
-	# CollectionManager's installCollection phase in GLI
-	# 2. Ping the library URL, and if it's a persistent server and running, release the collection
-	
-	my $is_persistent_server = undef;
-	if(!$skipactivation && $library_url) { # undef if no valid server URL
-
-		&print_msg("Pinging $library_url\n");		
-		if (&ping_library($library_url, $gs_mode, $site)) { # server running
+    # Now the logic in GLI's CollectionManager.java	(processComplete() 
+    # and installCollection()) and Gatherer.configGS3Server().
+    
+    # 1. Get library URL
+    
+    # For web servers that are external to a Greenstone installation, 
+    # the user can pass in their web server's library URL.
+    # For web servers included with GS (like tomcat for GS3 and server.exe 
+    # and apache for GS2), we work out the library URL:
+    if(!$library_url) { 
+	$library_url = &get_library_URL($gs_mode, $library_name); # returns undef if no server is running
+    }
+    
+    # CollectionManager's installCollection phase in GLI
+    # 2. Ping the library URL, and if it's a persistent server and running, release the collection
+    
+    my $is_persistent_server = undef;
+    if(!$skipactivation && $library_url) { # undef if no valid server URL
+	
+	&print_msg("Pinging $library_url\n");		
+	if (&ping_library($library_url, $gs_mode, $site)) { # server running
+	    
+	    # server is running, so release the collection if 
+	    # the server is persistent and the collection is active
+	    &print_msg("Checking if Greenstone server is persistent\n");
+	    $is_persistent_server = &is_persistent($library_url, $gs_mode);			
+	    
+	    if ($is_persistent_server) { # only makes sense to issue activate and deactivate cmds to a persistent server
 		
-			# server is running, so release the collection if 
-			# the server is persistent and the collection is active
-			&print_msg("Checking if Greenstone server is persistent\n");
-			$is_persistent_server = &is_persistent($library_url, $gs_mode);			
-			
-			if ($is_persistent_server) { # only makes sense to issue activate and deactivate cmds to a persistent server
-			    
-			    &print_msg("Checking if the collection $qualified_collection is already active\n");
-			    my $collection_active = &ping_library_collection($library_url, $gs_mode, $qualified_collection, $site);
-
-			    if ($collection_active) {
-				&print_msg("De-activating collection $qualified_collection\n");
-				&deactivate_collection($library_url, $gs_mode, $qualified_collection, $site);
-			    }
-			    else {
-				&print_msg("Collection is not active => No need to deactivate\n");
-			    }
-			}
-			else {
-			    &print_msg("Server is not persistent => No need to deactivate collection\n");
-			}
+		&print_msg("Checking if the collection $qualified_collection is already active\n");
+		my $collection_active = &ping_library_collection($library_url, $gs_mode, $qualified_collection, $site);
+		
+		if ($collection_active) {
+		    &print_msg("De-activating collection $qualified_collection\n");
+		    &deactivate_collection($library_url, $gs_mode, $qualified_collection, $site);
 		}
 		else {
-		    &print_msg("No response to Ping => Taken to mean server is not running\n");
-		}
-
-	}
-
+		    &print_msg("Collection is not active => No need to deactivate\n");
+		}
+	    }
+	    else {
+		&print_msg("Server is not persistent => No need to deactivate collection\n");
+	    }
+	}
+	else {
+	    &print_msg("No response to Ping => Taken to mean server is not running\n");
+	}
+	
+    }
+    
     # 2b. If we're working with a solr collection, then start up the solrserver now.
     my $solr_server;
@@ -681,5 +681,5 @@
 	$solr_server = new solrserver($build_dir);
 	$solr_server->start();
-
+	
 	# We'll be moving building to index. For solr collection, there's further 
 	# special processing to make a corresponding change to the solr.xml
@@ -688,73 +688,73 @@
 
 
-	# 3. Do all the moving building to index stuff now	
-
-	# If removeold: replace index dir with building dir.
-	# If keepold: move building's contents into index, where only duplicates will get deleted.
-	# removeold and keepold can't both be on at the same time
-        # incremental becomes relevant for solr, though it was irrelevant to what activate.pl does (moving building to index)
-	my $incremental_mode;
-	($removeold, $keepold, $incremental, $incremental_mode) = &scriptutil::check_removeold_and_keepold($removeold, $keepold, 
+    # 3. Do all the moving building to index stuff now	
+    
+    # If removeold: replace index dir with building dir.
+    # If keepold: move building's contents into index, where only duplicates will get deleted.
+    # removeold and keepold can't both be on at the same time
+    # incremental becomes relevant for solr, though it was irrelevant to what activate.pl does (moving building to index)
+    my $incremental_mode;
+    ($removeold, $keepold, $incremental, $incremental_mode) = &scriptutil::check_removeold_and_keepold($removeold, $keepold, 
 						   $incremental,
 						   $build_dir, # checkdir. Usually archives or export to be deleted. activate.pl deletes building 
 						   $collectcfg);
 	
-	if($removeold) {
-	    
-		if(&FileUtils::directoryExists($index_dir)) {
-			&print_task_msg("Removing \"index\"");
-
-			if ($buildtype eq "solr") {
-			    # if solr, remove any cores that are using the index_dir before deleting this dir
-			    foreach my $corename (@corenames) {
-				$solr_server->admin_unload_core($corename);
-			    }
-			}	
-
-			&FileUtils::removeFilesRecursive($index_dir);
-			
-			# Wait for a couple of seconds, just for luck
-			sleep 2;
-			
-			if (&FileUtils::directoryExists($index_dir)) {
-				&print_msg("The index directory $index_dir could not be deleted.\n"); # CollectionManager.Index_Not_Deleted
-			}
-		}
-		
-		# if remote GS server: gliserver.pl would call activate.pl to activate 
-		# the collection at this point since activate.pl lives on the server side
-		
-		if ($buildtype eq "solr") {
-		    # if solr, remove any cores that are using the building_dir before moving this dir onto index
-		    foreach my $corename (@corenames) {
-			$solr_server->admin_unload_core("building-$corename");
-		    }
-		}
-
-		# Move the building directory to become the new index directory
-		&print_task_msg("Moving \"building\" -> \"index\"");
-		&FileUtils::moveFiles($build_dir, $index_dir);
-		if(&FileUtils::directoryExists($build_dir) || !&FileUtils::directoryExists($index_dir)) {			
-			&print_msg("Could not move $build_dir to $index_dir.\n"); # CollectionManager.Build_Not_Moved
-		}
-	}
-	elsif ($keepold || $incremental) {
-	    	if ($buildtype eq "solr") {
-		    # if solr, remove any cores that may be using the building_dir before moving this dir onto index
-		    foreach my $corename (@corenames) {			
-			$solr_server->admin_unload_core("building-$corename") if $solr_server->admin_ping_core("building-$corename");
-		    }
-		}
-	    
-		if($build_dir eq $index_dir) { # building_dir can have been set to "index" folder, see incremental-buildcol.pl
-		    &print_task_msg("building folder is index folder, not moving");
-		} else {
-		    # Copy just the contents of building dir into the index dir, overwriting 
-		    # existing files, but don't replace index with building.
-		    &print_task_msg("Moving \"building\" -> \"index\"");		
-		    &FileUtils::moveDirectoryContents($build_dir, $index_dir);
-		}
-	}
-
+    if($removeold) {
+	
+	if(&FileUtils::directoryExists($index_dir)) {
+	    &print_task_msg("Removing \"index\"");
+	    
+	    if ($buildtype eq "solr") {
+		# if solr, remove any cores that are using the index_dir before deleting this dir
+		foreach my $corename (@corenames) {
+		    $solr_server->admin_unload_core($corename);
+		}
+	    }	
+	    
+	    &FileUtils::removeFilesRecursive($index_dir);
+	    
+	    # Wait for a couple of seconds, just for luck
+	    sleep 2;
+	    
+	    if (&FileUtils::directoryExists($index_dir)) {
+		&print_msg("The index directory $index_dir could not be deleted.\n"); # CollectionManager.Index_Not_Deleted
+	    }
+	}
+	
+	# if remote GS server: gliserver.pl would call activate.pl to activate 
+	# the collection at this point since activate.pl lives on the server side
+	
+	if ($buildtype eq "solr") {
+	    # if solr, remove any cores that are using the building_dir before moving this dir onto index
+	    foreach my $corename (@corenames) {
+		$solr_server->admin_unload_core("building-$corename");
+	    }
+	}
+	
+	# Move the building directory to become the new index directory
+	&print_task_msg("Moving \"building\" -> \"index\"");
+	&FileUtils::moveFiles($build_dir, $index_dir);
+	if(&FileUtils::directoryExists($build_dir) || !&FileUtils::directoryExists($index_dir)) {			
+	    &print_msg("Could not move $build_dir to $index_dir.\n"); # CollectionManager.Build_Not_Moved
+	}
+    }
+    elsif ($keepold || $incremental) {
+	if ($buildtype eq "solr") {
+	    # if solr, remove any cores that may be using the building_dir before moving this dir onto index
+	    foreach my $corename (@corenames) {			
+		$solr_server->admin_unload_core("building-$corename") if $solr_server->admin_ping_core("building-$corename");
+	    }
+	}
+	
+	if($build_dir eq $index_dir) { # building_dir can have been set to "index" folder, see incremental-buildcol.pl
+	    &print_task_msg("building folder is index folder, not moving");
+	} else {
+	    # Copy just the contents of building dir into the index dir, overwriting 
+	    # existing files, but don't replace index with building.
+	    &print_task_msg("Moving \"building\" -> \"index\"");		
+	    &FileUtils::moveDirectoryContents($build_dir, $index_dir);
+	}
+    }
+    
     if ($buildtype eq "solr") {
 	# Call CREATE action to get the old cores pointing to the index folder
@@ -775,67 +775,67 @@
 	    }
 	}
-
+	
 	# regenerate the solr.xml.in from solr.xml in case we are working off a dvd. 
 	$solr_server->solr_xml_to_solr_xml_in();
     }
-
-	# 4. Ping the library URL, and if it's a persistent server and running, activate the collection again	
-	
-	# Check for success: if building does not exist OR is empty OR if building is index (in which case there was no move)	
-	if($build_dir eq $index_dir || !&FileUtils::directoryExists($build_dir) || &FileUtils::isDirectoryEmpty($build_dir)) {
-	
-		if(!$skipactivation && $library_url) { # undef if no valid server URL
+    
+    # 4. Ping the library URL, and if it's a persistent server and running, activate the collection again	
+    
+    # Check for success: if building does not exist OR is empty OR if building is index (in which case there was no move)	
+    if($build_dir eq $index_dir || !&FileUtils::directoryExists($build_dir) || &FileUtils::isDirectoryEmpty($build_dir)) {
+	
+	if(!$skipactivation && $library_url) { # undef if no valid server URL
+	    
+	    &print_msg("Pinging $library_url\n");
+	    if (&ping_library($library_url, $gs_mode, $site)) { # server running
 		
-			&print_msg("Pinging $library_url\n");
-			if (&ping_library($library_url, $gs_mode, $site)) { # server running
+		# don't need to work out persistency of server more than once, since the libraryURL hasn't changed				
+		if (!defined $is_persistent_server) {
+		    &print_msg("Checking if Greenstone server is persistent\n");
+		    $is_persistent_server = &is_persistent($library_url, $gs_mode);
+		}
+		
+		
+		if ($is_persistent_server) { # persistent server, so can try activating collection
+		    
+		    &print_msg("Checking if the collection $qualified_collection is not already active\n");
+		    
+		    # Since we could have deactivated the collection at this point,
+		    # it is likely that it is not yet active. When pinging the collection
+		    # a "ping did not succeed" message is expected, therefore tell the ping
+		    # to proceed silently
+		    my $silent = 1;
+		    my $collection_active = &ping_library_collection($library_url, $gs_mode, $qualified_collection, $site, $silent);
+		    
+		    if (!$collection_active) {
+			&print_msg(" Collection is not active.\n");
+			&print_msg("Activating collection $qualified_collection\n");
+			&activate_collection($library_url, $gs_mode, $qualified_collection, $site);
 			
-				# don't need to work out persistency of server more than once, since the libraryURL hasn't changed				
-				if (!defined $is_persistent_server) {
-					&print_msg("Checking if Greenstone server is persistent\n");
-					$is_persistent_server = &is_persistent($library_url, $gs_mode);
-				}
-				
-					
-				if ($is_persistent_server) { # persistent server, so can try activating collection
-
-				    &print_msg("Checking if the collection $qualified_collection is not already active\n");
-
-				    # Since we could have deactivated the collection at this point,
-				    # it is likely that it is not yet active. When pinging the collection
-				    # a "ping did not succeed" message is expected, therefore tell the ping
-				    # to proceed silently
-				    my $silent = 1;
-				    my $collection_active = &ping_library_collection($library_url, $gs_mode, $qualified_collection, $site, $silent);
-
-				    if (!$collection_active) {
-					&print_msg(" Collection is not active.\n");
-					&print_msg("Activating collection $qualified_collection\n");
-					&activate_collection($library_url, $gs_mode, $qualified_collection, $site);
-					
-					# unless an error occurred, the collection should now be active:
-					$collection_active = &ping_library_collection($library_url, $gs_mode, $qualified_collection, $site); # not silent if ping did not succeed
-					if(!$collection_active) {
-					    &print_msg("ERROR: collection $qualified_collection did not get activated\n");
-					}
-				    }
-				    else {
-					&print_msg("Collection is already active => No need to activate\n");
-				    }
-				}
-				else {
-				    &print_msg("Server is not persistent => No need to activate collection\n");
-				}
+			# unless an error occurred, the collection should now be active:
+			$collection_active = &ping_library_collection($library_url, $gs_mode, $qualified_collection, $site); # not silent if ping did not succeed
+			if(!$collection_active) {
+			    &print_msg("ERROR: collection $qualified_collection did not get activated\n");
 			}
-			else {
-			    &print_msg("No response to Ping => Taken to mean server is not running\n");
-			}
-		}
-	} else { # installcollection failed		
-		#CollectionManager.Preview_Ready_Failed
-		&print_msg("Building directory is not empty or still exists. Failed to properly move $build_dir to $index_dir.\n");
-	}
-
+		    }
+		    else {
+			&print_msg("Collection is already active => No need to activate\n");
+		    }
+		}
+		else {
+		    &print_msg("Server is not persistent => No need to activate collection\n");
+		}
+	    }
+	    else {
+		&print_msg("No response to Ping => Taken to mean server is not running\n");
+	    }
+	}
+    } else { # installcollection failed		
+	#CollectionManager.Preview_Ready_Failed
+	&print_msg("Building directory is not empty or still exists. Failed to properly move $build_dir to $index_dir.\n");
+    }
+    
     &print_msg("\n");
-
+    
     if($buildtype eq "solr") {
 	if ($solr_server->explicitly_started()) {
