Skip to content
Snippets Groups Projects
Commit 01845303 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3259822 by phenaproxima: ComposerUtility should use the installed/local...

Issue #3259822 by phenaproxima: ComposerUtility should use the installed/local repository to get package info
parent 2d56faea
No related branches found
No related tags found
1 merge request!176Issue #3259822: ComposerUtility should use the installed/local repository to get package info
Showing
with 141 additions and 53 deletions
...@@ -73,9 +73,14 @@ class ComposerUtility { ...@@ -73,9 +73,14 @@ class ComposerUtility {
// @see https://getcomposer.org/doc/06-config.md#htaccess-protect // @see https://getcomposer.org/doc/06-config.md#htaccess-protect
$htaccess = getenv('COMPOSER_HTACCESS_PROTECT'); $htaccess = getenv('COMPOSER_HTACCESS_PROTECT');
$factory = new Factory();
putenv("COMPOSER_HOME=$dir"); putenv("COMPOSER_HOME=$dir");
putenv("COMPOSER_HTACCESS_PROTECT=false"); putenv("COMPOSER_HTACCESS_PROTECT=false");
$composer = Factory::create($io, $configuration); // Initialize the Composer API with plugins disabled and only the root
// package loaded (i.e., nothing from the global Composer project will be
// considered or loaded). This allows us to inspect the project directory
// using Composer's API in a "hands-off" manner.
$composer = $factory->createComposer($io, $configuration, TRUE, $dir, FALSE);
putenv("COMPOSER_HOME=$home"); putenv("COMPOSER_HOME=$home");
putenv("COMPOSER_HTACCESS_PROTECT=$htaccess"); putenv("COMPOSER_HTACCESS_PROTECT=$htaccess");
...@@ -104,7 +109,7 @@ class ComposerUtility { ...@@ -104,7 +109,7 @@ class ComposerUtility {
} }
/** /**
* Returns the names of the core packages in the lock file. * Returns the names of the installed core packages.
* *
* All packages listed in ../core_packages.json are considered core packages. * All packages listed in ../core_packages.json are considered core packages.
* *
...@@ -116,7 +121,7 @@ class ComposerUtility { ...@@ -116,7 +121,7 @@ class ComposerUtility {
*/ */
public function getCorePackageNames(): array { public function getCorePackageNames(): array {
$core_packages = array_intersect( $core_packages = array_intersect(
array_keys($this->getLockedPackages()), array_keys($this->getInstalledPackages()),
static::getCorePackageList() static::getCorePackageList()
); );
...@@ -147,22 +152,23 @@ class ComposerUtility { ...@@ -147,22 +152,23 @@ class ComposerUtility {
]; ];
return in_array($package->getType(), $drupal_package_types, TRUE); return in_array($package->getType(), $drupal_package_types, TRUE);
}; };
return array_filter($this->getLockedPackages(), $filter); return array_filter($this->getInstalledPackages(), $filter);
} }
/** /**
* Returns all packages in the lock file. * Returns information on all installed packages.
* *
* @return \Composer\Package\PackageInterface[] * @return \Composer\Package\PackageInterface[]
* All packages in the lock file, keyed by name. * All installed packages, keyed by name.
*/ */
protected function getLockedPackages(): array { protected function getInstalledPackages(): array {
$locked_packages = $this->getComposer()->getLocker() $installed_packages = $this->getComposer()
->getLockedRepository(TRUE) ->getRepositoryManager()
->getLocalRepository()
->getPackages(); ->getPackages();
$packages = []; $packages = [];
foreach ($locked_packages as $package) { foreach ($installed_packages as $package) {
$key = $package->getName(); $key = $package->getName();
$packages[$key] = $package; $packages[$key] = $package;
} }
......
{
"packages": [
{
"name": "drupal/test-distribution",
"version": "1.0.0",
"require": {
"drupal/core": "*"
}
},
{
"name": "drupal/core",
"version": "9.8.0"
}
]
}
{
"packages": [
{
"name": "drupal/test-distribution",
"version": "1.0.0",
"require": {
"drupal/core-recommended": "*"
}
},
{
"name": "drupal/core-recommended",
"version": "9.8.0",
"require": {
"drupal/core": "9.8.0"
}
},
{
"name": "drupal/core",
"version": "9.8.0"
}
]
}
{
"packages": [
{
"name": "drupal/test-distribution",
"version": "1.0.0",
"require": {
"drupal/core-recommended": "*"
}
},
{
"name": "drupal/core-recommended",
"version": "9.8.0",
"require": {
"drupal/core": "9.8.0"
}
},
{
"name": "drupal/core",
"version": "9.8.0"
},
{
"name": "drupal/core-dev",
"version": "9.8.0"
}
],
"dev": true,
"dev-package-names": [
"drupal/core-dev"
]
}
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
"description": "This project is removed but there should be no error because it is not a Drupal project.", "description": "This project is removed but there should be no error because it is not a Drupal project.",
"version": "1.3.1", "version": "1.3.1",
"type": "library" "type": "library"
} },
],
"packages-dev": [
{ {
"name": "drupal/dev-test_module", "name": "drupal/dev-test_module",
"version": "1.3.0", "version": "1.3.0",
...@@ -29,6 +27,10 @@ ...@@ -29,6 +27,10 @@
"version": "1.3.1", "version": "1.3.1",
"type": "library" "type": "library"
} }
],
"dev": true,
"dev-package-names": [
"drupal/dev-test_module",
"other/dev-removed"
] ]
} }
...@@ -20,9 +20,7 @@ ...@@ -20,9 +20,7 @@
"description": "This is newly added project but there should be no error because it is not a drupal project", "description": "This is newly added project but there should be no error because it is not a drupal project",
"version": "1.3.1", "version": "1.3.1",
"type": "library" "type": "library"
} },
],
"packages-dev": [
{ {
"name": "drupal/dev-test_module", "name": "drupal/dev-test_module",
"version": "1.3.0", "version": "1.3.0",
...@@ -39,5 +37,11 @@ ...@@ -39,5 +37,11 @@
"version": "1.3.1", "version": "1.3.1",
"type": "library" "type": "library"
} }
],
"dev": true,
"dev-package-names": [
"drupal/dev-test_module",
"drupal/dev-test_module2",
"other/dev-new_project"
] ]
} }
{
"packages": [],
"packages-dev": []
}
{
"packages": []
}
...@@ -21,9 +21,7 @@ ...@@ -21,9 +21,7 @@
"description": "This project version is changed but there should be no error because it is not a Drupal project.", "description": "This project version is changed but there should be no error because it is not a Drupal project.",
"version": "1.3.1", "version": "1.3.1",
"type": "library" "type": "library"
} },
],
"packages-dev": [
{ {
"name": "drupal/dev-test_module", "name": "drupal/dev-test_module",
"version": "1.3.0", "version": "1.3.0",
...@@ -41,5 +39,11 @@ ...@@ -41,5 +39,11 @@
"version": "1.3.1", "version": "1.3.1",
"type": "library" "type": "library"
} }
],
"dev": true,
"dev-package-names": [
"drupal/dev-test_module",
"other/dev-removed",
"other/dev-changed"
] ]
} }
...@@ -21,9 +21,7 @@ ...@@ -21,9 +21,7 @@
"description": "This project version is changed but there should be no error because it is not a Drupal project.", "description": "This project version is changed but there should be no error because it is not a Drupal project.",
"version": "1.3.2", "version": "1.3.2",
"type": "library" "type": "library"
} },
],
"packages-dev": [
{ {
"name": "drupal/dev-test_module", "name": "drupal/dev-test_module",
"version": "1.3.0", "version": "1.3.0",
...@@ -41,5 +39,11 @@ ...@@ -41,5 +39,11 @@
"version": "1.3.2", "version": "1.3.2",
"type": "library" "type": "library"
} }
],
"dev": true,
"dev-package-names": [
"drupal/dev-test_module",
"other/dev-new_project",
"other/dev-changed"
] ]
} }
...@@ -20,9 +20,7 @@ ...@@ -20,9 +20,7 @@
"description": "This project is removed but there should be no error because it is not a Drupal project.", "description": "This project is removed but there should be no error because it is not a Drupal project.",
"version": "1.3.1", "version": "1.3.1",
"type": "library" "type": "library"
} },
],
"packages-dev": [
{ {
"name": "drupal/dev-test_theme", "name": "drupal/dev-test_theme",
"version": "1.3.0", "version": "1.3.0",
...@@ -39,5 +37,11 @@ ...@@ -39,5 +37,11 @@
"version": "1.3.1", "version": "1.3.1",
"type": "library" "type": "library"
} }
],
"dev": true,
"dev-package-names": [
"drupal/dev-test_theme",
"drupal/dev-test_module2",
"other/dev-removed"
] ]
} }
...@@ -9,13 +9,15 @@ ...@@ -9,13 +9,15 @@
"name": "drupal/test_module2", "name": "drupal/test_module2",
"version": "1.3.1", "version": "1.3.1",
"type": "drupal-module" "type": "drupal-module"
} },
],
"packages-dev": [
{ {
"name": "drupal/dev-test_module2", "name": "drupal/dev-test_module2",
"version": "1.3.1", "version": "1.3.1",
"type": "drupal-module" "type": "drupal-module"
} }
],
"dev": true,
"dev-package-names": [
"drupal/dev-test_module2"
] ]
} }
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
"description": "This project version is changed but there should be no error because it is not a Drupal project.", "description": "This project version is changed but there should be no error because it is not a Drupal project.",
"version": "1.3.1", "version": "1.3.1",
"type": "library" "type": "library"
} },
],
"packages-dev": [
{ {
"name": "drupal/dev-test_module", "name": "drupal/dev-test_module",
"version": "1.3.0", "version": "1.3.0",
...@@ -29,5 +27,10 @@ ...@@ -29,5 +27,10 @@
"version": "1.3.1", "version": "1.3.1",
"type": "library" "type": "library"
} }
],
"dev": true,
"dev-package-names": [
"drupal/dev-test_module",
"other/dev-changed"
] ]
} }
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
"description": "This project version is changed but there should be no error because it is not a Drupal project.", "description": "This project version is changed but there should be no error because it is not a Drupal project.",
"version": "1.3.2", "version": "1.3.2",
"type": "library" "type": "library"
} },
],
"packages-dev": [
{ {
"name": "drupal/dev-test_module", "name": "drupal/dev-test_module",
"version": "1.3.1", "version": "1.3.1",
...@@ -29,5 +27,10 @@ ...@@ -29,5 +27,10 @@
"version": "1.3.2", "version": "1.3.2",
"type": "library" "type": "library"
} }
],
"dev": true,
"dev-package-names": [
"drupal/dev-test_module",
"other/dev-changed"
] ]
} }
...@@ -52,6 +52,8 @@ class StagedDatabaseUpdateValidatorTest extends AutomaticUpdatesKernelTestBase { ...@@ -52,6 +52,8 @@ class StagedDatabaseUpdateValidatorTest extends AutomaticUpdatesKernelTestBase {
$active_dir = $this->getDrupalRoot(); $active_dir = $this->getDrupalRoot();
@copy("$active_dir/composer.json", "$stage_dir/composer.json"); @copy("$active_dir/composer.json", "$stage_dir/composer.json");
@copy("$active_dir/composer.lock", "$stage_dir/composer.lock"); @copy("$active_dir/composer.lock", "$stage_dir/composer.lock");
mkdir("$stage_dir/vendor/composer", 0777, TRUE);
@copy("$active_dir/vendor/composer/installed.json", "$stage_dir/vendor/composer/installed.json");
// Copy the .install and .post_update.php files from every installed module // Copy the .install and .post_update.php files from every installed module
// into the staging directory. // into the staging directory.
......
...@@ -114,7 +114,8 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase { ...@@ -114,7 +114,8 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
// Composer data. // Composer data.
$fixture = __DIR__ . '/../../../fixtures/fake-site'; $fixture = __DIR__ . '/../../../fixtures/fake-site';
copy("$fixture/composer.json", 'public://composer.json'); copy("$fixture/composer.json", 'public://composer.json');
copy("$fixture/composer.lock", 'public://composer.lock'); mkdir('public://vendor/composer', 0777, TRUE);
copy("$fixture/vendor/composer/installed.json", 'public://vendor/composer/installed.json');
$event_dispatcher = $this->container->get('event_dispatcher'); $event_dispatcher = $this->container->get('event_dispatcher');
// Disable the disk space validator, since it doesn't work with vfsStream, // Disable the disk space validator, since it doesn't work with vfsStream,
...@@ -216,19 +217,6 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase { ...@@ -216,19 +217,6 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
$this->assertEmpty($results); $this->assertEmpty($results);
} }
/**
* Tests validation when a composer.lock file is not found.
*/
public function testNoLockFile(): void {
$fixtures_dir = realpath(__DIR__ . '/../../../fixtures/project_staged_validation/no_errors');
$results = $this->validate("$fixtures_dir/active", $fixtures_dir);
$this->assertCount(1, $results);
$result = array_pop($results);
$this->assertSame("No lockfile found. Unable to read locked packages", (string) $result->getMessages()[0]);
$this->assertSame('', (string) $result->getSummary());
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment