From 9bba180a10f7b1eef933619ff8d39995bbfe9512 Mon Sep 17 00:00:00 2001 From: denghao Date: Wed, 22 Mar 2023 10:59:08 +0800 Subject: [PATCH] Import Upstream version 1.0~alpha7 --- .pc/.quilt_patches | 1 + .pc/.quilt_series | 1 + .pc/.version | 1 + .pc/01-add-missing-dependencies.patch/pom.xml | 18 ++ .../factory/bsh/BshComponentFactory.java | 99 +++++++ .../factory/bsh/BshComponentFactoryTest.java | 27 ++ .pc/03-junit-dependency.patch/pom.xml | 24 ++ .pc/applied-patches | 3 + debian-orig/changelog | 63 +++++ debian-orig/control | 27 ++ debian-orig/copyright | 16 ++ debian-orig/libplexus-bsh-factory-java.poms | 2 + debian-orig/maven.properties | 2 + debian-orig/maven.rules | 3 + debian-orig/orig-tar.sh | 17 ++ .../patches/01-add-missing-dependencies.patch | 19 ++ .../02-plexus-containers-compatibility.patch | 56 ++++ debian-orig/patches/03-junit-dependency.patch | 13 + debian-orig/patches/series | 3 + debian-orig/rules | 4 + debian-orig/source/format | 1 + debian-orig/watch | 5 + pom.xml | 29 ++ release-pom.xml | 248 ++++++++++++++++++ .../component/factory/bsh/BshComponent.java | 16 ++ .../factory/bsh/BshComponentConfigurator.java | 77 ++++++ .../factory/bsh/BshComponentFactory.java | 104 ++++++++ .../resources/META-INF/plexus/components.xml | 17 ++ .../factory/bsh/BshComponentFactoryTest.java | 27 ++ .../plexus/component/factory/bsh/Hello.java | 13 + src/test/resources/DefaultHello.bsh | 33 +++ .../factory/bsh/BshComponentFactoryTest.xml | 18 ++ 32 files changed, 987 insertions(+) create mode 100644 .pc/.quilt_patches create mode 100644 .pc/.quilt_series create mode 100644 .pc/.version create mode 100644 .pc/01-add-missing-dependencies.patch/pom.xml create mode 100644 .pc/02-plexus-containers-compatibility.patch/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java create mode 100644 .pc/02-plexus-containers-compatibility.patch/src/test/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.java create mode 100644 .pc/03-junit-dependency.patch/pom.xml create mode 100644 .pc/applied-patches create mode 100644 debian-orig/changelog create mode 100644 debian-orig/control create mode 100644 debian-orig/copyright create mode 100644 debian-orig/libplexus-bsh-factory-java.poms create mode 100644 debian-orig/maven.properties create mode 100644 debian-orig/maven.rules create mode 100755 debian-orig/orig-tar.sh create mode 100644 debian-orig/patches/01-add-missing-dependencies.patch create mode 100644 debian-orig/patches/02-plexus-containers-compatibility.patch create mode 100644 debian-orig/patches/03-junit-dependency.patch create mode 100644 debian-orig/patches/series create mode 100755 debian-orig/rules create mode 100644 debian-orig/source/format create mode 100644 debian-orig/watch create mode 100644 pom.xml create mode 100644 release-pom.xml create mode 100755 src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponent.java create mode 100755 src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentConfigurator.java create mode 100644 src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java create mode 100644 src/main/resources/META-INF/plexus/components.xml create mode 100644 src/test/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.java create mode 100644 src/test/java/org/codehaus/plexus/component/factory/bsh/Hello.java create mode 100644 src/test/resources/DefaultHello.bsh create mode 100644 src/test/resources/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.xml diff --git a/.pc/.quilt_patches b/.pc/.quilt_patches new file mode 100644 index 0000000..6857a8d --- /dev/null +++ b/.pc/.quilt_patches @@ -0,0 +1 @@ +debian/patches diff --git a/.pc/.quilt_series b/.pc/.quilt_series new file mode 100644 index 0000000..c206706 --- /dev/null +++ b/.pc/.quilt_series @@ -0,0 +1 @@ +series diff --git a/.pc/.version b/.pc/.version new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/.pc/.version @@ -0,0 +1 @@ +2 diff --git a/.pc/01-add-missing-dependencies.patch/pom.xml b/.pc/01-add-missing-dependencies.patch/pom.xml new file mode 100644 index 0000000..5ea05ca --- /dev/null +++ b/.pc/01-add-missing-dependencies.patch/pom.xml @@ -0,0 +1,18 @@ + + + plexus-component-factories + org.codehaus.plexus + 1.0-alpha-5 + + 4.0.0 + plexus-bsh-factory + Plexus BSH Factory + 1.0-alpha-7 + + + bsh + bsh + 1.3.0 + + + \ No newline at end of file diff --git a/.pc/02-plexus-containers-compatibility.patch/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java b/.pc/02-plexus-containers-compatibility.patch/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java new file mode 100644 index 0000000..f2f3437 --- /dev/null +++ b/.pc/02-plexus-containers-compatibility.patch/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 Jason Van Zyl + * @author Brett Porter + */ +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; + } + +} diff --git a/.pc/02-plexus-containers-compatibility.patch/src/test/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.java b/.pc/02-plexus-containers-compatibility.patch/src/test/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.java new file mode 100644 index 0000000..c8a7204 --- /dev/null +++ b/.pc/02-plexus-containers-compatibility.patch/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(); + } +} diff --git a/.pc/03-junit-dependency.patch/pom.xml b/.pc/03-junit-dependency.patch/pom.xml new file mode 100644 index 0000000..f43ab87 --- /dev/null +++ b/.pc/03-junit-dependency.patch/pom.xml @@ -0,0 +1,24 @@ + + + plexus-component-factories + org.codehaus.plexus + 1.0-alpha-5 + + 4.0.0 + plexus-bsh-factory + Plexus BSH Factory + 1.0-alpha-7 + + + bsh + bsh + 1.3.0 + + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-9-stable-1 + provided + + + diff --git a/.pc/applied-patches b/.pc/applied-patches new file mode 100644 index 0000000..5a8d4bb --- /dev/null +++ b/.pc/applied-patches @@ -0,0 +1,3 @@ +01-add-missing-dependencies.patch +02-plexus-containers-compatibility.patch +03-junit-dependency.patch diff --git a/debian-orig/changelog b/debian-orig/changelog new file mode 100644 index 0000000..d4455e7 --- /dev/null +++ b/debian-orig/changelog @@ -0,0 +1,63 @@ +plexus-bsh-factory (1.0~alpha7-5) unstable; urgency=medium + + * Update Uploaders field (Closes: #889420) + * Update build-dep on libplexus-container-default-java (Closes: #1020427) + * Use debhelper-compat 13 + * Remove get-orig-source target from debian/rules + * Bump Standards-Version to 4.6.1 + * Freshen years in debian/copyright + + -- tony mancill Fri, 23 Sep 2022 08:15:07 -0700 + +plexus-bsh-factory (1.0~alpha7-4.1) unstable; urgency=medium + + * Non maintainer upload by the Reproducible Builds team. + * No source change upload to rebuild on buildd with .buildinfo files. + + -- Holger Levsen Mon, 28 Dec 2020 13:14:33 +0100 + +plexus-bsh-factory (1.0~alpha7-4) unstable; urgency=medium + + * Team upload. + * Depend on libplexus-container-default1.5-java + instead of libplexus-container-default-java + * Standards-Version updated to 4.1.0 + * Switch to debhelper level 10 + + -- Emmanuel Bourg Fri, 08 Sep 2017 09:43:49 +0200 + +plexus-bsh-factory (1.0~alpha7-3.1) unstable; urgency=medium + + * Non-maintainer upload. + * Build with maven-debian-helper + * Depend on libbsh-java instead of bsh + * Moved the package to Git + * Standards-Version updated to 3.9.7 (no changes) + * Switch to debhelper level 9 + * Converted debian/copyright to the Copyright Format 1.0 + + -- Emmanuel Bourg Fri, 19 Feb 2016 16:57:41 +0100 + +plexus-bsh-factory (1.0~alpha7-3) unstable; urgency=low + + * Add myself to Uploaders. + * Bump Standards-Version to 3.9.2: no changes needed. + * Fix FTBFS: remove version param (deprecated in debian-ant-helper) + and use POM version (Closes: #628345). + * Use mh_clean in clean rule. + * Bump to debhelper 7 compat level. + * Switch to source format 3.0 (quilt). + + -- Damien Raude-Morvan Sun, 29 May 2011 13:33:35 +0200 + +plexus-bsh-factory (1.0~alpha7-2) unstable; urgency=low + + * Switch to the new plexus-container package. + + -- Torsten Werner Mon, 13 Jul 2009 21:22:01 +0200 + +plexus-bsh-factory (1.0~alpha7-1) unstable; urgency=low + + * Initial release. (Closes: #535021) + + -- Ludovic Claude Sat, 28 Mar 2009 22:01:14 +0000 diff --git a/debian-orig/control b/debian-orig/control new file mode 100644 index 0000000..ec2452e --- /dev/null +++ b/debian-orig/control @@ -0,0 +1,27 @@ +Source: plexus-bsh-factory +Section: java +Priority: optional +Maintainer: Debian Java Maintainers +Uploaders: Ludovic Claude , + tony mancill +Build-Depends: debhelper-compat (= 13), + default-jdk, + junit4, + libbsh-java, + libplexus-container-default-java, + maven-debian-helper, +Standards-Version: 4.6.1 +Vcs-Git: https://salsa.debian.org/java-team/plexus-bsh-factory.git +Vcs-Browser: https://salsa.debian.org/java-team/plexus-bsh-factory +Homepage: http://plexus.codehaus.org/ + +Package: libplexus-bsh-factory-java +Architecture: all +Depends: ${misc:Depends}, libplexus-container-default1.5-java, libbsh-java +Description: Plexus Beanshell Factory + The Plexus project provides a full software stack for creating and + executing software projects. Based on the Plexus container, the applications + can utilise component-oriented programming to build modular, reusable + components that can easily be assembled and reused. + . + This package provides a factory for instantiating BeanShell with Plexus. diff --git a/debian-orig/copyright b/debian-orig/copyright new file mode 100644 index 0000000..ee7d531 --- /dev/null +++ b/debian-orig/copyright @@ -0,0 +1,16 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: Plexus BeanShell Factory +Source: http://plexus.codehaus.org + +Files: * +Copyright: 2001-2009, Codehaus Foundation. +License: Apache-2.0 + +Files: debian/* +Copyright: 2009-2022, Ludovic Claude + 2022 tony mancill +License: Apache-2.0 + +License: Apache-2.0 + On Debian systems, the full text of the Apache-2.0 license + can be found in the file '/usr/share/common-licenses/Apache-2.0' diff --git a/debian-orig/libplexus-bsh-factory-java.poms b/debian-orig/libplexus-bsh-factory-java.poms new file mode 100644 index 0000000..e3a3ef0 --- /dev/null +++ b/debian-orig/libplexus-bsh-factory-java.poms @@ -0,0 +1,2 @@ +pom.xml --no-parent + diff --git a/debian-orig/maven.properties b/debian-orig/maven.properties new file mode 100644 index 0000000..e2ae10b --- /dev/null +++ b/debian-orig/maven.properties @@ -0,0 +1,2 @@ +javadoc.dir=build/api +maven.test.skip=true diff --git a/debian-orig/maven.rules b/debian-orig/maven.rules new file mode 100644 index 0000000..4033cad --- /dev/null +++ b/debian-orig/maven.rules @@ -0,0 +1,3 @@ +junit junit * s/.*/4.x/ * * +s/bsh/org.beanshell/ bsh jar s/.*/debian/ +org.codehaus.plexus plexus-container-default * s/.*/1.5.5/ * * diff --git a/debian-orig/orig-tar.sh b/debian-orig/orig-tar.sh new file mode 100755 index 0000000..428e998 --- /dev/null +++ b/debian-orig/orig-tar.sh @@ -0,0 +1,17 @@ +#!/bin/sh -e + +VERSION=$2 +TAR=../plexus-bsh-factory_$VERSION.orig.tar.gz +DIR=plexus-bsh-factory-$VERSION +TAG=$(echo "plexus-bsh-factory-$VERSION" | sed 's,~\(alpha\|beta\),-\1-,' | sed 's/alpha-7/alpha-7-SNAPSHOT/') + +svn export http://svn.codehaus.org/plexus/tags/$TAG/ $DIR +tar -c -z -f $TAR $DIR +rm -rf $DIR ../$TAG + +# move to directory 'tarballs' +if [ -r .svn/deb-layout ]; then + . .svn/deb-layout + mv $TAR $origDir + echo "moved $TAR to $origDir" +fi diff --git a/debian-orig/patches/01-add-missing-dependencies.patch b/debian-orig/patches/01-add-missing-dependencies.patch new file mode 100644 index 0000000..7fe69af --- /dev/null +++ b/debian-orig/patches/01-add-missing-dependencies.patch @@ -0,0 +1,19 @@ +Description: Adds the missing dependency on junit +Author: Emmanuel Bourg +Forwarded: no +--- a/pom.xml ++++ b/pom.xml +@@ -14,5 +14,11 @@ + bsh + 1.3.0 + ++ ++ org.codehaus.plexus ++ plexus-container-default ++ 1.0-alpha-9-stable-1 ++ provided ++ + +- +\ No newline at end of file ++ diff --git a/debian-orig/patches/02-plexus-containers-compatibility.patch b/debian-orig/patches/02-plexus-containers-compatibility.patch new file mode 100644 index 0000000..e512c74 --- /dev/null +++ b/debian-orig/patches/02-plexus-containers-compatibility.patch @@ -0,0 +1,56 @@ +Description: Fixes the compatibility with the version of plexus-container-default in Debian +Author: Emmanuel Bourg +Forwarded: no +--- a/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java ++++ b/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java +@@ -25,6 +25,11 @@ + public class BshComponentFactory + extends AbstractComponentFactory + { ++ public String getId() ++ { ++ return "bsh"; ++ } ++ + public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm containerRealm, + PlexusContainer container ) + throws ComponentInstantiationException +@@ -69,23 +74,23 @@ + { + containerRealm.display(); + +- container.getLogger().info( "Error text: " + evalError.getErrorText() ); ++ ((org.codehaus.plexus.DefaultPlexusContainer) container).getLogger().info( "Error text: " + evalError.getErrorText() ); + + throw new ComponentInstantiationException( "Cannot build component for: " + +- componentDescriptor.getComponentKey() + ++ componentDescriptor.getHumanReadableKey() + + "; unable to read BeanShell script", evalError ); + } + catch ( FileNotFoundException e ) + { + containerRealm.display(); + throw new ComponentInstantiationException( "Cannot build component for: " + +- componentDescriptor.getComponentKey() + ++ componentDescriptor.getHumanReadableKey() + + "; unable to read BeanShell script", e ); + } + catch ( IOException e ) + { + throw new ComponentInstantiationException( "Cannot build component for: " + +- componentDescriptor.getComponentKey() + ++ componentDescriptor.getHumanReadableKey() + + "; unable to read BeanShell script", e ); + } + finally +--- a/src/test/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.java ++++ b/src/test/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.java +@@ -12,7 +12,7 @@ + public void testComponent() + throws Exception + { +- Hello hello = (Hello) lookup( Hello.ROLE ); ++ Hello hello = (Hello) lookup( Hello.class ); + + assertNotNull( hello ); + diff --git a/debian-orig/patches/03-junit-dependency.patch b/debian-orig/patches/03-junit-dependency.patch new file mode 100644 index 0000000..c3a3b34 --- /dev/null +++ b/debian-orig/patches/03-junit-dependency.patch @@ -0,0 +1,13 @@ +--- a/pom.xml ++++ b/pom.xml +@@ -20,5 +20,10 @@ + 1.0-alpha-9-stable-1 + provided + ++ ++ junit ++ junit ++ 4.12 ++ + + diff --git a/debian-orig/patches/series b/debian-orig/patches/series new file mode 100644 index 0000000..5a8d4bb --- /dev/null +++ b/debian-orig/patches/series @@ -0,0 +1,3 @@ +01-add-missing-dependencies.patch +02-plexus-containers-compatibility.patch +03-junit-dependency.patch diff --git a/debian-orig/rules b/debian-orig/rules new file mode 100755 index 0000000..2d33f6a --- /dev/null +++ b/debian-orig/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f + +%: + dh $@ diff --git a/debian-orig/source/format b/debian-orig/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian-orig/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian-orig/watch b/debian-orig/watch new file mode 100644 index 0000000..f5febbc --- /dev/null +++ b/debian-orig/watch @@ -0,0 +1,5 @@ +version=3 +opts="uversionmangle=s/alpha-7-SNAPSHOT/alpha-7/;s/-(alpha|beta)-/~$1/" \ + http://svn.codehaus.org/plexus/tags/ \ + plexus-bsh-factory-([0-9].*)/ debian debian/orig-tar.sh + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2f76847 --- /dev/null +++ b/pom.xml @@ -0,0 +1,29 @@ + + + plexus-component-factories + org.codehaus.plexus + 1.0-alpha-5 + + 4.0.0 + plexus-bsh-factory + Plexus BSH Factory + 1.0-alpha-7 + + + bsh + bsh + 1.3.0 + + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-9-stable-1 + provided + + + junit + junit + 4.12 + + + diff --git a/release-pom.xml b/release-pom.xml new file mode 100644 index 0000000..bf48eee --- /dev/null +++ b/release-pom.xml @@ -0,0 +1,248 @@ + + 4.0.0 + org.codehaus.plexus + plexus-bsh-factory + Plexus BSH Factory + 1.0-alpha-7 + + + + +
dev@plexus.codehaus.org
+
+
+ + irc + + 6667 + irc.codehaus.org + #plexus + + +
+
+ 2001 + + + Plexus Developer List + http://lists.codehaus.org/mailman/listinfo/plexus-dev + http://lists.codehaus.org/mailman/listinfo/plexus-dev + http://lists.codehaus.org/pipermail/plexus-dev/ + + + + + jvanzyl + Jason van Zyl + jason@zenplex.com + Zenplex + + Developer + Release Manager + + + + kaz + Pete Kazmier + + + + Developer + + + + jtaylor + James Taylor + james@jamestaylor.org + + + Developer + + + + dandiep + Dan Diephouse + dan@envoisolutions.com + Envoi solutions + + Developer + + + + kasper + Kasper Nielsen + apache@kav.dk + + + Developer + + + + bwalding + Ben Walding + bwalding@codehaus.org + Walding Consulting Services + + Developer + + + + mhw + Mark Wilkinson + mhw@kremvax.net + + Developer + + + + michal + Michal Maczka + mmaczka@interia.pl + + Developer + + + + evenisse + Emmanuel Venisse + evenisse@codehaus.org + + Developer + + + + trygvis + Trygve Laugstøl + trygvis@codehaus.org + + Developer + + + + kenney + Kenney Westerhof + kenney@codehaus.org + + Developer + + + + + scm:svn:svn://svn.codehaus.org/plexus/scm/trunk/plexus-component-factories/plexus-bsh-factory + scm:svn:https://svn.codehaus.org/plexus/trunk/plexus-component-factories/plexus-bsh-factory + + + Codehaus + http://www.codehaus.org/ + + + src/main/java + src/main/scripts + src/test/java + target/classes + target/test-classes + + + src/main/resources + + + + + src/test/resources + + + target + + + maven-release-plugin + 2.0-beta-3-SNAPSHOT + + https://svn.codehaus.org/plexus/tags + + + + + + + + false + + snapshots + Maven Snapshot Development Repository + http://snapshots.maven.codehaus.org/maven2 + + + + false + + central + Maven Repository Switchboard + http://repo1.maven.org/maven2 + + + + + + false + + snapshots-plugins + Maven Snapshot Plugins Development Repository + http://snapshots.maven.codehaus.org/maven2 + + + + false + + central + Maven Plugin Repository + http://repo1.maven.org/maven2 + + + + + org.codehaus.plexus + plexus-utils + 1.0.4 + compile + + + junit + junit + 3.8.1 + test + + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-8 + compile + + + classworlds + classworlds + 1.1-alpha-2 + compile + + + bsh + bsh + 1.3.0 + compile + + + + target/site + + + + repo1 + Maven Central Repository + scp://repo1.maven.org/home/projects/maven/repository-staging/to-ibiblio/maven2 + + + snapshots + Maven Central Development Repository + scp://repo1.maven.org/home/projects/maven/repository-staging/snapshots/maven2 + + +
\ No newline at end of file diff --git a/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponent.java b/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponent.java new file mode 100755 index 0000000..bfa3219 --- /dev/null +++ b/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 Brett Porter + * @version $Id: BshComponent.java 1817 2005-05-17 08:08:08Z brett $ + */ +public interface BshComponent +{ + Interpreter getInterpreter(); +} diff --git a/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentConfigurator.java b/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentConfigurator.java new file mode 100755 index 0000000..7f4a9d4 --- /dev/null +++ b/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 ); + } + } + } + + } + + +} diff --git a/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java b/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java new file mode 100644 index 0000000..a2849c7 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactory.java @@ -0,0 +1,104 @@ +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 Jason Van Zyl + * @author Brett Porter + */ +public class BshComponentFactory + extends AbstractComponentFactory +{ + public String getId() + { + return "bsh"; + } + + 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(); + + ((org.codehaus.plexus.DefaultPlexusContainer) container).getLogger().info( "Error text: " + evalError.getErrorText() ); + + throw new ComponentInstantiationException( "Cannot build component for: " + + componentDescriptor.getHumanReadableKey() + + "; unable to read BeanShell script", evalError ); + } + catch ( FileNotFoundException e ) + { + containerRealm.display(); + throw new ComponentInstantiationException( "Cannot build component for: " + + componentDescriptor.getHumanReadableKey() + + "; unable to read BeanShell script", e ); + } + catch ( IOException e ) + { + throw new ComponentInstantiationException( "Cannot build component for: " + + componentDescriptor.getHumanReadableKey() + + "; unable to read BeanShell script", e ); + } + finally + { + IOUtil.close( reader ); + } + + return result; + } + +} diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 0000000..7a66e02 --- /dev/null +++ b/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,17 @@ + + + + org.codehaus.plexus.component.factory.ComponentFactory + org.codehaus.plexus.component.factory.bsh.BshComponentFactory + bsh + + bsh + + + + org.codehaus.plexus.component.configurator.ComponentConfigurator + org.codehaus.plexus.component.factory.bsh.BshComponentConfigurator + bsh + + + diff --git a/src/test/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.java b/src/test/java/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.java new file mode 100644 index 0000000..58f8138 --- /dev/null +++ b/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.class ); + + assertNotNull( hello ); + + hello.initialize(); + + hello.start(); + + hello.hello(); + + hello.dispose(); + } +} diff --git a/src/test/java/org/codehaus/plexus/component/factory/bsh/Hello.java b/src/test/java/org/codehaus/plexus/component/factory/bsh/Hello.java new file mode 100644 index 0000000..231afa7 --- /dev/null +++ b/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(); +} diff --git a/src/test/resources/DefaultHello.bsh b/src/test/resources/DefaultHello.bsh new file mode 100644 index 0000000..7c38aae --- /dev/null +++ b/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; diff --git a/src/test/resources/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.xml b/src/test/resources/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.xml new file mode 100644 index 0000000..9e6b554 --- /dev/null +++ b/src/test/resources/org/codehaus/plexus/component/factory/bsh/BshComponentFactoryTest.xml @@ -0,0 +1,18 @@ + + + + + org.codehaus.plexus.component.factory.bsh.Hello + /DefaultHello.bsh + bsh + + +