Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update custom code and scripts for Phing 3 #213

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"drupal/coder": "^8.3.6",
"drush/drush": ">=9",
"mglaman/drupal-check": "^1.2",
"palantirnet/phing-drush-task": "^1.1",
"palantirnet/phing-drush-task": ">=1.1",
"pear/http_request2": "^2.3",
"pear/versioncontrol_git": "@dev",
"phing/phing": "^2.14",
"phing/phing": "^3.0",
"phpmd/phpmd": "^2.13",
"phpspec/prophecy-phpunit": "^2"
},
Expand All @@ -40,9 +40,6 @@
},
"extra": {
"patches": {
"phing/phing": {
"Support relative symliks in Phing": "https://raw.githubusercontent.com/palantirnet/the-build/7cdc28b6019fb88a0604261366f9ea35f1e21d96/patches/phing-relative-symlinks.patch"
}
}
}
}
3 changes: 2 additions & 1 deletion defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ styleguide:
# Location of the style guide, relative to the project root.
root: 'styleguide'
# Command to compile the style guide assets, for use during the build and artifact steps.
command: 'yarn default'
command: 'yarn'
command_args: 'default'

# Configuration for linting custom javascript.
#
Expand Down
28 changes: 19 additions & 9 deletions defaults/install/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@
<target name="behat" description="Run the Behat tests.">
<property name="behat.command" value="${behat.bin} ${behat.args}" />
<echo msg="$> ${behat.command}" />
<exec command="${behat.command}" logoutput="true" checkreturn="true" />
<exec executable="${behat.bin}" logoutput="true" checkreturn="true">
<arg line="${behat.args}"/>
</exec>
</target>


Expand All @@ -118,11 +120,13 @@

<!-- Run PHP Code Sniffer. -->
<echo msg="$> vendor/bin/phpcs" />
<exec command="vendor/bin/phpcs" logoutput="true" checkreturn="true" />
<exec executable="vendor/bin/phpcs" logoutput="true" checkreturn="true" />

<!-- Run PHP Mess Detector. -->
<echo msg="$> vendor/bin/phpmd" />
<exec command="vendor/bin/phpmd ${phpmd.directories} ${phpmd.format} ${phpmd.rulesets} --suffixes ${phpmd.suffixes}" logoutput="true" checkreturn="true" />
<exec executable="vendor/bin/phpmd" logoutput="true" checkreturn="true">
<arg line="${phpmd.directories} ${phpmd.format} ${phpmd.rulesets} --suffixes=${phpmd.suffixes}"/>
</exec>

<!-- Run Drupal Check. -->
<foreach list="${drupal-check.directories}" param="drupal-check.dir" target="drupal-check" />
Expand All @@ -131,7 +135,9 @@
<phingcall target="eslint" />

<!-- Ensure the composer.lock file is up to date -->
<exec command="composer validate --no-check-all --no-check-publish" logoutput="true" checkreturn="true" />
<exec executable="composer validate" logoutput="true" checkreturn="true">
<arg line="--no-check-all --no-check-publish"/>
</exec>
</target>


Expand All @@ -142,28 +148,30 @@
<property name="drupal-check.command" value="${drupal-check.bin} ${drupal-check.dir}" />

<echo msg="$> ${drupal-check.command}" />
<exec command="${drupal-check.command}" logoutput="true" checkreturn="true" />
<exec executable="${drupal-check.command}" logoutput="true" checkreturn="true" />
</target>

<!-- Target: eslint -->
<target name="eslint" depends="install-node-dependencies">
<!-- Lint custom module and theme (by default) javascript. -->
<echo msg="$> yarn run eslint --ext ${eslint.extensions} ${eslint.directory}" />
<exec command="yarn run eslint --fix-dry-run --ext ${eslint.extensions} --no-error-on-unmatched-pattern ${eslint.directory}" logoutput="true" checkreturn="true" />
<exec executable="yarn run eslint" logoutput="true" checkreturn="true" >
<arg line="--fix-dry-run --ext ${eslint.extensions} --no-error-on-unmatched-pattern ${eslint.directory}"/>
</exec>
</target>


<!-- Target: code-fix -->
<target name="code-fix" description="Run the automated code fixer.">
<!-- Run PHP Code Beautifier and Fixer. -->
<echo msg="$> vendor/bin/phpcbf" />
<exec command="vendor/bin/phpcbf" logoutput="true" checkreturn="false" />
<exec executable="vendor/bin/phpcbf" logoutput="true" checkreturn="false" />
</target>

