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

Issue #10055 - fix core deploy with --dry-run #10056

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,12 @@ else if (properties.size() > 0)
// TODO module path

for (Prop property : environment.getProperties())
cmd.addArg(property.key + "=" + property.value);
{
String value = property.value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this ever be a genuine environment variable that should appear unquoted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, as the environment should be the properties after expansion.

if (isDryRun() && value != null && value.contains("$"))
value = "'" + value + "'";
cmd.addArg(property.key + "=" + value);
Comment on lines +698 to +700
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit arbitrary. What if the value contains space? what if the value contains ' or "? Isn't there a method already that checks if a string needs to be quoted and then quotes it correctly, perhaps escaping quote characters?

}

for (Path xmlFile : environment.getXmlFiles())
cmd.addArg(xmlFile.toAbsolutePath().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1457,4 +1457,59 @@ public void testVirtualThreadPool() throws Exception
}
}
}

@Test
public void testStaticFile() throws Exception
{
Path jettyBase = newTestJettyBaseDirectory();
String jettyVersion = System.getProperty("jettyVersion");
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
.jettyVersion(jettyVersion)
.jettyBase(jettyBase)
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
.build();

try (JettyHomeTester.Run run1 = distribution.start("--approve-all-licenses", "--add-modules=http,core-deploy"))
{
assertTrue(run1.awaitFor(START_TIMEOUT, TimeUnit.SECONDS));
assertEquals(0, run1.getExitValue());

// Ensure .well-known directory exists.
Path webappsDir = distribution.getJettyBase().resolve("webapps");
assertTrue(Files.exists(webappsDir));
Files.createDirectory(webappsDir.resolve("ROOT"));

// Write content to a file in the ROOT directory.
String testFileContent = "hello world " + UUID.randomUUID();
File testFile = webappsDir.resolve("ROOT/index.html").toFile();
assertTrue(testFile.createNewFile());
testFile.deleteOnExit();
try (FileWriter fileWriter = new FileWriter(testFile))
{
fileWriter.write(testFileContent);
}

try (JettyHomeTester.Run run2 = distribution.start("--dry-run"))
{
run2.awaitFor(START_TIMEOUT, TimeUnit.SECONDS);
Queue<String> logs = run2.getLogs();
assertThat(logs.size(), equalTo(1));
String log = logs.poll();
System.err.println(log);
assertThat(log, containsString("contextHandlerClass='org.eclipse.jetty.server.handler.ResourceHandler$ResourceContext'"));
}

int port = distribution.freePort();
try (JettyHomeTester.Run run2 = distribution.start("jetty.http.port=" + port))
{
assertTrue(run2.awaitConsoleLogsFor("Started oejs.Server@", START_TIMEOUT, TimeUnit.SECONDS));

// Test we can access the static index.html file.
startHttpClient();
ContentResponse response = client.GET("http://localhost:" + port + "/");
assertThat(response.getStatus(), is(HttpStatus.OK_200));
assertThat(response.getContentAsString(), is(testFileContent));
}
}
}
}