Browse Source

Support for Abandoned in Packages

Added parsing for abandoned property into the CompletePackage Object.
Rafael Dohms 10 years ago
parent
commit
d6d087d348

+ 8 - 0
src/Composer/Package/AliasPackage.php

@@ -333,6 +333,14 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
     {
         return $this->aliasOf->getArchiveExcludes();
     }
+    public function isAbandoned()
+    {
+        return $this->aliasOf->isAbandoned();
+    }
+    public function getReplacementPackage()
+    {
+        return $this->aliasOf->getReplacementPackage();
+    }
     public function __toString()
     {
         return parent::__toString().' (alias of '.$this->aliasOf->getVersion().')';

+ 29 - 0
src/Composer/Package/CompletePackage.php

@@ -27,6 +27,7 @@ class CompletePackage extends Package implements CompletePackageInterface
     protected $homepage;
     protected $scripts = array();
     protected $support = array();
+    protected $abandoned = false;
 
     /**
      * @param array $scripts
@@ -169,4 +170,32 @@ class CompletePackage extends Package implements CompletePackageInterface
     {
         return $this->support;
     }
+
+    /**
+     * @return boolean
+     */
+    public function isAbandoned()
+    {
+        return (boolean) $this->abandoned;
+    }
+
+    /**
+     * @param boolean|string $abandoned
+     */
+    public function setAbandoned($abandoned)
+    {
+        $this->abandoned = $abandoned;
+    }
+
+    /**
+     * If the package is abandoned and has a suggested replacement, this method returns it
+     *
+     * @return string|null
+     */
+    public function getReplacementPackage()
+    {
+        return $this->abandoned ?: null;
+    }
+
+
 }

+ 14 - 0
src/Composer/Package/CompletePackageInterface.php

@@ -78,4 +78,18 @@ interface CompletePackageInterface extends PackageInterface
      * @return array
      */
     public function getSupport();
+
+    /**
+     * Returns if the package is abandoned or not
+     *
+     * @return boolean
+     */
+    public function isAbandoned();
+
+    /**
+     * If the package is abandoned and has a suggested replacement, this method returns it
+     *
+     * @return string
+     */
+    public function getReplacementPackage();
 }

+ 3 - 1
src/Composer/Package/Dumper/ArrayDumper.php

@@ -97,7 +97,7 @@ class ArrayDumper
                 'homepage',
                 'keywords',
                 'repositories',
-                'support',
+                'support'
             );
 
             $data = $this->dumpValues($package, $keys, $data);
@@ -105,6 +105,8 @@ class ArrayDumper
             if (isset($data['keywords']) && is_array($data['keywords'])) {
                 sort($data['keywords']);
             }
+
+            $data['abandoned'] = $package->getReplacementPackage() ?: false;
         }
 
         if ($package instanceof RootPackageInterface) {

+ 4 - 0
src/Composer/Package/Loader/ArrayLoader.php

@@ -195,6 +195,10 @@ class ArrayLoader implements LoaderInterface
             if (isset($config['support'])) {
                 $package->setSupport($config['support']);
             }
+
+            if (isset($config['abandoned'])) {
+                $package->setAbandoned($config['abandoned']);
+            }
         }
 
         if ($aliasNormalized = $this->getBranchAlias($config)) {

+ 21 - 1
tests/Composer/Test/Package/Dumper/ArrayDumperTest.php

@@ -45,7 +45,8 @@ class ArrayDumperTest extends \PHPUnit_Framework_TestCase
             array(
                 'name' => 'foo',
                 'version' => '1.0',
-                'version_normalized' => '1.0.0.0'
+                'version_normalized' => '1.0.0.0',
+                'abandoned' => false
             ),
             $config
         );
@@ -62,12 +63,31 @@ class ArrayDumperTest extends \PHPUnit_Framework_TestCase
         $this->assertSame('dev', $config['minimum-stability']);
     }
 
+    public function testDumpAbandoned()
+    {
+        $this->packageExpects('getReplacementPackage', true);
+
+        $config = $this->dumper->dump($this->package);
+
+        $this->assertSame(true, $config['abandoned']);
+    }
+
+    public function testDumpAbandonedReplacement()
+    {
+        $this->packageExpects('getReplacementPackage', 'foo/bar');
+
+        $config = $this->dumper->dump($this->package);
+
+        $this->assertSame('foo/bar', $config['abandoned']);
+    }
+
     /**
      * @dataProvider getKeys
      */
     public function testKeys($key, $value, $method = null, $expectedValue = null)
     {
         $this->packageExpects('get'.ucfirst($method ?: $key), $value);
+        $this->packageExpects('isAbandoned', $value);
 
         $config = $this->dumper->dump($this->package);
 

+ 26 - 1
tests/Composer/Test/Package/Loader/ArrayLoaderTest.php

@@ -117,7 +117,8 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase
             'archive' => array(
                 'exclude' => array('/foo/bar', 'baz', '!/foo/bar/baz'),
             ),
-            'transport-options' => array('ssl' => array('local_cert' => '/opt/certs/test.pem'))
+            'transport-options' => array('ssl' => array('local_cert' => '/opt/certs/test.pem')),
+            'abandoned' => 'foo/bar'
         );
 
         $package = $this->loader->load($config);
@@ -138,4 +139,28 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase
         $this->assertInstanceOf('Composer\Package\AliasPackage', $package);
         $this->assertEquals('1.0.x-dev', $package->getPrettyVersion());
     }
+
+    public function testAbandoned()
+    {
+        $config = array(
+            'name' => 'A',
+            'version' => '1.2.3.4',
+            'abandoned' => 'foo/bar'
+        );
+
+        $package = $this->loader->load($config);
+        $this->assertTrue($package->isAbandoned());
+        $this->assertEquals('foo/bar', $package->getReplacementPackage());
+    }
+
+    public function testNotAbandoned()
+    {
+        $config = array(
+            'name' => 'A',
+            'version' => '1.2.3.4'
+        );
+
+        $package = $this->loader->load($config);
+        $this->assertFalse($package->isAbandoned());
+    }
 }