Skip to content
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

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from

Conversation

rakshitkr
Copy link
Contributor

Signed-off-by: Rakshit Krishnappa Ravi rakshitkrishnapparavi@gmail.com

Signed-off-by: Rakshit Krishnappa Ravi <rakshitkrishnapparavi@gmail.com>
Signed-off-by: Rakshit Krishnappa Ravi <rakshitkrishnapparavi@gmail.com>
Signed-off-by: Rakshit Krishnappa Ravi <rakshitkrishnapparavi@gmail.com>
Signed-off-by: Rakshit Krishnappa Ravi <rakshitkrishnapparavi@gmail.com>
…iggering Kotlin Compiler

Signed-off-by: Rakshit Krishnappa Ravi <rakshitkrishnapparavi@gmail.com>
…is uninstalled

Signed-off-by: Rakshit Krishnappa Ravi <rakshitkrishnapparavi@gmail.com>
Signed-off-by: Rakshit Krishnappa Ravi <rakshitkrishnapparavi@gmail.com>
Signed-off-by: Rakshit Krishnappa Ravi <rakshitkrishnapparavi@gmail.com>
if(ip.hasNature("org.eclipse.m2e.core.maven2Nature")) {
if(KotlinUtils.verifyKotlinDependency(javaProject)) {

System.out.println("Custom Builder started.");
Copy link
Member

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") {
Copy link
Member

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();
Copy link
Member

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.");
Copy link
Member

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())
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

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"?>
Copy link
Member

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,
Copy link
Member

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);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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

rakshitkr added a commit to rakshitkr/CogniCrypt that referenced this pull request Mar 12, 2020
Signed-off-by: Rakshit Krishnappa Ravi <rakshitkrishnapparavi@gmail.com>

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 <rakshitkrishnapparavi@gmail.com>
Signed-off-by: Rakshit Krishnappa Ravi <rakshitkrishnapparavi@gmail.com>

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 <rakshitkrishnapparavi@gmail.com>

- 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 <rakshitkrishnapparavi@gmail.com>

- this is done because there is no Activator instance for kotlin plugin since its invoked as a listener by staticanalyzer
@kruegers kruegers self-requested a review May 6, 2020 16:38
@rakshitkr
Copy link
Contributor Author

rakshitkr commented May 7, 2020

The sample projects for testing kotlin plugin can be found here


while(builder.getState() != Job.NONE) {
Thread.sleep(3);
}
Copy link
Contributor

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.");
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants