Skip to content

Commit

Permalink
#2263: Replaced static section by private static method
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Oct 2, 2023
1 parent a405862 commit aa292f0
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,7 @@ public final class BinarizeMojo extends SafeMojo {
/**
* Name of executable file which is result of cargo building.
*/
public static final String LIB;

static {
if (SystemUtils.IS_OS_WINDOWS) {
LIB = "common.dll";
} else if (SystemUtils.IS_OS_LINUX) {
LIB = "libcommon.so";
} else if (SystemUtils.IS_OS_MAC) {
LIB = "libcommon.dylib";
} else {
throw new IllegalArgumentException(
String.format(
"Rust inserts are not supported in %s os. Only windows, linux and macos are allowed.",
System.getProperty("os.name")
)
);
}
}
public static final String LIB = BinarizeMojo.common();

/**
* The directory where to binarize to.
Expand Down Expand Up @@ -130,6 +113,29 @@ public void exec() throws IOException {
Logger.info(this, "Built in total %d cargo projects", total);
}

/**
* Calculates name for Rust shared library depending on OS.
* @return Name.
*/
private static String common() {
final String result;
if (SystemUtils.IS_OS_WINDOWS) {
result = "common.dll";
} else if (SystemUtils.IS_OS_LINUX) {
result = "libcommon.so";
} else if (SystemUtils.IS_OS_MAC) {
result = "libcommon.dylib";
} else {
throw new IllegalArgumentException(
String.format(
"Rust inserts are not supported in %s os. Only windows, linux and macos are allowed.",
System.getProperty("os.name")
)
);
}
return result;
}

/**
* Is the project valid?
* @param project File to check.
Expand Down

0 comments on commit aa292f0

Please sign in to comment.