[Git][java-team/plexus-bsh-factory][upstream] Import Upstream version 1.0~alpha7
Tony Mancill (@tmancill)
gitlab at salsa.debian.org
Fri Sep 23 16:20:11 BST 2022
Tony Mancill pushed to branch upstream at Debian Java Maintainers / plexus-bsh-factory
Commits:
01e6b3ce by tony mancill at 2022-09-22T21:35:18-07:00
Import Upstream version 1.0~alpha7
- - - - -
10 changed files:
- + pom.xml
- + release-pom.xml
- + src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponent.java
- + src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentConfigurator.java
- + src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java
- + src/main/resources/META-INF/plexus/components.xml
- + src/test/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.java
- + src/test/java/org/codehaus/plexus/component/factory/bsh/Hello.java
- + src/test/resources/DefaultHello.bsh
- + src/test/resources/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.xml
Changes:
=====================================
pom.xml
=====================================
@@ -0,0 +1,18 @@
+<project>
+ <parent>
+ <artifactId>plexus-component-factories</artifactId>
+ <groupId>org.codehaus.plexus</groupId>
+ <version>1.0-alpha-5</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>plexus-bsh-factory</artifactId>
+ <name>Plexus BSH Factory</name>
+ <version>1.0-alpha-7</version>
+ <dependencies>
+ <dependency>
+ <groupId>bsh</groupId>
+ <artifactId>bsh</artifactId>
+ <version>1.3.0</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
=====================================
release-pom.xml
=====================================
@@ -0,0 +1,248 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-bsh-factory</artifactId>
+ <name>Plexus BSH Factory</name>
+ <version>1.0-alpha-7</version>
+ <ciManagement>
+ <notifiers>
+ <notifier>
+ <configuration>
+ <address>dev at plexus.codehaus.org</address>
+ </configuration>
+ </notifier>
+ <notifier>
+ <type>irc</type>
+ <configuration>
+ <port>6667</port>
+ <host>irc.codehaus.org</host>
+ <channel>#plexus</channel>
+ </configuration>
+ </notifier>
+ </notifiers>
+ </ciManagement>
+ <inceptionYear>2001</inceptionYear>
+ <mailingLists>
+ <mailingList>
+ <name>Plexus Developer List</name>
+ <subscribe>http://lists.codehaus.org/mailman/listinfo/plexus-dev</subscribe>
+ <unsubscribe>http://lists.codehaus.org/mailman/listinfo/plexus-dev</unsubscribe>
+ <archive>http://lists.codehaus.org/pipermail/plexus-dev/</archive>
+ </mailingList>
+ </mailingLists>
+ <developers>
+ <developer>
+ <id>jvanzyl</id>
+ <name>Jason van Zyl</name>
+ <email>jason at zenplex.com</email>
+ <organization>Zenplex</organization>
+ <roles>
+ <role>Developer</role>
+ <role>Release Manager</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>kaz</id>
+ <name>Pete Kazmier</name>
+ <email></email>
+ <organization></organization>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>jtaylor</id>
+ <name>James Taylor</name>
+ <email>james at jamestaylor.org</email>
+ <organization></organization>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>dandiep</id>
+ <name>Dan Diephouse</name>
+ <email>dan at envoisolutions.com</email>
+ <organization>Envoi solutions</organization>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>kasper</id>
+ <name>Kasper Nielsen</name>
+ <email>apache at kav.dk</email>
+ <organization></organization>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>bwalding</id>
+ <name>Ben Walding</name>
+ <email>bwalding at codehaus.org</email>
+ <organization>Walding Consulting Services</organization>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>mhw</id>
+ <name>Mark Wilkinson</name>
+ <email>mhw at kremvax.net</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>michal</id>
+ <name>Michal Maczka</name>
+ <email>mmaczka at interia.pl</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>evenisse</id>
+ <name>Emmanuel Venisse</name>
+ <email>evenisse at codehaus.org</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>trygvis</id>
+ <name>Trygve Laugstl</name>
+ <email>trygvis at codehaus.org</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <id>kenney</id>
+ <name>Kenney Westerhof</name>
+ <email>kenney at codehaus.org</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ </developers>
+ <scm>
+ <connection>scm:svn:svn://svn.codehaus.org/plexus/scm/trunk/plexus-component-factories/plexus-bsh-factory</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/plexus/trunk/plexus-component-factories/plexus-bsh-factory</developerConnection>
+ </scm>
+ <organization>
+ <name>Codehaus</name>
+ <url>http://www.codehaus.org/</url>
+ </organization>
+ <build>
+ <sourceDirectory>src/main/java</sourceDirectory>
+ <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
+ <testSourceDirectory>src/test/java</testSourceDirectory>
+ <outputDirectory>target/classes</outputDirectory>
+ <testOutputDirectory>target/test-classes</testOutputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ </testResource>
+ </testResources>
+ <directory>target</directory>
+ <plugins>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.0-beta-3-SNAPSHOT</version>
+ <configuration>
+ <tagBase>https://svn.codehaus.org/plexus/tags</tagBase>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <id>snapshots</id>
+ <name>Maven Snapshot Development Repository</name>
+ <url>http://snapshots.maven.codehaus.org/maven2</url>
+ </repository>
+ <repository>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>central</id>
+ <name>Maven Repository Switchboard</name>
+ <url>http://repo1.maven.org/maven2</url>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <id>snapshots-plugins</id>
+ <name>Maven Snapshot Plugins Development Repository</name>
+ <url>http://snapshots.maven.codehaus.org/maven2</url>
+ </pluginRepository>
+ <pluginRepository>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>central</id>
+ <name>Maven Plugin Repository</name>
+ <url>http://repo1.maven.org/maven2</url>
+ </pluginRepository>
+ </pluginRepositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.0.4</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <version>1.0-alpha-8</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>classworlds</groupId>
+ <artifactId>classworlds</artifactId>
+ <version>1.1-alpha-2</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>bsh</groupId>
+ <artifactId>bsh</artifactId>
+ <version>1.3.0</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ <reporting>
+ <outputDirectory>target/site</outputDirectory>
+ </reporting>
+ <distributionManagement>
+ <repository>
+ <id>repo1</id>
+ <name>Maven Central Repository</name>
+ <url>scp://repo1.maven.org/home/projects/maven/repository-staging/to-ibiblio/maven2</url>
+ </repository>
+ <snapshotRepository>
+ <id>snapshots</id>
+ <name>Maven Central Development Repository</name>
+ <url>scp://repo1.maven.org/home/projects/maven/repository-staging/snapshots/maven2</url>
+ </snapshotRepository>
+ </distributionManagement>
+</project>
\ No newline at end of file
=====================================
src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponent.java
=====================================
@@ -0,0 +1,16 @@
+package org.codehaus.plexus.component.factory.bsh;
+
+import bsh.Interpreter;
+
+/**
+ * Beanshell components must implement this to be able to provide the interpreter.
+ * @todo This may not be needed if the creation and configuration is done in one step, or there is some other way
+ * of getting back the interpreter from the created component
+ *
+ * @author <a href="mailto:brett at apache.org">Brett Porter</a>
+ * @version $Id: BshComponent.java 1817 2005-05-17 08:08:08Z brett $
+ */
+public interface BshComponent
+{
+ Interpreter getInterpreter();
+}
=====================================
src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentConfigurator.java
=====================================
@@ -0,0 +1,77 @@
+package org.codehaus.plexus.component.factory.bsh;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+import org.codehaus.classworlds.ClassRealm;
+import org.codehaus.plexus.component.configurator.AbstractComponentConfigurator;
+import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
+import org.codehaus.plexus.component.configurator.ConfigurationListener;
+import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+
+/**
+ * @todo not happy that this has to be different to the object with fields configurator - should only need to redefine the "setValue" method
+ */
+public class BshComponentConfigurator
+ extends AbstractComponentConfigurator
+{
+
+ public void configureComponent( Object component, PlexusConfiguration configuration,
+ ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm,
+ ConfigurationListener listener )
+ throws ComponentConfigurationException
+ {
+ Interpreter interpreter = ( (BshComponent) component ).getInterpreter();
+
+ int items = configuration.getChildCount();
+
+ for ( int i = 0; i < items; i++ )
+ {
+ PlexusConfiguration childConfiguration = configuration.getChild( i );
+
+ String elementName = childConfiguration.getName();
+
+ Class type = Object.class;
+
+ String implementation = childConfiguration.getAttribute( "implementation", null );
+
+ if ( implementation != null )
+ {
+ try
+ {
+ type = containerRealm.loadClass( implementation );
+
+ }
+ catch ( ClassNotFoundException e )
+ {
+ String msg = "Class name which was explicitly given in configuration using 'implementation' attribute: '" +
+ implementation + "' cannot be loaded";
+
+ throw new ComponentConfigurationException( msg, e );
+ }
+ }
+
+ ConfigurationConverter converter = converterLookup.lookupConverterForType( type );
+
+ Object value = converter.fromConfiguration( converterLookup, childConfiguration, type, component.getClass(),
+ containerRealm.getClassLoader(), expressionEvaluator, listener );
+
+ if ( value != null )
+ {
+ try
+ {
+ interpreter.set( elementName, value );
+ }
+ catch ( EvalError evalError )
+ {
+ throw new ComponentConfigurationException( "Unable to evaluate beanshell", evalError );
+ }
+ }
+ }
+
+ }
+
+
+}
=====================================
src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java
=====================================
@@ -0,0 +1,99 @@
+package org.codehaus.plexus.component.factory.bsh;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+import bsh.UtilEvalError;
+import org.codehaus.classworlds.ClassRealm;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.factory.AbstractComponentFactory;
+import org.codehaus.plexus.component.factory.ComponentInstantiationException;
+import org.codehaus.plexus.component.repository.ComponentDescriptor;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+
+/**
+ * BeanShell component factory.
+ *
+ * @author <a href="mailto:jason at maven.org">Jason Van Zyl</a>
+ * @author <a href="mailto:brett at codehaus.org">Brett Porter</a>
+ */
+public class BshComponentFactory
+ extends AbstractComponentFactory
+{
+ public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm containerRealm,
+ PlexusContainer container )
+ throws ComponentInstantiationException
+ {
+ String impl = componentDescriptor.getImplementation();
+ if ( !impl.startsWith( "/" ) )
+ {
+ impl = "/" + impl;
+ }
+
+ URL scriptLocation = containerRealm.getResource( impl );
+
+ if ( scriptLocation == null )
+ {
+ StringBuffer buf = new StringBuffer( "Cannot find: " + impl + " in classpath:" );
+ for ( int i = 0; i < containerRealm.getConstituents().length; i++ )
+ {
+ URL constituent = containerRealm.getConstituents()[i];
+ buf.append( "\n [" + i + "] " + constituent );
+ }
+ throw new ComponentInstantiationException( buf.toString() );
+ }
+
+ Object result = null;
+ Reader reader = null;
+
+ try
+ {
+ Interpreter interp = new Interpreter();
+
+ reader = new InputStreamReader( scriptLocation.openStream() );
+
+ // TODO
+ // BeanShell honours the context classloader, which something is setting (erroneously?)
+// interp.setClassLoader( containerRealm.getClassLoader() );
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader( containerRealm.getClassLoader() );
+ result = interp.eval( reader );
+ Thread.currentThread().setContextClassLoader( oldClassLoader );
+ }
+ catch ( EvalError evalError )
+ {
+ containerRealm.display();
+
+ container.getLogger().info( "Error text: " + evalError.getErrorText() );
+
+ throw new ComponentInstantiationException( "Cannot build component for: " +
+ componentDescriptor.getComponentKey() +
+ "; unable to read BeanShell script", evalError );
+ }
+ catch ( FileNotFoundException e )
+ {
+ containerRealm.display();
+ throw new ComponentInstantiationException( "Cannot build component for: " +
+ componentDescriptor.getComponentKey() +
+ "; unable to read BeanShell script", e );
+ }
+ catch ( IOException e )
+ {
+ throw new ComponentInstantiationException( "Cannot build component for: " +
+ componentDescriptor.getComponentKey() +
+ "; unable to read BeanShell script", e );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+
+ return result;
+ }
+
+}
=====================================
src/main/resources/META-INF/plexus/components.xml
=====================================
@@ -0,0 +1,17 @@
+<component-set>
+ <components>
+ <component>
+ <role>org.codehaus.plexus.component.factory.ComponentFactory</role>
+ <implementation>org.codehaus.plexus.component.factory.bsh.BshComponentFactory</implementation>
+ <role-hint>bsh</role-hint>
+ <configuration>
+ <id>bsh</id>
+ </configuration>
+ </component>
+ <component>
+ <role>org.codehaus.plexus.component.configurator.ComponentConfigurator</role>
+ <implementation>org.codehaus.plexus.component.factory.bsh.BshComponentConfigurator</implementation>
+ <role-hint>bsh</role-hint>
+ </component>
+ </components>
+</component-set>
=====================================
src/test/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.java
=====================================
@@ -0,0 +1,27 @@
+package org.codehaus.plexus.component.factory.bsh;
+
+import org.codehaus.plexus.PlexusTestCase;
+
+public class BshComponentFactoryTest
+ extends PlexusTestCase
+{
+ public BshComponentFactoryTest()
+ {
+ }
+
+ public void testComponent()
+ throws Exception
+ {
+ Hello hello = (Hello) lookup( Hello.ROLE );
+
+ assertNotNull( hello );
+
+ hello.initialize();
+
+ hello.start();
+
+ hello.hello();
+
+ hello.dispose();
+ }
+}
=====================================
src/test/java/org/codehaus/plexus/component/factory/bsh/Hello.java
=====================================
@@ -0,0 +1,13 @@
+package org.codehaus.plexus.component.factory.bsh;
+
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable;
+
+public interface Hello
+ extends Initializable, Startable, Disposable
+{
+ static String ROLE = Hello.class.getName();
+
+ void hello();
+}
=====================================
src/test/resources/DefaultHello.bsh
=====================================
@@ -0,0 +1,33 @@
+import org.codehaus.plexus.component.factory.bsh.Hello;
+
+contextualize( context )
+{
+ System.out.println( "contextualize(context): " + context );
+}
+
+initialize()
+{
+ System.out.println( "initialize()" );
+}
+
+start()
+{
+ System.out.println( "start()" );
+}
+
+stop()
+{
+ System.out.println( "stop()" );
+}
+
+dispose()
+{
+ System.out.println( "dispose()" );
+}
+
+hello()
+{
+ System.out.println( "hello!" );
+}
+
+return (Hello)this;
=====================================
src/test/resources/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.xml
=====================================
@@ -0,0 +1,18 @@
+<plexus>
+ <!-- component-factory-manager implementation="org.codehaus.plexus.component.factory.DefaultComponentFactoryManager">
+ <component-factories>
+ <component-factory implementation="org.codehaus.plexus.component.factory.bsh.BshComponentFactory">
+ <id>bsh</id>
+ <bsh-home>${basedir}/target</bsh-home>
+ <bsh-path>${basedir}/src/bsh</bsh-path>
+ </component-factory>
+ </component-factories>
+ </component-factory-manager -->
+ <components>
+ <component>
+ <role>org.codehaus.plexus.component.factory.bsh.Hello</role>
+ <implementation>/DefaultHello.bsh</implementation>
+ <component-factory>bsh</component-factory>
+ </component>
+ </components>
+</plexus>
View it on GitLab: https://salsa.debian.org/java-team/plexus-bsh-factory/-/commit/01e6b3ce1eb3603870a42c6d67af881822ae247f
--
View it on GitLab: https://salsa.debian.org/java-team/plexus-bsh-factory/-/commit/01e6b3ce1eb3603870a42c6d67af881822ae247f
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/20220923/2faeaa29/attachment.htm>
More information about the pkg-java-commits
mailing list