Skip to content

Commit

Permalink
Merge branch 'master' into 3160-enable-pmd-in-eo-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed May 13, 2024
2 parents 33b264a + 88b3b4b commit ff1c2ed
Show file tree
Hide file tree
Showing 159 changed files with 1,515 additions and 1,385 deletions.
4 changes: 2 additions & 2 deletions eo-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ create a file `pom.xml` with this content (it's just a sample):
<plugin>
<groupId>org.eolang</groupId>
<artifactId>eo-maven-plugin</artifactId>
<version>0.37.0</version>
<version>0.38.0</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -156,7 +156,7 @@ execution within `eo-maven-plugin/pom.xml`:
...
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>0.37.0</version>
<version>0.38.0</version>
<configuration>
<skipInstallation>true</skipInstallation>
<skipInvocation>true</skipInvocation>
Expand Down
131 changes: 67 additions & 64 deletions eo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SOFTWARE.
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.22</version>
<version>1.9.22.1</version>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
Expand Down Expand Up @@ -435,68 +435,75 @@ SOFTWARE.
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<phase>test</phase>
<goals>
<goal>check</goal>
<goal>report</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.70</minimum>
</limit>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.73</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.54</minimum>
</limit>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.60</minimum>
</limit>
<limit>
<counter>METHOD</counter>
<value>COVEREDRATIO</value>
<minimum>0.79</minimum>
</limit>
<limit>
<counter>CLASS</counter>
<value>MISSEDCOUNT</value>
<maximum>8</maximum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jacoco</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<phase>test</phase>
<goals>
<goal>check</goal>
<goal>report</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.70</minimum>
</limit>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.73</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.54</minimum>
</limit>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.60</minimum>
</limit>
<limit>
<counter>METHOD</counter>
<value>COVEREDRATIO</value>
<minimum>0.79</minimum>
</limit>
<limit>
<counter>CLASS</counter>
<value>MISSEDCOUNT</value>
<maximum>8</maximum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>qulice</id>
<build>
Expand All @@ -516,10 +523,6 @@ SOFTWARE.
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>com.github.volodya-lombrozo</groupId>
<artifactId>jtcop-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public final class TranspileMojo extends SafeMojo {
"/org/eolang/maven/pre/tests.xsl",
"/org/eolang/maven/pre/rename-tests-inners.xsl",
"/org/eolang/maven/pre/attrs.xsl",
"/org/eolang/maven/pre/varargs.xsl",
"/org/eolang/maven/pre/data.xsl"
).back(),
new TrDefault<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@
*/
public final class CommitHashesMap extends MapEnvelope<String, CommitHash> {

/**
* Fake hashes.
*/
static final String FAKES = String.join(
"\n",
"5fe5ad8d21dbe418038fa4c86e096fb037f290a9 0.23.15",
"15c85d7f8cffe15b0deba96e90bdac98a76293bb 0.23.17",
"4b19944d86058e3c81e558340a3a13bc335a2b48 0.23.19",
"0aa6875c40d099c3f670e93d4134b629566c5643 0.25.0",
"ff32e9ff70c2b3be75982757f4b0607dc37b258a 0.25.5",
"e0b783692ef749bb184244acb2401f551388a328 0.26.0",
"cc554ab82909eebbfdacd8a840f9cf42a99b64cf 0.27.0",
"00b60c7b2112cbad4e37ba96b162469a0e75f6df 0.27.2",
"6a70071580e95aeac104b2e48293d3dfe0669973 0.28.0",
"0c15066a2026cec69d613b709a301f1573f138ec 0.28.1",
"9b883935257bd59d1ba36240f7e213d4890df7ca 0.28.10",
"a7a4556bf1aa697324d805570f42d70affdddb75 0.28.14",
"54d83d4b1d28075ee623d58fd742eaa529febd3d 0.28.2",
"6c6269d1f9a1c81ffe641538f119fe4e12706cb3 0.28.4",
"9c9352890b5d30e1b89c9147e7c95a90c9b8709f 0.28.5",
"17f89293e5ae6115e9a0234b754b22918c11c602 0.28.6",
"5f82cc1edffad67bf4ba816610191403eb18af5d 0.28.7",
"be83d9adda4b7c9e670e625fe951c80f3ead4177 0.28.9"
);

/**
* Whitespace pattern.
*/
Expand Down Expand Up @@ -105,31 +130,7 @@ public static final class Fake extends MapEnvelope<String, CommitHash> {
* Ctor.
*/
public Fake() {
super(
new CommitHashesMap(
String.join(
"\n",
"5fe5ad8d21dbe418038fa4c86e096fb037f290a9 0.23.15",
"15c85d7f8cffe15b0deba96e90bdac98a76293bb 0.23.17",
"4b19944d86058e3c81e558340a3a13bc335a2b48 0.23.19",
"0aa6875c40d099c3f670e93d4134b629566c5643 0.25.0",
"ff32e9ff70c2b3be75982757f4b0607dc37b258a 0.25.5",
"e0b783692ef749bb184244acb2401f551388a328 0.26.0",
"cc554ab82909eebbfdacd8a840f9cf42a99b64cf 0.27.0",
"00b60c7b2112cbad4e37ba96b162469a0e75f6df 0.27.2",
"6a70071580e95aeac104b2e48293d3dfe0669973 0.28.0",
"0c15066a2026cec69d613b709a301f1573f138ec 0.28.1",
"9b883935257bd59d1ba36240f7e213d4890df7ca 0.28.10",
"a7a4556bf1aa697324d805570f42d70affdddb75 0.28.14",
"54d83d4b1d28075ee623d58fd742eaa529febd3d 0.28.2",
"6c6269d1f9a1c81ffe641538f119fe4e12706cb3 0.28.4",
"9c9352890b5d30e1b89c9147e7c95a90c9b8709f 0.28.5",
"17f89293e5ae6115e9a0234b754b22918c11c602 0.28.6",
"5f82cc1edffad67bf4ba816610191403eb18af5d 0.28.7",
"be83d9adda4b7c9e670e625fe951c80f3ead4177 0.28.9"
)
)
);
super(new CommitHashesMap(CommitHashesMap.FAKES));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.eolang.maven.hash;

import com.jcabi.aspects.RetryOnFailure;
import com.jcabi.log.Logger;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.cactoos.scalar.Unchecked;
Expand All @@ -32,8 +33,9 @@

/**
* Commit hashes table as text from objectionary.
* This class serves the purpose of the global cache in order to avoid
* downloading the list of tags multiple times from objectionary.
*
* <p>This class serves the purpose of the global cache in order to avoid
* downloading the list of tags multiple times from objectionary.</p>
*
* @since 0.29.6
*/
Expand Down Expand Up @@ -64,7 +66,20 @@ final class CommitHashesText extends TextEnvelope {
@RetryOnFailure(delay = 1L, unit = TimeUnit.SECONDS)
private static String asText(final String url) {
return new Unchecked<>(
() -> new TextOf(new URL(url)).asString()
() -> {
String hashes;
try {
hashes = new TextOf(new URL(url)).asString();
} catch (final java.net.UnknownHostException ex) {
Logger.warn(
CommitHashesText.class,
"Can't load hashes: %[exception]s",
ex
);
hashes = CommitHashesMap.FAKES;
}
return hashes;
}
).value();
}
}
17 changes: 15 additions & 2 deletions eo-maven-plugin/src/main/java/org/eolang/maven/rust/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ public String name(final String loc) {
return cached.computeIfAbsent(
loc,
key -> String.format(
"%s%d",
"%s%d_%s",
Names.PREFIX,
cached.size()
cached.size(),
Names.trim(key)
)
);
}
Expand Down Expand Up @@ -145,6 +146,18 @@ public void save() throws IOException {
);
}

/**
* Format loc: Remove non-ascii symbols, replace 桅.org.eolang with QQ
* and limit length of name characters.
* @param loc Locator of Rust insert.
* @return Formatted name.
*/
private static String trim(final String loc) {
final String replaced = loc.replace("桅.org.eolang", "QQ")
.replaceAll("[^a-zA-Z0-9.-]", "").replaceAll("[. -]", "_");
return replaced.substring(Math.max(replaced.length() - 64, 0));
}

/**
* Prestructor to initialize this.all.
* @param dest Directory where to load from.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public PrimeModule(final String method, final String file) {
"use eo::eo_enum::EO::EOError;",
"#[no_mangle]",
"pub extern \"system\" fn",
String.format("Java_EOrust_natives_%s_%s", method, method),
translate(method),
"<'local> (env: JNIEnv<'local>, _class: JClass<'local>, universe: JObject<'local>) -> JByteArray<'local>",
"{ let mut eo = Portal::new(env, _class, universe); ",
"let arr = foo(&mut eo)",
Expand All @@ -58,4 +58,35 @@ public PrimeModule(final String method, final String file) {
file
);
}

/**
* Translates ("mangles") Java method name to native method name.
* For example, translated "native0_custom" to
* Java_EOrust_natives_native0_1custom_native0_1custom.
* See {@link PrimeModule#translate(String, String)} for motivation.
* @param jname Name of this function (and class) in Java.
* @return How it named in Rust.
*/
private static String translate(final String jname) {
return PrimeModule.translate(
"EOrust.natives.".concat(jname),
jname
);
}

/**
* Translates ("mangles") Java method name to native method name according to
* <a href="https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/design.html">documentation</a>
* or <a href="https://stackoverflow.com/questions/32470463/what-is-the-naming-convention-for-java-native-interface-method-and-module-name">stackoverflow</a>.
* @param clazz Simple name of class.
* @param method Name of method.
* @return How it named in Rust.
*/
private static String translate(final String clazz, final String method) {
return String.format(
"Java_%s_%s",
clazz.replace("_", "_1").replace(".", "_"),
method.replace("_", "_1")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ SOFTWARE.
<rusts>
<xsl:comment>"Rust inserts"</xsl:comment>
<xsl:for-each select="//o">
<xsl:if test="../attribute(base) = '.rust' and attribute(base) = 'org.eolang.string'">
<xsl:if test="(../attribute(base) = 'org.eolang.rust' or (../attribute(base) = '.rust' and ../o[1]/attribute(base) = '.eolang' and ../o[1]/o[1]/attribute(base) = '.org' and ../o[1]/o[1]/o[1]/attribute(base) = 'Q')) and (attribute(base) = 'org.eolang.string' or (attribute(base) = '.string' and o[1]/attribute(base) = '.eolang' and o[1]/o[1]/attribute(base) = '.org' and o[1]/o[1]/o[1]/attribute(base) = 'Q'))">
<rust>
<xsl:attribute name="code">
<xsl:value-of select="./o/text()"/>
<xsl:value-of select="./o[@data = 'bytes']/text()"/>
</xsl:attribute>
<xsl:attribute name="code_loc">
<xsl:value-of select="attribute(loc)"/>
</xsl:attribute>
<dependencies>
<xsl:for-each select="following-sibling::o/o">
<xsl:if test="parent::o[@base = 'org.eolang.tuple'] and @base = 'org.eolang.string'">
<xsl:if test="(parent::o/attribute(base) = 'org.eolang.tuple' or (parent::o/attribute(base) = '.tuple' and parent::o/o[1]/attribute(base) = '.eolang' and parent::o/o[1]/o[1]/attribute(base) = '.org' and parent::o/o[1]/o[1]/o[1]/attribute(base) = 'Q')) and (attribute(base) = 'org.eolang.string' or (attribute(base) = '.string' and o[1]/attribute(base) = '.eolang' and o[1]/o[1]/attribute(base) = '.org' and o[1]/o[1]/o[1]/attribute(base) = 'Q'))">
<dependency>
<xsl:attribute name="name">
<xsl:value-of select="./o/text()"/>
<xsl:value-of select="./o[@data = 'bytes']/text()"/>
</xsl:attribute>
</dependency>
</xsl:if>
Expand Down

0 comments on commit ff1c2ed

Please sign in to comment.