summaryrefslogtreecommitdiff
path: root/buildscripts/phing/tasks/BuildPradoPEARPackageTask.php
blob: a8128d1287ff7f24fa1044e190932284e17ed7f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
require_once 'phing/tasks/system/MatchingTask.php';
include_once 'phing/types/FileSet.php';
include_once 'phing/tasks/ext/pearpackage/Fileset.php';
require_once 'PEAR/PackageFileManager.php';
require_once 'PEAR/PackageFileManager/File.php';

/**
 * Task for creating a PEAR package definition file package.xml to be used with
 * the PEAR distribution of PRADO.
 *
 * @author   Knut Urdalen <knut.urdalen@gmail.com>
 * @package  phing.tasks.ext
 */
class BuildPradoPEARPackageTask extends MatchingTask {

    /* Base directory for reading files. */
    private $dir;

    /* PRADO version */
	private $version;

    /* PRADO state */
	private $state = 'stable';
	private $notes;
	private $filesets = array();

    /* Package file */
    private $packageFile;

    /**
     * Intitialize the task and throw a BuildException if something is missing.
     */
    public function init() {
        include_once 'PEAR/PackageFileManager2.php';
        if(!class_exists('PEAR_PackageFileManager2')) {
            throw new BuildException("You must have installed PEAR_PackageFileManager2 (PEAR_PackageFileManager >= 1.6.0) in order to create a PEAR package.xml file.");
        }
    }

    /**
     * Helper function to set PEAR package options.
     *
     * @param PEAR_PackageFileManager2 $pkg
     */
    private function setOptions($pkg) {
		$options['baseinstalldir'] = 'prado3';
        $options['packagedirectory'] = $this->dir->getAbsolutePath();

        if(empty($this->filesets)) {
			throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml");
		}

        // Use PEAR_PackageFileManager_Fileset from phing as file list generator
		$options['filelistgenerator'] = 'Fileset';

		// Some Phing-specific options needed by our Fileset reader
		$options['phing_project'] = $this->getProject();
		$options['phing_filesets'] = $this->filesets;

		if($this->packageFile !== null) {
            // Create one with full path
            $f = new PhingFile($this->packageFile->getAbsolutePath());
            $options['packagefile'] = $f->getName();
            // Must end in trailing slash
            $options['outputdirectory'] = $f->getParent().DIRECTORY_SEPARATOR;
            $this->log("Creating package file: ".$f->getPath(), PROJECT_MSG_INFO);
        } else {
            $this->log("Creating [default] package.xml file in base directory.", PROJECT_MSG_INFO);
        }
        $options['dir_roles'] = array('framework' => 'php');
        $pkg->setOptions($options);
    }

    /**
     * Main entry point.
     * @return void
     */
    public function main() {

        if($this->dir === null) {
            throw new BuildException("You must specify the \"dir\" attribute for PEAR package task.");
        }

		if($this->version === null) {
            throw new BuildException("You must specify the \"version\" attribute for PEAR package task.");
        }

		$package = new PEAR_PackageFileManager2();
		$this->setOptions($package);

		// the hard-coded stuff
		$package->setPackage('prado3');
		$package->setSummary('PRADO is a component-based and event-driven framework for rapid Web programming in PHP 5.');
		$package->setDescription('PRADO reconceptualizes Web application development in terms of components, events and properties instead of procedures, URLs and query parameters.

A PRADO component is a combination of a specification file (in XML), an HTML template and a PHP class. PRADO components are combined together to form larger components or complete PRADO pages.

Developing PRADO Web applications mainly involves instantiating prebuilt and application-specific component types, configuring them by setting their properties, responding to their events by writing handler functions, and composing them into application tasks. Event-driven programming

PRADO provides the following benefits for Web application developers:

o Reusability - Codes following the PRADO component protocol are highly reusable. Everything in PRADO is a reusable component.
o Ease of Use - Creating and using components are extremely easy. Usually they simply involve configuring component properties.
o Robustness - PRADO frees developers from writing boring, buggy code. They code in terms of objects, methods and properties, instead of URLs and query parameters. The latest PHP5 exception mechanism is exploited that enables line-precise error reporting.
o Performance - PRADO uses a cache technique to ensure the performance of applications based on it. The performance is in fact comparable to those based on commonly used template engines.
o Team Integration - PRADO enables separation of content and presentation. Components, typically pages, have their content (logic) and presentation stored in different files.');
		$package->setChannel('pear.pradosoft.com');
		$package->setPackageType('php');

		$package->setReleaseVersion($this->version);
		$package->setAPIVersion($this->version);

		$package->setReleaseStability($this->state);
		$package->setAPIStability($this->state);

		$package->setNotes($this->notes);

		$package->setLicense('BSD', 'http://www.opensource.org/licenses/bsd-license.php');

		// Add package maintainers
		$package->addMaintainer('lead', 'qxue', 'Qiang Xue', 'qiang.xue@gmail.com');
		$package->addMaintainer('lead', 'jrags', 'Jason Ragsdale', 'jrags@jasrags.net');
		$package->addMaintainer('lead', 'knut', 'Knut Urdalen', 'knut.urdalen@gmail.com');

		// "core" dependencies
		$package->setPhpDep('5.1.0');
		$package->setPearinstallerDep('1.4.7');

		$package->generateContents();

        $e = $package->writePackageFile();

        if(PEAR::isError($e)) {
            throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
        }
    }

    /**
     * Used by the PEAR_PackageFileManager_PhingFileSet lister.
     * @return array FileSet[]
     */
    public function getFileSets() {
        return $this->filesets;
    }

    // -------------------------------
    // Set properties from XML
    // -------------------------------

    /**
     * Nested creator, creates a FileSet for this task
     *
     * @return FileSet The created fileset object
     */
    function createFileSet() {
        $num = array_push($this->filesets, new FileSet());
        return $this->filesets[$num-1];
    }

	/**
     * Set the version we are building.
     * @param string $v
     * @return void
     */
	public function setVersion($v){
		$this->version = $v;
	}

	/**
     * Set the state we are building.
     * @param string $v
     * @return void
     */
	public function setState($v) {
		$this->state = $v;
	}

	/**
	 * Sets release notes field.
	 * @param string $v
	 * @return void
	 */
	public function setNotes($v) {
		$this->notes = $v;
	}
    /**
     * Sets "dir" property from XML.
     * @param PhingFile $f
     * @return void
     */
    public function setDir(PhingFile $f) {
        $this->dir = $f;
    }

    /**
     * Sets the file to use for generated package.xml
     */
    public function setDestFile(PhingFile $f) {
        $this->packageFile = $f;
    }

}