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

Use Composer 2 for fixture creation #126

Merged
merged 3 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:

before_install:
- nvm use 12.13.1
- composer self-update 1.10.16
- composer self-update --1
- ../orca/bin/travis/self-test/before_install.sh
- ../orca/bin/travis/before_install.sh

Expand Down
5 changes: 5 additions & 0 deletions bin/travis/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# DESCRIPTION
# Configures the Travis CI environment, installs ORCA, and prepares the SUT.

HOST_COMPOSER=$(command -v composer)

cd "$(dirname "$0")" || exit; source _includes.sh

# The remaining before_install commands should only be run on Travis CI.
Expand Down Expand Up @@ -49,6 +51,9 @@ gem install travis
# `composer create-project` approach.
[[ -d "$ORCA_ROOT/vendor" ]] || composer -d"$ORCA_ROOT" install

# Revert to Composer 2.
"$HOST_COMPOSER" self-update --2

# Display ORCA version and configuration values.
orca --version
orca debug:env-vars
Expand Down
2 changes: 0 additions & 2 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ services:
arguments:
$minimumStability: "dev"

Composer\Package\Version\VersionGuesser: ~

Composer\Semver\VersionParser: ~

Composer\Util\ProcessExecutor: ~
Expand Down
2 changes: 1 addition & 1 deletion example/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ before_install:
# Set Node.js to a version compatible with Drupal 9 + Nightwatch.js.
- nvm use 12.13.1
# Force the build to use Composer 1 until the ecosystem is ready for v2.
- composer self-update 1.10.16
- composer self-update --1
- composer create-project --no-dev acquia/orca ../orca "$ORCA_VERSION"
- ../orca/bin/travis/before_install.sh
# For custom testing needs, add your own scripts here. See the example script
Expand Down
69 changes: 0 additions & 69 deletions src/Console/Command/Debug/DebugGuessVersionCommand.php

This file was deleted.

69 changes: 25 additions & 44 deletions src/Domain/Composer/ComposerFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Acquia\Orca\Domain\Composer;

