Merge pull request #8843 from FIDATA/feature/archive-name
Add (default) base name of archive into composer.jsonpull/8880/head
commit
ba3df8faea
|
@ -877,6 +877,21 @@ A set of options for creating package archives.
|
||||||
|
|
||||||
The following options are supported:
|
The following options are supported:
|
||||||
|
|
||||||
|
* **name:** Allows configuring base name for archive.
|
||||||
|
By default (if not configured, and `--file` is not passed as command-line argument),
|
||||||
|
`preg_replace('#[^a-z0-9-_]#i', '-', name)` is used.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "org/strangeName",
|
||||||
|
"archive": {
|
||||||
|
"name": "Strange_name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
* **exclude:** Allows configuring a list of patterns for excluded paths. The
|
* **exclude:** Allows configuring a list of patterns for excluded paths. The
|
||||||
pattern syntax matches .gitignore files. A leading exclamation mark (!) will
|
pattern syntax matches .gitignore files. A leading exclamation mark (!) will
|
||||||
result in any matching files to be included even if a previous pattern
|
result in any matching files to be included even if a previous pattern
|
||||||
|
|
|
@ -359,6 +359,10 @@
|
||||||
"type": ["object"],
|
"type": ["object"],
|
||||||
"description": "Options for creating package archives for distribution.",
|
"description": "Options for creating package archives for distribution.",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A base name for archive."
|
||||||
|
},
|
||||||
"exclude": {
|
"exclude": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"description": "A list of patterns for paths to exclude or include if prefixed with an exclamation mark."
|
"description": "A list of patterns for paths to exclude or include if prefixed with an exclamation mark."
|
||||||
|
|
|
@ -395,6 +395,11 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
|
||||||
return $this->aliasOf->getNotificationUrl();
|
return $this->aliasOf->getNotificationUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getArchiveName()
|
||||||
|
{
|
||||||
|
return $this->aliasOf->getArchiveName();
|
||||||
|
}
|
||||||
|
|
||||||
public function getArchiveExcludes()
|
public function getArchiveExcludes()
|
||||||
{
|
{
|
||||||
return $this->aliasOf->getArchiveExcludes();
|
return $this->aliasOf->getArchiveExcludes();
|
||||||
|
|
|
@ -78,7 +78,12 @@ class ArchiveManager
|
||||||
*/
|
*/
|
||||||
public function getPackageFilename(PackageInterface $package)
|
public function getPackageFilename(PackageInterface $package)
|
||||||
{
|
{
|
||||||
$nameParts = array(preg_replace('#[^a-z0-9-_]#i', '-', $package->getName()));
|
if ($package->getArchiveName()) {
|
||||||
|
$baseName = $package->getArchiveName();
|
||||||
|
} else {
|
||||||
|
$baseName = preg_replace('#[^a-z0-9-_]#i', '-', $package->getName());
|
||||||
|
}
|
||||||
|
$nameParts = array($baseName);
|
||||||
|
|
||||||
if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) {
|
if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) {
|
||||||
array_push($nameParts, $package->getDistReference(), $package->getDistType());
|
array_push($nameParts, $package->getDistReference(), $package->getDistType());
|
||||||
|
@ -131,20 +136,6 @@ class ArchiveManager
|
||||||
}
|
}
|
||||||
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
if (null === $fileName) {
|
|
||||||
$packageName = $this->getPackageFilename($package);
|
|
||||||
} else {
|
|
||||||
$packageName = $fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Archive filename
|
|
||||||
$filesystem->ensureDirectoryExists($targetDir);
|
|
||||||
$target = realpath($targetDir).'/'.$packageName.'.'.$format;
|
|
||||||
$filesystem->ensureDirectoryExists(dirname($target));
|
|
||||||
|
|
||||||
if (!$this->overwriteFiles && file_exists($target)) {
|
|
||||||
return $target;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($package instanceof RootPackageInterface) {
|
if ($package instanceof RootPackageInterface) {
|
||||||
$sourcePath = realpath('.');
|
$sourcePath = realpath('.');
|
||||||
|
@ -167,12 +158,30 @@ class ArchiveManager
|
||||||
if (file_exists($composerJsonPath = $sourcePath.'/composer.json')) {
|
if (file_exists($composerJsonPath = $sourcePath.'/composer.json')) {
|
||||||
$jsonFile = new JsonFile($composerJsonPath);
|
$jsonFile = new JsonFile($composerJsonPath);
|
||||||
$jsonData = $jsonFile->read();
|
$jsonData = $jsonFile->read();
|
||||||
|
if (!empty($jsonData['archive']['name'])) {
|
||||||
|
$package->setArchiveName($jsonData['archive']['name']);
|
||||||
|
}
|
||||||
if (!empty($jsonData['archive']['exclude'])) {
|
if (!empty($jsonData['archive']['exclude'])) {
|
||||||
$package->setArchiveExcludes($jsonData['archive']['exclude']);
|
$package->setArchiveExcludes($jsonData['archive']['exclude']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null === $fileName) {
|
||||||
|
$packageName = $this->getPackageFilename($package);
|
||||||
|
} else {
|
||||||
|
$packageName = $fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Archive filename
|
||||||
|
$filesystem->ensureDirectoryExists($targetDir);
|
||||||
|
$target = realpath($targetDir).'/'.$packageName.'.'.$format;
|
||||||
|
$filesystem->ensureDirectoryExists(dirname($target));
|
||||||
|
|
||||||
|
if (!$this->overwriteFiles && file_exists($target)) {
|
||||||
|
return $target;
|
||||||
|
}
|
||||||
|
|
||||||
// Create the archive
|
// Create the archive
|
||||||
$tempTarget = sys_get_temp_dir().'/composer_archive'.uniqid().'.'.$format;
|
$tempTarget = sys_get_temp_dir().'/composer_archive'.uniqid().'.'.$format;
|
||||||
$filesystem->ensureDirectoryExists(dirname($tempTarget));
|
$filesystem->ensureDirectoryExists(dirname($tempTarget));
|
||||||
|
|
|
@ -70,6 +70,9 @@ class ArrayDumper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($package->getArchiveName()) {
|
||||||
|
$data['archive']['name'] = $package->getArchiveName();
|
||||||
|
}
|
||||||
if ($package->getArchiveExcludes()) {
|
if ($package->getArchiveExcludes()) {
|
||||||
$data['archive']['exclude'] = $package->getArchiveExcludes();
|
$data['archive']['exclude'] = $package->getArchiveExcludes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,6 +194,9 @@ class ArrayLoader implements LoaderInterface
|
||||||
$package->setNotificationUrl($config['notification-url']);
|
$package->setNotificationUrl($config['notification-url']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($config['archive']['name'])) {
|
||||||
|
$package->setArchiveName($config['archive']['name']);
|
||||||
|
}
|
||||||
if (!empty($config['archive']['exclude'])) {
|
if (!empty($config['archive']['exclude'])) {
|
||||||
$package->setArchiveExcludes($config['archive']['exclude']);
|
$package->setArchiveExcludes($config['archive']['exclude']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Package extends BasePackage
|
||||||
protected $autoload = array();
|
protected $autoload = array();
|
||||||
protected $devAutoload = array();
|
protected $devAutoload = array();
|
||||||
protected $includePaths = array();
|
protected $includePaths = array();
|
||||||
|
protected $archiveName;
|
||||||
protected $archiveExcludes = array();
|
protected $archiveExcludes = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -551,6 +552,24 @@ class Package extends BasePackage
|
||||||
return $this->notificationUrl;
|
return $this->notificationUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets default base filename for archive
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
*/
|
||||||
|
public function setArchiveName($name)
|
||||||
|
{
|
||||||
|
$this->archiveName = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getArchiveName()
|
||||||
|
{
|
||||||
|
return $this->archiveName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a list of patterns to be excluded from archives
|
* Sets a list of patterns to be excluded from archives
|
||||||
*
|
*
|
||||||
|
|
|
@ -357,6 +357,13 @@ interface PackageInterface
|
||||||
*/
|
*/
|
||||||
public function getPrettyString();
|
public function getPrettyString();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns default base filename for archive
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getArchiveName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of patterns to exclude from package archives
|
* Returns a list of patterns to exclude from package archives
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue