Normalize the alias of branch.

@param PackageInterface $package The package instance

@return string The alias branch name
504290
protected function normalizeBranchAlias(PackageInterface $package)
    {
        $stability = VersionParser::parseStability($this->versionParser->normalize($this->rootPackageVersion));
        $aliasNormalized = 'dev-'.$this->rootPackageVersion;

        if (BasePackage::STABILITY_STABLE === BasePackage::$stabilities[$stability]
            && null === $this->findPackage($package->getName(), $this->rootPackageVersion)) {
            $aliasNormalized = $this->versionParser->normalize($this->rootPackageVersion);
        }

        return $aliasNormalized;
    }
968599
public function isForPackage(PackageInterface $package)
    {
        if ($this->getForPackage() !== $package->getName()) {
            return false;
        }
        $fpv = $this->getForPackageVersion();
        if ($fpv !== null) {
            $pv = new Constraint('=', $package->getVersion());
            if (!$fpv->matches($pv)) {
                return false;
            }
        }

        return true;
    }
329538
public function uninstallPackage(PackageInterface $package, InstallerInterface $installer)
    {
        if (!$this->isPackageInstalled($package)) {
            throw new RuntimeException(sprintf('Package %s is not installed.', $package->getName()));
        }
        $installer->uninstall($package);
    }
325684
protected function isSourceDirUnused(PackageInterface $package)
    {
        $usageData = $this->packageDataManager->getPackageUsage($package);

        return sizeof($usageData) <= 1;
    }
186432
public function isPackageInstalled(PackageInterface $package)
    {
        return $this->filesystem->exists($this->config->getInstallDir() . '/' . $package->getName() . '/.bower.json');
    }
954838
public function getInstallPath(PackageInterface $package)
    {
        $moddir = explode('/', $package->getName());

        $xoops_modules = './htdocs/modules';

        $extra = $this->composer->getPackage()->getExtra();
        if (isset($extra['xoops_modules_path'])) {
            $xoops_modules = $extra['xoops_modules_path'];
        }

        return $xoops_modules . '/' . $moddir[1];
    }
866407
public function removePackageUsage(PackageInterface $package)
    {
        $usageData = $this->getPackageUsage($package);
        $newUsageData = array();
        $projectName = $this->composer->getPackage()->getName();

        foreach ($usageData as $usage) {
            if ($projectName !== $usage) {
                $newUsageData[] = $usage;
            }
        }

        $this->updatePackageUsageFile($package, $newUsageData);
    }
1336044
protected function getSymlinkSourcePath(PackageInterface $package)
    {
        if (null != $this->config->getSymlinkBasePath()) {
            $targetDir = $package->getTargetDir();
            $sourcePath =
                $this->config->getSymlinkBasePath()
                . '/' . $package->getPrettyName()
                . '/' . $package->getPrettyVersion()
                . ($targetDir ? '/' . $targetDir : '')
            ;
        } else {
            $sourcePath = $this->getInstallPath($package);
        }

        return $sourcePath;
    }
190396
public function lockPackage(PackageInterface $package)
    {
        $name = $package->getPrettyName();
        $lock = 'extra/tenside/version-locks/' . $this->escape($name);

        // Nothing to do?
        if ($this->has($lock)) {
            return $this;
        }

        if ($this->isRequiring($name)) {
            $this->set($lock, $this->getRequire($name));
        } else {
            $this->set($lock, false);
        }

        $this->requirePackage(
            $package->getPrettyName(),
            PackageConverter::convertPackageVersion($package, true)
        );

        return $this;
    }
205634
public function addPackage($alias, $package)
    {
        $container = $this->getContainer();

        if (is_string($package)) {
            if (!class_exists($package)) {
                return null;
            }

            /** @var \Windwalker\Core\Package\AbstractPackage $package */
            $package = $this->container->newInstance($package);
        }

        if (!$package) {
            return null;
        }

        // If we set custom name to package, use this as alias.
        if (!is_numeric($alias)) {
            $package->setName($alias);
        }

        // Get package identify name.
        $name = $package->getName();

        // Set container and init it
        $subContainer = $container->createChild($name);

        $package->setContainer($subContainer)->boot();

        /** @var WindwalkerApplicationInterface $application */
        $application = $container->get('application');

        // If in Console mode, register commands.
        if ($application->isConsole()) {
            $package->registerCommands($application);
        }

        $container->share('package.' . $name, $package);
        $this->packages[$name] = $package;

        $subContainer->alias('package', 'package.' . $name);

        // Add alias map
        $this->aliases[get_class($package)] = $name;

        return $package;
    }
