Package org.apache.continuum.buildagent.buildcontext

Examples of org.apache.continuum.buildagent.buildcontext.BuildContext


{
    public List<BuildContext> buildContexts;

    public BuildContext getBuildContext( int projectId )
    {
        BuildContext context = null;

        if (buildContexts!= null)
        {
            for ( BuildContext item : buildContexts )
            {
View Full Code Here


        }
    }

    private String getBuildAgentUrl( int projectId )
    {
        BuildContext context = buildContextManager.getBuildContext( projectId );

        if ( context != null )
        {
            return context.getBuildAgentUrl();
        }

        return "";
    }
View Full Code Here

        buildProjectExecutor.setBuildContextManager( buildContextManager );

        buildProjectExecutor.setBuildAgentManager( buildAgentManager );

        final BuildContext buildContext = createBuildContext();

        final List<LocalRepository> localRepos = new ArrayList<LocalRepository>();

        LocalRepository localRepo = createLocalRepository( "temp", "/tmp/.m2/repository", "default" );
        localRepos.add( localRepo );
View Full Code Here

        buildProjectExecutor.setBuildContextManager( buildContextManager );

        buildProjectExecutor.setBuildAgentManager( buildAgentManager );

        final BuildContext buildContext = createBuildContext();

        final List<LocalRepository> localRepos = new ArrayList<LocalRepository>();

        LocalRepository localRepo = createLocalRepository( "temp", "/tmp/.m2/repository", "default" );
        localRepos.add( localRepo );

        localRepo = createLocalRepository( "default", "/home/user/.m2/repository", "default" );
        localRepos.add( localRepo );

        final Map<String, String> masterBuildEnvironments = new HashMap<String, String>();
        masterBuildEnvironments.put( "M2_HOME", "/tmp/apache-maven-2.2.1" );

        final List<Installation> slaveBuildEnvironments = new ArrayList<Installation>();

        Installation slaveBuildEnvironment = createInstallation( "M2_HOME", "/home/user/apache-maven-2.2.1" );
        slaveBuildEnvironments.add( slaveBuildEnvironment );

        slaveBuildEnvironment = createInstallation( "EXTRA_VAR", "/home/user/extra" );
        slaveBuildEnvironments.add( slaveBuildEnvironment );

        final ContinuumAgentBuildExecutor executor = context.mock( ContinuumAgentBuildExecutor.class );
        final File workingDir = new File( "/tmp/data/working-directory/project-test" );
        final MavenProject project = new MavenProject();
        final File outputFile = new File( "/tmp/data/build-output-directory/output.txt" );

        context.checking( new Expectations()
        {
            {
                one( buildContextManager ).getBuildContext( 1 );
                will( returnValue( buildContext ) );

                one( buildAgentManager ).getEnvironments( 1, "maven2" );
                will( returnValue( masterBuildEnvironments ) );

                one( buildAgentConfigurationService ).getAvailableInstallations();
                will( returnValue( slaveBuildEnvironments ) );

                one( buildAgentConfigurationService ).getLocalRepositories();
                will( returnValue( localRepos ) );

                one( buildAgentManager ).shouldBuild( with( any( Map.class ) ) );
                will( returnValue( true ) );

                one( buildAgentBuildExecutorManager ).getBuildExecutor(
                    ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
                will( returnValue( executor ) );

                one( buildAgentConfigurationService ).getWorkingDirectory( 1 );
                will( returnValue( workingDir ) );

                one( executor ).getMavenProject( with( any( File.class ) ), with( any( BuildDefinition.class ) ) );
                will( returnValue( project ) );

                one( buildAgentManager ).startProjectBuild( 1 );

                one( buildAgentConfigurationService ).getBuildOutputFile( 1 );
                will( returnValue( outputFile ) );

                one( buildAgentManager ).returnBuildResult( with( any( Map.class ) ) );

                one( buildContextManager ).removeBuildContext( 1 );
            }
        } );

        try
        {
            buildProjectExecutor.executeTask( createBuildProjectTask() );

            Map<String, String> environments = (Map<String, String>) buildContext.getActionContext().get(
                ContinuumBuildAgentUtil.KEY_ENVIRONMENTS );
            assertEquals( 2, environments.size() );
            assertTrue( environments.containsKey( "M2_HOME" ) );
            assertTrue( environments.containsKey( "EXTRA_VAR" ) );
            // shows that build agent's environment variables overwrites Continuum Master's environment variables
View Full Code Here

        buildProjectExecutor.setBuildContextManager( buildContextManager );

        buildProjectExecutor.setBuildAgentManager( buildAgentManager );

        final BuildContext buildContext = createBuildContext();

        final List<LocalRepository> localRepos = new ArrayList<LocalRepository>();

        LocalRepository localRepo = createLocalRepository( "temp", "/tmp/.m2/repository", "default" );
        localRepos.add( localRepo );

        localRepo = createLocalRepository( "default", "/home/user/.m2/repository", "default" );
        localRepos.add( localRepo );

        final Map<String, String> masterBuildEnvironments = new HashMap<String, String>();
        masterBuildEnvironments.put( "M2_HOME", "/tmp/apache-maven-2.2.1" );

        final List<Installation> slaveBuildEnvironments = new ArrayList<Installation>();

        final ContinuumAgentBuildExecutor executor = context.mock( ContinuumAgentBuildExecutor.class );
        final File workingDir = new File( "/tmp/data/working-directory/project-test" );
        final MavenProject project = new MavenProject();
        final File outputFile = new File( "/tmp/data/build-output-directory/output.txt" );

        context.checking( new Expectations()
        {
            {
                one( buildContextManager ).getBuildContext( 1 );
                will( returnValue( buildContext ) );

                one( buildAgentManager ).getEnvironments( 1, "maven2" );
                will( returnValue( masterBuildEnvironments ) );

                one( buildAgentConfigurationService ).getAvailableInstallations();
                will( returnValue( slaveBuildEnvironments ) );

                one( buildAgentConfigurationService ).getLocalRepositories();
                will( returnValue( localRepos ) );

                one( buildAgentManager ).shouldBuild( with( any( Map.class ) ) );
                will( returnValue( true ) );

                one( buildAgentBuildExecutorManager ).getBuildExecutor(
                    ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
                will( returnValue( executor ) );

                one( buildAgentConfigurationService ).getWorkingDirectory( 1 );
                will( returnValue( workingDir ) );

                one( executor ).getMavenProject( with( any( File.class ) ), with( any( BuildDefinition.class ) ) );
                will( returnValue( project ) );

                one( buildAgentManager ).startProjectBuild( 1 );

                one( buildAgentConfigurationService ).getBuildOutputFile( 1 );
                will( returnValue( outputFile ) );

                one( buildAgentManager ).returnBuildResult( with( any( Map.class ) ) );

                one( buildContextManager ).removeBuildContext( 1 );
            }
        } );

        try
        {
            buildProjectExecutor.executeTask( createBuildProjectTask() );

            Map<String, String> environments = (Map<String, String>) buildContext.getActionContext().get(
                ContinuumBuildAgentUtil.KEY_ENVIRONMENTS );
            assertEquals( 1, environments.size() );
            assertTrue( environments.containsKey( "M2_HOME" ) );
            assertEquals( "/tmp/apache-maven-2.2.1", environments.get( "M2_HOME" ) );
        }
View Full Code Here

        return task;
    }

    private BuildContext createBuildContext()
    {
        BuildContext context = new BuildContext();
        context.setProjectId( 1 );
        context.setProjectVersion( "1.0-SNAPSHOT" );
        context.setBuildDefinitionId( 1 );
        context.setBuildFile( "pom.xml" );
        context.setExecutorId( ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
        context.setGoals( "clean intall" );
        context.setArguments( "--batch --non-recursive" );
        context.setScmUrl( "scm:svn:http://svn.example.com/repos/dummy/trunk" );
        context.setScmUsername( "" );
        context.setScmPassword( "" );
        context.setBuildFresh( false );
        context.setProjectGroupId( 1 );
        context.setProjectGroupName( "Test Project Group" );
        context.setScmRootAddress( "scm:svn:http://svn.example.com/repos/dummy" );
        context.setScmRootId( 1 );
        context.setProjectName( "Test Project" );
        context.setProjectState( 1 );
        context.setTrigger( 1 );
        context.setUsername( "" );
        context.setLocalRepository( "default" );
        context.setBuildNumber( 1 );

        ScmResult scmResult = new ScmResult();
        scmResult.setSuccess( true );

        context.setScmResult( scmResult );
        context.setLatestUpdateDate( Calendar.getInstance().getTime() );
        context.setBuildAgentUrl( "http://localhost:8181/continuum-buildagent/xmlrpc" );
        context.setMaxExecutionTime( 7200 );
        context.setBuildDefinitionLabel( "Default Build Definition" );
        context.setScmTag( "scm:svn:http://svn.example.com/repos/dummy/tags" );

        return context;
    }
View Full Code Here

        }

        log.debug( "Check if project {} is the one currently building in the agent", projectId );
        if ( projectId == currentBuildId )
        {
            BuildContext buildContext = buildContextManager.getBuildContext( projectId );

            result.put( ContinuumBuildAgentUtil.KEY_PROJECT_ID, buildContext.getProjectId() );
            result.put( ContinuumBuildAgentUtil.KEY_BUILD_DEFINITION_ID, buildContext.getBuildDefinitionId() );
            result.put( ContinuumBuildAgentUtil.KEY_TRIGGER, buildContext.getTrigger() );
            result.put( ContinuumBuildAgentUtil.KEY_USERNAME, buildContext.getUsername() );

            BuildResult buildResult = buildContext.getBuildResult();

            if ( buildResult != null )
            {
                if ( buildResult.getStartTime() <= 0 )
                {
                    result.put( ContinuumBuildAgentUtil.KEY_START_TIME, Long.toString(
                        buildContext.getBuildStartTime() ) );
                }
                else
                {
                    result.put( ContinuumBuildAgentUtil.KEY_START_TIME, Long.toString( buildResult.getStartTime() ) );
                }

                if ( buildResult.getError() == null )
                {
                    result.put( ContinuumBuildAgentUtil.KEY_BUILD_ERROR, "" );
                }
                else
                {
                    result.put( ContinuumBuildAgentUtil.KEY_BUILD_ERROR, buildResult.getError() );
                }

                result.put( ContinuumBuildAgentUtil.KEY_BUILD_STATE, buildResult.getState() );
                result.put( ContinuumBuildAgentUtil.KEY_END_TIME, Long.toString( buildResult.getEndTime() ) );
                result.put( ContinuumBuildAgentUtil.KEY_BUILD_EXIT_CODE, buildResult.getExitCode() );
            }
            else
            {
                result.put( ContinuumBuildAgentUtil.KEY_START_TIME, Long.toString( buildContext.getBuildStartTime() ) );
                result.put( ContinuumBuildAgentUtil.KEY_END_TIME, Long.toString( 0 ) );
                result.put( ContinuumBuildAgentUtil.KEY_BUILD_STATE, ContinuumProjectState.BUILDING );
                result.put( ContinuumBuildAgentUtil.KEY_BUILD_ERROR, "" );
                result.put( ContinuumBuildAgentUtil.KEY_BUILD_EXIT_CODE, 0 );
            }
View Full Code Here

    {
        List<BuildContext> buildContext = new ArrayList<BuildContext>();

        for ( Map<String, Object> map : projectsBuildContext )
        {
            BuildContext context = new BuildContext();
            context.setProjectId( ContinuumBuildAgentUtil.getProjectId( map ) );
            context.setProjectVersion( ContinuumBuildAgentUtil.getProjectVersion( map ) );
            context.setBuildDefinitionId( ContinuumBuildAgentUtil.getBuildDefinitionId( map ) );
            context.setBuildFile( ContinuumBuildAgentUtil.getBuildFile( map ) );
            context.setExecutorId( ContinuumBuildAgentUtil.getExecutorId( map ) );
            context.setGoals( ContinuumBuildAgentUtil.getGoals( map ) );
            context.setArguments( ContinuumBuildAgentUtil.getArguments( map ) );
            context.setScmUrl( ContinuumBuildAgentUtil.getScmUrl( map ) );
            context.setScmUsername( ContinuumBuildAgentUtil.getScmUsername( map ) );
            context.setScmPassword( ContinuumBuildAgentUtil.getScmPassword( map ) );
            context.setBuildFresh( ContinuumBuildAgentUtil.isBuildFresh( map ) );
            context.setProjectGroupId( ContinuumBuildAgentUtil.getProjectGroupId( map ) );
            context.setProjectGroupName( ContinuumBuildAgentUtil.getProjectGroupName( map ) );
            context.setScmRootAddress( ContinuumBuildAgentUtil.getScmRootAddress( map ) );
            context.setScmRootId( ContinuumBuildAgentUtil.getScmRootId( map ) );
            context.setProjectName( ContinuumBuildAgentUtil.getProjectName( map ) );
            context.setProjectState( ContinuumBuildAgentUtil.getProjectState( map ) );
            context.setTrigger( ContinuumBuildAgentUtil.getTrigger( map ) );
            context.setUsername( ContinuumBuildAgentUtil.getUsername( map ) );
            context.setLocalRepository( ContinuumBuildAgentUtil.getLocalRepository( map ) );
            context.setBuildNumber( ContinuumBuildAgentUtil.getBuildNumber( map ) );
            context.setOldScmResult( getScmResult( ContinuumBuildAgentUtil.getOldScmChanges( map ) ) );
            context.setLatestUpdateDate( ContinuumBuildAgentUtil.getLatestUpdateDate( map ) );
            context.setBuildAgentUrl( ContinuumBuildAgentUtil.getBuildAgentUrl( map ) );
            context.setMaxExecutionTime( ContinuumBuildAgentUtil.getMaxExecutionTime( map ) );
            context.setBuildDefinitionLabel( ContinuumBuildAgentUtil.getBuildDefinitionLabel( map ) );
            context.setScmTag( ContinuumBuildAgentUtil.getScmTag( map ) );

            buildContext.add( context );
        }

        buildContextManager.addBuildContexts( buildContext );
View Full Code Here

    private PrepareBuildProjectsTask createPrepareBuildProjectsTask( List<BuildContext> buildContexts )
        throws ContinuumBuildAgentException
    {
        if ( buildContexts != null && buildContexts.size() > 0 )
        {
            BuildContext context = buildContexts.get( 0 );
            return new PrepareBuildProjectsTask( buildContexts, new BuildTrigger( context.getTrigger(),
                                                                                  context.getUsername() ),
                                                 context.getProjectGroupId(), context.getScmRootAddress(),
                                                 context.getScmRootId() );
        }
        else
        {
            log.info( "Nothing to build" );
            return null;
View Full Code Here

        throws TaskExecutionException
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put( ContinuumBuildAgentUtil.KEY_BUILD_CONTEXTS, buildContexts );

        BuildContext context = new BuildContext();
        context.setActionContext( map );

        performAction( "create-agent-build-project-task", context );
    }
View Full Code Here

TOP

Related Classes of org.apache.continuum.buildagent.buildcontext.BuildContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.