Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Java 17 Dev Container",
"image": "mcr.microsoft.com/devcontainers/java:17",
"features": {
"ghcr.io/devcontainers/features/java:1": {
"version": "none",
"installGradle": "false",
"installMaven": "true"
}
},
"settings": {},
"extensions": []
}
6 changes: 6 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 1.8
distribution: 'temurin'
java-version: '17'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 1.8
distribution: 'temurin'
java-version: '17'
- name: Build with Maven
run: mvn -B package --file pom.xml
50 changes: 8 additions & 42 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,9 @@
<version>4.0.0</version>
<build>
<plugins>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>hack-binary</id>
<phase>clean</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${JAVA_HOME}/lib/tools.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>jdk1.8.0</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -44,20 +23,7 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>windows-profile</id>
<properties>
<toolsjar>${JAVA_HOME}/lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>mac-profile</id>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
</profiles>
<!-- obsolete profiles removed -->
<dependencies>
<dependency>
<groupId>junit</groupId>
Expand All @@ -73,8 +39,8 @@
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>

6 changes: 3 additions & 3 deletions nb-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ You can copy and paste the single properties, into the pom.xml file and the IDE
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.jdkPlatform>JDK_1.8</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>
<netbeans.hint.jdkPlatform>JDK_17</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>
62 changes: 25 additions & 37 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,30 @@
<artifactId>hellofunction</artifactId>
<version>6.0.1</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<!--
<repository>
<id>cagatay-gurturk</id>
<url>http://maven.cagataygurturk.com/releases</url>
</repository>
</repository> -->
<!-- <repository>
<id>repo.eclipse.org</id>
<name>Eclipse Repository - Releases</name>
<url>https://repo.eclipse.org/content/repositories/eclipse-staging/</url>
</repository>-->
</repositories>
<profiles>
<profile>
<id>windows-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<file>
<exists>${JAVA_HOME}/lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${JAVA_HOME}/lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>mac-profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
</profiles>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.911</version>
<version>1.12.789</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -62,7 +38,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-lambda</artifactId>
<version>1.11.893</version>
<version>1.12.789</version>
</dependency>

<dependency>
Expand All @@ -75,13 +51,13 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.0</version>
<version>2.15.4</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.0</version>
<version>2.15.4</version>
</dependency>

<!-- -->
Expand All @@ -93,13 +69,14 @@
</dependency>-->
<!-- -->

<!--
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>(,3.13.0]</version> <!-- version 3.13.50 is missing a dep, >= 3.13.100 looks for files on drive and not in memory -->
<!-- see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=541269 -->
<version>3.42.0</version>
</dependency>

-->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -140,7 +117,18 @@
</arguments>
</configuration>
</plugin>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<systemPropertyVariables>
<run.mycode.debug>true</run.mycode.debug>
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
46 changes: 30 additions & 16 deletions src/main/java/run/myCode/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import run.myCode.compiler.InMemoryJavaFileObject;
import java.util.Base64;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import run.myCode.compiler.InMemoryJavaFileObject;

/**
*
Expand All @@ -24,19 +26,31 @@ public static List<InMemoryJavaFileObject> createSourceFileObjects(CompileReques

List<InMemoryJavaFileObject> objects = new ArrayList<>(req.getSourceFiles().size());

// Pull all of the source code files in the request
req.getSourceFiles().forEach((f) -> {
String contents = "";
for (String s : f.getContents()) {
// Save the file's contents
contents += s + '\n';
}

// Add them to a list of files
objects.add(new InMemoryJavaFileObject(f.getName(), contents));
});
return objects;
}
// Pull all of the source code files in the request
req.getSourceFiles().forEach((f) -> {
String contents = "";
for (String s : f.getContents()) {
// Save the file's contents
contents += s + '\n';
}

String fileName = f.getName();
// If the source declares a package, prefix the file name with its
// package path so the compiler's file manager can resolve the
// class correctly. ECJ expects the source path to mirror the
// package declaration, otherwise it will try to locate the file on
// disk and fail with "File ... is missing".
Pattern pkgPattern = Pattern.compile("(?m)^\\s*package\\s+([\\w\\.]+)\\s*;");
Matcher m = pkgPattern.matcher(contents);
if (m.find()) {
fileName = m.group(1).replace('.', '/') + "/" + fileName;
}

// Add them to a list of files
objects.add(new InMemoryJavaFileObject(fileName, contents));
});
return objects;
}

public static void saveData(DataRequest data) {
if (data == null) {
Expand Down
34 changes: 21 additions & 13 deletions src/main/java/run/myCode/compiler/FromMemoryClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import java.util.List;
import java.util.Map;

public class FromMemoryClassLoader extends ClassLoader {

private final Map<String, MemoryByteCode> m = new HashMap<>();
private final ClassLoader parent;
public class FromMemoryClassLoader extends ClassLoader {

private static final boolean DEBUG = Boolean.getBoolean("run.mycode.debug");

private final Map<String, MemoryByteCode> m = new HashMap<>();
private final ClassLoader parent;

public FromMemoryClassLoader(ClassLoader parent) {
this.parent = parent;
Expand All @@ -20,13 +22,16 @@ public Class<?> findClass(String name) throws ClassNotFoundException {
try {
// System.out.println("Class search:" + name);
MemoryByteCode mbc = m.get(name);
if (mbc == null) {
mbc = m.get(name.replace(".", "/"));
if (mbc == null) {
return super.findClass(name);
}
}
return defineClass(name, mbc.getBytes(), 0, mbc.getBytes().length);
if (mbc == null) {
mbc = m.get(name.replace(".", "/"));
if (mbc == null) {
return super.findClass(name);
}
}
if (DEBUG) {
System.out.println("Loading in-memory class " + name);
}
return defineClass(name, mbc.getBytes(), 0, mbc.getBytes().length);
} catch (ClassNotFoundException e) {
// System.err.println("Could not find: " + name);
if (this.parent != null) {
Expand All @@ -46,8 +51,11 @@ public Class<?> findClass(String name) throws ClassNotFoundException {
public void addClass(String name, MemoryByteCode mbc) {
// System.err.println("Added class: " + name);
// System.out.println("Added class:" + name);
m.put(name, mbc);
}
m.put(name, mbc);
if (DEBUG) {
System.out.println("Added in-memory class " + name);
}
}

public List<String> getClassNames() {
return new ArrayList(m.keySet());
Expand Down
Loading
Loading