-
Notifications
You must be signed in to change notification settings - Fork 24
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
Enables plugin to analyze kotlin projects #378
base: develop
Are you sure you want to change the base?
Conversation
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]>
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]>
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]>
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]>
…iggering Kotlin Compiler Signed-off-by: Rakshit Krishnappa Ravi <[email protected]>
…is uninstalled Signed-off-by: Rakshit Krishnappa Ravi <[email protected]>
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]>
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]>
if(ip.hasNature("org.eclipse.m2e.core.maven2Nature")) { | ||
if(KotlinUtils.verifyKotlinDependency(javaProject)) { | ||
|
||
System.out.println("Custom Builder started."); |
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.
Use Activator.getDefault().logInfo() if you really want to log something.
In this case, be more specific than "custom builder". A user would have no idea, what builder this message is talking about.
if(KotlinUtils.verifyKotlinDependency(javaProject)) { | ||
|
||
System.out.println("Custom Builder started."); | ||
final Job builder = new Job("Custom Builder") { |
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.
Same here.
try { | ||
ip.build(IncrementalProjectBuilder.CLEAN_BUILD, null); | ||
} catch (CoreException e) { | ||
e.printStackTrace(); |
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.
All exception logging should go through Activator.getDefault.logError().
while(builder.getState() != Job.NONE) { | ||
Thread.sleep(3); | ||
} | ||
System.out.println("Custom Builder finished."); |
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.
.
KotlinUtils.waitForBuildAndRefreshJobs(); | ||
|
||
KotlinCompilerResult result = KotlinCompiler.compileKotlinFiles(javaProject); | ||
if(result.compiledCorrectly()) |
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.
Add curly braces, even if there is just one line in the branch.
Also, inline "result". The variable is only used once.
|
||
if (pomFile != null && pomFile.exists()) | ||
{ | ||
FileReader reader = null; |
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.
Rather use try with resource: https://docs.oracle.com/en/java/javase/13/language/try-resources.html
dialog.setMessage("Analysis requires maven kotlin-stdlib dependency. Would you like to add it?"); | ||
dialog.setText("CAUTION"); | ||
int opt = dialog.open(); | ||
if (opt == SWT.YES) |
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.
Change to "return dialog.open();"
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> | ||
<?xml version="1.0" encoding="UTF-8"?> |
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.
This file should stay as it is.
@@ -23,4 +23,5 @@ Bundle-ActivationPolicy: lazy | |||
Bundle-ClassPath: ., | |||
resources/ | |||
Automatic-Module-Name: de.cognicrypt.staticanalyzer | |||
Import-Package: org.eclipse.ui.texteditor | |||
Import-Package: de.cognicrypt.staticanalyzer.kotlin.utilities, |
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.
If there is a dependency between these two plugins, it should be the other way around. Please check why this dependency exists and resolve it differently.
return true; | ||
} | ||
|
||
KotlinUtils.compileKotlinFiles(ip); |
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.
Do not call the kotlin plugin from inside this one like this. This call causes the kotlin plugin to be required under all circumstances.
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.
Could you please suggest me some way to achieve this? I've implemented rest of your review changes except this one.
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 think reflection or some kind of dependency injection would be the way to go. Reflection is not that clean. We should look up some dependency injection frameworks that are clean. This sounds tricky to accomplish but a needed requirement as we do not want to have dependency from kotlin to base.
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.
One option is to use the factory pattern. Have a base factory runner that calls the kotlin runner if configuration is kotlin. https://www.tutorialspoint.com/design_pattern/factory_pattern.htm
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]> Below changes have been made: - replaced sysouts with logInfos - changed exception logging to go through Activator.getDefault.logError() - added curly braces to single line branch code - removed single use variables - used try-with-resource syntax instead of try-finally - changed return type of selectedDialogOption method
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]>
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]> Below changes have been made: - replaced sysouts with logInfos - changed exception logging to go through Activator.getDefault.logError() - added curly braces to single line branch code - removed single use variables - used try-with-resource syntax instead of try-finally - changed return type of selectedDialogOption method
6c94a02
to
f0ac0c0
Compare
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]> - implemented extension - staticanalyzer plugin is the host plugin - kotlin plugin is the extender plugin that gets triggered when the project is of kotlin nature - this would would make staticanalyzer plugin independent of kotlin plugin
Signed-off-by: Rakshit Krishnappa Ravi <[email protected]> - this is done because there is no Activator instance for kotlin plugin since its invoked as a listener by staticanalyzer
The sample projects for testing kotlin plugin can be found here |
|
||
while(builder.getState() != Job.NONE) { | ||
Thread.sleep(3); | ||
} |
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.
Do we need to sleep or could we just Thread.yield()?
} | ||
} | ||
|
||
throw new ClassNotFoundException("Class " + className + " not found."); |
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.
Either use a CogniCryptException or IOException
import org.eclipse.jdt.core.JavaModelException; | ||
|
||
public interface IListener { | ||
void listen1(IProject ip); |
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.
Do we have better names?
} | ||
} | ||
catch (final JavaModelException e) { | ||
throw new ClassNotFoundException("Class " + className + " not found.", e); |
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.
same as above
Signed-off-by: Rakshit Krishnappa Ravi [email protected]