Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

Commit

Permalink
chain project.jenkins.init
Browse files Browse the repository at this point in the history
  • Loading branch information
elnebuloso committed Nov 13, 2014
1 parent 58bea19 commit 0ddc738
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
/bin
/build
/vendor
build.properties.jenkins
build.properties.local
composer.lock
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# CHANGELOG

## 6.7.1
## 6.8.0

- testing jenkins github publisher
- new target: project.jenkins.init
- project.jenkins.init writes jenkins build.properties
- project.jenkins.init added in chain php on build:before
- project.jenkins.init added in chain php-composer-package on build:before

## 6.7.0

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.7.19
6.8.0
8 changes: 1 addition & 7 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
project.vendor = elnebuloso
project.name = phing-commons
project.chains = php

;JENKINS ENVIRONMENT VARIABLES
PBC_PROJECT_VERSION = 6.7.19

[JENKINS]
PBC_PROJECT_VERSION_JENKINS = 6.7.19
project.chains = php
1 change: 1 addition & 0 deletions commons/chains/php-composer-package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<target name="init:main" hidden="true" depends="composer.validate, composer.update" />
<target name="test:main" hidden="true" depends="test.phplint, test.phpunit" />
<target name="build:before" hidden="true" depends="project.jenkins.init" />
<target name="build:after" hidden="true" depends="report" />

</project>
1 change: 1 addition & 0 deletions commons/chains/php.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<echo message="loading chain: php" />

<target name="test:main" hidden="true" depends="test.phplint, test.phpunit" />
<target name="build:before" hidden="true" depends="project.jenkins.init" />
<target name="build:after" hidden="true" depends="report" />

</project>
2 changes: 1 addition & 1 deletion commons/commons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<!-- ============================================ -->
<!-- commons tasks -->
<!-- ============================================ -->
<taskdef classname="Commons_Phing_Task_Version_Update" name="commons-project-version-update" />
<taskdef classname="Commons_Phing_Task_Project_Jenkins_Init" name="commons-project-jenkins-init" />
<taskdef classname="Commons_Phing_Task_System_ImportChains" name="commons-system-import-chains" />


Expand Down
2 changes: 2 additions & 0 deletions commons/targets/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
<project default="project:help">


<import file="${phing:commons:commons}/targets/project/jenkins/init.xml" />
<import file="${phing:commons:commons}/targets/project/version/update.xml" />


<target name="project:help" depends="project.version.update:help">
<echo message="TARGET DESCRIPTION" />
<echo message="----------------------------------------------------------------------------------------------------" />
<echo message="project.jenkins.init Init Jenkins, write Jenkins Properties File" />
<echo message="project.version.update Updates Files Project Files with new Version" />
</target>

Expand Down
37 changes: 37 additions & 0 deletions commons/targets/project/jenkins/init.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>


<project default="project.jenkins.init">


<target name="project.jenkins.init:init" hidden="true">
<echo message="no actions defined" level="debug" />
</target>


<target name="project.jenkins.init:before" hidden="true">
<echo message="no actions defined" level="debug" />
</target>


<target name="project.jenkins.init:main" hidden="true">
<commons-project-jenkins-init version="${project.version}" propertiesFile="${project.root}/build.properties" />
</target>


<target name="project.jenkins.init:after" hidden="true">
<echo message="no actions defined" level="debug" />
</target>


<target name="project.jenkins.init" depends="project.jenkins.init:init, project.jenkins.init:before, project.jenkins.init:main, project.jenkins.init:after">
<echo message="successful" />
</target>


<target name="project.jenkins.init:help" depends="project.jenkins.init:init">
<echo message="no help defined" />
</target>


</project>
2 changes: 0 additions & 2 deletions commons/targets/project/version/update.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

<echo message="" />
<echo message="version: ${project.version}" />

<commons-project-version-update version="${project.version}" propertiesFile="${project.root}/build.properties" />
</target>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author Jeff Tunessen <jeff.tunessen@gmail.com>
*/
class Commons_Phing_Task_Version_Update extends Task {
class Commons_Phing_Task_Project_Jenkins_Init extends Task {

/**
* @var string
Expand All @@ -16,6 +16,11 @@ class Commons_Phing_Task_Version_Update extends Task {
*/
private $propertiesFile;

/**
* @var array
*/
private $properties;

/**
* @param string $version
* @throws \BuildException
Expand Down Expand Up @@ -43,32 +48,20 @@ public function setPropertiesFile($propertiesFile) {
* @return void
*/
public function main() {
$properties = parse_ini_file($this->propertiesFile);
$this->properties = parse_ini_file($this->propertiesFile);

if($properties === false) {
if($this->properties === false) {
throw new \BuildException('unable to parse properties file');
}

// remove properties that were updated
$this->unsetProperty($properties, 'project.version');
$this->unsetProperty($properties, 'PBC_PROJECT_VERSION');

$fp = fopen($this->propertiesFile, "r+");
$fp = fopen(dirname($this->propertiesFile) . '/build.properties.jenkins', "w+");

if(flock($fp, LOCK_EX)) {
ftruncate($fp, 0); // write new file content

foreach($properties as $key => $value) {
fwrite($fp, $this->getIniSetting($key, $value));
}

fwrite($fp, PHP_EOL);
fwrite($fp, ';JENKINS ENVIRONMENT VARIABLES' . PHP_EOL);
fwrite($fp, $this->getIniSetting('PBC_PROJECT_VERSION', $this->version));

fwrite($fp, PHP_EOL);
fwrite($fp, '[JENKINS]' . PHP_EOL);
fwrite($fp, $this->getIniSetting('PBC_PROJECT_VERSION_JENKINS', $this->version));
$this->writeIniSetting($fp, 'PBC_PROJECT_VERSION_JENKINS', $this->version);
$this->writeIniSettingFromBuildProperty($fp, 'project.vendor');
$this->writeIniSettingFromBuildProperty($fp, 'project.name');

flock($fp, LOCK_UN); // release lock
}
Expand All @@ -80,19 +73,22 @@ public function main() {
}

/**
* @param resource $fp
* @param string $key
* @param string $value
* @return string
*/
private function getIniSetting($key, $value) {
return "$key = $value" . PHP_EOL;
private function writeIniSetting($fp, $key, $value) {
fwrite($fp, "$key = $value" . PHP_EOL);
}

/**
* @param array $properties
* @param resource $fp
* @param string $key
*/
private function unsetProperty(array &$properties, $key) {
unset($properties[$key]);
private function writeIniSettingFromBuildProperty($fp, $key) {
if(array_key_exists($key, $this->properties)) {
$this->writeIniSetting($fp, 'PBC_' . strtoupper(str_replace('.', '_', $key)), $this->properties[$key]);
}
}
}

0 comments on commit 0ddc738

Please sign in to comment.