View Javadoc

1   package org.apache.maven.plugins.patchtracker;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugins.patchtracker.tracking.PatchTracker;
25  import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerException;
26  import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerRequest;
27  import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerResult;
28  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
29  import org.codehaus.plexus.components.interactivity.PrompterException;
30  
31  /**
32   * Goal which create a diff/patch file from the current project and create an issue in the project
33   * with attaching the created patch file
34   *
35   * @goal update
36   * @aggregator
37   */
38  public class UpdatePatchMojo
39      extends AbstractPatchMojo
40  {
41  
42      /**
43       * @parameter expression="${patch.patchId}" default-value=""
44       */
45      protected String patchId;
46  
47  
48      public void execute()
49          throws MojoExecutionException
50      {
51  
52          try
53          {
54              // TODO do a status before and complains if some files in to be added status ?
55  
56              String patchContent = getPatchContent();
57  
58              PatchTrackerRequest patchTrackerRequest = buidPatchTrackerRequest( false );
59  
60              patchTrackerRequest.setPatchId( getPatchId() ).setPatchContent( patchContent ).setDescription(
61                  getPatchTrackerDescription() );
62  
63              getLog().debug( patchTrackerRequest.toString() );
64              PatchTracker patchTracker = getPatchTracker();
65              PatchTrackerResult result = patchTracker.updatePatch( patchTrackerRequest, getLog() );
66              getLog().info( "issue updated with id:" + result.getPatchId() + ", url:" + result.getPatchUrl() );
67          }
68          catch ( ComponentLookupException e )
69          {
70              throw new MojoExecutionException( e.getMessage(), e );
71          }
72          catch ( PatchTrackerException e )
73          {
74              throw new MojoExecutionException( e.getMessage(), e );
75          }
76          catch ( PrompterException e )
77          {
78              throw new MojoExecutionException( e.getMessage(), e );
79          }
80  
81  
82      }
83  
84      protected String getPatchId()
85          throws PrompterException, MojoExecutionException
86      {
87          String value = null;
88  
89          // cli must win !
90          if ( StringUtils.isNotEmpty( patchId ) )
91          {
92              value = patchId;
93          }
94  
95          return getValue( value, "patch id to update ?", null, true,
96                           "you must configure a patch id when updating an issue or at least use interactive mode", value,
97                           false );
98      }
99  
100 
101 }