diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java index 83ad977209d5..40e353998d09 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java @@ -20,9 +20,11 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import org.apache.maven.artifact.Artifact; +import org.eclipse.jetty.ee10.webapp.WebAppContext; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.resource.MountedPathResource; import org.eclipse.jetty.util.resource.Resource; @@ -45,9 +47,10 @@ public OverlayManager(WarPluginInfo warPlugin) public void applyOverlays(MavenWebAppContext webApp) throws IOException { + Objects.requireNonNull(webApp); List resourceBases = new ArrayList(); - for (Overlay o : getOverlays()) + for (Overlay o : getOverlays(webApp)) { //can refer to the current project in list of overlays for ordering purposes if (o.getConfig() != null && o.getConfig().isCurrentProject() && webApp.getBaseResource().exists()) @@ -56,7 +59,7 @@ public void applyOverlays(MavenWebAppContext webApp) throws IOException continue; } //add in the selectively unpacked overlay in the correct order to the webapp's resource base - resourceBases.add(unpackOverlay(o)); + resourceBases.add(unpackOverlay(webApp, o)); } if (!resourceBases.contains(webApp.getBaseResource()) && webApp.getBaseResource().exists()) @@ -73,7 +76,7 @@ public void applyOverlays(MavenWebAppContext webApp) throws IOException /** * Generate an ordered list of overlays */ - protected List getOverlays() + protected List getOverlays(WebAppContext webApp) { Set matchedWarArtifacts = new HashSet(); List overlays = new ArrayList(); @@ -98,7 +101,7 @@ protected List getOverlays() if (a != null) { matchedWarArtifacts.add(a); - Resource resource = ResourceFactory.root().newJarFileResource(a.getFile().toPath().toUri()); // TODO leak + Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); SelectiveJarResource r = new SelectiveJarResource(resource); r.setIncludes(config.getIncludes()); r.setExcludes(config.getExcludes()); @@ -112,7 +115,7 @@ protected List getOverlays() { if (!matchedWarArtifacts.contains(a)) { - Resource resource = ResourceFactory.root().newJarFileResource(a.getFile().toPath().toUri()); // TODO leak + Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); Overlay overlay = new Overlay(null, resource); overlays.add(overlay); } @@ -127,9 +130,11 @@ protected List getOverlays() * @return the location to which it was unpacked * @throws IOException if there is an IO problem */ - protected Resource unpackOverlay(Overlay overlay) + protected Resource unpackOverlay(WebAppContext webApp, Overlay overlay) throws IOException { + Objects.requireNonNull(webApp); + if (overlay.getResource() == null) return null; //nothing to unpack @@ -153,6 +158,6 @@ protected Resource unpackOverlay(Overlay overlay) overlay.unpackTo(unpackDir); //use top level of unpacked content - return ResourceFactory.root().newResource(unpackDir.getCanonicalPath()); // TODO leak + return webApp.getResourceFactory().newResource(unpackDir.getCanonicalPath()); } } diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java index 76fb39b7842c..23cfb3672b46 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java @@ -20,9 +20,11 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import org.apache.maven.artifact.Artifact; +import org.eclipse.jetty.ee9.webapp.WebAppContext; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.resource.MountedPathResource; import org.eclipse.jetty.util.resource.Resource; @@ -36,7 +38,7 @@ */ public class OverlayManager { - private WarPluginInfo warPlugin; + private final WarPluginInfo warPlugin; public OverlayManager(WarPluginInfo warPlugin) { @@ -48,7 +50,7 @@ public void applyOverlays(MavenWebAppContext webApp) { List resourceBases = new ArrayList(); - for (Overlay o : getOverlays()) + for (Overlay o : getOverlays(webApp)) { //can refer to the current project in list of overlays for ordering purposes if (o.getConfig() != null && o.getConfig().isCurrentProject() && webApp.getBaseResource().exists()) @@ -57,7 +59,7 @@ public void applyOverlays(MavenWebAppContext webApp) continue; } //add in the selectively unpacked overlay in the correct order to the webapp's resource base - resourceBases.add(unpackOverlay(o)); + resourceBases.add(unpackOverlay(webApp, o)); } if (!resourceBases.contains(webApp.getBaseResource()) && webApp.getBaseResource().exists()) @@ -74,9 +76,11 @@ public void applyOverlays(MavenWebAppContext webApp) /** * Generate an ordered list of overlays */ - protected List getOverlays() + protected List getOverlays(WebAppContext webApp) throws Exception - { + { + Objects.requireNonNull(webApp); + Set matchedWarArtifacts = new HashSet(); List overlays = new ArrayList(); @@ -100,7 +104,7 @@ protected List getOverlays() if (a != null) { matchedWarArtifacts.add(a); - Resource resource = ResourceFactory.root().newJarFileResource(a.getFile().toPath().toUri()); // TODO leak + Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); SelectiveJarResource r = new SelectiveJarResource(resource); r.setIncludes(config.getIncludes()); r.setExcludes(config.getExcludes()); @@ -114,7 +118,7 @@ protected List getOverlays() { if (!matchedWarArtifacts.contains(a)) { - Resource resource = ResourceFactory.root().newJarFileResource(a.getFile().toPath().toUri()); // TODO leak + Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); Overlay overlay = new Overlay(null, resource); overlays.add(overlay); } @@ -129,9 +133,12 @@ protected List getOverlays() * @return the location to which it was unpacked * @throws IOException if there is an IO problem */ - protected Resource unpackOverlay(Overlay overlay) + protected Resource unpackOverlay(WebAppContext webApp, Overlay overlay) throws IOException { + Objects.requireNonNull(webApp); + Objects.requireNonNull(overlay); + if (overlay.getResource() == null) return null; //nothing to unpack @@ -154,6 +161,6 @@ protected Resource unpackOverlay(Overlay overlay) overlay.unpackTo(unpackDir); //use top level of unpacked content - return ResourceFactory.root().newResource(unpackDir.getCanonicalPath()); // TODO leak + return webApp.getResourceFactory().newResource(unpackDir.getCanonicalPath()); } }