Skip to content

Commit

Permalink
moved to dependency-injected hse transpiler usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nlchar committed Aug 20, 2021
1 parent 1b858ac commit d91d9f1
Show file tree
Hide file tree
Showing 62 changed files with 82 additions and 5,357 deletions.
51 changes: 6 additions & 45 deletions eo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,63 +136,24 @@ SOFTWARE.
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eolang</groupId>
<artifactId>eo-runtime-hse</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.ainslec</groupId>
<artifactId>picocog</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
<groupId>io.github.hse-eolang</groupId>
<artifactId>transpiler</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
<groupId>io.github.hse-eolang</groupId>
<artifactId>runtime</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>${maven.compiler.target}</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
71 changes: 10 additions & 61 deletions eo-maven-plugin/src/main/java/org/eolang/maven/CompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@
import com.jcabi.log.Logger;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import io.github.hse_eolang.transpiler.Transpiler;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand All @@ -44,14 +38,16 @@
import org.cactoos.list.ListOf;
import org.cactoos.text.FormattedText;
import org.cactoos.text.UncheckedText;
import org.eolang.maven.transpiler.medium2target.Medium2TargetTranspiler;
import org.eolang.maven.transpiler.mediumcodemodel.EOSourceEntity;
import org.eolang.maven.transpiler.mediumcodemodel.EOSourceFile;
import org.eolang.maven.transpiler.mediumcodemodel.EOTargetFile;
import org.eolang.maven.transpiler.xml2medium.Xml2MediumParser;
import org.eolang.parser.Xsline;
import org.slf4j.impl.StaticLoggerBinder;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

/**
* Compile.
*
Expand Down Expand Up @@ -140,9 +136,10 @@ public void execute() throws MojoFailureException {
}
switch (this.compiler) {
case CompileMojo.COMPILER_HSE:
Transpiler transpiler = new Transpiler(this.generatedDir);
Files.walk(dir)
.filter(file -> !file.toFile().isDirectory())
.forEach(this::compileHse);
.forEach(transpiler::compileHse);
break;
case CompileMojo.COMPILER_ORIGINAL:
default:
Expand Down Expand Up @@ -231,54 +228,6 @@ private void compile(final Path file) {
Logger.info(this, "%s compiled to %s with the original compiler", file, this.generatedDir);
}

/**
* Compile one XML file.
*
* @param path The path to the XML file being compiled.
*/
private void compileHse(final Path path) {
final File file = new File(path.toUri());
final Xml2MediumParser xml = new Xml2MediumParser(file);
try {
final EOSourceEntity smth = xml.parse();
final ArrayList<EOTargetFile> code =
Medium2TargetTranspiler.transpile(
(EOSourceFile) smth
);
code.forEach(
javaFile -> {
try {
new Save(
javaFile.getContents(),
this.generatedDir.toPath().resolve(
Paths.get(
javaFile.getFileName()
)
)
).save();
} catch (final IOException exception) {
throw new IllegalStateException(
String.format(
"Can't read the path %s",
path
),
exception
);
}
}
);
} catch (final Xml2MediumParser.Xml2MediumParserException exception) {
throw new IllegalStateException(
String.format(
"The HSE compiler failed to parse the %s file.",
file
),
exception
);
}
Logger.info(this, "%s compiled to %s with the HSE compiler", path, this.generatedDir);
}

/**
* Check for errors.
*
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit d91d9f1

Please sign in to comment.