001 package org.apache.maven.scm.plugin; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import org.apache.maven.plugin.MojoExecutionException; 023 import org.apache.maven.project.MavenProject; 024 import org.apache.maven.scm.ScmException; 025 import org.apache.maven.scm.command.update.UpdateScmResult; 026 import org.apache.maven.scm.command.update.UpdateScmResultWithRevision; 027 import org.apache.maven.scm.repository.ScmRepository; 028 029 import java.io.IOException; 030 031 /** 032 * Update the local working copy with the latest source from the configured scm url. 033 * 034 * @author <a href="evenisse@apache.org">Emmanuel Venisse</a> 035 * @version $Id: UpdateMojo.java 685670 2008-08-13 20:25:56Z vsiveton $ 036 * @goal update 037 * @aggregator 038 */ 039 public class UpdateMojo 040 extends AbstractScmMojo 041 { 042 /** 043 * The version type (branch/tag/revision) of scmVersion. 044 * 045 * @parameter expression="${scmVersionType}" 046 */ 047 private String scmVersionType; 048 049 /** 050 * The version (revision number/branch name/tag name). 051 * 052 * @parameter expression="${scmVersion}" 053 */ 054 private String scmVersion; 055 056 /** 057 * The project property where to store the revision name. 058 * 059 * @parameter expression="${revisionKey}" default-value="scm.revision" 060 */ 061 private String revisionKey; 062 063 /** 064 * The maven project. 065 * 066 * @parameter expression="${project}" 067 * @required 068 * @readonly 069 */ 070 private MavenProject project; 071 072 /** 073 * Run Changelog after update. 074 * 075 * @parameter expression="${runChangelog}" default-value="false" 076 */ 077 private boolean runChangelog = false; 078 079 /** {@inheritDoc} */ 080 public void execute() 081 throws MojoExecutionException 082 { 083 super.execute(); 084 085 try 086 { 087 ScmRepository repository = getScmRepository(); 088 089 UpdateScmResult result = getScmManager().update( repository, getFileSet(), 090 getScmVersion( scmVersionType, scmVersion ), 091 runChangelog ); 092 093 checkResult( result ); 094 095 if ( result instanceof UpdateScmResultWithRevision ) 096 { 097 String revision = ( (UpdateScmResultWithRevision) result ).getRevision(); 098 099 getLog().info( "Storing revision in '" + revisionKey + "' project property." ); 100 101 if ( project.getProperties() != null ) // Remove the test when we'll use plugin-test-harness 1.0-alpha-2 102 { 103 project.getProperties().put( revisionKey, revision ); 104 } 105 106 getLog().info( "Project at revision " + revision ); 107 } 108 } 109 catch ( IOException e ) 110 { 111 throw new MojoExecutionException( "Cannot run update command : ", e ); 112 } 113 catch ( ScmException e ) 114 { 115 throw new MojoExecutionException( "Cannot run update command : ", e ); 116 } 117 } 118 }