Skip to content

Commit dbabfd3

Browse files
authored
Merge pull request #104 from codellm-devkit/issue-86-entrypoints
Issue 86 entrypoints
2 parents eb040d7 + 8a2be2d commit dbabfd3

File tree

393 files changed

+45658
-182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

393 files changed

+45658
-182
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ plugins {
1515
// Apply the application plugin to add support for building a CLI application in Java.
1616
id 'eclipse'
1717
id 'application'
18-
id 'org.graalvm.buildtools.native' version '0.9.28'
18+
id 'org.graalvm.buildtools.native' version '0.10.4'
1919
}
2020

2121
// Get the version from the property file first

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=2.0.2
1+
version=2.1.0-dev

src/main/java/com/ibm/cldk/SymbolTable.java

Lines changed: 311 additions & 176 deletions
Large diffs are not rendered by default.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.ibm.cldk.entities;
2+
3+
import com.ibm.cldk.utils.annotations.NotImplemented;
4+
import com.ibm.cldk.utils.annotations.Todo;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
import java.util.List;
9+
10+
@Data
11+
@NoArgsConstructor
12+
@AllArgsConstructor
13+
@NotImplemented
14+
public class CRUDOperation {
15+
public enum OperationType {
16+
CREATE,
17+
READ,
18+
UPDATE,
19+
DELETE,
20+
UNKNOWN
21+
}
22+
23+
@Todo(comment = "Add more frameworks, and consider moving this outside because this may be generic.")
24+
@NotImplemented
25+
public enum JavaFramework {
26+
JPA,
27+
SPRING
28+
}
29+
30+
private OperationType operationType;
31+
private String targetTable;
32+
private int lineNumber;
33+
private int startPosition;
34+
private int endPosition;
35+
36+
@NotImplemented
37+
private String operationString;
38+
@NotImplemented
39+
private List<String> involvedFields;
40+
@NotImplemented
41+
private String condition;
42+
@NotImplemented
43+
private List<String> joinedTables;
44+
@NotImplemented
45+
private JavaFramework framework;
46+
@NotImplemented
47+
private boolean isBatchOperation = false;
48+
}

src/main/java/com/ibm/cldk/entities/Callable.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import lombok.Data;
44

5+
import java.util.ArrayList;
56
import java.util.List;
67

78
@Data
@@ -25,4 +26,6 @@ public class Callable {
2526
private List<CallSite> callSites;
2627
private List<VariableDeclaration> variableDeclarations;
2728
private int cyclomaticComplexity;
29+
private boolean isEntrypoint = false;
30+
private List<CRUDOperation> crudOperations = null;
2831
}

src/main/java/com/ibm/cldk/entities/Type.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ public class Type {
2525
private Map<String, Callable> callableDeclarations;
2626
private List<Field> fieldDeclarations;
2727
private List<EnumConstant> enumConstants;
28+
private boolean isEntrypointClass = false;
2829
}