use Acquia\Orca\Domain\Composer\Version\VersionGuesser;
use Acquia\Orca\Domain\Package\Package;
use Acquia\Orca\Domain\Package\PackageManager;
use Acquia\Orca\Helper\Filesystem\FixturePathHandler;
use Acquia\Orca\Helper\Filesystem\OrcaPathHandler;
use Acquia\Orca\Helper\Process\ProcessRunner;
use Acquia\Orca\Options\FixtureOptions;
use Composer\Package\Loader\ValidatingArrayLoader;
Expand Down Expand Up @@ -38,36 +38,36 @@ class ComposerFacade {
private $packageManager;

/**
* The process runner.
* The ORCA path handler.
*
* @var \Acquia\Orca\Helper\Process\ProcessRunner
* @var \Acquia\Orca\Helper\Filesystem\OrcaPathHandler
*/
private $processRunner;
private $orca;

/**
* The version guesser.
* The process runner.
*
* @var \Acquia\Orca\Domain\Composer\Version\VersionGuesser
* @var \Acquia\Orca\Helper\Process\ProcessRunner
*/
private $versionGuesser;
private $processRunner;

/**
* Constructs an instance.
*
* @param \Acquia\Orca\Helper\Filesystem\FixturePathHandler $fixture_path_handler
* The fixture path handler.
* @param \Acquia\Orca\Helper\Filesystem\OrcaPathHandler $orca
* The ORCA path handler.
* @param \Acquia\Orca\Domain\Package\PackageManager $package_manager
* The package manager.
* @param \Acquia\Orca\Helper\Process\ProcessRunner $process_runner
* The process runner.
* @param \Acquia\Orca\Domain\Composer\Version\VersionGuesser $version_guesser
* The version guesser.
*/
public function __construct(FixturePathHandler $fixture_path_handler, PackageManager $package_manager, ProcessRunner $process_runner, VersionGuesser $version_guesser) {
public function __construct(FixturePathHandler $fixture_path_handler, OrcaPathHandler $orca, PackageManager $package_manager, ProcessRunner $process_runner) {
$this->fixture = $fixture_path_handler;
$this->orca = $orca;
$this->packageManager = $package_manager;
$this->processRunner = $process_runner;
$this->versionGuesser = $version_guesser;
}

/**
Expand All @@ -84,8 +84,7 @@ public function createProject(FixtureOptions $options): void {
$stability = 'dev';
}

$this->processRunner->runOrcaVendorBin([
'composer',
$this->processRunner->runExecutable('composer', [
'create-project',
"--stability={$stability}",
'--no-dev',
Expand All @@ -94,7 +93,7 @@ public function createProject(FixtureOptions $options): void {
'--no-interaction',
$this->getProjectTemplateString(),
$this->fixture->getPath(),
]);
], $this->orca->getPath());
}

/**
Expand All @@ -109,7 +108,7 @@ private function getProjectTemplateString(): string {

// The project template is the SUT.
if ($sut && $sut->isProjectTemplate()) {
return $this->guessSutTemplateString();
return $this->options->getProjectTemplate();
}

// The project template is BLT project.
Expand All @@ -120,23 +119,6 @@ private function getProjectTemplateString(): string {
return $project_template;
}

/**
* Gets the project template string when the template is the SUT.
*
* Gets the project template string based on Composer's guess of its version.
*
* @return string
* The project template string.
*/
private function guessSutTemplateString(): string {
/** @var \Acquia\Orca\Domain\Package\Package $sut */
$sut = $this->options->getSut();

$version = $this->versionGuesser
->guessVersion($sut->getRepositoryUrlAbsolute());
return $this->options->getProjectTemplate() . ':' . $version;
}

/**
* Gets the project template string for BLT project.
*
Expand All @@ -147,7 +129,7 @@ private function getBltProjectTemplateString(): string {
$project_template = $this->options->getProjectTemplate();
$blt = $this->packageManager->getBlt();
if ($this->options->isDev()) {
return $project_template . ':' . $blt->getVersionDev($this->options->getCore());
return $project_template;
}
return $project_template . ':' . $blt->getVersionRecommended($this->options->getCore());
}
Expand All @@ -163,26 +145,25 @@ private function getBltProjectTemplateString(): string {
* @throws \Acquia\Orca\Exception\OrcaParseError
*/
public function createProjectFromPackage(Package $package): void {
$version = $this->versionGuesser->guessVersion($package->getRepositoryUrlAbsolute());
$repository = json_encode([
'type' => 'path',
'url' => $package->getRepositoryUrlAbsolute(),
'options' => [
'symlink' => FALSE,
'canonical' => TRUE,
],
]);
$this->processRunner->runOrcaVendorBin([
'composer',
$this->processRunner->runExecutable('composer', [
'create-project',
'--stability=dev',
"--repository={$repository}",
'--no-dev',
'--no-scripts',
'--no-install',
'--no-interaction',
"{$package->getPackageName()}:{$version}",
$package->getPackageName(),
$this->fixture->getPath(),
]);
], $this->orca->getPath());
}

/**
Expand Down Expand Up @@ -261,10 +242,11 @@ public function requirePackages(array $packages, ?bool $prefer_source = FALSE, ?
* Updates composer.lock.
*/
public function updateLockFile(): void {
$this->runComposer([
'update',
'--lock',
]);
$this->processRunner
->runExecutable('composer', [
'update',
'--lock',
], $this->fixture->getPath());
}

/**
Expand All @@ -276,10 +258,9 @@ public function updateLockFile(): void {
* A list of of command arguments, e.g., ['vendor/package'].
*/
private function runComposer(array $command, array $args = []): void {
array_unshift($command, 'composer');
$command = array_merge($command, $args);
$this->processRunner
->runOrcaVendorBin($command, $this->fixture->getPath());
->runExecutable('composer', $command, $this->fixture->getPath());
}

}
80 changes: 0 additions & 80 deletions src/Domain/Composer/Version/VersionGuesser.php

This file was deleted.

Loading