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 * Updates all projects in a multi project build. This is useful for users who have adopted the flat project structure 033 * where the aggregator project is a sibling of the sub projects rather than sitting in the parent directory. 034 * 035 * @goal update-subprojects 036 * @version $Id: UpdateSubprojectsMojo.java 685542 2008-08-13 13:28:43Z vsiveton $ 037 */ 038 public class UpdateSubprojectsMojo 039 extends AbstractScmMojo 040 { 041 /** 042 * The version type (branch/tag/revision) of scmVersion. 043 * 044 * @parameter expression="${scmVersionType}" 045 */ 046 private String scmVersionType; 047 048 /** 049 * The version (revision number/branch name/tag name). 050 * 051 * @parameter expression="${scmVersion}" 052 */ 053 private String scmVersion; 054 055 /** 056 * The project property where to store the revision name. 057 * 058 * @parameter expression="${revisionKey}" default-value="scm.revision" 059 */ 060 private String revisionKey; 061 062 /** 063 * The maven project. 064 * 065 * @parameter expression="${project}" 066 * @required 067 * @readonly 068 */ 069 private MavenProject project; 070 071 /** {@inheritDoc} */ 072 public void execute() 073 throws MojoExecutionException 074 { 075 super.execute(); 076 077 try 078 { 079 ScmRepository repository = getScmRepository(); 080 081 UpdateScmResult result = 082 getScmManager().update( repository, getFileSet(), getScmVersion( scmVersionType, scmVersion ) ); 083 084 checkResult( result ); 085 086 if ( result instanceof UpdateScmResultWithRevision ) 087 { 088 getLog().info( "Storing revision in '" + revisionKey + "' project property." ); 089 090 if ( project.getProperties() != null ) // Remove the test when we'll use plugin-test-harness 1.0-alpha-2 091 { 092 project.getProperties().put( revisionKey, ( (UpdateScmResultWithRevision) result ).getRevision() ); 093 } 094 } 095 } 096 catch ( IOException e ) 097 { 098 throw new MojoExecutionException( "Cannot run update command : ", e ); 099 } 100 catch ( ScmException e ) 101 { 102 throw new MojoExecutionException( "Cannot run update command : ", e ); 103 } 104 } 105 }