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
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 3 additions & 26 deletions plugins/de.cognicrypt.core/src/de/cognicrypt/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
Expand All @@ -27,12 +28,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
Expand All @@ -55,7 +52,9 @@
import org.ini4j.InvalidFileFormatException;
import org.ini4j.Wini;
import org.osgi.framework.Bundle;

import com.google.common.base.CharMatcher;

import crypto.analysis.CrySLRulesetSelector.RuleFormat;
import crypto.cryslhandler.CrySLModelReader;
import crypto.rules.CrySLRule;
Expand Down Expand Up @@ -98,28 +97,6 @@ public static List<IProject> complileListOfJavaProjectsInWorkspace() {
return javaProjects;
}

public static IResource findClassByName(final String className, final IProject currentProject) throws ClassNotFoundException {
try {
for (final IPackageFragment l : JavaCore.create(currentProject).getPackageFragments()) {
for (final ICompilationUnit cu : l.getCompilationUnits()) {
final IJavaElement cuResource = JavaCore.create(cu.getCorrespondingResource());
String name = cuResource.getParent().getElementName() + "." + cuResource.getElementName();

if (name.startsWith(".")) {
name = name.substring(1);
}
if (name.startsWith(className)) {
return cu.getCorrespondingResource();
}
}
}
}
catch (final JavaModelException e) {
throw new ClassNotFoundException("Class " + className + " not found.", e);
}
throw new ClassNotFoundException("Class " + className + " not found.");
}

/**
* This method returns the currently open editor as an {@link IEditorPart}.
*
Expand Down
12 changes: 12 additions & 0 deletions plugins/de.cognicrypt.staticanalyzer.kotlin/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/org.jetbrains.kotlin.core.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
34 changes: 34 additions & 0 deletions plugins/de.cognicrypt.staticanalyzer.kotlin/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>de.cognicrypt.staticanalyzer.kotlin</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
18 changes: 18 additions & 0 deletions plugins/de.cognicrypt.staticanalyzer.kotlin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CogniCrypt Static Analyzer for Kotlin
Bundle-SymbolicName: de.cognicrypt.staticanalyzer.kotlin
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: de.cognicrypt.staticanalyzer.kotlin.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: de.cognicrypt.staticanalyzer.kotlin
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
lib/
Require-Bundle: org.eclipse.jdt.core,
org.eclipse.m2e.maven.runtime,
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.ui,
org.jetbrains.kotlin.core;bundle-version="0.8.19";resolution:=optional
Export-Package: de.cognicrypt.staticanalyzer.kotlin.utilities
7 changes: 7 additions & 0 deletions plugins/de.cognicrypt.staticanalyzer.kotlin/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
src/,\
lib/
source.. = src/
Binary file not shown.
152 changes: 152 additions & 0 deletions plugins/de.cognicrypt.staticanalyzer.kotlin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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>de.cognicrypt</groupId>
<artifactId>de.cognicrypt.staticanalyzer.kotlin</artifactId>
<packaging>eclipse-plugin</packaging>
<parent>
<groupId>de.cognicrypt</groupId>
<artifactId>de.cognicrypt.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<reportsDirectory>../../shippable/testresults</reportsDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>compiletests</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.eclipse.tycho</groupId>
<artifactId>
tycho-packaging-plugin
</artifactId>
<versionRange>
[0.26.0,)
</versionRange>
<goals>
<goal>build-qualifier</goal>
<goal>validate-id</goal>
<goal>validate-version</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.eclipse.tycho</groupId>
<artifactId>
tycho-compiler-plugin
</artifactId>
<versionRange>
[0.26.0,)
</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<versionRange>
[0.26.0,)
</versionRange>
<goals>
<goal>test-compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<versionRange>
[0.26.0,)
</versionRange>
<goals>
<goal>test</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package de.cognicrypt.staticanalyzer.kotlin;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {

// The plug-in ID
public static final String PLUGIN_ID = "de.cognicrypt.staticanalyzer.kotlin"; //$NON-NLS-1$

// The shared instance
private static Activator plugin;

/**
* The constructor
*/
public Activator() {
}

@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}

@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}

/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}

private void log(final int severity, final String message, final Exception ex) {
getLog().log(new Status(severity, Activator.PLUGIN_ID, message, ex));
}

public void logError(final Exception ex) {
logError(ex, ex.getMessage());
}

public void logError(final Exception ex, final String message) {
log(IStatus.ERROR, message, ex);
}

public void logError(final String message) {
log(IStatus.ERROR, message, null);
}

public void logInfo(final String message) {
log(IStatus.INFO, message, null);
}
}