Skip to content

Commit

Permalink
#2322: Ordered method
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Aug 16, 2023
1 parent f322196 commit a5abbd9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
10 changes: 3 additions & 7 deletions eo-maven-plugin/src/main/java/org/eolang/maven/rust/Cargo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@
package org.eolang.maven.rust;

import com.moandjiezana.toml.TomlWriter;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.cactoos.io.OutputStreamTo;
import org.cactoos.io.OutputTo;
import org.cactoos.map.MapEntry;
import org.cactoos.map.MapOf;

Expand Down Expand Up @@ -66,8 +61,8 @@ public class Cargo extends Savable {
*/
public Cargo(final String name) {
super(
name,
"rs"
"Cargo",
"toml"
);
this.pack = new MapOf<>(
new MapEntry<>("name", name),
Expand All @@ -93,6 +88,7 @@ public void add(final String crate, final Object content) {

/**
* Save it to specified folder.
* @return Content of built cargo.
* @throws IOException If any issues with I/O
*/
public String content() {
Expand Down
13 changes: 10 additions & 3 deletions eo-maven-plugin/src/main/java/org/eolang/maven/rust/Commented.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@
* Commented file.
* @since 0.30
*/
public class Commented extends Savable {
public final class Commented extends Savable {

final Savable origin;
final String start;
/**
* Origin file.
*/
private final Savable origin;

/**
* Commentary mark.
*/
private final String start;

/**
* Ctor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
*/
public class Module extends Savable {

final String raw;
/**
* Code in the module.
*/
private final String raw;

/**
* Ctor.
Expand All @@ -46,7 +49,7 @@ public Module(final String raw, final String name) {
}

@Override
String content() {
final String content() {
return this.raw;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
*/
public final class Native extends Savable {

final String pack;
/**
* Package of the java file.
*/
private final String pack;

/**
* Ctor.
Expand All @@ -52,7 +55,7 @@ String content() {
System.lineSeparator(),
String.format(
"package %s;",
pack
this.pack
),
"import org.eolang.Universe;",
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Path save() throws IOException {
for (final Module module: this.modules) {
new Commented(module, "//").save(this.footprint);
}
this.cargo.save(new FtDefault(this.dest.resolve("Cargo.toml")));
new Commented(this.cargo, "#").save(this.footprint);
return this.dest;
}
}
12 changes: 6 additions & 6 deletions eo-maven-plugin/src/main/java/org/eolang/maven/rust/Savable.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package org.eolang.maven.rust;

import java.io.IOException;
import org.cactoos.Scalar;
import org.eolang.maven.footprint.Footprint;

/**
Expand All @@ -44,11 +43,6 @@ public abstract class Savable {
*/
protected final String ext;

/**
* Content inside file.
*/
abstract String content();

/**
* Ctor.
* @param name Name of the file.
Expand All @@ -67,4 +61,10 @@ public Savable(final String name, final String ext) {
public void save(final Footprint footprint) throws IOException {
footprint.save(this.name, this.ext, this::content);
}

/**
* Content inside file.
* @return Content.
*/
abstract String content();
}

0 comments on commit a5abbd9

Please sign in to comment.