<!-- Target: install-node-dependencies -->
<target name="install-node-dependencies" depends="" description="Install project, core, and custom module node dependencies">
<echo msg="Install project node dependencies to get eslint libraries." />
<exec dir="${drupal.root}/.." command="yarn install" logoutput="true" />
<exec dir="${drupal.root}/.." executable="yarn install" logoutput="true" />
</target>


Expand All @@ -177,7 +185,9 @@

<!-- Default target: list -->
<target name="list" hidden="true">
<exec command="${phing.home}/bin/phing -q -f ${phing.file} -l" passthru="true"/>
<exec executable="${phing.home}/bin/phing" passthru="true">
<arg line="-q -f ${phing.file} -l"/>
</exec>
<echo>Find more documentation for palantirnet/the-build on GitHub:

https://github.com/palantirnet/the-build#using-the-build</echo>
Expand Down
14 changes: 8 additions & 6 deletions src/TheBuild/Acquia/GetLatestBackupTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use AcquiaCloudApi\Endpoints\Applications;
use AcquiaCloudApi\Endpoints\DatabaseBackups;
use AcquiaCloudApi\Endpoints\Environments;
use Phing\Exception\BuildException;
use Phing\Io\File;

/**
* Fetch a recent backup from Acquia.
Expand All @@ -16,7 +18,7 @@ class GetLatestBackupTask extends \Task {
/**
* Required. Directory for storing downloaded database backups.
*
* @var \PhingFile
* @var \Phing\Io\File
*/
protected $dir;

