ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/BootStrapProject.pm
Revision: 1.12
Committed: Tue Nov 6 14:13:51 2007 UTC (17 years, 6 months ago) by muzaffar
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD_SM_071214, v103_xml_071106
Branch point for: HEAD_BRANCH_SM_071214
Changes since 1.11: +4 -3 lines
Log Message:
xml scram with changes to make it fast

File Contents

# User Rev Content
1 sashby 1.7 =head1 NAME
2    
3     Configuration::BootStrapProject - File parsing utilities for boot files.
4    
5     =head1 SYNOPSIS
6    
7     my $obj = Configuration::BootStrapProject->new([$area]);
8    
9     =head1 DESCRIPTION
10    
11     Package containing functions for parsing bootstrap files (project initialisation documents).
12 muzaffar 1.12
13 sashby 1.7 =head1 METHODS
14    
15     =over
16    
17     =cut
18    
19     =item C<new($cache,$installbase)>
20    
21     A new bootstrapper.
22    
23     =item C<boot(url[,$devareaname])>
24    
25     Boot up a new project and return the Configuration::ConfigArea.
26    
27     =back
28    
29     =head1 AUTHOR
30    
31     Originally written by Christopher Williams.
32    
33     =head1 MAINTAINER
34    
35     Shaun ASHBY
36    
37     =cut
38 williamc 1.2
39     package Configuration::BootStrapProject;
40     use ActiveDoc::SimpleURLDoc;
41     use URL::URLhandler;
42     use Utilities::Verbose;
43     require 5.004;
44    
45     @ISA=qw(Utilities::Verbose);
46 sashby 1.10 $Configuration::BootStrapProject::self;
47 williamc 1.2
48 sashby 1.10 sub new()
49 sashby 1.5 {
50 sashby 1.10 my $class=shift;
51     # Initialise the global package variable:
52     no strict 'refs';
53     $self = defined $self ? $self
54     : (bless {}, $class );
55     $self->{havesourcedir}=0;
56     $self->{cache}=shift;
57     $self->{baselocation}=shift;
58    
59     if ( @_ )
60     {
61     $self->{area}=shift;
62     }
63    
64     $self->{mydoctype}="Configuration::BootStrapProject";
65     $self->{mydocversion}="1.0";
66     $self->{scramdoc} = ActiveDoc::SimpleURLDoc->new($self->{cache});
67     $self->{scramdoc}->newparse("bootstrap",$self->{mydoctype},'Subs');
68     $self->{Arch}=1;
69     push @{$self->{ARCHBLOCK}}, $self->{Arch};
70     return $self;
71 sashby 1.5 }
72    
73 sashby 1.10 sub boot()
74 sashby 1.5 {
75     my $self=shift;
76     my $url=shift;
77 sashby 1.10 my $filemode = 0644;
78     # Check that the boot file is XML (simplistic check: make sure file
79     # suffix is xml!):
80     if ($url !~ /xml$/) {
81     die __PACKAGE__.": Wrong boot file type (MUST be XML!)\n";
82     }
83    
84     # -- override directory name
85     if ( @_ )
86     {
87     $self->{devareaname}=shift;
88     }
89     else
90     {
91     $self->{devareaname}="";
92     }
93    
94     my ($fullurl,$filename)=$self->{scramdoc}->urldownload($url);
95 sashby 1.6 chmod $filemode,$filename;
96 sashby 1.10 $self->{scramdoc}->filetoparse($filename);
97 muzaffar 1.12 my $fhead='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc type="Configuration::BootStrapProject" version="1.0">';
98     my $ftail='</doc>';
99     $self->{scramdoc}->parse("bootstrap",$fhead,$ftail);
100 sashby 1.5 return $self->{area};
101     }
102    
103 williamc 1.2 # --- Tag Routines
104 sashby 1.10 sub project()
105     {
106     my ($xmlparser,$name,%attributes)=@_;
107     my $name = $attributes{'name'};
108     my $version = $attributes{'version'};
109    
110     print "Creating New Project ".$name.
111     " Version ".$version."\n";
112     print "\n";
113    
114     use Configuration::ConfigArea;
115     $self->{area}=Configuration::ConfigArea->new();
116    
117     $self->{area}->name($name);
118     $self->{area}->version($version);
119     $self->{area}->setup($self->{baselocation});
120    
121     # new urlhandler based on area cache
122     $self->{scramdoc}->cache($self->{area}->cache());
123     }
124 williamc 1.2
125 sashby 1.10 sub project_()
126     {
127     my ($xmlparser,$name,%attributes)=@_;
128     $self->{area}->sourcedir('src');
129     $ENV{SCRAM_SOURCEDIR} = $self->{area}->sourcedir();
130     $self->{area}->save();
131     }
132 williamc 1.2
133 sashby 1.10 sub config()
134 sashby 1.4 {
135 sashby 1.10 my ($xmlparser,$name,%attributes)=@_;
136 sashby 1.4 # Set the project config dir variable here so that
137     # "projconfigdir" value can be used while bootstrapping:
138 sashby 1.10 $ENV{SCRAM_CONFIGDIR} = $attributes{'dir'};
139     $self->{area}->configurationdir($attributes{'dir'});
140 sashby 1.4 }
141 williamc 1.2
142 sashby 1.10 sub download()
143     {
144     my ($xmlparser,$name,%attributes)=@_;
145     # -- download into top directory
146     my ($fullurl,$filename)=$self->{scramdoc}->urlget($attributes{'url'},
147     $self->{area}->location()."/".$attributes{'name'});
148     }
149 williamc 1.2
150 sashby 1.10 sub requirementsdoc() {
151     my ($xmlparser,$name,%attributes)=@_;
152     my ($filename,$fullurl);
153    
154     if ( exists $attributes{'url'} ) {
155 sashby 1.9 # -- download into our cache
156 sashby 1.10 ($fullurl,$filename)=$self->{scramdoc}->urlget($attributes{'url'});
157     } else {
158     $filename=$attributes{'name'};
159     }
160    
161     # Check that the requirements file is XML (simplistic check: make sure file
162     # suffix is xml!):
163     if ($filename !~ /xml$/) {
164     # We have to use exit here because die() doesn't respond...I guess
165     # that SIG{__DIE__} has been trapped somewhere:
166     print __PACKAGE__.": Wrong requirements file type (MUST be XML!)\n";
167     exit(1);
168     }
169    
170     $self->{area}->requirementsdoc($filename);
171 williamc 1.2 }
172    
173 sashby 1.10 sub doc()
174     {
175     my ($xmlparser,$name,%attributes)=@_;
176     my $doctype = $attributes{'type'};
177 sashby 1.5
178 sashby 1.10 if ($doctype ne $self->{mydoctype})
179     {
180     warn "Configuration::BootStrapProject::boot: Unable to handle doc of type $doctype";
181     }
182     }
183 sashby 1.5
184 sashby 1.10 sub AUTOLOAD()
185     {
186     my ($xmlparser,$name,%attributes)=@_;
187     return if $AUTOLOAD =~ /::DESTROY$/;
188     my $name=$AUTOLOAD;
189     $name =~ s/.*://;
190     if ($name eq 'base' || $name eq 'base_')
191     {
192     $self->{scramdoc}->$name(%attributes);
193     }
194 sashby 1.5 }
195    
196 sashby 1.10 1;