Skip to content

Commit

Permalink
Merge branch 'composer_filter-ESDEV-4443'
Browse files Browse the repository at this point in the history
  • Loading branch information
rezonanc-oxid committed Jun 13, 2017
2 parents c83b6dd + d54c286 commit 9bc672d
Show file tree
Hide file tree
Showing 32 changed files with 3,091 additions and 818 deletions.
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: php

notifications:
email: false

php:
- "5.6"
- "7.0"
- "7.1"

install:
- composer install

script:
- vendor/bin/phpunit tests
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
OXID eShop composer plugin
==========================

.. image:: https://travis-ci.org/OXID-eSales/oxideshop_composer_plugin.svg?branch=master
:target: https://travis-ci.org/OXID-eSales/oxideshop_composer_plugin

.. image:: https://img.shields.io/packagist/v/oxid-esales/oxideshop-composer-plugin.svg?maxAge=3600
:target: https://packagist.org/packages/oxid-esales/oxideshop-composer-plugin

This plugin is used to install OXID eShop and OXID eShop third party integrations (modules, themes).

More information how to install OXID eShop using this plugin can be found `here <http://oxid-eshop-developer-documentation.readthedocs.io/en/latest/getting_started/eshop_installation.html#eshop-installation-via-composer>`__.
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"prefer-stable": true,
"require": {
"composer-plugin-api": "^1.0",
"symfony/filesystem": "^3.0"
"symfony/filesystem": "^3.0",
"webmozart/glob": "^4.1",
"webmozart/path-util": "^2.3"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
Expand Down
29 changes: 0 additions & 29 deletions src/Installer/DirectoriesSkipIteratorBuilder.php

This file was deleted.

68 changes: 0 additions & 68 deletions src/Installer/DirectoryRecursiveFilterIterator.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
* @version OXID eShop Composer plugin
*/

namespace OxidEsales\ComposerPlugin\Installer;
namespace OxidEsales\ComposerPlugin\Installer\Package;

use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
use Symfony\Component\Filesystem\Filesystem;

/**
* Class is responsible for preparing project structure.
* It copies necessary files to specific directories.
*/
abstract class AbstractInstaller
abstract class AbstractPackageInstaller
{
const EXTRA_PARAMETER_KEY_ROOT = 'oxideshop';

Expand All @@ -46,8 +45,20 @@ abstract class AbstractInstaller
/** Used to decide what the shop source directory is. */
const EXTRA_PARAMETER_SOURCE_PATH = 'source-path';

/** @var Filesystem */
private $fileSystem;
/** List of glob expressions used to blacklist files being copied. */
const EXTRA_PARAMETER_FILTER_BLACKLIST = 'blacklist-filter';

/** Glob expression to filter all files, might be used to filter whole directory. */
const BLACKLIST_ALL_FILES = '**/*';

/** Name of directory to be excluded for VCS */
const BLACKLIST_VCS_DIRECTORY = '.git';

/** Name of ignore files to be excluded for VCS */
const BLACKLIST_VCS_IGNORE_FILE = '.gitignore';

/** Glob filter expression to exclude VCS files */
const BLACKLIST_VCS_DIRECTORY_FILTER = self::BLACKLIST_VCS_DIRECTORY . DIRECTORY_SEPARATOR . self::BLACKLIST_ALL_FILES;

/** @var IOInterface */
private $io;
Expand All @@ -61,14 +72,12 @@ abstract class AbstractInstaller
/**
* AbstractInstaller constructor.
*
* @param Filesystem $fileSystem
* @param IOInterface $io
* @param string $rootDirectory
* @param IOInterface $io
* @param string $rootDirectory
* @param PackageInterface $package
*/
public function __construct(Filesystem $fileSystem, IOInterface $io, $rootDirectory, PackageInterface $package)
public function __construct(IOInterface $io, $rootDirectory, PackageInterface $package)
{
$this->fileSystem = $fileSystem;
$this->io = $io;
$this->rootDirectory = $rootDirectory;
$this->package = $package;
Expand Down Expand Up @@ -98,14 +107,6 @@ public function isInstalled()
return false;
}

/**
* @return Filesystem
*/
protected function getFileSystem()
{
return $this->fileSystem;
}

/**
* @return IOInterface
*/
Expand All @@ -130,23 +131,68 @@ public function getPackage()
return $this->package;
}

/**
* @return string
*/
protected function getPackageName()
{
return $this->package->getName();
}

/**
* Search for parameter with specific key in "extra" composer configuration block
*
* @param string $extraParameterKey
* @return null|string
* @param string $defaultValue
*
* @return array|string|null
*/
protected function getExtraParameterValueByKey($extraParameterKey, $defaultValue = null)
{
$extraParameters = $this->getPackage()->getExtra();

$extraParameterValue = isset($extraParameters[static::EXTRA_PARAMETER_KEY_ROOT][$extraParameterKey])?
$extraParameters[static::EXTRA_PARAMETER_KEY_ROOT][$extraParameterKey]:
null;

return (!empty($extraParameterValue)) ? $extraParameterValue : $defaultValue;
}

/**
* Return the value defined in composer extra parameters for blacklist filtering.
*
* @return array
*/
protected function getBlacklistFilterValue()
{
return $this->getExtraParameterValueByKey(static::EXTRA_PARAMETER_FILTER_BLACKLIST, []);
}

/**
* Get VCS glob filter expression
*
* @return array
*/
protected function getExtraParameterValueByKey($extraParameterKey)
protected function getVCSFilter()
{
$extraParameterValue = null;
$package = $this->getPackage();
$extraParameters = $package->getExtra();
if (isset($extraParameters[static::EXTRA_PARAMETER_KEY_ROOT])
&& isset($extraParameters[static::EXTRA_PARAMETER_KEY_ROOT][$extraParameterKey])
) {
$extraParameterValue = $extraParameters[static::EXTRA_PARAMETER_KEY_ROOT][$extraParameterKey];
return [self::BLACKLIST_VCS_DIRECTORY_FILTER, self::BLACKLIST_VCS_IGNORE_FILE];
}

/**
* Combine multiple glob expression lists into one list
*
* @param array $listOfGlobExpressionLists E.g. [["*.txt", "*.pdf"], ["*.md"]]
*
* @return array
*/
protected function getCombinedFilters($listOfGlobExpressionLists)
{
$filters = [];
foreach ($listOfGlobExpressionLists as $filter) {
$filters = array_merge($filters, $filter);
}
return $extraParameterValue;

return $filters;
}

/**
Expand All @@ -155,22 +201,33 @@ protected function getExtraParameterValueByKey($extraParameterKey)
*/
protected function askQuestionIfNotInstalled($messageToAsk)
{
if ($this->isInstalled()) {
return $this->askQuestion($messageToAsk);
}
return true;
return $this->isInstalled() ? $this->askQuestion($messageToAsk) : true;
}

/**
* Returns true if the human answer to the given question was answered with a positive value (Yes/yes/Y/y).
*
* @param string $messageToAsk
* @return bool
*/
protected function askQuestion($messageToAsk)
{
$response = $this->getIO()->ask($messageToAsk, 'No');
if ((strtolower($response) === 'yes' || strtolower($response) === 'y')) {
return true;
}
return false;
$userInput = $this->getIO()->ask($messageToAsk, 'No');

return $this->isPositiveUserInput($userInput);
}

/**
* Return true if the input from user is a positive answer (Yes/yes/Y/y)
*
* @param string $userInput Raw user input
*
* @return bool
*/
private function isPositiveUserInput($userInput)
{
$positiveAnswers = ['yes', 'y'];

return in_array(strtolower(trim($userInput)), $positiveAnswers, true);
}
}
Loading

0 comments on commit 9bc672d

Please sign in to comment.