Persist the patches_applied to the package extra section.

@param \Composer\Package\PackageInterface $package
@param array $patchesAppliedData
12702
protected function setPatchedPackageData(PackageInterface $package, array $patchesAppliedData)
    {
        $extra = $package->getExtra();
        $extra['patches_applied'] = $patchesAppliedData;
        $package->setExtra($extra);
        $this->composer->getRepositoryManager()->getLocalRepository()->write();
    }
719463
public function add(Package $package)
    {
        $name = $package->getName();
        if (isset($this->packages[$name])) {
            return;
        }

        $this->packages[$name] = $package;
    }
101755
public function containsPatchesFor(PackageInterface $package)
    {
        foreach ($this->getPatches() as $patch) {
            if ($patch->isForPackage($package)) {
                return true;
            }
        }

        return false;
    }
32865
protected function mustUninstallPackage(PackageInterface $package)
    {
        if ($package instanceof AliasPackage) {
            return false;
        }
        $packageExtra = $package->getExtra();
        $packageHasAppliedPatches = !empty($packageExtra['patches_applied']);
        $packagePatches = $this->getPatchCollection()->getPatchesFor($package);
        $packageHasPatches = !$packagePatches->isEmpty();
        if ($packageHasAppliedPatches === false && $packageHasPatches === false) {
            return false;
        }
        if ($packageHasAppliedPatches === true && $packageHasPatches === true) {
            $installedHash = empty($packageExtra['patches_applied']['hash']) ? '' : $packageExtra['patches_applied']['hash'];
            if ($installedHash === '') {
                return true;
            }
            $patchesHash = $packagePatches->getHash();
            if ($installedHash !== $patchesHash) {
                return true;
            }
        }

        return false;
    }
126733
protected function removeLoader(PackageInterface $package)
    {
        $target = $this->getLoaderFileInstallPath($package);

        if (!$this->filesystem->remove($target)) {
            throw new \RuntimeException('Could not completely delete ' . $target . ', aborting.');
        }
    }
435324
public function update(\Composer\Repository\InstalledRepositoryInterface $repo, \Composer\Package\PackageInterface $initial, 
			\Composer\Package\PackageInterface $target) {
		if (!$this->needsUpdate($initial)) {
			//add the new version of the module to the composer.lock
			$repo->removePackage($initial);
			if (!$repo->hasPackage($target)) {
				$repo->addPackage(clone $target);
			}
			return;
		}
				
    	$this->moveBackResources($initial);
				
		parent::update($repo, $initial, $target);
		
		$this->removeResources($target);
		$this->installResources($target);
	}
608745
public static function registerPackage(PackageInterface $package, $target, AssetsInstallerInterface $installer = null)
    {
        self::$__autoloader->registerPackage($package, $target, $installer);
    }
153437
protected function iterateDependencies(Package $package, $dev = false)
    {
        $deps = $dev ? $package->getDevRequires() : $package->getRequires();
        foreach (array_keys($deps) as $target) {
            if (isset($this->plainList[$target]) && empty($this->orderedList[$target])) {
                $this->iteratePackage($this->plainList[$target]);
            }
        }
    }
455951
public function removeComposerPatch($package, $url) {
    $composer_json = $this->getComposerJson();
    if (!empty($composer_json['extra']['patches'][$package])) {
      foreach ($composer_json['extra']['patches'][$package] as $key => $patch_url) {
        if ($patch_url == $url) {
          unset($composer_json['extra']['patches'][$package][$key]);
          // If that was the only patch for this module, unset the parent too.
          if (empty($composer_json['extra']['patches'][$package])) {
            unset($composer_json['extra']['patches'][$package]);
          }
          $this->writeComposerJson($composer_json);

          return TRUE;
        }
      }
    }
    return FALSE;
  }
914695
public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        if (false === parent::isInstalled($repo, $package)) {
            return false;
        }

        $targetRoot = $this->getContaoRoot();

        foreach ($this->getSources($package) as $targetPath) {
            if (!file_exists($this->filesystem->normalizePath($targetRoot . '/' . $targetPath))) {
                return false;
            }
        }

        return true;
    }
1075203
public static function isAsset(PackageInterface $package, array $configPackages = array())
    {
        $projectConfig = self::getProjectActivation($package, $configPackages);
        $enabled = false !== $projectConfig;

        return $enabled && (static::hasExtraActivation($package)
            || static::hasPluginDependency($package->getRequires())
            || static::hasPluginDependency($package->getDevRequires())
            || true === $projectConfig);
    }
116
public function getPattern(PackageInterface $package)
    {
        if (isset($this->packages[$package->getName()])) {
            return $this->packages[$package->getName()];
        } elseif (isset($this->packages[$package->getPrettyName()])) {
            return $this->packages[$package->getPrettyName()];
        } elseif (isset($this->types[$package->getType()])) {
            return $this->types[$package->getType()];
        }
    }
739806
protected function deleteIgnoredFiles(PackageInterface $package)
    {
        $manager = IgnoreFactory::create($this->config, $this->composer, $package, $this->getInstallPath($package));

        if ($manager->isEnabled() && !$manager->hasPattern()) {
            $this->addIgnorePatterns($manager, $package);
        }

        $manager->cleanup();
    }
