ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/BootStrapProject.pm
Revision: 1.10
Committed: Tue Feb 27 11:59:47 2007 UTC (18 years, 2 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.9: +122 -231 lines
Log Message:
Merged from XML branch to HEAD. Start release prep.

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    
13     =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     $self->{scramdoc}->parse("bootstrap");
98 sashby 1.5 return $self->{area};
99     }
100    
101 williamc 1.2 # --- Tag Routines
102 sashby 1.10 sub project()
103     {
104     my ($xmlparser,$name,%attributes)=@_;
105     my $name = $attributes{'name'};
106     my $version = $attributes{'version'};
107    
108     print "Creating New Project ".$name.
109     " Version ".$version."\n";
110     print "\n";
111    
112     use Configuration::ConfigArea;
113     $self->{area}=Configuration::ConfigArea->new();
114    
115     $self->{area}->name($name);
116     $self->{area}->version($version);
117     $self->{area}->setup($self->{baselocation});
118    
119     # new urlhandler based on area cache
120     $self->{scramdoc}->cache($self->{area}->cache());
121     }
122 williamc 1.2
123 sashby 1.10 sub project_()
124     {
125     my ($xmlparser,$name,%attributes)=@_;
126     $self->{area}->sourcedir('src');
127     $ENV{SCRAM_SOURCEDIR} = $self->{area}->sourcedir();
128     $self->{area}->save();
129     }
130 williamc 1.2
131 sashby 1.10 sub config()
132 sashby 1.4 {
133 sashby 1.10 my ($xmlparser,$name,%attributes)=@_;
134 sashby 1.4 # Set the project config dir variable here so that
135     # "projconfigdir" value can be used while bootstrapping:
136 sashby 1.10 $ENV{SCRAM_CONFIGDIR} = $attributes{'dir'};
137     $self->{area}->configurationdir($attributes{'dir'});
138 sashby 1.4 }
139 williamc 1.2
140 sashby 1.10 sub download()
141     {
142     my ($xmlparser,$name,%attributes)=@_;
143     # -- download into top directory
144     my ($fullurl,$filename)=$self->{scramdoc}->urlget($attributes{'url'},
145     $self->{area}->location()."/".$attributes{'name'});
146     }
147 williamc 1.2
148 sashby 1.10 sub requirementsdoc() {
149     my ($xmlparser,$name,%attributes)=@_;
150     my ($filename,$fullurl);
151    
152     if ( exists $attributes{'url'} ) {
153 sashby 1.9 # -- download into our cache
154 sashby 1.10 ($fullurl,$filename)=$self->{scramdoc}->urlget($attributes{'url'});
155     } else {
156     $filename=$attributes{'name'};
157     }
158    
159     # Check that the requirements file is XML (simplistic check: make sure file
160     # suffix is xml!):
161     if ($filename !~ /xml$/) {
162     # We have to use exit here because die() doesn't respond...I guess
163     # that SIG{__DIE__} has been trapped somewhere:
164     print __PACKAGE__.": Wrong requirements file type (MUST be XML!)\n";
165     exit(1);
166     }
167    
168     $self->{area}->requirementsdoc($filename);
169 williamc 1.2 }
170    
171 sashby 1.10 sub doc()
172     {
173     my ($xmlparser,$name,%attributes)=@_;
174     my $doctype = $attributes{'type'};
175 sashby 1.5
176 sashby 1.10 if ($doctype ne $self->{mydoctype})
177     {
178     warn "Configuration::BootStrapProject::boot: Unable to handle doc of type $doctype";
179     }
180     }
181 sashby 1.5
182 sashby 1.10 sub AUTOLOAD()
183     {
184     my ($xmlparser,$name,%attributes)=@_;
185     return if $AUTOLOAD =~ /::DESTROY$/;
186     my $name=$AUTOLOAD;
187     $name =~ s/.*://;
188     if ($name eq 'base' || $name eq 'base_')
189     {
190     $self->{scramdoc}->$name(%attributes);
191     }
192 sashby 1.5 }
193    
194 sashby 1.10 1;