Skip to content

Commit

Permalink
Merge pull request #3891 from maxonfjvipon/bug/#2698/compile-mojo
Browse files Browse the repository at this point in the history
bug(#2698): introduced `compile` goal
  • Loading branch information
yegor256 authored Feb 5, 2025
2 parents de529b2 + 7c71fe6 commit b9258ba
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 349 deletions.
197 changes: 11 additions & 186 deletions eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,20 @@
package org.eolang.maven;

import com.jcabi.log.Logger;
import java.io.File;
import java.nio.file.Path;
import java.util.Set;
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.cactoos.set.SetOf;

/**
* Pull all necessary EO XML files from Objectionary and parse them all.
*
* @since 0.1
* @todo #2406:90min Make up with idea how to get rid of duplicate parameters between mojos.
* There's a situation where AssembleMojo owns, creates and executes other mojos,
* like {@link ParseMojo} or {@link ShakeMojo}. When we configure our compiler via pom.xml maven
* tries to set parameters directly to the calling mojo. That's why we must to have all parameters
* from child mojos in AssembleMojo or {@link SafeMojo} (in order they won't be skipped and lost).
* That causes duplication of parameters between "parent" mojo and "child" mojos.
* Also it obliges the developer to remember that if he adds new parameter to some child mojo,
* this parameter must be present in parent mojo as well.
* We didn't find a way how we can resolve such duplication at the moment.
* So we need to either accept this as impossible to solve or resolve somehow.
* Anyway don't forget to remove the puzzle when the decision about the puzzle is made.
*/
@Mojo(
name = "assemble",
defaultPhase = LifecyclePhase.PROCESS_SOURCES,
threadSafe = true
)
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.TooManyFields"})
public final class AssembleMojo extends SafeMojo {

/**
* The intermediate representation extension.
*/
Expand All @@ -70,180 +49,26 @@ public final class AssembleMojo extends SafeMojo {
public static final String EO = "eo";

/**
* Output.
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(
property = "eo.outputDir",
required = true,
defaultValue = "${project.build.outputDirectory}"
)
private File outputDir;

/**
* List of inclusion GLOB filters for finding class files.
* @since 0.15
* @checkstyle MemberNameCheck (7 lines)
* @checkstyle ConstantUsageCheck (5 lines)
*/
@Parameter
private final Set<String> includeBinaries = new SetOf<>("**");

/**
* List of exclusion GLOB filters for finding class files.
* @since 0.15
* @checkstyle MemberNameCheck (7 lines)
* @checkstyle ConstantUsageCheck (5 lines)
*/
@Parameter
private final Set<String> excludeBinaries = new SetOf<>();

/**
* The central.
*/
@SuppressWarnings("PMD.ImmutableField")
private BiConsumer<Dependency, Path> central;

/**
* Pull again even if the .eo file is already present?
* @since 0.10.0
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(property = "eo.overWrite", required = true, defaultValue = "false")
private boolean overWrite;

/**
* Track optimization steps into intermediate XML files?
*
* @since 0.24.0
* @checkstyle MemberNameCheck (7 lines)
*/
@SuppressWarnings("PMD.LongVariable")
@Parameter(property = "eo.trackTransformationSteps", required = true, defaultValue = "false")
private boolean trackTransformationSteps;

/**
* The Git tag to pull objects from, in objectionary.
* @since 0.21.0
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(property = "eo.tag", required = true, defaultValue = "master")
private String tag = "master";

/**
* Skip artifact with the version 0.0.0.
* @since 0.9.0
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(property = "eo.skipZeroVersions", required = true, defaultValue = "true")
private boolean skipZeroVersions;

/**
* Shall we discover JAR artifacts for .EO sources?
* @since 0.12.0
* @checkstyle MemberNameCheck (7 lines)
* Mojas to execute.
*/
@Parameter(property = "eo.discoverSelf", required = true, defaultValue = "false")
private boolean discoverSelf;

/**
* Fail resolution process on conflicting dependencies.
*
* @since 0.1.0
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(property = "eo.ignoreVersionConflicts", required = true, defaultValue = "false")
@SuppressWarnings("PMD.LongVariable")
private boolean ignoreVersionConflicts;

/**
* 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.
* @since 0.29.0
* @checkstyle MemberNameCheck (7 lines)
* @checkstyle VisibilityModifierCheck (10 lines)
*/
@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;

/**
* Pull objects from objectionary or not.
* @since 0.32.0
*/
@Parameter(property = "eo.offline", required = true, defaultValue = "false")
private boolean offline;
private static final Moja<?>[] MOJAS = {
new Moja<>(ParseMojo.class),
new Moja<>(ShakeMojo.class),
new Moja<>(ProbeMojo.class),
new Moja<>(PullMojo.class),
new Moja<>(ResolveMojo.class),
new Moja<>(MarkMojo.class),
new Moja<>(PlaceMojo.class),
};

@Override
public void exec() {
final long begin = System.currentTimeMillis();
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<>(ShakeMojo.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.currentTimeMillis();
for (final Moja<?> moja : mojas) {
for (final Moja<?> moja : AssembleMojo.MOJAS) {
moja.copy(this).execute();
}
final String after = this.scopedTojos().status();
Expand Down
62 changes: 62 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/CompileMojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2025 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 org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;

/**
* Compile and lint all EO files.
*
* @since 0.52
*/
@Mojo(
name = "compile",
defaultPhase = LifecyclePhase.PROCESS_SOURCES,
threadSafe = true
)
public final class CompileMojo extends SafeMojo {
/**
* Mojas to execute.
*/
private static final Moja<?>[] MOJAS = {
new Moja<>(DownloadDepsMojo.class),
new Moja<>(AssembleMojo.class),
new Moja<>(LintMojo.class),
};

@Override
public void exec() {
final long begin = System.currentTimeMillis();
for (final Moja<?> moja : CompileMojo.MOJAS) {
moja.copy(this).execute();
}
Logger.info(
this,
"Compilation process took %[ms]s",
System.currentTimeMillis() - begin
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package org.eolang.maven;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand All @@ -52,17 +50,8 @@ public final class DownloadDepsMojo extends SafeMojo {
new DepFunc("net.java.dev.jna", "jna", "5.14.0")
);

/**
* The central.
*/
@SuppressWarnings("PMD.ImmutableField")
private BiConsumer<Dependency, Path> central;

@Override
void exec() throws IOException {
if (this.central == null) {
this.central = new Central(this.project, this.session, this.manager);
}
for (final Supplier<Dependency> dep : DownloadDepsMojo.DEPS) {
this.central.accept(dep.get(), this.classesDir.toPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
threadSafe = true
)
public final class MarkMojo extends SafeMojo {

@Override
public void exec() throws IOException {
final Path home = this.targetDir.toPath().resolve(ResolveMojo.DIR);
Expand Down
13 changes: 0 additions & 13 deletions eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
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.apache.maven.plugins.annotations.ResolutionScope;
import org.cactoos.Func;
import org.cactoos.io.InputOf;
Expand All @@ -56,7 +54,6 @@
threadSafe = true,
requiresDependencyResolution = ResolutionScope.COMPILE
)
@SuppressWarnings("PMD.ImmutableField")
public final class ParseMojo extends SafeMojo {

/**
Expand All @@ -74,16 +71,6 @@ public final class ParseMojo extends SafeMojo {
*/
public static final String CACHE = "parsed";

/**
* The current version of eo-maven-plugin.
* Maven 3 only.
* 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;

@Override
public void exec() {
final long start = System.currentTimeMillis();
Expand Down
Loading

1 comment on commit b9258ba

@0pdd
Copy link

@0pdd 0pdd commented on b9258ba Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2406-a7fa785a disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java), that's why I closed #3782. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.