Skip to content

Commit a3aeb8c

Browse files
committed
run without copy
1 parent c9a6310 commit a3aeb8c

File tree

9 files changed

+115
-54
lines changed

9 files changed

+115
-54
lines changed

dockerfiles/swagger-petstore.dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ COPY ./dist/jacocoagent.jar .
55

66

77

8+
9+
COPY ./scripts/dockerize/data/additional_files/swagger-petstore/inflector.yaml .
10+
11+
12+
813
#ENV TOOL="undefined"
914
#ENV RUN="0"
1015

jdk_8_maven/cs/rest/original/swagger-petstore/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@
227227
</build>
228228
<dependencies>
229229
<!--MODIFIED-->
230+
<dependency>
231+
<groupId>org.glassfish.jersey.containers</groupId>
232+
<artifactId>jersey-container-servlet</artifactId>
233+
<version>2.41</version>
234+
</dependency>
230235
<dependency>
231236
<groupId>org.apache.tomcat.embed</groupId>
232237
<artifactId>tomcat-embed-core</artifactId>

jdk_8_maven/cs/rest/original/swagger-petstore/src/main/java/io/swagger/petstore/Main.java

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22

33
package io.swagger.petstore;
44

5+
import org.apache.catalina.Context;
6+
import org.apache.catalina.Wrapper;
57
import org.apache.catalina.startup.Tomcat;
6-
8+
import org.apache.catalina.webresources.DirResourceSet;
9+
import org.apache.catalina.webresources.JarResourceSet;
10+
import org.apache.catalina.webresources.StandardRoot;
11+
12+
import javax.servlet.Servlet;
13+
import javax.servlet.http.HttpServlet;
14+
import javax.servlet.http.HttpServletRequest;
15+
import javax.servlet.http.HttpServletResponse;
716
import java.io.File;
17+
import java.io.IOException;
18+
import java.io.InputStream;
19+
import java.io.OutputStream;
820
import java.net.URL;
921
import java.nio.file.Files;
22+
import java.security.CodeSource;
1023

