diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..83f8759 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,37 @@ +# Agent guide for codehaus-plexus.github.io + +This repository is the source of the Codehaus Plexus organization site at + (`org.codehaus.plexus:plexus-site`, `pom` packaging). It has no +Java code and no test suite. Pages are Markdown under `src/site/markdown`: the overview +(`index.md`), `get-involved.md`, and the retired Plexus container documentation under `guides/` and +`ref/`. `src/site/site.xml` defines the menu, and `apt-old/`, `src/site/xdoc` and `src/site/old` +hold older material that is not rendered. The published URLs of the container guides are linked +from a lot of external writing: do not move, rename or delete a page, and do not change its +headings. The container tutorials are short notes that point to +`guides/migrating-from-plexus-container.md`; put new migration advice there, not in the old pages. + +## Build and test + +- Run `mvn site` to render the site into `target/site`. The reports configured in the POM are the + `maven-project-info-reports-plugin` team, issue-management, licenses and scm reports. +- The site is the organization page, so `maven-scm-publish-plugin` publishes it to the `master` + branch (`scmBranch` in the POM), not to `gh-pages`. `mvn site-deploy` does that; the + `site.yml` workflow runs the same publish through the shared `codehaus-plexus/.github` site + workflow, and its `dry-run` input builds without committing. Publishing steps are in + `RELEASING.md` of that shared repository. +- `.github/workflows/maven.yml` calls the shared `codehaus-plexus/.github` build workflow (the + default `mvn verify javadoc:javadoc` on the shared JDK and operating system matrix) and then the + shared deploy workflow. +- Run `mvn spotless:apply` on JDK 17 to 21 before pushing; it also formats Markdown. + +## Documentation updates + +A change that users or contributors can notice ships with the documentation it affects, in the +same pull request. A refactor with no visible effect needs none. + +- A library gets a new site, is retired, or changes its one-line description: the matching entry in + `src/site/markdown/index.md`, under Libraries, Components, Tooling or Retired. +- A page is added or removed: the menu in `src/site/site.xml`. +- The way the site is built or published: `README.md` and the Build and test section of this file. +- A new convention, build gate or fixture: this file. + diff --git a/README.md b/README.md index 4ca6b9b..1c5baa4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # Codehaus Plexus site -This repository holds the source for the [Codehaus Plexus organization site](https://codehaus-plexus.github.io/), including the component index and reference pages. +This repository holds the source of the [Codehaus Plexus organization site](https://codehaus-plexus.github.io/): +the list of Plexus libraries, with a link to each project site, and the documentation of the retired +Plexus container. Each library publishes its own site from its own repository. -Maintainers publish the site as described in [RELEASING.md](https://github.com/codehaus-plexus/.github/blob/master/RELEASING.md) in the shared `.github` repository. +Run `mvn site` to render the site into `target/site`. Maintainers publish it as described in +[RELEASING.md](https://github.com/codehaus-plexus/.github/blob/master/RELEASING.md) in the shared +`.github` repository. Contributor notes are in [AGENTS.md](AGENTS.md). diff --git a/src/site/markdown/guides/developer-guide/appendices/javadoc-tags-reference.md b/src/site/markdown/guides/developer-guide/appendices/javadoc-tags-reference.md index 27c664b..2c49326 100644 --- a/src/site/markdown/guides/developer-guide/appendices/javadoc-tags-reference.md +++ b/src/site/markdown/guides/developer-guide/appendices/javadoc-tags-reference.md @@ -6,43 +6,18 @@ author: date: 2006-07-09 --- -`The contents of this document are a work in progress` - # Javadoc Tags used by Plexus tools -Here is a reference of the Javadoc annotations that can be used to 'decorate' the Java sources to allow Plexus tools like Component Descriptor Creator (CDC) to generate Component Descriptors. - -|**Tag/Annotation**|**Available on**|**Required**|**Descriptor Element**| -|---|---|---|---| -|[@plexus.component](#@plexus.component)|Class|Yes|Indicate to Plexus CDC that the class is a component| -|[@plexus.configuration](#@plexus.configuration)|Field|No|Tell Plexus CDC that this item should be configured through the `components.xml`| -|[@plexus.requirement](#@plexus.requirement)|Field|No|Indicate to Plexus CDC that the field is required by the component| +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page listed the Javadoc tags read by the Component Descriptor Creator. # @plexus.component -The `@plexus.component` tag is used to show that the class it annotates is a plexus component. This will add a ` element to the ` in components.xml. The following parameters are available, but remember the `role` is required. The text in the javadoc tag describing this class is copied into the component's ` tag. - -|**Parameter**|**Required**|**Description**| -|---|---|---| -|role|Yes|The role that this class provides an implementation for (usually the class name of an implemented Interface| -|role-hint|No|The hints are used to differentiate multiple implementations of the same role| -|version|No|Set the version of the component| +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection) and [Component index](/guides/migrating-from-plexus-container.html#Component_index). # @plexus.configuration -The `@plexus.configuration` tags are used to mark fields in a class for configuration through the `components.xml`. - -|**Parameter**|**Required**|**Description**| -|---|---|---| -|default-value|Currently|The default values are currently required for the ` tag to be written to `components.xml`.| +Replaced by [Configuration](/guides/migrating-from-plexus-container.html#Configuration). # @plexus.requirement -Tagging a field with `@plexus.requirement` will tell plexus to inject the required component or list of components before the component itself is started. Fields can be of the type of the Interface defining the component you wish to be injected or of type `java.util.List` or `java.util.Map`. - -Fields of type `java.lang.List` will have a list of components injected whereas a field of type `java.lang.Map` will have a mapping in the form of `role-hint -> component`. The `role` parameter is required if using a `List` or `Map` whereas a role-hint is not allowed. - -|**Parameter**|**Required**|**Description**| -|---|---|---| -|role|No. Yes if the field is a `List` or a `Map`|The role parameter is used to tell plexus what Component role you are interested in. For singleton fields their type is used as a default.| -|role-hint|No. Not allowed if the field is a `List` or a `Map`|Links to the role-hint defined by a component when looking up a component. Not allowed with `List` or `Map` fields, as they return all `role-hint`s.| +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection). diff --git a/src/site/markdown/guides/developer-guide/building-applications/cdc.md b/src/site/markdown/guides/developer-guide/building-applications/cdc.md index d80d8f1..afb7c1f 100644 --- a/src/site/markdown/guides/developer-guide/building-applications/cdc.md +++ b/src/site/markdown/guides/developer-guide/building-applications/cdc.md @@ -6,114 +6,18 @@ author: date: 2006-07-09 --- -`The contents of this document are a work in progress` - # Plexus Component Descriptor Creator -**NOTE: This document and the CDC itself is currently a work in progress.** - -The Component Descriptor Creator (or CDC for short) is a tool that will create the `components.xml` file from your Java code. It uses JavaDoc tags to gather the information it needs to create the component descriptor. - -There is a tag for marking components, requirements and configuration. Each of the tags can have parameters as documented below. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page described the Javadoc tags that generated `components.xml`. ## Component Tag Parameters -|**Tag**|**Required**|**Description**| -|---|---|---| -|role|y|The role of the component.| -|role-hint|n|The role-hint of the component.| -|version|n|The component version.| -|lifecycle-handler|n|The lifecycle handler of the component. _TODO: link to the different lifecycle handlers_| -|instantiation-strategy|n|The instantiation strategy of the component. _TODO: link to the different instantiation strategies_| - - - - - -``` -package org.foo; - -/** - * @plexus.component - * role="com.foo.ActionManager" - * lifecycle-handler="plexus-configurable" - */ -public class DefaultActionManager - extends AbstractLogEnabled - implements ActionManager, Serviceable -{ -``` - - -This will be generated in component.xml: - -``` - - org.foo.ActionManager - org.foo.DefaultActionManager - plexus-configurable - -``` +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection) and [Component index](/guides/migrating-from-plexus-container.html#Component_index). ## Requirement Tag Parameters -These tags are used on fields to state requirements. TODO: it should be possible to override the role for a normal field. - -|**Tag**|**Required**|**Description**| -|---|---|---| -|role|y/n|The role of the component. Only required if the field is a List or Map| -|role-hint|n|The role-hint of the component.| - -``` -/** - * @plexus.requirement - * role-hint="foo" - */ -private ActionManager actionManager; -``` - - -This will be generated in component.xml: - -``` - - org.foo.MyComponent - org.foo.MyComponentImplementation - - - org.foo.ActionManager - foo - actionManager - - - -``` +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection). ## Configuration Tag Parameters -Note that the default value tag won't be required in the future when these tags will be used to generate a separate configuration declaration section. - -|**Tag**|**Required**|**Description**| -|---|---|---| -|default-value|y|Sets the default value for the configuration field| - -``` -/** - * @plexus.configuration - * default-value="Trygve" - */ -private String name; -``` - - -This will be generated in component.xml: - -``` - - org.foo.MyComponent - org.foo.MyComponentImplementation - - Trygve - - -``` +Replaced by [Configuration](/guides/migrating-from-plexus-container.html#Configuration). diff --git a/src/site/markdown/guides/developer-guide/building-applications/index.md b/src/site/markdown/guides/developer-guide/building-applications/index.md index ca5e9bf..d60b6a9 100644 --- a/src/site/markdown/guides/developer-guide/building-applications/index.md +++ b/src/site/markdown/guides/developer-guide/building-applications/index.md @@ -8,217 +8,24 @@ date: 2006-06-17 # Building Plexus Applications and Runtimes -To be able to build Plexus applications and runtimes you'll need: - -- The Plexus mojo - -- The Plexus application archetype - -- The Plexus runtime archetype - -`TODO: Make a link to the maven site that explains what a archetype is.` +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page built a Plexus component, application and runtime. # Introduction -Some stub directories will be created: - -[`/my-component`] - Here we'll make a Plexus component - -[`/my-application`] - Here we'll make an application - -[`/my-runtime`] - Here we'll make a runtime that will host your application. This runtime will contain startup scripts for Unix, Windows and OS X and will be completly standalone. +See the [migration guide](/guides/migrating-from-plexus-container.html). # Creating a Simple Plexus Component -## Making the Component Stub - -``` -$ mvn archetype:create \ - -DarchetypeGroupId=org.codehaus.plexus \ - -DarchetypeArtifactId=plexus-archetype-component-simple \ - -DarchetypeVersion=1.0-alpha-1-SNAPSHOT \ - -DgroupId=mygroup \ - -DartifactId=my-component \ - -Dversion=1.0-SNAPSHOT \ - -Dpackage=my.component -``` - -## Building the Plexus Component - -To build the component simply type in `/my-component`: - -``` -$ mvn install -``` - -You should now have a packaged Plexus component in `target/my-component-1.0-SNAPSHOT.jar` +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection) and [Component index](/guides/migrating-from-plexus-container.html#Component_index). # Creating a Simple Plexus Application -## Making the Application Stub - -``` -$ mvn archetype:create \ - -DarchetypeGroupId=org.codehaus.plexus \ - -DarchetypeArtifactId=plexus-archetype-application \ - -DarchetypeVersion=1.0-alpha-1-SNAPSHOT \ - -DgroupId=mygroup \ - -DartifactId=my-application \ - -Dversion=1.0-SNAPSHOT \ - -Dpackage=my.app -``` - -## Adding the Plexus Component dependency - -You need to add the following dependency in `/my-application` pom: - -``` - - mygroup - my-component - 1.0-SNAPSHOT - -``` - -and in `src/conf/application.xml`, add this so the Plexus component will be loaded at startup: - -``` - - - mygroup.HelloWorld - - -``` - -## Building the Plexus Application - -To build the application simply type in `/my-application`: - -``` -$ mvn plexus-appserver:assemble-app -``` - -and you should have a application in `target/plexus-application`. Inside the exploded application there will be two directories: `conf` and `lib`. The `conf` directory contains the configuration file for your application and `lib` contains all the dependencies the application has. - -If you want to do some extra processing on these files or possibly add your own files you can have a plugin with a post goal on `plexus:app` and it would be invoked before the application was packaged. - -If you now run the `plexus-appserver:package-app` goal: - -``` -$ mvn plexus-appserver:package-app -``` - -the resulting JAR file will be ready for deployment in a Plexus runtime. Our example application JAR will be `target/my-application-1.0-SNAPSHOT.jar`. - -you can run the above commands in one: - -``` -$ mvn install -``` +Replaced by [Looking up components](/guides/migrating-from-plexus-container.html#Looking_up_components). # Creating the Runtime -## Making the Runtime Stub - -Creating the stub runtime is as easy as creating the application: - -``` -$ mvn archetype:create \ - -DarchetypeGroupId=org.codehaus.plexus \ - -DarchetypeArtifactId=plexus-archetype-runtime \ - -DarchetypeVersion=1.0-alpha-1-SNAPSHOT \ - -DgroupId=mygroup \ - -DartifactId=my-runtime \ - -Dversion=1.0-SNAPSHOT \ - -Dpackage=my.runtime -``` - -## Building the Runtime - -``` -$ mvn package -``` - -You should now have a usable runtime in `target/plexus-runtime` and a packaged runtime in `target/my-runtime-1.0-SNAPSHOT.jar`. Now lets copy over the application: - -``` -$ cp ../my-application/target/my-application-1.0-SNAPSHOT.jar \ - target/plexus-app-runtime/apps -``` - -You can also add a dependency on my-application in the my-runtime pom, so it won't be necessary to copy the application manually in the runtime. - -``` - - mygroup - my-application - 1.0-SNAPSHOT - plexus-application - -``` - -Now you have a working Plexus runtime with your application installed. To start it run: - -``` -$ sh target/plexus-app-runtime/bin/plexus.sh -``` - -Hopefully you should now have a runtime running with. The message "Starting Hello Component." sended by `my-component` at startup must appears in logs. +Replaced by [Parts without a replacement](/guides/migrating-from-plexus-container.html#Parts_without_a_replacement). # Getting fancy: Adding a Shared Servlet Container -Plexus runtimes can have a set of services thats shared between the applications. One very useful service is a servlet container. This enables several isolated applications to share the same Jetty instance without the need for complicated Apache HTTPD proxy setups. The servlet container service will all the web in a configured directory. The application contains a commented out configuration section for the servlet container which you must uncomment so the service would be enabled. - -`NOTE: This example assumes that you have the runtime that was created in the last section.` - -First add the service dependency into the runtime: - -``` - - org.codehaus.plexus - plexus-appserver-service-jetty - 2.0-alpha-1 - plexus-service - -``` - -Now we need to add a web application to the application. As a simple web application we're using the Jetty JavaDocs. Add this in `my-application` pom: - -``` - - jetty - javadoc - 4.2.23RC0 - war - -``` - -Now we need to configure the servlet container service so it knows where to find the web applications. In `src/conf/application.xml` uncomment the servlet container section. Now bundle the application again: - -``` -$ mvn install -``` - -We suppose there you added `my-application` dependency in `my-runtime` pom. Execute this commands from `/my-runtime` - -``` -$ mvn package -``` - -Now when the application server is started again it should - -- Deploy the servlet container. - -- Boot Jetty. - -- Deploy the application. - -- The servlet container will detect that a new application was deployed and deploy the JavaDoc WAR. - -So lets start it: - -``` -$ sh target/plexus-app-runtime/bin/plexus.sh -``` - -And open your browser to http://localhost:8080/ +Replaced by [Parts without a replacement](/guides/migrating-from-plexus-container.html#Parts_without_a_replacement). diff --git a/src/site/markdown/guides/developer-guide/building-components/component-testing.md b/src/site/markdown/guides/developer-guide/building-components/component-testing.md index a2ab2a0..a8d0734 100644 --- a/src/site/markdown/guides/developer-guide/building-components/component-testing.md +++ b/src/site/markdown/guides/developer-guide/building-components/component-testing.md @@ -4,359 +4,14 @@ author: Michal Maczka date: 2006-06-17 --- -`The contents of this document are a work in progress` - # Testing Plexus Components -If you are using Plexus you are going to use and most likely write your own components. In the second case you will need to be able to test them. Plexus container uses quite a rare approach for testing components: components are tested inside the container. - -Like a fish needs water, a component by its \[definition\] needs a container. Fish should be only lifted from the water - its natural environment - for a short time, as fish needs water to breathe and water supports the weight of the fish. Keep the fish in water; keep the component in its natural environment - the container. As there are fishes, which are hard to catch, there are components, which are hard to test outside the container. And as there are some fishes, which can be never caught, there are some components, which practically cannot be tested outside the container. - -Important remark: \*component testing\* is not exactly the same thing as \*class testing\*. In case of Plexus a component in the simplest possible case is a java class plus the component descriptor. Traditional unit testing allows you to test java classes, but you should be able to test if component as a whole is error free and ready to be used. It means that component's metadata must also be validated - you want to be sure that component definition was written properly, component's requirements were stated properly, correct component profile was chosen etc. - -Another thing, which is so appealing about this approach is the fact that testing environment and production environment are exactly the same - this eliminates some surprises which otherwise would appear only when component was deployed. - -Last but not least -although it might be counter-intuitive such approach is really making testing easier! Plexus and other lightweight containers have proven to \*be a perfect mock infrastructure\*: the container is used for "plumbing" components with its depended components. That is why a container is a perfect tool for injecting Mock implementation during test time and real implementation at the runtime. - -Note that Plexus is quite "lightweight" and it usually can be embedded a couple of times per second. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page tested components inside the container. ## Example -Component Interface - -``` -package org.codehaus.plexus.tutorial.lesson2; - -public interface HelloWorld -{ - String ROLE = HelloWorld.class.getName(); - - String getGreeting(); -} -``` - -Component Implementation: - -``` -package org.codehaus.plexus.tutorial.lesson2; - -public class DefaultHelloWorld implements HelloWorld -{ - public String getGreeting() - { - return "Hello World!"; - } -} -``` - -Component Test Case: - -``` -package org.codehaus.plexus.tutorial.lesson2; - -import org.codehaus.plexus.PlexusTestCase; - -public class DefaultHelloWorldTest - extends PlexusTestCase -{ - public void testHelloWorld() - throws exception - { - HelloWorld helloWorld = ( HelloWorld ) lookup( HelloWorld.ROLE ); - - assertEquals( "Hello World!", helloWorld.getGreeting() ); - } -} -``` - -Normal \[component discovery\] is performed during the initialization of the test case. It means that if your component descriptor was alraedy added to /META-INF/plexus/components.xml file it will be visible during tests. - -In case when you want to override the deafults the only thing you have to do is to create new xml file having the name which matches the class name but with extentinon ".xml". This file must be placed in the same package as the class and be visible in the unit test's classpath. - -In case of DefaultHelloWorldTest the file should be names DefaultHelloWorldTest.xml - -``` - - - - org.codehaus.plexus.tutorial.lesson2.HelloWorld - org.codehaus.plexus.tutorial.lesson2.DefaultHelloWorld - - - -``` +Replaced by [Testing components](/guides/migrating-from-plexus-container.html#Testing_components) and [Plexus Testing](https://codehaus-plexus.github.io/plexus-testing/). ## Container Driven Testing -Now we will show an example how container can help in component testing and how it can be used for providing "mock components" during tests. - -As exmplained above plexus provides a possiblity of perform lightning-fast component tests. which directly which takes place inside container. As Plexus suports IoC paradigm and it's Dependecy Injection in particular the container is a perfect envinroment for providing mock implementation of component's requirements. - - -### Implementation: - -``` -src\main\java\org\codehaus\plexus\example\CheeseConnoisseur.java - \Cheese.java - \DefaultCheeseFinder.java - \CheeseFinder.java - \CheeseEater.java -src\main\resources\META-INF\plexus\components.xml -``` - -### Tests: - -``` -$root\src\main\test\org\codehaus\plexus\example\ - MockCheeseFinder.java - CheeseConnoisseurTest.java - CheeseConnoisseurTest.xml -``` - -Now file by file we will explain what is inside of each of files: - -``` -$root\src\main\java\org\codehaus\plexus\example\Cheese.java -``` - -``` -package org.codehaus.plexus.example; - -public class Cheese -{ - String name; - - int price; - - public Cheese( String name, int price ) - { - this.name = name; - - this.price = price; - } - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - public int getPrice() - { - return price; - } - - public void setPrice( int price ) - { - this.price = price; - } -} -``` - -``` -$root\src\main\java\org\codehaus\plexus\example\CheeseEater.java -``` - -``` -package org.codehaus.plexus.example; - -public interface CheeseEater -{ - String ROLE = CheeseEater.class.getName(); - - Cheese chooseCheese(); - -} -``` - -``` -$root\src\main\java\org\codehaus\plexus\example\CheeseFinder.java -``` - -``` -package org.codehaus.plexus.example; - -import java.util.List; - -public interface CheeseFinder -{ - String ROLE = CheeseFinder.class.getName(); - - List getAllCheeses(); -} -``` - -``` -$root\src\main\java\org\codehaus\plexus\example\DefaultCheeseFinder.java -``` - -``` -package org.codehaus.plexus.example; - -import java.util.List; - -public class DefaultCheeseFinder implements CheeseFinder -{ - - public List getAllCheeses() - { - List retValue = null; - - //... - - return retValue; - - } -} -``` - -``` -$root\src\main\java\org\codehaus\plexus\example\CheeseConnoisseur.java -``` - -``` -package org.codehaus.plexus.example; - -import java.util.Iterator; -import java.util.List; - -public class CheeseConnoisseur implements CheeseEater -{ - /** - * @component.requirement - */ - private CheeseFinder cheeseFinder; - - public Cheese chooseCheese() - { - Cheese retValue = null; - - int maxPrice = 0; - - List cheeses = cheeseFinder.getAllCheeses(); - - for ( Iterator iterator = cheeses.iterator(); iterator.hasNext(); ) - { - Cheese cheese = ( Cheese ) iterator.next(); - - int currentPrice = cheese.getPrice(); - - if ( currentPrice > maxPrice ) - { - retValue = cheese; - - maxPrice = currentPrice; - } - } - - return retValue; - } -} -``` - -``` -$root\src\main\resources\META-INF\plexus\components.xml -``` - -``` - - - - org.codehaus.plexus.example.CheeseEater - org.codehaus.plexus.example.CheeseConnoisseur - - - org.codehaus.plexus.example.CheeseFinder - - - - - -``` - -### Test Code: - -``` -$root\src\test\java\org\codehaus\plexus\example\CheeseConnoisseurTest.java -``` - -``` -package org.codehaus.plexus.example; - -import org.codehaus.plexus.PlexusTestCase; - -public class CheeseConnoisseurTest extends PlexusTestCase -{ - - private CheeseEater connoisseur; - - protected void setUp() throws Exception - { - super.setUp(); - - connoisseur = ( CheeseEater ) lookup( CheeseEater.ROLE ); - } - - public void testConnoisseur() - { - Cheese cheese = connoisseur.chooseCheese(); - - assertEquals( "Gruyere", cheese.getName() ); - } -} -``` - -``` -$root\src\test\java\org\codehaus\plexus\example\MockCheeseFinder.java -``` - -``` -package org.codehaus.plexus.example; - -import java.util.List; -import java.util.LinkedList; - -public class MockCheeseFinder implements CheeseFinder -{ - public List getAllCheeses() - { - List retValue = new LinkedList(); - - addCheese( retValue, "Gruyere", 120 ); - - addCheese( retValue, "Appenzell", 100 ); - - addCheese( retValue, "Vacherin-Fribourgeois", 80 ); - - return retValue; - } - - private void addCheese( List cheeses, String name, int price ) - { - Cheese chesee = new Cheese( name, price ); - - cheeses.add( chesee ); - - } -} -``` - -``` -$root\src\test\java\org\codehaus\plexus\example\CheeseConnoisseurTest.xml -``` - -``` - - - - - org.codehaus.plexus.example.CheeseFinder - org.codehaus.plexus.example.MockCheeseFinder - - - -``` +Replaced by [Testing components](/guides/migrating-from-plexus-container.html#Testing_components) and [Plexus Testing](https://codehaus-plexus.github.io/plexus-testing/). diff --git a/src/site/markdown/guides/developer-guide/configuration/component-descriptor.md b/src/site/markdown/guides/developer-guide/configuration/component-descriptor.md index c608c40..eb3aaf9 100644 --- a/src/site/markdown/guides/developer-guide/configuration/component-descriptor.md +++ b/src/site/markdown/guides/developer-guide/configuration/component-descriptor.md @@ -4,286 +4,20 @@ author: Rahul Thakur date: 2006-06-17 --- -`The contents of this document are a work in progress` - # Plexus Component Descriptor -We are discussing the component descriptors for components which are compatible with [Plexus Personality](../personalities/plexus-personality.html). We show a limited picture of what can be done with components and component descriptors in Plexus. - -Nevertheless what you learn here should be sufficient to write even a large Plexus application! - -A component descriptor describes the properties of a component required by the container in order to manage the lifecycle of that component. Let's take a look at the simplest example of a component descriptor: - -``` - - - - foo.Foo - foo.DefaultFoo - - - -``` - -It starts off with a `component` tag, then values for the `role` and `implementation` tags are defined. The `role` tag defines the interface provided by this component. It is usually the name of the Java interface. Names of the classes (including abstract) are also allowed. You are not allowed to use arbitrary strings. The `implementation` tag tells Plexus what you want to use to implement the specified `role`. In a normal case you will have to specify the name of the java class (`foo.DefaultFoo` in the example above), which implements the given interface (role). - -If there is more than one component which provides an implementation of a given role you can differentiate them with the help of the `role-hint` attribute: +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page documented the `components.xml` descriptor format. -``` -... - - foo.SomeComponent - componentA - foo.FooA - - - - foo.SomeComponent - componentB - foo.FooB - -... -``` - -The `role` and the `role-hint` are what defines [component identity](../building-components/component-identity.html) and what you use to look up your component from Plexus. The `role-hint` tag is optional. It serves as an extra id qualifier that allows you to differentiate components of the same type (role). You can use any arbitrary string you like as the value of the `role-hint` attribute. Note that you can deploy the same implementation of the component two or more times with different `role-hint`s e.g.: - -``` -... - - foo.SomeComponent - instance-one - foo.FooA - - - - foo.SomeComponent - instance-two - foo.FooA - -... -``` +For the replacement, see [Component index](/guides/migrating-from-plexus-container.html#Component_index). ## Requirements -Components aren't very useful as isolated entities nor are they always ready to use standalone. They become useful when we connect them together with other components and provide configuration settings to them. There are several different ways to compose your system from components. - -The default, and the simplest of them, is a part of [Plexus Personality](../personalities/plexus-personality.html) This uses a strategy called 'field injection' for wiring components. This means that Plexus takes selected objects and assigns them to fields of component objects. - -How does Plexus know into which fields requirements should be injected and what those requirements are? There is a `requirements` section in the component descriptor where you declare what components you depend on: - -``` -... - - ... - - - ... - - - ... - - - -... -``` - -In a simple case the declaration of a dependency looks like this: - -``` - ... - - org.codehaus.plexus.ComponentA - - ... -``` - -In the case when you want to declare a dependecy on a component which has specified both `role` and `role-hint` attributes you use: - -``` - ... - - org.codehaus.plexus.ComponentB - foo - - ... -``` - -In any case Component Composer will try to find a matching field and property for the given requirements. In the standard case the component composer will try to find a field in the component class (this is usually a private field), which has a type which matches the requirement's `role`. - -For example in the case of this Java class: - -``` -package foo; -public class SomeComponentImpl -{ - // this is a "requirement" of this component - org.codehaus.plexus.ComponentA a; - - // this is ordinary field - int b; -} -``` - -You will need to prepare the following component descriptor which lists ComponentA as a requirement: - -``` -... - - foo.SomeComponent - foo.SomeComponentImpl - - - org.codehaus.plexus.ComponentA - - - -... -``` +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection) and [converting Plexus components to JSR-330](https://eclipse.dev/sisu/org.eclipse.sisu.plexus/conversion-to-jsr330.html) in the Sisu documentation. ### Collections -Plexus can also inject Maps, List or arrays of dependent components. In the case of arrays of components the same approach is applied as in the case of "singular" dependencies. The only difference is that all visible implementations of a given role will be used. - -Java: - -``` -package foo; -public class SomeComponentImpl -{ - org.codehaus.plexus.ComponentA a[]; -} -``` - -XML Descriptor: - -``` -... - - foo.SomeComponent - foo.SomeComponentImpl - - - org.codehaus.plexus.ComponentA - - - - -... - - - org.codehaus.plexus.ComponentA - A - ... - - - org.codehaus.plexus.ComponentA - B - ... - -... -``` - -In case of a `List`, or a `Map` you must explicitly define where dependencies should be injected. You can do this with the help of the `field-name` tag: - -XML Descriptor: - -``` -... - - ... - - - org.codehaus.plexus.ComponentB - foo - mapA - - - org.codehaus.plexus.ComponentB - bar - listB - - - -... -``` - -Java: - -``` -package foo; -public class SomeComponentImpl -{ - private Map mapA; - private List listB; -} -``` - -**Note** that when using a Map the value of a component's `role-hint` is used as the key and the component instance is used as the value. - -You can also use the `field` tag for a "singular" component's requirements. - -XML Descriptor: - -``` -... - - ... - - - org.codehaus.plexus.ComponentB - foo - b1 - - - org.codehaus.plexus.ComponentB - bar - b2 - - - -... -``` - -Java: - -``` -package foo; -public class SomeComponentImpl -{ - //(component with role-hint = "foo" will be injected here) - org.codehaus.plexus.ComponentB b1; - - //(component with role-hint = "bar" will be injected here) - org.codehaus.plexus.ComponentB b2; -} -``` - -Explicit specification into which field dependencies should be injected is considered to be a good pattern and might even be required in future versions of Plexus. +Replaced by [Looking up components](/guides/migrating-from-plexus-container.html#Looking_up_components). ### Configuration -Lastly, there is an optional configuration section which is used to configure your component. - -``` -... - - ... - - bleh - - 1 - 2.0f - - - -... -``` - -You may read more about it [here](./plexus-auto-configuration.html). - -And that's all you need to know about component configuration to get you started! - -**Important remark**: Component configuration and component requirements (definition of dependencies on some other components) are separated in Plexus. In some popular containers like Spring this is not the case. The reason for this is that component requirements are constant - components always needs to use the same set of services provided by other components in order to function properly. But configuration of a component is more dynamic. For example components which provide an implementation of a jdbc database connection pool must always be configured in each application which uses it. - - -If you want to learn more about more advanced options you can read [Component Descriptor](./component-descriptor-specification.xml). +Replaced by [Configuration](/guides/migrating-from-plexus-container.html#Configuration). diff --git a/src/site/markdown/guides/developer-guide/configuration/index.md b/src/site/markdown/guides/developer-guide/configuration/index.md index 7e68153..b6e8345 100644 --- a/src/site/markdown/guides/developer-guide/configuration/index.md +++ b/src/site/markdown/guides/developer-guide/configuration/index.md @@ -6,56 +6,16 @@ date: 2006-06-17 # **The contents of this document are a work in progress** -# Configuration files - -## Plexus is using the following configuration files - -- plexus.xml - -- plexus.properties - -- components.xml files stored in jars - -!plexus-configuration-files.gif! - -All components which can be used by plexus must have a [Component Descriptor](./component-descriptor.html). - -Component Descriptors can be declared in two places: **plexus.xml**and in**components.xml** files which are kept in jars (META-INF/plexus/components.xml). - -**plexus.xml** files allows you to configure the following aspects of application: - -- Define new component descriptors +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page listed `plexus.xml`, `plexus.properties` and `components.xml`. -- Override component descriptors which are defined in components.xml files - -- Set up LoggerManager for the Application. - -- Choose which component should be loaded on startup - - - -- Location of [component repository]() - -Plexus component descriptor contains many pieces which must be provided only once. For example componet requiremnets, profile etc are pratically constant. - -That's why it is profitable to put such information into jar files and reuse it. +# Configuration files -**plexus.properties** file is used for seeding [plexus context](/404.html) which is then used for interpolation of variables in xml configuration files (see the explanation below) +See the [migration guide](/guides/migrating-from-plexus-container.html). ## Component configuration through `/META-INF/plexus/components.xml` -When starting up Plexus will start discovering components. The default configuration uses the [DefaultComponentDiscoverer](http://svn.plexus.codehaus.org/plexus/trunk/plexus-container/src/java/org/codehaus/plexus/component/discovery/DefaultComponentDiscoverer.java?rev\=HEAD&view\=auto) to discover components. - -The [DefaultComponentDiscoverer](/404.html) will look for `/META-INF/plexus/components.xml` files using [ClassLoader.getResources()](http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResources(java.lang.String)). For getting your components picked up by plexus all you need is to have the [components.xml](/404.html) file in your jar. +Replaced by [Component index](/guides/migrating-from-plexus-container.html#Component_index). ## Interpolation of configuration files -Plexus will interpolate all the variables that are strings in the plexus context in the configuration file. For instance, the "plexus.home" is a context variable that tells you the location of the Plexus install. To use that in your configuration, you would do something like this: - -``` - - ${plexus.home}/directory - -``` - -This would automatically be expanded to the full directory name when you configure your component. +Replaced by [Configuration](/guides/migrating-from-plexus-container.html#Configuration). diff --git a/src/site/markdown/guides/developer-guide/configuration/plexus-auto-configuration.md b/src/site/markdown/guides/developer-guide/configuration/plexus-auto-configuration.md index 107a445..b7cc613 100644 --- a/src/site/markdown/guides/developer-guide/configuration/plexus-auto-configuration.md +++ b/src/site/markdown/guides/developer-guide/configuration/plexus-auto-configuration.md @@ -4,201 +4,10 @@ author: Michal Maczka date: 2004-10-13 --- -`The contents of this document are a work in progress` - # Plexus Auto Configuration -## Auto configuration is ... - -If you are familiar with libraries like [xstream](http://xstream.codehaus.org) you will feel at home. If not, it's simple enough anyway. - -The best way to understand how the plexus ComponentConfigurator functions is by example. Assuming that the auto-configuration mechanism is applied to class: - -**com.MyComponent** - -``` -class com.MyComponent implements com.SomeInterface -{ - private String propertyA; - - private int propertyB; - - ... -} -``` - -with a plexus configuration like so: - -``` - - com.SomeInterface - com.MyComponent - - foo - 1 - - -``` - -The actions the plexus ComponentConfigurator would perform on the instance of component would be something like this: - -``` -com.SomeInterface component = new com.MyComponent(); - -component.propertyA = "foo"; - -component.propertyB = 1; -``` - -### Types Supported by Autoconfiguration - -#### Basic - -- java.lang.Boolean & boolean - -- java.lang.Byte & byte - -- java.lang.Character & char - -- java.lang.Double & double - -- java.lang.Float & float - -- java.lang.Integer & int - -- java.lang.Long & long - -- java.lang.Short & short - -- java.lang.StringBuffer - -- java.lang.String - -- java.util.Date (todo: document supported patterns) - -- java.math.BigDecimal - -- java.math.BigInteger - -#### Composite types (Object properties) - -- **Object with properties** - -_Component implementation:_ +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page explained how the container filled component fields from XML. -``` -class com.MyComponent -{ - private Person person; - - ... -} - -class com.Person -{ - private String firstname; - - private String lastname; - - ... -} -``` - -_Component configuration :_ - -``` - - - Baltzar - Gabka - - -``` - -_Actions taken by Component Configurator:_ - -``` -Person person = new Person(); - -person.firstname = "Baltazar"; -person.lastname = "Gabka"; - -component.person = person; -``` - -- **Collections** - -TODO: Collections example. - -- **java.lang.Properties** - -_Component implementation:_ - -``` -class com.MyComponent -{ - private Properties propertiesA; - ... -} -``` - -_Component configuration :_ - -``` - - - - key1 - value1 - - - key2 - value2 - - - -``` - -_Actions taken by Component Configurator:_ - -``` - -com.MyComponent component; - -Properties properties = new Properties(); - -properties.put( "key1", "name1" ) - -properties.put( "key2", "name2" ) - -setFieldValue( component, "propertiesA", properties ); - -component.propertiesA = properties; - -``` - -#### Advanced mapping - - - - -``` - - ala - ala - ala - -``` - -or possibly (pending implementation) +## Auto configuration is ... -``` - - - foo - - - ala - - -``` +Replaced by [Configuration](/guides/migrating-from-plexus-container.html#Configuration). diff --git a/src/site/markdown/guides/developer-guide/index.md b/src/site/markdown/guides/developer-guide/index.md index 4319b5c..94bef08 100644 --- a/src/site/markdown/guides/developer-guide/index.md +++ b/src/site/markdown/guides/developer-guide/index.md @@ -6,10 +6,12 @@ author: date: 2006-06-17 --- -`The contents of this document are a work in progress` + # Table of Contents +This guide documented the retired Plexus container. Pages that taught the container now point to the replacement, and the conceptual pages are kept as written. To move to JSR-330 and Eclipse Sisu, see the [migration guide](/guides/migrating-from-plexus-container.html). + - [Introduction to Plexus](./introduction.html) - [Developing Components](./developing-components.html) diff --git a/src/site/markdown/guides/developer-guide/introduction-to-components.md b/src/site/markdown/guides/developer-guide/introduction-to-components.md index 32f1c5e..edd9e0e 100644 --- a/src/site/markdown/guides/developer-guide/introduction-to-components.md +++ b/src/site/markdown/guides/developer-guide/introduction-to-components.md @@ -12,7 +12,7 @@ date: 2006-06-17 Other projects have also offered what a component may be: -- [ PicoContainer](http://picocontainer.codehaus.org/Components) +- [ PicoContainer](http://picocontainer.com/) - [ Avalon](http://avalon.apache.org/central/cop/index.html) diff --git a/src/site/markdown/guides/developer-guide/personalities/index.md b/src/site/markdown/guides/developer-guide/personalities/index.md index 368aff4..cc92d8a 100644 --- a/src/site/markdown/guides/developer-guide/personalities/index.md +++ b/src/site/markdown/guides/developer-guide/personalities/index.md @@ -8,7 +8,7 @@ date: 2006-06-17 # Overview -Plexus personalities give you the capability to customize how your component lifecycle works. You can mix and match personalities within Plexus to meet your needs. There is the core Plexus personality for "Plexus Components" as well as personalities for [Avalon](http://avalon.apache.org) and [PicoContainer](http://picocontainer.codehaus.org) +Plexus personalities give you the capability to customize how your component lifecycle works. You can mix and match personalities within Plexus to meet your needs. There is the core Plexus personality for "Plexus Components" as well as personalities for [Avalon](http://avalon.apache.org) and [PicoContainer](http://picocontainer.com/) Which personality you should use depends on your needs. If you are just starting, you will most likely want to use the Plexus personality. However, each personality has it's own pros and cons. diff --git a/src/site/markdown/guides/developer-guide/personalities/pico-personality.md b/src/site/markdown/guides/developer-guide/personalities/pico-personality.md index 057373c..023bfa4 100644 --- a/src/site/markdown/guides/developer-guide/personalities/pico-personality.md +++ b/src/site/markdown/guides/developer-guide/personalities/pico-personality.md @@ -14,7 +14,7 @@ What characterizes Pico personality is the fact that for Pico components instant For Plexus this type of dependency injection is not fundamentally different from other types of dependency injection, which are supported by plexus: Field Dependency Injection, Setter Dependency Injection, Contextualizable Lookup etc. The main differences between Plexus and Pico container is this that our "Pico" friends strongly believe that constructor dependency injection is is superior to anything else and that container can function (almost) without any metadata. -We don't subscribe to this point of view. Plexus' native API promotes [Field Dependency Injection](/404.html) and we are recommending using it as it clearly separates two concerns: component instantiation and resolution of component's dependencies. This type of dependency injection makes the encapsulation even stronger as internals of component are not exposed via any public API. +We don't subscribe to this point of view. Plexus' native API promotes Field Dependency Injection and we are recommending using it as it clearly separates two concerns: component instantiation and resolution of component's dependencies. This type of dependency injection makes the encapsulation even stronger as internals of component are not exposed via any public API. But we leave the choice to users which type of the dependency injection is the most suitable for them. Components are all about composition and composition takes place on meta level of the container and meta data is the glue which makes it possible. We believe that any "serious" container must have rich enough metadata for effectively "plumbing" existing components. We also believe that although we do require much more metadata then Pico, the usage of Plexus is almost as simple as usage of Pico but we provide more powerful options, which are eliminated by the lack of metadata in Pico container. Note also that component testing is often even simpler in case of Plexus then in case of Pico due to the fact that we leverage container as mock infrastructure and we make a use of existing metadata so for example "requirements" (dependencies) of the component does not have to be listed specifically for unit tests. This makes unit tests shorter hence simpler. diff --git a/src/site/markdown/guides/developer-guide/personalities/plexus-personality.md b/src/site/markdown/guides/developer-guide/personalities/plexus-personality.md index 6970726..d65c8a6 100644 --- a/src/site/markdown/guides/developer-guide/personalities/plexus-personality.md +++ b/src/site/markdown/guides/developer-guide/personalities/plexus-personality.md @@ -39,7 +39,7 @@ Plexus has the ability to do automatic dependency injection. When your component ### Configuration -The Plexus personality can configure your component two ways. In the auto configuration mode, it matches the xml to fields and classes on your components using [XStream](http://xstream.codehaus.org). For example, if you have a String field named "cheese" on your component, then this would automatically set that field to "swiss". +The Plexus personality can configure your component two ways. In the auto configuration mode, it matches the xml to fields and classes on your components using [XStream](https://x-stream.github.io/). For example, if you have a String field named "cheese" on your component, then this would automatically set that field to "swiss". ``` diff --git a/src/site/markdown/guides/migrating-from-plexus-container.md b/src/site/markdown/guides/migrating-from-plexus-container.md new file mode 100644 index 0000000..5fd110e --- /dev/null +++ b/src/site/markdown/guides/migrating-from-plexus-container.md @@ -0,0 +1,229 @@ +--- +title: Migrating from the Plexus container +--- + +# Migrating from the Plexus container + +The Plexus IoC container ([plexus-containers](https://github.com/codehaus-plexus/plexus-containers)) is retired. Maven, and every library on this site, now use [JSR-330](https://jcp.org/en/jsr/detail?id=330) annotations on top of [Eclipse Sisu](https://eclipse.dev/sisu/). The old tutorials and guides keep their addresses because other sites link to them, but they no longer teach the container. This page maps each old concept to its replacement and links the maintained documentation for each step. + +## Where the maintained documentation is + +The following pages already cover most of the migration, so this page only summarizes them. + +- [Converting Plexus components to JSR-330](https://eclipse.dev/sisu/org.eclipse.sisu.plexus/conversion-to-jsr330.html) in the Sisu documentation covers `@Component`, `@Requirement`, `@Configuration` and the lifecycle interfaces, each with a before and after. +- [Maven and JSR-330](https://maven.apache.org/maven-jsr330.html) covers the POM setup and the index for plugins and extensions. +- [Sisu lifecycle support](https://eclipse.dev/sisu/org.eclipse.sisu.inject/lifecycle.html) covers `@PostConstruct` and `@PreDestroy`. +- [Plexus Testing](https://codehaus-plexus.github.io/plexus-testing/) covers JUnit 5 tests of components. +- [Maven Plugin Testing Harness](https://maven.apache.org/plugin-testing/maven-plugin-testing-harness/) and its [migration recipes](https://maven.apache.org/plugin-testing/maven-plugin-testing-harness/migration-3.4.0.html) cover tests of Mojos. + +## Components and injection + +A Plexus component is a class with a role, an optional role hint and fields marked `@Requirement`. In JSR-330 the class is a `@Named` bean, the hint becomes the name, and the requirements are `@Inject` constructor parameters. Prefer constructor injection: a component can then be created in a unit test without any container. + +Before, with the retired container: + +```java +@Component( role = Parser.class, hint = "my" ) +public class MyParser implements Parser +{ + @Requirement + private Logger logger; +} +``` + +After: + +```java +@Named( "my" ) +@Singleton +public class MyParser implements Parser +{ + private final Helper helper; + + @Inject + public MyParser( Helper helper ) + { + this.helper = helper; + } +} +``` + +A component that was not a singleton (`instantiationStrategy="per-lookup"`) drops `@Singleton`. An optional requirement becomes a parameter annotated `@Nullable` (`org.eclipse.sisu.Nullable`). Both cases, and the `Default` prefix naming rule, are in the Sisu conversion page. + +## Component index + +The container read `META-INF/plexus/components.xml`, which you wrote by hand or generated with `plexus-component-metadata` or the Javadoc-tag tools. Sisu reads `META-INF/sisu/javax.inject.Named`, a plain list of class names that the `sisu-maven-plugin` generates from the `@Named` classes at build time. Nothing needs to be written by hand. + +```xml + + + javax.inject + javax.inject + 1 + provided + + + + + + + org.eclipse.sisu + sisu-maven-plugin + + + + index-components + + main-index + + + + + + +``` + +The `main-index` goal runs in the `process-classes` phase; `test-index` does the same for test classes. Maven itself only reads the index and does not scan the class path, so a component without an index is not found. + +## Looking up components + +`container.lookup( role, hint )` becomes injection. A named bean is requested with `@Named`, and every implementation of an interface is requested with a `List` or a `Map` keyed by name. + +```java +@Inject +public MyComponent( @Named( "my" ) Parser parser, Map allParsers ) +{ + ... +} +``` + +Code that cannot be injected, such as a plugin that must pick an implementation at run time, can inject the Sisu `BeanLocator` (`org.eclipse.sisu.inject.BeanLocator`) and query it. A standalone application builds its own injector with Guice, Sisu's `SpaceModule` and `WireModule`, as shown in the [Sisu overview](https://eclipse.dev/sisu/org.eclipse.sisu.inject/). + +## Lifecycle + +`Initializable.initialize()` usually moves to the end of the constructor, or to a method annotated `@PostConstruct`. `Contextualizable` becomes an injected `@Parameters Map`. `Startable` and `Disposable` have no direct counterpart; Sisu supports `@PostConstruct` and `@PreDestroy` when its lifecycle module is enabled, which Maven 3.5 and later do. See the Sisu lifecycle page for what each annotation does and does not call. + +## Configuration + +The `` block of a component descriptor and `@Configuration` become `@Named` parameters with an expression, and a default after `:-`. + +```java +@Inject +public MyComponent( @Named( "${configDir:-target/config}" ) String configDir ) +{ + ... +} +``` + +In the Plexus compatibility layer the values come from the container context data; the Javadoc of the `org.eclipse.sisu.wire` package describes the expression syntax. A component that took a complex configuration object can instead take a plain constructor parameter. + +## Testing components + +The old test base class is a JUnit 3 class, so tests built on it cannot move to JUnit 5 without a rewrite. The replacement is the `@PlexusTest` annotation of `org.codehaus.plexus:plexus-testing`, which creates a container for each test method and injects the `@Inject` fields of the test class. + +Before: + +```java +public class MyComponentTest extends PlexusTestCase +{ + public void testIt() throws Exception + { + MyComponent component = (MyComponent) lookup( MyComponent.class ); + } +} +``` + +After: + +```java +import javax.inject.Inject; + +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@PlexusTest +class MyComponentTest +{ + @Inject + MyComponent component; + + @Test + void itWorks() + { + assertNotNull( component ); + } +} +``` + +```xml + + org.codehaus.plexus + plexus-testing + + test + + + org.junit.jupiter + junit-jupiter + + test + +``` + +With constructor injection a plain JUnit 5 test, with or without Mockito, often needs no container at all. Customizing the container, and resolving paths such as the base directory, are covered on the Plexus Testing site. + +## Testing Maven plugins + +`AbstractMojoTestCase`, with `lookupMojo` and a test POM, is replaced by the `@MojoTest` and `@InjectMojo` annotations of `org.apache.maven.plugin-testing:maven-plugin-testing-harness` 3.4.0 and later, which run on JUnit 5. + +Before: + +```java +public class MyMojoTest extends AbstractMojoTestCase +{ + public void testExecute() throws Exception + { + MyMojo mojo = (MyMojo) lookupMojo( "touch", pom ); + mojo.execute(); + } +} +``` + +After: + +```java +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; +import org.junit.jupiter.api.Test; + +@MojoTest +class MyMojoTest +{ + @Test + @InjectMojo( goal = "touch", pom = "src/test/resources/unit/project-to-test/pom.xml" ) + void execute( MyMojo mojo ) throws Exception + { + mojo.execute(); + } +} +``` + +The harness migration page lists the other replacements, such as stubs becoming `@Provides` methods. + +## Logging + +The container provided `org.codehaus.plexus.logging.Logger` through `AbstractLogEnabled` or a `@Requirement`. Use [SLF4J](https://www.slf4j.org/) instead: `LoggerFactory.getLogger( MyComponent.class )`, or `getLog()` inside a Mojo. A custom `LoggerManager` has no counterpart; the logging backend is chosen by the application, and Maven picks its own. + +## plexus-utils and plexus-xml + +The XML classes (`Xpp3Dom`, `Xpp3DomBuilder`, `Xpp3DomWriter`, the pull parser) moved out of `plexus-utils` 4 into [plexus-xml](https://codehaus-plexus.github.io/plexus-xml/), so a project that used them from `plexus-utils` adds `org.codehaus.plexus:plexus-xml`. The rest stays in [plexus-utils](https://codehaus-plexus.github.io/plexus-utils/). Where the JDK offers an equivalent, such as `java.nio.file.Files` instead of `FileUtils`, prefer the JDK. + +## Parts without a replacement + +The following parts of the old guides have no replacement, because the container they depended on does not exist any more. + +- The Plexus embedder, `PlexusServletContextListener` and the application server with its PAR packaging: use Guice with Sisu in a standalone application, or the dependency injection of your web framework. +- The Plexus archetypes and the Codehaus snapshot repositories are gone. Create a plain Maven project from Maven Central. +- The Plexus Javadoc tags (`@plexus.component` and friends) and the `plexus-maven-plugin` are not supported by any current tool. Use the annotations above. diff --git a/src/site/markdown/guides/plexus-web-applications/01_preparing_for_project.md b/src/site/markdown/guides/plexus-web-applications/01_preparing_for_project.md index 3c1fa64..d6c0715 100644 --- a/src/site/markdown/guides/plexus-web-applications/01_preparing_for_project.md +++ b/src/site/markdown/guides/plexus-web-applications/01_preparing_for_project.md @@ -6,123 +6,6 @@ date: 2006-07-10 # Overview -The chapter explains how to set up a Plexus web application project. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page set up a web application project from a Plexus archetype. -## Pre-requisites - -The tutorial assumes you have Maven 2.0.x\+ setup and have an internet connection and are able to download required Maven artifacts from online repositories. - -## Set up a Web application project from an Archetype - -We use Maven's Web application archetype to create a skeleton web application project to get us started. - -From the command prompt, change directory to the location where you wish to set up the new Plexus Component project. Run the following command from the command line to setup an initial project structure - -``` - mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetype -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeVersion=1.0- -SNAPSHOT -DgroupId=org.codehaus.plexus.examples -DartifactId=plexus-example-webapp -DpackageName=org.codehaus.plexus.tutorial -Dpackaging=war -``` - -This should create a blank web application project. - -### Archetype creation options explained - -More info on archetype creation and usage can be found here? - -The following table explains the options that we used above. - -|Commandline Option|Description|Required| -|---|---|---| -|-DarchetypeGroupId|"groupId" for the archetype we want to use|Yes| -|-DarchetypeArtifact|"artifactId" for the archetype we want to use|Yes| -|-DarchetypeVersion|"version" for the archetype we want to use|Yes| -|-DgroupId|"groupId" for the project to be generated|Yes| -|-DartifactId|"artifactId" for the project to be generated|Yes| -|-DpackageName|Base package name to be use for any Java sources being copied over|No| - -## Generate a Project for your IDE. - -### For Eclipse. - -1. Change directory to the newly created directory 'plexus-example-webapp' - -1. Open up pom.xml and review the handful of dependencies setup there for version changes. - -1. Run the following command from command prompt to generate Eclipse project setting files. - -``` - mvn eclipse:eclipse -``` - -Eclipse project files should get generated succesfully at this point. If there were any unsatisfied dependencies (due to 2-1-3), update _version_ for dependencies in pom.xml to an available release version. - -1. Fire up Eclipse and import the generated project into an Eclipse Workspace. - -### Add sources/resources directories - -Create the following directories under the project root for our application resources: - -1. `src/main/java` - -1. `src/main/resources` - -1. `src/test/java` - -1. `src/test/resources` - -## Adding project dependencies - -We add project dependencies to the `pom.xml` located under project root. The `pom.xml` looks like below: - -``` - - - plexus-examples - org.codehaus.plexus.examples - 1-SNAPSHOT - - 4.0.0 - org.codehaus.plexus.examples - plexus-example-webapp - war - Plexus Web Application Example - 1.0-SNAPSHOT - http://maven.apache.org - - plexus-example-webapp - - - - junit - junit - 3.8.1 - test - - - - org.codehaus.plexus - plexus-servlet - 1.0-beta-5-SNAPSHOT - - - org.codehaus.plexus - plexus-container-default - 1.0-alpha-10-SNAPSHOT - - - -``` - -Update Eclipse project dependencies for new library that we added above, to do this: - -1. Open up a command prompt window - -1. Change directory to the Website Monitor project's folder, and - -1. Run the following command to update the Eclipse project dependencies. - -``` -mvn eclipse:clean eclipse:eclipse -``` - -Refresh the Eclipse project in the workspace to reflect the updated dependencies. +For the replacement, see [Parts without a replacement](/guides/migrating-from-plexus-container.html#Parts_without_a_replacement). diff --git a/src/site/markdown/guides/plexus-web-applications/index.md b/src/site/markdown/guides/plexus-web-applications/index.md index cda6a06..133fbca 100644 --- a/src/site/markdown/guides/plexus-web-applications/index.md +++ b/src/site/markdown/guides/plexus-web-applications/index.md @@ -4,10 +4,10 @@ author: Rahul Thakur date: 2006-07-07 --- -`The contents of this document are a work in progress` + # About this trail -This trail demonstrates how Plexus can be used in Web applications. +This trail showed how to use the retired Plexus container in web applications. The chapter below is kept at its address as a short note. See the [migration guide](/guides/migrating-from-plexus-container.html) for what replaced it. - [Setting up a Web Project](./01_preparing_for_project.html) diff --git a/src/site/markdown/guides/quick-start/component-descriptor-creator.md b/src/site/markdown/guides/quick-start/component-descriptor-creator.md index d35dede..41e6853 100644 --- a/src/site/markdown/guides/quick-start/component-descriptor-creator.md +++ b/src/site/markdown/guides/quick-start/component-descriptor-creator.md @@ -6,76 +6,18 @@ author: date: 2006-05-27 --- -`The contents of this document are a work in progress` - # Plexus Component Descriptor Creator -**NOTE: This document and the CDC itself is currently a work in progress.** - -The Component Descriptor Creator (or CDC for short) is a tool that will create the `components.xml` file from your Java code. It uses JavaDoc tags to gather the information it needs to create the component descriptor. - -There is a tag for marking components, requirements and configuration. Each of the tags can have parameters as documented below. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page described the Javadoc tags that generated `components.xml`. ## Component Tag Parameters -|**Tag**|**Required**|**Description**| -|---|---|---| -|role|y|The role of the component.| -|role-hint|y|The role-hint of the component.| -|version|n|The component version.| -|lifecycle-handler|n|The lifecycle handler of the component. _TODO: link to the different lifecycle handlers_| -|instantiation-strategy|n|The instantiation strategy of the component. _TODO: link to the different instantiation strategies_| - - - - - -``` -/** - * @plexus.component - * lifecycle-handler="plexus-configurable" - */ -public class DefaultActionManager - extends AbstractLogEnabled - implements ActionManager, Serviceable -{ -``` - - +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection) and [Component index](/guides/migrating-from-plexus-container.html#Component_index). ## Requirement Tag Parameters -These tags are used on fields to state requirements. TODO: it should be possible to override the role for a normal field. - -|**Tag**|**Required**|**Description**| -|---|---|---| -|role|y/n|Only required if the field is a List or Map| -|role-hint|n|| - -``` -/** - * @plexus.requirement - * role-hint="foo" - */ -private ActionManager actionManager; -``` - - +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection). ## Configuration Tag Parameters -Note that the default value tag won't be required in the future when these tags will be used to generate a separate configuration declaration section. - -|**Tag**|**Required**|**Description**| -|---|---|---| -|default-value|y|Sets the default value for the configuration field| - -``` -/** - * @plexus.configuration - * default-value="Trygve" - */ -private String name; -``` - - +Replaced by [Configuration](/guides/migrating-from-plexus-container.html#Configuration). diff --git a/src/site/markdown/guides/quick-start/getting-started.md b/src/site/markdown/guides/quick-start/getting-started.md index 11a4dae..b601ea5 100644 --- a/src/site/markdown/guides/quick-start/getting-started.md +++ b/src/site/markdown/guides/quick-start/getting-started.md @@ -4,146 +4,22 @@ author: Brett Porter date: 2006-05-26 --- -`The contents of this document are a work in progress` - # Five Minute Tutorial -In this tutorial, you will create a simple component, and use the Plexus to start a container. - -**Note:** If you are using Maven 2, you can obtain the full sample code, and then build and run it using the following commands: - -``` -mvn archetype:create \ - -DarchetypeVersion=1.0-SNAPSHOT\ - -DarchetypeGroupId=org.codehaus.plexus.examples -DarchetypeArtifactId=plexus-examples-tutorial \ - -DartifactId=tutorial -DgroupId=test -DremoteRepositories=http://snapshots.repository.codehaus.org/ -cd tutorial -mvn package exec:java -``` - - -## Creating a Component Interface - -The first task to creating a component is to define its _role_. In Java, this usually takes the form of defining an interface with the functionality the component will expose. - -**Note:** Plexus does not strictly require you use an interface to define the role, however it is strongly recommended to help improve your application design. - -``` -package org.codehaus.plexus.examples.tutorial; - -public interface Cheese -{ - /** The Plexus role identifier. */ - String ROLE = Cheese.class.getName(); - - /** - * Slices the cheese for apportioning onto crackers. - * @param slices the number of slices - */ - void slice( int slices ); - - /** - * Get the description of the aroma of the cheese. - * @return the aroma - */ - String getAroma(); -} -``` - -The interface declares the `String` identifier for the role in the `ROLE` field. The name and value of this field are simply a convention, and could possibly be any other value, as long as they are unique within the container. Using the package and class name guarantees this. - - -The other methods in the interface declare the functionality of the component: an ability to slice the cheese into a given number of slices, and method to retrieve a description of the cheese's aroma. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page built a small component, described it in `components.xml` and looked it up from a `DefaultPlexusContainer`. ## Creating a Component Implementation -Once an interface is declared, you need to create one or more implementations of the functionality declared by it. - -``` -package org.codehaus.plexus.examples.tutorial; - -public class ParmesanCheese - implements Cheese -{ - public void slice( int slices ) - { - throw new UnsupportedOperationException( "No can do" ); - } - - public String getAroma() - { - return "strong"; - } -} -``` - -The implementation of the `Cheese` interface above, `ParmesanCheese` provides the functionality for both the `slice()` and `getAroma()` methods, making the component complete. +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection) and [converting Plexus components to JSR-330](https://eclipse.dev/sisu/org.eclipse.sisu.plexus/conversion-to-jsr330.html) in the Sisu documentation. ## Creating a Component Descriptor -The final step is to create a component descriptor file, located in `META-INF/plexus/components.xml` inside the JAR or classloader that houses the component. - -``` - - - - org.codehaus.plexus.examples.tutorial.Cheese - parmesan - org.codehaus.plexus.examples.tutorial.ParmesanCheese - - - -``` - -As you can see, the descriptor contains the single component, with the role declared earlier of `Cheese`. The descriptor specifies what implementation is used for a given _role hint_. The hint is a mandatory field that differentiates implementations of a given component, and is used when later referencing the component. - -**Note:** It is not necessary to create this descriptor, as the [ Component Descriptor Creator](./component-descriptor-creator.html) can do it for you based on the Java class definition and some additional Javadoc annotations. +Replaced by [Component index](/guides/migrating-from-plexus-container.html#Component_index) and [Maven and JSR-330](https://maven.apache.org/maven-jsr330.html). ## Executing the Plexus Application -The final step is to execute the application that uses this component. In this example, you will use an container from a standard Java class with a `main()` method. - -### Creating the container - -Creating the container is very simple: - -``` -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.PlexusContainerException; - -public class App -{ - public static void main(String args[]) throws Exception - { - PlexusContainer container= new DefaultPlexusContainer(); - ... - container.dispose(); - } -} -``` - -That's all there is to it: create the container, and start it. Defaults and the current classloader will be used, however if you need a more advanced embedder container configuration, see [ Using the embedder](./embedder.html). - -### Retrieving the Component - -To retrieve the `Cheese` component from the container and execute it's `getAroma()` method, add the following lines after those that start the container: - -``` - Cheese cheese = (Cheese) container.lookup( Cheese.ROLE, "parmesan" ); - System.out.println( "Parmesan is " + cheese.getAroma() ); -``` - -That's all there is to getting started with Plexus. Congratulations! - -If you are not familiar with component-oriented programming, you may be wondering why you wouldn't just do this: - -``` - Cheese cheese = new ParmesanCheese(); - System.out.println( "Parmesan is " + cheese.getAroma() ); -``` - -For answers to this question and more, see [ Why Use Components?](/ref/why-use-components.html) +Replaced by [Looking up components](/guides/migrating-from-plexus-container.html#Looking_up_components). ## Learning More -To learn more about writing components, take the [ Component Tutorial](/guides/writing-components/00_index.html). +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection) and [Eclipse Sisu](https://eclipse.dev/sisu/). diff --git a/src/site/markdown/guides/quick-start/one-minute-tutorial.md b/src/site/markdown/guides/quick-start/one-minute-tutorial.md index 28e18ae..b4ad047 100644 --- a/src/site/markdown/guides/quick-start/one-minute-tutorial.md +++ b/src/site/markdown/guides/quick-start/one-minute-tutorial.md @@ -4,28 +4,6 @@ title: Plexus # **This is an old piece of documentation, yet to be integrated into the new site and removed** -# ... +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page showed a component that implements `Initializable`. -1. You must create your component implementation. - -``` -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; - -public class DefaultCheeseComponent - implements Initializable, CheeseComponent -{ - private String cheese; - - public void initialize() throws Exception - { - cheese = "cheese!"; - } - - public String cheese() - { - return cheese; - } -} -``` - -Notice that we implement `Intializable`. This is part of the [Component Lifecycle](./plexus-lifecycle.html). When plexus automatically instantiates your component it will automatically `intiailize()` it as well. +For the replacement, see [Lifecycle](/guides/migrating-from-plexus-container.html#Lifecycle) and [Sisu lifecycle support](https://eclipse.dev/sisu/org.eclipse.sisu.inject/lifecycle.html). diff --git a/src/site/markdown/guides/trails/index.md b/src/site/markdown/guides/trails/index.md index 90a6c1e..0d8d452 100644 --- a/src/site/markdown/guides/trails/index.md +++ b/src/site/markdown/guides/trails/index.md @@ -6,6 +6,8 @@ date: 2006-06-16 # Documentation Trails +The Plexus container is retired. The trails below are kept because other sites link to them; the [migration guide](/guides/migrating-from-plexus-container.html) describes what replaced the container. + The Plexus documentation is organised into trails, depending on how you intend to use it. ## Component-oriented Programming Trail diff --git a/src/site/markdown/guides/writing-components/00_index.md b/src/site/markdown/guides/writing-components/00_index.md index 423e0c2..81cdecd 100644 --- a/src/site/markdown/guides/writing-components/00_index.md +++ b/src/site/markdown/guides/writing-components/00_index.md @@ -4,11 +4,11 @@ author: Rahul Thakur date: 2006-06-08 --- -`The contents of this document are a work in progress` + # About this trail -This trail shows how to get started with Plexus Component development. It starts off with a simple Plexus component and gradually evolves it to show different ways a component can be used. +This trail taught writing Plexus components for the retired Plexus container. The chapters below are kept at their addresses, but each is now a short note that points to the replacement. To move a component to JSR-330 and Eclipse Sisu, start with the [migration guide](/guides/migrating-from-plexus-container.html). - [Prepping project: Website Monitor component](./01_preparing_for_project.html) diff --git a/src/site/markdown/guides/writing-components/01_preparing_for_project.md b/src/site/markdown/guides/writing-components/01_preparing_for_project.md index a4fd1d3..f784b35 100644 --- a/src/site/markdown/guides/writing-components/01_preparing_for_project.md +++ b/src/site/markdown/guides/writing-components/01_preparing_for_project.md @@ -4,80 +4,10 @@ author: Rahul Thakur date: 2006-06-08 --- -`The contents of this document are a work in progress` - # Overview -The chapter gets you to jump start into Plexus Component development. While a scan through of 'Concepts' would be helpful, it is not really required. - -Where ever deemed neccessary cross-references are provided to make it easy for a new developer to reference the required material. - -# Pre-requisites - -The tutorial assumes you have Maven 2.0.x\+ setup and have an internet connection and are able to download required Maven artifacts from online repositories. - -For the purpose of this tutorial we will develop a Plexus Website Monitor component. - -Lets get started! +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page created a project from the Plexus archetypes. ## Create that skeleton! -Plexus has some archetypes available that can make initial project setups a breeze. We use one such archetype for our Plexus component here. From the command prompt, change directory to the location where you wish to set up the new Plexus Component project. Run the following command from the command line to setup an initial project structure - -``` - - mvn archetype:create -DarchetypeGroupId=org.codehaus.plexus -DarchetypeArtifactId=plexus-archetype-component-simple -DarchetypeVersion=1.0-alpha-1-SNAPSHOT -DgroupId=org.codehaus.plexus -DartifactId=plexus-website-monitor-component -DpackageName=org.codehaus.plexus.tutorial -Dpackaging=jar -DremoteRepositories=http://snapshots.repository.codehaus.org/ - -``` - -Cool! At this point you've created a basic project structure that should give you a jump-start into development. - -### Archetype creation options explained - -More info on archetype creation and usage can be found [here](http://maven.apache.org/guides/getting-started/index.html) on the Maven website. - -The following table explains the options that we used above. - -|**Commandline Option**|**Description**|**Required**| -|---|---|---| -|-DarchetypeGroupId|"groupId" for the archetype we want to use|Yes| -|-DarchetypeArtifact|"artifactId" for the archetype we want to use|Yes| -|-DarchetypeVersion|"version" for the archetype we want to use|Yes| -|-DgroupId|"groupId" for the project to be generated|Yes| -|-DartifactId|"artifactId" for the project to be generated|Yes| -|-DpackageName|Base package name to be use for any Java sources being copied over|No| -|-Dpackaging|Packaging to be used for the created project|No| -|-DremoteRepositories|Comma-separated list of repositories to lookup to retrieve archetype|No| - -## Generate a Project for your IDE. - -### For Eclipse. - -1. Change directory to the newly created directory 'plexus-website-monitor-component' - -1. Open up pom.xml and review the handful of dependencies setup there for version changes. - -- As of this writing Plexus Snapshots were not being published to the Codehaus snapshots repository. Hopefully this should get resolved quickly. - -1. Run the following command from command prompt to generate Eclipse project setting files. - -``` - E:\workspaces\plexus-docs\plexus-website-monitor-component>mvn eclipse:eclipse -``` - -Eclipse project files should get generated succesfully at this point. If there were any unsatisfied dependencies (due to 2-1-3), update _version_ for dependencies in pom.xml to an available release version. - -1. Fire up Eclipse and import the generated project into an Eclipse Workspace. - -Now, let's quickly recap the resources we see in our Eclipse project. - -Eclipse Package Explorer View of our import Plexus Component project. - - -That concludes the preparation for our component project, we are all set to get our hands dirty with our first Plexus component. - -If you have a developer's itch and want to see if there is something we can do with the minimal project setup by the archetype for us - well, good news! Navigate your way through to the "HelloWorldTest" class (selected in the image above). Right click on it and choose "Run As \> JUnit Test" and see for yourself. eeeks.....our unit test failed!! But fear not, for we come back to Component testing in a later chapter, so stay put! - -The project resources that we setup so far can be downloaded from this link here: - - +Replaced by [Parts without a replacement](/guides/migrating-from-plexus-container.html#Parts_without_a_replacement). diff --git a/src/site/markdown/guides/writing-components/02_diving_in.md b/src/site/markdown/guides/writing-components/02_diving_in.md index 9381264..ea92e67 100644 --- a/src/site/markdown/guides/writing-components/02_diving_in.md +++ b/src/site/markdown/guides/writing-components/02_diving_in.md @@ -4,123 +4,16 @@ author: Rahul Thakur date: 2006-06-11 --- -`The contents of this document are a work in progress` - # Creating a Component 'Role' -If you browse through the sources generated by the Plexus component archetype used for preparing and setting up our project, you will see that we have: - -1. an Interface "HelloWorld.java" , and - -1. a Class "DefaultHelloWorld.java" which implements the interface in (1) above. - -1. a Component Descriptor "components.xml" located under _project-root_/src/main/resources/META-INF/ - -Components are registered with Plexus Container based on "ROLE" they can play or implement. If you look at the interface sources you will notice the ROLE specified by that interface. The class DefaultHelloWorld is the provider or concrete implementation of the interface HelloWorld. It can reside within the same JAR as the inteface or a different one. Think of ROLE as a key that can be used to query the Plexus Container for an implementation. The component descriptor, as the name implies, describes our component. We will revisit it again in later chapters but for the moment, know that the descriptor holds: - -1. the ROLE that the component implements or acts a provider for. - -1. the configuration for the component implementation. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page created a role interface, an implementation and a component descriptor. -When Plexus Container starts up, it uses Classworlds (the library that handles the classloading) to discover any Plexus components. It does this by looking for component descriptors ([More on Component Descriptor here ](/guides/developer-guide/configuration/component-descriptor.html)) under standard location - META-INF/plexus. - -That's enough to start tinkering with your website monitor component, so let's get our hands dirty! Identify a Component Role - -Delete the .java files from the sources (under src/main and src/test ) that were generated by the archetype. The first thing we need to do is to identify a ROLE for our component - WebsiteMonitor. - -``` -public interface WebsiteMonitor { - - /** - * Role used to register component implementations with the container. - */ - String ROLE = WebsiteMonitor.class.getName (); - - /** - * Monitor the specified website. - * - * @param website - * Website URL to monitor - * @throws Exception - * error encountered while performing the monitoring request. - */ - public void monitor(String website) throws Exception; -} -``` +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection) and [converting Plexus components to JSR-330](https://eclipse.dev/sisu/org.eclipse.sisu.plexus/conversion-to-jsr330.html) in the Sisu documentation. # Create provider for the Role -Lets create a bare-bones implementation of a provider for the component Role that we identified above and gradually flesh it out. - -``` -public class DefaultWebsiteMonitor implements WebsiteMonitor { - - /* - * (non-Javadoc) - * - * @see org.codehaus.plexus.tutorial.WebsiteMonitor#monitor(java.lang.String) - */ - public void monitor(String website) throws Exception { - // TODO implement - - } - -} -``` +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection). # Create a Component descriptor -Locate the component descriptor for our component provider under _project-root_/src/main/resources/META-INF/plexus/component.xml. Edit its content to reflect as below: - -``` - - - - org.codehaus.plexus.tutorial.WebsiteMonitor - - org.codehaus.plexus.tutorial.DefaultWebsiteMonitor - - - - - -``` - -Before we implement the the provider, we need to update our project dependencies and include Jakarta Commons HttpClient library. To do this, locate pom.xml under _project-root_ and edit it to reflect the _dependencies_ section of our pom.xml as below: - -``` - - - org.codehaus.plexus - plexus-container-default - 1.0-alpha-9 - - - junit - junit - 3.8.1 - test - - - commons-httpclient - commons-httpclient - 3.0.1 - - -``` - -Update Eclipse project dependencies for new library that we added above, to do this: - -1. Open up a command prompt window - -1. Change directory to the Website Monitor project's folder, and - -1. Run the following command to update the Eclipse project dependencies. - -``` -mvn eclipse:clean eclipse:eclipse -``` - -Refresh the Eclipse project in the workspace to reflect the updated dependencies. - -We are now ready to start writing some unit tests for our (yet empty) component and drilling some useful implementation details into it! +Replaced by [Component index](/guides/migrating-from-plexus-container.html#Component_index) and [Maven and JSR-330](https://maven.apache.org/maven-jsr330.html). diff --git a/src/site/markdown/guides/writing-components/03_joys_of_tdd.md b/src/site/markdown/guides/writing-components/03_joys_of_tdd.md index d23aafe..3508683 100644 --- a/src/site/markdown/guides/writing-components/03_joys_of_tdd.md +++ b/src/site/markdown/guides/writing-components/03_joys_of_tdd.md @@ -4,115 +4,8 @@ author: Rahul Thakur date: 2006-06-11 --- -`The contents of this document are a work in progress` - # Testing our Plexus Component -We create a basic unit test for our component. We do this by extending the PlexusTestCase class rather than the JUnit TestCase. PlexusTestCase sets up a Plexus Container intance for us to allow our component to be executed as it would when its deployed. - -Note that if we override the setUp () and tearDown() methods to add some custom set up or clean up bits to our test case, then we need to ensure that super.XXX() is called (where XXX is the method being overridden). Othewise we will need to take care of Plexus container instance setup and clean ups ourselves. - -Here is a rudimentary test case for your component. - -``` -package org.codehaus.plexus.tutorial; - -import java.net.UnknownHostException; - -import org.codehaus.plexus.PlexusTestCase; - -/** - * Basic test. - */ -public class WebsiteMonitorTest extends PlexusTestCase { - - /** - * sets up a Plexus container instance for running test. - */ - protected void setUp() throws Exception { - // call this to enable super class to setup a Plexus container test - // instance and enable component lookup. - super.setUp (); - } - - /** - * Test if we are able to lookup and obtain our component instance from the - * container. - * - * @throws Exception - */ - public void testBasic() throws Exception { - WebsiteMonitor component = (WebsiteMonitor) lookup (WebsiteMonitor.ROLE); - assertNotNull (component); - } - - /** - * Test an unkown host. - * - * @throws Exception - */ - public void testUnknownHost() throws Exception { - WebsiteMonitor component = (WebsiteMonitor) lookup (WebsiteMonitor.ROLE); - assertNotNull (component); - Exception e = null; - try { - component.monitor ("http://www.yadayadayda.com/"); - } catch (Exception e1) { - e = e1; - } - assertNotNull (e); - assertEquals (true, (e instanceof UnknownHostException)); - } - - /** - * Test a page that does not exists. - * - * @throws Exception - */ - public void testNotOKCode() throws Exception { - WebsiteMonitor component = (WebsiteMonitor) lookup (WebsiteMonitor.ROLE); - assertNotNull (component); - Exception e = null; - try { - component.monitor ("http://www.google.co.nz/unknown_404_.html"); - } catch (Exception e1) { - e = e1; - } - assertNotNull (e); - } - -} -``` - -Time to take our unit test for a spin! Right click on the test case class in the Package Explorer view in Eclipse and choose to "Run As \> JUnit Test" - our test case fails as expected. Lets start stubbing in some implementation into the component and fixing the situation. The monitor(String website) is implemented as below to check the status of the provided website URL. - -``` -public class DefaultWebsiteMonitor implements WebsiteMonitor { - - /* - * (non-Javadoc) - * - * @see org.codehaus.plexus.tutorial.WebsiteMonitor#monitor(java.lang.String, - * long) - */ - public void monitor(String website) throws Exception { - HttpClient client = new HttpClient (); - HttpMethod getMethod = new GetMethod (website); - getMethod.setFollowRedirects (false); - - try { - int statusCode = client.executeMethod (getMethod); - - if (statusCode < HttpStatus.SC_OK || statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) { - System.err.println ("HTTP request returned HTTP status code: " + statusCode); - throw new Exception ("HTTP request returned HTTP status code: " + statusCode); - } - System.out.println ("HTTP request returned HTTP status code: " + statusCode); - } catch (UnknownHostException e) { - System.err.println ("Specified host '" + website + "' could not be resolved."); - throw e; - } - } +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page tested a component with a JUnit 3 base class that started a container. -} -``` +For the replacement, see [Testing components](/guides/migrating-from-plexus-container.html#Testing_components) and [Plexus Testing](https://codehaus-plexus.github.io/plexus-testing/). diff --git a/src/site/markdown/guides/writing-components/04_more_bells_n_whistles.md b/src/site/markdown/guides/writing-components/04_more_bells_n_whistles.md index eaa8b1e..525e443 100644 --- a/src/site/markdown/guides/writing-components/04_more_bells_n_whistles.md +++ b/src/site/markdown/guides/writing-components/04_more_bells_n_whistles.md @@ -4,45 +4,12 @@ author: Rahul Thakur date: 2006-06-11 --- -`The contents of this document are a work in progress` - # Control those 'evil' System.out's! -We tweak our component implementation a bit to allow more control over messages being logged the console. To to this we update DefaultWebsiteMonitor to extend from org.codehaus.plexus.logging.AbstractLogEnabled. System.outs are then replaced by call to getLogger() to obtain the org.codehaus.plexus.logging.Logger instance setup by the container for us. The resulting code looks like this: - -``` -public class DefaultWebsiteMonitor extends AbstractLogEnabled implements WebsiteMonitor { - - /* - * (non-Javadoc) - * - * @see org.codehaus.plexus.tutorial.WebsiteMonitor#monitor(java.lang.String) - */ - public void monitor(String website) throws Exception { - HttpClient client = new HttpClient (); - HttpMethod getMethod = new GetMethod (website); - getMethod.setFollowRedirects (false); - - try { - int statusCode = client.executeMethod (getMethod); - - if (statusCode < HttpStatus.SC_OK || statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) { - if (getLogger ().isErrorEnabled ()) - getLogger ().error ("HTTP request returned HTTP status code: " + statusCode); - throw new Exception ("HTTP request returned HTTP status code: " + statusCode); - } - if (getLogger ().isInfoEnabled ()) - getLogger ().info ("HTTP request returned HTTP status code: " + statusCode); - } catch (UnknownHostException e) { - if (getLogger ().isErrorEnabled ()) - getLogger ().error ("Specified host '" + website + "' could not be resolved."); - throw e; - } - } +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page replaced the container logger with a custom `LoggerManager`. -} -``` +Replaced by [Logging](/guides/migrating-from-plexus-container.html#Logging). # Plugging in our custom Logging implementation -An example of plugging in a custom logging implementation is demonstrated [ here](./05_01_custom_logging_implementation.html). +Replaced by [Logging](/guides/migrating-from-plexus-container.html#Logging). diff --git a/src/site/markdown/guides/writing-components/05_01_custom_logging_implementation.md b/src/site/markdown/guides/writing-components/05_01_custom_logging_implementation.md index 3bdb69a..65f8cc0 100644 --- a/src/site/markdown/guides/writing-components/05_01_custom_logging_implementation.md +++ b/src/site/markdown/guides/writing-components/05_01_custom_logging_implementation.md @@ -6,75 +6,6 @@ date: 2006-06-11 # Using a custom LoggerManager -Say, we want to use Log4j logging for the log messages in our Website monitor component - how could we replace the default logging implementation? +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page showed a custom `LoggerManager`. -Before we demonstrate how logger can be swapped, some notes on how logging is setup up for a Plexus component - -- Logging for a component is handled using a org.codehaus.plexus.logging.LoggerManager component. - -- LoggerManager makes a org.codehaus.plexus.logging.Logger instance available to the Plexus container. The LoggerManager can create (or obtain) as well as configure the Logger instance before making it available to the Plexus container. - -- Each component in Plexus runtime get its own Logger instance. - -- LoggerManager is initialized on Plexus container startup. It is for this reason, the LoggerManager should be overridden via Plexus container's configuration. - -From what we have coded up so far, we don't have Plexus container configuration available to us, nor is it desirable to run our component in a Plexus container without being fully tested. So here is what we do: - -1. Override the configuration used by PlexusTestCase to set up a Plexus Container instance. - -1. Setup the Log4jLoggerManager in the overridden configuration. - -For step (1) above we update the WebMonitorTest and override the getCustomConfiguration() method from PlexusTestCase as follows: - -``` -protected InputStream getCustomConfiguration() throws Exception { - InputStream is = this.getClass ().getClassLoader ().getResourceAsStream ("org/codehaus/plexus/PlexusTestContainerConfig.xml"); - return is; - } -``` - -For step (2), create an XML configuration file under \/src/test/resources/org/codehaus/plexus/PlexusTestContainerConfig.xml, with following contents: - -``` - - - - - org.codehaus.plexus.logging.LoggerManager - - org.codehaus.plexus.logging.log4j.Log4JLoggerManager - - - - - rolling - DEBUG - org.apache.log4j.RollingFileAppender - - %-4r [%t] %-5p %c %x - %m%n - - - - file - ${plexus.home}/logs/plexus-rolling.log - - - append - true - - - maxBackupIndex - 10 - - - maxFileSize - 20 - - - - - - - - -``` +For the replacement, see [Logging](/guides/migrating-from-plexus-container.html#Logging). diff --git a/src/site/markdown/guides/writing-components/05_configuring_to_get_it_right.md b/src/site/markdown/guides/writing-components/05_configuring_to_get_it_right.md index 86761df..22f250b 100644 --- a/src/site/markdown/guides/writing-components/05_configuring_to_get_it_right.md +++ b/src/site/markdown/guides/writing-components/05_configuring_to_get_it_right.md @@ -4,147 +4,8 @@ author: Rahul Thakur date: 2006-06-11 --- -`The contents of this document are a work in progress` - # Configuring a Plexus Component via descriptor - -We change the Component Role interface to look like this: - -``` -public interface WebsiteMonitor -{ - - /** - * Role used to register component implementations with the container. - */ - String ROLE = WebsiteMonitor.class.getName(); - - /** - * Monitor the specified website at the specified time intervals. - * - * @throws Exception - * error encountered while performing the monitoring request. - */ - public void monitor() - throws Exception; - - /** - * Specify a list of websites that can be monitored by this component. - * - * @param websites List of websites - */ - void addWebsites( List websites ); - - /** - * Determines if the website monitor component was properly initialized. - * - * @return true if initiailized, else false. - */ - boolean isInitialized(); -} -``` - -and, factor our component provider implementation to look like this: - -``` -public class DefaultWebsiteMonitor - extends AbstractLogEnabled - implements WebsiteMonitor -{ - - /** - * Websites to monitor. - * - * @plexus.configuration - */ - private List websites; - - /** - * @see org.codehaus.plexus.tutorial.WebsiteMonitor#monitor(java.lang.String) - */ - public void monitor() - throws Exception - { - HttpClient client = new HttpClient(); - - for ( Iterator it = websites.iterator(); it.hasNext(); ) - { - String website = (String) it.next(); - HttpMethod getMethod = new GetMethod( website ); - getMethod.setFollowRedirects( false ); - - try - { - int statusCode = client.executeMethod( getMethod ); - - if ( statusCode < HttpStatus.SC_OK || statusCode >= HttpStatus.SC_MULTIPLE_CHOICES ) - { - if ( getLogger().isErrorEnabled() ) - getLogger().error( - "HTTP request returned HTTP status code: " + statusCode + " for website: " - + website ); - throw new Exception( "HTTP request returned HTTP status code: " + statusCode + " for website: " - + website ); - } - if ( getLogger().isInfoEnabled() ) - getLogger().info( - "HTTP request returned HTTP status code: " + statusCode + " for website: " - + website ); - } - catch ( UnknownHostException e ) - { - if ( getLogger().isErrorEnabled() ) - getLogger().error( "Specified host '" + website + "' could not be resolved." ); - throw e; - } - finally - { - if ( null != getMethod ) - getMethod.releaseConnection(); - } - } - } - - public void addWebsites( List websites ) - { - this.websites = websites; - } - - public boolean isInitialized() - { - return ( null != websites && this.websites.size() > 0 ); - } - -} -``` - -Note how `'websites'` is now a java.util.List property rather than a argument to the method. Also notice the annotation @plexus.configuration that indicates that this property is a plexus configuration element. This annotation is processed by Plexus' Component Descriptor Creator (or CDC). The CDC can parse and generate a components.xml from Java sources. - -Now that we made `'websites'` to be a configuration property, we need to update the component's descriptor and specify values for websites. We add a list of websites as shown the the snippet below. Plexus container ensures that a component's fields are mapped and initialized and mapped from a component's configuration file. It can intelligently discover and map configuration items of different types like String, Lists (in this case). You can also specify you own configuration implementation class by specifying an `'implementation'` attribute on ` element. Plexus will then attempt to inject the values from the XML configuration into the Configuration implementation's properties. Each of the nested element maps to a configuration property in the implementation class. - - -This mandates a change in the descriptor, which now looks something like this: - -``` - - - - org.codehaus.plexus.tutorial.WebsiteMonitor - - org.codehaus.plexus.tutorial.DefaultWebsiteMonitor - - - - http://www.google.co.nz/ - http://www.nonexistent.yadayada3249834739547.org/ - http://maven.apache.org/ - - - - - -``` +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page configured a component through its descriptor. - - +For the replacement, see [Configuration](/guides/migrating-from-plexus-container.html#Configuration) and [converting Plexus components to JSR-330](https://eclipse.dev/sisu/org.eclipse.sisu.plexus/conversion-to-jsr330.html) in the Sisu documentation. diff --git a/src/site/markdown/guides/writing-components/07_01_configuring_monitor_mojo.md b/src/site/markdown/guides/writing-components/07_01_configuring_monitor_mojo.md index 3a40f32..c0fd1e8 100644 --- a/src/site/markdown/guides/writing-components/07_01_configuring_monitor_mojo.md +++ b/src/site/markdown/guides/writing-components/07_01_configuring_monitor_mojo.md @@ -4,73 +4,8 @@ author: Rahul Thakur date: 2006-06-27 --- -`The contents of this document are a work in progress` - # Adding Configuration for the Monitor Mojo -## Configuring a 'short-hand' to invoke Monitor Mojo - -By default Maven expects all Maven plugin artifacts: - -1. to belong to the group `org.apache.maven.plugins` - -1. to have the artifactId follow pattern `maven-xxxx-plugin`, where `xxxx` can serve as a short-hand prefix to invoke a Mojo from a Maven plugin. - -For our case we need to let Maven know that our plugin's `groupId` and `artifactId` are different from what Maven expects by default. - -So we define for our Maven plugin a **plugin prefix** via our plugin's pom.xml. - -To do this, we add the following to our pom.xml under the ` element. - -``` - - - . - . - . - - - - maven-plugin-plugin - - website - - - - - - -``` - -This tells Maven to use **website** as a plugin prefix or a 'short-hand' to allow invoking available Mojo(s) from our plugin. - -1. Next we add the `groupId` of our Maven plugin in Maven settings file. This is available under `~/.m2/settings.xml`. - -1. Edit it and add the following: - -``` - - . - . - . - - org.codehaus.plexus - - -``` - -This should allow our Mojo to be invoked from the command prompt without have the need to type fully qualified reference to MonitorMojo (org.codehaus.plexus:plexus-website-monitor-plugin:monitor), and by simply typing: - -``` - mvn website:monitor -``` - -A more definitive reference on plugin prefix resolution is available [here](http://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html) on the Maven website. - -## Configuring list of websites - - - -We will come back to configuring the MonitorMojo but before we do that we'll look at setting up unit tests for it. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page configured a Mojo that used a Plexus component. -[Next: Setting up Mojo unit tests](./07_01_setting_up_mojo_unit_tests.html) +For the replacement, see [Configuration](/guides/migrating-from-plexus-container.html#Configuration) and [Guide to Configuring Plugins](https://maven.apache.org/guides/mini/guide-configuring-plugins.html). diff --git a/src/site/markdown/guides/writing-components/07_01_from_a_maven_mojo.md b/src/site/markdown/guides/writing-components/07_01_from_a_maven_mojo.md index 328ec1c..046021d 100644 --- a/src/site/markdown/guides/writing-components/07_01_from_a_maven_mojo.md +++ b/src/site/markdown/guides/writing-components/07_01_from_a_maven_mojo.md @@ -6,78 +6,8 @@ date: 2006-06-08 # Website Monitor Plugin -This section will show how to use a Plexus component from within a Maven mojo. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page used a Plexus component from a Mojo in a plugin built from an archetype. ## Setting up a Maven Plugin Project -### Creating a Maven plugin Project using an archetype - -Maven Archetypes are discussed in detail [here](http://maven.apache.org/guides/mini/guide-creating-archetypes.html). - -1. From the command prompt, change directory to the location where you want to setup the maven plugin project. - -1. Run the following command to set up a skeleton Maven Plugin project. - -``` - - mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-mojo \ - -DarchetypeVersion=1.0-SNAPSHOT -DgroupId=org.codehaus.plexus -DartifactId=plexus-website-monitor-plugin - -``` - -The `maven-archetype-mojo` sets up a skeleton Maven plugin project '`plexus-website-monitor-plugin`' for us with reasonable defaults. - -### Updating pom.xml dependencies - -1. Locate pom.xml under the '`plexus-website-monitor-plugin`' folder. - -1. Edit it and add a `dependency` to the plexus-website-monitor-component that we have developed in earlier chapters. - -The pom.xml should look like this now: - -``` - - - 4.0.0 - org.codehaus.plexus - plexus-website-monitor-plugin - maven-plugin - Maven Mojo Archetype - 1.0-SNAPSHOT - http://maven.apache.org - - - org.apache.maven - maven-plugin-api - 2.0 - - - junit - junit - 3.8.1 - test - - - org.codehaus.plexus - plexus-website-monitor-component - 1.0-SNAPSHOT - - - -``` - -### Setting up an Eclipse project - -Note that this step assumes that we have Plexus Website Monitor Component available in our local repository or downloadable from a remote repository. - -1. Run the following command to generate Eclipse project and set up library path to dependencies. - -``` - mvn eclipse:eclipse -``` - -1. From the Eclipse workbench, use 'File \> Import \> Existing projects into workspace' to import the created maven plugin project. - -The website monitor plugin should now be set up as a project under Eclipse. - -[Next: Implementing Monitor Mojo](./07_01_implementing_monitor_mojo.html) +Replaced by [Parts without a replacement](/guides/migrating-from-plexus-container.html#Parts_without_a_replacement) and [Guide to Developing Java Plugins](https://maven.apache.org/guides/plugin/guide-java-plugin-development.html). diff --git a/src/site/markdown/guides/writing-components/07_01_implementing_monitor_mojo.md b/src/site/markdown/guides/writing-components/07_01_implementing_monitor_mojo.md index 14a12a2..b6da44b 100644 --- a/src/site/markdown/guides/writing-components/07_01_implementing_monitor_mojo.md +++ b/src/site/markdown/guides/writing-components/07_01_implementing_monitor_mojo.md @@ -4,138 +4,10 @@ author: Rahul Thakur date: 2006-06-27 --- -`The contents of this document are a work in progress` - # Implementing the Monitor Mojo -If you would like to understand what a Maven Mojo is, please refer to the documentation [here](http://maven.apache.org/guides/plugin/guide-java-plugin-development.html) on the Maven website. - -## Monitor Mojo - -We noticed that the archetype creator filled in the maven plugin project with some reasonable defaults. It also created a `MyMojo` placeholder implementation of a Mojo for us, but it doesn't do much for us. - -So, - -1. Delete `MyMojo` implementation from the project sources. - -1. Create a `MonitorMojo` that extends `org.apache.maven.plugin.AbstractMojo`. - -The Mojo source should like this: - -``` - -public class MonitorMojo - extends AbstractMojo -{ - - public void execute() - throws MojoExecutionException, MojoFailureException - { - // TODO Auto-generated method stub - - } - -} - -``` - -1. Add a Javadoc `@goal` annotation in Javadoc comments for a Class to bind a goal name that runs this Mojo. - -``` - -/** - * A Mojo that monitors a given list of websites. - * - * @version $Id$ - * @goal monitor - */ -public class MonitorMojo - extends AbstractMojo -{ - - public void execute() - throws MojoExecutionException, MojoFailureException - { - // TODO Auto-generated method stub - - } - -} - -``` +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page wired a component into a Mojo through a Plexus requirement. ## Wiring the Website Monitor Component -1. Declare a field of type `org.codehaus.plexus.tutorial.WebsiteMonitor` for `MonitorMojo`. - -1. Add a Javadoc annotation `@component` on the field. This indicates to Plexus runtime to lookup and populate the field with an implementation with a Component ROLE = '`org.codehaus.plexus.tutorial.WebsiteMonitor`' - -``` - -/** - * A Mojo that monitors a given list of websites. - * - * @version $Id$ - * @goal monitor - */ -public class MonitorMojo - extends AbstractMojo -{ - - /** - * The website monitor component instance that will be injected - * by the Plexus runtime. - * @component - */ - private WebsiteMonitor monitor; - - public void execute() - throws MojoExecutionException, MojoFailureException - { - // TODO Auto-generated method stub - - } - -} - -``` - -1. (optional) We can get choosy if we know there are more than one implementations of `org.codehaus.plexus.tutorial.WebsiteMonitor` ROLE available. This can done by adding an attribute '`role-hint`' to the Javadoc annotation that we added in the previous step. - -Say, for instance we had a different website monitor implementation to monitor FTP websites, the Javadoc annotation for that Mojo field will look like the snippet below. - -Of course, the value of `role-hint` provided in the code snippet reproduced below should have been defined for the website monitor's implementation's component descriptor that monitors FTP sites. - -Again the Plexus runtime does the magic of injecting the appropriate implementation. - -``` - -/** - * A Mojo that monitors a given list of websites. - * - * @version $Id$ - * @goal monitor - */ -public class MonitorMojo - extends AbstractMojo -{ - - /** - * The website monitor component instance that will be injected - * by the Plexus runtime. - * @component role-hint="ftp" - */ - private WebsiteMonitor monitor; - - public void execute() - throws MojoExecutionException, MojoFailureException - { - // TODO Auto-generated method stub - - } - -} - -``` - -[Next: Adding configuration for the Mojo](./07_01_configuring_monitor_mojo.html) +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection) and [Maven and JSR-330](https://maven.apache.org/maven-jsr330.html). diff --git a/src/site/markdown/guides/writing-components/07_01_setting_up_mojo_unit_tests.md b/src/site/markdown/guides/writing-components/07_01_setting_up_mojo_unit_tests.md index 9584ce3..c1d38c6 100644 --- a/src/site/markdown/guides/writing-components/07_01_setting_up_mojo_unit_tests.md +++ b/src/site/markdown/guides/writing-components/07_01_setting_up_mojo_unit_tests.md @@ -4,211 +4,14 @@ author: Rahul Thakur date: 2006-06-27 --- -`The contents of this document are a work in progress` - # Setting up unit tests for Monitor Mojo -Unit testing allows us to test out our Mojo implmentation without requiring a project to be set up. - -Maven provides a **Plugin Test Harness** to enable testing of Mojos. - -Some relatively comprehensive notes on the Maven Plugin Harness are available [here](http://docs.codehaus.org/display/MAVEN/Maven\+Plugin\+Harness). - -## Adding test sources directory to the project - -This step is needed as the Mojo Archetype (as of this writing) does not sets up test folder when we created our Maven plugin project. - -1. To the project root add a directory `src/test/java`. We will create our unit tests under this location. - -1. To the project root add a director `src/test/resources`. This directory will hold resources that we use for Mojo testing. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page tested a Mojo with `AbstractMojoTestCase`. ## Adding plugin test harness dependency -1. First thing we need to do is to add the Maven plugin test harness dependency to our Plugin's `pom.xml`. Locate the `pom.xml` and add the harness dependency as follows. - -``` - - . - . - . - - org.apache.maven.shared - maven-plugin-testing-harness - 1.0-beta-1 - test - - -``` - -1. Next we need to update depdendency references in our Eclipse project settings to make the plugin testing harness available. To do this run the following from the command prompt from the plugin project's directory. - -``` - mvn eclipse:clean eclipse:eclipse -``` - -1. Refresh the Eclipse project by selecting the project root folder and pressing 'F5' key. - -You will see that the plugin testing harness dependency and the test directory that we added in the previous step are now updated. +Replaced by [Testing Maven plugins](/guides/migrating-from-plexus-container.html#Testing_Maven_plugins) and [Maven Plugin Testing Harness](https://maven.apache.org/plugin-testing/maven-plugin-testing-harness/getting-started/index.html). ## Writing our Mojo unit tests -1. Create a new package `org.codehaus.plexus` to create our test in. Note that we create the package with the same name that our Mojo implementation resides in. This is a convenience to test out methods on Mojo which may have access specifiers that allow access only from within same package. - -1. We write a couple of tests to ensure that our Mojo instance is being retrieved as expected, and to test that it executes without errors for a valid list of websites. - -Our test source looks as follows: - -``` -public class MonitorMojoTest - extends AbstractMojoTestCase -{ - - public void testMojoLookup() - throws Exception - { - File pluginXml = new File( getBasedir(), "src/test/resources/unit/plugin-config.xml" ); - MonitorMojo mojo = (MonitorMojo) lookupMojo( "monitor", pluginXml ); - assertNotNull( mojo ); - } - - public void testMojoExecution() - throws Exception - { - File pluginXml = new File( getBasedir(), "src/test/resources/unit/plugin-config.xml" ); - MonitorMojo mojo = (MonitorMojo) lookupMojo( "monitor", pluginXml ); - assertNotNull( mojo.getWebsites() ); - assertEquals( 1, mojo.getWebsites().size() ); - assertNotNull( mojo.getMonitor() ); - try - { - mojo.execute(); - } - catch ( Exception e ) - { - fail( "Unexpected exception with test data." ); - } - } -} -``` - -1. We set up a test configuration for the Mojo under `src/test/resources/unit/plugin-config.xml` (yes, that's the file that we refer to in the test above!). - -``` - - - - - org.codehaus.plexus - plexus-website-monitor-plugin - - - http://plexus.codehaus.org/ - - - - - - -``` - -1. Also our Mojo implementation is now updated to be as below: - -``` -public class MonitorMojo - extends AbstractMojo -{ - - /** - * List of websites to monitor. - * @parameter - */ - private List websites; - - /** - * The website monitor component instance that will be injected - * by the Plexus runtime. - * @component - */ - private WebsiteMonitor monitor; - - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( !hasWebsites() ) - { - if ( getLog().isWarnEnabled() ) - getLog().warn( "No websites specified to be monitored." ); - return; - } - - if ( getLog().isDebugEnabled() ) - showMonitoredWebsites(); - - monitor.addWebsites( websites ); - try - { - monitor.monitor(); - } - catch ( Exception e ) - { - if ( getLog().isErrorEnabled() ) - getLog().error( "Error monitoring websites.", e ); - } - } - - private void showMonitoredWebsites() - { - getLog().debug( "Monitoring following websites:" ); - for ( Iterator it = websites.iterator(); it.hasNext(); ) - { - String website = (String) it.next(); - getLog().debug( "\t" + website ); - } - } - - /** - * Determines if websites were specified to the Mojo. - * - * @return true if there were websites specified. - */ - private boolean hasWebsites() - { - return ( null != websites && websites.size() > 0 ); - } - - /** - * Returns the list of websites.

