continuum-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Venisse" <emmanuel.veni...@gmail.com>
Subject Re: svn commit: r649749 - in /continuum/trunk/continuum-core/src: main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java test/java/org/apache/maven/continuum/execution/AbstractContinuumBuildExecutorTest.java
Date Thu, 24 Apr 2008 07:31:21 GMT
ping

On Mon, Apr 21, 2008 at 3:32 PM, Emmanuel Venisse <
emmanuel.venisse@gmail.com> wrote:

> Is it work on windows??? chroot/sudo aren't DOS commands.
>
> Emmanuel
>
>
> On Sat, Apr 19, 2008 at 5:17 AM, <carlos@apache.org> wrote:
>
> > Author: carlos
> > Date: Fri Apr 18 20:17:07 2008
> > New Revision: 649749
> >
> > URL: http://svn.apache.org/viewvc?rev=649749&view=rev
> > Log:
> > [CONTINUUM-1731] Add some commands to use a chroot jail in the build
> > executor, keeping previous functionality unmodified
> >
> > Added:
> >
> >  continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/AbstractContinuumBuildExecutorTest.java
> >   (with props)
> > Modified:
> >
> >  continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java
> >
> > Modified:
> > continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java
> > URL:
> > http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java?rev=649749&r1=649748&r2=649749&view=diff
> >
> > ==============================================================================
> > ---
> > continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java
> > (original)
> > +++
> > continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java
> > Fri Apr 18 20:17:07 2008
> > @@ -19,6 +19,7 @@
> >  * under the License.
> >  */
> >
> > +import org.apache.maven.continuum.configuration.ConfigurationService;
> >  import org.apache.maven.continuum.installation.InstallationService;
> >  import org.apache.maven.continuum.model.project.BuildDefinition;
> >  import org.apache.maven.continuum.model.project.Project;
> > @@ -51,6 +52,9 @@
> >     extends AbstractLogEnabled
> >     implements ContinuumBuildExecutor, Initializable
> >  {
> > +    private static final String SUDO_EXECUTABLE = "sudo";
> > +    private static final String CHROOT_EXECUTABLE = "chroot";
> > +
> >     //
> > ----------------------------------------------------------------------
> >     //
> >     //
> > ----------------------------------------------------------------------
> > @@ -78,6 +82,11 @@
> >     /**
> >      * @plexus.configuration
> >      */
> > +    private File chrootJailDirectory;
> > +
> > +    /**
> > +     * @plexus.configuration
> > +     */
> >     private String defaultExecutable;
> >
> >     //
> > ----------------------------------------------------------------------
> > @@ -232,6 +241,26 @@
> >
> >         try
> >         {
> > +            File chrootJailDirectory = getChrootJailDirectory();
> > +            if ( chrootJailDirectory != null )
> > +            {
> > +                StringBuilder sb = new StringBuilder();
> > +                sb.append( CHROOT_EXECUTABLE );
> > +                sb.append( " " );
> > +                sb.append( new File( chrootJailDirectory,
> > project.getGroupId() ) );
> > +                sb.append( " " );
> > +                sb.append( " cd " );
> > +                sb.append( getRelativePath( chrootJailDirectory,
> > workingDirectory, project.getGroupId() ) );
> > +                sb.append( " && " );
> > +                sb.append( actualExecutable );
> > +                sb.append( " " );
> > +                sb.append( arguments );
> > +
> > +                arguments = sb.toString();
> > +                actualExecutable = SUDO_EXECUTABLE;
> > +                workingDirectory = chrootJailDirectory; // not really
> > used but must exist
> > +            }
> > +
> >             ExecutionResult result =
> >                 getShellCommandHelper().executeShellCommand(
> > workingDirectory, actualExecutable, arguments, output,
> >
> >  project.getId(), environments );
> > @@ -260,6 +289,21 @@
> >         }
> >     }
> >
> > +    private String getRelativePath( File chrootDir, File
> > workingDirectory, String groupId )
> > +    {
> > +        String path = workingDirectory.getPath();
> > +        String chrootBase = new File( chrootDir, groupId ).getPath();
> > +        if ( path.startsWith( chrootBase ) )
> > +        {
> > +            return path.substring( chrootBase.length(), path.length()
> > );
> > +        }
> > +        else
> > +        {
> > +            throw new IllegalArgumentException( "Working directory is
> > not inside the chroot jail " + chrootBase +
> > +                " , " + path );
> > +        }
> > +    }
> > +
> >     protected abstract Map<String, String> getEnvironments(
> > BuildDefinition buildDefinition );
> >
> >     protected String getJavaHomeValue( BuildDefinition buildDefinition )
> > @@ -374,5 +418,15 @@
> >     public void setExecutableResolver( ExecutableResolver
> > executableResolver )
> >     {
> >         this.executableResolver = executableResolver;
> > +    }
> > +
> > +    public void setChrootJailDirectory( File chrootJailDirectory )
> > +    {
> > +        this.chrootJailDirectory = chrootJailDirectory;
> > +    }
> > +
> > +    public File getChrootJailDirectory()
> > +    {
> > +        return chrootJailDirectory;
> >     }
> >  }
> >
> > Added:
> > continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/AbstractContinuumBuildExecutorTest.java
> > URL:
> > http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/AbstractContinuumBuildExecutorTest.java?rev=649749&view=auto
> >
> > ==============================================================================
> > ---
> > continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/AbstractContinuumBuildExecutorTest.java
> > (added)
> > +++
> > continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/AbstractContinuumBuildExecutorTest.java
> > Fri Apr 18 20:17:07 2008
> > @@ -0,0 +1,141 @@
> > +package org.apache.maven.continuum.execution;
> > +
> > +import java.io.File;
> > +import java.util.HashMap;
> > +import java.util.Map;
> > +
> > +import junit.framework.TestCase;
> > +
> > +import org.apache.maven.continuum.configuration.ConfigurationService;
> > +import
> > org.apache.maven.continuum.configuration.DefaultConfigurationService;
> > +import org.apache.maven.continuum.model.project.BuildDefinition;
> > +import org.apache.maven.continuum.model.project.Project;
> > +import org.apache.maven.continuum.model.project.ProjectGroup;
> > +import
> > org.apache.maven.continuum.utils.ChrootJailWorkingDirectoryService;
> > +import org.apache.maven.continuum.utils.shell.ExecutionResult;
> > +import org.apache.maven.continuum.utils.shell.ShellCommandHelper;
> > +import org.codehaus.plexus.logging.Logger;
> > +import org.codehaus.plexus.logging.console.ConsoleLogger;
> > +import org.jmock.Expectations;
> > +import org.jmock.Mock;
> > +import org.jmock.Mockery;
> > +import org.jmock.core.Constraint;
> > +
> > +public class AbstractContinuumBuildExecutorTest
> > +    extends TestCase
> > +{
> > +    protected AbstractBuildExecutor executor = new BuildExecutorStub();
> > +
> > +    private Mockery context = new Mockery();
> > +
> > +    private String toSystemPath( String path )
> > +    {
> > +        if ( File.separator.equals( "\\" ) )
> > +        {
> > +            return path.replaceAll( "/", "\\" + File.separator );
> > +        }
> > +        return path;
> > +    }
> > +
> > +    public void testExecuteShellCommand()
> > +        throws Exception
> > +    {
> > +        final File chrootJailFile = new File( toSystemPath( "/home" )
> > );
> > +        final File workingDirectory = new File( toSystemPath(
> > "/dir1/dir2/workingdir" ) );
> > +
> > +        final ShellCommandHelper helper = context.mock(
> > ShellCommandHelper.class );
> > +
> > +        ConfigurationService configurationService = new
> > DefaultConfigurationService()
> > +        {
> > +            @Override
> > +            public File getWorkingDirectory()
> > +            {
> > +                return workingDirectory;
> > +            }
> > +        };
> > +
> > +        ChrootJailWorkingDirectoryService directoryService = new
> > ChrootJailWorkingDirectoryService();
> > +        directoryService.setConfigurationService( configurationService
> > );
> > +        directoryService.setChrootJailDirectory( chrootJailFile );
> > +
> > +        executor.setChrootJailDirectory( chrootJailFile );
> > +        executor.setShellCommandHelper( helper );
> > +        executor.setWorkingDirectoryService( directoryService );
> > +        executor.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG,
> > "" ) );
> > +
> > +        final Project project = new Project();
> > +        project.setId( 7 );
> > +        project.setGroupId( "xx" );
> > +        ProjectGroup projectGroup = new ProjectGroup();
> > +        projectGroup.setGroupId( project.getGroupId() );
> > +        project.setProjectGroup( projectGroup );
> > +
> > +        assertEquals( toSystemPath( chrootJailFile.getPath() + "/" +
> > project.getGroupId() + workingDirectory.getPath() +
> > +            "/" + project.getId() ),
> > directoryService.getWorkingDirectory( project ).getPath() );
> > +
> > +        String executable = "mvn";
> > +        final String arguments = "-o clean install";
> > +        final File output = new File( "target/tmp" );
> > +        final Map<String, String> environments = new HashMap<String,
> > String>();
> > +
> > +        final String cmd =
> > +            "chroot /home/xx " + " cd /dir1/dir2/workingdir/" +
> > project.getId() + " && " + executable + " " + arguments;
> > +        // Constraint[] args =
> > +        // new Constraint[] { eq( chrootJailFile ), eq( "sudo" ), eq(
> > toSystemPath( cmd ) ), eq( output ),
> > +        // eq( project.getId() ), eq( environments ) };
> > +        final ExecutionResult result = new ExecutionResult( 0 );
> > +
> > +        context.checking( new Expectations()
> > +        {
> > +            {
> > +                one( helper ).executeShellCommand( chrootJailFile,
> > "sudo", toSystemPath( cmd ), output,
> > +                                                   project.getId(),
> > environments );
> > +                will( returnValue( result ) );
> > +            }
> > +        } );
> > +
> > +        // helperMock.expects( once() ).method( "executeShellCommand"
> > ).with( args ).will( returnValue( result ) );
> > +
> > +        executor.executeShellCommand( project, executable, arguments,
> > output, environments );
> > +
> > +        context.assertIsSatisfied();
> > +        // super.verify();
> > +    }
> > +
> > +    class BuildExecutorStub
> > +        extends AbstractBuildExecutor
> > +    {
> > +
> > +        protected BuildExecutorStub()
> > +        {
> > +            super( "stub", true );
> > +        }
> > +
> > +        protected String findExecutable( Project project, String
> > executable, String defaultExecutable,
> > +                                         boolean resolveExecutable,
> > File workingDirectory )
> > +        {
> > +            return executable;
> > +        }
> > +
> > +        @Override
> > +        protected Map<String, String> getEnvironments( BuildDefinition
> > buildDefinition )
> > +        {
> > +            // TODO Auto-generated method stub
> > +            return null;
> > +        }
> > +
> > +        public ContinuumBuildExecutionResult build( Project project,
> > BuildDefinition buildDefinition, File buildOutput )
> > +            throws ContinuumBuildExecutorException
> > +        {
> > +            // TODO Auto-generated method stub
> > +            return null;
> > +        }
> > +
> > +        public void updateProjectFromCheckOut( File workingDirectory,
> > Project project, BuildDefinition buildDefinition )
> > +            throws ContinuumBuildExecutorException
> > +        {
> > +            // TODO Auto-generated method stub
> > +
> > +        }
> > +    }
> > +}
> >
> > Propchange:
> > continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/AbstractContinuumBuildExecutorTest.java
> >
> > ------------------------------------------------------------------------------
> >    svn:eol-style = native
> >
> > Propchange:
> > continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/AbstractContinuumBuildExecutorTest.java
> >
> > ------------------------------------------------------------------------------
> >    svn:keywords = "Author Date Id Revision"
> >
> >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message