Merge branch 'support/3.2' into develop

# Conflicts:
#	lib/composer/installed.php
This commit is contained in:
jf-cbd
2024-03-14 17:12:39 +01:00
270 changed files with 680 additions and 62524 deletions

View File

@@ -1,169 +0,0 @@
<?php
/**
* Copyright (C) 2010-2023 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
*
*/
namespace Combodo\iTop\Composer;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
class iTopComposer
{
/**
* Parenthesis around alternation as it is eager (see linked ref), and we really want to use start / end of string
* `^test|examples$i` would match Tester for example
* `^(test|examples)$i` is not !
*
* @since 3.2.0 N°7175 update regexp to also remove `examples` dir
* @link https://www.regular-expressions.info/alternation.html RegExp alternation reference
*/
public const TEST_DIR_REGEXP = '/^(tests?|examples)$/i';
/**
* @return array List of all subdirs of /lib that are {@see IsTestDir}.
* Warning : each path contains slashes (meaning on Windows you'll get eg `C:/Dev/wamp64/www/itop-27/lib/goaop/framework/tests`)
*/
public function ListAllTestDir()
{
$aAllTestDirs = array();
$sPath = realpath(APPROOT.'lib');
$oDirectoryIterator = new RecursiveDirectoryIterator($sPath, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO|FilesystemIterator::SKIP_DOTS|FilesystemIterator::UNIX_PATHS);
$iterator = new RecursiveIteratorIterator(
$oDirectoryIterator,
RecursiveIteratorIterator::CHILD_FIRST);
/** @var DirectoryIterator $file */
foreach($iterator as $file) {
if(!$file->isDir()) {
continue;
}
$sDirName = $file->getFilename();
if (!$this->IsTestDir($sDirName))
{
continue;
}
$sTestPathDir = $file->getRealpath();
$sTestPathDir = str_replace('\\', '/', $sTestPathDir);
$aAllTestDirs[] = $sTestPathDir;
}
return $aAllTestDirs;
}
/**
* @param $sDirName
*
* @return false|int as {@see \preg_match()}
* @uses self::TEST_DIR_REGEXP
* @uses \preg_match()
*/
public static function IsTestDir($sDirName)
{
return preg_match(static::TEST_DIR_REGEXP, $sDirName);
}
/**
* @return string APPROOT constant but with slashes instead of DIRECTORY_SEPARATOR.
* This ease writing our paths, as we can use '/' for every platforms.
*/
private function GetApprootWithSlashes()
{
return str_replace(DIRECTORY_SEPARATOR, '/', APPROOT);
}
public function ListAllowedTestDir()
{
$APPROOT_WITH_SLASHES = $this->GetApprootWithSlashes();
return array(
$APPROOT_WITH_SLASHES.'lib/twig/twig/src/Node/Expression/Test',
$APPROOT_WITH_SLASHES.'lib/twig/twig/lib/Twig/Node/Expression/Test',
);
}
public function ListDeniedTestDir()
{
$APPROOT_WITH_SLASHES = $this->GetApprootWithSlashes();
return array(
$APPROOT_WITH_SLASHES.'lib/doctrine/lexer/tests',
$APPROOT_WITH_SLASHES.'lib/goaop/framework/tests',
$APPROOT_WITH_SLASHES.'lib/laminas/laminas-servicemanager/src/Test',
$APPROOT_WITH_SLASHES.'lib/nikic/php-parser/test',
$APPROOT_WITH_SLASHES.'lib/pear/archive_tar/tests',
$APPROOT_WITH_SLASHES.'lib/pear/console_getopt/tests',
$APPROOT_WITH_SLASHES.'lib/pear/pear_exception/tests',
$APPROOT_WITH_SLASHES.'lib/psr/log/Psr/Log/Test',
$APPROOT_WITH_SLASHES.'lib/symfony/cache/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/cache/Tests/DoctrineProviderTest.php',
$APPROOT_WITH_SLASHES.'lib/symfony/class-loader/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/config/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/console/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/css-selector/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/debug/Resources/ext/tests',
$APPROOT_WITH_SLASHES.'lib/symfony/debug/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/dependency-injection/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/dotenv/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/event-dispatcher/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/filesystem/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/finder/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/http-client-contracts/Test',
$APPROOT_WITH_SLASHES.'lib/symfony/http-foundation/Test',
$APPROOT_WITH_SLASHES.'lib/symfony/http-kernel/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/service-contracts/Test',
$APPROOT_WITH_SLASHES.'lib/symfony/framework-bundle/Test',
$APPROOT_WITH_SLASHES.'lib/symfony/mime/Test',
$APPROOT_WITH_SLASHES.'lib/symfony/routing/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/stopwatch/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/translation-contracts/Test',
$APPROOT_WITH_SLASHES.'lib/symfony/twig-bridge/Test',
$APPROOT_WITH_SLASHES.'lib/symfony/twig-bundle/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/var-dumper/Test',
$APPROOT_WITH_SLASHES.'lib/symfony/var-dumper/Tests/Test',
$APPROOT_WITH_SLASHES.'lib/symfony/var-dumper/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/web-profiler-bundle/Tests',
$APPROOT_WITH_SLASHES.'lib/symfony/yaml/Tests',
$APPROOT_WITH_SLASHES.'lib/tecnickcom/tcpdf/examples',
$APPROOT_WITH_SLASHES.'lib/thenetworg/oauth2-azure/tests',
$APPROOT_WITH_SLASHES.'lib/twig/twig/src/Test',
$APPROOT_WITH_SLASHES.'lib/twig/twig/lib/Twig/Test',
$APPROOT_WITH_SLASHES.'lib/twig/twig/doc/tests',
$APPROOT_WITH_SLASHES.'lib/laminas/laminas-servicemanager/src/Test',
);
}
public function ListDeniedButStillPresent()
{
$aDeniedTestDir = $this->ListDeniedTestDir();
$aAllTestDir = $this->ListAllTestDir();
return array_intersect($aDeniedTestDir, $aAllTestDir);
}
}