- * Not public API. For unit tests only. - * - * @return List of websites specified via Mojo configuration. - */ - protected List getWebsites() - { - return this.websites; - } - - /** - * Returns the {@link WebsiteMonitor} component instance.

- * Not public API. For unit tests only. - * - * @return the {@link WebsiteMonitor} instance. - */ - protected WebsiteMonitor getMonitor() - { - return monitor; - } - -} -``` - -1. Let's run the test and see what happens. You can run the test from within your favourite IDE, or from command prompt by typing - -``` - mvn clean test -``` - -At this point, the Mojo test should run without any failures. - -Great! You have just hooked your Plexus component successfully to a Maven plugin. - -For more information on developing and using Maven plugins, please refer to [Guide to Developing Java Plugins](http://maven.apache.org/guides/plugin/guide-java-plugin-development.html) +Replaced by [Testing Maven plugins](/guides/migrating-from-plexus-container.html#Testing_Maven_plugins) and [Maven Plugin Testing Harness](https://maven.apache.org/plugin-testing/maven-plugin-testing-harness/getting-started/index.html). diff --git a/src/site/markdown/guides/writing-components/07_02_from_a_plexus_application.md b/src/site/markdown/guides/writing-components/07_02_from_a_plexus_application.md index 0525bfb..780db90 100644 --- a/src/site/markdown/guides/writing-components/07_02_from_a_plexus_application.md +++ b/src/site/markdown/guides/writing-components/07_02_from_a_plexus_application.md @@ -4,238 +4,8 @@ author: Rahul Thakur date: 2006-06-08 --- -`The contents of this document are a work in progress` - # Plexus Website Monitor Application -This section will show how to use a Plexus component in a Plexus application. - -## Setting up a Plexus Application project - -### Creating a Plexus application project using an archetype - -Maven Archetypes are discussed in detail [here](http://maven.apache.org/guides/mini/guide-creating-archetypes.html). - -1. From the command prompt, change directory to the location where you want to setup the Plexus application project. - -1. Run the following command to set up a skeleton Plexus Application project. - -``` - - mvn archetype:create -DarchetypeGroupId=org.codehaus.plexus -DarchetypeArtifactId=plexus-archetype-application \ - -DarchetypeVersion=1.0-alpha-1-SNAPSHOT -DgroupId=org.codehaus.plexus -DartifactId=plexus-website-monitor-application \ - -DremoteRepositories=http://snapshots.repository.codehaus.org/ - -``` - -The `maven-archetype-mojo` sets up a skeleton Maven plugin project '`plexus-website-monitor-application`' for us with reasonable defaults. - -### Updating pom.xml dependencies - -1. Locate pom.xml under the '`plexus-website-monitor-application`' folder. - -1. Edit it and add a `dependency` to the plexus-website-monitor-component that we have developed in earlier chapters. - -1. We also configure a - -The pom.xml should look like this now: - -``` - - - - plexus-examples - org.codehaus.plexus.examples - 1-SNAPSHOT - - 4.0.0 - org.codehaus.plexus - plexus-website-monitor-application - plexus-application - 1.0-SNAPSHOT - - - - org.codehaus.plexus - plexus-appserver-maven-plugin - true - - src/conf - foo - src/conf/application.xml - src/plexus.properties - - - - - - - junit - junit - 3.8.1 - test - - - org.codehaus.plexus - plexus-website-monitor-component - 1.0-SNAPSHOT - - - - -``` - -### Setting up an IDE project - -Before we proceed further let us set up an Eclipse project for our Plexus application project. To do so currently, and as a workaround we comment out the generated `` element in the `pom.xml` and add a `jar`. To generate an Eclipse project: - -1. Open up a command prompt/terminal, and - -1. run the following command - -``` - - mvn eclipse:clean eclipse:eclipse - -``` - -Import the generated project under an Eclipse Project. - -### Adding an Application Entry Class - -For any standalone Java application, we need a Class that defines a `main` method; the case of Plexus application is no different. We add a Application main class for our application (don't worry about the implementation details yet). - -We create a folder for Java sources `src/main/java` and add a sensible package for the main class. For this trail, we have created the package `org.codehaus.plexus.site.monitor` and create a main class `Main.java` under it. - -The generated source with a `System.out.println()` looks like below: - -``` - -public class Main -{ - - public static void main( String[] args ) - { - System.out.println ("Hello Plexus application!"); - - } - -} - -``` - -Having imported the project and added a main class, we now revert the `packaging` back to value `plexus-application`. - -### Setting up packaging configuration - -Next we set up an application assembler plugin for our Plexus application project. To do this, - -1. Locate the pom.xml for the plexus application project - -1. update the ` element configuration such that it is reflected as below - -``` - -... - - - - org.codehaus.plexus - plexus-appserver-maven-plugin - true - - src/conf - foo - src/conf/application.xml - src/plexus.properties - - - - - org.codehaus.mojo - appassembler-maven-plugin - - - package - - assemble - - - - - target/site-monitor-app - - true - - - - monitor - - org.codehaus.plexus.site.monitor.Main - - - - - - - -... - -``` - -Note how the assembly directory is specified in the `appassembler` plugin configuration - this is where our Plexus application will be packaged up when the Maven plugin is invoked. - -The discussion on Plugin configuration is beyond the scope of this tutorial, you can refer to book 'Better builds with Maven' or other resources available at: - -1. [Maven Books and Articles](http://maven.apache.org/articles.html). - -### Adding `\ for Appassembler plugin download - -As of this writing the Appassembler pluging is available from the Codehaus snapshots repository. To have Maven download the latest version (snapshot), we add the `pluginRepositories` information to the `pom.xml` - -``` - -.... -.... - - - codehaus-mojo-snapshots - Codehaus Snapshots - http://snapshots.repository.codehaus.org/ - - - -``` - -### Testing Application configuration - -Before we go any further, let us take our Plexus site monitor application for a spin. To do this: - -1. Open a command prompt/terminal - -1. Change directory to the Plexus application project's directory - -1. Run the following Maven command - -``` -mvn clean package -``` - -If you look under `target` directory you will see that the Site Monitor application is assembled under `site-monitor-app` directory. The contents under that directory consist of executable scripts (Shell and batch script by default). - -Lets try running the application and see what happens. To do this: - -1. At the command prompt, change directory to `$project-home/target/site-monitor-app/bin` - -1. Run the script appropriate for your operating system. - -You should an output similar to as below on the console: - -``` -E:\plexus\plexus-examples\plexus-website-monitor-application\target\site-monitor-app\bin>monitor.bat -Hello Plexus application! -``` - -At this point we are ready to play with Plexus Embedder and hook our Website monitor component into our Plexus application. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page embedded a Plexus container in a standalone application. -[Next: Plexus Embedder Intro & Site Monitor component integration into the application ](./07_02_plexus_embedder_and_component_integration.html) +For the replacement, see [Looking up components](/guides/migrating-from-plexus-container.html#Looking_up_components) and [Parts without a replacement](/guides/migrating-from-plexus-container.html#Parts_without_a_replacement). diff --git a/src/site/markdown/guides/writing-components/07_02_plexus_embedder_and_component_integration.md b/src/site/markdown/guides/writing-components/07_02_plexus_embedder_and_component_integration.md index 5424251..813c363 100644 --- a/src/site/markdown/guides/writing-components/07_02_plexus_embedder_and_component_integration.md +++ b/src/site/markdown/guides/writing-components/07_02_plexus_embedder_and_component_integration.md @@ -4,113 +4,8 @@ author: Rahul Thakur date: 2006-11-15 --- -`The contents of this document are a work in progress` - # Plexus Embedder -The Plexus Embedder allows us to set up and start a Plexus Container container from within a Standalone application. The components can then be looked up in usual manner (we will see demonstrate in bit, if you don't know). - -## Making Embedder available to the application - -First thing, we need to make the Embedder available to our application by adding a dependency on it in the `pom.xml`. Follow snippet shows the relevant ` section of the application project's `pom.xml`. - -``` - - - ... - - - junit - junit - 3.8.1 - test - - - org.codehaus.plexus - plexus-website-monitor-component - 1.0-SNAPSHOT - - - - org.codehaus.plexus - plexus-container-default - 1.0-alpha-9 - - - ... - - -``` - -Regenerate the IDE project again as discussed in the previous section. - -## Starting up an embedded Plexus Container instance - -Lets add some code to our Site Monitor application entry class that: - -1. creates and starts an Embedder instance - -1. Obtains `PlexusContainer` instance, and - -1. performs a lookup for `WebsiteMonitor` component - -Our updated code looks as below: - -``` -public class Main -{ - - /** - * @param args - */ - public static void main( String[] args ) - { - Embedder embedder = new Embedder(); - try - { - embedder.start(); - PlexusContainer container = embedder.getContainer(); - WebsiteMonitor monitor = (WebsiteMonitor) container.lookup( WebsiteMonitor.ROLE ); - try - { - monitor.monitor(); - } - catch ( Exception e ) - { - e.printStackTrace(); - } - - } - catch ( PlexusContainerException e ) - { - e.printStackTrace(); - } - catch ( ComponentLookupException e ) - { - e.printStackTrace(); - } - - } - -} -``` - -At this point you can try running the above `Main` class from your favorite IDE. For demonstration purposes the `WebsiteMonitor` is by default configured to monitor `http://plexus.codehaus.org`. You should see it output the HTTP status for the monitoring request issued. - -Something like this: - -``` -[INFO] HTTP request returned HTTP status code: 200 for website: http://plexus.codehaus.org/ -``` - -## How does Plexus Embedder works? - -Plexus Embedder creates an instance of Plexus Container, which then loads and parses all available dependencies to discover any Plexus Components and registers them internally to make them available for look-ups. - -To recapture again, the container looks for a Component descriptor under: - -1. META-INF/plexus/components.xml - -This is exactly what those few lines of code achieve in the above snippet. You can, of course, use the Embedder to do fancier stuff. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page started an embedded container. -Great! we have just finished integrating our site monitor component into our site monitor application. +For the replacement, see [Looking up components](/guides/migrating-from-plexus-container.html#Looking_up_components). diff --git a/src/site/markdown/guides/writing-components/07_03_from_a_web_application.md b/src/site/markdown/guides/writing-components/07_03_from_a_web_application.md index a982026..1454ec7 100644 --- a/src/site/markdown/guides/writing-components/07_03_from_a_web_application.md +++ b/src/site/markdown/guides/writing-components/07_03_from_a_web_application.md @@ -6,142 +6,8 @@ author: date: 2006-11-21 --- -`The contents of this document are a work in progress` - # How to use Plexus in web applications -Before we demonstrate how we can set up a web application to start a Plexus Container and look up Plexus components, let us understand the alternatives that are available to embed Plexus container in web applications. - -## Configuration - -Plexus Servlet module exists for simplifying embedding and usage of Plexus in context of web applications which run inside the servlet container. - -There are two ways of embedding Plexus. - -1. By setting up a **Plexus[ServletContextListener](http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html)** - -1. By setting up a **PlexusLoaderServlet**. - -The first way is suported by servlet containers which are compliant with servlet specification 2.3 or higher. Second one should be used for compatibility with older versions of servlet containers - -## Setting up PlexusServletContextListener to embed Plexus - -``` - - ... - - org.codehaus.plexus.servlet.PlexusServletContextListener - - ... - -``` - -## Setting up PlexusLoaderServlet to embed Plexus - -``` - - plexus - org.codehaus.plexus.servlet.PlexusLoaderServlet - 1 - -``` - -By default, in both the above cases, the Plexus Embedder will search for the configuration files in the following locations: - -- /WEB-INF/plexus.xml (for main Plexus configuration file) - -- /WEB-INF/plexus.properties (for properties file which is used for seeding Plexus context) - -These location can be overidden _TODO: explain how_ - - - - - - -In both the above cases a new instance of Plexus Conatiner will be created and stored in "application" scope for the web application under the key: **org.codehaus.plexus.PlexusConstants.PLEXUS_KEY** - -## How to lookup and release components - -### In a Servlet - -``` -... -ServletContext context = getServletContext(); -VelocityComponent velocityComponent = ( VelocityComponent ) PlexusServletUtils.lookup( context, VelocityComponent.ROLE ); -... -PlexusServletUtils.release( context, velocityComponent ); -... -``` - -### In JSP - -``` -<% -... -VelocityComponent velocityComponent = ( VelocityComponent ) PlexusServletUtils.lookup( application, VelocityComponent.ROLE ); -... -PlexusServletUtils.release( application, velocityComponent ); -... -%> -``` - -### In Struts Action or in similar case - -``` -public abstract class BaseAction extends Action -{ - protected Object lookup( HttpServletRequest request, String role ) - throws ServletException - { - HttpSession session = request.getSession(); - - ServletContext application = session.getServletContext(); - - Object retValue = PlexusServletUtils.lookup( application, role ); - - return retValue; - } - - protected void release( HttpServletRequest request, Object component ) - throws ServletException - { - HttpSession session = request.getSession(); - - ServletContext application = session.getServletContext(); - - PlexusServletUtils.release( application, component ); - } - - void someAction( HttpServletRequest request ) - { - VelocityComponent velocityComponent= ( VelocityComponent ) lookup( request, VelocityComponent.ROLE ); - - .... - - release( request, velocityComponent ); - } -} -``` - -## Obtaining the Plexus Container instance - -If you need to access the instance of PlexusContainer object, it can be obtained by the following call: - -``` -PlexusContainer getPlexusContainer( ServletContext servletContext ) -``` - -### Required artifacts - -Maven dependency: - -``` - - plexus - plexus-servlet - 1.0-beta-2 - -``` +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page used the Plexus servlet listener and loader in a web application. -[Next: Setting up a Web Application Project ](./07_03_setting_up_a_web_application.html) +For the replacement, see [Parts without a replacement](/guides/migrating-from-plexus-container.html#Parts_without_a_replacement). diff --git a/src/site/markdown/guides/writing-components/07_03_setting_up_a_web_application.md b/src/site/markdown/guides/writing-components/07_03_setting_up_a_web_application.md index 22e0c4b..28433d4 100644 --- a/src/site/markdown/guides/writing-components/07_03_setting_up_a_web_application.md +++ b/src/site/markdown/guides/writing-components/07_03_setting_up_a_web_application.md @@ -4,138 +4,8 @@ author: Rahul Thakur date: 2006-11-22 --- -`The contents of this document are a work in progress` - # Preparing the web application project to use Plexus -We will create a very basic web application project first and then gradually evolve it to demonstrate how Plexus can be embedded. - -To create a web application skeleton: - -1. Open the command prompt/terminal window. - -1. Change directory to where you want to create your web application project. - -1. Run the following Maven command - -``` -mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes \ - -DarchetypeArtifactId=maven-archetype-webapp \ - -DarchetypeVersion=1.0-alpha-4-SNAPSHOT \ - -DgroupId=org.codehaus.plexus.examples \ - -DartifactId=plexus-example-webapp \ - -DpackageName=org.codehaus.plexus.tutorial \ - -Dpackaging=war \ - -DremoteRepositories=http://people.apache.org/repo/m2-snapshot-repository/ -``` - -**Archetype creation options are explained here:** - -|**Commandline Option**|**Description**|**Required**| -|---|---|---| -|-DarchetypeGroupId|"groupId" for the archetype we want to use|Yes| -|-DarchetypeArtifact|"artifactId" for the archetype we want to use|Yes| -|-DarchetypeVersion|"version" for the archetype we want to use|Yes| -|-DgroupId|"groupId" for the project to be generated|Yes| -|-DartifactId|"artifactId" for the project to be generated|Yes| -|-DpackageName|Base package name to be use for any Java sources being copied over|No| -|-Dpackaging|Packaging to be used for the created project|No| -|-DremoteRepositories|Comma-separated list of repositories to lookup to retrieve archetype|No| - -For more information on Maven Archetypes please refer to [this resource](http://maven.apache.org/guides/getting-started/index.html) on the Maven website. - -A web application project should have been created now at the location where you ran the `archetype:create` command. - -Locate the `pom.xml` under the created project, the contents of the POM should be as below: - -``` - - 4.0.0 - org.codehaus.plexus.examples - plexus-example-webapp - war - 1.0-SNAPSHOT - Maven Webapp Archetype - http://maven.apache.org - - - junit - junit - 3.8.1 - test - - - - plexus-example-webapp - - -``` - -## Updating the POM - -Before we can embed Plexus in our web application we need to make the JAR library that contains the Plexus Embedder available to our project. We do this by introducing required ` elements in the project's `pom.xml`. - -The updated `pom.xml` (along with some other updates) looks as below: - -``` - - - plexus-examples - org.codehaus.plexus.examples - 1-SNAPSHOT - - 4.0.0 - org.codehaus.plexus.examples - plexus-example-webapp - war - Plexus Web Application Example - 1.0-SNAPSHOT - http://maven.apache.org - - plexus-example-webapp - - - - junit - junit - 3.8.1 - test - - - - org.codehaus.plexus - plexus-servlet - 1.0-beta-5 - - - org.codehaus.plexus - plexus-container-default - 1.0-alpha-10 - - - -``` - -## Generate a Project for your IDE. - -### For Eclipse. - -1. Change directory to the newly created directory 'plexus-example-webapp' - -1. Run the following command from command prompt to generate Eclipse project setting files. - -``` - (for WTP 0.7) - E:\plexus\plexus-examples\plexus-example-webapp>mvn eclipse:eclipse -``` - -``` - (for WTP 1.0 or higher) - E:\plexus\plexus-examples\plexus-example-webapp>mvn eclipse:eclipse -Dwtpversion=1.0 -``` - -Eclipse project files should get generated succesfully at this point. If there were any unsatisfied dependencies, update ` for dependencies in pom.xml to an available release version. +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page set up a web application project for the Plexus servlet integration. -1. Fire up Eclipse and import the generated project into an Eclipse Workspace. +For the replacement, see [Parts without a replacement](/guides/migrating-from-plexus-container.html#Parts_without_a_replacement). diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 1b81bc8..7a4e569 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -16,7 +16,7 @@ Each project has its own site, linked below, with Javadoc and reports. Sources a Plexus originally had two halves: an IoC container, and a set of components written for it. **The container is retired.** Maven moved to [Eclipse Sisu](https://www.eclipse.org/sisu/) and [JSR-330](https://jcp.org/en/jsr/detail?id\=330) years ago, and nothing listed below needs a Plexus container to run -- the components are ordinary JSR-330 beans. -What remains, and what this project is now, is the second half: the libraries below. The container documentation is still on this site, under _Old IoC Documentation_, because a great deal of writing from that era links to it. See [Feature Comparison](./ref/feature-comparison.html) for how Plexus related to other IoC ecosystems of the time. +What remains, and what this project is now, is the second half: the libraries below. The container documentation is still on this site, under _Plexus Container (retired)_, because a great deal of writing from that era links to it. Pages that taught the container now point to replacements; start with [Migrating from the Plexus container](./guides/migrating-from-plexus-container.html). See [Feature Comparison](./ref/feature-comparison.html) for how Plexus related to other IoC ecosystems of the time. # Libraries @@ -62,7 +62,7 @@ What remains, and what this project is now, is the second half: the libraries be These are archived and receive no fixes, including security fixes. Don't start anything new on them. -- [plexus-containers](./plexus-containers/) -- use [Eclipse Sisu](https://www.eclipse.org/sisu/) with JSR-330 annotations. +- [plexus-containers](./plexus-containers/) -- use [Eclipse Sisu](https://www.eclipse.org/sisu/) with JSR-330 annotations; see [Migrating from the Plexus container](./guides/migrating-from-plexus-container.html). - [plexus-cipher](https://github.com/codehaus-plexus/plexus-cipher) -- absorbed into [plexus-sec-dispatcher](./plexus-sec-dispatcher/) 4.x. diff --git a/src/site/markdown/new-container-gotchas.md b/src/site/markdown/new-container-gotchas.md index f8c824e..913a67f 100644 --- a/src/site/markdown/new-container-gotchas.md +++ b/src/site/markdown/new-container-gotchas.md @@ -22,4 +22,4 @@ Similar to above, but more serious. This causes the new component API to be load ## Maven Jetty Plugin -The Maven Jetty Plugin seems to be failing with webapps that use the plexus container in some instances. In former versions of plexus-xwork-integration, the container was forced to ignore plexus.xml from Maven using a classloader. Using the new version this appears not to work (though I suspect it would work if Maven was using the new container too - ie, trunk). More investigation needed. See [ JETTY-62](http://jira.codehaus.org/browse/JETTY-62) for the original problem that is reoccurring. +The Maven Jetty Plugin seems to be failing with webapps that use the plexus container in some instances. In former versions of plexus-xwork-integration, the container was forced to ignore plexus.xml from Maven using a classloader. Using the new version this appears not to work (though I suspect it would work if Maven was using the new container too - ie, trunk). More investigation needed. See JETTY-62 for the original problem that is reoccurring. diff --git a/src/site/markdown/ref/component-configuration.md b/src/site/markdown/ref/component-configuration.md index abfbda3..878bf9e 100644 --- a/src/site/markdown/ref/component-configuration.md +++ b/src/site/markdown/ref/component-configuration.md @@ -2,68 +2,14 @@ title: Component Configuration --- -`The contents of this document are a work in progress` - # Component Configuration -## Overview - -For each component plexus creates a component profile. The profiles keeps track of the following things for each component: - -- [Component_Factory](#Component_Factory) - -- [Lifecycle_Handler](#Lifecycle_Handler) +The Plexus container is retired and archived, so this page no longer carries the instructions it once had. It stays at this address because other sites link to it. The original page described the component profile and the `components.xml` descriptor. -- [Component_Composer](#Component_Composer) - -- [Instantiation_Strategy](#Instantiation_Strategy) +## Overview -- The configuration for the component +Replaced by [Components and injection](/guides/migrating-from-plexus-container.html#Components_and_injection) and [converting Plexus components to JSR-330](https://eclipse.dev/sisu/org.eclipse.sisu.plexus/conversion-to-jsr330.html) in the Sisu documentation. ## Component Descriptor -Let's take a look at the component descriptor. It starts off with a block for the component: - -``` - -``` - -You can then declare the role and the role hint of the component. The role and the hint are what you use to look up your component from plexus. The hint is optional. The hint is just an extra id that allows you to differentiate components of the same type. - -``` -org.codehaus.plexus.Component -component1 -``` - -The implementation attribute tells plexus what you want to use to implement the specified role: - -``` -org.codehaus.plexus.DefaultComponent -``` - -You can specify how your class should be created via the component factory. The default is java. But, there are additional \[Component Factories\] as well for groovy, bsh, and jpython. - -``` -org.codehaus.plexus.DefaultComponent -``` - -If you want to use a personality that is not the default personality, you can specify a lifecycle handler. You will need this when you are mixing and matching component personalities. - -``` -avalon -``` - -Then, there is the instantiation strategy. This controls how often plexus creates your components. There are the following options: - -|**Strategy**|**Description**|| -|---|---|---| -|per-lookup|Every time you lookup a component one will be created.|| -|singleton|Only one instance of your component will ever be created.|| -|keep-alive|This ensures a component is only used as a singleton, and is only shutdown when the container shuts down.|| -|poolable|Pools several component instances.|| - -The default is singleton and you can change the strategy like this: - -``` -per-lookup -``` +Replaced by [Component index](/guides/migrating-from-plexus-container.html#Component_index). diff --git a/src/site/markdown/ref/why-use-components.md b/src/site/markdown/ref/why-use-components.md index f93063e..cad97e1 100644 --- a/src/site/markdown/ref/why-use-components.md +++ b/src/site/markdown/ref/why-use-components.md @@ -78,7 +78,7 @@ While components can usually be tested by conventional means, Plexus comes with Clear separation of components, along with well-defined interfaces, allow replacing components with other implementations. This can facilitate advanced application architectures without code modifications. -An example of this can be seen in Apache Geronimo's GBuild, which is built on [ Apache Continuum](http://continuum.apache.org/), a Plexus application. By replacing some components with identical functionality that works with ActiveMQ, a distributed countinuous integration server was built. +An example of this can be seen in Apache Geronimo's GBuild, which is built on [ Apache Continuum](https://continuum.apache.org/), a Plexus application. By replacing some components with identical functionality that works with ActiveMQ, a distributed countinuous integration server was built. Additionally, the container can provide features that can be applied to all components consistently without code modifications. For example, Plexus can resolve components transparently at runtime from a Maven repository. @@ -88,7 +88,7 @@ Additionally, the container can provide features that can be applied to all comp Other projects have also offered what a component may be: -- [ PicoContainer](http://picocontainer.codehaus.org/Inversion\+of\+Control) +- [ PicoContainer](http://picocontainer.com/) - [ Avalon](http://avalon.apache.org/central/cop/index.html) diff --git a/src/site/site.xml b/src/site/site.xml index 30cc192..8d6abe1 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -50,19 +50,20 @@ under the License. Kept, and kept at these exact URLs, because a great deal of external writing links to it. Do not move or delete these pages. -->

- + + - + - + - + - +