Expand Down Expand Up @@ -50,8 +52,8 @@ class GetLatestBackupTask extends \Task {
/**
* {@inheritdoc}
*
* @throws \IOException
* @throws \NullPointerException
* @throws \Phing\Io\IOException
* @throws \HTTP_Request2_Exception
*/
public function main() {
$this->validate();
Expand All @@ -77,7 +79,7 @@ private function getAcquiaCloudCredentials() {
$this->log("Couldn't find ACQUIA_CLOUD_API_SECRET env variable.");
}
if (!$api_key || !$api_secret) {
throw new \BuildException("Credentials are required.");
throw new BuildException("Credentials are required.");
}

return [
Expand Down Expand Up @@ -185,7 +187,7 @@ public function setDatabase(string $value) {
* Directory path.
*/
public function setDir(string $value) {
$this->dir = new \PhingFile($value);
$this->dir = new File($value);
}

/**
Expand All @@ -200,7 +202,7 @@ protected function validate() {
// Check the build attributes.
foreach (['dir', 'site', 'env'] as $attribute) {
if (empty($this->$attribute)) {
throw new \BuildException("$attribute attribute is required.");
throw new BuildException("$attribute attribute is required.");
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/TheBuild/CopyPropertiesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

namespace TheBuild;

use Phing\Task;
use Phing\Exception\BuildException;
use Phing\Util\StringHelper;

/**
* Copy properties matching a prefix to properties with a different prefix.
*/
class CopyPropertiesTask extends \Task {
class CopyPropertiesTask extends Task {

/**
* Prefix for properties to copy.
Expand Down Expand Up @@ -59,11 +63,11 @@ public function main() {
*/
public function validate() {
if (empty($this->fromPrefix)) {
throw new \BuildException("fromPrefix attribute is required.", $this->location);
throw new BuildException("fromPrefix attribute is required.", $this->getLocation());
}

if (empty($this->toPrefix)) {
throw new \BuildException("toPrefix attribute is required.", $this->location);
throw new BuildException("toPrefix attribute is required.", $this->getLocation());
}
}

Expand All @@ -74,7 +78,7 @@ public function validate() {
* Prefix to copy properties from.
*/
public function setFromPrefix($prefix) {
if (!\StringHelper::endsWith(".", $prefix)) {
if (!StringHelper::endsWith(".", $prefix)) {
$prefix .= ".";
}

Expand All @@ -88,7 +92,7 @@ public function setFromPrefix($prefix) {
* Prefix to copy properties into.
*/
public function setToPrefix($prefix) {
if (!\StringHelper::endsWith(".", $prefix)) {
if (!StringHelper::endsWith(".", $prefix)) {
$prefix .= ".";
}

Expand Down
12 changes: 8 additions & 4 deletions src/TheBuild/ForeachKeyTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

namespace TheBuild;

use Phing\Task;
use Phing\Exception\BuildException;
use Phing\Util\StringHelper;

/**
* Phing task to run a target for each property in an array.
*/
class ForeachKeyTask extends \Task {
class ForeachKeyTask extends Task {

/**
* Prefix of properties to iterate over.
Expand Down Expand Up @@ -45,7 +49,7 @@ class ForeachKeyTask extends \Task {
/**
* Instance of PhingCallTask to use/run.
*
* @var \PhingCallTask
* @var \Phing\Task\System\PhingCallTask
*/
protected $callee;

Expand Down Expand Up @@ -109,7 +113,7 @@ public function main() {
public function validate() {
foreach (['prefix', 'target', 'keyParam', 'prefixParam'] as $attribute) {
if (empty($this->$attribute)) {
throw new \BuildException("$attribute attribute is required.", $this->location);
throw new BuildException("$attribute attribute is required.", $this->getLocation());
}
}
}
Expand All @@ -121,7 +125,7 @@ public function validate() {
* The key prefix.
*/
public function setPrefix($value) {
if (!\StringHelper::endsWith(".", $value)) {
if (!StringHelper::endsWith(".", $value)) {
$value .= ".";
}

Expand Down
30 changes: 17 additions & 13 deletions src/TheBuild/IncludeResourceTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

namespace TheBuild;

use Phing\Task;
use Phing\Exception\BuildException;
use Phing\Io\File;

/**
* Copy or symlink a file or directory, depending on a flag.
*/
class IncludeResourceTask extends \Task {
class IncludeResourceTask extends Task {

/**
* Either 'symlink' or 'copy'.
Expand All @@ -17,14 +21,14 @@ class IncludeResourceTask extends \Task {
/**
* The source file or directory to include.
*
* @var \PhingFile
* @var \Phing\Io\File
*/
protected $source;

/**
* The location to link the file to.
*
* @var \PhingFile
* @var \Phing\Io\File
*/
protected $dest = NULL;

Expand Down Expand Up @@ -63,19 +67,19 @@ public function main() {
$this->log("Replacing existing resource '" . $this->dest->getPath() . "'");

if ($this->dest->delete(TRUE) === FALSE) {
throw new \BuildException("Failed to delete existing destination '$this->dest'");
throw new BuildException("Failed to delete existing destination '$this->dest'");
}
}

// Link or copy the source artifact. @phpstan-ignore-next-line
// Link or copy the source artifact.
$this->dest->getParentFile()->mkdirs();
if ($this->mode == 'copy') {
$this->log(sprintf("Copying '%s' to '%s'", $this->source->getPath(), $this->dest->getPath()));
$this->source->copyTo($this->dest);
}
else {
$this->log(sprintf("Linking '%s' to '%s'", $this->source->getPath(), $this->dest->getPath()));
/** @var \SymlinkTask $symlink_task */
/** @var \Phing\Task\System\SymlinkTask $symlink_task */
$symlink_task = $this->project->createTask("symlink");
$symlink_task->setTarget($this->source->getPath());
$symlink_task->setLink($this->dest->getPath());
Expand All @@ -89,11 +93,11 @@ public function main() {
*/
public function validate() {
if (!in_array($this->mode, ['symlink', 'copy'])) {
throw new \BuildException("mode attribute must be either 'symlink' or 'copy'", $this->location);
throw new BuildException("mode attribute must be either 'symlink' or 'copy'", $this->getLocation());
}

if (empty($this->source) || empty($this->dest)) {
throw new \BuildException("Both the 'source' and 'dest' attributes are required.");
throw new BuildException("Both the 'source' and 'dest' attributes are required.");
}
}

Expand All @@ -110,12 +114,12 @@ public function setMode(string $mode) {
/**
* Set the source of the resource to include.
*
* @param \PhingFile $source
* @param \Phing\Io\File $source
* Source file.
*/
public function setSource(\PhingFile $source) {
public function setSource(File $source) {
if (!$source->exists()) {
throw new \BuildException("resource '$source' is not available'");
throw new BuildException("resource '$source' is not available'");
}

$this->source = $source;
Expand All @@ -124,10 +128,10 @@ public function setSource(\PhingFile $source) {
/**
* Set the destination for the resource.
*
* @param \PhingFile $dest
* @param \Phing\Io\File $dest
* File destination.
*/
public function setDest(\PhingFile $dest) {
public function setDest(File $dest) {
$this->dest = $dest;
}

Expand Down
4 changes: 3 additions & 1 deletion src/TheBuild/MenuInputRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace TheBuild;

use Phing\Input\InputRequest;

/**
* Input interface that prompts the user to select from a menu of options.
*/
class MenuInputRequest extends \InputRequest {
class MenuInputRequest extends InputRequest {

/**
* Prompt to display with the menu.
Expand Down
Loading