-
-
Notifications
You must be signed in to change notification settings - Fork 351
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
feature: add support for Jar files analysis with JarLauncher (decompile then build AST with spoon) #2455
Conversation
…, and add read default profile if it exists to get source version
…mposed of the concatenation of a string and another property
public class CFRDecompiler implements Decompiler { | ||
@Override | ||
public void decompile(File jar, File outputDir) { | ||
Main.main(new String[]{jar.getAbsolutePath(), "--outputdir", outputDir.getAbsolutePath()}); |
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.
is their a proper Java API?
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.
Not as far as I know.
* @param outputDir | ||
* Path for the output directory for decompilation. | ||
*/ | ||
void decompile(File jar, File outputDir); |
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.
What about
List<SpoonFile> decompile(String jarPath);
List<SpoonResource> decompile(String jarPath);
CtModel decompile(String jarPath);
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.
I'm not convinced by either of this solutions. My plan was to call the decompiler only if the input jar has been modified after last decompilation or if user forces it. I would prefer having directory declaration in JarLauncher than in Decompiler.
|
||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | ||
|
||
public class JarLauncher extends Launcher { |
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.
pom.xml
Outdated
<groupId>org.benf</groupId> | ||
<artifactId>cfr</artifactId> | ||
<version>${version.cfr}</version> | ||
<scope>system</scope> |
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.
Scope system
will not package the dependency into the resulting jar. You need to create a local maven repository and add it to git. See: https://sookocheff.com/post/java/local-maven-repository/
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.
Thanks. I'll do that.
Ready for review. |
LGTM. Could you add the corresponding documentation in |
pom.xml
Outdated
@@ -306,6 +306,9 @@ | |||
<groupId>org.benf</groupId> | |||
<artifactId>cfr</artifactId> | |||
<version>0.132.0</version> | |||
<!-- since it is not on Maven central, we don't package it --> | |||
<!-- if you need it, download it at http://www.benf.org/other/cfr/ and put the jar in the classpath yourself --> | |||
<scope>provided</scope> |
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.
It is not on maven central, but I've upload it on maven.inria.fr
, so it is still publicly available. (So we could package it if we wanted it.)
What's the license of CFR? Is it compatible with LGPL? |
It's MIT. |
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.
Thanks a lot, this opens interesting and fun new perspectives for Spoon
Dear all, I'd like to nominate Nicolas Harrand (@nharrand) to become an integrator in Spoon. Nicolas has done several key contributions over the past year: * he has added support for paths in order to uniquely identify AST nodes (#1874), this feature is unique (to my knowledge, it does not exist in any other source code analysis library for Java), and enables original source code analysis over time and versions. * he has added support for analysis of binary files with decompilation (#2455) * he has laid down the foundations of a modularized Spoon, which will likely be key in the future * he has ported Spoon to JDK 11 (#2789). This kind of infrastructure contribution is also very important in the long term. In addition, Nicolas has proven his ability to communicate constructively and respectfully over issues and pull-requests. What do you think?
This PR aims at providing support for JAR annalysis. (Related to #675 ).
My typical usecase is to be able to download an artifact's jar from maven central (and optionally its pom to get dependency information) to decompile it and build a spoon AST.
This code provide a small wrapper named JarLauncher that does just that.
Still lack:
As the decompiler I use ( CFR ) is not avilable on maven central I propose to add its jar in /libs.
WDYT?