-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathAssembleMojo.java
More file actions
165 lines (155 loc) · 5.63 KB
/
AssembleMojo.java
File metadata and controls
165 lines (155 loc) · 5.63 KB
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
/*
* SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
* SPDX-License-Identifier: MIT
*/
package org.eolang.jeo;
import com.jcabi.log.Logger;
import java.io.File;
import java.nio.file.Path;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
/**
* Assembles XMIR representation of Java bytecode into executable class files.
*
* <p>This Maven plugin converts low-level EO representation (in XMIR format) into Java bytecode
* that can be executed by the Java Virtual Machine. The plugin performs pure assembly without
* applying any optimizations or improvements to the bytecode.</p>
*
* <p>The plugin supports optional bytecode verification to ensure generated classes are valid
* and can be loaded by the JVM.</p>
*
* @since 0.1.0
*/
@Mojo(name = "assemble", defaultPhase = LifecyclePhase.PROCESS_CLASSES, requiresProject = false)
public final class AssembleMojo extends AbstractMojo {
/**
* Maven project instance.
* <p>
* Provides access to project configuration and dependencies required for bytecode verification.
* </p>
*
* @since 0.2.0
*/
@Parameter(defaultValue = "${project}", readonly = true)
private MavenProject project;
/**
* Source directory containing XMIR files to be assembled.
* <p>
* This directory should contain EO files in XMIR format that represent Java bytecode
* instructions. These files are typically generated by the disassemble goal.
* </p>
*
* @since 0.2.0
* @checkstyle MemberNameCheck (6 lines)
*/
@Parameter(
property = "jeo.assemble.sourcesDir",
defaultValue = "${project.build.directory}/generated-sources/jeo-xmir"
)
private File sourcesDir;
/**
* Target directory for generated bytecode class files.
* <p>
* All assembled class files will be written to this directory, preserving the package
* structure as defined in the source XMIR files.
* </p>
*
* @since 0.2.0
* @checkstyle MemberNameCheck (6 lines)
*/
@Parameter(
property = "jeo.assemble.outputDir",
defaultValue = "${project.build.outputDirectory}"
)
private File outputDir;
/**
* Flag to skip bytecode verification after assembly.
* <p>
* By default, all generated bytecode is verified to ensure it conforms to JVM specifications
* and can be loaded without errors. Set this parameter to {@code true} to skip verification,
* which may speed up the build but could result in invalid class files.
* </p>
*
* @since 0.2.0
* @checkstyle MemberNameCheck (6 lines)
*/
@Parameter(
property = "jeo.assemble.skip.verification",
defaultValue = "false"
)
private boolean skipVerification;
/**
* Flag to enable XMIR verification before assembling.
* <p>
* When enabled, verifies all XMIR files for structural integrity and correctness before
* attempting to assemble them into bytecode. If any XMIR file is invalid or corrupted,
* the build process will fail. This verification is disabled by default for performance.
* </p>
*
* @since 0.8.0
* @checkstyle MemberNameCheck (6 lines)
*/
@Parameter(
property = "jeo.assemble.xmir.verification",
defaultValue = "false"
)
private boolean xmirVerification;
/**
* Flag to disable the plugin execution.
* <p>
* When set to {@code true}, the plugin will skip all processing and exit immediately.
* This can be useful for conditional builds or troubleshooting.
* </p>
*
* @since 0.2.0
* @checkstyle MemberNameCheck (6 lines)
*/
@Parameter(
property = "jeo.assemble.disabled",
defaultValue = "false"
)
private boolean disabled;
/**
* Enable debug logging for the assembling process.
* @since 0.15.0
* @checkstyle MemberNameCheck (6 lines)
*/
@Parameter(property = "jeo.assemble.debug", defaultValue = "false")
private boolean debug;
@Override
public void execute() throws MojoExecutionException {
final Path src = new MavenPath(this.sourcesDir).resolve();
final Path out = new MavenPath(this.outputDir).resolve();
try {
if (this.disabled) {
Logger.info(this, "Assemble mojo is disabled, skipping");
} else {
if (this.xmirVerification) {
Logger.info(this, "Verifying all the XMIR files before assembling...");
new XmirFiles(src).verify();
} else {
Logger.info(this, "XMIR verification before assembling is disabled, skipping");
}
new Assembler(
src,
out,
this.debug
).assemble();
if (this.skipVerification) {
Logger.info(this, "Bytecode verification is disabled, skipping");
} else {
Logger.info(this, "Verifying bytecode of all the generated classes...");
new PluginStartup(this.project, out).init();
new BytecodeClasses(out).verify();
}
}
} catch (final DependencyResolutionRequiredException exception) {
throw new MojoExecutionException(exception);
}
}
}