| package org.apache.maven.scm.provider.svn.command.checkin; |
| |
| /* |
| * Copyright 2001-2005 The Apache Software Foundation. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| import org.apache.maven.scm.ScmException; |
| import org.apache.maven.scm.ScmFileSet; |
| import org.apache.maven.scm.command.checkin.AbstractCheckInCommand; |
| import org.apache.maven.scm.command.checkin.CheckInScmResult; |
| import org.apache.maven.scm.provider.ScmProviderRepository; |
| import org.apache.maven.scm.provider.svn.command.SvnCommandLineUtils; |
| import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository; |
| import org.codehaus.plexus.util.FileUtils; |
| import org.codehaus.plexus.util.StringUtils; |
| import org.codehaus.plexus.util.cli.CommandLineException; |
| import org.codehaus.plexus.util.cli.CommandLineUtils; |
| import org.codehaus.plexus.util.cli.Commandline; |
| |
| import java.io.File; |
| import java.io.IOException; |
| |
| /** |
| * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> |
| * @version $Id$ |
| */ |
| public class SvnCheckInCommand |
| extends AbstractCheckInCommand |
| { |
| protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message, |
| String tag ) |
| throws ScmException |
| { |
| if ( !StringUtils.isEmpty( tag ) ) |
| { |
| throw new ScmException( "This provider can't handle tags." ); |
| } |
| |
| File messageFile = FileUtils.createTempFile( "maven-scm-", ".commit", null ); |
| |
| try |
| { |
| FileUtils.fileWrite( messageFile.getAbsolutePath(), message ); |
| } |
| catch ( IOException ex ) |
| { |
| return new CheckInScmResult( null, |
| "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false ); |
| } |
| |
| Commandline cl = createCommandLine( (SvnScmProviderRepository) repo, fileSet, messageFile ); |
| |
| SvnCheckInConsumer consumer = new SvnCheckInConsumer( getLogger(), fileSet.getBasedir() ); |
| |
| CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
| |
| getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() ); |
| getLogger().info( "Command line: " + cl ); |
| |
| int exitCode; |
| |
| try |
| { |
| exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); |
| } |
| catch ( CommandLineException ex ) |
| { |
| throw new ScmException( "Error while executing command.", ex ); |
| } |
| finally |
| { |
| try |
| { |
| FileUtils.forceDelete( messageFile ); |
| } |
| catch ( IOException ex ) |
| { |
| // ignore |
| } |
| } |
| |
| if ( exitCode != 0 ) |
| { |
| return new CheckInScmResult( cl.toString(), "The svn command failed.", stderr.getOutput(), false ); |
| } |
| |
| return new CheckInScmResult( cl.toString(), consumer.getCheckedInFiles() ); |
| } |
| |
| // ---------------------------------------------------------------------- |
| // |
| // ---------------------------------------------------------------------- |
| |
| public static Commandline createCommandLine( SvnScmProviderRepository repository, ScmFileSet fileSet, |
| File messageFile ) |
| { |
| Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine( fileSet.getBasedir(), repository ); |
| |
| cl.createArgument().setValue( "commit" ); |
| |
| cl.createArgument().setValue( "--file" ); |
| |
| cl.createArgument().setValue( messageFile.getAbsolutePath() ); |
| |
| SvnCommandLineUtils.addFiles( cl, fileSet.getFiles() ); |
| |
| return cl; |
| } |
| } |