[Git][java-team/plexus-cli][master] 5 commits: Initial upstream branch.
Andreas Tille (@tille)
gitlab at salsa.debian.org
Sun Feb 23 20:15:00 GMT 2025
Andreas Tille pushed to branch master at Debian Java Maintainers / plexus-cli
Commits:
f1fdbf6e by Emmanuel Bourg at 2017-07-21T09:45:34+02:00
Initial upstream branch.
- - - - -
837db84d by Andreas Tille at 2025-02-23T21:01:22+01:00
New upstream version 1.2
- - - - -
2352678c by Andreas Tille at 2025-02-23T21:01:22+01:00
Update upstream source from tag 'upstream/1.2'
Update to upstream version '1.2'
with Debian dir 9d39b24c571d78a3a00eb9fde9d1f94f07b9c814
- - - - -
d3646f49 by Andreas Tille at 2025-02-23T21:13:34+01:00
Fix watch file and remove README.source, orig-tar.sh
- - - - -
7500bd2b by Andreas Tille at 2025-02-23T21:14:27+01:00
Build-Depends:
- s/libplexus-container-default1.5-java/libplexus-container-default-java/
- s/default-jdk/default-jdk-headless/
- - - - -
11 changed files:
- − debian/README.source
- debian/changelog
- debian/control
- − debian/orig-tar.sh
- debian/rules
- debian/watch
- + pom.xml
- + src/main/java/org/codehaus/plexus/tools/cli/AbstractCli.java
- + src/main/java/org/codehaus/plexus/tools/cli/Cli.java
- + src/test/java/org/codehaus/plexus/tools/cli/CliTest.java
- + src/test/java/org/codehaus/plexus/tools/cli/TestCli.java
Changes:
=====================================
debian/README.source deleted
=====================================
@@ -1,9 +0,0 @@
-Information about plexus-cli
-----------------------------
-
-This package was debianized using the mh_make command
-from the maven-debian-helper package.
-
-The build system uses Maven but prevents it from downloading
-anything from the Internet, making the build compliant with
-the Debian policy.
=====================================
debian/changelog
=====================================
@@ -1,3 +1,13 @@
+plexus-cli (1.2-8) UNRELEASED; urgency=medium
+
+ * Team upload.
+ * Fix watch file and remove README.source, orig-tar.sh
+ * Build-Depends:
+ - s/libplexus-container-default1.5-java/libplexus-container-default-java/
+ - s/default-jdk/default-jdk-headless/
+
+ -- Andreas Tille <tille at debian.org> Sun, 23 Feb 2025 21:12:45 +0100
+
plexus-cli (1.2-7) unstable; urgency=medium
* Team upload.
=====================================
debian/control
=====================================
@@ -5,13 +5,13 @@ Maintainer: Debian Java Maintainers <pkg-java-maintainers at lists.alioth.debian.or
Uploaders: tony mancill <tmancill at debian.org>
Build-Depends:
debhelper (>= 10),
- default-jdk,
+ default-jdk-headless,
default-jdk-doc,
junit4,
libcommons-cli-java,
libguava-java,
libmaven-javadoc-plugin-java,
- libplexus-container-default1.5-java,
+ libplexus-container-default-java,
libplexus-utils2-java,
libplexus-utils2-java-doc,
maven-debian-helper (>= 1.4)
=====================================
debian/orig-tar.sh deleted
=====================================
@@ -1,18 +0,0 @@
-#!/bin/sh -e
-
-# There is no svn tag for plexus-cli! :-(
-
-# VERSION=$2
-VERSION=1.2
-REVISION=7025
-
-TAR=../plexus-cli_$VERSION.orig.tar.gz
-DIR=plexus-cli-$VERSION
-TAG=plexus-cli-$VERSION
-
-svn export -r$REVISION http://svn.codehaus.org/plexus/plexus-components/trunk/plexus-cli $DIR
-# New versions should appear here:
-#svn export http://svn.codehaus.org/plexus/plexus-components/tags/$TAG $DIR
-
-GZIP=--best tar -c -z -f $TAR $DIR || exit 2
-rm -rf $DIR ../$TAG
=====================================
debian/rules
=====================================
@@ -2,6 +2,3 @@
%:
dh $@
-
-get-orig-source:
- uscan --download-current-version --force-download --rename
=====================================
debian/watch
=====================================
@@ -1,3 +1,4 @@
-version=3
-http://svn.codehaus.org/plexus/plexus-components/tags/ \
- plexus-cli-(.*)/ debian debian/orig-tar.sh
+version=4
+
+opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%@PACKAGE at -$1.tar.gz%" \
+ https://github.com/codehaus-plexus/@PACKAGE@/tags (?:.*?/)?@PACKAGE at -@ANY_VERSION@@ARCHIVE_EXT@
=====================================
pom.xml
=====================================
@@ -0,0 +1,47 @@
+<?xml version="1.0"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>plexus-tools</artifactId>
+ <groupId>org.codehaus.plexus</groupId>
+ <version>1.0.8</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-cli</artifactId>
+ <name>Plexus CLI</name>
+ <description>Easily create CLIs with Plexus components</description>
+ <version>1.2</version>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <version>1.0-alpha-34</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.4.7</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.0</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-lang</artifactId>
+ <groupId>commons-lang</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <scm>
+ <connection>scm:svn:http://svn.codehaus.org/plexus/plexus-tools/tags/plexus-cli-1.2</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/plexus/plexus-tools/tags/plexus-cli-1.2</developerConnection>
+ <url>http://fisheye.codehaus.org/browse/plexus/plexus-tools/tags/plexus-cli-1.2</url>
+ </scm>
+</project>
=====================================
src/main/java/org/codehaus/plexus/tools/cli/AbstractCli.java
=====================================
@@ -0,0 +1,466 @@
+package org.codehaus.plexus.tools.cli;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.codehaus.plexus.ContainerConfiguration;
+import org.codehaus.plexus.DefaultContainerConfiguration;
+import org.codehaus.plexus.DefaultPlexusContainer;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.PlexusContainerException;
+import org.codehaus.plexus.classworlds.ClassWorld;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @author jason van zyl
+ * @version $Id: AbstractCli.java 7021 2007-10-26 23:41:24Z jvanzyl $
+ * @noinspection UseOfSystemOutOrSystemErr,ACCESS_STATIC_VIA_INSTANCE
+ */
+public abstract class AbstractCli
+ implements Cli
+{
+ // ----------------------------------------------------------------------------
+ // These are standard options that we would want to use for all our projects.
+ // ----------------------------------------------------------------------------
+
+ public static final char QUIET = 'q';
+
+ public static final char DEBUG = 'X';
+
+ public static final char ERRORS = 'e';
+
+ public static final char HELP = 'h';
+
+ public static final char VERSION = 'v';
+
+ public static final char SET_SYSTEM_PROPERTY = 'D';
+
+ // ----------------------------------------------------------------------------
+ // Abstract methods
+ // ----------------------------------------------------------------------------
+
+ public abstract Options buildCliOptions( Options options );
+
+ public abstract void invokePlexusComponent( CommandLine cli,
+ PlexusContainer container )
+ throws Exception;
+
+ public String getPomPropertiesPath()
+ {
+ return null;
+ }
+
+ public int execute( String[] args )
+ {
+ ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() );
+
+ return execute( args, classWorld );
+ }
+
+ public int execute( String[] args,
+ ClassWorld classWorld )
+ {
+ CommandLine cli;
+
+ try
+ {
+ cli = parse( args );
+ }
+ catch ( ParseException e )
+ {
+ System.err.println( "Unable to parse command line options: " + e.getMessage() );
+
+ displayHelp();
+
+ return 1;
+ }
+
+ if ( System.getProperty( "java.class.version", "44.0" ).compareTo( "48.0" ) < 0 )
+ {
+ System.err.println( "Sorry, but JDK 1.4 or above is required to execute Maven" );
+
+ System.err.println(
+ "You appear to be using Java version: " + System.getProperty( "java.version", "<unknown>" ) );
+
+ return 1;
+ }
+
+ boolean debug = cli.hasOption( DEBUG );
+
+ boolean quiet = !debug && cli.hasOption( QUIET );
+
+ boolean showErrors = debug || cli.hasOption( ERRORS );
+
+ if ( showErrors )
+ {
+ System.out.println( "+ Error stacktraces are turned on." );
+ }
+
+ // ----------------------------------------------------------------------------
+ // Logging
+ // ----------------------------------------------------------------------------
+
+ int loggingLevel;
+
+ if ( debug )
+ {
+ loggingLevel = 0;
+ }
+ else if ( quiet )
+ {
+ loggingLevel = 0;
+ }
+ else
+ {
+ loggingLevel = 0;
+ }
+
+ // ----------------------------------------------------------------------
+ // Process particular command line options
+ // ----------------------------------------------------------------------
+
+ if ( cli.hasOption( HELP ) )
+ {
+ displayHelp();
+
+ return 0;
+ }
+
+ if ( cli.hasOption( VERSION ) )
+ {
+ showVersion();
+
+ return 0;
+ }
+ else if ( debug )
+ {
+ showVersion();
+ }
+
+ // ----------------------------------------------------------------------------
+ // This is what we will generalize for the invocation of the command line.
+ // ----------------------------------------------------------------------------
+
+ try
+ {
+ ContainerConfiguration configuration = new DefaultContainerConfiguration()
+ .setClassWorld( classWorld );
+
+ PlexusContainer plexus = new DefaultPlexusContainer( configuration );
+
+ invokePlexusComponent( cli, plexus );
+ }
+ catch ( PlexusContainerException e )
+ {
+ showFatalError( "Cannot create Plexus container.", e, true );
+ }
+ catch ( ComponentLookupException e )
+ {
+ showError( "Cannot lookup application component.", e, true );
+ }
+ catch ( Exception e )
+ {
+ showError( "Problem executing command line.", e, true );
+ }
+
+ return 0;
+ }
+
+ protected int showFatalError( String message,
+ Exception e,
+ boolean show )
+ {
+ System.err.println( "FATAL ERROR: " + message );
+
+ if ( show )
+ {
+ System.err.println( "Error stacktrace:" );
+
+ e.printStackTrace();
+ }
+ else
+ {
+ System.err.println( "For more information, run with the -e flag" );
+ }
+
+ return 1;
+ }
+
+ protected void showError( String message,
+ Exception e,
+ boolean show )
+ {
+ System.err.println( message );
+
+ if ( show )
+ {
+ System.err.println( "Error stacktrace:" );
+
+ e.printStackTrace();
+ }
+ }
+
+ // Need to get the versions of the application in a general way, so that I need a way to get the
+ // specifics of the application so that I can do this in a general way.
+ private void showVersion()
+ {
+ InputStream is;
+
+ try
+ {
+ Properties properties = new Properties();
+
+ String pomPropertiesPath = getPomPropertiesPath();
+
+ if ( pomPropertiesPath == null )
+ {
+ System.err.println( "Unable determine version from JAR file." );
+
+ return;
+ }
+
+ is = AbstractCli.class.getClassLoader().getResourceAsStream( pomPropertiesPath );
+
+ if ( is == null )
+ {
+ System.err.println( "Unable determine version from JAR file." );
+
+ return;
+ }
+
+ properties.load( is );
+
+ if ( properties.getProperty( "builtOn" ) != null )
+ {
+ System.out.println( "Version: " + properties.getProperty( "version", "unknown" ) + " built on " +
+ properties.getProperty( "builtOn" ) );
+ }
+ else
+ {
+ System.out.println( "Version: " + properties.getProperty( "version", "unknown" ) );
+ }
+ }
+ catch ( IOException e )
+ {
+ System.err.println( "Unable determine version from JAR file: " + e.getMessage() );
+ }
+ }
+
+ // ----------------------------------------------------------------------
+ // System properties handling
+ // ----------------------------------------------------------------------
+
+ private Properties getExecutionProperties( CommandLine commandLine )
+ {
+ Properties executionProperties = new Properties();
+
+ // ----------------------------------------------------------------------
+ // Options that are set on the command line become system properties
+ // and therefore are set in the session properties. System properties
+ // are most dominant.
+ // ----------------------------------------------------------------------
+
+ if ( commandLine.hasOption( SET_SYSTEM_PROPERTY ) )
+ {
+ String[] defStrs = commandLine.getOptionValues( SET_SYSTEM_PROPERTY );
+
+ for ( int i = 0; i < defStrs.length; ++i )
+ {
+ setCliProperty( defStrs[i], executionProperties );
+ }
+ }
+
+ executionProperties.putAll( System.getProperties() );
+
+ return executionProperties;
+ }
+
+ private void setCliProperty( String property,
+ Properties executionProperties )
+ {
+ String name;
+
+ String value;
+
+ int i = property.indexOf( "=" );
+
+ if ( i <= 0 )
+ {
+ name = property.trim();
+
+ value = "true";
+ }
+ else
+ {
+ name = property.substring( 0, i ).trim();
+
+ value = property.substring( i + 1 ).trim();
+ }
+
+ executionProperties.setProperty( name, value );
+
+ // ----------------------------------------------------------------------
+ // I'm leaving the setting of system properties here as not to break
+ // the SystemPropertyProfileActivator. This won't harm embedding. jvz.
+ // ----------------------------------------------------------------------
+
+ System.setProperty( name, value );
+ }
+
+ private Options options;
+
+ public Options buildDefaultCliOptions()
+ {
+ options = new Options();
+
+ options.addOption(
+ OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( "Define a system property" ).create(
+ SET_SYSTEM_PROPERTY ) );
+ options.addOption(
+ OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create( HELP ) );
+ options.addOption(
+ OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create( VERSION ) );
+ options.addOption(
+ OptionBuilder.withLongOpt( "quiet" ).withDescription( "Quiet output - only show errors" ).create( QUIET ) );
+ options.addOption(
+ OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" ).create( DEBUG ) );
+ options.addOption(
+ OptionBuilder.withLongOpt( "errors" ).withDescription( "Produce execution error messages" ).create(
+ ERRORS ) );
+
+ return buildCliOptions( options );
+ }
+
+ public CommandLine parse( String[] args )
+ throws ParseException
+ {
+ // We need to eat any quotes surrounding arguments...
+ String[] cleanArgs = cleanArgs( args );
+
+ CommandLineParser parser = new GnuParser();
+
+ return parser.parse( buildDefaultCliOptions(), cleanArgs );
+ }
+
+ private static String[] cleanArgs( String[] args )
+ {
+ List cleaned = new ArrayList();
+
+ StringBuffer currentArg = null;
+
+ for ( int i = 0; i < args.length; i++ )
+ {
+ String arg = args[i];
+
+ boolean addedToBuffer = false;
+
+ if ( arg.startsWith( "\"" ) )
+ {
+ // if we're in the process of building up another arg, push it and start over.
+ // this is for the case: "-Dfoo=bar "-Dfoo2=bar two" (note the first unterminated quote)
+ if ( currentArg != null )
+ {
+ cleaned.add( currentArg.toString() );
+ }
+
+ // start building an argument here.
+ currentArg = new StringBuffer( arg.substring( 1 ) );
+
+ addedToBuffer = true;
+ }
+
+ // this has to be a separate "if" statement, to capture the case of: "-Dfoo=bar"
+ if ( arg.endsWith( "\"" ) )
+ {
+ String cleanArgPart = arg.substring( 0, arg.length() - 1 );
+
+ // if we're building an argument, keep doing so.
+ if ( currentArg != null )
+ {
+ // if this is the case of "-Dfoo=bar", then we need to adjust the buffer.
+ if ( addedToBuffer )
+ {
+ currentArg.setLength( currentArg.length() - 1 );
+ }
+ // otherwise, we trim the trailing " and append to the buffer.
+ else
+ {
+ // TODO: introducing a space here...not sure what else to do but collapse whitespace
+ currentArg.append( ' ' ).append( cleanArgPart );
+ }
+
+ // we're done with this argument, so add it.
+ cleaned.add( currentArg.toString() );
+ }
+ else
+ {
+ // this is a simple argument...just add it.
+ cleaned.add( cleanArgPart );
+ }
+
+ // the currentArg MUST be finished when this completes.
+ currentArg = null;
+
+ continue;
+ }
+
+ // if we haven't added this arg to the buffer, and we ARE building an argument
+ // buffer, then append it with a preceding space...again, not sure what else to
+ // do other than collapse whitespace.
+ // NOTE: The case of a trailing quote is handled by nullifying the arg buffer.
+ if ( !addedToBuffer )
+ {
+ // append to the argument we're building, collapsing whitespace to a single space.
+ if ( currentArg != null )
+ {
+ currentArg.append( ' ' ).append( arg );
+ }
+ // this is a loner, just add it directly.
+ else
+ {
+ cleaned.add( arg );
+ }
+ }
+ }
+
+ // clean up.
+ if ( currentArg != null )
+ {
+ cleaned.add( currentArg.toString() );
+ }
+
+ int cleanedSz = cleaned.size();
+ String[] cleanArgs = null;
+
+ if ( cleanedSz == 0 )
+ {
+ // if we didn't have any arguments to clean, simply pass the original array through
+ cleanArgs = args;
+ }
+ else
+ {
+ cleanArgs = (String[]) cleaned.toArray( new String[cleanedSz] );
+ }
+
+ return cleanArgs;
+ }
+
+ public void displayHelp()
+ {
+ System.out.println();
+
+ HelpFormatter formatter = new HelpFormatter();
+
+ formatter.printHelp( "mvn [options] [<goal(s)>] [<phase(s)>]", "\nOptions:", options, "\n" );
+ }
+}
=====================================
src/main/java/org/codehaus/plexus/tools/cli/Cli.java
=====================================
@@ -0,0 +1,20 @@
+package org.codehaus.plexus.tools.cli;
+
+import org.codehaus.plexus.PlexusContainer;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.CommandLine;
+
+/**
+ * @author Jason van Zyl
+ */
+public interface Cli
+{
+ Options buildCliOptions( Options options );
+
+ void invokePlexusComponent( CommandLine cli,
+ PlexusContainer container )
+ throws Exception;
+
+ // this can be calculated
+ String getPomPropertiesPath();
+}
=====================================
src/test/java/org/codehaus/plexus/tools/cli/CliTest.java
=====================================
@@ -0,0 +1,39 @@
+package org.codehaus.plexus.tools.cli;
+
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.io.File;
+
+/**
+ * @author Jason van Zyl
+ */
+public class CliTest
+ extends PlexusTestCase
+{
+ public void testCli()
+ throws Exception
+ {
+ String[] args = new String[]{"-n", getBasedir()};
+
+ Class clazz = TestCli.class;
+
+ Method m = clazz.getMethod( "main", new Class[]{String[].class} );
+
+ int modifiers = m.getModifiers();
+
+ if ( Modifier.isStatic( modifiers ) && Modifier.isPublic( modifiers ) )
+ {
+ if ( m.getReturnType() == Integer.TYPE || m.getReturnType() == Void.TYPE )
+ {
+ m.invoke( clazz, new Object[]{args} );
+ }
+ }
+
+ String s = FileUtils.fileRead( new File( getBasedir(), "target/cli.txt" ) );
+
+ assertEquals( "NAME_OPTION_INVOKED", s );
+ }
+}
=====================================
src/test/java/org/codehaus/plexus/tools/cli/TestCli.java
=====================================
@@ -0,0 +1,44 @@
+package org.codehaus.plexus.tools.cli;
+
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.util.FileUtils;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+
+import java.io.File;
+
+/**
+ * @author Jason van Zyl
+ */
+public class TestCli
+ extends AbstractCli
+{
+ public static void main( String[] args )
+ throws Exception
+ {
+ new TestCli().execute( args );
+ }
+
+ public Options buildCliOptions( Options options )
+ {
+ options.addOption(
+ OptionBuilder.withLongOpt( "name" ).withDescription( "Display name." ).hasArg().create( 'n' ) );
+
+ return options;
+ }
+
+ public void invokePlexusComponent( CommandLine cli,
+ PlexusContainer container )
+ throws Exception
+ {
+ if ( cli.hasOption( 'n' ) )
+ {
+ String directory = cli.getOptionValue( 'n' );
+
+ FileUtils.mkdir( new File( directory, "target" ).getAbsolutePath() );
+
+ FileUtils.fileWrite( new File( directory, "target/cli.txt").getAbsolutePath() , "NAME_OPTION_INVOKED" );
+ }
+ }
+}
View it on GitLab: https://salsa.debian.org/java-team/plexus-cli/-/compare/f5ef226d1afd92d54b63831bb35eaefafea46786...7500bd2b9861813d3fd149fd5d966e3346c2c277
--
View it on GitLab: https://salsa.debian.org/java-team/plexus-cli/-/compare/f5ef226d1afd92d54b63831bb35eaefafea46786...7500bd2b9861813d3fd149fd5d966e3346c2c277
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20250223/85b41a67/attachment.htm>
More information about the pkg-java-commits
mailing list