src/main/java/com/ibm/cldk/utils/BuildProject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,18 @@ public static boolean downloadLibraryDependencies(String projectPath, String pro
234234
String[] mavenCommand = {MAVEN_CMD, "--no-transfer-progress", "-f", Paths.get(projectRoot, "pom.xml").toString(), "dependency:copy-dependencies", "-DoutputDirectory=" + libDownloadPath.toString()};
235235
return buildWithTool(mavenCommand);
236236
} else if (new File(projectRoot, "build.gradle").exists() || new File(projectRoot, "build.gradle.kts").exists()) {
237-
if (GRADLE_CMD == null || !commandExists(new File(GRADLE_CMD)).getKey()) {
238-
libDownloadPath = Paths.get(projectPath, "build", LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath();
237+
libDownloadPath = Paths.get(projectPath, "build", LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath();
239238
if (mkLibDepDirs(projectPath))
240239
Log.debug("Dependencies found/created in " + libDownloadPath);
241240
else
242241
throw new IllegalStateException("Error creating library dependency directory in " + libDownloadPath);
243242

243+
if (GRADLE_CMD == null || !commandExists(new File(GRADLE_CMD)).getKey()) {
244244
String msg = GRADLE_CMD == null ?
245245
"Could not find Gradle or valid Gradle Wrapper" :
246246
MessageFormat.format("Could not verify that {0} exists", GRADLE_CMD);
247247
Log.error(msg);
248-
throw new IllegalStateException("Unable to execute Maven command. " +
248+
throw new IllegalStateException("Unable to execute Gradle command. " +
249249
(GRADLE_CMD == null ?
250250
"Could not find Gradle or valid Gradle Wrapper" :
251251
"Attempt failed with message\n" + commandExists(new File(GRADLE_CMD)).getValue()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ibm.cldk.utils.annotations;
2+
3+
import java.lang.annotation.*;
4+
5+
@Documented
6+
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
7+
@Retention(RetentionPolicy.RUNTIME)
8+
public @interface NotImplemented {
9+
String value() default "";
10+
String since() default "";
11+
String issue() default "";
12+
String comment() default "";
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.ibm.cldk.utils.annotations;
2+
3+
import java.lang.annotation.*;
4+
5+
@Documented
6+
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
7+
@Retention(RetentionPolicy.RUNTIME)
8+
public @interface Todo {
9+
String value() default "";
10+
String issue() default "";
11+
String comment() default "";
12+
}

src/test/java/com/ibm/cldk/CodeAnalyzerIntegrationTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.ibm.cldk;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonObject;
36
import org.junit.jupiter.api.BeforeAll;
47
import org.junit.jupiter.api.Test;
58
import org.junit.jupiter.api.Assertions;
@@ -15,8 +18,11 @@
1518
import java.nio.file.Path;
1619
import java.nio.file.Paths;
1720
import java.text.MessageFormat;
21+
import java.util.Map;
1822
import java.util.Properties;
1923

24+
import static com.ibm.cldk.CodeAnalyzer.gson;
25+
import static org.junit.Assert.assertTrue;
2026
import static org.junit.jupiter.api.Assertions.assertThrows;
2127

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

6673

6774
@BeforeAll
@@ -145,4 +152,17 @@ void corruptMavenShouldNotTerminateWithErrorWhenMavenIsNotPresentUnlessAnalysisL
145152
Assertions.assertEquals(1, runCodeAnalyzer.getExitCode());
146153
Assertions.assertTrue(runCodeAnalyzer.getStderr().contains("java.lang.RuntimeException"));
147154
}
155+
156+
@Test
157+
void shouldBeAbleToGenerateAnalysisArtifactForDaytrader8() throws Exception {
158+
var runCodeAnalyzerOnDaytrader8 = mavenContainer.execInContainer(
159+
"java",
160+
"-jar",
161+
String.format("/opt/jars/codeanalyzer-%s.jar", codeanalyzerVersion),
162+
"--input=/test-applications/daytrader8",
163+
"--analysis-level=1"
164+
);
165+
Assertions.assertTrue(runCodeAnalyzerOnDaytrader8.getStdout().contains("\"is_entrypoint_class\": true"), "No entry point classes found");
166+
Assertions.assertTrue(runCodeAnalyzerOnDaytrader8.getStdout().contains("\"is_entrypoint\": true"), "No entry point methods found");
167+
}
148168
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/.apt_generated/
2+
/target/
3+
/build/
4+
/bin/
5+
.classpath
6+
.project
7+
/.settings/
8+
/wlp/
9+
/openliberty/
10+
.factorypath
11+
.DS_Store
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM open-liberty:full
2+
3+
COPY --chown=1001:0 src/main/liberty/config/server.xml /config/server.xml
4+
COPY --chown=1001:0 src/main/liberty/config/bootstrap.properties /config/bootstrap.properties
5+
COPY --chown=1001:0 target/io.openliberty.sample.daytrader8.war /config/apps/
6+
7+
#Derby
8+
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
9+
COPY --chown=1001:0 target/liberty/wlp/usr/shared/resources/data /opt/ol/wlp/usr/shared/resources/data
10+
11+
ENV MAX_USERS=1000
12+
ENV MAX_QUOTES=500
13+
14+
#RUN configure.sh
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Create folder db2jars/ and copy db2jcc4.jar and db2jcc_license_cu.jar to it.
2+
# Set Env below
3+
4+
FROM open-liberty:full
5+
6+
COPY --chown=1001:0 src/main/liberty/config/server.xml_db2 /config/server.xml
7+
COPY --chown=1001:0 src/main/liberty/config/bootstrap.properties /config/bootstrap.properties
8+
COPY --chown=1001:0 target/io.openliberty.sample.daytrader8.war /config/apps/
9+
10+
# DB2 JARS
11+
COPY --chown=1001:0 /db2jars /opt/ol/wlp/usr/shared/resources/db2jars
12+
13+
ENV contextRoot=daytrader
14+
ENV dbUser=
15+
ENV dbPass=
16+
ENV tradeDbHost=
17+
ENV tradeDbPort=
18+
ENV tradeDbName=
19+
20+
21+
#RUN configure.sh

0 commit comments

Comments
 (0)