Commit dd8ded97 authored by rpopma's avatar rpopma
Browse files

[BUILD] removed picocli tests from core tests; they do not add value here and...

[BUILD] removed picocli tests from core tests; they do not add value here and occasionally fail when building Log4j on a console that supports ANSI colors
parent ec10b16e
release-2.x CVE-creation-process LOG4J2-2266 LOG4J2-2644-2.x LOG4J2-2829 LOG4J2-2948 LOG4J2-2993 LOG4J2-3004 LOG4J2-3020 LOG4J2-3051 LOG4J2-3056 LOG4J2-3075 LOG4J2-3080 LOG4J2-3116 LOG4J2-3185 LOG4J2-3301 LOG4J2-3368 LOG4J2-3393 LOG4J2-913 api-separation-documentation dependabot/maven/com.h2database-h2-2.0.206 dependabot/maven/com.h2database-h2-2.1.210 dependabot/maven/com.h2database-h2-2.1.212 dependabot/maven/com.sleepycat-je-18.3.12 dependabot/maven/de.flapdoodle.embed-de.flapdoodle.embed.mongo-3.3.1 dependabot/maven/de.flapdoodle.embed-de.flapdoodle.embed.mongo-3.4.5 dependabot/maven/io.fabric8-docker-maven-plugin-0.39.0 dependabot/maven/io.fabric8-kubernetes-client-5.11.2 dependabot/maven/javax.servlet-javax.servlet-api-4.0.1 dependabot/maven/jmh.version-1.34 dependabot/maven/log4j-cassandra/org.apache.cassandra-cassandra-all-3.0.26 dependabot/maven/logbackVersion-1.2.10 dependabot/maven/mockitoVersion-4.3.1 dependabot/maven/mongodb3.version-3.12.10 dependabot/maven/net.javacrumbs.json-unit-json-unit-2.31.0 dependabot/maven/org.apache.activemq-activemq-broker-5.17.0 dependabot/maven/org.apache.activemq-activemq-broker-5.17.1 dependabot/maven/org.apache.felix-maven-bundle-plugin-5.1.4 dependabot/maven/org.apache.felix-maven-bundle-plugin-5.1.5 dependabot/maven/org.apache.felix-org.apache.felix.framework-7.0.3 dependabot/maven/org.apache.kafka-kafka-clients-3.0.0 dependabot/maven/org.apache.kafka-kafka-clients-3.1.0 dependabot/maven/org.apache.maven-maven-core-3.8.4 dependabot/maven/org.apache.maven.plugins-maven-checkstyle-plugin-3.1.2 dependabot/maven/org.apache.maven.plugins-maven-pdf-plugin-1.6.0 dependabot/maven/org.apache.maven.plugins-maven-project-info-reports-plugin-3.2.2 dependabot/maven/org.apache.maven.plugins-maven-scm-plugin-1.12.2 dependabot/maven/org.apache.maven.plugins-maven-site-plugin-3.12.0 dependabot/maven/org.apache.tomcat-tomcat-catalina-10.0.14 dependabot/maven/org.awaitility-awaitility-4.1.1 dependabot/maven/org.codehaus.mojo-build-helper-maven-plugin-3.2.0 dependabot/maven/org.codehaus.mojo-build-helper-maven-plugin-3.3.0 dependabot/maven/org.codehaus.plexus-plexus-utils-3.4.1 dependabot/maven/org.lightcouch-lightcouch-0.2.0 dependabot/maven/org.liquibase-liquibase-core-3.10.3 dependabot/maven/org.liquibase-liquibase-core-4.6.2 dependabot/maven/org.liquibase-liquibase-core-4.7.0 dependabot/maven/org.springframework.ws-spring-ws-core-3.1.2 dependabot/maven/slf4jVersion-1.7.36 dependabot/maven/spring-boot.version-2.6.2 dependabot/maven/xmlunitVersion-2.9.0 ldap-controls log4j-2.11.1-patches log4j-2.12 log4j-2.17.1-site new-iso-date-time-formats release-2.12.x/LOG4J2-3242 slf4j-2.0 rel/2.17.2 rel/2.17.1 rel/2.17.0 rel/2.16.0 rel/2.15.0 rel/2.14.1 rel/2.14.0 rel/2.13.3 rel/2.13.2 rel/2.13.1 rel/2.13.0 rel/2.12.4 rel/2.12.3 rel/2.12.2 rel/2.12.1 rel/2.12.0 rel/2.11.2 rel/2.11.1 log4j-2.17.2-rc1 log4j-2.17.1-rc1 log4j-2.17.0-rc1 log4j-2.16.0-rc1 log4j-2.15.1-rc1 log4j-2.15.0-rc2 log4j-2.15.0-rc1 log4j-2.14.1-rc1 log4j-2.14.0-rc1 log4j-2.13.3 log4j-2.13.3-rc1 log4j-2.13.2 log4j-2.13.2-rc1 log4j-2.13.1 log4j-2.13.1-rc2 log4j-2.13.1-rc1 log4j-2.13.0-rc2 log4j-2.13.0-rc1 log4j-2.12.4-rc1 log4j-2.12.3-rc1 log4j-2.12.2-rc1 log4j-2.12.1 log4j-2.12.1-rc1 log4j-2.12.0 log4j-2.12.0-rc2 log4j-2.12.0-rc1 log4j-2.11.2 log4j-2.11.2-rc3 log4j-2.11.2-rc2 log4j-2.11.2-rc1 log4j-2.11.1 log4j-2.11.1-rc1
No related merge requests found
Showing with 0 additions and 7605 deletions
+0 -7605
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.logging.log4j.core.tools.picocli;
import org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.Ansi.Text;
import org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.Column;
import org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.IOptionRenderer;
import org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.IParameterRenderer;
import org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.Layout;
import org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.TextTable;
import java.lang.reflect.Field;
import static org.apache.logging.log4j.core.tools.picocli.CommandLine.*;
import static org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.Column.Overflow.SPAN;
import static org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.Column.Overflow.TRUNCATE;
import static org.apache.logging.log4j.core.tools.picocli.CommandLine.Help.Column.Overflow.WRAP;
/**
* Demonstrates how the CommandLine.Help API can be used to create custom layouts for usage help messages.
*/
@Command(name = "picocli.CustomLayoutDemo", description = "Demonstrates picocli custom layouts.",
footer = {
"Run with -Dpicocli.ansi=true to force picocli to use ansi codes,",
"or with -Dpicocli.ansi=false to force picocli to NOT use ansi codes.",
"By default picocli will use ansi codes if the platform supports it."
}
)
public class CustomLayoutDemo implements Runnable {
public static void main(String[] args) {
CommandLine.run(new CustomLayoutDemo(), System.err, args);
}
@Option(names = {"-z", "--zip"}, description = "Show usage help for a layout with 2 options per row.")
private boolean showZip;
@Option(names = {"-n", "--netstat"}, description = "Show usage help for a layout with a narrow options column and a wide description column. Descriptions that wrap to the next row are not indented.")
private boolean showNetstat;
@Override
public void run() {
if (!showZip && !showNetstat) {
CommandLine.usage(this, System.err);
return;
}
if (showZip) { System.out.println(createZipUsageFormat(Help.Ansi.AUTO)); }
if (showNetstat) { System.out.println(createNetstatUsageFormat(Help.Ansi.AUTO)); }
}
public static String createZipUsageFormat(Help.Ansi ansi) {
@Command(description = {
"Copyright (c) 1990-2008 Info-ZIP - Type 'zip \"-L\"' for software license.",
"Zip 3.0 (July 5th 2008). Command:",
"@|bold zip|@ [@|yellow -options|@] [@|yellow -b|@ @|underline path|@] [@|yellow -t|@ @|underline mmddyyyy|@] [@|yellow -n|@ @|underline suffixes|@] [@|yellow zipfile|@ @|underline list|@] [@|yellow -xi|@ @|underline list|@]",
" The default action is to add or replace zipfile entries from list, which",
" can include the special name - to compress standard input.",
" If @|yellow zipfile|@ and @|yellow list|@ are omitted, zip compresses stdin to stdout."}
)
class Zip {
@Option(names = "-f", description = "freshen: only changed files")
boolean freshen;
@Option(names = "-u", description = "update: only changed or new files")
boolean update;
@Option(names = "-d", description = "delete entries in zipfile")
boolean delete;
@Option(names = "-m", description = "move into zipfile (delete OS files)")
boolean move;
@Option(names = "-r", description = "recurse into directories")
boolean recurse;
@Option(names = "-j", description = "junk (don't record) directory names")
boolean junk;
@Option(names = "-0", description = "store only")
boolean store;
@Option(names = "-l", description = "convert LF to CR LF (@|yellow -ll|@ CR LF to LF)")
boolean lf2crlf;
@Option(names = "-1", description = "compress faster")
boolean faster;
@Option(names = "-9", description = "compress better")
boolean better;
@Option(names = "-q", description = "quiet operation")
boolean quiet;
@Option(names = "-v", description = "verbose operation/print version info")
boolean verbose;
@Option(names = "-c", description = "add one-line comments")
boolean comments;
@Option(names = "-z", description = "add zipfile comment")
boolean zipComment;
@Option(names = "-@", description = "read names from stdin")
boolean readFileList;
@Option(names = "-o", description = "make zipfile as old as latest entry")
boolean old;
@Option(names = "-x", description = "exclude the following names")
boolean exclude;
@Option(names = "-i", description = "include only the following names")
boolean include;
@Option(names = "-F", description = "fix zipfile (@|yellow -FF|@ try harder)")
boolean fix;
@Option(names = "-D", description = "do not add directory entries")
boolean directories;
@Option(names = "-A", description = "adjust self-extracting exe")
boolean adjust;
@Option(names = "-J", description = "junk zipfile prefix (unzipsfx)")
boolean junkPrefix;
@Option(names = "-T", description = "test zipfile integrity")
boolean test;
@Option(names = "-X", description = "eXclude eXtra file attributes")
boolean excludeAttribs;
@Option(names = "-y", description = "store symbolic links as the link instead of the referenced file")
boolean symbolic;
@Option(names = "-e", description = "encrypt")
boolean encrypt;
@Option(names = "-n", description = "don't compress these suffixes")
boolean dontCompress;
@Option(names = "-h2", description = "show more help")
boolean moreHelp;
}
class TwoOptionsPerRowLayout extends Layout { // define a custom layout
TextTable.Cell previous = new TextTable.Cell(0, 0);
private TwoOptionsPerRowLayout(Help.ColorScheme colorScheme, TextTable textTable,
IOptionRenderer optionRenderer,
IParameterRenderer parameterRenderer) {
super(colorScheme, textTable, optionRenderer, parameterRenderer);
}
@Override
public void layout(Field field, Text[][] values) {
Text[] columnValues = values[0]; // we know renderer creates a single row with two values
// We want to show two options on one row, next to each other,
// unless the first option spanned multiple columns (in which case there are not enough columns left)
int col = previous.column + 1;
if (col == 1 || col + columnValues.length > table.columns.length) { // if true, write into next row
// table also adds an empty row if a text value spanned multiple columns
if (table.rowCount() == 0 || table.rowCount() == previous.row + 1) { // avoid adding 2 empty rows
table.addEmptyRow(); // create the slots to write the text values into
}
col = 0; // we are starting a new row, reset the column to write into
}
for (int i = 0; i < columnValues.length; i++) {
// always write to the last row, column depends on what happened previously
previous = table.putValue(table.rowCount() - 1, col + i, columnValues[i]);
}
}
}
TextTable textTable = new TextTable(ansi,
new Column(5, 2, TRUNCATE), // values should fit
new Column(30, 2, SPAN), // overflow into adjacent columns
new Column(4, 1, TRUNCATE), // values should fit again
new Column(39, 2, WRAP));
TwoOptionsPerRowLayout layout = new TwoOptionsPerRowLayout(
Help.defaultColorScheme(ansi),
textTable,
Help.createMinimalOptionRenderer(),
Help.createMinimalParameterRenderer());
Help help = new Help(new Zip(), ansi);
StringBuilder sb = new StringBuilder();
sb.append(help.description()); // show the first 6 lines, including copyright, description and usage
// Note that we don't sort the options, so they appear in the order the fields are declared in the Zip class.
layout.addOptions(help.optionFields, help.parameterLabelRenderer);
sb.append(layout); // finally, copy the options details help text into the StringBuilder
return sb.toString();
}
/** for Netstat test */
private enum Protocol {IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, UDPv6}
public static String createNetstatUsageFormat(Help.Ansi ansi) {
@Command(name = "NETSTAT",
separator = " ",
abbreviateSynopsis = true,
header = "Displays protocol statistics and current TCP/IP network connections.%n")
class Netstat {
@Option(names="-a", description="Displays all connections and listening ports.")
boolean displayAll;
@Option(names="-b", description="Displays the executable involved in creating each connection or "
+ "listening port. In some cases well-known executables host "
+ "multiple independent components, and in these cases the "
+ "sequence of components involved in creating the connection "
+ "or listening port is displayed. In this case the executable "
+ "name is in [] at the bottom, on top is the component it called, "
+ "and so forth until TCP/IP was reached. Note that this option "
+ "can be time-consuming and will fail unless you have sufficient "
+ "permissions.")
boolean displayExecutable;
@Option(names="-e", description="Displays Ethernet statistics. This may be combined with the -s option.")
boolean displayEthernetStats;
@Option(names="-f", description="Displays Fully Qualified Domain Names (FQDN) for foreign addresses.")
boolean displayFQCN;
@Option(names="-n", description="Displays addresses and port numbers in numerical form.")
boolean displayNumerical;
@Option(names="-o", description="Displays the owning process ID associated with each connection.")
boolean displayOwningProcess;
@Option(names="-p", paramLabel = "proto",
description="Shows connections for the protocol specified by proto; proto "
+ "may be any of: TCP, UDP, TCPv6, or UDPv6. If used with the -s "
+ "option to display per-protocol statistics, proto may be any of: "
+ "IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPv6.")
Protocol proto;
@Option(names="-q", description="Displays all connections, listening ports, and bound "
+ "nonlistening TCP ports. Bound nonlistening ports may or may not "
+ "be associated with an active connection.")
boolean query;
@Option(names="-r", description="Displays the routing table.")
boolean displayRoutingTable;
@Option(names="-s", description="Displays per-protocol statistics. By default, statistics are "
+ "shown for IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6; "
+ "the -p option may be used to specify a subset of the default.")
boolean displayStatistics;
@Option(names="-t", description="Displays the current connection offload state.")
boolean displayOffloadState;
@Option(names="-x", description="Displays NetworkDirect connections, listeners, and shared endpoints.")
boolean displayNetDirect;
@Option(names="-y", description="Displays the TCP connection template for all connections. "
+ "Cannot be combined with the other options.")
boolean displayTcpConnectionTemplate;
@Parameters(arity = "0..1", paramLabel = "interval", description = ""
+ "Redisplays selected statistics, pausing interval seconds "
+ "between each display. Press CTRL+C to stop redisplaying "
+ "statistics. If omitted, netstat will print the current "
+ "configuration information once.")
int interval;
}
StringBuilder sb = new StringBuilder();
Help help = new Help(new Netstat(), ansi);
help.synopsisHeading = "";
sb.append(help.header()).append(help.detailedSynopsis(0, null, false));
sb.append(System.getProperty("line.separator"));
TextTable textTable = new TextTable(ansi,
new Column(15, 2, TRUNCATE),
new Column(65, 1, WRAP));
textTable.indentWrappedLines = 0;
Layout layout = new Layout(
Help.defaultColorScheme(ansi),
textTable,
Help.createMinimalOptionRenderer(),
Help.createMinimalParameterRenderer());
layout.addOptions(help.optionFields, help.parameterLabelRenderer);
layout.addPositionalParameters(help.positionalParametersFields, Help.createMinimalParamLabelRenderer());
sb.append(layout);
return sb.toString();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment