1 | |
package org.apache.maven.plugin.changes; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.text.ParseException; |
24 | |
import java.text.SimpleDateFormat; |
25 | |
import java.util.List; |
26 | |
|
27 | |
import org.apache.commons.lang.StringUtils; |
28 | |
import org.apache.maven.plugin.AbstractMojo; |
29 | |
import org.apache.maven.plugin.MojoExecutionException; |
30 | |
import org.apache.maven.plugins.annotations.Mojo; |
31 | |
import org.apache.maven.plugins.annotations.Parameter; |
32 | |
import org.apache.maven.plugins.changes.model.Release; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
@Mojo( name = "changes-check", threadSafe = true ) |
43 | 0 | public class ChangesCheckMojo |
44 | |
extends AbstractMojo |
45 | |
{ |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
@Parameter( property = "changes.releaseDateFormat", defaultValue = "yyyy-MM-dd" ) |
51 | |
private String releaseDateFormat; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
@Parameter( property = "changes.version", defaultValue = "${project.version}", required = true ) |
57 | |
private String version; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
@Parameter( property = "changes.xmlPath", defaultValue = "src/changes/changes.xml" ) |
63 | |
private File xmlPath; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
@Parameter( property = "changes.skipSnapshots", defaultValue = "false" ) |
71 | |
private boolean skipSnapshots; |
72 | |
|
73 | 0 | private ReleaseUtils releaseUtils = new ReleaseUtils( getLog() ); |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public void execute() |
81 | |
throws MojoExecutionException |
82 | |
{ |
83 | 0 | if ( this.version.endsWith( "-SNAPSHOT" ) && this.skipSnapshots ) |
84 | |
{ |
85 | 0 | getLog().info( "Skipping snapshot version '" + this.version + "'." ); |
86 | |
} |
87 | 0 | else if ( xmlPath.exists() ) |
88 | |
{ |
89 | 0 | ChangesXML xml = new ChangesXML( xmlPath, getLog() ); |
90 | 0 | ReleaseUtils releaseUtils = new ReleaseUtils( getLog() ); |
91 | 0 | Release release = |
92 | |
releaseUtils.getLatestRelease( releaseUtils.convertReleaseList( xml.getReleaseList() ), version ); |
93 | |
|
94 | 0 | if ( !isValidDate( release.getDateRelease(), releaseDateFormat ) ) |
95 | |
{ |
96 | 0 | throw new MojoExecutionException( |
97 | |
"The file " + xmlPath.getAbsolutePath() + " has an invalid release date." ); |
98 | |
|
99 | |
} |
100 | 0 | } |
101 | |
else |
102 | |
{ |
103 | 0 | getLog().warn( "The file " + xmlPath.getAbsolutePath() + " does not exist." ); |
104 | |
} |
105 | 0 | } |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
protected static boolean isValidDate( String string, String pattern ) |
115 | |
{ |
116 | 13 | if ( StringUtils.isEmpty( string ) ) |
117 | |
{ |
118 | 6 | return false; |
119 | |
} |
120 | |
|
121 | 7 | if ( StringUtils.isEmpty( pattern ) ) |
122 | |
{ |
123 | 4 | return false; |
124 | |
} |
125 | |
|
126 | |
try |
127 | |
{ |
128 | 3 | SimpleDateFormat df = new SimpleDateFormat( pattern ); |
129 | 3 | df.parse( string ); |
130 | 1 | return true; |
131 | |
} |
132 | 2 | catch ( ParseException e ) |
133 | |
{ |
134 | 2 | return false; |
135 | |
} |
136 | |
} |
137 | |
} |