890536
protected function loadInits(PackageInterface $package)
    {
        if (!$package->getInits()) {
            return $this;
        }

        $initLoader = \Parable\DI\Container::create(\Parable\Framework\Loader\InitLoader::class);
        $initLoader->load($package->getInits());
        return $this;
    }
1021879
protected function getPackageEntryPoints(PackageInterface $package)
    {
        $dir = $this->composer->getInstallationManager()->getInstallPath($package);
        $entry = $this->getPackageExtra($package, 'wordpress-muplugin-entry');
        $entryPoints = $entry ? (is_array($entry) ? $entry : [ $entry ]) : [];

        if (empty($entryPoints)) {
            $phpFiles = glob(rtrim($dir, '/') . '/*.php', GLOB_NOSORT);

            foreach ($phpFiles as $file) {
                $entryPoints[] = basename($file);
            }
        }

        foreach ($entryPoints as $index => $file) {
            $entryPoints[ $index ] = $dir . $file;
        }

        return array_filter($entryPoints, [ $this, 'looksLikePlugin' ]);
    }
938154
public function getInstallPath(PackageInterface $package)
    {
        if ($package->getType() === 'oxid-base') {
            return $this->_locations[$package->getType()];
        }
        $themeName = "ra";
        $extra = $package->getExtra();
        $installFolder = $this->_locations[$package->getType()] . '/' . str_replace(array($themeName . "/", '-theme'), '', $package->getPrettyName());
        if ($extra) {
            $themeName = $extra["themeName"];
            $installFolder = $this->_locations[$package->getType()] . '/' . $themeName;
        }

        return $installFolder;
    }
1108486
public static function primaryNamespace($package)
    {
        $primaryNs = null;
        $autoLoad = $package->getAutoload();
        foreach ($autoLoad as $type => $pathMap) {
            if ($type !== 'psr-4') {
                continue;
            }
            $count = count($pathMap);

            if ($count === 1) {
                $primaryNs = key($pathMap);
                break;
            }

            $matches = preg_grep('#^(\./)?src/?$#', $pathMap);
            if ($matches) {
                $primaryNs = key($matches);
                break;
            }

            foreach (['', '.'] as $path) {
                $key = array_search($path, $pathMap, true);
                if ($key !== false) {
                    $primaryNs = $key;
                }
            }
            break;
        }

        if (!$primaryNs) {
            throw new RuntimeException(
                sprintf(
                    "Unable to get primary namespace for package %s." .
                    "\nEnsure you have added proper 'autoload' section to your plugin's config.",
                    $package->getName()
                )
            );
        }
        return trim($primaryNs, '\\');
    }
501689
protected function installGitignore(PackageInterface $package)
    {
        $installPath = $this->getInstallPath($package) . '/.gitignore';
        $templatePath = $this->getTempPath($package) . '/.gitignore.template';
        
        $data = ['APP_PUBLIC' => $this->plugin->getPublicDirectory()];
        
        if (! file_exists($installPath)) {
            return $this->compileTemplate($templatePath, $installPath, $data);
        }
        
        $downloadGitignore = $this->compileTemplate($templatePath, $data);
        $installGitignore = file_get_contents($installPath);
        
        $gitignore = preg_split('/\r?\n/', $downloadGitignore . PHP_EOL . '# User rules' . PHP_EOL . $installGitignore);
        $group = 'user rules';
        $groups = [];
        $rules = [];
        
        $groups['user rules'] = [];
        
        foreach ($gitignore as $rule) {
            if (preg_match('/^#\s*(.*)/', $rule, $matches)) {
                $group = strtolower($matches[1]);
                
                if (! isset($groups[$group])) {
                    $groups[$group] = [];
                }
            } elseif (! preg_match('/^\s*$/', $rule) && ! in_array($rule, $rules)) {
                $groups[$group][] = $rules[] = $rule;
            }
        }
        
        $gitignore = [];
        
        foreach ($groups as $group => $rules) {
            if (! count($rules) || $group == 'user rules') {
                continue;
            }
            
            $this->sortRules($rules);
            
            $gitignore[] = '# ' . ucfirst($group);
            $gitignore = array_merge($gitignore, $rules);
            $gitignore[] = '';
        }
        
        $this->sortRules($groups['user rules']);
        
        $gitignore[] = '# User rules';
        $gitignore = array_merge($gitignore, $groups['user rules']);
        $gitignore[] = '';
        
        file_put_contents($installPath, implode(PHP_EOL, $gitignore));
    }
106423
public function normalize(PathInterface $path)
    {
        if ($path instanceof AbsolutePathInterface) {
            return $this->normalizeAbsolutePath($path);
        }

        return $this->normalizeRelativePath($path);
    }
742359
protected function getSourceStandards(PackageInterface $package)
    {
        $basePath = $this->getInstallPath($package);

        return $this->findStandards($basePath);
    }