Skip to content

Commit

Permalink
Merge pull request #107 from hendrikebbers/106-fix
Browse files Browse the repository at this point in the history
Fix for issue 106: Change folder of BIN and ABI artifacts
  • Loading branch information
gtebrean committed May 15, 2023
2 parents 749496c + e2400b9 commit d734868
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,4 @@ fabric.properties
# *.ipr

# Sonarlint plugin
.idea/sonarlint

# End of https://www.gitignore.io/api/intellij
.idea/jarRepositories.xml
.idea/encodings.xml
.idea/jarRepositories.xml
**/.idea/*
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class JavaClassGeneratorMojo extends AbstractMojo {
protected String outputJavaParentContractClassName;

private Path createPath(String destinationPath) throws IOException {
Path path = Paths.get(destinationPath, packageName);
Path path = Paths.get(destinationPath, packageName.replace('.', '/'));

if (!path.toFile().exists()) {
Files.createDirectories(path);
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/web3j/mavenplugin/IssueITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,22 @@ public void issue83_solidityVersion_withABI() throws Exception {
.collect(Collectors.toList());
assertEquals("EtherWallet.java", files.get(0).getFileName().toString());
}

@Test
public void issue106_ABI_and_BIN_destination() throws Exception {
File pom = new File(resources.getBasedir("issue/106"), "pom.xml");
assertNotNull(pom);
assertTrue(pom.exists());

JavaClassGeneratorMojo mojo = (JavaClassGeneratorMojo) mojoRule.lookupMojo("generate-sources", pom);
assertNotNull(mojo);

mojo.sourceDestination = testFolder.getRoot().getPath();
mojo.outputDirectory.setAbi(testFolder.getRoot().getPath() + "/abi");
mojo.outputDirectory.setBin(testFolder.getRoot().getPath() + "/bin");
mojo.execute();

assertTrue(Paths.get(testFolder.getRoot().getPath(), "abi", "com", "sample", "generated", "Sample.json").toFile().exists());
assertTrue(Paths.get(testFolder.getRoot().getPath(), "bin", "com", "sample", "generated", "Sample.bin").toFile().exists());
}
}
34 changes: 34 additions & 0 deletions src/test/projects/issue/106/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.zuehlke.bc</groupId>
<artifactId>project-to-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Mojo Test Project</name>

<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>4.8.7</version>
<configuration>
<soliditySourceFiles>
<directory>src/test/resources/issue-106</directory>
<includes>
<include>**/*.sol</include>
</includes>
</soliditySourceFiles>
<outputFormat>java,abi,bin</outputFormat>
<packageName>com.sample.generated</packageName>
</configuration>
</plugin>
</plugins>
</build>

</project>
10 changes: 10 additions & 0 deletions src/test/resources/issue-106/sample.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.1 < 0.9.0;


library Sample {
function convert(uint amount, uint conversionRate) pure public returns (uint convertedAmount)
{
return amount * conversionRate;
}
}

0 comments on commit d734868

Please sign in to comment.