Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Generating anonymous psf file using PERL script

{{#eclipseproject:technology.higgins|eclipse_custom_style.css}}

  • Save the following script as generatePSF.pl
#!/usr/bin/perl -w

use IO::File;
use strict;

my $cvsloc = "http://dev.eclipse.org/viewcvs/index.cgi";
my %RES = ();
my %PROJECTS = ();

my %DONE = ();
my $fh;

sub generatePSF {
	my $p = shift;
	
	print STDOUT "Generating ${p}.psf\n";
	
	$fh = new IO::File("${p}.psf", "w") or die $!;
	print $fh <<PSF;
<?xml version="1.0" encoding="UTF-8"?>
<psf version="2.0">
<provider id="org.eclipse.team.cvs.core.cvsnature">
PSF

	%DONE = ();
	getDependencies($p);

	print $fh <<PSF2;
</provider>
</psf>
PSF2
	close($fh);
}

sub getDependencies {
	my ($id) = shift;
	my %deps = getDependenciesFromCVS($id);
	print $fh "<project reference=\"1.0,$RES{$id}{REPLOC},$RES{$id}{PATH},$id,$RES{$id}{VERSION}\"/>\n" unless $DONE{$id};
	$DONE{$id}++;
	foreach my $d(keys %{$deps{$id}}) {
		getDependencies($d) unless $DONE{$d};
	}
}

sub getDependenciesFromCVS {
	my ($pn) = shift;
	
	my %DEP = ();
	
	return %DEP unless $pn;
	
	my $dependencies_xml_url = "${cvsloc}/$RES{$pn}{PATH}/dependencies.xml?root=Technology_Project\\\&view=co";
	my $dependencies_xml_local = "${pn}.dependencies.xml";
	
	system("wget -o wget.tmp -O $dependencies_xml_local $dependencies_xml_url");
	open(D, $dependencies_xml_local) or die $!;
	my $proj = "";
	while(my $ln = <D>) {
		chomp $ln;
		if($ln =~ /<dependencies/) {
			($proj) = $ln =~ /id=\"(.*?)\"/; $proj =~ s/\s+//g;
		}
		elsif($ln =~ /<project/) {
			my ($dep) = $ln =~ /id=\"(.*?)\"/; $dep =~ s/\s+//g;
			$DEP{$proj}{$dep} = 1;
		}
	}
	close(D);
	unlink("wget.tmp");
	unlink($dependencies_xml_local);
	
	return %DEP;
}

if(@ARGV < 3) {
	print "Usage: $0 project_name path_to_projects_xml path_to_resourcelocation_xml\n";
	exit(0);
}

my ($project_name, $project_xml, $resourceloc_xml) = @ARGV;

open(P, $project_xml) or die $!;
while(my $ln = <P>) {
	chomp $ln;
	if($ln =~ /id=/) {
		my ($id) = $ln =~ /id=\"(.*?)\"/; $id =~ s/\s+//g;
		$PROJECTS{$id} = 1;
	}
}
close(P);

my $found = 0;
my $buf = "";

open(R, $resourceloc_xml) or die $!;
while(my $ln = <R>) {
	chomp $ln;
	if($ln =~ /<project/) {
		$found = 1;
		$buf = "";		
	}
	elsif($ln =~ /<\/project>/) {
		$found = 0;
		my ($id) = $buf =~ /id=\"(.*?)\"/; $id =~ s/\s+//g;
		my ($ver) = $buf =~ /<version>(.*?)<\/version>/; $ver =~ s/\s+//g;
		my ($reploc) = $buf =~ /<repositoryLocation>(.*?)<\/repositoryLocation>/; $reploc =~ s/\s+//g;
		my ($path) = $buf =~ /<path>(.*?)<\/path>/; $path =~ s/\s+//g;
		$RES{$id}{VERSION} = $ver;
		$RES{$id}{REPLOC} = $reploc;
		$RES{$id}{PATH} = $path;
		#print "$id ** $ver ** $reploc ** $path\n";
	}
	
	if($found) {
		$buf .= $ln;	
	}
}
close(R);

if($project_name eq "all") {
	foreach my $p(keys %PROJECTS) {
		generatePSF($p);	
	}
}
else {
	generatePSF($project_name);	
}
 ./generatePSF.pl  project_name  path_to_projects_xml path_to_resourcelocation_xml

 e.g:
 ./generatePSF.pl org.eclipse.higgins.idas.cp.jndi projects.xml  resourceLocation.xml
 
 or
 
 ./generatePSF.pl all projects.xml  resourceLocation.xml

If you pass project_name=all, the script will generate psf for all projects in projects.xml, otherwise it will generate psf for the project specified

Note: This script requires PERL and wget installed on your machine. You can get both PERL and wget by installing cygwin from http://www.cygwin.com on Windows

Back to the top