Skip to content

Commit

Permalink
Merge pull request #104 from codellm-devkit/issue-86-entrypoints
Browse files Browse the repository at this point in the history
Issue 86 entrypoints
  • Loading branch information
rahlk authored Feb 5, 2025
2 parents eb040d7 + 8a2be2d commit dbabfd3
Show file tree
Hide file tree
Showing 393 changed files with 45,658 additions and 182 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'eclipse'
id 'application'
id 'org.graalvm.buildtools.native' version '0.9.28'
id 'org.graalvm.buildtools.native' version '0.10.4'
}

// Get the version from the property file first
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.0.2
version=2.1.0-dev
487 changes: 311 additions & 176 deletions src/main/java/com/ibm/cldk/SymbolTable.java

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions src/main/java/com/ibm/cldk/entities/CRUDOperation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.ibm.cldk.entities;

import com.ibm.cldk.utils.annotations.NotImplemented;
import com.ibm.cldk.utils.annotations.Todo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@NotImplemented
public class CRUDOperation {
public enum OperationType {
CREATE,
READ,
UPDATE,
DELETE,
UNKNOWN
}

@Todo(comment = "Add more frameworks, and consider moving this outside because this may be generic.")
@NotImplemented
public enum JavaFramework {
JPA,
SPRING
}

private OperationType operationType;
private String targetTable;
private int lineNumber;
private int startPosition;
private int endPosition;

@NotImplemented
private String operationString;
@NotImplemented
private List<String> involvedFields;
@NotImplemented
private String condition;
@NotImplemented
private List<String> joinedTables;
@NotImplemented
private JavaFramework framework;
@NotImplemented
private boolean isBatchOperation = false;
}
3 changes: 3 additions & 0 deletions src/main/java/com/ibm/cldk/entities/Callable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
Expand All @@ -25,4 +26,6 @@ public class Callable {
private List<CallSite> callSites;
private List<VariableDeclaration> variableDeclarations;
private int cyclomaticComplexity;
private boolean isEntrypoint = false;
private List<CRUDOperation> crudOperations = null;
}
1 change: 1 addition & 0 deletions src/main/java/com/ibm/cldk/entities/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public class Type {
private Map<String, Callable> callableDeclarations;
private List<Field> fieldDeclarations;
private List<EnumConstant> enumConstants;
private boolean isEntrypointClass = false;
}
6 changes: 3 additions & 3 deletions src/main/java/com/ibm/cldk/utils/BuildProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,18 @@ public static boolean downloadLibraryDependencies(String projectPath, String pro
String[] mavenCommand = {MAVEN_CMD, "--no-transfer-progress", "-f", Paths.get(projectRoot, "pom.xml").toString(), "dependency:copy-dependencies", "-DoutputDirectory=" + libDownloadPath.toString()};
return buildWithTool(mavenCommand);
} else if (new File(projectRoot, "build.gradle").exists() || new File(projectRoot, "build.gradle.kts").exists()) {
if (GRADLE_CMD == null || !commandExists(new File(GRADLE_CMD)).getKey()) {
libDownloadPath = Paths.get(projectPath, "build", LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath();
libDownloadPath = Paths.get(projectPath, "build", LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath();
if (mkLibDepDirs(projectPath))
Log.debug("Dependencies found/created in " + libDownloadPath);
else
throw new IllegalStateException("Error creating library dependency directory in " + libDownloadPath);

if (GRADLE_CMD == null || !commandExists(new File(GRADLE_CMD)).getKey()) {
String msg = GRADLE_CMD == null ?
"Could not find Gradle or valid Gradle Wrapper" :
MessageFormat.format("Could not verify that {0} exists", GRADLE_CMD);
Log.error(msg);
throw new IllegalStateException("Unable to execute Maven command. " +
throw new IllegalStateException("Unable to execute Gradle command. " +
(GRADLE_CMD == null ?
"Could not find Gradle or valid Gradle Wrapper" :
"Attempt failed with message\n" + commandExists(new File(GRADLE_CMD)).getValue()
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/ibm/cldk/utils/annotations/NotImplemented.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ibm.cldk.utils.annotations;

import java.lang.annotation.*;

@Documented
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface NotImplemented {
String value() default "";
String since() default "";
String issue() default "";
String comment() default "";
}
12 changes: 12 additions & 0 deletions src/main/java/com/ibm/cldk/utils/annotations/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.ibm.cldk.utils.annotations;

import java.lang.annotation.*;

@Documented
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Todo {
String value() default "";
String issue() default "";
String comment() default "";
}
22 changes: 21 additions & 1 deletion src/test/java/com/ibm/cldk/CodeAnalyzerIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.ibm.cldk;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
Expand All @@ -15,8 +18,11 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.Map;
import java.util.Properties;

import static com.ibm.cldk.CodeAnalyzer.gson;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;

@Testcontainers
Expand Down Expand Up @@ -61,7 +67,8 @@ public class CodeAnalyzerIntegrationTest {
.withCommand("-c", "while true; do sleep 1; done")
.withCopyFileToContainer(MountableFile.forHostPath(Paths.get(System.getProperty("user.dir")).resolve("build/libs")), "/opt/jars")
.withCopyFileToContainer(MountableFile.forHostPath(Paths.get(System.getProperty("user.dir")).resolve("src/test/resources/test-applications/mvnw-corrupt-test")), "/test-applications/mvnw-corrupt-test")
.withCopyFileToContainer(MountableFile.forHostPath(Paths.get(System.getProperty("user.dir")).resolve("src/test/resources/test-applications/mvnw-working-test")), "/test-applications/mvnw-working-test");
.withCopyFileToContainer(MountableFile.forHostPath(Paths.get(System.getProperty("user.dir")).resolve("src/test/resources/test-applications/mvnw-working-test")), "/test-applications/mvnw-working-test")
.withCopyFileToContainer(MountableFile.forHostPath(Paths.get(System.getProperty("user.dir")).resolve("src/test/resources/test-applications/daytrader8")), "/test-applications/daytrader8");


@BeforeAll
Expand Down Expand Up @@ -145,4 +152,17 @@ void corruptMavenShouldNotTerminateWithErrorWhenMavenIsNotPresentUnlessAnalysisL
Assertions.assertEquals(1, runCodeAnalyzer.getExitCode());
Assertions.assertTrue(runCodeAnalyzer.getStderr().contains("java.lang.RuntimeException"));
}

@Test
void shouldBeAbleToGenerateAnalysisArtifactForDaytrader8() throws Exception {
var runCodeAnalyzerOnDaytrader8 = mavenContainer.execInContainer(
"java",
"-jar",
String.format("/opt/jars/codeanalyzer-%s.jar", codeanalyzerVersion),
"--input=/test-applications/daytrader8",
"--analysis-level=1"
);
Assertions.assertTrue(runCodeAnalyzerOnDaytrader8.getStdout().contains("\"is_entrypoint_class\": true"), "No entry point classes found");
Assertions.assertTrue(runCodeAnalyzerOnDaytrader8.getStdout().contains("\"is_entrypoint\": true"), "No entry point methods found");
}
}
11 changes: 11 additions & 0 deletions src/test/resources/test-applications/daytrader8/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.apt_generated/
/target/
/build/
/bin/
.classpath
.project
/.settings/
/wlp/
/openliberty/
.factorypath
.DS_Store
14 changes: 14 additions & 0 deletions src/test/resources/test-applications/daytrader8/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM open-liberty:full

COPY --chown=1001:0 src/main/liberty/config/server.xml /config/server.xml
COPY --chown=1001:0 src/main/liberty/config/bootstrap.properties /config/bootstrap.properties
COPY --chown=1001:0 target/io.openliberty.sample.daytrader8.war /config/apps/

#Derby
COPY --chown=1001:0 target/liberty/wlp/usr/shared/resources/DerbyLibs/derby-10.14.2.0.jar /opt/ol/wlp/usr/shared/resources/DerbyLibs/derby-10.14.2.0.jar
COPY --chown=1001:0 target/liberty/wlp/usr/shared/resources/data /opt/ol/wlp/usr/shared/resources/data

ENV MAX_USERS=1000
ENV MAX_QUOTES=500

#RUN configure.sh
21 changes: 21 additions & 0 deletions src/test/resources/test-applications/daytrader8/Dockerfile-db2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Create folder db2jars/ and copy db2jcc4.jar and db2jcc_license_cu.jar to it.
# Set Env below

FROM open-liberty:full

COPY --chown=1001:0 src/main/liberty/config/server.xml_db2 /config/server.xml
COPY --chown=1001:0 src/main/liberty/config/bootstrap.properties /config/bootstrap.properties
COPY --chown=1001:0 target/io.openliberty.sample.daytrader8.war /config/apps/

# DB2 JARS
COPY --chown=1001:0 /db2jars /opt/ol/wlp/usr/shared/resources/db2jars

ENV contextRoot=daytrader
ENV dbUser=
ENV dbPass=
ENV tradeDbHost=
ENV tradeDbPort=
ENV tradeDbName=


#RUN configure.sh
Loading

0 comments on commit dbabfd3

Please sign in to comment.