1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package com.qulice.maven;
32
33 import com.jcabi.log.Logger;
34 import com.qulice.spi.ValidationException;
35 import org.apache.maven.model.Dependency;
36 import org.apache.maven.model.Extension;
37 import org.apache.maven.model.Plugin;
38
39
40
41
42
43
44
45 public final class SnapshotsValidator implements MavenValidator {
46
47 @Override
48 public void validate(final MavenEnvironment env)
49 throws ValidationException {
50 if (!env.exclude("snapshots", "")) {
51 final String version = env.project().getVersion();
52 if (!SnapshotsValidator.isSnapshot(version)) {
53 this.check(env);
54 }
55 }
56 }
57
58
59
60
61
62
63 private void check(final MavenEnvironment env) throws ValidationException {
64 int errors = 0;
65 for (final Extension ext : env.project().getBuildExtensions()) {
66 if (SnapshotsValidator.isSnapshot(ext.getVersion())) {
67 Logger.warn(
68 this,
69 "%s build extension is SNAPSHOT",
70 ext
71 );
72 ++errors;
73 }
74 }
75 for (final Plugin plugin : env.project().getBuildPlugins()) {
76 if (SnapshotsValidator.isSnapshot(plugin.getVersion())) {
77 Logger.warn(
78 this,
79 "%s build plugin is SNAPSHOT",
80 plugin
81 );
82 ++errors;
83 }
84 }
85 for (final Dependency dep : env.project().getDependencies()) {
86 if (SnapshotsValidator.isSnapshot(dep.getVersion())) {
87 Logger.warn(
88 this,
89 "%s dependency is SNAPSHOT",
90 dep
91 );
92 ++errors;
93 }
94 }
95 if (errors > 0) {
96 Logger.warn(
97 this,
98 "The version of the project is not SNAPSHOT; there shouldn't not be any SNAPSHOT dependencies (%d found)",
99 errors
100 );
101 throw new ValidationException(
102 "%d dependencies are in SNAPSHOT state",
103 errors
104 );
105 }
106 }
107
108
109
110
111
112
113 private static boolean isSnapshot(final String version) {
114 return version.endsWith("-SNAPSHOT");
115 }
116
117 }