From b1b394b4bfec0be964713f17c65400181be376b2 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sun, 18 Aug 2013 10:40:15 -0700 Subject: [PATCH] jetty.base is always defined. --- .../java/org/eclipse/jetty/start/Config.java | 4 +- .../main/java/org/eclipse/jetty/start/FS.java | 3 +- .../org/eclipse/jetty/start/HomeBase.java | 43 ++++++++++--------- .../java/org/eclipse/jetty/start/Main.java | 12 +----- 4 files changed, 27 insertions(+), 35 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java index 72a02c2e110..1af85edaa97 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java @@ -204,9 +204,7 @@ public class Config __instance=this; _homebase = new HomeBase(); setProperty("jetty.home",_homebase.getHome()); - if(_homebase.hasBase()) { - setProperty("jetty.base",_homebase.getBase()); - } + setProperty("jetty.base",_homebase.getBase()); } public HomeBase getHomeBase() diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java index abcaad75a32..1a5999103d6 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java @@ -22,6 +22,7 @@ import java.io.Closeable; import java.io.File; import java.io.FileFilter; import java.io.IOException; +import java.util.Locale; import java.util.regex.Pattern; public class FS @@ -122,7 +123,7 @@ public class FS public static boolean isXml(String filename) { - return Pattern.compile(".xml$",Pattern.CASE_INSENSITIVE).matcher(filename).matches(); + return filename.toLowerCase(Locale.ENGLISH).endsWith(".xml"); } public static String separators(String path) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java index 8b4153515da..b225f2832b4 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java @@ -28,7 +28,13 @@ import java.util.List; import java.util.Objects; /** - * File access for ${jetty.home}, and optional ${jetty.base}, directories. + * File access for ${jetty.home}, ${jetty.base}, directories. + *

+ * By default, both ${jetty.home} and ${jetty.base} are the same directory, but they can point at different directories. + *

+ * The ${jetty.home} directory is where the main Jetty binaries and default configuration is housed. + *

+ * The ${jetty.base} directory is where the execution specific configuration and webapps are obtained from. */ public class HomeBase { @@ -39,11 +45,7 @@ public class HomeBase { String userDir = System.getProperty("user.dir"); this.homeDir = new File(System.getProperty("jetty.home",userDir)); - String base = System.getProperty("jetty.base"); - if (base != null) - { - this.baseDir = new File(base); - } + this.baseDir = new File(System.getProperty("jetty.base",homeDir.getAbsolutePath())); } public HomeBase(File homeDir, File baseDir) @@ -51,12 +53,12 @@ public class HomeBase this.homeDir = homeDir; this.baseDir = baseDir; } - - public boolean hasBase() + + public boolean isBaseDifferent() { - return this.baseDir != null; + return homeDir.compareTo(baseDir) != 0; } - + public void setBaseDir(File dir) { this.baseDir = dir; @@ -95,7 +97,7 @@ public class HomeBase String rpath = FS.separators(path); // Relative to Base Directory First - if (baseDir != null) + if (isBaseDifferent()) { File file = new File(baseDir,rpath); if (file.exists()) @@ -114,7 +116,7 @@ public class HomeBase // Finally, as an absolute path return new File(rpath); } - + public void setHomeDir(File dir) { this.homeDir = dir; @@ -165,7 +167,7 @@ public class HomeBase List homeFiles = new ArrayList<>(); homeFiles.addAll(Arrays.asList(homePath.listFiles(filter))); - if (baseDir != null) + if (isBaseDifferent()) { // merge File basePath = new File(baseDir,FS.separators(relPathToDirectory)); @@ -186,20 +188,19 @@ public class HomeBase // add any remaining home files. ret.addAll(homeFiles); - Collections.sort(ret, new NaturalSort.Files()); + Collections.sort(ret,new NaturalSort.Files()); return ret; } else { // simple return - Collections.sort(homeFiles, new NaturalSort.Files()); + Collections.sort(homeFiles,new NaturalSort.Files()); return homeFiles; } } - + /** - * Collect the list of files in both ${jetty.base} and ${jetty.home}, with - * , even if the same file shows up in both places. + * Collect the list of files in both ${jetty.base} and ${jetty.home}, with , even if the same file shows up in both places. */ public List rawListFiles(String relPathToDirectory, FileFilter filter) { @@ -211,7 +212,7 @@ public class HomeBase File homePath = new File(homeDir,FS.separators(relPathToDirectory)); ret.addAll(Arrays.asList(homePath.listFiles(filter))); - if (baseDir != null) + if (isBaseDifferent()) { // Base Dir File basePath = new File(baseDir,FS.separators(relPathToDirectory)); @@ -219,7 +220,7 @@ public class HomeBase } // Sort - Collections.sort(ret, new NaturalSort.Files()); + Collections.sort(ret,new NaturalSort.Files()); return ret; } @@ -265,7 +266,7 @@ public class HomeBase return "${jetty.home}" + path.substring(value.length()); } - if (baseDir != null) + if (isBaseDifferent()) { value = baseDir.getAbsolutePath(); if (path.startsWith(value)) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 86058bffb73..c4bb917a944 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -775,10 +775,7 @@ public class Main implements IncludeListener cmd.addArg(x); } cmd.addRawArg("-Djetty.home=" + _config.getHomeBase().getHome()); - if (_config.getHomeBase().hasBase()) - { - cmd.addRawArg("-Djetty.base=" + _config.getHomeBase().getBase()); - } + cmd.addRawArg("-Djetty.base=" + _config.getHomeBase().getBase()); // Special Stop/Shutdown properties ensureSystemPropertySet("STOP.PORT"); @@ -901,12 +898,7 @@ public class Main implements IncludeListener + "then overlapping entries will not be repeated in the eventual classpath."); System.out.println(); System.out.printf("${jetty.home} = %s%n",_config.getHomeBase().getHome()); - String base = ""; - if (_config.getHomeBase().hasBase()) - { - base = _config.getHomeBase().getBase(); - } - System.out.printf("${jetty.base} = %s%n",base); + System.out.printf("${jetty.base} = %s%n",_config.getHomeBase().getBase()); System.out.println(); for (String sectionId : sectionIds)