Developed with love by KnpLabs Hire us for your project!
28

MassiveBuildBundle

by massiveart

Massive Build Bundle

The Massive Build Bundle provides a massive:build command which runs build
targets.

Targets are classes which execute arbitary code, and are registred in the
dependency injection container via. tags. Targets can depend on other targets.

Virtual targets can be created in you applications configuration file. These
virtual targets simply declare depenencies, enabling you to configure custom
build processes.

The aim of this bundle is to provide an extensible, decoupled, way of building
software project environments, especially in a development context.

If you often find youself executing several Symfony commands consecutively to
establish your environment, then this bundle is for you.

This tool is not mean to replace Make or Ant or Phing. The bundle should only
be used to execute build steps which are contained in the client application.

Defining targets

You can define new build targets in you applications configuration file:

massive_build:
    targets:
        main:
            target_one: ~
            target_two: ~
            target_three: ~
        quick:
            target_one: ~

The above will allow you to execute:

$ php app/console massive:build main

and:

$ php app/console massive:build quick

Creating build classes

You create builder classes in your application / bundles. Each build class
should have a specific responsiblity.

A minimal example:

<?php

namespace My\Web\Application;

use Massive\Bundle\BuildBundle\Build\BuilderInterface;

class MyBuilder implements BuilderInterface
{
    protected $context;

    public function getName()
    {
        return 'mybuildername';
    }

    public function getDependencies()
    {
        return array();
    }

    public function build()
    {
        $application = $this->context->getApplication();
        $input = $this->context->getInput();
        $output = $this->context->getOutput();

        $output->writeln('Hello World!');
    }

    public function setContext(BuilderContext $context)
    {
        $this->context = $context;
    }
}
  • getName: Return a name for the builder.
  • getDependencies: Return the names of any builders that this builder depends on.
  • build: Execute all logic in this method
  • setContext: Called automatically by the master build command, contains the Input, Output and Application.

Registring the builder class

You can register the builder class in the dependency injection container and#
then tag it with

<service id="sulu.core.build.builder.database" class="My\Web\Application\Builder\FooBuilder">
    <tag name="massive_build.builder" />
</service>

Accessing the container

You can access the service container by implementing the
ContainerAwareInterface:

<?php
// ...

class MyBuilder implements ContainerAwareInterface, BuilderInterface
{
    // ...
}

Adding global options and customization

You can make options available to your commands (e.g. to specify that they
should destroy the database, or that the name of user "x" should be set to
"y").

By taking this approach you are free to customize the build command in
anyway that you like.

To so this you need to extend the massive BuildCommand and configuring the
MassiveBuild bundle to use your extended class.

<?php

namespace Sulu\Bundle\CoreBundle\Command;

use Massive\Bundle\BuildBundle\Command\BuildCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

class SuluBuildCommand extends BuildCommand
{
    public function configure()
    {
        parent::configure();

        // change the name of the command from "massive:build"
        $this->setName('myapp:build');

        // add an option
        $this->addOption('destroy', null, InputOption::VALUE_NONE, 'Destroy existing data');
    }
}

Launching the build

You can launch all the builders with the following command:

$ php app/console massive:build

Launch a specific target:

$ php app/console massive:build mytarget

If you want to see which targets are available, use the --nobuild option:

$ php app/console massive:build --nobuild
Build Targets
=============

+---+----------+--------------------+
| # | Builder  | Deps               |
+---+----------+--------------------+
| 0 | database |                    |
| 1 | phpcr    | database           |
| 2 | fixtures | database           |
| 3 | user     | database, fixtures |
+---+----------+--------------------+

By default if you specify a specific target, the build system will build any dependencies
it has, to disable this use the --nodeps option.

$ php app/console massive:build --nodeps

Requirements

  • Symfony: 2.4+
The MIT License (MIT)

Copyright (c) 2018 MASSIVE ART WebServices GmbH

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.
massive_art_build:
command_class: Massive\Bundle\BuildBundle\Command\BuildCommand
targets:

# Prototype
name:
dependencies:

# Prototype
key: []
  • bumped version
    By wachterjohannes, 1 year ago
  • Merge pull request #16 from massiveart/enhacnement/symfony4
    By web-flow, 1 year ago
  • updated symfony dependency to symfony 4
    By wachterjohannes, 1 year ago
  • Updated copyright year and holder in LICENSE file (information may be wrong) (#15)
    By wachterjohannes, 1 year ago
  • bumped version
    By wachterjohannes, 1 year ago
  • do not indent message when decoration is disabled (#14)
    By wachterjohannes, 1 year ago
  • bumped version
    By danrot, 2 years ago
  • Merge pull request #13 from wachterjohannes/upgrade/symfony-3
    By web-flow, 2 years ago
  • updated to symfony3
    By wachterjohannes, 2 years ago
  • replaced deprecated console helpers (#12)
    By wachterjohannes, 2 years ago
  • Added fix for '.'
    By dantleech, 4 years ago
  • Merge pull request #11 from OskarStark/patch-1
    By dantleech, 4 years ago
  • removed duplicate app/console
    By OskarStark, 4 years ago
  • Merge pull request #7 from massiveart/mandatory_build_target
    By dantleech, 5 years ago
  • Build target is now mandatory
    By dantleech, 5 years ago
  • Merge pull request #6 from massiveart/build_config
    By dantleech, 5 years ago
  • Allow configuration of virtual build targets
    By dantleech, 5 years ago
  • Merge pull request #5 from massiveart/ghi-4
    By dantleech, 5 years ago
  • [bug] dependency not found when specifying target
    By dantleech, 5 years ago
  • Set version
    By dantleech, 5 years ago
  • Added LICENSE
    By dantleech, 5 years ago
  • Updated README
    By dantleech, 5 years ago
  • Updated README
    By dantleech, 5 years ago
  • Updated README
    By dantleech, 5 years ago
  • Updated
    By dantleech, 5 years ago
  • Updated composer
    By dantleech, 5 years ago
  • Refactored namespace
    By dantleech, 5 years ago
  • Added travis
    By dantleech, 5 years ago
  • Added compiler pass to register builders
    By dantleech, 5 years ago
  • Build command "works"
    By dantleech, 5 years ago