Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 0 additions & 101 deletions eo-maven-plugin/src/main/java/org/eolang/maven/CopyMojo.java

This file was deleted.

37 changes: 20 additions & 17 deletions eo-maven-plugin/src/main/java/org/eolang/maven/DpsWithRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.net.URL;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.apache.maven.model.Dependency;
import org.cactoos.list.ListOf;
import org.cactoos.scalar.Sticky;
Expand Down Expand Up @@ -95,21 +96,23 @@ private static Unchecked<Dep> mavenDependency() {
"https://repo.maven.apache.org/maven2/%s/maven-metadata.xml",
"org/eolang/eo-runtime"
);
try {
return DpsWithRuntime.dependency(
new Xnav(new XMLDocument(new URL(url)).inner())
.element("metadata")
.element("versioning")
.element("latest")
.text()
.get()
);
} catch (final IOException ex) {
throw new IllegalStateException(
String.format("Can't get eo-runtime dependency by the URL: %s", url),
ex
);
}
return DpsWithRuntime.dependency(
() -> {
try {
return new Xnav(new XMLDocument(new URL(url)).inner())
.element("metadata")
.element("versioning")
.element("latest")
.text()
.get();
} catch (final IOException ex) {
throw new IllegalStateException(
String.format("Can't get eo-runtime dependency by the URL: %s", url),
ex
);
}
}
);
}

/**
Expand All @@ -128,14 +131,14 @@ private static boolean isRuntime(final Dependency other) {
* @param version Version of eo-runtime
* @return Maven Dependency.
*/
private static Unchecked<Dep> dependency(final String version) {
private static Unchecked<Dep> dependency(final Supplier<String> version) {
return new Unchecked<>(
new Synced<>(
new Sticky<>(
() -> new Dep()
.withGroupId("org.eolang")
.withArtifactId("eo-runtime")
.withVersion(version)
.withVersion(version.get())
.withClassifier("")
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
* SPDX-License-Identifier: MIT
*/
package org.eolang.maven;

import com.jcabi.log.Logger;
import java.io.File;
import java.nio.file.Path;

/**
* Delete empty directories in provided root.
*
* @since 0.55
*/
final class EmptyDirectoriesIn {
/**
* Root path.
*/
private final File root;

/**
* Ctor.
* @param root Root directory.
*/
EmptyDirectoriesIn(final Path root) {
this(root.toFile());
}

/**
* Ctor.
* @param root Root directory
*/
EmptyDirectoriesIn(final File root) {
this.root = root;
}

/**
* Clear empty directories in {@code this.root}.
*/
void clear() {
if (!this.root.isDirectory()) {
throw new IllegalStateException(
Logger.format("Provided path %[file]s is not a directory", this.root)
);
}
this.delete(this.root);
}

/**
* Recursively delete empty directories.
* @param dir Directory to delete
* @checkstyle NestedIfDepthCheck (20 lines)
*/
private void delete(final File dir) {
if (!dir.isDirectory()) {
return;
}
final File[] before = dir.listFiles();
if (before != null) {
for (final File file : before) {
if (file.isDirectory()) {
this.delete(file);
}
}
}
final File[] after = dir.listFiles();
if (after != null && after.length == 0 && !dir.equals(this.root) && dir.delete()) {
Logger.debug(EmptyDirectoriesIn.class, "Deleted empty directory %[file]s", dir);
}
}
}
36 changes: 16 additions & 20 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PlaceMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Supplier;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.cactoos.io.InputOf;
Expand Down Expand Up @@ -67,17 +68,16 @@ private long placeDependency(final Path home, final String dep) {
Logger.debug(this, "Found placed binaries from %s", dep);
}
final Path dir = home.resolve(dep);
final long copied = new BinariesDependency(dir, dep, this.rewriteBinaries).place();
this.placedTojos.placeJar(dep);
final long copied = new PlaceMojo.PlacedDependency(dir, dep, this.rewriteBinaries).get();
if (copied > 0) {
Logger.debug(
this, "Placed %d binary file(s) out of %d, found in %s, to %[file]s",
copied, new Walk(dir).size(), dep, this.outputDir
copied, new Walk(dir).size(), dep, this.classesDir
);
} else {
Logger.debug(
this, "No binary file(s) out of %d were placed from %s, to %[file]s",
new Walk(dir).size(), dep, this.outputDir
new Walk(dir).size(), dep, this.classesDir
);
}
return copied;
Expand All @@ -88,7 +88,7 @@ copied, new Walk(dir).size(), dep, this.outputDir
*
* @since 0.30
*/
private final class BinariesDependency {
private final class PlacedDependency implements Supplier<Long> {

/**
* Directory to read from.
Expand All @@ -111,7 +111,7 @@ private final class BinariesDependency {
* @param dependency The name of dependency
* @param rwte Rewrite binaries in output directory or not
*/
private BinariesDependency(
private PlacedDependency(
final Path directory,
final String dependency,
final boolean rwte
Expand All @@ -121,14 +121,11 @@ private BinariesDependency(
this.rewrite = rwte;
}

/**
* Place all binaries from this dependency.
* @return How many binaries placed
*/
private long place() {
@Override
public Long get() {
return new Walk(this.dir)
.includes(PlaceMojo.this.includeBinaries)
.excludes(PlaceMojo.this.excludeBinaries)
.includes(PlaceMojo.this.placeBinaries)
.excludes(PlaceMojo.this.skipBinaries)
.stream()
.filter(this::isNotAlreadyPlaced)
.peek(this::printLogInfoAboutBinary)
Expand All @@ -142,15 +139,14 @@ private long place() {
* @return True if the file is not already placed.
*/
private boolean isNotAlreadyPlaced(final Path file) {
final Path target = PlaceMojo.this.outputDir.toPath().resolve(
final Path target = PlaceMojo.this.classesDir.toPath().resolve(
this.dir.relativize(file)
);
final Optional<TjPlaced> tojo = PlaceMojo.this.placedTojos.find(target);
final boolean res;
if (tojo.isPresent()
&& Files.exists(target)
&& (this.sameLength(target, file)
|| !tojo.get().unplaced())
&& (this.sameLength(target, file) || !tojo.get().unplaced())
) {
Logger.debug(
this,
Expand All @@ -169,7 +165,7 @@ private boolean isNotAlreadyPlaced(final Path file) {
* @param file The file to place.
*/
private void printLogInfoAboutBinary(final Path file) {
final Path target = PlaceMojo.this.outputDir.toPath().resolve(
final Path target = PlaceMojo.this.classesDir.toPath().resolve(
this.dir.relativize(file)
);
final Optional<TjPlaced> tojo = PlaceMojo.this.placedTojos.find(target);
Expand Down Expand Up @@ -204,17 +200,17 @@ private void placeBinary(final Path file) {
final Path target = new FpIfTargetExists(
new FpFork(this.rewrite, generated, new FpIgnore()),
generated
).apply(file, PlaceMojo.this.outputDir.toPath().resolve(path));
).apply(file, PlaceMojo.this.classesDir.toPath().resolve(path));
PlaceMojo.this.placedTojos.placeClass(
target,
PlaceMojo.this.outputDir.toPath().relativize(target).toString(),
PlaceMojo.this.classesDir.toPath().relativize(target).toString(),
this.dep
);
} catch (final IOException ex) {
throw new IllegalStateException(
Logger.format(
"Failed to place %[file]s to home %[file]s with path %s",
file, PlaceMojo.this.outputDir, path
file, PlaceMojo.this.classesDir, path
),
ex
);
Expand Down
Loading