Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit with build command

  • Loading branch information...
commit 4badd6d232df3f986f443b9a5aced70973df8518 0 parents
@Seldaek Seldaek authored
6 .gitignore
@@ -0,0 +1,6 @@
+/.settings
+/.project
+/.buildpath
+/satis.phar
+/composer.lock
+/vendor
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Jordi Boggiano, Nils Adermann
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
31 README.md
@@ -0,0 +1,31 @@
+Satis - Package Repository Generator
+====================================
+
+
+
+Contributing
+------------
+
+All code contributions - including those of people having commit access -
+must go through a pull request and approved by a core developer before being
+merged. This is to ensure proper review of all the code.
+
+Fork the project, create a feature branch, and send us a pull request.
+
+Requirements
+------------
+
+PHP 5.3+
+
+Authors
+-------
+
+Jordi Boggiano - <j.boggiano@seld.be> - <http://twitter.com/seldaek> - <http://seld.be><br />
+Nils Adermann - <naderman@naderman.de> - <http://twitter.com/naderman> - <http://www.naderman.de><br />
+
+See also the list of [contributors](https://github.com/composer/satis/contributors) who participated in this project.
+
+License
+-------
+
+Satis is licensed under the MIT License - see the LICENSE file for details
14 bin/compile
@@ -0,0 +1,14 @@
+#!/usr/bin/env php
+<?php
+
+if (!@include __DIR__.'/../vendor/.composer/autoload.php') {
+ die('You must set up the project dependencies, run the following commands:
+wget http://getcomposer.org/composer.phar
+php composer.phar install
+');
+}
+
+use Composer\Satis\Compiler;
+
+$compiler = new Compiler();
+$compiler->compile();
14 bin/satis
@@ -0,0 +1,14 @@
+#!/usr/bin/env php
+<?php
+
+if (!@include __DIR__.'/../vendor/.composer/autoload.php') {
+ die('You must set up the project dependencies, run the following commands:
+wget http://getcomposer.org/composer.phar
+php composer.phar install
+');
+}
+
+use Composer\Satis\Console\Application;
+
+$application = new Application();
+$application->run();
29 composer.json
@@ -0,0 +1,29 @@
+{
+ "name": "composer/satis",
+ "description": "Simple Repository Generator",
+ "keywords": ["package", "repository", "generator"],
+ "homepage": "https://github.com/composer/satis",
+ "type": "library",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Jordi Boggiano",
+ "email": "j.boggiano@seld.be",
+ "homepage": "http://seld.be"
+ },
+ {
+ "name": "Nils Adermann",
+ "email": "naderman@naderman.de",
+ "homepage": "http://www.naderman.de"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.0",
+ "composer/composer": "*",
+ "symfony/console": "2.0.6",
+ "symfony/process": "2.0.6"
+ },
+ "autoload": {
+ "psr-0": { "Composer\\Satis": "src/" }
+ }
+}
25 phpunit.xml.dist
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="tests/bootstrap.php"
+>
+ <testsuites>
+ <testsuite name="Satis Test Suite">
+ <directory>./tests/Composer/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./src/Composer/</directory>
+ </whitelist>
+ </filter>
+</phpunit>
80 src/Composer/Satis/Command/BuildCommand.php
@@ -0,0 +1,80 @@
+<?php
+
+/*
+ * This file is part of Satis.
+ *
+ * (c) Jordi Boggiano <j.boggiano@seld.be>
+ * Nils Adermann <naderman@naderman.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Satis\Command;
+
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Command\Command;
+use Composer\Console\Application as ComposerApplication;
+use Composer\Package\Dumper\ArrayDumper;
+use Composer\Package\LinkConstraint\VersionConstraint;
+use Composer\Json\JsonFile;
+
+/**
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class BuildCommand extends Command
+{
+ protected function configure()
+ {
+ $this
+ ->setName('build')
+ ->setDescription('Builds a repository out of a composer json file')
+ ->setDefinition(array(
+ new InputArgument('file', InputArgument::REQUIRED, 'Json file to use'),
+ new InputArgument('build-dir', InputArgument::REQUIRED, 'Location where to output built files'),
+ ))
+ ->setHelp(<<<EOT
+The <info>build</info> command reads the given json file and
+outputs a composer repository in the given build-dir.
+EOT
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $composer = $this->getComposer($input->getArgument('file'));
+
+ $packages = array();
+ $targets = array();
+ $dumper = new ArrayDumper;
+
+ foreach ($composer->getPackage()->getRequires() as $link) {
+ $targets[$link->getTarget()] = $link->getConstraint();
+ }
+
+ foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
+ foreach ($repository->getPackages() as $package) {
+ $name = $package->getName();
+ if (isset($targets[$name]) && $targets[$name]->matches(new VersionConstraint('=', $package->getVersion()))) {
+ $packages[$package->getName()][$package->getVersion()] = $dumper->dump($package);
+ }
+ }
+ }
+
+ $output->writeln('Writing packages.json');
+ $repoJson = new JsonFile($input->getArgument('build-dir').'/packages.json');
+ $repoJson->write($packages);
+ }
+
+ /**
+ * @return Composer
+ */
+ public function getComposer($file)
+ {
+ return ComposerApplication::bootstrapComposer($file);
+ }
+}
130 src/Composer/Satis/Compiler.php
@@ -0,0 +1,130 @@
+<?php
+
+/*
+ * This file is part of Satis.
+ *
+ * (c) Jordi Boggiano <j.boggiano@seld.be>
+ * Nils Adermann <naderman@naderman.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Satis;
+
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Process\Process;
+
+/**
+ * The Compiler class compiles satis into a phar
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class Compiler
+{
+ /**
+ * Compiles satis into a single phar file
+ *
+ * @throws \RuntimeException
+ * @param string $pharFile The full path to the file to create
+ */
+ public function compile($pharFile = 'satis.phar')
+ {
+ if (file_exists($pharFile)) {
+ unlink($pharFile);
+ }
+
+ $process = new Process('git log --pretty="%h" -n1 HEAD');
+ if ($process->run() != 0) {
+ throw new \RuntimeException('The git binary cannot be found.');
+ }
+ $this->version = trim($process->getOutput());
+
+ $phar = new \Phar($pharFile, 0, 'satis.phar');
+ $phar->setSignatureAlgorithm(\Phar::SHA1);
+
+ $phar->startBuffering();
+
+ $finder = new Finder();
+ $finder->files()
+ ->ignoreVCS(true)
+ ->name('*.php')
+ ->notName('Compiler.php')
+ ->in(dirname(__DIR__))
+ ;
+
+ foreach ($finder as $file) {
+ $this->addFile($phar, $file);
+ }
+
+ $finder = new Finder();
+ $finder->files()
+ ->ignoreVCS(true)
+ ->name('*.php')
+ ->in(__DIR__.'/../../vendor/')
+ ;
+
+ foreach ($finder as $file) {
+ $this->addFile($phar, $file);
+ }
+
+ $this->addSatisBin($phar);
+
+ // Stubs
+ $phar->setStub($this->getStub());
+
+ $phar->stopBuffering();
+
+ $phar->compressFiles(\Phar::GZ);
+
+ $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../LICENSE'), false);
+
+ unset($phar);
+ }
+
+ private function addFile($phar, $file, $strip = true)
+ {
+ $path = str_replace(dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR, '', $file->getRealPath());
+
+ if ($strip) {
+ $content = php_strip_whitespace($file);
+ } else {
+ $content = "\n".file_get_contents($file)."\n";
+ }
+
+ $content = str_replace('@package_version@', $this->version, $content);
+
+ $phar->addFromString($path, $content);
+ }
+
+ private function addSatisBin($phar)
+ {
+ $content = file_get_contents(__DIR__.'/../../bin/satis');
+ $content = preg_replace('{^#!/usr/bin/env php\s*}', '', $content);
+ $phar->addFromString('bin/satis', $content);
+ }
+
+ private function getStub()
+ {
+ return <<<'EOF'
+#!/usr/bin/env php
+<?php
+/*
+ * This file is part of Satis.
+ *
+ * (c) Jordi Boggiano <j.boggiano@seld.be>
+ * Nils Adermann <naderman@naderman.de>
+ *
+ * For the full copyright and license information, please view
+ * the license that is located at the bottom of this file.
+ */
+
+Phar::mapPhar('satis.phar');
+
+require 'phar://satis.phar/bin/satis';
+
+__HALT_COMPILER();
+EOF;
+ }
+}
53 src/Composer/Satis/Console/Application.php
@@ -0,0 +1,53 @@
+<?php
+
+/*
+ * This file is part of Satis.
+ *
+ * (c) Jordi Boggiano <j.boggiano@seld.be>
+ * Nils Adermann <naderman@naderman.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Satis\Console;
+
+use Symfony\Component\Console\Application as BaseApplication;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Output\ConsoleOutput;
+use Composer\Satis\Command;
+use Composer\Console\Application as ComposerApplication;
+use Composer\Json\JsonFile;
+use Composer\Satis\Satis;
+
+/**
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class Application extends BaseApplication
+{
+ protected $composer;
+
+ public function __construct()
+ {
+ parent::__construct('Satis', Satis::VERSION);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function doRun(InputInterface $input, OutputInterface $output)
+ {
+ $this->registerCommands();
+
+ return parent::doRun($input, $output);
+ }
+
+ /**
+ * Initializes all the composer commands
+ */
+ protected function registerCommands()
+ {
+ $this->add(new Command\BuildCommand());
+ }
+}
21 src/Composer/Satis/Satis.php
@@ -0,0 +1,21 @@
+<?php
+
+/*
+ * This file is part of Satis.
+ *
+ * (c) Jordi Boggiano <j.boggiano@seld.be>
+ * Nils Adermann <naderman@naderman.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Satis;
+
+/**
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class Satis
+{
+ const VERSION = '1.0.0-dev';
+}
14 tests/bootstrap.php
@@ -0,0 +1,14 @@
+<?php
+
+/*
+ * This file is part of Satis.
+ *
+ * (c) Jordi Boggiano <j.boggiano@seld.be>
+ * Nils Adermann <naderman@naderman.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+$loader = require __DIR__.'/../vendor/.composer/autoload.php';
+$loader->add('Composer\Test', __DIR__);
Please sign in to comment.
Something went wrong with that request. Please try again.