1124
public class Main {
1225
Tomcat tomcat;
@@ -19,59 +32,37 @@ public void startServer(int port) throws Exception {
1932

2033
tomcat.setPort(port);
2134
tomcat.getConnector();
22-
URL webappUrl = Main.class.getClassLoader().getResource("webapp");
23-
24-
String webappDirLocation;
25-
26-
// Handle the case where the webapp is inside a JAR
27-
if (webappUrl.getProtocol().equals("jar")) {
28-
// Extract the JAR file path and the entry path
29-
String jarPath = webappUrl.getPath().substring(5, webappUrl.getPath().indexOf("!"));
30-
String entryPath = webappUrl.getPath().substring(webappUrl.getPath().indexOf("!") + 2);
31-
32-
// Create a temporary directory to extract the webapp resources
33-
File tempDir = Files.createTempDirectory("webapp").toFile();
34-
tempDir.deleteOnExit();
35-
36-
// Extract the JAR entry to the temporary directory
37-
try (java.util.jar.JarFile jar = new java.util.jar.JarFile(new File(jarPath))) {
38-
java.util.Enumeration<java.util.jar.JarEntry> entries = jar.entries();
39-
while (entries.hasMoreElements()) {
40-
java.util.jar.JarEntry entry = entries.nextElement();
41-
if (entry.getName().startsWith(entryPath) && !entry.isDirectory()) {
42-
File file = new File(tempDir, entry.getName().substring(entryPath.length()));
43-
file.getParentFile().mkdirs();
44-
try (java.io.InputStream is = jar.getInputStream(entry);
45-
java.io.FileOutputStream fos = new java.io.FileOutputStream(file)) {
46-
while (is.available() > 0) {
47-
fos.write(is.read());
48-
}
49-
}
50-
}
51-
}
52-
}
53-
System.out.println(tempDir);
54-
//also extract inflector.yaml
55-
try (java.io.InputStream is = Main.class.getClassLoader().getResourceAsStream("inflector.yaml")) {
56-
if (is != null) {
57-
File inflectorFile = new File("./", "inflector.yaml");
58-
try (java.io.FileOutputStream fos = new java.io.FileOutputStream(inflectorFile)) {
59-
byte[] buffer = new byte[1024];
60-
int bytesRead;
61-
while ((bytesRead = is.read(buffer)) != -1) {
62-
fos.write(buffer, 0, bytesRead);
63-
}
64-
}
65-
}
35+
36+
Context ctx = tomcat.addContext("", null);
37+
38+
StandardRoot resources = new StandardRoot(ctx);
39+
CodeSource src = Main.class.getProtectionDomain().getCodeSource();
40+
if (src != null) {
41+
URL jar = src.getLocation();
42+
String jarPath = new File(jar.toURI()).getAbsolutePath();
43+
if (jarPath.endsWith(".jar")) {
44+
resources.addJarResources(new JarResourceSet(resources, "/", jarPath, "/webapp"));
45+
}else {
46+
URL webappUrl = Main.class.getClassLoader().getResource("webapp");
47+
String webappDirLocation = new File(webappUrl.toURI()).getAbsolutePath();
48+
resources.addPreResources(new DirResourceSet(resources, "/", webappDirLocation, "/"));
6649
}
50+
}
51+
ctx.setResources(resources);
52+
ctx.addWelcomeFile("index.html");
6753

54+
// Swagger-Inflector / Jersey servlet
55+
Wrapper jerseyServlet = Tomcat.addServlet(ctx, "jersey-container-servlet",
56+
"org.glassfish.jersey.servlet.ServletContainer");
6857

69-
webappDirLocation = tempDir.getAbsolutePath();
70-
} else {
71-
// Handle the case where the webapp is in the filesystem
72-
webappDirLocation = new File(webappUrl.toURI()).getAbsolutePath();
73-
}
74-
tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
58+
jerseyServlet.addInitParameter("javax.ws.rs.Application", "io.swagger.oas.inflector.OpenAPIInflector");
59+
jerseyServlet.setLoadOnStartup(1);
60+
61+
ctx.addServletMappingDecoded("/api/*", "jersey-container-servlet");
62+
63+
Wrapper defaultServlet = Tomcat.addServlet(ctx, "default", "org.apache.catalina.servlets.DefaultServlet");
64+
defaultServlet.setLoadOnStartup(1);
65+
ctx.addServletMappingDecoded("/", "default");
7566

7667
System.out.println("Swagger Petstore running at http://localhost:" + port);
7768
tomcat.start();

jdk_8_maven/em/external/rest/swagger-petstore/src/main/java/em/external/swagger/petstore/ExternalEvoMasterController.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
import org.evomaster.client.java.controller.problem.RestProblem;
1010
import org.evomaster.client.java.sql.DbSpecification;
1111

12+
import java.io.InputStream;
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
15+
import java.nio.file.Paths;
16+
import java.nio.file.StandardCopyOption;
1217
import java.util.List;
1318

1419
public class ExternalEvoMasterController extends ExternalSutController {
@@ -54,6 +59,7 @@ public static void main(String[] args) {
5459
private final int timeoutSeconds;
5560
private final int sutPort;
5661
private String jarLocation;
62+
private final String CONFIG_FILE = "inflector.yaml";
5763

5864
private List<DbSpecification> dbSpecification;
5965

@@ -79,6 +85,7 @@ public ExternalEvoMasterController(
7985
this.timeoutSeconds = timeoutSeconds;
8086
setControllerPort(controllerPort);
8187
setJavaCommand(command);
88+
createConfigurationFile();
8289
}
8390

8491
@Override
@@ -88,9 +95,30 @@ public String[] getInputParameters() {
8895
};
8996
}
9097

98+
private void createConfigurationFile() {
99+
100+
//save config to same folder of JAR file
101+
Path path = getConfigPath();
102+
103+
try(InputStream is = this.getClass().getResourceAsStream("/"+ CONFIG_FILE )){
104+
Files.copy(is, path, StandardCopyOption.REPLACE_EXISTING);
105+
} catch (Exception e){
106+
throw new RuntimeException(e);
107+
}
108+
}
109+
110+
private Path getConfigPath(){
111+
return Paths.get(jarLocation)
112+
.toAbsolutePath()
113+
.getParent()
114+
.resolve(CONFIG_FILE)
115+
.normalize();
116+
}
117+
91118
@Override
92119
public String[] getJVMParameters() {
93120
return new String[]{
121+
"-Dconfig="+getConfigPath().toAbsolutePath().toString(),
94122
};
95123
}
96124

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
controllerPackage: io.swagger.petstore.controller
2+
modelPackage: io.swagger.petstore.model
3+
swaggerUrl: webapp/openapi.yaml
4+
5+
exposedSpecOptions:
6+
useOriginalNotParsed: true
7+
8+
entityProcessors:
9+
- json
10+
- yaml
11+
- xml
12+
13+
swaggerProcessors:
14+
- io.swagger.petstore.utils.HandleAuthUrlProcessor
15+
16+
rootPath: /api
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
controllerPackage: io.swagger.petstore.controller
2+
modelPackage: io.swagger.petstore.model
3+
swaggerUrl: webapp/openapi.yaml
4+
5+
exposedSpecOptions:
6+
useOriginalNotParsed: true
7+
8+
entityProcessors:
9+
- json
10+
- yaml
11+
- xml
12+
13+
swaggerProcessors:
14+
- io.swagger.petstore.utils.HandleAuthUrlProcessor
15+
16+
rootPath: /api

scripts/dockerize/data/sut.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ spring-rest-example,TRUE,"","--server.port=8080 --spring.datasource.username=roo
3030
erc20-rest-service,TRUE,"",--server.port=8080,http://localhost:8080/v2/api-docs,http://localhost:8080,FALSE,,,,,,FALSE,FALSE,
3131
spring-actuator-demo,TRUE,"",--server.port=8080,http://localhost:8080/v3/api-docs,http://localhost:8080,FALSE,,,,,,FALSE,FALSE,
3232
webgoat,TRUE,"-Drunning.in.docker=true","--webgoat.port=8080 --webwolf.port=8081 --server.address=""0.0.0.0"" --spring.profiles.active=dev --spring.datasource.driver-class-name=org.h2.Driver --spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect --spring.jpa.properties.jakarta.persistence.schema-generation.scripts.action=none --spring.sql.init.mode=never --spring.datasource.url=""jdbc:h2:file:./test"" --spring.datasource.username=sa --spring.datasource.password",http://localhost:8080/WebGoat/v3/api-docs,http://localhost:8080,TRUE,,,,,,FALSE,FALSE,
33-
swagger-petstore,TRUE,"","8080",http://localhost:8080//api/v3/openapi.json,http://localhost:8080,FALSE,,,,,,FALSE,FALSE,
33+
swagger-petstore,TRUE,"","8080",http://localhost:8080//api/v3/openapi.json,http://localhost:8080,TRUE,,,,,,FALSE,FALSE,

statistics/data.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TRUE,scout-api,REST,Java,JDK 8,Maven,93,9736,H2,MIT,49,TRUE,https://github.com/m
2727
TRUE,spring-actuator-demo,REST,Java,JDK 8,Maven,5,117,,UNDEFINED,2,TRUE,https://github.com/callicoder/spring-boot-actuator-demo
2828
TRUE,spring-batch-rest,REST,Java,JDK 8,Maven,65,3668,,Apache,5,FALSE,https://github.com/chrisgleissner/spring-batch-rest
2929
TRUE,spring-rest-example,REST,Java,JDK 17,Maven,32,1426,MySQL,MIT,9,FALSE,https://github.com/phantasmicmeans/spring-boot-restful-api-example
30-
TRUE,swagger-petstore,REST,Java,JDK 8,Maven,23,1640,,Apache,19,FALSE,https://github.com/swagger-api/swagger-petstore
30+
TRUE,swagger-petstore,REST,Java,JDK 8,Maven,23,1631,,Apache,19,FALSE,https://github.com/swagger-api/swagger-petstore
3131
TRUE,genome-nexus,REST,Java,JDK 8,Maven,405,30004,MongoDB,MIT,23,FALSE,https://github.com/genome-nexus/genome-nexus
3232
TRUE,market,REST,Java,JDK 11,Maven,124,9861,H2,MIT,13,TRUE,https://github.com/aleksey-lukyanets/market
3333
TRUE,petclinic-graphql,GraphQL,Java,JDK 8,Maven,89,5212,PostgreSQL,Apache,15,FALSE,https://github.com/spring-petclinic/spring-petclinic-graphql

statistics/table_emb.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
|__bibliothek__|REST|2176|33|8|Java|JDK 17|Gradle|MongoDB||
2828
|__restcountries__|REST|1977|24|22|Java|JDK 8|Maven|||
2929
|__reservations-api__|REST|1853|39|7|Java|JDK 11|Gradle|MongoDB|&check;|
30-
|__swagger-petstore__|REST|1640|23|19|Java|JDK 8|Maven|||
30+
|__swagger-petstore__|REST|1631|23|19|Java|JDK 8|Maven|||
3131
|__session-service__|REST|1471|15|8|Java|JDK 8|Maven|MongoDB||
3232
|__spring-rest-example__|REST|1426|32|9|Java|JDK 17|Maven|MySQL||
3333
|__erc20-rest-service__|REST|1378|7|13|Java|JDK 8|Gradle|||

0 commit comments

Comments
 (0)