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

# Content
1 =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
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 $Configuration::BootStrapProject::self;
47
48 sub new()
49 {
50 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 }
72
73 sub boot()
74 {
75 my $self=shift;
76 my $url=shift;
77 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 chmod $filemode,$filename;
96 $self->{scramdoc}->filetoparse($filename);
97 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 return $self->{area};
101 }
102
103 # --- Tag Routines
104 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
125 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
133 sub config()
134 {
135 my ($xmlparser,$name,%attributes)=@_;
136 # Set the project config dir variable here so that
137 # "projconfigdir" value can be used while bootstrapping:
138 $ENV{SCRAM_CONFIGDIR} = $attributes{'dir'};
139 $self->{area}->configurationdir($attributes{'dir'});
140 }
141
142 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
150 sub requirementsdoc() {
151 my ($xmlparser,$name,%attributes)=@_;
152 my ($filename,$fullurl);
153
154 if ( exists $attributes{'url'} ) {
155 # -- download into our cache
156 ($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 }
172
173 sub doc()
174 {
175 my ($xmlparser,$name,%attributes)=@_;
176 my $doctype = $attributes{'type'};
177
178 if ($doctype ne $self->{mydoctype})
179 {
180 warn "Configuration::BootStrapProject::boot: Unable to handle doc of type $doctype";
181 }
182 }
183
184 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 }
195
196 1;