Skip to content

Commit

Permalink
Fix #6114 Deploy symlink webapps
Browse files Browse the repository at this point in the history
Use Path.toRealPath rather than getCanonicalPath in the Scanner
Make following symlinks configurable

Signed-off-by: Greg Wilkins <[email protected]>
  • Loading branch information
gregw committed May 24, 2021
1 parent 7252367 commit 340213f
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public abstract class ScanningAppProvider extends ContainerLifeCycle implements
private final List<Resource> _monitored = new CopyOnWriteArrayList<>();
private int _scanInterval = 10;
private Scanner _scanner;
private boolean _followSymlinks;

private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener()
{
Expand Down Expand Up @@ -81,6 +82,16 @@ protected ScanningAppProvider(FilenameFilter filter)
addBean(_appMap);
}

public boolean isFollowSymlinks()
{
return _followSymlinks;
}

public void setFollowSymlinks(boolean followSymlinks)
{
_followSymlinks = followSymlinks;
}

protected void setFilenameFilter(FilenameFilter filter)
{
if (isRunning())
Expand Down Expand Up @@ -128,7 +139,7 @@ protected void doStart() throws Exception
LOG.warn("Does not exist: {}", resource);
}

_scanner = new Scanner();
_scanner = new Scanner(null, _followSymlinks);
_scanner.setScanDirs(files);
_scanner.setScanInterval(_scanInterval);
_scanner.setFilenameFilter(_filenameFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ protected void fileChanged(String filename) throws Exception
{
//if a .xml file exists for it, then redeploy that instead
File xml = new File(parent, xmlname);
super.fileChanged(xml.getCanonicalPath());
super.fileChanged(xml.getPath());
return;
}

Expand All @@ -384,7 +384,7 @@ protected void fileChanged(String filename) throws Exception
{
//if a .XML file exists for it, then redeploy that instead
File xml = new File(parent, xmlname);
super.fileChanged(xml.getCanonicalPath());
super.fileChanged(xml.getPath());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.jetty.deploy.providers;

import java.io.File;
import java.net.URL;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -35,7 +34,6 @@
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -45,7 +43,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.condition.OS.LINUX;
import static org.junit.jupiter.api.condition.OS.MAC;

@ExtendWith(WorkDirExtension.class)
public class WebAppProviderTest
Expand Down Expand Up @@ -95,7 +92,6 @@ public void teardownEnvironment() throws Exception
jetty.stop();
}

@Disabled("See issue #1200")
@Test
public void testStartupContext()
{
Expand All @@ -109,10 +105,9 @@ public void testStartupContext()
assertDirNotExists("root of work directory", workDir, "jsp");

// Test for correct behaviour
assertTrue(hasJettyGeneratedPath(workDir, "foo.war"), "Should have generated directory in work directory: " + workDir);
assertTrue(hasJettyGeneratedPath(workDir, "foo_war"), "Should have generated directory in work directory: " + workDir);
}

@Disabled("See issue #1200")
@Test
public void testStartupSymlinkContext()
{
Expand All @@ -128,7 +123,7 @@ public void testStartupSymlinkContext()

// Test for expected work/temp directory behaviour
File workDir = jetty.getJettyDir("workish");
assertTrue(hasJettyGeneratedPath(workDir, "bar.war"), "Should have generated directory in work directory: " + workDir);
assertTrue(hasJettyGeneratedPath(workDir, "bar_war"), "Should have generated directory in work directory: " + workDir);
}

@Test
Expand Down
1 change: 1 addition & 0 deletions jetty-deploy/src/test/resources/jetty-deploy-wars.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Set name="monitoredDirName"><SystemProperty name="jetty.home" />/webapps</Set>
<Set name="scanInterval">1</Set>
<Set name="tempDir"><Property name="jetty.home" default="target" />/workish</Set>
<Set name="followSymlinks">false</Set>
</New>
</Item>
</Array>
Expand Down
Loading

0 comments on commit 340213f

Please sign in to comment.