1 package org.apache.maven.plugins.patchtracker;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.http.impl.client.DefaultHttpClient;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.MojoFailureException;
25 import org.apache.maven.plugins.patchtracker.patching.PatchRepository;
26 import org.apache.maven.plugins.patchtracker.patching.PatchRepositoryException;
27 import org.apache.maven.plugins.patchtracker.patching.PatchRepositoryRequest;
28 import org.apache.maven.plugins.patchtracker.patching.PatchRepositoryResult;
29 import org.apache.maven.plugins.patchtracker.tracking.PatchTracker;
30 import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerException;
31 import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerRequest;
32 import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerResult;
33 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
34
35
36
37
38
39
40
41 public class PatchToIssueMojo
42 extends AbstractPatchMojo
43 {
44
45
46
47
48
49
50 protected String organisation;
51
52
53
54
55
56
57 protected String repository;
58
59
60
61
62
63
64 protected String id;
65
66
67
68
69
70
71
72 protected String patchSystemUrl;
73
74
75 DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
76
77 public void execute()
78 throws MojoExecutionException, MojoFailureException
79 {
80
81 try
82 {
83 PatchRepositoryRequest patchRepositoryRequest =
84 new PatchRepositoryRequest().setUrl( patchSystemUrl ).setRepository( repository ).setId(
85 id ).setOrganization( organisation );
86
87 PatchRepository patchRepository = getPatchRepository();
88
89 PatchRepositoryResult result = patchRepository.getPatch( patchRepositoryRequest, getLog() );
90
91 PatchTrackerRequest patchTrackerRequest = buidPatchTrackerRequest( false );
92
93 patchTrackerRequest.setSummary( result.getTitle() );
94
95 patchTrackerRequest.setDescription( result.getDescription() + ". url: " + result.getPatchUrl() );
96
97 patchTrackerRequest.setPatchContent( result.getPatchContent() );
98
99 getLog().debug( "patchTrackerRequest:" + patchTrackerRequest.toString() );
100
101 PatchTracker patchTracker = getPatchTracker();
102
103 PatchTrackerResult patchTrackerResult = patchTracker.createPatch( patchTrackerRequest, getLog() );
104 getLog().info( "issue created with id:" + patchTrackerResult.getPatchId() + ", url:"
105 + patchTrackerResult.getPatchUrl() );
106
107 }
108 catch ( ComponentLookupException e )
109 {
110 throw new MojoExecutionException( e.getMessage(), e );
111 }
112 catch ( PatchRepositoryException e )
113 {
114 throw new MojoExecutionException( e.getMessage(), e );
115 }
116 catch ( PatchTrackerException e )
117 {
118 throw new MojoExecutionException( e.getMessage(), e );
119 }
120 }
121
122 }