Skip to content

Commit

Permalink
[mms] Composer file is now generated/updated before releasing.
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Oct 16, 2013
1 parent 1fdf2b4 commit 121d1f7
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 39 deletions.
11 changes: 10 additions & 1 deletion components/lib/Components/Component.php
Expand Up @@ -184,6 +184,15 @@ public function changed(
*/
public function timestampAndSync($options);

/**
* Updates the composer.json file.
*
* @param array $options Options for the operation.
*
* @return string The success message.
*/
public function updateComposer($options);

/**
* Add the next version to the package.xml.
*
Expand Down Expand Up @@ -284,4 +293,4 @@ public function installChannel(
public function install(
Components_Pear_Environment $env, $options = array(), $reason = ''
);
}
}
16 changes: 15 additions & 1 deletion components/lib/Components/Component/Base.php
Expand Up @@ -290,6 +290,20 @@ public function timestampAndSync($options)
);
}

/**
* Updates the composer.json file.
*
* @param array $options Options for the operation.
*
* @return string The success message.
*/
public function updateComposer($options)
{
throw new Components_Exception(
'Updating composer.json is not supported!'
);
}

/**
* Add the next version to the package.xml.
*
Expand Down Expand Up @@ -476,4 +490,4 @@ protected function _hasCi()
}
return $response->code != 404;
}
}
}
26 changes: 26 additions & 0 deletions components/lib/Components/Component/Source.php
Expand Up @@ -264,6 +264,32 @@ public function timestampAndSync($options)
return $result;
}

/**
* Updates the composer.json file.
*
* @param array $options Options for the operation.
*
* @return string The success message.
*/
public function updateComposer($options)
{
if (empty($options['pretend'])) {
$composer = new Components_Helper_Composer();
$composer->generateComposeJson(
$this->getPackageXmlPath()
);
$result = 'Updated composer.json.';
} else {
$result = 'Would update composer.json now.';
}
if (!empty($options['commit'])) {
$options['commit']->add(
$this->_directory . '/composer.json', $this->_directory
);
}
return $result;
}

/**
* Set the version in the package.xml
*
Expand Down
38 changes: 10 additions & 28 deletions components/lib/Components/Helper/Composer.php
Expand Up @@ -23,45 +23,27 @@
class Components_Helper_Composer
{
/**
* The output handler.
* Updates the composer.json file.
*
* @param Component_Output
* @param string $package Path to the package.xml file.
* @param array $options The set of options for the operation.
*/
private $_output;

/**
* Constructor.
*
* @param Component_Output $output The output handler.
*/
public function __construct(Components_Output $output)
{
$this->_output = $output;
}

/**
* Updates the component information in the horde-web repository.
*
* @param Components_Component $component The data of this component will
* be updated.
* @param array $options The set of options for the
* operation.
*/
public function generateComposeJson(Components_Component $component,
$options)
public function generateComposeJson($package, array $options = array())
{
require_once __DIR__ . '/../../Conductor/PEARPackageFilev2.php';
require_once __DIR__ . '/../../Conductor/Package2XmlToComposer.php';

$converter = new Package2XmlToComposer($component->getPackageXmlPath());
$converter = new Package2XmlToComposer($package);
$converter->setRepositories(array(
array('pear', 'http://pear.horde.org')
));
$converter->convert();

$this->_output->ok(
'Created composer.json file.'
);
if (isset($options['logger'])) {
$options['logger']->ok(
'Created composer.json file.'
);
}
}

}
1 change: 1 addition & 0 deletions components/lib/Components/Module/Release.php
Expand Up @@ -164,6 +164,7 @@ public function getHelp($action)
The available tasks are:
- timestamp : Timestamp the package.xml and sync the change log.
- composer : Update the composer.json file.
- sentinel : Update the sentinels in docs/CHANGES and lib/Application.php.
- commit : Commit any changes with an automated message.
- package : Prepare a *.tgz package.
Expand Down
82 changes: 82 additions & 0 deletions components/lib/Components/Release/Task/Composer.php
@@ -0,0 +1,82 @@
<?php
/**
* Copyright 2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2013 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Components
* @package Components
*/

/**
* This task updates the composer.json file right before the release.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2013 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Components
* @package Components
*/
class Components_Release_Task_Composer
extends Components_Release_Task_Base
{
/**
* Can the task be skipped?
*
* @param array $options Additional options.
*
* @return boolean True if it can be skipped.
*/
public function skip($options)
{
return false;
}

/**
* Validate the preconditions required for this release task.
*
* @param array $options Additional options.
*
* @return array An empty array if all preconditions are met and a list of
* error messages otherwise.
*/
public function validate($options)
{
if (!$this->getComponent()->hasLocalPackageXml()) {
return array(
'The component lacks a local package.xml!',
);
}
$diff_options = $options;
$diff_options['no_timestamp'] = true;
$diff = $this->getComponent()->updatePackageXml('diff', $diff_options);
if (!empty($diff)) {
return array(
"The package.xml file is not up-to-date:\n$diff"
);
}
return array();
}

/**
* Run the task.
*
* @param array &$options Additional options.
*
* @return NULL
*/
public function run(&$options)
{
$result = $this->getComponent()->updateComposer($options);
if (!$this->getTasks()->pretend()) {
$this->getOutput()->ok($result);
} else {
$this->getOutput()->info($result);
}
}
}
22 changes: 13 additions & 9 deletions components/lib/Components/Runner/Composer.php
Expand Up @@ -36,28 +36,32 @@ class Components_Runner_Composer
*
* @var Components_Helper_Composer
*/
private $_composer;
private $_output;

/**
* Constructor.
*
* @param Components_Config $config The configuration for the
* current job.
* @param Components_Helper_Composer $composer The composer helper.
* @param Components_Config $config The configuration for the current
* job.
* @param Components_Output $output The output handler.
*/
public function __construct(
Components_Config $config,
Components_Helper_Composer $composer
Components_Output $output
) {
$this->_config = $config;
$this->_composer = $composer;
$this->_output = $output;
}

public function run()
{
$this->_composer->generateComposeJson(
$this->_config->getComponent(),
$this->_config->getOptions()
$composer = new Components_Helper_Composer();
$options = $this->_config->getOptions();
$options['logger'] = $this->_output;

$composer->generateComposeJson(
$this->_config->getComponent()->getPackageXmlPath(),
$options
);
}
}
5 changes: 5 additions & 0 deletions components/lib/Components/Runner/Release.php
Expand Up @@ -79,6 +79,11 @@ public function run()
$pre_commit = true;
}

if ($this->_doTask('composer')) {
$sequence[] = 'Composer';
$pre_commit = true;
}

if ($this->_doTask('sentinel')) {
$sequence[] = 'CurrentSentinel';
$pre_commit = true;
Expand Down
2 changes: 2 additions & 0 deletions components/package.xml
Expand Up @@ -22,6 +22,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Composer file is now generated/updated before releasing.
* [mms] Add PHP Composer generator.
* [mms] Added PHPDCD QC test.
* [mms] Added PHPLOC QC test.
Expand Down Expand Up @@ -868,6 +869,7 @@
<date>2013-02-13</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Composer file is now generated/updated before releasing.
* [mms] Add PHP Composer generator.
* [mms] Added PHPDCD QC test.
* [mms] Added PHPLOC QC test.
Expand Down

0 comments on commit 121d1f7

Please sign in to comment.