-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the output of compileJava
an input of neow3jCompile
to have a consistent caching behavior
#1026
Make the output of compileJava
an input of neow3jCompile
to have a consistent caching behavior
#1026
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good start! 💪
So... the tests didn't run because, most likely, the code has a compilation problem. Did you try ./gradlew clean compileJava
?
Also, tests are missing. It's rule that for each new feature, tests should be developed. Unit tests and integration tests. For the case of gradle-plugin
module, we just develop integration tests. See here.
One way is to create a test case where the cacheable=false
also running the compilation twice. If the task outcome of the second execution is FROM_CACHE
, then the test didn't pass. If the outcome is SUCCESS
, then it passed. We can discuss this in Discord, if you want. 👍
gradle-plugin/src/main/java/io/neow3j/devpack/gradle/Neow3jCompileTask.java
Outdated
Show resolved
Hide resolved
gradle-plugin/src/main/java/io/neow3j/devpack/gradle/Neow3jPlugin.java
Outdated
Show resolved
Hide resolved
gradle-plugin/src/main/java/io/neow3j/devpack/gradle/Neow3jPlugin.java
Outdated
Show resolved
Hide resolved
gradle-plugin/src/main/java/io/neow3j/devpack/gradle/Neow3jCompileTask.java
Outdated
Show resolved
Hide resolved
gradle-plugin/src/main/java/io/neow3j/devpack/gradle/Neow3jCompileTask.java
Outdated
Show resolved
Hide resolved
gradle-plugin/src/main/java/io/neow3j/devpack/gradle/Neow3jPluginExtension.java
Outdated
Show resolved
Hide resolved
Thinking out loud: we might think about using an |
From the docs: |
@gsmachado At first, I've completed the initial approach so we can continue from here. I created the test case, but the second |
That's a good progress! So... let me elaborate a bit more on why I came up with this comment: In the past, I was playing with neow3j and realized that, sometimes, when I changed a smart contract (i.e., a Thinking a bit better, I remembered about past experiments with Gradle, as well as the logic of inputs and outputs. Also, by reading the code, I realized that I went with a simpler implementation and did not properly use the output of Then, I suggest you try the following:
protected static void replaceMethodName(String filePath, String oldMethodName, String newMethodName) throws IOException {
Path path = Paths.get(filePath);
// Read the file content into a String
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
// Replace the method name
content = content.replaceAll("\\b" + oldMethodName + "\\b", newMethodName);
// Write the modified content back to the file
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
} This method intends to replace a string on a file. The intention here is to change the method name of the testing smart contract. We could try to change anything else (like, the class name), but since the smart contract used for testing is pretty simple, I'd just go with changing the method name.
protected GradleProjectTestCase replaceMethodName(String oldMethodName, String newMethodName)
throws IOException {
TestCaseUtils.replaceMethodName(this.smartContractSourceFile.getAbsolutePath(), oldMethodName, newMethodName);
return this;
}
What does this mean? It means that, in the second Then, my initial goal to add a So, how do we solve it? How do we make this test pass? (i.e., the second Some suggestions for you:
@InputDirectory
public abstract DirectoryProperty getBuildDirectory();
task.getProject().getPluginManager().apply(JavaLibraryPlugin.class);
JavaCompile compileJava = (JavaCompile) project.getTasks().getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME);
task.getBuildDirectory().set(compileJava.getDestinationDir());
task.dependsOn(JavaPlugin.COMPILE_JAVA_TASK_NAME);
Happy coding. |
@gsmachado this other approach seems to be working well, if I'm not mistaken. The only problem I'm seeing is that one test case is breaking, probably because of directory / path stuff. Look: here: It seems that the build output directory does not exist after a compilation error. JavaCompile compileJava = (JavaCompile) project.getTasks().getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME);
task.getBuildDirectory().set(compileJava.getDestinationDir()); Maybe they're hitting different destinations? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work.
I requested few (minor) changes in the test files.
In addition to that, I believe that the logic of these lines, which the test is failing now, can be changed -- because is not entirely correct.
I would propose to delete these lines and add this one:
assertFalse(testCase.getBuildNeow3jOutputDir().exists());
Meaning that: if the neow3jCompile
fails (this line), then the build dir related to neow3j smart contracts should also not exist as a result.
...n/src/test-integration/java/io/neow3j/devpack/gradle/Neow3jCompilePluginIntegrationTest.java
Show resolved
Hide resolved
...n/src/test-integration/java/io/neow3j/devpack/gradle/Neow3jCompilePluginIntegrationTest.java
Show resolved
Hide resolved
Done @gsmachado . Thanks for all the help. Now I understand much better how neow3j works, and I'm sure this will help on future contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. 👍 ✅
compileJava
an input of neow3jCompile
to have a consistent caching behavior
@Lorenzobattistela I made a small change in the |
@Lorenzobattistela congrats on the first PR merged to neow3j. 🎉 |
#1016
So @gsmachado I've followed your instructions, and I think this is the right way. I'm sure i dont understand 100% how it all happens, but Im getting along. Now I need to test this changes (specially the syntax around Spec), but I'm not quite sure how, running
./gradlew tests
or./gradlew integrationTests
is failing, is there any setup needed? If so, where can I find it?