396207
protected function getPackageExtra(PackageInterface $package, $key, $default = null)
    {
        $extra = $package->getExtra();

        return array_key_exists($key, $extra) ? $extra[ $key ] : $default;
    }
1063844
protected function extractPatchData(PackageInterface $package, $patchData)
    {
        $levels = null;
        if (is_string($patchData)) {
            $path = $patchData;
        } else {
            if (!is_array($patchData) || !isset($patchData['path']) || is_string($patchData['path'])) {
                throw new Exception\InvalidPackageConfigurationValue($package, 'extra.patches.[...]', $package, "The value of a patch must be a string or an array with a 'path' node value.");
            }
            $path = $patchData['path'];
            if (isset($patchData['levels'])) {
                $levels = $patchData['levels'];
                if (!is_array($levels) || empty($levels)) {
                    throw new Exception\InvalidPackageConfigurationValue($package, 'extra.patches.[...].levels', $package, 'The patch levels must be an array of strings.');
                }
            }
        }
        if ($levels === null) {
            $levels = $this->getDefaultPatchLevels();
        }

        return array($path, $levels);
    }
1261216
protected function addExtension(PackageInterface $package)
    {
        $extra = $package->getExtra();
        if (isset($extra[self::EXTRA_FIELD]['name'])) {
            //处理前端模块
            if (isset($extra[self::EXTRA_FIELD]['frontend']['class'])) {
                $modules = $this->loadConfig(self::FRONTEND_MODULE_FILE);
                $modules[$extra[self::EXTRA_FIELD]['name']] = $extra[self::EXTRA_FIELD]['frontend'];
                $this->saveConfig($modules, self::FRONTEND_MODULE_FILE);
            }
            //处理后端模块
            if (isset($extra[self::EXTRA_FIELD]['backend']['class'])) {
                $backendModules = $this->loadConfig(self::BACKEND_MODULE_FILE);
                $backendModules[$extra[self::EXTRA_FIELD]['name']] = $extra[self::EXTRA_FIELD]['backend'];
                $this->saveConfig($backendModules, self::BACKEND_MODULE_FILE);
            }
            //处理迁移
            if (isset($extra[self::EXTRA_FIELD]['migrationNamespace'])) {
                $migrations = $this->loadConfig(self::MIGRATION_FILE);
                $migrations[] = $extra[self::EXTRA_FIELD]['migrationNamespace'];
                $migrations = array_unique($migrations);
                $this->saveConfig($migrations, self::MIGRATION_FILE);
            }
            //处理语言包
            if (isset($extra[self::EXTRA_FIELD]['name']) && isset($extra[self::EXTRA_FIELD]['i18n'])) {
                $translates = $this->loadConfig(self::TRANSLATE_FILE);
                $translateName = $extra[self::EXTRA_FIELD]['name'] . '*';
                $translates[$translateName] = $extra[self::EXTRA_FIELD]['i18n'];
                $this->saveConfig($translates, self::TRANSLATE_FILE);
            }
            //处理事件
            if (isset($extra[self::EXTRA_FIELD]['name']) && isset($extra[self::EXTRA_FIELD]['events'])) {
                $events = $this->loadConfig(self::EVENT_FILE);
                $translateName = $extra[self::EXTRA_FIELD]['name'];
                $events[$translateName] = $extra[self::EXTRA_FIELD]['events'];
                $this->saveConfig($events, self::EVENT_FILE);
            }
            //处理定时任务
            if (isset($extra[self::EXTRA_FIELD]['name']) && isset($extra[self::EXTRA_FIELD]['cron'])) {
                $crons = $this->loadConfig(self::CRON_FILE);
                $translateName = $extra[self::EXTRA_FIELD]['name'];
                $crons[$translateName] = $extra[self::EXTRA_FIELD]['cron'];
                $this->saveConfig($crons, self::CRON_FILE);
            }
        }
    }
1102063
public function applyPatch(Patch $patch, PackageInterface $package)
    {
        $this->io->write('<info>Applying patch '.$patch->getFromPackage()->getName().'/'.$patch->getDescription().' to '.$package->getName().'... </info>', false);
        $baseDirectory = $this->installationManager->getInstallPath($package);
        $this->eventDispatcher->dispatch(null, new PatchEvent(PatchEvent::EVENTNAME_PRE_APPLY_PATCH, $patch));
        try {
            if (GitPatcher::shouldBeUsetToApplyPatchesTo($baseDirectory)) {
                $this->getGitPatcher()->applyPatch($patch, $baseDirectory);
            } else {
                $this->getPatchPatcher()->applyPatch($patch, $baseDirectory);
            }
            $this->io->write('<info>done.</info>');
        } catch (Exception\PatchAlreadyApplied $x) {
            $this->io->write('<info>patch was already applied.</info>');
        }
        $this->eventDispatcher->dispatch(null, new PatchEvent(PatchEvent::EVENTNAME_POST_APPLY_PATCH, $patch));
    }