Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2014-10-28 19:32:55 +0000
committerJoakim Erdfelt2014-10-28 19:32:55 +0000
commit8a72a153a1280aad6390f27372b5a8af8127cc82 (patch)
treeb06e32b68604c9dda7d607a1968d941326ae95ea /jetty-start
parent8d2acb681706fb32c6fcea47a2124065381bbc89 (diff)
parente3f71430a64ca954bc3bef7ab62456515138e877 (diff)
downloadorg.eclipse.jetty.project-8a72a153a1280aad6390f27372b5a8af8127cc82.tar.gz
org.eclipse.jetty.project-8a72a153a1280aad6390f27372b5a8af8127cc82.tar.xz
org.eclipse.jetty.project-8a72a153a1280aad6390f27372b5a8af8127cc82.zip
Merge branch 'jetty-9.2.x'
Diffstat (limited to 'jetty-start')
-rw-r--r--jetty-start/src/main/java/org/eclipse/jetty/start/BaseHomeWarning.java51
-rw-r--r--jetty-start/src/main/java/org/eclipse/jetty/start/Main.java171
-rw-r--r--jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java22
-rw-r--r--jetty-start/src/main/resources/org/eclipse/jetty/start/base-home-warning.txt16
4 files changed, 196 insertions, 64 deletions
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/BaseHomeWarning.java b/jetty-start/src/main/java/org/eclipse/jetty/start/BaseHomeWarning.java
new file mode 100644
index 0000000000..bd1fc70561
--- /dev/null
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/BaseHomeWarning.java
@@ -0,0 +1,51 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.start;
+
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.jetty.start.Props.Prop;
+
+public class BaseHomeWarning
+{
+ public static void show(Props props)
+ {
+ Prop showWarn = props.getProp("org.eclipse.jetty.start.home.warning",true);
+ if (showWarn == null || Boolean.parseBoolean(showWarn.value))
+ {
+ if (!Main.printTextResource("org/eclipse/jetty/start/base-home-warning.txt"))
+ {
+ StartLog.warn("It is not recommended to run Jetty from within {jetty.home}");
+ StartLog.warn("Use a proper {jetty.base} setup");
+ StartLog.warn("See: http://www.eclipse.org/jetty/documentation/current/startup.html");
+ }
+
+ try
+ {
+ System.err.print("Your startup will proceed shortly ...");
+ TimeUnit.SECONDS.sleep(2);
+ System.err.println();
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+}
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 f405ae22ec..ba0e2aa681 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
@@ -82,12 +82,13 @@ import org.eclipse.jetty.start.config.CommandLineConfigSource;
public class Main
{
private static final int EXIT_USAGE = 1;
- private static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
public static String join(Collection<?> objs, String delim)
{
if (objs==null)
+ {
return "";
+ }
StringBuilder str = new StringBuilder();
boolean needDelim = false;
for (Object obj : objs)
@@ -399,23 +400,29 @@ public class Main
{
// is it an explicit request to create an ini file?
if (topLevel && !FS.exists(startd_ini) && !appendStartIni)
+ {
buildIni=true;
-
- // else is it transitive
- else if (transitive)
+ }
+ // else is it transitive
+ else if (transitive)
{
// do we need an ini anyway?
- if (module.hasDefaultConfig() || module.hasLicense())
- buildIni=true;
+ if (module.hasDefaultConfig() || module.hasLicense())
+ {
+ buildIni = true;
+ }
else
+ {
StartLog.info("%-15s initialised transitively",name);
+ }
}
-
// else must be initialized explicitly
else
{
for (String source : module.getSources())
+ {
StartLog.info("%-15s initialised in %s",name,baseHome.toShortForm(source));
+ }
}
}
else
@@ -435,13 +442,28 @@ public class Main
System.err.printf(" + has not been audited for compliance with its license%n");
System.err.printf("%n");
for (String l : module.getLicense())
+ {
System.err.printf(" %s%n",l);
+ }
- System.err.printf("%nProceed (y/N)? ");
- String line = input.readLine();
-
- if (line==null || line.length()==0 || !line.toLowerCase().startsWith("y"))
- System.exit(1);
+ if (args.isApproveAllLicenses())
+ {
+ System.err.println("All licenses approved via command line");
+ }
+ else
+ {
+ try (BufferedReader input = new BufferedReader(new InputStreamReader(System.in)))
+ {
+ System.err.printf("%nProceed (y/N)? ");
+ String line = input.readLine();
+
+ if (line == null || line.length() == 0 || !line.toLowerCase().startsWith("y"))
+ {
+ System.err.printf("Exiting: license not acknowledged%n");
+ System.exit(1);
+ }
+ }
+ }
}
@@ -567,7 +589,9 @@ public class Main
}
if (complete)
+ {
break;
+ }
// look for any new ones resolved via expansion
depends.clear();
@@ -701,7 +725,7 @@ public class Main
if (args.isStopCommand())
{
- doStop(args);
+ doStop(args);
}
// Initialize start.ini
@@ -727,14 +751,25 @@ public class Main
if (!FS.exists(file))
{
- /* Startup should NEVER fail to run on missing content.
- * See Bug #427204
- */
- // args.setRun(false);
- String type=arg.location.endsWith("/")?"directory":"file";
- if (arg.uri!=null)
+ boolean isDir = arg.location.endsWith("/");
+ if (isDir)
{
- StartLog.warn("Required %s '%s' not downloaded from %s. Run with --create-files to download",type,baseHome.toShortForm(file),arg.uri);
+ System.err.println("MKDIR: " + baseHome.toShortForm(file));
+ FS.ensureDirectoryExists(file);
+ /* Startup should not fail to run on missing directories.
+ * See Bug #427204
+ */
+ // args.setRun(false);
+ }
+ else
+ {
+ StartLog.warn("Missing Required File: %s",baseHome.toShortForm(file));
+ args.setRun(false);
+ if (arg.uri != null)
+ {
+ StartLog.warn(" Can be downloaded From: %s",arg.uri);
+ StartLog.warn(" Run start.jar --create-files to download");
+ }
}
}
}
@@ -744,6 +779,12 @@ public class Main
{
return;
}
+
+ // Warning Message
+ if (!baseHome.isBaseDifferent() && args.isNormalMainClass())
+ {
+ BaseHomeWarning.show(args.getProperties());
+ }
// execute Jetty in another JVM
if (args.isExec())
@@ -791,20 +832,21 @@ public class Main
}
}
- private void doStop(StartArgs args) {
- int stopPort = Integer.parseInt(args.getProperties().getString("STOP.PORT"));
- String stopKey = args.getProperties().getString("STOP.KEY");
+ private void doStop(StartArgs args)
+ {
+ int stopPort = Integer.parseInt(args.getProperties().getString("STOP.PORT"));
+ String stopKey = args.getProperties().getString("STOP.KEY");
- if (args.getProperties().getString("STOP.WAIT") != null)
- {
- int stopWait = Integer.parseInt(args.getProperties().getString("STOP.WAIT"));
+ if (args.getProperties().getString("STOP.WAIT") != null)
+ {
+ int stopWait = Integer.parseInt(args.getProperties().getString("STOP.WAIT"));
- stop(stopPort,stopKey,stopWait);
- }
- else
- {
- stop(stopPort,stopKey);
- }
+ stop(stopPort,stopKey,stopWait);
+ }
+ else
+ {
+ stop(stopPort,stopKey);
+ }
}
/**
@@ -880,15 +922,26 @@ public class Main
public void usage(boolean exit)
{
StartLog.endStartLog();
- String usageResource = "org/eclipse/jetty/start/usage.txt";
- boolean usagePresented = false;
- try (InputStream usageStream = getClass().getClassLoader().getResourceAsStream(usageResource))
+ if(!printTextResource("org/eclipse/jetty/start/usage.txt"))
+ {
+ System.err.println("ERROR: detailed usage resource unavailable");
+ }
+ if (exit)
{
- if (usageStream != null)
+ System.exit(EXIT_USAGE);
+ }
+ }
+
+ public static boolean printTextResource(String resourceName)
+ {
+ boolean resourcePrinted = false;
+ try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName))
+ {
+ if (stream != null)
{
- try (InputStreamReader reader = new InputStreamReader(usageStream); BufferedReader buf = new BufferedReader(reader))
+ try (InputStreamReader reader = new InputStreamReader(stream); BufferedReader buf = new BufferedReader(reader))
{
- usagePresented = true;
+ resourcePrinted = true;
String line;
while ((line = buf.readLine()) != null)
{
@@ -898,50 +951,44 @@ public class Main
}
else
{
- System.out.println("No usage.txt ??");
+ System.out.println("Unable to find resource: " + resourceName);
}
}
catch (IOException e)
{
StartLog.warn(e);
}
- if (!usagePresented)
- {
- System.err.println("ERROR: detailed usage resource unavailable");
- }
- if (exit)
- {
- System.exit(EXIT_USAGE);
- }
+
+ return resourcePrinted;
}
// ------------------------------------------------------------
// implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy)
public void init(String[] args) throws Exception
{
- try
- {
- startupArgs = processCommandLine(args);
- }
- catch (UsageException e)
- {
- System.err.println(e.getMessage());
- usageExit(e.getCause(),e.getExitCode());
- }
- catch (Throwable e)
- {
- usageExit(e,UsageException.ERR_UNKNOWN);
- }
+ try
+ {
+ startupArgs = processCommandLine(args);
+ }
+ catch (UsageException e)
+ {
+ System.err.println(e.getMessage());
+ usageExit(e.getCause(),e.getExitCode());
+ }
+ catch (Throwable e)
+ {
+ usageExit(e,UsageException.ERR_UNKNOWN);
+ }
}
public void start() throws Exception
{
- start(startupArgs);
+ start(startupArgs);
}
public void stop() throws Exception
{
- doStop(startupArgs);
+ doStop(startupArgs);
}
public void destroy()
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java
index 06b92461dd..d561e54589 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java
@@ -78,7 +78,7 @@ public class StartArgs
private Map<String, String> propertySource = new HashMap<>();
/** List of all active [files] sections from enabled modules */
private List<FileArg> files = new ArrayList<>();
- /** List of all active [lib] sectinos from enabled modules */
+ /** List of all active [lib] sections from enabled modules */
private Classpath classpath;
/** List of all active [xml] sections from enabled modules */
private List<Path> xmls = new ArrayList<>();
@@ -122,6 +122,7 @@ public class StartArgs
private boolean dryRun = false;
private boolean exec = false;
+ private boolean approveAllLicenses = false;
public StartArgs()
{
@@ -574,7 +575,7 @@ public class StartArgs
for (String key : systemPropertyKeys)
{
// ignored keys
- if ("jetty.home".equals(key) || "jetty.base".equals(key))
+ if ("jetty.home".equals(key) || "jetty.base".equals(key) || "main.class".equals(key))
{
// skip
continue;
@@ -584,6 +585,11 @@ public class StartArgs
return false;
}
+ public boolean isApproveAllLicenses()
+ {
+ return approveAllLicenses;
+ }
+
public boolean isDownload()
{
return download;
@@ -598,6 +604,11 @@ public class StartArgs
{
return exec;
}
+
+ public boolean isNormalMainClass()
+ {
+ return SERVER_MAIN.equals(getMainClassname());
+ }
public boolean isHelp()
{
@@ -749,6 +760,13 @@ public class StartArgs
return;
}
+ // Enable forked execution of Jetty server
+ if ("--approve-all-licenses".equals(arg))
+ {
+ approveAllLicenses = true;
+ return;
+ }
+
// Arbitrary Libraries
if (arg.startsWith("--lib="))
{
diff --git a/jetty-start/src/main/resources/org/eclipse/jetty/start/base-home-warning.txt b/jetty-start/src/main/resources/org/eclipse/jetty/start/base-home-warning.txt
new file mode 100644
index 0000000000..a34bfdba7e
--- /dev/null
+++ b/jetty-start/src/main/resources/org/eclipse/jetty/start/base-home-warning.txt
@@ -0,0 +1,16 @@
+============================================================================
+WARNING: Jetty is starting using LEGACY behavior.
+
+A proper {jetty.base} should be configured with no changes being made to the {jetty.home} directory.
+
+Please see http://www.eclipse.org/jetty/documentation/current/startup.html
+
+A demo-base directory has been provided as an example of this setup.
+
+ $ cd demo-base
+ $ java -jar ../start.jar
+
+This warning may be disabled by setting the system property
+
+ -Dorg.eclipse.jetty.start.home.warning=false
+============================================================================

Back to the top