View File

@@ -0,0 +1,140 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Dependencies;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
/**
* Class AbstractFolderAnalyzer
*
* Extend this class to enable a dependency manager such as Composer or NPM to clean unnecessary files after an installation or update of a package.
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Dependencies
*
* @since 3.2.0 N°7331 class creation to have managers for both Composer and NPM (only Composer was existing before)
*/
abstract class AbstractFolderAnalyzer
{
/**
* Questionnable folder is a folder name that seems like it doesn't need to be package as it only contain
* unnecessary files (e.g. lib test or example files)
*
* Parenthesis around alternation as it is eager (see linked ref), and we really want to use start / end of string
* `^test|examples$i` would match Tester for example
* `^(test|examples)$i` is not !
*
* @since 3.2.0 N°7175 update regexp to also remove `examples` folder
* @link https://www.regular-expressions.info/alternation.html RegExp alternation reference
*/
public const QUESTIONNABLE_FOLDER_REGEXP = '/^(tests?|examples?|htdocs?|demos?|external)$/i';
/**
* @return string Relative path to the root folder of the dependencies (e.g. "lib" for composer, "node_modules" for npm, ...) from iTop app. root
*/
abstract protected function GetDependenciesRootFolderRelPath(): string;
/**
* @return string Absolute path to the root folder of the dependencies
*/
public function GetDependenciesRootFolderAbsPath(): string
{
return $this->GetApprootPathWithSlashes() . $this->GetDependenciesRootFolderRelPath();
}
/**
* @return string APPROOT constant but with slashes instead of DIRECTORY_SEPARATOR.
* This ease writing our paths, as we can use '/' for every platform.
*/
final protected function GetApprootPathWithSlashes(): string
{
return str_replace(DIRECTORY_SEPARATOR, '/', APPROOT);
}
/**
* @return array List of all subdirs of the dependencies folder that are {@see IsQuestionnableFolder}.
* Warning : each path contains slashes (meaning on Windows you'll get eg `C:/Dev/wamp64/www/itop-27/lib/goaop/framework/tests`)
*/
public function ListAllFoldersAbsPaths(): array
{
$aAllTestDirs = array();
$sPath = realpath($this->GetDependenciesRootFolderAbsPath());
$oDirectoryIterator = new RecursiveDirectoryIterator($sPath, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO|FilesystemIterator::SKIP_DOTS|FilesystemIterator::UNIX_PATHS);
$iterator = new RecursiveIteratorIterator(
$oDirectoryIterator,
RecursiveIteratorIterator::CHILD_FIRST);
/** @var DirectoryIterator $file */
foreach($iterator as $file) {
if(!$file->isDir()) {
continue;
}
$sDirName = $file->getFilename();
if (!$this->IsQuestionnableFolder($sDirName))
{
continue;
}
$sTestPathDir = $file->getRealpath();
$sTestPathDir = str_replace('\\', '/', $sTestPathDir);
$aAllTestDirs[] = $sTestPathDir;
}
return $aAllTestDirs;
}
/**
* @param string $sFolderName
*
* @return false|int as {@see \preg_match()}
* @uses static::QUESTIONNABLE_FOLDER_REGEXP
* @uses \preg_match()
*/
public static function IsQuestionnableFolder(string $sFolderName): false|int
{
return preg_match(static::QUESTIONNABLE_FOLDER_REGEXP, $sFolderName);
}
/**
* @return array Array of absolute paths to allowed questionnable folders
*/
abstract public function ListAllowedFoldersRelPaths(): array;
/**
* @return array Array of absolute paths to allowed folders
*/
public function ListAllowedFoldersAbsPaths(): array
{
return array_map(fn ($sRelPath): string => $this->GetDependenciesRootFolderAbsPath() . $sRelPath, $this->ListAllowedFoldersRelPaths());
}
/**
* @return array Array of relative paths (from dependencies root folder {@see static::GetDependenciesRootFolderAbsPath()}) to denied folders
*/
abstract public function ListDeniedFoldersRelPaths(): array;
/**
* @return array Array of absolute paths to denied folders
*/
public function ListDeniedFoldersAbsPaths(): array
{
return array_map(fn ($sRelPath): string => $this->GetDependenciesRootFolderAbsPath() . $sRelPath, $this->ListDeniedFoldersRelPaths());
}
/**
* @return array Array of absolute paths to questionnable denied test folders that need to be marked as allowed or denied
*/
public function ListDeniedButStillPresentFoldersAbsPaths(): array
{
$aDeniedTestDir = $this->ListDeniedFoldersAbsPaths();
$aAllTestDir = $this->ListAllowedFoldersAbsPaths();
return array_intersect($aDeniedTestDir, $aAllTestDir);
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* Copyright (C) 2010-2023 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
*
*/
namespace Combodo\iTop\Dependencies\Composer;
use Combodo\iTop\Dependencies\AbstractFolderAnalyzer;
class iTopComposer extends AbstractFolderAnalyzer
{
/**
* @inheritDoc
*/
protected function GetDependenciesRootFolderRelPath(): string
{
return "lib/";
}
/**
* @inheritDoc
*/
public function ListAllowedFoldersRelPaths(): array
{
return [
'twig/twig/src/Node/Expression/Test',
];
}
/**
* @inheritDoc
*/
public function ListDeniedFoldersRelPaths(): array
{
return [
'doctrine/lexer/tests',
'goaop/framework/tests',
'laminas/laminas-servicemanager/src/Test',
'nikic/php-parser/test',
'pear/archive_tar/tests',
'pear/console_getopt/tests',
'pear/pear_exception/tests',
'psr/log/Psr/Log/Test',
'symfony/cache/Tests',
'symfony/cache/Tests/DoctrineProviderTest.php',
'symfony/class-loader/Tests',
'symfony/config/Tests',
'symfony/console/Tests',
'symfony/css-selector/Tests',
'symfony/debug/Resources/ext/tests',
'symfony/debug/Tests',
'symfony/dependency-injection/Tests',
'symfony/dotenv/Tests',
'symfony/event-dispatcher/Tests',
'symfony/filesystem/Tests',
'symfony/finder/Tests',
'symfony/http-client-contracts/Test',
'symfony/http-foundation/Test',
'symfony/http-kernel/Tests',
'symfony/service-contracts/Test',
'symfony/framework-bundle/Test',
'symfony/mime/Test',
'symfony/routing/Tests',
'symfony/stopwatch/Tests',
'symfony/translation-contracts/Test',
'symfony/twig-bridge/Test',
'symfony/twig-bundle/Tests',
'symfony/var-dumper/Test',
'symfony/var-dumper/Tests/Test',
'symfony/var-dumper/Tests',
'symfony/web-profiler-bundle/Tests',
'symfony/yaml/Tests',
'tecnickcom/tcpdf/examples',
'thenetworg/oauth2-azure/tests',
'twig/twig/src/Test',
'twig/twig/lib/Twig/Test',
'twig/twig/doc/tests',
'laminas/laminas-servicemanager/src/Test',
];
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* Copyright (C) 2010-2023 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
*
*/
namespace Combodo\iTop\Dependencies\NPM;
use Combodo\iTop\Dependencies\AbstractFolderAnalyzer;
class iTopNPM extends AbstractFolderAnalyzer
{
/**
* @inheritDoc
*/
protected function GetDependenciesRootFolderRelPath(): string
{
return "node_modules/";
}
/**
* @inheritDoc
*/
public function ListAllowedFoldersRelPaths(): array
{
return [
// jQuery Sizzle used by jQuery
'jquery/external',
];
}
/**
* @inheritDoc
*/
public function ListDeniedFoldersRelPaths(): array
{
return [
// ACE Editor see https://www.npmjs.com/package/ace-builds for dir contents
'ace-builds/demo',
'ace-builds/src',
'ace-builds/src-min-noconflict',
'ace-builds/src-noconflict',
'c3/htdocs',
'clipboard/demo',
'clipboard/test',
'delegate/demo',
'delegate/test',
'good-listener/demo',
'good-listener/test',
'jquery-migrate/test',
// `jquery-ui` package is just there for vulnerability scans, so we don't want to version its files (only `jquery-ui-dist` is used within the code base)
'jquery-ui/.github',
'jquery-ui/build',
'jquery-ui/dist',
'jquery-ui/external',
'jquery-ui/themes',
'jquery-ui/ui',
'jquery-ui-dist/external',
'mousetrap/plugins/record/tests',
'mousetrap/tests',
'select/demo',
'select/test',
'selectize-plugin-a11y/examples',
'tiny-emitter/test',
'toastify-js/example',
];
}
}