-
Notifications
You must be signed in to change notification settings - Fork 122
/
AssembleMojo.java
240 lines (221 loc) 路 8.03 KB
/
AssembleMojo.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.maven;
import com.jcabi.log.Logger;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.function.BiConsumer;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eolang.maven.objectionary.Objectionaries;
import org.eolang.maven.objectionary.ObjsDefault;
/**
* Pull all necessary EO XML files from Objectionary and parse them all.
*
* @since 0.1
*/
@Mojo(
name = "assemble",
defaultPhase = LifecyclePhase.PROCESS_SOURCES,
threadSafe = true
)
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.TooManyFields"})
public final class AssembleMojo extends SafeMojo {
/**
* The intermediate representation extension.
*/
public static final String IR_EXTENSION = "xmir";
/**
* Output.
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(
property = "eo.outputDir",
required = true,
defaultValue = "${project.build.outputDirectory}"
)
private File outputDir;
/**
* Objectionaries.
* @checkstyle MemberNameCheck (6 lines)
* @checkstyle ConstantUsageCheck (5 lines)
*/
private final Objectionaries objectionaries = new ObjsDefault();
/**
* The central.
*/
@SuppressWarnings("PMD.ImmutableField")
private BiConsumer<Dependency, Path> central;
/**
* Pull again even if the .eo file is already present?
* @checkstyle MemberNameCheck (7 lines)
* @since 0.10.0
*/
@Parameter(property = "eo.overWrite", required = true, defaultValue = "false")
private boolean overWrite;
/**
* The Git tag to pull objects from, in objectionary.
* @since 0.21.0
* @todo #2302:30min Rename the parameter "hash". This parameter is actually
* a tag, not a hash. By this tag application actually finds hash and then
* uses it. So need to rename this parameter to "tag" and rename it in all
* places where it's used. Also it would be better to use name "hash" for
* parameter "hsh" in {@link ProbeMojo} and {@link PullMojo}
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(property = "eo.hash", required = true, defaultValue = "master")
private String hash = "master";
/**
* Skip artifact with the version 0.0.0.
* @checkstyle MemberNameCheck (7 lines)
* @since 0.9.0
*/
@Parameter(property = "eo.skipZeroVersions", required = true, defaultValue = "true")
private boolean skipZeroVersions;
/**
* Shall we discover JAR artifacts for .EO sources?
* @checkstyle MemberNameCheck (7 lines)
* @since 0.12.0
*/
@Parameter(property = "eo.discoverSelf", required = true, defaultValue = "false")
private boolean discoverSelf;
/**
* Track optimization steps into intermediate XML files?
* @checkstyle MemberNameCheck (7 lines)
* @since 0.24.0
*/
@SuppressWarnings("PMD.LongVariable")
@Parameter(property = "eo.trackOptimizationSteps", required = true, defaultValue = "false")
private boolean trackOptimizationSteps;
/**
* Whether we should fail on error.
* @checkstyle MemberNameCheck (7 lines)
* @since 0.23.0
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(
property = "eo.failOnError",
defaultValue = "true")
private boolean failOnError = true;
/**
* Whether we should fail on warn.
* @checkstyle MemberNameCheck (10 lines)
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(
property = "eo.failOnWarning",
required = true,
defaultValue = "false"
)
private boolean failOnWarning;
/**
* Fail resolution process on transitive dependencies.
*
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(property = "eo.ignoreTransitive", required = true, defaultValue = "false")
@SuppressWarnings("PMD.ImmutableField")
private boolean ignoreTransitive;
/**
* Add eo-runtime dependency to the classpath.
*
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(property = "eo.ignoreRuntime", required = true, defaultValue = "true")
@SuppressWarnings({"PMD.ImmutableField", "PMD.LongVariable"})
private boolean withRuntimeDependency = true;
/**
* If set to TRUE, the exception on exit will be printed in details
* to the log.
* @checkstyle MemberNameCheck (7 lines)
* @checkstyle VisibilityModifierCheck (10 lines)
* @since 0.29.0
*/
@Parameter(property = "eo.unrollExitError")
@SuppressWarnings("PMD.ImmutableField")
private boolean unrollExitError = true;
/**
* The current version of eo-maven-plugin.
* Maven 3 only.
* It is the predefined maven property as MavenProject, MavenSession, MojoExecution, etc.
* You can read more about that property
* <a href="https://maven.apache.org/plugin-tools/maven-plugin-tools-annotations/index.html#Supported_Annotations">here</a>.
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(defaultValue = "${plugin}", readonly = true)
private PluginDescriptor plugin;
/**
* Place only binaries that have EO sources inside jar.
* @since 0.31
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter
@SuppressWarnings("PMD.LongVariable")
private boolean placeBinariesThatHaveSources;
@Override
public void exec() throws IOException {
if (this.central == null) {
this.central = new Central(this.project, this.session, this.manager);
}
String before = this.scopedTojos().status();
int cycle = 0;
final Moja<?>[] mojas = {
new Moja<>(ParseMojo.class),
new Moja<>(VersionsMojo.class),
new Moja<>(OptimizeMojo.class),
new Moja<>(DiscoverMojo.class),
new Moja<>(ProbeMojo.class),
new Moja<>(PullMojo.class),
new Moja<>(ResolveMojo.class),
new Moja<>(MarkMojo.class),
new Moja<>(PlaceMojo.class),
};
while (true) {
final long start = System.nanoTime();
for (final Moja<?> moja : mojas) {
moja.copy(this).execute();
}
final String after = this.scopedTojos().status();
++cycle;
if (Logger.isInfoEnabled(this)) {
Logger.info(
this, "Assemble cycle #%d (%s -> %s), took %[nano]s",
cycle, before, after, System.nanoTime() - start
);
}
if (after.equals(before)) {
break;
}
before = after;
}
Logger.info(
this, "%d assemble cycle(s) produced some new object(s): %s",
cycle, before
);
}
}