pax_global_header00006660000000000000000000000064116632706670014530gustar00rootroot0000000000000052 comment=4d78d1ff3dbdb59bb938d7133e5a4b889a4cb224 plexus-containers1.5-1.5.5/000077500000000000000000000000001166327066700154475ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/000077500000000000000000000000001166327066700233225ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/pom.xml000066400000000000000000000014331166327066700246400ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus plexus-containers 1.5.5 plexus-component-annotations Plexus :: Component Annotations Plexus Component "Java 5" Annotations, to describe plexus components properties in java sources with standard annotations instead of javadoc annotations. plexus-containers1.5-1.5.5/plexus-component-annotations/src/000077500000000000000000000000001166327066700241115ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/src/main/000077500000000000000000000000001166327066700250355ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/src/main/java/000077500000000000000000000000001166327066700257565ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/src/main/java/org/000077500000000000000000000000001166327066700265455ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/src/main/java/org/codehaus/000077500000000000000000000000001166327066700303405ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/src/main/java/org/codehaus/plexus/000077500000000000000000000000001166327066700316605ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/src/main/java/org/codehaus/plexus/component/000077500000000000000000000000001166327066700336625ustar00rootroot00000000000000000077500000000000000000000000001166327066700361405ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/src/main/java/org/codehaus/plexus/component/annotationsComponent.java000066400000000000000000000031441166327066700407470ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/src/main/java/org/codehaus/plexus/component/annotations/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.component.annotations; import java.lang.annotation.Documented; import static java.lang.annotation.ElementType.TYPE; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Target; /** * Marks a class as a Plexus component. * * @since 1.0-alpha-33 * @version $Id: Component.java 8467 2009-10-05 20:55:48Z hboutemy $ */ @Documented @Retention(RUNTIME) @Target(TYPE) @Inherited public @interface Component { Class role(); String hint() default ""; String version() default ""; String alias() default ""; String description() default ""; String lifecycleHandler() default ""; String instantiationStrategy() default ""; String factory() default ""; String type() default ""; String profile() default ""; String composer() default ""; String configurator() default ""; boolean isolatedRealm() default false; } Configuration.java000066400000000000000000000023531166327066700416150ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/src/main/java/org/codehaus/plexus/component/annotations/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.component.annotations; import java.lang.annotation.Documented; import static java.lang.annotation.ElementType.FIELD; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Target; /** * Marks a field as a configuration element with a default value. * * @since 1.0-alpha-33 * @version $Id: Configuration.java 8467 2009-10-05 20:55:48Z hboutemy $ */ @Documented @Retention(RUNTIME) @Target(FIELD) @Inherited public @interface Configuration { String name() default ""; String value(); } Requirement.java000066400000000000000000000027251166327066700413110ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-annotations/src/main/java/org/codehaus/plexus/component/annotations/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.component.annotations; import java.lang.annotation.Documented; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Target; /** * Configures a requirement. * * @since 1.0-alpha-33 * @version $Id: Requirement.java 8467 2009-10-05 20:55:48Z hboutemy $ */ @Documented @Retention(RUNTIME) @Target({ FIELD, METHOD }) @Inherited public @interface Requirement { Class role() default Object.class; String hint() default ""; // // HACK: This is here to support component requirement lists, which can take a list of hints // String[] hints() default {}; boolean optional() default false; } plexus-containers1.5-1.5.5/plexus-component-javadoc/000077500000000000000000000000001166327066700223745ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/pom.xml000066400000000000000000000047321166327066700237170ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus plexus-containers 1.5.5 plexus-component-javadoc Plexus :: Javadoc Taglets Plexus Javadoc Taglets to generate additional documentation for plexus components' javadoc from plexus javadoc annotations. 2007 default-tools.jar java.vendor Sun Microsystems Inc. com.sun tools 1.4.2 system ${java.home}/../lib/tools.jar run-its maven.test.skip !true maven-invoker-plugin 1.4 true ${project.build.directory}/it setup verify ${project.build.directory}/local-repo src/it/settings.xml clean javadoc:javadoc integration-test install run plexus-containers1.5-1.5.5/plexus-component-javadoc/src/000077500000000000000000000000001166327066700231635ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/000077500000000000000000000000001166327066700235775ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/basic/000077500000000000000000000000001166327066700246605ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/basic/pom.xml000066400000000000000000000032431166327066700261770ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus.plexus-javadoc test 1.0-SNAPSHOT jar 2008 Test Plexus Tags org.apache.maven.plugins maven-javadoc-plugin 2.3 ${basedir}/target/site/apidocs true private UTF-8 UTF-8 UTF-8 org.codehaus.plexus.javadoc.PlexusComponentTaglet org.codehaus.plexus.javadoc.PlexusConfigurationTaglet org.codehaus.plexus.javadoc.PlexusRequirementTaglet org.codehaus.plexus plexus-component-javadoc @project.version@ plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/basic/src/000077500000000000000000000000001166327066700254475ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/basic/src/main/000077500000000000000000000000001166327066700263735ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/basic/src/main/java/000077500000000000000000000000001166327066700273145ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/basic/src/main/java/plexus/000077500000000000000000000000001166327066700306345ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/basic/src/main/java/plexus/test/000077500000000000000000000000001166327066700316135ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/basic/src/main/java/plexus/test/App.java000066400000000000000000000032371166327066700332030ustar00rootroot00000000000000package plexus.test; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * App class * * @author Vincent Siveton * @version 1.0 * @plexus.component role="org.codehaus.plexus.test.App" role-hint="app" */ public class App { /** * @plexus.configuration default-value="someone" */ private String name; /** * @plexus.requirement * role-hint="foo" */ private App app; /** * The main method * * @param args an array of strings that contains the arguments */ public static void main( String[] args ) { System.out.println( "Sample Application." ); } /** * Sample method that prints out the parameter string. * * @param str The string value to be printed. */ protected void sampleMethod( String str ) { System.out.println( str ); } } plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/basic/verify.bsh000066400000000000000000000042451166327066700266670ustar00rootroot00000000000000import java.io.*; import java.util.*; import java.util.regex.*; import org.codehaus.plexus.util.*; setAccessibility( true ); File docsDir = new File( basedir, "target/site/apidocs" ); System.out.println( "Checking for existence of: " + docsDir ); if ( !docsDir.exists() ) { throw new FileNotFoundException( docsDir + " was not created" ); } File docFile = new File( docsDir, "plexus/test/App.html" ); System.out.println( "Checking for existence of: " + docFile ); if ( !docFile.isFile() ) { throw new FileNotFoundException( docFile + " was not created" ); } String html = FileUtils.fileRead( docFile, "UTF-8" ).replaceAll( "(\r\n)|(\r)|(\n)", "" ); System.out.println( "Checking for documentation of Plexus component" ); String plexusComponent = "
plexus component:
" + "
" + "
" + "
role:
" + "
\"org.codehaus.plexus.test.app\"
" + "
role-hint:
" + "
\"app\"
" + "
"; if ( html.toLowerCase( Locale.ENGLISH ).indexOf( ( plexusComponent ).toLowerCase( Locale.ENGLISH ) ) < 0 ) { throw new IllegalStateException( "Plexus component doc wrong" ); } System.out.println( "Checking for documentation of Plexus configuration" ); String plexusConfig = "
plexus configuration:
" + "
" + "
default-value:
" + "
\"someone\"
"; if ( html.toLowerCase( Locale.ENGLISH ).indexOf( ( plexusConfig ).toLowerCase( Locale.ENGLISH ) ) < 0 ) { throw new IllegalStateException( "Plexus configuration doc wrong" ); } System.out.println( "Checking for documentation of Plexus requirement" ); String plexusRequirement = "
plexus requirement:
" + "
" + "
role-hint:
\"foo\"
" + "
"; if ( html.toLowerCase( Locale.ENGLISH ).indexOf( ( plexusRequirement ).toLowerCase( Locale.ENGLISH ) ) < 0 ) { throw new IllegalStateException( "Plexus requirement doc wrong" ); } return true; plexus-containers1.5-1.5.5/plexus-component-javadoc/src/it/settings.xml000066400000000000000000000015761166327066700261720ustar00rootroot00000000000000 it-repo true local.central @localRepositoryUrl@ true true local.central @localRepositoryUrl@ true true plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/000077500000000000000000000000001166327066700241075ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/java/000077500000000000000000000000001166327066700250305ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/java/org/000077500000000000000000000000001166327066700256175ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/java/org/codehaus/000077500000000000000000000000001166327066700274125ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/java/org/codehaus/plexus/000077500000000000000000000000001166327066700307325ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/java/org/codehaus/plexus/javadoc/000077500000000000000000000000001166327066700323415ustar00rootroot00000000000000AbstractPlexusTaglet.java000066400000000000000000000127221166327066700372360ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/java/org/codehaus/plexus/javadocpackage org.codehaus.plexus.javadoc; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Enumeration; import java.util.StringTokenizer; import javax.swing.text.AttributeSet; import javax.swing.text.MutableAttributeSet; import javax.swing.text.SimpleAttributeSet; import com.sun.javadoc.Tag; import com.sun.tools.doclets.Taglet; /** * Abstract Taglet for Plexus tags. * * @see * http://plexus.codehaus.org/guides/developer-guide/appendices/javadoc-tags-reference.html * * @author Vincent Siveton * @version $Id: AbstractPlexusTaglet.java 7277 2008-04-11 18:12:21Z bentmann $ */ public abstract class AbstractPlexusTaglet implements Taglet { /** {@inheritDoc} */ public String toString( Tag tag ) { if ( tag == null ) { return null; } String tagText = tag.text(); MutableAttributeSet att = getAttributes( tagText ); StringBuffer sb = new StringBuffer(); if ( ( att == null ) || ( att.getAttributeCount() == 0 ) ) { sb.append( "
" ).append( getHeader() ).append( "
" ); } else { sb.append( "
" ).append( getHeader() ).append( ":
" ); sb.append( "
" ); appendPlexusTag( sb, att ); sb.append( "
" ); } return sb.toString(); } /** {@inheritDoc} */ public String toString( Tag[] tags ) { if ( tags.length == 0 ) { return null; } boolean hasParameters = false; for ( int i = 0; i < tags.length; i++ ) { String tagText = tags[i].text(); MutableAttributeSet att = getAttributes( tagText ); if ( att != null ) { hasParameters = att.getAttributeCount() > 0; } } StringBuffer sb = new StringBuffer(); sb.append( "
" ).append( getHeader() ).append( ( hasParameters ? ":" : "" ) ).append( "
" ); sb.append( "
" ); for ( int i = 0; i < tags.length; i++ ) { if ( i > 0 ) { sb.append( ", " ); } String tagText = tags[i].text(); appendPlexusTag( sb, getAttributes( tagText ) ); } sb.append( "
" ); return sb.toString(); } /** * @return the header to display */ public abstract String getHeader(); /** * @param text the Tag text returned by {@link Tag#text()} * @return a MutableAttributeSet or null if text was null */ private MutableAttributeSet getAttributes( String text ) { if ( text == null || text.trim().length() == 0 ) { return null; } MutableAttributeSet att = new SimpleAttributeSet(); StringTokenizer token = new StringTokenizer( text, " " ); while ( token.hasMoreTokens() ) { String nextToken = token.nextToken(); StringTokenizer token2 = new StringTokenizer( nextToken, "=" ); if ( token2.countTokens() != 2 ) { System.err.println( "The annotation '" + getName() + "' has a wrong Plexus annotations: " + text ); continue; } String name = token2.nextToken(); String value = token2.nextToken(); att.addAttribute( name, value ); } return att; } /** * Append the wanted display in the javadoc. * * @param sb * @param att */ private static void appendPlexusTag( StringBuffer sb, MutableAttributeSet att ) { if ( att == null ) { return; } if ( att.getAttributeCount() > 0 ) { sb.append( "
" ); Enumeration names = att.getAttributeNames(); while ( names.hasMoreElements() ) { Object key = names.nextElement(); Object value = att.getAttribute( key ); if ( value instanceof AttributeSet ) { // ignored } else { sb.append( "
" ).append( key ).append( ":
" ); sb.append( "
" ).append( value ).append( "
" ); } } sb.append( "
" ); } } } PlexusComponentTaglet.java000066400000000000000000000077031166327066700374400ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/java/org/codehaus/plexus/javadocpackage org.codehaus.plexus.javadoc; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Map; import com.sun.tools.doclets.Taglet; /** * The @plexus.component tag is used to show that the class it annotates is a plexus component. * This will add a <component> element to the <components> 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 <description> tag. * * * * * * * * * * * * * * * * * * * * * * * *
ParameterRequiredDescription
roleYesThe role that this class provides an implementation for (usually the class name * of an implemented Interface
role-hintNoThe hints are used to differentiate multiple implementations of the same role
versionNoSet the version of the component
* * @see * http://plexus.codehaus.org/guides/developer-guide/appendices/javadoc-tags-reference.html * * @author Vincent Siveton * @version $Id: PlexusComponentTaglet.java 7277 2008-04-11 18:12:21Z bentmann $ */ public class PlexusComponentTaglet extends AbstractPlexusTaglet { private static final String NAME = "plexus.component"; private static final String HEADER = "Plexus component"; /** {@inheritDoc} */ public String getHeader() { return HEADER; } /** {@inheritDoc} */ public String getName() { return NAME; } /** {@inheritDoc} */ public boolean inConstructor() { return false; } /** {@inheritDoc} */ public boolean inField() { return false; } /** {@inheritDoc} */ public boolean inMethod() { return false; } /** {@inheritDoc} */ public boolean inOverview() { return false; } /** {@inheritDoc} */ public boolean inPackage() { return false; } /** {@inheritDoc} */ public boolean inType() { return true; } /** {@inheritDoc} */ public boolean isInlineTag() { return false; } /** * Register this Taglet. * * @param tagletMap the map to register this tag to. */ public static void register( Map tagletMap ) { PlexusComponentTaglet tag = new PlexusComponentTaglet(); Taglet t = (Taglet) tagletMap.get( tag.getName() ); if ( t != null ) { tagletMap.remove( tag.getName() ); } tagletMap.put( tag.getName(), tag ); } } PlexusConfigurationTaglet.java000066400000000000000000000065321166327066700403040ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/java/org/codehaus/plexus/javadocpackage org.codehaus.plexus.javadoc; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Map; import com.sun.tools.doclets.Taglet; /** * The @plexus.configuration tags are used to mark fields in a class for configuration through * the components.xml. * * * * * * * * * * * * * *
ParameterRequiredDescription
default-valueCurrentlyThe default values are currently required for the <configuration> * tag to be written to components.xml.
* * @see * http://plexus.codehaus.org/guides/developer-guide/appendices/javadoc-tags-reference.html * * @author Vincent Siveton * @version $Id: PlexusConfigurationTaglet.java 7277 2008-04-11 18:12:21Z bentmann $ */ public class PlexusConfigurationTaglet extends AbstractPlexusTaglet { private static final String NAME = "plexus.configuration"; private static final String HEADER = "Plexus configuration"; /** {@inheritDoc} */ public String getHeader() { return HEADER; } /** {@inheritDoc} */ public String getName() { return NAME; } /** {@inheritDoc} */ public boolean inConstructor() { return false; } /** {@inheritDoc} */ public boolean inField() { return true; } /** {@inheritDoc} */ public boolean inMethod() { return false; } /** {@inheritDoc} */ public boolean inOverview() { return false; } /** {@inheritDoc} */ public boolean inPackage() { return false; } /** {@inheritDoc} */ public boolean inType() { return false; } /** {@inheritDoc} */ public boolean isInlineTag() { return false; } /** * Register this Taglet. * * @param tagletMap the map to register this tag to. */ public static void register( Map tagletMap ) { PlexusConfigurationTaglet tag = new PlexusConfigurationTaglet(); Taglet t = (Taglet) tagletMap.get( tag.getName() ); if ( t != null ) { tagletMap.remove( tag.getName() ); } tagletMap.put( tag.getName(), tag ); } } PlexusRequirementTaglet.java000066400000000000000000000104121166327066700377650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/java/org/codehaus/plexus/javadocpackage org.codehaus.plexus.javadoc; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Map; import com.sun.tools.doclets.Taglet; /** * 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. * * * * * * * * * * * * * * * * * * *
ParameterRequiredDescription
roleNo. Yes if the field is a List or a MapThe 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-hintNo. Not allowed if the field is a List or a MapLinks 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-hints.
* * @see * http://plexus.codehaus.org/guides/developer-guide/appendices/javadoc-tags-reference.html * * @author Vincent Siveton * @version $Id: PlexusRequirementTaglet.java 7277 2008-04-11 18:12:21Z bentmann $ */ public class PlexusRequirementTaglet extends AbstractPlexusTaglet { private static final String NAME = "plexus.requirement"; private static final String HEADER = "Plexus requirement"; /** {@inheritDoc} */ public String getHeader() { return HEADER; } /** {@inheritDoc} */ public String getName() { return NAME; } /** {@inheritDoc} */ public boolean inConstructor() { return false; } /** {@inheritDoc} */ public boolean inField() { return true; } /** {@inheritDoc} */ public boolean inMethod() { return false; } /** {@inheritDoc} */ public boolean inOverview() { return false; } /** {@inheritDoc} */ public boolean inPackage() { return false; } /** {@inheritDoc} */ public boolean inType() { return false; } /** {@inheritDoc} */ public boolean isInlineTag() { return false; } /** * Register this Taglet. * * @param tagletMap the map to register this tag to. */ public static void register( Map tagletMap ) { PlexusRequirementTaglet tag = new PlexusRequirementTaglet(); Taglet t = (Taglet) tagletMap.get( tag.getName() ); if ( t != null ) { tagletMap.remove( tag.getName() ); } tagletMap.put( tag.getName(), tag ); } } plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/javadoc/000077500000000000000000000000001166327066700255165ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/javadoc/org/000077500000000000000000000000001166327066700263055ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/javadoc/org/codehaus/000077500000000000000000000000001166327066700301005ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/javadoc/org/codehaus/plexus/000077500000000000000000000000001166327066700314205ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/javadoc/org/codehaus/plexus/javadoc/000077500000000000000000000000001166327066700330275ustar00rootroot00000000000000package.html000077500000000000000000000026301166327066700352350ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/main/javadoc/org/codehaus/plexus/javadoc

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 Class Yes Indicate to Plexus CDC that the class is a component
@plexus.configuration Field No Tell Plexus CDC that this item should be configured through the components.xml
@plexus.requirement FieldNo Indicate to Plexus CDC that the field is required by the component
plexus-containers1.5-1.5.5/plexus-component-javadoc/src/site/000077500000000000000000000000001166327066700241275ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/site/apt/000077500000000000000000000000001166327066700247135ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-javadoc/src/site/apt/index.apt000066400000000000000000000024771166327066700265420ustar00rootroot00000000000000 ------ Introduction ------ Vincent Siveton ------ August 2007 ------ ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/guides/mini/guide-apt-format.html Plexus Doclet The Plexus Doclet project is a collection of several tags handle by the javadoc tool. For more information about the standard Javadoc tool, please refer to {{{http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html}Reference Guide}}. * Usage Instructions on how to use this project can be found {{{usage.html}here}}. plexus-containers1.5-1.5.5/plexus-component-javadoc/src/site/apt/usage.apt000066400000000000000000000047661166327066700265420ustar00rootroot00000000000000 ------ Usage ------ Vincent Siveton ------ August 2007 ------ ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/guides/mini/guide-apt-format.html Usage The doclets could be use directly in the {{{http://maven.apache.org/plugins/maven-javadoc-plugin/}maven-javadoc-plugin/}}. +-----+ ... org.apache.maven.plugins maven-javadoc-plugin org.codehaus.plexus.javadoc.PlexusComponentTaglet org.codehaus.plexus plexus-javadoc 1.0-SNAPSHOT org.codehaus.plexus.javadoc.PlexusConfigurationTaglet org.codehaus.plexus plexus-javadoc 1.0-SNAPSHOT org.codehaus.plexus.javadoc.PlexusRequirementTaglet org.codehaus.plexus plexus-javadoc 1.0-SNAPSHOT ... ... ... +-----+ plexus-containers1.5-1.5.5/plexus-component-javadoc/src/site/site.xml000066400000000000000000000006461166327066700256230ustar00rootroot00000000000000 plexus-containers1.5-1.5.5/plexus-component-metadata/000077500000000000000000000000001166327066700225455ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/README.txt000066400000000000000000000004021166327066700242370ustar00rootroot00000000000000The org.codehaus.plexus.component.repository.cdc package contains some classes copied from the container before it started using the "default" role hints. This can be removed once all supported maven versions are using a container newer than 1.0-alpha-19. plexus-containers1.5-1.5.5/plexus-component-metadata/pom.xml000066400000000000000000000072271166327066700240720ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus plexus-containers 1.5.5 plexus-component-metadata maven-plugin Plexus :: Component Metadata A Maven plugin to generate Plexus descriptors from source tags and class annotations. org.codehaus.plexus plexus-container-default org.codehaus.plexus plexus-component-annotations org.codehaus.plexus plexus-utils com.thoughtworks.qdox qdox jdom jdom org.apache.maven maven-plugin-api org.apache.maven maven-model org.apache.maven maven-project org.codehaus.plexus plexus-cli 1.2 commons-cli commons-cli 1.0 asm asm 3.1 org.apache.maven.plugins maven-plugin-plugin 2.4.2 run-its maven-invoker-plugin 1.4 true src/it ${project.build.directory}/it annotation-processing-test/* setup validate ${project.build.directory}/local-repo src/it/settings.xml clean process-classes integration-test install run plexus-containers1.5-1.5.5/plexus-component-metadata/src/000077500000000000000000000000001166327066700233345ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/000077500000000000000000000000001166327066700237505ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/000077500000000000000000000000001166327066700312515ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/pom.xml000066400000000000000000000032241166327066700325670ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus annotation-processing-test jar 1.0-SNAPSHOT annotation-processing-test http://maven.apache.org 1.0-beta-3.0.6-SNAPSHOT junit junit 3.8.1 test org.codehaus.plexus plexus-component-annotations ${plexusVersion} org.apache.maven.plugins maven-compiler-plugin 1.5 1.5 org.codehaus.plexus plexus-component-metadata ${plexusVersion} generate-metadata plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/000077500000000000000000000000001166327066700320405ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/000077500000000000000000000000001166327066700327645ustar00rootroot00000000000000000077500000000000000000000000001166327066700336265ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/java000077500000000000000000000000001166327066700344155ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/java/org000077500000000000000000000000001166327066700362105ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/java/org/codehaus000077500000000000000000000000001166327066700375305ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/java/org/codehaus/plexusAbstractPlexusComponent.java000066400000000000000000000003401166327066700452170ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; import org.codehaus.plexus.component.annotations.Requirement; public abstract class AbstractPlexusComponent implements PlexusComponent { @Requirement protected Executor executor; } Executor.java000066400000000000000000000001221166327066700421640ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; public interface Executor { String execute(); } FastExecutor.java000066400000000000000000000004011166327066700430020ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; import org.codehaus.plexus.component.annotations.Component; @Component(role = Executor.class, hint = "fast") public class FastExecutor implements Executor { public String execute() { return "fast"; } } PlexusComponent.java000066400000000000000000000001311166327066700435310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; public interface PlexusComponent { String execute(); } SlowExecutor.java000066400000000000000000000004041166327066700430340ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; import org.codehaus.plexus.component.annotations.Component; @Component(role=Executor.class,hint="slow") public class SlowExecutor implements Executor { public String execute() { return "slow"; } } SubclassPlexusComponent.java000066400000000000000000000004261166327066700452400ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; import org.codehaus.plexus.component.annotations.Component; @Component(role = Component.class) public class SubclassPlexusComponent extends AbstractPlexusComponent { public String execute() { return executor.execute(); } } plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/test/000077500000000000000000000000001166327066700330175ustar00rootroot00000000000000000077500000000000000000000000001166327066700336615ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/test/java000077500000000000000000000000001166327066700344505ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/test/java/org000077500000000000000000000000001166327066700362435ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/test/java/org/codehaus000077500000000000000000000000001166327066700375635ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/test/java/org/codehaus/plexusAppTest.java000066400000000000000000000012071166327066700420060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/annotation-processing-test/src/test/java/org/codehaus/plexuspackage org.codehaus.plexus; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Unit test for simple App. */ public class AppTest extends TestCase { /** * Create the test case * * @param testName name of the test case */ public AppTest( String testName ) { super( testName ); } /** * @return the suite of tests being tested */ public static Test suite() { return new TestSuite( AppTest.class ); } /** * Rigourous Test :-) */ public void testApp() { assertTrue( true ); } } plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/descriptor-1/000077500000000000000000000000001166327066700262645ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/descriptor-1/pom.xml000066400000000000000000000043011166327066700275770ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus.it.plexus-cdc-anno descriptor-1 testing org.codehaus.plexus plexus-component-annotations @project.version@ org.apache.maven.plugins maven-compiler-plugin 1.5 1.5 org.codehaus.plexus plexus-component-metadata @project.version@ generate-metadata plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/descriptor-1/src/000077500000000000000000000000001166327066700270535ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/descriptor-1/src/main/000077500000000000000000000000001166327066700277775ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/descriptor-1/src/main/java/000077500000000000000000000000001166327066700307205ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/descriptor-1/src/main/java/testing/000077500000000000000000000000001166327066700323755ustar00rootroot00000000000000ChildComponent.java000066400000000000000000000015231166327066700360700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/descriptor-1/src/main/java/testing/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package testing; import org.codehaus.plexus.component.annotations.*; /** * ??? * * @version $Id: ChildComponent.java 6922 2007-10-01 04:21:46Z user57 $ */ @Component(role=ChildComponent.class) public class ChildComponent { } MyComponent.java000066400000000000000000000017011166327066700354300ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/descriptor-1/src/main/java/testing/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package testing; import org.codehaus.plexus.component.annotations.*; /** * ??? * * @version $Id: MyComponent.java 6922 2007-10-01 04:21:46Z user57 $ */ @Component(role=MyComponent.class, hint="foo") public class MyComponent { @Requirement private ChildComponent child; @Configuration("bar") private String foo; } plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/descriptor-1/validate.groovy000066400000000000000000000016141166327066700313260ustar00rootroot00000000000000/* * Copyright (C) 2006-2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // // $Id: validate.groovy 8178 2009-05-12 19:21:54Z bentmann $ // def file = new File(basedir, 'target/classes/META-INF/plexus/components.xml') assert file.exists() def componentSet = new XmlParser().parse(file) assert componentSet.components.component.size() == 2 return true; plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/settings.xml000066400000000000000000000015761166327066700263430ustar00rootroot00000000000000 it-repo true local.central @localRepositoryUrl@ true true local.central @localRepositoryUrl@ true true plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/000077500000000000000000000000001166327066700270345ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/latin-1/000077500000000000000000000000001166327066700303015ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/latin-1/pom.xml000066400000000000000000000025511166327066700316210ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus.its.metadata latin-1 1.0 Latin-1 Test that source files using Latin-1 are properly parsed. ISO-8859-1 org.apache.maven.plugins maven-compiler-plugin 2.0.2 org.apache.maven.plugins maven-resources-plugin 2.2 org.codehaus.plexus plexus-component-metadata @project.version@ generate-metadata plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/latin-1/src/000077500000000000000000000000001166327066700310705ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/latin-1/src/main/000077500000000000000000000000001166327066700320145ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/latin-1/src/main/java/000077500000000000000000000000001166327066700327355ustar00rootroot00000000000000000077500000000000000000000000001166327066700336355ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/latin-1/src/main/java/testComponent.java000066400000000000000000000003161166327066700364420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/latin-1/src/main/java/testpackage test; // NOTE: This source file is by design encoded using ISO-8859-1! /** * TEST-CHARS: ÄÖÜäöüß * * @plexus.component role="test.Component" role-hint="default" */ public class Component { } plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/pom.xml000066400000000000000000000012451166327066700303530ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus.its.metadata aggregator 1.0 pom Aggregator Test that the character encoding of source files is respected by the metadata extractor. utf-8 latin-1 plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/utf-8/000077500000000000000000000000001166327066700277775ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/utf-8/pom.xml000066400000000000000000000025361166327066700313220ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus.its.metadata utf-8 1.0 UTF-8 Test that source files using UTF-8 are properly parsed. UTF-8 org.apache.maven.plugins maven-compiler-plugin 2.0.2 org.apache.maven.plugins maven-resources-plugin 2.2 org.codehaus.plexus plexus-component-metadata @project.version@ generate-metadata plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/utf-8/src/000077500000000000000000000000001166327066700305665ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/utf-8/src/main/000077500000000000000000000000001166327066700315125ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/utf-8/src/main/java/000077500000000000000000000000001166327066700324335ustar00rootroot00000000000000000077500000000000000000000000001166327066700333335ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/utf-8/src/main/java/testComponent.java000066400000000000000000000003171166327066700361410ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/utf-8/src/main/java/testpackage test; // NOTE: This source file is by design encoded using UTF-8! /** * TEST-CHARS: ßıΣЯ×€ * * @plexus.component role="test.Component" role-hint="default" */ public class Component { } plexus-containers1.5-1.5.5/plexus-component-metadata/src/it/source-encoding/validate.groovy000066400000000000000000000011651166327066700320770ustar00rootroot00000000000000def latin1File = new File(basedir, 'latin-1/target/classes/META-INF/plexus/components.xml') assert latin1File.exists() def latin1Chars = new XmlParser().parse(latin1File).components.component.description.text() println latin1Chars assert "TEST-CHARS: \u00C4\u00D6\u00DC\u00E4\u00F6\u00FC\u00DF".equals( latin1Chars ) def utf8File = new File(basedir, 'utf-8/target/classes/META-INF/plexus/components.xml') assert utf8File.exists() def utf8Chars = new XmlParser().parse(utf8File).components.component.description.text() println utf8Chars assert "TEST-CHARS: \u00DF\u0131\u03A3\u042F\u05D0\u20AC".equals( utf8Chars ) return true; plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/000077500000000000000000000000001166327066700242605ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/000077500000000000000000000000001166327066700252015ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/000077500000000000000000000000001166327066700257705ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/000077500000000000000000000000001166327066700275635ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/000077500000000000000000000000001166327066700311035ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/000077500000000000000000000000001166327066700331055ustar00rootroot00000000000000000077500000000000000000000000001166327066700352455ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repositoryComponentDescriptor.java000066400000000000000000000440131166327066700421130ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.configuration.PlexusConfiguration; import java.util.ArrayList; import java.util.List; import java.util.Arrays; import java.util.Collections; /** * Component instantiation description. * * @author Jason van Zyl * @author bob mcwhirter * @author Michal Maczka * @version $Id: ComponentDescriptor.java 8155 2009-04-26 01:22:53Z jvanzyl $ */ public class ComponentDescriptor { private String alias = null; private String role = null; private Class roleClass; private String roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT; private String implementation; private Class implementationClass; private String version; private String componentType; private PlexusConfiguration configuration; private String instantiationStrategy; private String lifecycleHandler; private String componentProfile; private final List requirements = new ArrayList(); private String componentFactory; private String componentComposer; private String componentConfigurator; private String description; private ClassRealm realm; // ---------------------------------------------------------------------- // These two fields allow for the specification of an isolated class realm // and dependencies that might be specified in a component configuration // setup by a user i.e. this is here to allow isolation for components // that are not picked up by the discovery mechanism. // ---------------------------------------------------------------------- private boolean isolatedRealm; // ---------------------------------------------------------------------- private ComponentSetDescriptor componentSetDescriptor; private String source; // ---------------------------------------------------------------------- // Instance methods // ---------------------------------------------------------------------- public ComponentDescriptor() { } public ComponentDescriptor( Class implementationClass, ClassRealm realm ) { this.implementationClass = implementationClass; this.implementation = implementationClass.getName(); this.realm = realm; } /** * The location this information came from (descriptor file URI). */ public void setSource( String source ) { this.source = source; } /** * The location this information came from (descriptor file URI). */ public String getSource() { return source; } /** * Returns a human-friendly key, suitable for display. * * @return a human-friendly key */ public String getHumanReadableKey() { StringBuffer key = new StringBuffer(); key.append( "role: '" ).append( role ).append( "'" ); key.append( ", implementation: '" ).append( implementation ).append( "'" ); if ( roleHint != null ) { key.append( ", role hint: '" ).append( roleHint ).append( "'" ); } if ( alias != null ) { key.append( ", alias: '" ).append( alias ).append( "'" ); } return key.toString(); } /** * Returns an alias for this component. An alias as an alternate name other than the normal key. * * @return an alias for this component */ public String getAlias() { return alias; } /** * Sets the alias for this component. * * @param alias alternate name to set */ public void setAlias( String alias ) { this.alias = alias; } /** * Returns the role of this component. * * @return the role of this component */ public String getRole() { return role; } public Class getRoleClass() { attemptRoleLoad(); if (roleClass == null) { return (Class) Object.class; } return roleClass; } private void attemptRoleLoad() { if ( roleClass == null && role != null && realm != null ) { try { roleClass = realm.loadClass( role ); Thread.currentThread(); } catch ( Throwable ignored ) { Thread.currentThread(); } } } /** * Sets the role of this component. * * @param role this component's role */ public void setRole( String role ) { this.role = role; // reload role class roleClass = null; attemptRoleLoad(); } public void setRoleClass( Class roleClass ) { this.roleClass = roleClass; if (roleClass == null) { role = null; } else { role = roleClass.getName(); } } /** * Returns the role-hint of this component. * * @return the role-hint of this component */ public String getRoleHint() { return roleHint; } /** * Sets the role-hint of this component. Pasing null will set the hint to the default value. * * @param roleHint this component's role-hint */ public void setRoleHint( String roleHint ) { if ( ( roleHint == null ) || roleHint.trim().equals( "" ) ) { this.roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT; } else { this.roleHint = roleHint; } } /** * Returns the implementation of this componet. Implementation is a string denoting a FQCN in normal Java * components, or some other name or file for other component factory implementations. * * @return the implementation of this componet's role. */ public String getImplementation() { return implementation; } /** * Sets the implementation of this componet. * * @param implementation string denoting a FQCN in normal Java components, or some other name or file for other * component factory implementations */ public void setImplementation( String implementation ) { this.implementation = implementation; // reload implementation class implementationClass = null; attemptImplementationLoad(); } /** * Returns the implementation class of this componet, or null if the implementation class can not be loaded. * * @return the implementation of this componet's role. */ public Class getImplementationClass() { attemptImplementationLoad(); if (implementationClass == null) { return (Class) Object.class; } return implementationClass; } private void attemptImplementationLoad() { if ( implementationClass == null && implementation != null && realm != null ) { try { implementationClass = realm.loadClass( implementation ); Thread.currentThread(); } catch ( Throwable ignored ) { Thread.currentThread(); } } } public void setImplementationClass( Class implementationClass ) { this.implementationClass = implementationClass; if (implementationClass == null) { implementation = null; } else { implementation = implementationClass.getName(); } } /** * Returns a specific point in a components's project timeline. i.e. version 1, or 2.1.4 * * @return a specific point in a components's project timeline */ public String getVersion() { return version; } /** * Sets the point in a components's project development timeline * * @param version the components's version */ public void setVersion( String version ) { this.version = version; } /** * Returns the type of this component. * * @return the type of this component */ public String getComponentType() { return componentType; } /** * Sets this component's type. * * @param componentType the type to set */ public void setComponentType( String componentType ) { this.componentType = componentType; } /** * Returns the type of instantiation strategy for this component. * * @return the type of instantiation strategy for this component */ public String getInstantiationStrategy() { return instantiationStrategy; } /** * Returns configuration values defined for this component. * * @return configuration values defined for this component */ public PlexusConfiguration getConfiguration() { return configuration; } /** * Sets the configuration hierarchy for this component. * * @param configuration the configuration hierarchy to set */ public void setConfiguration( PlexusConfiguration configuration ) { this.configuration = configuration; } /** * Returns true if this component has a configuration. * * @return true if this component has a configuration */ public boolean hasConfiguration() { return configuration != null; } /** * Returns the lifecycle-handler for this component. * * @return the lifecycle-handler for this component */ public String getLifecycleHandler() { return lifecycleHandler; } /** * Sets the lifecycle-handler for this component. For example, "basic", "passive", "bootstrap". * * @param lifecycleHandler the lifecycle handler string to set */ public void setLifecycleHandler( String lifecycleHandler ) { this.lifecycleHandler = lifecycleHandler; } public String getComponentProfile() { return componentProfile; } public void setComponentProfile( String componentProfile ) { this.componentProfile = componentProfile; } /** * Add a project requirement to this component. * * @param requirement the requirement to add */ public void addRequirement( ComponentRequirement requirement ) { this.requirements.add( requirement ); } /** * Add a project requirement to this component. * * @param requirement the requirement to add */ public void addRequirement( ComponentRequirement... requirement ) { this.requirements.addAll( Arrays.asList( requirement )); } /** * Adds a list of requirements to this component. * * @param requirements the requirements to add */ public void addRequirements( List requirements ) { this.requirements.addAll( requirements ); } /** * Remove a project requirement from this component. * * @param requirement the requirement to remove */ public void removeRequirement( ComponentRequirement... requirement ) { this.requirements.removeAll( Arrays.asList( requirement )); } /** * Removes a list of requirements from this component. * * @param requirements the requirements to remove */ public void removeRequirements( List requirements ) { this.requirements.removeAll( requirements ); } /** * Returns all project requirements of this component. * * @return all project requirements of this component */ public List getRequirements() { return Collections.unmodifiableList( requirements ); } /** * Returns an id of the factory used to create this component. * * @return an id of the factory used to create this component */ public String getComponentFactory() { return componentFactory; } /** * Sets the id of the factory to use to create this component. For example, "jruby" will use a JRuby factory. * * @param componentFactory */ public void setComponentFactory( String componentFactory ) { this.componentFactory = componentFactory; } /** * Returns the ID of the type of composer this component will use. For example, "setter" or "field" for the * different types of dependency injection. * * @return the ID of the type of composer this component will use */ public String getComponentComposer() { return componentComposer; } /** * Sets a representation of the composer this component uses. * * @param componentComposer string representation of the composer to use */ public void setComponentComposer( String componentComposer ) { this.componentComposer = componentComposer; } /** * Return a human-readable description of this component. * * @return a human-readable description of this component */ public String getDescription() { return description; } /** * Sets a description of this component for users to read. * * @param description a human-readable description of this component */ public void setDescription( String description ) { this.description = description; } /** * Sets the instantiation-strategy for this component. For example, "container". * * @param instantiationStrategy */ public void setInstantiationStrategy( String instantiationStrategy ) { this.instantiationStrategy = instantiationStrategy; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- /** * Returns true if this may be in an isolated classrealm. * * @return true if this may be in an isolated classrealm */ public boolean isIsolatedRealm() { return isolatedRealm; } /** * Sets the component set descriptor of components and dependencies for this component. * * @param componentSetDescriptor the component set descriptor of components and dependencies */ public void setComponentSetDescriptor( ComponentSetDescriptor componentSetDescriptor ) { this.componentSetDescriptor = componentSetDescriptor; } /** * Returns the component set descriptor. * * @return the component set descriptor */ public ComponentSetDescriptor getComponentSetDescriptor() { return componentSetDescriptor; } /** * Sets that this component may be in an isolated classrealm. * * @param isolatedRealm true if this component may be in an isolated classrealm */ public void setIsolatedRealm( boolean isolatedRealm ) { this.isolatedRealm = isolatedRealm; } /** * Returns the type of component configurator for this project. For example "basic" for normal, or "map-oriented" * for map oriented components. * * @return the type of component configurator for this project */ public String getComponentConfigurator() { return componentConfigurator; } /** * Sets the type of component configurator for this project. * * @param componentConfigurator */ public void setComponentConfigurator( String componentConfigurator ) { this.componentConfigurator = componentConfigurator; } /** * The ClassRealm that this component lives under. * * @return ClassRealm that this component lives under */ public ClassRealm getRealm() { return realm; } /** * Set the ClassRealm that this component lives under. * * @param realm the ClassRealm that this component lives under */ public void setRealm( ClassRealm realm ) { this.realm = realm; // reload implementation class implementationClass = null; attemptImplementationLoad(); // reload role class roleClass = null; attemptRoleLoad(); } // Component identity established here! public boolean equals( Object other ) { if ( !( other instanceof ComponentDescriptor ) ) { return false; } else { ComponentDescriptor otherDescriptor = (ComponentDescriptor) other; boolean isEqual = true; String role = getRole(); String otherRole = otherDescriptor.getRole(); isEqual = isEqual && ( ( role.equals( otherRole ) ) || role.equals( otherRole ) ); String roleHint = getRoleHint(); String otherRoleHint = otherDescriptor.getRoleHint(); isEqual = isEqual && ( ( roleHint.equals( otherRoleHint ) ) || roleHint.equals( otherRoleHint ) ); return isEqual; } } public String toString() { return getClass().getName() + " [role: '" + getRole() + "', hint: '" + getRoleHint() + "', realm: " + ( realm == null ? "NULL" : "'" + realm + "'" ) + "]"; } public int hashCode() { int result = getRole().hashCode() + 1; String hint = getRoleHint(); if ( hint != null ) { result += hint.hashCode(); } return result; } } ComponentRequirement.java000066400000000000000000000117331166327066700423000ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This represents a component this is required by another component. * * @author Michal Maczka * @version $Id: ComponentRequirement.java 8525 2009-11-06 15:23:51Z bentmann $ */ public class ComponentRequirement { private String role; private String roleHint = ""; private String fieldName; private String fieldMappingType; private boolean optional; /** * Returns the field name that this component requirement will inject. * @return the field name that this component requirement will inject */ public String getFieldName() { return fieldName; } /** * Sets the name of the field that will be populated by the required * component. * @param fieldName the name of the field to be populated */ public void setFieldName( String fieldName ) { this.fieldName = fieldName; } /** * Returns the role of the required component. * @return the role of the required component */ public String getRole() { return role; } /** * Sets the role of the require component. * @param role the required component's role */ public void setRole( String role ) { this.role = role; } /** * Returns the role-hint of the required component. * @return the role-hint of the required component */ public String getRoleHint() { return roleHint; } /** * Sets the role-hint of the require component. * Passing null or an empty string will match any available implementation. * @param roleHint the required component's role-hint */ public void setRoleHint( String roleHint ) { this.roleHint = ( roleHint != null ) ? roleHint : ""; } /** * Returns the type of the field this component requirement will inject. * @return the type of the field this component requirement will inject */ public String getFieldMappingType() { return fieldMappingType; } /** * Sets the type of the field that will be populated by the required * component. * @param fieldType the type of the field to be populated */ public void setFieldMappingType( String fieldType ) { this.fieldMappingType = fieldType; } /** * Whether this component requirement is optional and needs not be satisfied * * @return {@code true} if the requested component may be missing, {@code false} if the component is mandatory. * @since 1.3.0 */ public boolean isOptional() { return optional; } /** * Controls whether a failure to satisfy this requirement can be tolerated by host component or whether construction * of the host component should also fail. * * @param optional {@code true} if the requested component may be missing, {@code false} if the component is * mandatory. * @since 1.3.0 */ public void setOptional( boolean optional ) { this.optional = optional; } public String toString() { return "ComponentRequirement{" + "role='" + getRole() + "'" + ", " + "roleHint='" + getRoleHint() + "', " + "fieldName='" + getFieldName() + "'" + "}"; } /** * Returns a human-friendly key, suitable for display. * @return a human-friendly key */ public String getHumanReadableKey() { StringBuffer key = new StringBuffer(); key.append( "role: '").append( getRole() ).append( "'" ); if ( getRoleHint() != null ) { key.append( ", role-hint: '" ).append( getRoleHint() ).append( "'. " ); } if ( getFieldName() != null ) { key.append( ", field name: '" ).append( getFieldName() ).append( "' " ); } return key.toString(); } public boolean equals( Object other ) { if ( other instanceof ComponentRequirement ) { String myId = role + ":" + roleHint; ComponentRequirement req = (ComponentRequirement) other; String otherId = req.role + ":" + req.roleHint; return myId.equals( otherId ); } return false; } public int hashCode() { return ( role + ":" + roleHint ).hashCode(); } } ComponentRequirementList.java000066400000000000000000000015261166327066700431330ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; import java.util.List; /** * Created by IntelliJ IDEA. * * @author Andrew Williams * @version $Id: ComponentRequirementList.java 7828 2008-11-14 22:07:56Z dain $ * @since 1.0 */ public class ComponentRequirementList extends ComponentRequirement { private List roleHints; public List getRoleHints() { return roleHints; } public void setRoleHints(List roleHints) { this.roleHints = roleHints; } public String getRoleHint() { StringBuffer buffer = new StringBuffer(); for ( String hint : roleHints ) { if (buffer.length() > 0) { buffer.append(","); } buffer.append(hint); } return buffer.toString(); } } ComponentSetDescriptor.java000066400000000000000000000107301166327066700425660ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.List; /** * Contains a set of ComponentDescriptors and the set's dependencies. * * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: ComponentSetDescriptor.java 7828 2008-11-14 22:07:56Z dain $ */ public class ComponentSetDescriptor { // This field is not currently used in Maven, or Plexus private String id; /** The source location of this component source descriptor */ private String source; /** Flag to indicate whether this component should be loaded in a realm/classloader of its own. */ private boolean isolatedRealm; /** The component descriptors that can be found within this component set descriptor. */ private final List> components = new ArrayList>(); /** The dependencies that are required by the set of components found in this component set descriptor. */ private final List dependencies = new ArrayList(); /** * Returns a list of components in this set. * @return a list of components */ public List> getComponents() { return components; } /** * Add a new ComponentDescriptor to this set. * @param cd the ComponentDescriptor to add */ public void addComponentDescriptor( ComponentDescriptor cd ) { components.add( cd ); } /** * Sets a List of components as this set's contents. * @param components the List of components to set */ public void setComponents( List> components ) { this.components.clear(); this.components.addAll(components); } /** * Returns a List of dependencies of this set of components. * @return a List of dependencies of this set of components */ public List getDependencies() { return dependencies; } /** * Add a depenency to this set's contents. * @param cd the ComponentDependency to add */ public void addDependency( ComponentDependency cd ) { dependencies.add( cd ); } /** * Sets a List of dependencies as this set's component dependencies. * @param dependencies the List of components to set */ public void setDependencies( List dependencies ) { this.dependencies.clear(); this.dependencies.addAll(dependencies); } /** * Sets that this set of components may be in an isolated classrealm. * @param isolatedRealm true if this set of components may be in an * isolated classrealm */ public void setIsolatedRealm( boolean isolatedRealm ) { this.isolatedRealm = isolatedRealm; } /** * Returns true if this set may be in an isolated classrealm. * @return true if this set may be in an isolated classrealm */ public boolean isIsolatedRealm() { return isolatedRealm; } /** * Returns the identifier of this set. * @return the identifier of this set */ public String getId() { return id; } /** * Sets the identifier of this set. * @param id the identifier to set */ public void setId( String id ) { this.id = id; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append( "Component Descriptor: " ); for ( ComponentDescriptor cd : components ) { sb.append( cd.getHumanReadableKey() ).append( "\n" ); } sb.append( "---" ); return sb.toString(); } public String getSource() { return source; } public void setSource( String source ) { this.source = source; } } README.txt000066400000000000000000000003241166327066700367420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repositoryThis package contains some classes copied from the container before it started using the "default" role hints. This can be removed once all supported maven versions are using a container newer than 1.0-alpha-19.plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/maven/000077500000000000000000000000001166327066700322115ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/maven/plugin/000077500000000000000000000000001166327066700335075ustar00rootroot00000000000000AbstractDescriptorMojo.java000066400000000000000000000036351166327066700407310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/maven/pluginpackage org.codehaus.plexus.maven.plugin; /* * The MIT License * * Copyright (c) 2004-2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.metadata.MetadataGenerator; /** * @author Jason van Zyl */ public abstract class AbstractDescriptorMojo extends AbstractMojo { /** * @parameter expression="${project}" * @required * @readonly */ protected MavenProject mavenProject; /** * The file encoding of the source files. * * @parameter default-value="${project.build.sourceEncoding}" */ protected String sourceEncoding; /** @component */ protected MavenProjectHelper mavenProjectHelper; /** @component */ protected MetadataGenerator metadataGenerator; } PlexusDescriptorMojo.java000066400000000000000000000067321166327066700404470ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/maven/pluginpackage org.codehaus.plexus.maven.plugin; /* * Copyright (c) 2004-2005, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.File; import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.plexus.metadata.MetadataGenerationRequest; /** * Generates a Plexus components.xml component descriptor file from source (javadoc) or * class annotations. * * @goal generate-metadata * @phase process-classes * @requiresDependencyResolution compile * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: PlexusDescriptorMojo.java 7986 2008-12-31 09:47:23Z bentmann $ */ public class PlexusDescriptorMojo extends AbstractDescriptorMojo { /** * The output location for the generated descriptor. * * @parameter default-value="${project.build.outputDirectory}/META-INF/plexus/components.xml" * @required */ protected File generatedMetadata; /** * The location of manually crafted component descriptors. The contents of the descriptor files in this directory is * merged with the information extracted from the project's sources/classes. * * @parameter default-value="${basedir}/src/main/resources/META-INF/plexus" * @required */ protected File staticMetadataDirectory; /** * The output location for the intermediary descriptor. This descriptors contains only the information extracted * from the project's sources/classes. * * @parameter default-value="${project.build.directory}/components.xml" * @required */ protected File intermediaryMetadata; public void execute() throws MojoExecutionException { MetadataGenerationRequest request = new MetadataGenerationRequest(); try { request.classpath = mavenProject.getCompileClasspathElements(); request.classesDirectory = new File( mavenProject.getBuild().getOutputDirectory() ); request.sourceDirectories = mavenProject.getCompileSourceRoots(); request.sourceEncoding = sourceEncoding; request.componentDescriptorDirectory = staticMetadataDirectory; request.intermediaryFile = intermediaryMetadata; request.outputFile = generatedMetadata; metadataGenerator.generateDescriptor( request ); } catch ( Exception e ) { throw new MojoExecutionException( "Error generating metadata: ", e ); } } } PlexusMergeMojo.java000066400000000000000000000052521166327066700373640ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/maven/pluginpackage org.codehaus.plexus.maven.plugin; /* * Copyright (c) 2004-2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.plexus.metadata.merge.Merger; /** * Merges a set of Plexus descriptors into one descriptor file. * * @goal merge-metadata * @phase process-classes * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: PlexusMergeMojo.java 7986 2008-12-31 09:47:23Z bentmann $ */ public class PlexusMergeMojo extends AbstractMojo { /** * The destination for the merged descriptor. * * @parameter default-value="${project.build.outputDirectory}/META-INF/plexus/components.xml" * @required */ private File output; /** * The paths of the input descriptors to merge. * * @parameter */ private File[] descriptors; /** @component role-hint="componentsXml" */ private Merger merger; public void execute() throws MojoExecutionException { List files = new ArrayList(); if ( descriptors != null ) { files.addAll( Arrays.asList( descriptors ) ); } if ( files.isEmpty() ) { return; } try { merger.mergeDescriptors( output, files ); } catch ( IOException e ) { throw new MojoExecutionException( "Error while executing component descritor creator.", e ); } } } PlexusTestDescriptorMojo.java000066400000000000000000000070361166327066700413050ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/maven/pluginpackage org.codehaus.plexus.maven.plugin; /* * Copyright (c) 2004-2005, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.File; import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.plexus.metadata.MetadataGenerationRequest; /** * Generates a Plexus components.xml component descriptor file from test source (javadoc) * or test class annotations. * * @goal generate-test-metadata * @phase process-test-classes * @requiresDependencyResolution test * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: PlexusTestDescriptorMojo.java 7988 2008-12-31 10:15:47Z bentmann $ */ public class PlexusTestDescriptorMojo extends AbstractDescriptorMojo { /** * The output location for the generated descriptor. * * @parameter default-value="${project.build.testOutputDirectory}/META-INF/plexus/components.xml" * @required */ protected File testGeneratedMetadata; /** * The location of manually crafted component descriptors. The contents of the descriptor files in this directory is * merged with the information extracted from the project's sources/classes. * * @parameter default-value="${basedir}/src/test/resources/META-INF/plexus" * @required */ protected File testStaticMetadataDirectory; /** * The output location for the intermediary descriptor. This descriptors contains only the information extracted * from the project's sources/classes. * * @parameter default-value="${project.build.directory}/test-components.xml" * @required */ protected File testIntermediaryMetadata; public void execute() throws MojoExecutionException { MetadataGenerationRequest request = new MetadataGenerationRequest(); try { request.classpath = mavenProject.getTestClasspathElements(); request.classesDirectory = new File( mavenProject.getBuild().getTestOutputDirectory() ); request.sourceDirectories = mavenProject.getTestCompileSourceRoots(); request.sourceEncoding = sourceEncoding; request.componentDescriptorDirectory = testStaticMetadataDirectory; request.intermediaryFile = testIntermediaryMetadata; request.outputFile = testGeneratedMetadata; metadataGenerator.generateDescriptor( request ); } catch ( Exception e ) { throw new MojoExecutionException( "Error generating test metadata: ", e ); } } } plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/000077500000000000000000000000001166327066700326635ustar00rootroot00000000000000ClassComponentDescriptorExtractor.java000066400000000000000000000122231166327066700423320ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package org.codehaus.plexus.metadata; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.metadata.gleaner.AnnotationComponentGleaner; import org.codehaus.plexus.metadata.gleaner.ClassComponentGleaner; import org.codehaus.plexus.util.DirectoryScanner; /** * Extracts {@link ComponentDescriptor} from class files. * * @version $Id: ClassComponentDescriptorExtractor.java 8174 2009-05-11 15:15:23Z jvanzyl $ */ public class ClassComponentDescriptorExtractor extends ComponentDescriptorExtractorSupport { private ClassComponentGleaner gleaner; public ClassComponentDescriptorExtractor( final ClassComponentGleaner gleaner ) { this.gleaner = gleaner; } public ClassComponentDescriptorExtractor() { this.gleaner = new AnnotationComponentGleaner(); } public List> extract( MetadataGenerationRequest configuration, final ComponentDescriptor[] roleDefaults ) throws Exception { // We don't have a reasonable default to use, so just puke up if ( gleaner == null ) { throw new IllegalStateException( "Gleaner is not bound" ); } if ( !configuration.classesDirectory.exists() ) { return Collections.emptyList(); } if ( configuration.useContextClassLoader ) { return extract( configuration.classesDirectory, Thread.currentThread().getContextClassLoader(), getDefaultsByRole( roleDefaults ) ); } else { ClassLoader prev = Thread.currentThread().getContextClassLoader(); ClassLoader cl = createClassLoader( configuration.classpath ); Thread.currentThread().setContextClassLoader( cl ); try { return extract( configuration.classesDirectory, cl, getDefaultsByRole( roleDefaults ) ); } finally { Thread.currentThread().setContextClassLoader( prev ); } } } private ClassLoader createClassLoader( final List elements ) throws Exception { List list = new ArrayList(); // Add the projects dependencies for ( String filename : elements ) { try { list.add( new File( filename ).toURI().toURL() ); } catch ( MalformedURLException e ) { throw new MojoExecutionException( "Invalid classpath entry: " + filename, e ); } } URL[] urls = list.toArray( new URL[list.size()] ); //getLogger().debug( "Classpath:" ); for ( int i = 0; i < urls.length; i++ ) { //getLogger().debug( " " + urls[i] ); } return new URLClassLoader( urls, null ); } private List> extract( File classesDir, ClassLoader cl, Map> defaultsByRole ) throws Exception { assert classesDir != null; assert cl != null; assert defaultsByRole != null; List> descriptors = new ArrayList>(); DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir( classesDir ); scanner.addDefaultExcludes(); scanner.setIncludes( new String[] { "**/*.class" } ); //getLogger().debug( "Scanning for classes in: " + classesDir ); scanner.scan(); String[] includes = scanner.getIncludedFiles(); for ( String include : includes ) { String className = include.substring( 0, include.lastIndexOf( ".class" ) ).replace( '\\', '.' ).replace( '/', '.' ); try { // Class type = cl.loadClass( className ); ComponentDescriptor descriptor = gleaner.glean( className, cl ); if ( descriptor != null ) { applyDefaults( descriptor, defaultsByRole ); descriptors.add( descriptor ); } } catch ( VerifyError e ) { // getLogger().error( "Failed to load class: " + className + "; cause: " + e ); } } return descriptors; } }ComponentDescriptorExtractor.java000066400000000000000000000022611166327066700413450ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package org.codehaus.plexus.metadata; import java.util.List; import org.codehaus.plexus.component.repository.ComponentDescriptor; /** * An abstraction to allow pluggable {@link ComponentDescriptor} extraction to be dropped. * * @version $Id: ComponentDescriptorExtractor.java 7966 2008-12-25 15:25:22Z bentmann $ */ public interface ComponentDescriptorExtractor { String ROLE = ComponentDescriptorExtractor.class.getName(); List> extract( MetadataGenerationRequest configuration, ComponentDescriptor[] roleDefaults ) throws Exception; } ComponentDescriptorExtractorSupport.java000066400000000000000000000044561166327066700427520ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package org.codehaus.plexus.metadata; import java.util.HashMap; import java.util.Map; import org.codehaus.plexus.component.repository.ComponentDescriptor; /** * Support for {@link ComponentDescriptorExtractor} implementations. * * @version $Id: ComponentDescriptorExtractorSupport.java 8174 2009-05-11 15:15:23Z jvanzyl $ */ public abstract class ComponentDescriptorExtractorSupport implements ComponentDescriptorExtractor { protected Map> getDefaultsByRole( final ComponentDescriptor[] roleDefaults ) { Map> defaultsByRole = new HashMap>(); if ( roleDefaults != null ) { for ( int i = 0; i < roleDefaults.length; i++ ) { String role = roleDefaults[i].getRole(); if ( role == null ) { throw new IllegalArgumentException( "Invalid role defaults; found null role in: " + roleDefaults[i] ); } defaultsByRole.put( role, roleDefaults[i] ); } } return defaultsByRole; } protected void applyDefaults( ComponentDescriptor descriptor, Map> defaultsByRole ) { assert descriptor != null; assert defaultsByRole != null; if ( defaultsByRole.containsKey( descriptor.getRole() ) ) { ComponentDescriptor defaults = defaultsByRole.get( descriptor.getRole() ); if ( descriptor.getInstantiationStrategy() == null ) { descriptor.setInstantiationStrategy( defaults.getInstantiationStrategy() ); } } } }ComponentDescriptorWriteException.java000066400000000000000000000033301166327066700423410ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadatapackage org.codehaus.plexus.metadata; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: ComponentDescriptorWriteException.java 7688 2008-08-23 02:56:25Z jvanzyl $ */ public class ComponentDescriptorWriteException extends Exception { public ComponentDescriptorWriteException( String message ) { super( message ); } public ComponentDescriptorWriteException( String message, Throwable cause ) { super( message, cause ); } public ComponentDescriptorWriteException( Throwable cause ) { super( cause ); } }ComponentDescriptorWriter.java000066400000000000000000000031141166327066700406440ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/* * The MIT License * * Copyright (c) 2007, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package org.codehaus.plexus.metadata; import java.io.IOException; import java.io.Writer; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; /** * @author Kenney Westerhof */ public interface ComponentDescriptorWriter { void writeDescriptorSet( Writer writer, ComponentSetDescriptor componentSetDescriptor, boolean containerDescriptor ) throws ComponentDescriptorWriteException, IOException; } DefaultComponentDescriptorWriter.java000066400000000000000000000220461166327066700421560ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/* * The MIT License * * Copyright (c) 2007, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package org.codehaus.plexus.metadata; import java.io.IOException; import java.io.Writer; import java.util.List; import org.codehaus.plexus.component.repository.ComponentDependency; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.component.repository.ComponentRequirementList; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; /** * Serializes a {@link ComponentSetDescriptor}. * * @author Kenney Westerhof * @author Jason van Zyl * @author Trygve Laugstøl */ public class DefaultComponentDescriptorWriter implements ComponentDescriptorWriter { private static final String LS = System.getProperty( "line.separator" ); public void writeDescriptorSet( Writer writer, ComponentSetDescriptor componentSetDescriptor, boolean containerDescriptor ) throws ComponentDescriptorWriteException, IOException { try { XMLWriter w = new PrettyPrintXMLWriter( writer ); w.startElement( containerDescriptor ? "plexus" : "component-set" ); writeComponents( w, componentSetDescriptor.getComponents() ); writeDependencies( w, componentSetDescriptor.getDependencies() ); w.endElement(); writer.write( LS ); // Flush, but don't close the writer... we are not its owner writer.flush(); } catch ( PlexusConfigurationException e ) { throw new ComponentDescriptorWriteException( "Internal error while writing out the configuration", e ); } } private void writeComponents( XMLWriter w, List> componentDescriptors ) throws ComponentDescriptorWriteException, PlexusConfigurationException { if ( componentDescriptors == null ) { return; } w.startElement( "components" ); for ( ComponentDescriptor cd : componentDescriptors ) { w.startElement( "component" ); element( w, "role", cd.getRole() ); element( w, "role-hint", cd.getRoleHint() ); element( w, "implementation", cd.getImplementation() ); element( w, "version", cd.getVersion() ); element( w, "component-type", cd.getComponentType() ); element( w, "instantiation-strategy", cd.getInstantiationStrategy() ); element( w, "lifecycle-handler", cd.getLifecycleHandler() ); element( w, "component-profile", cd.getComponentProfile() ); element( w, "component-composer", cd.getComponentComposer() ); element( w, "component-configurator", cd.getComponentConfigurator() ); element( w, "component-factory", cd.getComponentFactory() ); element( w, "description", cd.getDescription() ); element( w, "alias", cd.getAlias() ); element( w, "isolated-realm", Boolean.toString( cd.isIsolatedRealm() ) ); writeRequirements( w, cd.getRequirements() ); writeConfiguration( w, cd.getConfiguration() ); w.endElement(); } w.endElement(); } public void writeDependencies( XMLWriter w, List deps ) { if ( deps == null || deps.size() == 0 ) { return; } w.startElement( "dependencies" ); for ( ComponentDependency dep : deps ) { writeDependencyElement( dep, w ); } w.endElement(); } private void writeDependencyElement( ComponentDependency dependency, XMLWriter w ) { w.startElement( "dependency" ); String groupId = dependency.getGroupId(); element( w, "groupId", groupId ); String artifactId = dependency.getArtifactId(); element( w, "artifactId", artifactId ); String type = dependency.getType(); if ( type != null ) { element( w, "type", type ); } String version = dependency.getVersion(); element( w, "version", version ); w.endElement(); } private void writeRequirements( XMLWriter w, List requirements ) { if ( requirements == null || requirements.size() == 0 ) { return; } w.startElement( "requirements" ); for ( ComponentRequirement cr : requirements ) { w.startElement( "requirement" ); element( w, "role", cr.getRole() ); if ( cr instanceof ComponentRequirementList ) { List hints = ( (ComponentRequirementList) cr ).getRoleHints(); if ( hints != null ) { w.startElement( "role-hints" ); for ( String roleHint : hints ) { w.startElement( "role-hint" ); w.writeText( roleHint ); w.endElement(); } w.endElement(); } } else { element( w, "role-hint", cr.getRoleHint() ); } element( w, "field-name", cr.getFieldName() ); element( w, "optional", cr.isOptional() ? Boolean.TRUE.toString() : null ); w.endElement(); } w.endElement(); } private void writeConfiguration( XMLWriter w, PlexusConfiguration configuration ) throws ComponentDescriptorWriteException, PlexusConfigurationException { if ( configuration == null || configuration.getChildCount() == 0 ) { return; } if ( !configuration.getName().equals( "configuration" ) ) { throw new ComponentDescriptorWriteException( "The root node of the configuration must be 'configuration'."); } writePlexusConfiguration( w, configuration ); } private void writePlexusConfiguration( XMLWriter xmlWriter, PlexusConfiguration c ) throws PlexusConfigurationException { if ( c.getAttributeNames().length == 0 && c.getChildCount() == 0 && c.getValue() == null ) { return; } xmlWriter.startElement( c.getName() ); // ---------------------------------------------------------------------- // Write the attributes // ---------------------------------------------------------------------- String[] attributeNames = c.getAttributeNames(); for ( String attributeName : attributeNames ) { xmlWriter.addAttribute( attributeName, c.getAttribute( attributeName ) ); } // ---------------------------------------------------------------------- // Write the children // ---------------------------------------------------------------------- PlexusConfiguration[] children = c.getChildren(); if ( children.length > 0 ) { for ( PlexusConfiguration aChildren : children ) { writePlexusConfiguration( xmlWriter, aChildren ); } } else { String value = c.getValue(); if ( value != null ) { xmlWriter.writeText( value ); } } xmlWriter.endElement(); } private void element( XMLWriter w, String name, String value ) { if ( value == null ) { return; } w.startElement( name ); w.writeText( value ); w.endElement(); } } DefaultMetadataGenerator.java000066400000000000000000000133731166327066700403520ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadatapackage org.codehaus.plexus.metadata; /* * The MIT License * * Copyright (c) 2004-2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.ComponentDependency; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.metadata.gleaner.AnnotationComponentGleaner; import org.codehaus.plexus.metadata.merge.Merger; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; /** * @author Jason van Zyl */ @Component(role = MetadataGenerator.class) public class DefaultMetadataGenerator extends AbstractLogEnabled implements MetadataGenerator { @Requirement private Merger merger; private ComponentDescriptor[] roleDefaults; // should be a component private ComponentDescriptorExtractor[] extractors; // should be a component private ComponentDescriptorWriter writer = new DefaultComponentDescriptorWriter(); public void generateDescriptor( MetadataGenerationRequest request ) throws Exception { assert request.outputFile != null; if ( extractors == null || extractors.length == 0 ) { extractors = new ComponentDescriptorExtractor[] { new SourceComponentDescriptorExtractor(), new ClassComponentDescriptorExtractor( new AnnotationComponentGleaner() ) }; } List> descriptors = new ArrayList>(); for ( int i = 0; i < extractors.length; i++ ) { try { List> list = extractors[i].extract( request, roleDefaults ); if ( list != null && !list.isEmpty() ) { descriptors.addAll( list ); } } catch ( Exception e ) { throw new Exception( "Failed to extract descriptors", e ); } } List componentDescriptors = new ArrayList(); // // If we found descriptors, write out the discovered descriptors // if ( descriptors.size() > 0 ) { getLogger().info( "Discovered " + descriptors.size() + " component descriptors(s)" ); ComponentSetDescriptor set = new ComponentSetDescriptor(); set.setComponents( descriptors ); set.setDependencies( Collections. emptyList() ); if ( request.componentDescriptorDirectory == null ) { writeDescriptor( set, request.outputFile ); } else { if ( request.intermediaryFile == null ) { request.intermediaryFile = File.createTempFile( "plexus-metadata", "xml" ); request.intermediaryFile.deleteOnExit(); } writeDescriptor( set, request.intermediaryFile ); componentDescriptors.add( request.intermediaryFile ); } } // // Deal with merging // if ( request.componentDescriptorDirectory != null && request.componentDescriptorDirectory.isDirectory() ) { File[] files = request.componentDescriptorDirectory.listFiles(); for ( File file : files ) { if ( file.getName().endsWith( ".xml" ) && !file.getName().equals( "plexus.xml" ) ) { componentDescriptors.add( file ); } } } if ( componentDescriptors.size() > 0 ) { merger.mergeDescriptors( request.outputFile, componentDescriptors ); } } private void writeDescriptor( ComponentSetDescriptor desc, File outputFile ) throws Exception { assert desc != null; assert outputFile != null; FileUtils.forceMkdir( outputFile.getParentFile() ); BufferedWriter output = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( outputFile ), "UTF-8" ) ); try { writer.writeDescriptorSet( output, desc, false ); output.flush(); } finally { IOUtil.close( output ); } getLogger().debug( "Wrote: " + outputFile ); } } MetadataGenerationRequest.java000066400000000000000000000024501166327066700405550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadatapackage org.codehaus.plexus.metadata; import java.io.File; import java.util.List; public class MetadataGenerationRequest { /** Source to examine for Javadoc annotions which are used to generate component metadata. */ public List sourceDirectories; //todo: these should be files /** The character encoding of the source files, may be {@code null} or empty to use platform's default encoding. */ public String sourceEncoding; /** Classes to examine for annotations which are used to generate component metadata. */ public File classesDirectory; /** Supporting classpath required by class-based annotation processing. */ public List classpath; //todo: these should be files /** Flag to indicate using the context classloader for the supporting classpath required by annotation-based processing. */ public boolean useContextClassLoader; /** Directory where existing component descriptors live. */ public File componentDescriptorDirectory; /** Existing component descriptors that need to be merged. */ public List componentDescriptors; /** Where existing component descriptors are merged. */ public File intermediaryFile; /** Output file for the final component descriptor. */ public File outputFile; } MetadataGenerator.java000066400000000000000000000002601166327066700370340ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadatapackage org.codehaus.plexus.metadata; public interface MetadataGenerator { void generateDescriptor( MetadataGenerationRequest configuration ) throws Exception; } PlexusMetadataGeneratorCli.java000066400000000000000000000053601166327066700406730ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadatapackage org.codehaus.plexus.metadata; import java.io.File; import java.util.Arrays; import java.util.Collections; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.tools.cli.AbstractCli; public class PlexusMetadataGeneratorCli extends AbstractCli { public static final char SOURCE_DIRECTORY = 's'; public static final char SOURCE_ENCODING = 'e'; public static final char CLASSES_DIRECTORY = 'c'; public static final char OUTPUT_FILE = 'o'; public static final char DESCRIPTORS_DIRECTORY = 'm'; public static void main( String[] args ) throws Exception { new PlexusMetadataGeneratorCli().execute( args ); } @Override public String getPomPropertiesPath() { return "META-INF/maven/org.codehaus.plexus/plexus-metadata-generator/pom.properties"; } @Override @SuppressWarnings("static-access") public Options buildCliOptions( Options options ) { options.addOption( OptionBuilder.withLongOpt( "source" ).hasArg().withDescription( "Source directory." ).create( SOURCE_DIRECTORY ) ); options.addOption( OptionBuilder.withLongOpt( "encoding" ).hasArg().withDescription( "Source file encoding." ).create( SOURCE_ENCODING ) ); options.addOption( OptionBuilder.withLongOpt( "classes" ).hasArg().withDescription( "Classes directory." ).create( CLASSES_DIRECTORY ) ); options.addOption( OptionBuilder.withLongOpt( "output" ).hasArg().withDescription( "Output directory." ).create( OUTPUT_FILE ) ); options.addOption( OptionBuilder.withLongOpt( "descriptors" ).hasArg().withDescription( "Descriptors directory." ).create( DESCRIPTORS_DIRECTORY ) ); return options; } public void invokePlexusComponent( CommandLine cli, PlexusContainer plexus ) throws Exception { MetadataGenerator metadataGenerator = plexus.lookup( MetadataGenerator.class ); MetadataGenerationRequest request = new MetadataGenerationRequest(); request.classesDirectory = new File( cli.getOptionValue( CLASSES_DIRECTORY ) ); request.classpath = Collections.emptyList(); request.sourceDirectories = Arrays.asList( new String[]{ new File( cli.getOptionValue( SOURCE_DIRECTORY ) ).getAbsolutePath() } ); request.sourceEncoding = cli.getOptionValue( SOURCE_ENCODING ); request.useContextClassLoader = true; request.outputFile = new File( cli.getOptionValue( OUTPUT_FILE ) ); request.componentDescriptorDirectory = new File( cli.getOptionValue( DESCRIPTORS_DIRECTORY ) ); metadataGenerator.generateDescriptor( request ); } } SourceComponentDescriptorExtractor.java000066400000000000000000000062361166327066700425340ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package org.codehaus.plexus.metadata; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.metadata.gleaner.QDoxComponentGleaner; import org.codehaus.plexus.metadata.gleaner.SourceComponentGleaner; import org.codehaus.plexus.util.StringUtils; import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.JavaClass; /** * Extracts {@link ComponentDescriptor} from source files. * * @version $Rev: 8174 $ $Date: 2009-05-11 17:15:23 +0200 (lun. 11 mai 2009) $ */ public class SourceComponentDescriptorExtractor extends ComponentDescriptorExtractorSupport { private SourceComponentGleaner gleaner; public SourceComponentDescriptorExtractor() { } public SourceComponentDescriptorExtractor( final SourceComponentGleaner gleaner ) { this.gleaner = gleaner; } public List> extract( MetadataGenerationRequest configuration, final ComponentDescriptor[] roleDefaults ) throws Exception { if ( gleaner == null ) { gleaner = new QDoxComponentGleaner(); } return extract( configuration.sourceDirectories, configuration.sourceEncoding, getDefaultsByRole( roleDefaults ) ); } private List> extract( final List sourceDirectories, final String sourceEncoding, final Map> defaultsByRole ) throws Exception { assert sourceDirectories != null; assert defaultsByRole != null; List> descriptors = new ArrayList>(); // Scan the sources JavaDocBuilder builder = new JavaDocBuilder(); if ( StringUtils.isNotEmpty( sourceEncoding ) ) { builder.setEncoding( sourceEncoding ); } for ( String sourceDirectory : sourceDirectories ) { File dir = new File( sourceDirectory ); builder.addSourceTree( dir ); } JavaClass[] classes = builder.getClasses(); // For each class we find, try to glean off a descriptor for ( int i = 0; i < classes.length; i++ ) { ComponentDescriptor descriptor = gleaner.glean( builder, classes[i] ); if ( descriptor != null ) { applyDefaults( descriptor, defaultsByRole ); descriptors.add( descriptor ); } } return descriptors; } } plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/ann/000077500000000000000000000000001166327066700334375ustar00rootroot00000000000000Ann.java000066400000000000000000000027551166327066700347500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/ann/* * Copyright (C) 2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.ann; import java.lang.reflect.Proxy; import java.util.LinkedHashMap; import java.util.Map; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class Ann { private String desc; private Map params = new LinkedHashMap(); public Ann(String desc) { this.desc = desc; } public void addParam(String name, Object value) { params.put(name, value); } public String getDesc() { return desc; } public String getType() { return Type.getType(desc).getClassName(); } public Map getParams() { return params; } @SuppressWarnings("unchecked") public T getAnnotation(Class c, ClassLoader cl) { return (T) Proxy.newProxyInstance(Ann.class.getClassLoader(), new Class[] { c }, // new AnnInvocationHandler(this, cl, c)); } } AnnClass.java000066400000000000000000000057651166327066700357420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/ann/* * Copyright (C) 2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.ann; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class AnnClass { private int access; private String name; private String superName; private String[] interfaces; private Map anns = new LinkedHashMap(); private Map fields = new LinkedHashMap(); private Map methods = new LinkedHashMap(); private ClassLoader cl; // setters public AnnClass(ClassLoader cl) { this.cl = cl; } public void setName(String name) { this.name = name; } public void setAccess(int access) { this.access = access; } public void setSuperName(String superName) { this.superName = superName; } public void setInterfaces(String[] interfaces) { this.interfaces = interfaces; } public void addAnn(Ann ann) { anns.put(ann.getDesc(), ann); } public void addField(AnnField field) { fields.put(field.getName(), field); } public void addMethod(AnnMethod method) { methods.put(method.getName() + method.getDesc(), method); } // getters public ClassLoader getClassLoader() { return cl; } public int getAccess() { return access; } public String getName() { return name; } public String getSuperName() { return superName; } public String[] getInterfaces() { return interfaces; } public Map getAnns() { return anns; } public Map getFields() { return fields; } public Map getMethods() { return methods; } public Set getFieldNames() { return fields.keySet(); } public Set getMethodKeys() { return methods.keySet(); } // conversion to java.lang.Annotation public T getAnnotation(Class c) { Ann ann = anns.get(Type.getDescriptor(c)); return ann == null ? null : ann.getAnnotation(c, cl); } public T getFieldAnnotation(String fieldName, Class c) { AnnField field = fields.get(fieldName); return field==null ? null : field.getAnnotation(c); } public T getMethodAnnotation(String methodKey, Class c) { AnnMethod method = methods.get(methodKey); return method==null ? null : method.getAnnotation(c); } } AnnEnum.java000066400000000000000000000033411166327066700355650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/ann/* * Copyright (C) 2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.ann; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class AnnEnum { private final String desc; private final String value; public AnnEnum(String desc, String value) { this.desc = desc; this.value = value; } public String getDesc() { return desc; } public String getValue() { return value; } public String getType() { return Type.getType(desc).getClassName(); } public int hashCode() { return 31 * (31 + desc.hashCode()) + value.hashCode(); } public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } AnnEnum other = (AnnEnum) obj; if (desc == null) { if (other.desc != null) { return false; } } else if (!desc.equals(other.desc)) { return false; } if (value == null) { if (other.value != null) { return false; } } else if (!value.equals(other.value)) { return false; } return true; } } AnnField.java000066400000000000000000000032661166327066700357120ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/ann/* * Copyright (C) 2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.ann; import java.util.LinkedHashMap; import java.util.Map; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class AnnField { private final AnnClass owner; private final int access; private final String name; private final String desc; private Map anns = new LinkedHashMap(); public AnnField(AnnClass owner, int access, String name, String desc) { this.owner = owner; this.access = access; this.desc = desc; this.name = name; } public int getAccess() { return access; } public String getName() { return name; } public String getDesc() { return desc; } public Map getAnns() { return anns; } public String getType() { return Type.getType(desc).getClassName(); } public void addAnn(Ann ann) { anns.put(ann.getDesc(), ann); } public T getAnnotation(Class c) { Ann ann = anns.get(Type.getDescriptor(c)); return ann == null ? null : ann.getAnnotation(c, owner.getClassLoader()); } } AnnInvocationHandler.java000066400000000000000000000050131166327066700402660ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/ann/* * Copyright (C) 2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.ann; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.util.Arrays; import java.util.Map; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class AnnInvocationHandler implements InvocationHandler { private final Ann ann; private final ClassLoader cl; private final Class c; public AnnInvocationHandler(Ann ann, ClassLoader cl, Class c) { this.ann = ann; this.cl = cl; this.c = c; } public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { String name = m.getName(); if("toString".equals(name)) { StringBuffer sb = new StringBuffer(ann.getType()); sb.append("["); String sep = ""; for(Map.Entry e : ann.getParams().entrySet()) { // TODO conversion for class, array, enum, and annotation types sb.append(sep).append(e.getKey()+"="+e.getValue()); sep = "; "; } sb.append("]"); return sb.toString(); } Object value = ann.getParams().get(name); if(value!=null) { if(value instanceof Type) { String className = ((Type) value).getClassName(); try { return Class.forName(className, false, cl); } catch(ClassNotFoundException ex) { if(cl instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) cl).getURLs(); throw new RuntimeException("Unable to load class " + className + " from " + Arrays.toString(urls), ex); } throw new RuntimeException("Unable to load class " + className + " from " + cl, ex); } } // TODO conversion for class, array, enum, and annotation types return value; } else { Method am = c.getDeclaredMethod(m.getName(), m.getParameterTypes()); return am.getDefaultValue(); } } } AnnMethod.java000066400000000000000000000045431166327066700361060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/ann/* * Copyright (C) 2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.ann; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class AnnMethod { private final AnnClass owner; private final int access; private final String name; private final String desc; private Map anns = new LinkedHashMap(); private Map> paramAnns = new HashMap>(); public AnnMethod(AnnClass owner, int access, String name, String desc) { this.owner = owner; this.access = access; this.name = name; this.desc = desc; } public int getAccess() { return access; } public String getName() { return name; } public String getDesc() { return desc; } public Map getAnns() { return anns; } public Map> getParamAnns() { return paramAnns; } public void addAnn(Ann ann) { anns.put(ann.getDesc(), ann); } public void addParamAnn(int parameter, Ann ann) { Map anns = paramAnns.get(parameter); if(anns==null) { anns = new LinkedHashMap(); paramAnns.put(parameter, anns); } anns.put(ann.getDesc(), ann); } public T getAnnotation(Class c) { Ann ann = anns.get(Type.getDescriptor(c)); return ann == null ? null : ann.getAnnotation(c, owner.getClassLoader()); } public T getParameterAnnotation(int parameter, Class c) { Map anns = paramAnns.get(parameter); if (anns == null) { return null; } Ann ann = anns.get(Type.getDescriptor(c)); return ann == null ? null : ann.getAnnotation(c, owner.getClassLoader()); } } AnnReader.java000066400000000000000000000152411166327066700360650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/ann/* * Copyright (C) 2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.ann; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Attribute; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; /** * @author Eugene Kuleshov */ public class AnnReader implements ClassVisitor { private final AnnClass annClass; private AnnReader(AnnClass annClass) { this.annClass = annClass; } public static AnnClass read(InputStream is, ClassLoader cl) throws IOException { AnnClass annClass = new AnnClass(cl); AnnReader cv = new AnnReader(annClass); ClassReader r = new ClassReader(is); r.accept(cv, ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE); return annClass; } public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { annClass.setName(name); annClass.setAccess(access); annClass.setSuperName(superName); annClass.setInterfaces(interfaces); } public AnnotationVisitor visitAnnotation(final String desc, boolean visible) { Ann ann = new Ann(desc); annClass.addAnn(ann); return new AnnAnnReader(ann); } public FieldVisitor visitField(int access, final String name, final String desc, String signature, Object value) { final AnnField field = new AnnField(annClass, access, name, desc); annClass.addField(field); return new FieldVisitor() { public AnnotationVisitor visitAnnotation(String desc, boolean visible) { Ann ann = new Ann(desc); field.addAnn(ann); return new AnnAnnReader(ann); } public void visitAttribute(Attribute attr) { } public void visitEnd() { } }; } public MethodVisitor visitMethod(int access, final String mname, final String mdesc, String signature, String[] exceptions) { final AnnMethod method = new AnnMethod(annClass, access, mname, mdesc); annClass.addMethod(method); return new MethodVisitor() { public AnnotationVisitor visitAnnotation(String desc, boolean visible) { Ann ann = new Ann(desc); method.addAnn(ann); return new AnnAnnReader(ann); } public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) { Ann ann = new Ann(desc); method.addParamAnn(parameter, ann); return new AnnAnnReader(ann); } public AnnotationVisitor visitAnnotationDefault() { // TODO return null; } public void visitAttribute(Attribute attr) { } public void visitCode() { } public void visitFieldInsn(int opcode, String owner, String name, String desc) { } public void visitFrame(int type, int local, Object[] local2, int stack, Object[] stack2) { } public void visitIincInsn(int var, int increment) { } public void visitInsn(int opcode) { } public void visitIntInsn(int opcode, int operand) { } public void visitJumpInsn(int opcode, Label label) { } public void visitLabel(Label label) { } public void visitLdcInsn(Object cst) { } public void visitMethodInsn(int opcode, String owner, String name, String desc) { } public void visitMultiANewArrayInsn(String desc, int dims) { } public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) { } public void visitTableSwitchInsn(int min, int max, Label dflt, Label[] labels) { } public void visitTypeInsn(int opcode, String type) { } public void visitVarInsn(int opcode, int var) { } public void visitMaxs(int maxStack, int maxLocals) { } public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) { } public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { } public void visitLineNumber(int line, Label start) { } public void visitEnd() { } }; } public void visitInnerClass(String name, String outer, String inner, int access) { } public void visitOuterClass(String owner, String name, String desc) { } public void visitAttribute(Attribute attr) { } public void visitSource(String source, String debug) { } public void visitEnd() { } static class AnnAnnReader implements AnnotationVisitor { private Ann ann; public AnnAnnReader(Ann ann) { this.ann = ann; } public void visit(String name, Object value) { ann.addParam(name, value); } public void visitEnum(String name, String desc, String value) { ann.addParam(name, new AnnEnum(desc, value)); } public AnnotationVisitor visitAnnotation(String name, String desc) { Ann ann = new Ann(desc); this.ann.addParam(name, ann); return new AnnAnnReader(ann); } public AnnotationVisitor visitArray(String name) { return new AnnAnnArrayReader(ann, name); } public void visitEnd() { } } static class AnnAnnArrayReader implements AnnotationVisitor { private Ann ann; private String name; // TODO good enough for now, but does not cover general case private ArrayList array = new ArrayList(); public AnnAnnArrayReader(Ann ann, String name) { this.ann = ann; this.name = name; } public void visit(String name, Object value) { if(value instanceof String) { array.add((String) value); } } public AnnotationVisitor visitAnnotation(String name, String value) { return null; } public AnnotationVisitor visitArray(String arg0) { return null; } public void visitEnd() { ann.addParam(name, array.toArray(new String[array.size()])); } public void visitEnum(String arg0, String arg1, String arg2) { } } } 000077500000000000000000000000001166327066700342215ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/gleanerAnnotationComponentGleaner.java000066400000000000000000000211071166327066700423600ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/gleaner/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Modifier; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; import java.util.List; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Configuration; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.component.repository.ComponentRequirementList; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.metadata.ann.AnnClass; import org.codehaus.plexus.metadata.ann.AnnField; import org.codehaus.plexus.metadata.ann.AnnReader; import org.codehaus.plexus.util.IOUtil; /** * A class component gleaner which inspects each type for org.codehaus.plexus.component.annotations.* annotations * and when found translates them into a {@link ComponentDescriptor}. * * @version $Id: AnnotationComponentGleaner.java 8455 2009-10-01 22:10:12Z bentmann $ */ public class AnnotationComponentGleaner extends ComponentGleanerSupport implements ClassComponentGleaner { public ComponentDescriptor glean(String className, ClassLoader cl) throws ComponentGleanerException { assert className != null; assert cl != null; AnnClass annClass = readClass(className.replace('.', '/'), cl); // Skip abstract classes if (Modifier.isAbstract(annClass.getAccess())) { return null; } Component anno = annClass.getAnnotation(Component.class); if (anno == null) { return null; } ComponentDescriptor component = new ComponentDescriptor(); component.setRole(anno.role().getName()); component.setRoleHint(filterEmptyAsNull(anno.hint())); component.setImplementation(className); component.setVersion(filterEmptyAsNull(anno.version())); component.setComponentType(filterEmptyAsNull(anno.type())); component.setInstantiationStrategy(filterEmptyAsNull(anno.instantiationStrategy())); component.setLifecycleHandler(filterEmptyAsNull(anno.lifecycleHandler())); component.setComponentProfile(filterEmptyAsNull(anno.profile())); component.setComponentComposer(filterEmptyAsNull(anno.composer())); component.setComponentConfigurator(filterEmptyAsNull(anno.configurator())); component.setComponentFactory(filterEmptyAsNull(anno.factory())); component.setDescription(filterEmptyAsNull(anno.description())); component.setAlias(filterEmptyAsNull(anno.alias())); component.setIsolatedRealm(anno.isolatedRealm()); for (AnnClass c : getClasses(annClass, cl)) { for (AnnField field : c.getFields().values()) { ComponentRequirement requirement = findRequirement(field, c, cl); if (requirement != null) { component.addRequirement(requirement); } PlexusConfiguration config = findConfiguration(field, c, cl); if (config != null) { addChildConfiguration(component, config); } } // // TODO: Inspect methods? // } return component; } private AnnClass readClass(String className, ClassLoader cl) throws ComponentGleanerException { InputStream is = null; try { // only read annotation from project classes (not jars) Enumeration en = cl.getResources( className + ".class" ); while ( en.hasMoreElements() ) { URL url = en.nextElement(); if( url.toString().startsWith( "file:" ) ) { is = url.openStream(); return AnnReader.read( is, cl ); } } throw new ComponentGleanerException("Can't find class " + className); } catch (IOException ex) { throw new ComponentGleanerException("Can't read class " + className, ex); } finally { IOUtil.close(is); } } private AnnClass readClass2(String className, ClassLoader cl) throws ComponentGleanerException { InputStream is = null; try { is = cl.getResourceAsStream(className + ".class"); return AnnReader.read(is, cl); } catch (IOException ex) { throw new ComponentGleanerException("Can't read class " + className, ex); } finally { IOUtil.close(is); } } /** * Returns a list of all of the classes which the given type inherits from. */ private List getClasses(AnnClass annClass, ClassLoader cl) throws ComponentGleanerException { assert annClass != null; List classes = new ArrayList(); while(annClass!=null) { classes.add(annClass); if(annClass.getSuperName()!=null) { annClass = readClass2(annClass.getSuperName(), cl); } else { break; } // // TODO: See if we need to include interfaces here too? // } return classes; } private ComponentRequirement findRequirement(final AnnField field, AnnClass annClass, ClassLoader cl) throws ComponentGleanerException { assert field != null; Requirement anno = field.getAnnotation(Requirement.class); if (anno == null) { return null; } String fieldType = field.getType(); // TODO implement type resolution without loading classes Class type; try { type = Class.forName(fieldType, false, cl); } catch (ClassNotFoundException ex) { // TODO Auto-generated catch block throw new ComponentGleanerException("Can't load class " + fieldType); } ComponentRequirement requirement; if (isRequirementListType(type)) { requirement = new ComponentRequirementList(); String[] hints = anno.hints(); if (hints != null && hints.length > 0) { ((ComponentRequirementList)requirement).setRoleHints(Arrays.asList(hints)); } // // TODO: See if we can glean any type details out of any generic information from the map or collection // } else { requirement = new ComponentRequirement(); requirement.setRoleHint(filterEmptyAsNull(anno.hint())); } // TODO need to read default annotation values // if (anno.role()==null || anno.role().isAssignableFrom(Object.class)) { if (anno.role().isAssignableFrom(Object.class)) { requirement.setRole(type.getName()); } else { requirement.setRole(anno.role().getName()); } requirement.setFieldName(field.getName()); requirement.setFieldMappingType(type.getName()); requirement.setOptional( anno.optional() ); return requirement; } private PlexusConfiguration findConfiguration(AnnField field, AnnClass c, ClassLoader cl) { assert field != null; Configuration anno = field.getAnnotation(Configuration.class); if (anno == null) { return null; } String name = filterEmptyAsNull(anno.name()); if (name == null) { name = field.getName(); } name = deHump(name); XmlPlexusConfiguration config = new XmlPlexusConfiguration(name); String value = filterEmptyAsNull(anno.value()); if (value != null) { config.setValue(value); } return config; } } ClassComponentGleaner.java000066400000000000000000000021361166327066700413140ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/gleanerpackage org.codehaus.plexus.metadata.gleaner; /* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.repository.ComponentDescriptor; /** * Interface for component gleaners which glean off of compiled classes.. * * @version $Id: ClassComponentGleaner.java 7966 2008-12-25 15:25:22Z bentmann $ */ public interface ClassComponentGleaner { String ROLE = ClassComponentGleaner.class.getName(); ComponentDescriptor glean(String className, ClassLoader cl) throws ComponentGleanerException; }ComponentGleanerException.java000066400000000000000000000032701166327066700422050ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/gleanerpackage org.codehaus.plexus.metadata.gleaner; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: ComponentGleanerException.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class ComponentGleanerException extends Exception { public ComponentGleanerException( String message ) { super( message ); } public ComponentGleanerException( String message, Throwable cause ) { super( message, cause ); } public ComponentGleanerException( Throwable cause ) { super( cause ); } }ComponentGleanerSupport.java000066400000000000000000000045761166327066700417350ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/gleaner/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner; import java.util.Collection; import java.util.Map; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; /** * Support for component gleaner implementations. * * @version $Id: ComponentGleanerSupport.java 7966 2008-12-25 15:25:22Z bentmann $ */ public abstract class ComponentGleanerSupport { private static final String EMPTY_STRING = ""; protected String filterEmptyAsNull(final String value) { if (value == null) { return null; } else if (EMPTY_STRING.equals(value.trim())) { return null; } else { return value; } } protected boolean isRequirementListType(final Class type) { // assert type != null; return Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type); } protected void addChildConfiguration(final ComponentDescriptor component, final PlexusConfiguration config) { // assert component != null; // assert config != null; if (!component.hasConfiguration()) { component.setConfiguration(new XmlPlexusConfiguration("configuration")); } component.getConfiguration().addChild(config); } protected String deHump(final String string) { // assert string != null; StringBuffer buff = new StringBuffer(); for (int i = 0; i < string.length(); i++) { if (i != 0 && Character.isUpperCase(string.charAt(i))) { buff.append('-'); } buff.append(string.charAt(i)); } return buff.toString().trim().toLowerCase(); } }QDoxComponentGleaner.java000066400000000000000000000475201166327066700411300ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/gleanerpackage org.codehaus.plexus.metadata.gleaner; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.component.repository.ComponentRequirementList; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Configurable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; import org.codehaus.plexus.util.StringUtils; import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; /** * A source component gleaner which uses QDox to discover Javadoc annotations. * * @author Trygve Laugstøl * @version $Id: QDoxComponentGleaner.java 8455 2009-10-01 22:10:12Z bentmann $ */ public class QDoxComponentGleaner extends ComponentGleanerSupport implements SourceComponentGleaner { public static final String PLEXUS_COMPONENT_TAG = "plexus.component"; public static final String PLEXUS_REQUIREMENT_TAG = "plexus.requirement"; public static final String PLEXUS_CONFIGURATION_TAG = "plexus.configuration"; public static final String PLEXUS_VERSION_PARAMETER = "version"; public static final String PLEXUS_ROLE_PARAMETER = "role"; public static final String PLEXUS_ROLE_HINT_PARAMETER = "role-hint"; public static final String PLEXUS_ROLE_HINT_LIST_PARAMETER = "role-hints"; public static final String PLEXUS_ALIAS_PARAMETER = "alias"; public static final String PLEXUS_DEFAULT_VALUE_PARAMETER = "default-value"; public static final String PLEXUS_LIFECYCLE_HANDLER_PARAMETER = "lifecycle-handler"; public static final String PLEXUS_INSTANTIATION_STARTEGY_PARAMETER = "instantiation-strategy"; public static final String PLEXUS_OPTIONAL_PARAMETER = "optional"; public static final String PLEXUS_DEFAULT_HINT = "default"; // ---------------------------------------------------------------------- // ComponentGleaner Implementation // ---------------------------------------------------------------------- public ComponentDescriptor glean( JavaDocBuilder classCache, JavaClass javaClass ) throws ComponentGleanerException { DocletTag tag = javaClass.getTagByName( PLEXUS_COMPONENT_TAG ); if ( tag == null ) { return null; } Map parameters = tag.getNamedParameterMap(); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- String fqn = javaClass.getFullyQualifiedName(); //log.debug( "Creating descriptor for component: {}", fqn ); ComponentDescriptor componentDescriptor = new ComponentDescriptor(); componentDescriptor.setImplementation( fqn ); // ---------------------------------------------------------------------- // Role // ---------------------------------------------------------------------- String role = getParameter( parameters, PLEXUS_ROLE_PARAMETER ); if ( role == null ) { role = findRole( javaClass ); if ( role == null ) { /* log.warn( "Could not figure out a role for the component '" + fqn + "'. " + "Please specify a role with a parameter '" + PLEXUS_ROLE_PARAMETER + "' " + "on the @" + PLEXUS_COMPONENT_TAG + " tag." ); */ return null; } } componentDescriptor.setRole( role ); // ---------------------------------------------------------------------- // Role hint // ---------------------------------------------------------------------- String roleHint = getParameter( parameters, PLEXUS_ROLE_HINT_PARAMETER ); if ( roleHint != null ) { // getLogger().debug( " Role hint: " + roleHint ); } componentDescriptor.setRoleHint( roleHint ); // ---------------------------------------------------------------------- // Version // ---------------------------------------------------------------------- String version = getParameter( parameters, PLEXUS_VERSION_PARAMETER ); componentDescriptor.setVersion( version ); // ---------------------------------------------------------------------- // Lifecycle handler // ---------------------------------------------------------------------- String lifecycleHandler = getParameter( parameters, PLEXUS_LIFECYCLE_HANDLER_PARAMETER ); componentDescriptor.setLifecycleHandler( lifecycleHandler ); // ---------------------------------------------------------------------- // Lifecycle handler // ---------------------------------------------------------------------- String instatiationStrategy = getParameter( parameters, PLEXUS_INSTANTIATION_STARTEGY_PARAMETER ); componentDescriptor.setInstantiationStrategy( instatiationStrategy ); // ---------------------------------------------------------------------- // Alias // ---------------------------------------------------------------------- componentDescriptor.setAlias( getParameter( parameters, PLEXUS_ALIAS_PARAMETER ) ); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- findExtraParameters( PLEXUS_COMPONENT_TAG, parameters ); // ---------------------------------------------------------------------- // Requirements // ---------------------------------------------------------------------- findRequirements( classCache, componentDescriptor, javaClass ); // ---------------------------------------------------------------------- // Description // ---------------------------------------------------------------------- String comment = javaClass.getComment(); if ( comment != null ) { int i = comment.indexOf( '.' ); if ( i > 0 ) { comment = comment.substring( 0, i + 1 ); // include the dot } } componentDescriptor.setDescription( comment ); // ---------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------- XmlPlexusConfiguration configuration = new XmlPlexusConfiguration( "configuration" ); findConfiguration( configuration, javaClass ); componentDescriptor.setConfiguration( configuration ); return componentDescriptor; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- private final static List IGNORED_INTERFACES = Collections.unmodifiableList( Arrays.asList( new String[]{ LogEnabled.class.getName(), Initializable.class.getName(), Configurable.class.getName(), Contextualizable.class.getName(), Disposable.class.getName(), Startable.class.getName(), } ) ); private static String getPackage( JavaClass javaClass ) { if ( javaClass.getPackage() != null ) { return javaClass.getPackage().getName(); } else { return ""; } } private String findRole( JavaClass javaClass ) { // ---------------------------------------------------------------------- // Remove any Plexus specific interfaces from the calculation // ---------------------------------------------------------------------- List interfaces = new ArrayList( Arrays.asList( javaClass.getImplementedInterfaces() ) ); for ( Iterator it = interfaces.iterator(); it.hasNext(); ) { JavaClass ifc = it.next(); if ( IGNORED_INTERFACES.contains( ifc.getFullyQualifiedName() ) ) { it.remove(); } } // ---------------------------------------------------------------------- // For each implemented interface, check to see if it's a candiate // interface // ---------------------------------------------------------------------- String role = null; String className = javaClass.getName(); for ( Iterator it = interfaces.iterator(); it.hasNext(); ) { JavaClass ifc = it.next(); String fqn = ifc.getFullyQualifiedName(); String pkg = getPackage( ifc ); if ( pkg == null ) { int index = fqn.lastIndexOf( '.' ); if ( index == -1 ) { // ----------------------------------------------------------------------- // This is a special case which will happen in two cases: // 1) The component is in the default/root package // 2) The interface is in another build, typically in an -api package // while the code beeing gleaned in in the -impl build. // // Since it's most likely in another package than in the default package // prepend the gleaned class' package // ----------------------------------------------------------------------- pkg = getPackage( javaClass ); fqn = pkg + "." + fqn; } else { pkg = fqn.substring( 0, index ); } } if ( fqn == null ) { fqn = ifc.getName(); } String name = fqn.substring( pkg.length() + 1 ); if ( className.endsWith( name ) ) { if ( role != null ) { /* log.warn( "Found several possible roles for component " + "'" + javaClass.getFullyQualifiedName() + "', " + "will use '" + role + "', found: " + ifc.getName() + "." ); */ } role = fqn; } } if ( role == null ) { JavaClass superClass = javaClass.getSuperJavaClass(); if ( superClass != null ) { role = findRole( superClass ); } } return role; } private void findRequirements( JavaDocBuilder classCache, ComponentDescriptor componentDescriptor, JavaClass javaClass ) { JavaField[] fields = javaClass.getFields(); // ---------------------------------------------------------------------- // Search the super class for requirements // ---------------------------------------------------------------------- if ( javaClass.getSuperJavaClass() != null ) { findRequirements( classCache, componentDescriptor, javaClass.getSuperJavaClass() ); } // ---------------------------------------------------------------------- // Search the current class for requirements // ---------------------------------------------------------------------- for ( int i = 0; i < fields.length; i++ ) { JavaField field = fields[i]; DocletTag tag = field.getTagByName( PLEXUS_REQUIREMENT_TAG ); if ( tag == null ) { continue; } Map parameters = new HashMap( tag.getNamedParameterMap() ); // ---------------------------------------------------------------------- // Role // ---------------------------------------------------------------------- String requirementClass = field.getType().getJavaClass().getFullyQualifiedName(); boolean isMap = requirementClass.equals( Map.class.getName() ) || requirementClass.equals( Collection.class.getName() ); try { isMap = isMap || Collection.class.isAssignableFrom( Class.forName( requirementClass ) ); } catch ( ClassNotFoundException e ) { // ignore the assignable Collection test, though this should never happen } boolean isList = requirementClass.equals( List.class.getName() ); ComponentRequirement cr; String hint = getParameter( parameters, PLEXUS_ROLE_HINT_PARAMETER ); if ( isMap || isList ) { cr = new ComponentRequirementList(); String hintList = getParameter( parameters, PLEXUS_ROLE_HINT_LIST_PARAMETER ); if ( hintList != null ) { String[] hintArr = hintList.split( "," ); ( (ComponentRequirementList) cr).setRoleHints( Arrays.asList( hintArr ) ); } } else { cr = new ComponentRequirement(); cr.setRoleHint( hint ); } String role = getParameter( parameters, PLEXUS_ROLE_PARAMETER ); if ( role == null ) { cr.setRole( requirementClass ); } else { cr.setRole( role ); } String optional = getParameter( parameters, PLEXUS_OPTIONAL_PARAMETER ); cr.setOptional( Boolean.parseBoolean( optional ) ); cr.setFieldName( field.getName() ); if ( isMap || isList ) { if ( hint != null ) { /* log.warn( "Field: '" + field.getName() + "': A role hint cannot be specified if the " + "field is a java.util.Map or a java.util.List" ); */ continue; } if ( role == null ) { /* log.warn( "Field: '" + field.getName() + "': A java.util.Map or java.util.List " + "requirement has to specify a '" + PLEXUS_ROLE_PARAMETER + "' parameter on " + "the @" + PLEXUS_REQUIREMENT_TAG + " tag so Plexus can know which components to " + "put in the map or list." ); */ continue; } JavaClass roleClass = classCache.getClassByName( role ); if ( role.indexOf( '.' ) == -1 && StringUtils.isEmpty( getPackage( roleClass ) ) ) { role = getPackage( javaClass ) + "." + roleClass.getName(); } cr.setRole( role ); findExtraParameters( PLEXUS_REQUIREMENT_TAG, parameters ); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- componentDescriptor.addRequirement( cr ); } } private void findConfiguration( XmlPlexusConfiguration configuration, JavaClass javaClass ) throws ComponentGleanerException { JavaField[] fields = javaClass.getFields(); // ---------------------------------------------------------------------- // Search the super class for configurable fields. // ---------------------------------------------------------------------- if ( javaClass.getSuperJavaClass() != null ) { findConfiguration( configuration, javaClass.getSuperJavaClass() ); } // ---------------------------------------------------------------------- // Search the current class for configurable fields. // ---------------------------------------------------------------------- for ( int i = 0; i < fields.length; i++ ) { JavaField field = fields[i]; DocletTag tag = field.getTagByName( PLEXUS_CONFIGURATION_TAG ); if ( tag == null ) { continue; } Map parameters = new HashMap( tag.getNamedParameterMap() ); /* don't use the getParameter helper as we like empty strings */ String defaultValue = parameters.remove( PLEXUS_DEFAULT_VALUE_PARAMETER ); if ( defaultValue == null ) { /* log.warn( "Component: " + javaClass.getName() + ", field name: '" + field.getName() + "': " + "Currently configurable fields will not be written to the descriptor " + "without a default value." );*/ continue; } String name = deHump( field.getName() ); XmlPlexusConfiguration c; c = new XmlPlexusConfiguration( name ); c.setValue( defaultValue ); //log.debug( " Configuration: {}={}", name, defaultValue ); configuration.addChild( c ); findExtraParameters( PLEXUS_CONFIGURATION_TAG, parameters ); } } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- private void findExtraParameters( String tagName, Map parameters ) { for ( Iterator it = parameters.keySet().iterator(); it.hasNext(); ) { String s = it.next(); //log.warn( "Extra parameter on the '" + tagName + "' tag: '" + s + "'." ); } } private String getParameter( Map parameters, String parameter ) { String value = parameters.remove( parameter ); if ( StringUtils.isEmpty( value ) ) { return null; } return value; } }SourceComponentGleaner.java000066400000000000000000000023011166327066700415010ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/gleanerpackage org.codehaus.plexus.metadata.gleaner; /* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.repository.ComponentDescriptor; import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.JavaClass; /** * Interface for component gleaners which glean off of source code. * * @version $Id: SourceComponentGleaner.java 8340 2009-08-17 09:34:27Z bentmann $ */ public interface SourceComponentGleaner { String ROLE = SourceComponentGleaner.class.getName(); ComponentDescriptor glean( JavaDocBuilder classCache, JavaClass javaClass ) throws ComponentGleanerException; }000077500000000000000000000000001166327066700337035ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/mergeAbstractMerger.java000066400000000000000000000071441166327066700374610ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/mergepackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.List; import org.codehaus.plexus.util.IOUtil; import org.jdom.Document; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; /** * Base class for common mergers. * * @author Brett Porter */ public abstract class AbstractMerger implements Merger { /** * @see org.codehaus.plexus.metadata.merge.Merger#writeMergedDocument(org.jdom.Document, * java.io.File) */ public void writeMergedDocument( Document mergedDocument, File file ) throws IOException { if ( !file.getParentFile().exists() ) { file.getParentFile().mkdirs(); } XMLOutputter out = new XMLOutputter(); Writer fw = null; try { fw = new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ); out.output( mergedDocument, fw ); } finally { IOUtil.close( fw ); } } public void mergeDescriptors( File outputDescriptor, List descriptors ) throws IOException { SAXBuilder builder = new SAXBuilder( Driver.class.getName() ); Document finalDoc = null; for ( File f : descriptors ) { try { Document doc = builder.build( f ); if ( finalDoc != null ) { // Last specified has dominance finalDoc = merge( doc, finalDoc ); } else { finalDoc = doc; } } catch ( JDOMException e ) { throw new IOException( "Invalid input descriptor for merge: " + f + " --> " + e.getMessage() ); } catch ( MergeException e ) { throw new IOException( "Error merging descriptor: " + f + " --> " + e.getMessage() ); } } if ( finalDoc != null ) { try { writeMergedDocument( finalDoc, outputDescriptor ); } catch ( IOException e ) { throw new IOException( "Error writing merged descriptor: " + outputDescriptor ); } } } } ComponentsXmlMerger.java000066400000000000000000000044301166327066700405170ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/mergepackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.metadata.merge.support.ComponentSetElement; import org.jdom.Document; /** * @author Rahul Thakur * @version $Id: ComponentsXmlMerger.java 8174 2009-05-11 15:15:23Z jvanzyl $ */ @Component(role=Merger.class,hint="componentsXml") public class ComponentsXmlMerger extends AbstractMerger { /** * @see Merger#merge(Document, Document) */ public Document merge( Document dDocument, Document rDocument ) throws MergeException { // TODO: Ideally we don't want to manipulate the original // dominant document but use its copy for merge. //Document mDoc = (Document) dDocument.clone(); // doesn't merge properly Document mDoc = dDocument; ComponentSetElement dCSE = new ComponentSetElement( mDoc.getRootElement() ); ComponentSetElement rCSE = new ComponentSetElement( rDocument.getRootElement() ); dCSE.merge( rCSE ); // the contents are merged into the dominant document DOM. return mDoc; } } Driver.java000066400000000000000000000431021166327066700360010ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/ // for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/) package org.codehaus.plexus.metadata.merge; import java.io.InputStream; import java.io.IOException; import java.io.Reader; // not J2ME classes -- remove if you want to run in MIDP devices import java.net.URL; import java.net.MalformedURLException; // not J2ME classes import java.io.FileInputStream; import java.io.FileNotFoundException; import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.xml.sax.Attributes; import org.xml.sax.DTDHandler; import org.xml.sax.ContentHandler; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; /** * SAX2 Driver that pulls events from XmlPullParser * and comverts them into SAX2 callbacks. * * @author Aleksander Slominski */ public class Driver implements Locator, XMLReader, Attributes { protected static final String DECLARATION_HANDLER_PROPERTY = "http://xml.org/sax/properties/declaration-handler"; protected static final String LEXICAL_HANDLER_PROPERTY = "http://xml.org/sax/properties/lexical-handler"; protected static final String NAMESPACES_FEATURE = "http://xml.org/sax/features/namespaces"; protected static final String NAMESPACE_PREFIXES_FEATURE = "http://xml.org/sax/features/namespace-prefixes"; protected static final String VALIDATION_FEATURE = "http://xml.org/sax/features/validation"; protected static final String APACHE_SCHEMA_VALIDATION_FEATURE = "http://apache.org/xml/features/validation/schema"; protected static final String APACHE_DYNAMIC_VALIDATION_FEATURE = "http://apache.org/xml/features/validation/dynamic"; protected ContentHandler contentHandler = new DefaultHandler(); protected ErrorHandler errorHandler = new DefaultHandler();; protected String systemId; protected XmlPullParser pp; public Driver() throws XmlPullParserException { pp = new MXParser(); try { setFeature( NAMESPACES_FEATURE, true ); setFeature( NAMESPACE_PREFIXES_FEATURE, true ); } catch ( Exception e ) { e.printStackTrace(); } } // -- Attributes interface public int getLength() { return pp.getAttributeCount(); } public String getURI(int index) { return pp.getAttributeNamespace(index); } public String getLocalName(int index) { return pp.getAttributeName(index); } public String getQName(int index) { final String prefix = pp.getAttributePrefix(index); if(prefix != null) { return prefix+':'+pp.getAttributeName(index); } else { return pp.getAttributeName(index); } } public String getType(int index) { return pp.getAttributeType(index); } public String getValue(int index) { return pp.getAttributeValue(index); } public int getIndex(String uri, String localName) { for (int i = 0; i < pp.getAttributeCount(); i++) { if(pp.getAttributeNamespace(i).equals(uri) && pp.getAttributeName(i).equals(localName)) { return i; } } return -1; } public int getIndex(String qName) { for (int i = 0; i < pp.getAttributeCount(); i++) { if(pp.getAttributeName(i).equals(qName)) { return i; } } return -1; } public String getType(String uri, String localName) { for (int i = 0; i < pp.getAttributeCount(); i++) { if(pp.getAttributeNamespace(i).equals(uri) && pp.getAttributeName(i).equals(localName)) { return pp.getAttributeType(i); } } return null; } public String getType(String qName) { for (int i = 0; i < pp.getAttributeCount(); i++) { if(pp.getAttributeName(i).equals(qName)) { return pp.getAttributeType(i); } } return null; } public String getValue(String uri, String localName) { return pp.getAttributeValue(uri, localName); } public String getValue(String qName) { return pp.getAttributeValue(null, qName); } // -- Locator interface public String getPublicId() { return null; } public String getSystemId() { return systemId; } public int getLineNumber() { return pp.getLineNumber(); } public int getColumnNumber() { return pp.getColumnNumber(); } // --- XMLReader interface //"http://xml.org/sax/features/namespaces", //true public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { if(NAMESPACES_FEATURE.equals(name)) { return pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES); } else if(NAMESPACE_PREFIXES_FEATURE.equals(name)) { return pp.getFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES); } else if(VALIDATION_FEATURE.equals(name)) { return pp.getFeature(XmlPullParser.FEATURE_VALIDATION); // } else if(APACHE_SCHEMA_VALIDATION_FEATURE.equals(name)) { // return false; //TODO // } else if(APACHE_DYNAMIC_VALIDATION_FEATURE.equals(name)) { // return false; //TODO } else { return pp.getFeature(name); //throw new SAXNotRecognizedException("unrecognized feature "+name); } } public void setFeature (String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { try { if(NAMESPACES_FEATURE.equals(name)) { pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, value); } else if(NAMESPACE_PREFIXES_FEATURE.equals(name)) { if(pp.getFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES) != value) { pp.setFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES, value); } } else if(VALIDATION_FEATURE.equals(name)) { pp.setFeature(XmlPullParser.FEATURE_VALIDATION, value); } else { pp.setFeature(name, value); //throw new SAXNotRecognizedException("unrecognized feature "+name); } } catch(XmlPullParserException ex) { throw new SAXNotSupportedException("problem with setting feature "+name+": "+ex); } } public Object getProperty (String name) throws SAXNotRecognizedException, SAXNotSupportedException { if(DECLARATION_HANDLER_PROPERTY.equals(name)) { return null; } else if(LEXICAL_HANDLER_PROPERTY.equals(name)) { return null; } else { return pp.getProperty(name); //throw new SAXNotRecognizedException("not recognized get property "+name); } } public void setProperty (String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { // if(DECLARATION_HANDLER_PROPERTY.equals(name)) { throw new SAXNotSupportedException("not supported setting property "+name);//+" to "+value); } else if(LEXICAL_HANDLER_PROPERTY.equals(name)) { throw new SAXNotSupportedException("not supported setting property "+name);//+" to "+value); } else { try { pp.setProperty(name, value); } catch(XmlPullParserException ex) { throw new SAXNotSupportedException("not supported set property "+name+": "+ ex); } //throw new SAXNotRecognizedException("not recognized set property "+name); } } public void setEntityResolver (EntityResolver resolver) {} public EntityResolver getEntityResolver () { return null; } public void setDTDHandler (DTDHandler handler) {} public DTDHandler getDTDHandler () { return null; } public void setContentHandler (ContentHandler handler) { this.contentHandler = handler; } public ContentHandler getContentHandler() { return contentHandler; } public void setErrorHandler(ErrorHandler handler) { this.errorHandler = handler; } public ErrorHandler getErrorHandler() { return errorHandler; } public void parse(InputSource source) throws SAXException, IOException { systemId = source.getSystemId(); contentHandler.setDocumentLocator(this); final Reader reader = source.getCharacterStream(); try { if (reader == null) { InputStream stream = source.getByteStream(); final String encoding = source.getEncoding(); if (stream == null) { systemId = source.getSystemId(); if(systemId == null) { SAXParseException saxException = new SAXParseException( "null source systemId" , this); errorHandler.fatalError(saxException); return; } // NOTE: replace with Connection to run in J2ME environment try { final URL url = new URL(systemId); stream = url.openStream(); } catch (MalformedURLException nue) { try { stream = new FileInputStream(systemId); } catch (FileNotFoundException fnfe) { final SAXParseException saxException = new SAXParseException( "could not open file with systemId "+systemId, this, fnfe); errorHandler.fatalError(saxException); return; } } } pp.setInput(stream, encoding); } else { pp.setInput(reader); } } catch (XmlPullParserException ex) { final SAXParseException saxException = new SAXParseException( "parsing initialization error: "+ex, this, ex); //if(DEBUG) ex.printStackTrace(); errorHandler.fatalError(saxException); return; } // start parsing - move to first start tag try { contentHandler.startDocument(); // get first event pp.next(); // it should be start tag... if(pp.getEventType() != XmlPullParser.START_TAG) { final SAXParseException saxException = new SAXParseException( "expected start tag not"+pp.getPositionDescription(), this); //throw saxException; errorHandler.fatalError(saxException); return; } } catch (XmlPullParserException ex) { final SAXParseException saxException = new SAXParseException( "parsing initialization error: "+ex, this, ex); //ex.printStackTrace(); errorHandler.fatalError(saxException); return; } // now real parsing can start! parseSubTree(pp); // and finished ... contentHandler.endDocument(); } public void parse(String systemId) throws SAXException, IOException { parse(new InputSource(systemId)); } public void parseSubTree(XmlPullParser pp) throws SAXException, IOException { this.pp = pp; final boolean namespaceAware = pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES); try { if(pp.getEventType() != XmlPullParser.START_TAG) { throw new SAXException( "start tag must be read before skiping subtree"+pp.getPositionDescription()); } final int[] holderForStartAndLength = new int[2]; final StringBuffer rawName = new StringBuffer(16); String prefix = null; String name = null; int level = pp.getDepth() - 1; int type = XmlPullParser.START_TAG; LOOP: do { switch(type) { case XmlPullParser.START_TAG: if(namespaceAware) { final int depth = pp.getDepth() - 1; final int countPrev = (level > depth) ? pp.getNamespaceCount(depth) : 0; //int countPrev = pp.getNamespaceCount(pp.getDepth() - 1); final int count = pp.getNamespaceCount(depth + 1); for (int i = countPrev; i < count; i++) { contentHandler.startPrefixMapping( pp.getNamespacePrefix(i), pp.getNamespaceUri(i) ); } name = pp.getName(); prefix = pp.getPrefix(); if(prefix != null) { rawName.setLength(0); rawName.append(prefix); rawName.append(':'); rawName.append(name); } startElement(pp.getNamespace(), name, prefix != null ? name : rawName.toString()); } else { startElement(pp.getNamespace(), pp.getName(), pp.getName()); } //++level; break; case XmlPullParser.TEXT: final char[] chars = pp.getTextCharacters(holderForStartAndLength); contentHandler.characters(chars, holderForStartAndLength[0], //start holderForStartAndLength[1] //len ); break; case XmlPullParser.END_TAG: //--level; if(namespaceAware) { name = pp.getName(); prefix = pp.getPrefix(); if(prefix != null) { rawName.setLength(0); rawName.append(prefix); rawName.append(':'); rawName.append(name); } contentHandler.endElement(pp.getNamespace(), name, prefix != null ? name : rawName.toString() ); // when entering show prefixes for all levels!!!! final int depth = pp.getDepth(); final int countPrev = (level > depth) ? pp.getNamespaceCount(pp.getDepth()) : 0; int count = pp.getNamespaceCount(pp.getDepth() - 1); // undeclare them in reverse order for (int i = count - 1; i >= countPrev; i--) { contentHandler.endPrefixMapping( pp.getNamespacePrefix(i) ); } } else { contentHandler.endElement(pp.getNamespace(), pp.getName(), pp.getName() ); } break; case XmlPullParser.END_DOCUMENT: break LOOP; } type = pp.next(); } while(pp.getDepth() > level); } catch (XmlPullParserException ex) { final SAXParseException saxException = new SAXParseException("parsing error: "+ex, this, ex); ex.printStackTrace(); errorHandler.fatalError(saxException); } } /** * Calls {@link ContentHandler.startElement(String, String, String, Attributes) startElement} * on the ContentHandler with this driver object as the * {@link Attributes} implementation. In default implementation * {@link Attributes} object is valid only during this method call and may not * be stored. Sub-classes can overwrite this method to cache attributes. */ protected void startElement(String namespace, String localName, String qName) throws SAXException { contentHandler.startElement(namespace, localName, qName, this); } } MXParser.java000066400000000000000000004034231166327066700362550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/ /* * Copyright (c) 2003 Extreme! Lab, Indiana University. All rights reserved. * * This software is open source. See the bottom of this file for the licence. * * $Id: MXParser.java 8174 2009-05-11 15:15:23Z jvanzyl $ */ package org.codehaus.plexus.metadata.merge; import java.io.EOFException; import java.io.IOException; import java.io.Reader; import java.io.UnsupportedEncodingException; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; //import java.util.Hashtable; //TODO best handling of interning issues // have isAllNewStringInterned ??? //TODO handling surrogate pairs: http://www.unicode.org/unicode/faq/utf_bom.html#6 //TODO review code for use of bufAbsoluteStart when keeping pos between next()/fillBuf() /** * Absolutely minimal implementation of XMLPULL V1 API. Encoding handling done with XmlReader * * @see org.codehaus.plexus.util.xml.XmlReader * @author Aleksander Slominski */ public class MXParser implements XmlPullParser { //NOTE: no interning of those strings --> by Java leng spec they MUST be already interned protected final static String XML_URI = "http://www.w3.org/XML/1998/namespace"; protected final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; protected final static String FEATURE_XML_ROUNDTRIP= //"http://xmlpull.org/v1/doc/features.html#xml-roundtrip"; "http://xmlpull.org/v1/doc/features.html#xml-roundtrip"; protected final static String FEATURE_NAMES_INTERNED = "http://xmlpull.org/v1/doc/features.html#names-interned"; protected final static String PROPERTY_XMLDECL_VERSION = "http://xmlpull.org/v1/doc/properties.html#xmldecl-version"; protected final static String PROPERTY_XMLDECL_STANDALONE = "http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone"; protected final static String PROPERTY_XMLDECL_CONTENT = "http://xmlpull.org/v1/doc/properties.html#xmldecl-content"; protected final static String PROPERTY_LOCATION = "http://xmlpull.org/v1/doc/properties.html#location"; protected final static String REPORT_NAMESPACE_PREFIXES = "http://xmlpull.org/v1/doc/features.html#report-namespace-prefixes"; /** * Implementation notice: * the is instance variable that controls if newString() is interning. *

NOTE: newStringIntern always returns interned strings * and newString MAY return interned String depending on this variable. *

NOTE: by default in this minimal implementation it is false! */ protected boolean allStringsInterned; protected boolean usePC; protected boolean seenStartTag; protected boolean seenEndTag; protected boolean pastEndTag; protected boolean seenAmpersand; protected boolean seenMarkup; protected boolean seenDocdecl; // transient variable set during each call to next/Token() protected boolean tokenize; protected String text; protected String entityRefName; protected String xmlDeclVersion; protected Boolean xmlDeclStandalone; protected String xmlDeclContent; // NOTE: features are not resetable and typically defaults to false ... protected boolean processNamespaces; protected boolean roundtripSupported; // global parser state protected String location; protected int lineNumber; protected int columnNumber; protected boolean seenRoot; protected boolean reachedEnd; protected int eventType; protected boolean emptyElementTag; // element stack protected int depth; protected char[] elRawName[]; protected int elRawNameEnd[]; protected int elRawNameLine[]; protected String elName[]; protected String elPrefix[]; protected String elUri[]; //protected String elValue[]; protected int elNamespaceCount[]; // input buffer management protected static final int READ_CHUNK_SIZE = 8*1024; //max data chars in one read() call protected Reader reader; protected String inputEncoding; protected int bufLoadFactor = 95; // 99% //protected int bufHardLimit; // only matters when expanding protected char buf[] = new char[READ_CHUNK_SIZE]; protected int bufSoftLimit = ( bufLoadFactor * buf.length ) /100; protected boolean preventBufferCompaction; protected int bufAbsoluteStart; // this is buf protected int bufStart; protected int bufEnd; protected int pos; protected int posStart; protected int posEnd; protected char pc[] = new char[READ_CHUNK_SIZE]; protected int pcStart; protected int pcEnd; protected void resetStringCache() { //System.out.println("resetStringCache() minimum called"); } protected String newString(char[] cbuf, int off, int len) { return new String(cbuf, off, len); } protected String newStringIntern(char[] cbuf, int off, int len) { return (new String(cbuf, off, len)).intern(); } private static final boolean TRACE_SIZING = false; /** * Make sure that we have enough space to keep element stack if passed size. * It will always create one additional slot then current depth */ protected void ensureElementsCapacity() { final int elStackSize = elName != null ? elName.length : 0; if( (depth + 1) >= elStackSize) { // we add at least one extra slot ... final int newSize = (depth >= 7 ? 2 * depth : 8) + 2; // = lucky 7 + 1 //25 if(TRACE_SIZING) { System.err.println("TRACE_SIZING elStackSize "+elStackSize+" ==> "+newSize); } final boolean needsCopying = elStackSize > 0; String[] arr = null; // resue arr local variable slot arr = new String[newSize]; if(needsCopying) System.arraycopy(elName, 0, arr, 0, elStackSize); elName = arr; arr = new String[newSize]; if(needsCopying) System.arraycopy(elPrefix, 0, arr, 0, elStackSize); elPrefix = arr; arr = new String[newSize]; if(needsCopying) System.arraycopy(elUri, 0, arr, 0, elStackSize); elUri = arr; int[] iarr = new int[newSize]; if(needsCopying) { System.arraycopy(elNamespaceCount, 0, iarr, 0, elStackSize); } else { // special initialization iarr[0] = 0; } elNamespaceCount = iarr; //TODO: avoid using element raw name ... iarr = new int[newSize]; if(needsCopying) { System.arraycopy(elRawNameEnd, 0, iarr, 0, elStackSize); } elRawNameEnd = iarr; iarr = new int[newSize]; if(needsCopying) { System.arraycopy(elRawNameLine, 0, iarr, 0, elStackSize); } elRawNameLine = iarr; final char[][] carr = new char[newSize][]; if(needsCopying) { System.arraycopy(elRawName, 0, carr, 0, elStackSize); } elRawName = carr; // arr = new String[newSize]; // if(needsCopying) System.arraycopy(elLocalName, 0, arr, 0, elStackSize); // elLocalName = arr; // arr = new String[newSize]; // if(needsCopying) System.arraycopy(elDefaultNs, 0, arr, 0, elStackSize); // elDefaultNs = arr; // int[] iarr = new int[newSize]; // if(needsCopying) System.arraycopy(elNsStackPos, 0, iarr, 0, elStackSize); // for (int i = elStackSize; i < iarr.length; i++) // { // iarr[i] = (i > 0) ? -1 : 0; // } // elNsStackPos = iarr; //assert depth < elName.length; } } // attribute stack protected int attributeCount; protected String attributeName[]; protected int attributeNameHash[]; //protected int attributeNameStart[]; //protected int attributeNameEnd[]; protected String attributePrefix[]; protected String attributeUri[]; protected String attributeValue[]; //protected int attributeValueStart[]; //protected int attributeValueEnd[]; /** * Make sure that in attributes temporary array is enough space. */ protected void ensureAttributesCapacity(int size) { final int attrPosSize = attributeName != null ? attributeName.length : 0; if(size >= attrPosSize) { final int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25 if(TRACE_SIZING) { System.err.println("TRACE_SIZING attrPosSize "+attrPosSize+" ==> "+newSize); } final boolean needsCopying = attrPosSize > 0; String[] arr = null; arr = new String[newSize]; if(needsCopying) System.arraycopy(attributeName, 0, arr, 0, attrPosSize); attributeName = arr; arr = new String[newSize]; if(needsCopying) System.arraycopy(attributePrefix, 0, arr, 0, attrPosSize); attributePrefix = arr; arr = new String[newSize]; if(needsCopying) System.arraycopy(attributeUri, 0, arr, 0, attrPosSize); attributeUri = arr; arr = new String[newSize]; if(needsCopying) System.arraycopy(attributeValue, 0, arr, 0, attrPosSize); attributeValue = arr; if( ! allStringsInterned ) { final int[] iarr = new int[newSize]; if(needsCopying) System.arraycopy(attributeNameHash, 0, iarr, 0, attrPosSize); attributeNameHash = iarr; } arr = null; // //assert attrUri.length > size } } // namespace stack protected int namespaceEnd; protected String namespacePrefix[]; protected int namespacePrefixHash[]; protected String namespaceUri[]; protected void ensureNamespacesCapacity(int size) { final int namespaceSize = namespacePrefix != null ? namespacePrefix.length : 0; if(size >= namespaceSize) { final int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25 if(TRACE_SIZING) { System.err.println("TRACE_SIZING namespaceSize "+namespaceSize+" ==> "+newSize); } final String[] newNamespacePrefix = new String[newSize]; final String[] newNamespaceUri = new String[newSize]; if(namespacePrefix != null) { System.arraycopy( namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd); System.arraycopy( namespaceUri, 0, newNamespaceUri, 0, namespaceEnd); } namespacePrefix = newNamespacePrefix; namespaceUri = newNamespaceUri; if( ! allStringsInterned ) { final int[] newNamespacePrefixHash = new int[newSize]; if(namespacePrefixHash != null) { System.arraycopy( namespacePrefixHash, 0, newNamespacePrefixHash, 0, namespaceEnd); } namespacePrefixHash = newNamespacePrefixHash; } //prefixesSize = newSize; // //assert nsPrefixes.length > size && nsPrefixes.length == newSize } } /** * simplistic implementation of hash function that has constant * time to compute - so it also means diminishing hash quality for long strings * but for XML parsing it should be good enough ... */ protected static final int fastHash( char ch[], int off, int len ) { if(len == 0) return 0; //assert len >0 int hash = ch[off]; // hash at beginning //try { hash = (hash << 7) + ch[ off + len - 1 ]; // hash at the end //} catch(ArrayIndexOutOfBoundsException aie) { // aie.printStackTrace(); //should never happen ... // throw new RuntimeException("this is violation of pre-condition"); //} if(len > 16) hash = (hash << 7) + ch[ off + (len / 4)]; // 1/4 from beginning if(len > 8) hash = (hash << 7) + ch[ off + (len / 2)]; // 1/2 of string size ... // notice that hash is at most done 3 times <<7 so shifted by 21 bits 8 bit value // so max result == 29 bits so it is quite just below 31 bits for long (2^32) ... //assert hash >= 0; return hash; } // entity replacement stack protected int entityEnd; protected String entityName[]; protected char[] entityNameBuf[]; protected String entityReplacement[]; protected char[] entityReplacementBuf[]; protected int entityNameHash[]; protected void ensureEntityCapacity() { final int entitySize = entityReplacementBuf != null ? entityReplacementBuf.length : 0; if(entityEnd >= entitySize) { final int newSize = entityEnd > 7 ? 2 * entityEnd : 8; // = lucky 7 + 1 //25 if(TRACE_SIZING) { System.err.println("TRACE_SIZING entitySize "+entitySize+" ==> "+newSize); } final String[] newEntityName = new String[newSize]; final char[] newEntityNameBuf[] = new char[newSize][]; final String[] newEntityReplacement = new String[newSize]; final char[] newEntityReplacementBuf[] = new char[newSize][]; if(entityName != null) { System.arraycopy(entityName, 0, newEntityName, 0, entityEnd); System.arraycopy(entityNameBuf, 0, newEntityNameBuf, 0, entityEnd); System.arraycopy(entityReplacement, 0, newEntityReplacement, 0, entityEnd); System.arraycopy(entityReplacementBuf, 0, newEntityReplacementBuf, 0, entityEnd); } entityName = newEntityName; entityNameBuf = newEntityNameBuf; entityReplacement = newEntityReplacement; entityReplacementBuf = newEntityReplacementBuf; if( ! allStringsInterned ) { final int[] newEntityNameHash = new int[newSize]; if(entityNameHash != null) { System.arraycopy(entityNameHash, 0, newEntityNameHash, 0, entityEnd); } entityNameHash = newEntityNameHash; } } } protected void reset() { location = null; lineNumber = 1; columnNumber = 0; seenRoot = false; reachedEnd = false; eventType = START_DOCUMENT; emptyElementTag = false; depth = 0; attributeCount = 0; namespaceEnd = 0; entityEnd = 0; reader = null; inputEncoding = null; preventBufferCompaction = false; bufAbsoluteStart = 0; bufEnd = bufStart = 0; pos = posStart = posEnd = 0; pcEnd = pcStart = 0; usePC = false; seenStartTag = false; seenEndTag = false; pastEndTag = false; seenAmpersand = false; seenMarkup = false; seenDocdecl = false; xmlDeclVersion = null; xmlDeclStandalone = null; xmlDeclContent = null; resetStringCache(); } public MXParser() { } /** * Method setFeature * * @param name a String * @param state a boolean * * @throws XmlPullParserException * */ public void setFeature(String name, boolean state) throws XmlPullParserException { if(name == null) throw new IllegalArgumentException("feature name should not be null"); if(FEATURE_PROCESS_NAMESPACES.equals(name)) { if(eventType != START_DOCUMENT) throw new XmlPullParserException( "namespace processing feature can only be changed before parsing", this, null); processNamespaces = state; // } else if(FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) { // if(type != START_DOCUMENT) throw new XmlPullParserException( // "namespace reporting feature can only be changed before parsing", this, null); // reportNsAttribs = state; } else if(FEATURE_NAMES_INTERNED.equals(name)) { if(state != false) { throw new XmlPullParserException( "interning names in this implementation is not supported"); } } else if(FEATURE_PROCESS_DOCDECL.equals(name)) { if(state != false) { throw new XmlPullParserException( "processing DOCDECL is not supported"); } //} else if(REPORT_DOCDECL.equals(name)) { // paramNotifyDoctype = state; } else if(FEATURE_XML_ROUNDTRIP.equals(name)) { //if(state == false) { // throw new XmlPullParserException( // "roundtrip feature can not be switched off"); //} roundtripSupported = state; } else { throw new XmlPullParserException("unsupporte feature "+name); } } /** Unknown properties are always returned as false */ public boolean getFeature(String name) { if(name == null) throw new IllegalArgumentException("feature name should not be nulll"); if(FEATURE_PROCESS_NAMESPACES.equals(name)) { return processNamespaces; // } else if(FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) { // return reportNsAttribs; } else if(FEATURE_NAMES_INTERNED.equals(name)) { return false; } else if(FEATURE_PROCESS_DOCDECL.equals(name)) { return false; //} else if(REPORT_DOCDECL.equals(name)) { // return paramNotifyDoctype; } else if(FEATURE_XML_ROUNDTRIP.equals(name)) { //return true; return roundtripSupported; } else if( REPORT_NAMESPACE_PREFIXES.equals( name ) ) { return processNamespaces; } return false; } public void setProperty(String name, Object value) throws XmlPullParserException { if(PROPERTY_LOCATION.equals(name)) { location = (String) value; } else { throw new XmlPullParserException("unsupported property: '"+name+"'"); } } public Object getProperty(String name) { if(name == null) throw new IllegalArgumentException("property name should not be nulll"); if(PROPERTY_XMLDECL_VERSION.equals(name)) { return xmlDeclVersion; } else if(PROPERTY_XMLDECL_STANDALONE.equals(name)) { return xmlDeclStandalone; } else if(PROPERTY_XMLDECL_CONTENT.equals(name)) { return xmlDeclContent; } else if(PROPERTY_LOCATION.equals(name)) { return location; } return null; } public void setInput(Reader in) throws XmlPullParserException { reset(); reader = in; } public void setInput(java.io.InputStream inputStream, String inputEncoding) throws XmlPullParserException { if(inputStream == null) { throw new IllegalArgumentException("input stream can not be null"); } Reader reader; try { if(inputEncoding != null) { reader = ReaderFactory.newReader(inputStream, inputEncoding); } else { reader = ReaderFactory.newXmlReader(inputStream); } } catch (UnsupportedEncodingException une) { throw new XmlPullParserException( "could not create reader for encoding "+inputEncoding+" : "+une, this, une); } catch ( IOException e ) { throw new XmlPullParserException( "could not create reader : "+e, this, e); } setInput(reader); //must be here as reset() was called in setInput() and has set this.inputEncoding to null ... this.inputEncoding = inputEncoding; } public String getInputEncoding() { return inputEncoding; } public void defineEntityReplacementText(String entityName, String replacementText) throws XmlPullParserException { // throw new XmlPullParserException("not allowed"); //protected char[] entityReplacement[]; ensureEntityCapacity(); // this is to make sure that if interning works we will take advantage of it ... this.entityName[entityEnd] = newString(entityName.toCharArray(), 0, entityName.length()); entityNameBuf[entityEnd] = entityName.toCharArray(); entityReplacement[entityEnd] = replacementText; entityReplacementBuf[entityEnd] = replacementText.toCharArray(); if(!allStringsInterned) { entityNameHash[ entityEnd ] = fastHash(entityNameBuf[entityEnd], 0, entityNameBuf[entityEnd].length); } ++entityEnd; //TODO disallow < or & in entity replacement text (or ]]>???) // TOOD keepEntityNormalizedForAttributeValue cached as well ... } public int getNamespaceCount(int depth) throws XmlPullParserException { if(processNamespaces == false || depth == 0) { return 0; } //int maxDepth = eventType == END_TAG ? this.depth + 1 : this.depth; //if(depth < 0 || depth > maxDepth) throw new IllegalArgumentException( if(depth < 0 || depth > this.depth) throw new IllegalArgumentException( "napespace count mayt be for depth 0.."+this.depth+" not "+depth); return elNamespaceCount[ depth ]; } public String getNamespacePrefix(int pos) throws XmlPullParserException { //int end = eventType == END_TAG ? elNamespaceCount[ depth + 1 ] : namespaceEnd; //if(pos < end) { if(pos < namespaceEnd) { return namespacePrefix[ pos ]; } else { throw new XmlPullParserException( "position "+pos+" exceeded number of available namespaces "+namespaceEnd); } } public String getNamespaceUri(int pos) throws XmlPullParserException { //int end = eventType == END_TAG ? elNamespaceCount[ depth + 1 ] : namespaceEnd; //if(pos < end) { if(pos < namespaceEnd) { return namespaceUri[ pos ]; } else { throw new XmlPullParserException( "position "+pos+" exceedded number of available namespaces "+namespaceEnd); } } public String getNamespace( String prefix ) //throws XmlPullParserException { //int count = namespaceCount[ depth ]; if(prefix != null) { for( int i = namespaceEnd -1; i >= 0; i--) { if( prefix.equals( namespacePrefix[ i ] ) ) { return namespaceUri[ i ]; } } if("xml".equals( prefix )) { return XML_URI; } else if("xmlns".equals( prefix )) { return XMLNS_URI; } } else { for( int i = namespaceEnd -1; i >= 0; i--) { if( namespacePrefix[ i ] == null) { //"") { //null ) { //TODO check FIXME Alek return namespaceUri[ i ]; } } } return null; } public int getDepth() { return depth; } private static int findFragment(int bufMinPos, char[] b, int start, int end) { //System.err.println("bufStart="+bufStart+" b="+printable(new String(b, start, end - start))+" start="+start+" end="+end); if(start < bufMinPos) { start = bufMinPos; if(start > end) start = end; return start; } if(end - start > 65) { start = end - 10; // try to find good location } int i = start + 1; while(--i > bufMinPos) { if((end - i) > 65) break; final char c = b[i]; if(c == '<' && (start - i) > 10) break; } return i; } /** * Return string describing current position of parsers as * text 'STATE [seen %s...] @line:column'. */ public String getPositionDescription () { String fragment = null; if(posStart <= pos) { final int start = findFragment(0, buf, posStart, pos); //System.err.println("start="+start); if(start < pos) { fragment = new String(buf, start, pos - start); } if(bufAbsoluteStart > 0 || start > 0) fragment = "..." + fragment; } // return " at line "+tokenizerPosRow // +" and column "+(tokenizerPosCol-1) // +(fragment != null ? " seen "+printable(fragment)+"..." : ""); return " "+TYPES[ eventType ] + (fragment != null ? " seen "+printable(fragment)+"..." : "") +" "+(location != null ? location : "") +"@"+getLineNumber()+":"+getColumnNumber(); } public int getLineNumber() { return lineNumber; } public int getColumnNumber() { return columnNumber; } public boolean isWhitespace() throws XmlPullParserException { if(eventType == TEXT || eventType == CDSECT) { if(usePC) { for (int i = pcStart; i = 0; i--) { // if( prefix.equals( namespacePrefix[ i ] ) ) { // return namespaceUri[ i ]; // } // } // } else { // for( int i = namespaceEnd -1; i >= 0; i--) { // if( namespacePrefix[ i ] == null ) { // return namespaceUri[ i ]; // } // } // // } // return ""; } public String getName() { if(eventType == START_TAG) { //return elName[ depth - 1 ] ; return elName[ depth ] ; } else if(eventType == END_TAG) { return elName[ depth ] ; } else if(eventType == ENTITY_REF) { if(entityRefName == null) { entityRefName = newString(buf, posStart, posEnd - posStart); } return entityRefName; } else { return null; } } public String getPrefix() { if(eventType == START_TAG) { //return elPrefix[ depth - 1 ] ; return elPrefix[ depth ] ; } else if(eventType == END_TAG) { return elPrefix[ depth ] ; } return null; // if(eventType != START_TAG && eventType != END_TAG) return null; // int maxDepth = eventType == END_TAG ? depth : depth - 1; // return elPrefix[ maxDepth ]; } public boolean isEmptyElementTag() throws XmlPullParserException { if(eventType != START_TAG) throw new XmlPullParserException( "parser must be on START_TAG to check for empty element", this, null); return emptyElementTag; } public int getAttributeCount() { if(eventType != START_TAG) return -1; return attributeCount; } public String getAttributeNamespace(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(processNamespaces == false) return NO_NAMESPACE; if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return attributeUri[ index ]; } public String getAttributeName(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return attributeName[ index ]; } public String getAttributePrefix(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(processNamespaces == false) return null; if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return attributePrefix[ index ]; } public String getAttributeType(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return "CDATA"; } public boolean isAttributeDefault(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return false; } public String getAttributeValue(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return attributeValue[ index ]; } public String getAttributeValue(String namespace, String name) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"+getPositionDescription()); if(name == null) { throw new IllegalArgumentException("attribute name can not be null"); } // TODO make check if namespace is interned!!! etc. for names!!! if(processNamespaces) { if(namespace == null) { namespace = ""; } for(int i = 0; i < attributeCount; ++i) { if((namespace == attributeUri[ i ] || namespace.equals(attributeUri[ i ]) ) //(namespace != null && namespace.equals(attributeUri[ i ])) // taking advantage of String.intern() && name.equals(attributeName[ i ]) ) { return attributeValue[i]; } } } else { if(namespace != null && namespace.length() == 0) { namespace = null; } if(namespace != null) throw new IllegalArgumentException( "when namespaces processing is disabled attribute namespace must be null"); for(int i = 0; i < attributeCount; ++i) { if(name.equals(attributeName[i])) { return attributeValue[i]; } } } return null; } public int getEventType() throws XmlPullParserException { return eventType; } public void require(int type, String namespace, String name) throws XmlPullParserException, IOException { if(processNamespaces == false && namespace != null) { throw new XmlPullParserException( "processing namespaces must be enabled on parser (or factory)"+ " to have possible namespaces delcared on elements" +(" (postion:"+ getPositionDescription())+")"); } if (type != getEventType() || (namespace != null && !namespace.equals (getNamespace())) || (name != null && !name.equals (getName ())) ) { throw new XmlPullParserException ( "expected event "+TYPES[ type ] +(name != null ? " with name '"+name+"'" : "") +(namespace != null && name != null ? " and" : "") +(namespace != null ? " with namespace '"+namespace+"'" : "") +" but got" +(type != getEventType() ? " "+TYPES[ getEventType() ] : "") +(name != null && getName() != null && !name.equals (getName ()) ? " name '"+getName()+"'" : "") +(namespace != null && name != null && getName() != null && !name.equals (getName ()) && getNamespace() != null && !namespace.equals (getNamespace()) ? " and" : "") +(namespace != null && getNamespace() != null && !namespace.equals (getNamespace()) ? " namespace '"+getNamespace()+"'" : "") +(" (postion:"+ getPositionDescription())+")"); } } /** * Skip sub tree that is currently porser positioned on. *
NOTE: parser must be on START_TAG and when funtion returns * parser will be positioned on corresponding END_TAG */ public void skipSubTree() throws XmlPullParserException, IOException { require(START_TAG, null, null); int level = 1; while(level > 0) { int eventType = next(); if(eventType == END_TAG) { --level; } else if(eventType == START_TAG) { ++level; } } } // public String readText() throws XmlPullParserException, IOException // { // if (getEventType() != TEXT) return ""; // String result = getText(); // next(); // return result; // } public String nextText() throws XmlPullParserException, IOException { // String result = null; // boolean onStartTag = false; // if(eventType == START_TAG) { // onStartTag = true; // next(); // } // if(eventType == TEXT) { // result = getText(); // next(); // } else if(onStartTag && eventType == END_TAG) { // result = ""; // } else { // throw new XmlPullParserException( // "parser must be on START_TAG or TEXT to read text", this, null); // } // if(eventType != END_TAG) { // throw new XmlPullParserException( // "event TEXT it must be immediately followed by END_TAG", this, null); // } // return result; if(getEventType() != START_TAG) { throw new XmlPullParserException( "parser must be on START_TAG to read next text", this, null); } int eventType = next(); if(eventType == TEXT) { final String result = getText(); eventType = next(); if(eventType != END_TAG) { throw new XmlPullParserException( "TEXT must be immediately followed by END_TAG and not " +TYPES[ getEventType() ], this, null); } return result; } else if(eventType == END_TAG) { return ""; } else { throw new XmlPullParserException( "parser must be on START_TAG or TEXT to read text", this, null); } } public int nextTag() throws XmlPullParserException, IOException { next(); if(eventType == TEXT && isWhitespace()) { // skip whitespace next(); } if (eventType != START_TAG && eventType != END_TAG) { throw new XmlPullParserException("expected START_TAG or END_TAG not " +TYPES[ getEventType() ], this, null); } return eventType; } public int next() throws XmlPullParserException, IOException { tokenize = false; return nextImpl(); } public int nextToken() throws XmlPullParserException, IOException { tokenize = true; return nextImpl(); } protected int nextImpl() throws XmlPullParserException, IOException { text = null; pcEnd = pcStart = 0; usePC = false; bufStart = posEnd; if(pastEndTag) { pastEndTag = false; --depth; namespaceEnd = elNamespaceCount[ depth ]; // less namespaces available } if(emptyElementTag) { emptyElementTag = false; pastEndTag = true; return eventType = END_TAG; } // [1] document ::= prolog element Misc* if(depth > 0) { if(seenStartTag) { seenStartTag = false; return eventType = parseStartTag(); } if(seenEndTag) { seenEndTag = false; return eventType = parseEndTag(); } // ASSUMPTION: we are _on_ first character of content or markup!!!! // [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* char ch; if(seenMarkup) { // we have read ahead ... seenMarkup = false; ch = '<'; } else if(seenAmpersand) { seenAmpersand = false; ch = '&'; } else { ch = more(); } posStart = pos - 1; // VERY IMPORTANT: this is correct start of event!!! // when true there is some potential event TEXT to return - keep gathering boolean hadCharData = false; // when true TEXT data is not continuous (like ) and requires PC merging boolean needsMerging = false; MAIN_LOOP: while(true) { // work on MARKUP if(ch == '<') { if(hadCharData) { //posEnd = pos - 1; if(tokenize) { seenMarkup = true; return eventType = TEXT; } } ch = more(); if(ch == '/') { if(!tokenize && hadCharData) { seenEndTag = true; //posEnd = pos - 2; return eventType = TEXT; } return eventType = parseEndTag(); } else if(ch == '!') { ch = more(); if(ch == '-') { // note: if(tokenize == false) posStart/End is NOT changed!!!! parseComment(); if(tokenize) return eventType = COMMENT; if( !usePC && hadCharData ) { needsMerging = true; } else { posStart = pos; //completely ignore comment } } else if(ch == '[') { //posEnd = pos - 3; // must remember previous posStart/End as it merges with content of CDATA //int oldStart = posStart + bufAbsoluteStart; //int oldEnd = posEnd + bufAbsoluteStart; parseCDSect(hadCharData); if(tokenize) return eventType = CDSECT; final int cdStart = posStart; final int cdEnd = posEnd; final int cdLen = cdEnd - cdStart; if(cdLen > 0) { // was there anything inside CDATA section? hadCharData = true; if(!usePC) { needsMerging = true; } } // posStart = oldStart; // posEnd = oldEnd; // if(cdLen > 0) { // was there anything inside CDATA section? // if(hadCharData) { // // do merging if there was anything in CDSect!!!! // // if(!usePC) { // // // posEnd is correct already!!! // // if(posEnd > posStart) { // // joinPC(); // // } else { // // usePC = true; // // pcStart = pcEnd = 0; // // } // // } // // if(pcEnd + cdLen >= pc.length) ensurePC(pcEnd + cdLen); // // // copy [cdStart..cdEnd) into PC // // System.arraycopy(buf, cdStart, pc, pcEnd, cdLen); // // pcEnd += cdLen; // if(!usePC) { // needsMerging = true; // posStart = cdStart; // posEnd = cdEnd; // } // } else { // if(!usePC) { // needsMerging = true; // posStart = cdStart; // posEnd = cdEnd; // hadCharData = true; // } // } // //hadCharData = true; // } else { // if( !usePC && hadCharData ) { // needsMerging = true; // } // } } else { throw new XmlPullParserException( "unexpected character in markup "+printable(ch), this, null); } } else if(ch == '?') { parsePI(); if(tokenize) return eventType = PROCESSING_INSTRUCTION; if( !usePC && hadCharData ) { needsMerging = true; } else { posStart = pos; //completely ignore PI } } else if( isNameStartChar(ch) ) { if(!tokenize && hadCharData) { seenStartTag = true; //posEnd = pos - 2; return eventType = TEXT; } return eventType = parseStartTag(); } else { throw new XmlPullParserException( "unexpected character in markup "+printable(ch), this, null); } // do content comapctation if it makes sense!!!! } else if(ch == '&') { // work on ENTITTY //posEnd = pos - 1; if(tokenize && hadCharData) { seenAmpersand = true; return eventType = TEXT; } final int oldStart = posStart + bufAbsoluteStart; final int oldEnd = posEnd + bufAbsoluteStart; final char[] resolvedEntity = parseEntityRef(); if(tokenize) return eventType = ENTITY_REF; // check if replacement text can be resolved !!! if(resolvedEntity == null) { if(entityRefName == null) { entityRefName = newString(buf, posStart, posEnd - posStart); } throw new XmlPullParserException( "could not resolve entity named '"+printable(entityRefName)+"'", this, null); } //int entStart = posStart; //int entEnd = posEnd; posStart = oldStart - bufAbsoluteStart; posEnd = oldEnd - bufAbsoluteStart; if(!usePC) { if(hadCharData) { joinPC(); // posEnd is already set correctly!!! needsMerging = false; } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; // write into PC replacement text - do merge for replacement text!!!! for (int i = 0; i < resolvedEntity.length; i++) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = resolvedEntity[ i ]; } hadCharData = true; //assert needsMerging == false; } else { if(needsMerging) { //assert usePC == false; joinPC(); // posEnd is already set correctly!!! //posStart = pos - 1; needsMerging = false; } //no MARKUP not ENTITIES so work on character data ... // [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) hadCharData = true; boolean normalizedCR = false; final boolean normalizeInput = tokenize == false || roundtripSupported == false; // use loop locality here!!!! boolean seenBracket = false; boolean seenBracketBracket = false; do { // check that ]]> does not show in if(ch == ']') { if(seenBracket) { seenBracketBracket = true; } else { seenBracket = true; } } else if(seenBracketBracket && ch == '>') { throw new XmlPullParserException( "characters ]]> are not allowed in content", this, null); } else { if(seenBracket) { seenBracketBracket = seenBracket = false; } // assert seenTwoBrackets == seenBracket == false; } if(normalizeInput) { // deal with normalization issues ... if(ch == '\r') { normalizedCR = true; posEnd = pos -1; // posEnd is already set if(!usePC) { if(posEnd > posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { // if(!usePC) { joinPC(); } else { if(pcEnd >= pc.length) ensurePC(); } if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } ch = more(); } while(ch != '<' && ch != '&'); posEnd = pos - 1; continue MAIN_LOOP; // skip ch = more() from below - we are already ahead ... } ch = more(); } // endless while(true) } else { if(seenRoot) { return parseEpilog(); } else { return parseProlog(); } } } protected int parseProlog() throws XmlPullParserException, IOException { // [2] prolog: ::= XMLDecl? Misc* (doctypedecl Misc*)? and look for [39] element char ch; if(seenMarkup) { ch = buf[ pos - 1 ]; } else { ch = more(); } if(eventType == START_DOCUMENT) { // bootstrap parsing with getting first character input! // deal with BOM // detect BOM and crop it (Unicode int Order Mark) if(ch == '\uFFFE') { throw new XmlPullParserException( "first character in input was UNICODE noncharacter (0xFFFE)"+ "- input requires int swapping", this, null); } if(ch == '\uFEFF') { // skipping UNICODE int Order Mark (so called BOM) ch = more(); } } seenMarkup = false; boolean gotS = false; posStart = pos - 1; final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; boolean normalizedCR = false; while(true) { // deal with Misc // [27] Misc ::= Comment | PI | S // deal with docdecl --> mark it! // else parseStartTag seen <[^/] if(ch == '<') { if(gotS && tokenize) { posEnd = pos - 1; seenMarkup = true; return eventType = IGNORABLE_WHITESPACE; } ch = more(); if(ch == '?') { // check if it is 'xml' // deal with XMLDecl boolean isXMLDecl = parsePI(); if(tokenize) { if (isXMLDecl) { return eventType = START_DOCUMENT; } return eventType = PROCESSING_INSTRUCTION; } } else if(ch == '!') { ch = more(); if(ch == 'D') { if(seenDocdecl) { throw new XmlPullParserException( "only one docdecl allowed in XML document", this, null); } seenDocdecl = true; parseDocdecl(); if(tokenize) return eventType = DOCDECL; } else if(ch == '-') { parseComment(); if(tokenize) return eventType = COMMENT; } else { throw new XmlPullParserException( "unexpected markup posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } } else { throw new XmlPullParserException( "only whitespace content allowed before start tag and not "+printable(ch), this, null); } ch = more(); } } protected int parseEpilog() throws XmlPullParserException, IOException { if(eventType == END_DOCUMENT) { throw new XmlPullParserException("already reached end of XML input", this, null); } if(reachedEnd) { return eventType = END_DOCUMENT; } boolean gotS = false; final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; boolean normalizedCR = false; try { // epilog: Misc* char ch; if(seenMarkup) { ch = buf[ pos - 1 ]; } else { ch = more(); } seenMarkup = false; posStart = pos - 1; if(!reachedEnd) { while(true) { // deal with Misc // [27] Misc ::= Comment | PI | S if(ch == '<') { if(gotS && tokenize) { posEnd = pos - 1; seenMarkup = true; return eventType = IGNORABLE_WHITESPACE; } ch = more(); if(reachedEnd) { break; } if(ch == '?') { // check if it is 'xml' // deal with XMLDecl parsePI(); if(tokenize) return eventType = PROCESSING_INSTRUCTION; } else if(ch == '!') { ch = more(); if(reachedEnd) { break; } if(ch == 'D') { parseDocdecl(); //FIXME if(tokenize) return eventType = DOCDECL; } else if(ch == '-') { parseComment(); if(tokenize) return eventType = COMMENT; } else { throw new XmlPullParserException( "unexpected markup posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } } else { throw new XmlPullParserException( "in epilog non whitespace content is not allowed but got "+printable(ch), this, null); } ch = more(); if(reachedEnd) { break; } } } // throw Exception("unexpected content in epilog // catch EOFException return END_DOCUMENT //try { } catch(EOFException ex) { reachedEnd = true; } if(reachedEnd) { if(tokenize && gotS) { posEnd = pos; // well - this is LAST available character pos return eventType = IGNORABLE_WHITESPACE; } return eventType = END_DOCUMENT; } else { throw new XmlPullParserException("internal error in parseEpilog"); } } public int parseEndTag() throws XmlPullParserException, IOException { //ASSUMPTION ch is past "' char ch = more(); if(!isNameStartChar(ch)) { throw new XmlPullParserException( "expected name start and not "+printable(ch), this, null); } posStart = pos - 3; final int nameStart = pos - 1 + bufAbsoluteStart; do { ch = more(); } while(isNameChar(ch)); // now we go one level down -- do checks //--depth; //FIXME // check that end tag name is the same as start tag //String name = new String(buf, nameStart - bufAbsoluteStart, // (pos - 1) - (nameStart - bufAbsoluteStart)); //int last = pos - 1; int off = nameStart - bufAbsoluteStart; //final int len = last - off; final int len = (pos - 1) - off; final char[] cbuf = elRawName[depth]; if(elRawNameEnd[depth] != len) { // construct strings for exception final String startname = new String(cbuf, 0, elRawNameEnd[depth]); final String endname = new String(buf, off, len); throw new XmlPullParserException( "end tag name must match start tag name <"+startname+">" +" from line "+elRawNameLine[depth], this, null); } for (int i = 0; i < len; i++) { if(buf[off++] != cbuf[i]) { // construct strings for exception final String startname = new String(cbuf, 0, len); final String endname = new String(buf, off - i - 1, len); throw new XmlPullParserException( "end tag name must be the same as start tag <"+startname+">" +" from line "+elRawNameLine[depth], this, null); } } while(isS(ch)) { ch = more(); } // skip additional white spaces if(ch != '>') { throw new XmlPullParserException( "expected > to finsh end tag not "+printable(ch) +" from line "+elRawNameLine[depth], this, null); } //namespaceEnd = elNamespaceCount[ depth ]; //FIXME posEnd = pos; pastEndTag = true; return eventType = END_TAG; } public int parseStartTag() throws XmlPullParserException, IOException { //ASSUMPTION ch is past ' // [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' ++depth; //FIXME posStart = pos - 2; emptyElementTag = false; attributeCount = 0; // retrieve name final int nameStart = pos - 1 + bufAbsoluteStart; int colonPos = -1; char ch = buf[ pos - 1]; if(ch == ':' && processNamespaces) throw new XmlPullParserException( "when namespaces processing enabled colon can not be at element name start", this, null); while(true) { ch = more(); if(!isNameChar(ch)) break; if(ch == ':' && processNamespaces) { if(colonPos != -1) throw new XmlPullParserException( "only one colon is allowed in name of element when namespaces are enabled", this, null); colonPos = pos - 1 + bufAbsoluteStart; } } // retrieve name ensureElementsCapacity(); //TODO check for efficient interning and then use elRawNameInterned!!!! int elLen = (pos - 1) - (nameStart - bufAbsoluteStart); if(elRawName[ depth ] == null || elRawName[ depth ].length < elLen) { elRawName[ depth ] = new char[ 2 * elLen ]; } System.arraycopy(buf, nameStart - bufAbsoluteStart, elRawName[ depth ], 0, elLen); elRawNameEnd[ depth ] = elLen; elRawNameLine[ depth ] = lineNumber; String name = null; // work on prefixes and namespace URI String prefix = null; if(processNamespaces) { if(colonPos != -1) { prefix = elPrefix[ depth ] = newString(buf, nameStart - bufAbsoluteStart, colonPos - nameStart); name = elName[ depth ] = newString(buf, colonPos + 1 - bufAbsoluteStart, //(pos -1) - (colonPos + 1)); pos - 2 - (colonPos - bufAbsoluteStart)); } else { prefix = elPrefix[ depth ] = null; name = elName[ depth ] = newString(buf, nameStart - bufAbsoluteStart, elLen); } } else { name = elName[ depth ] = newString(buf, nameStart - bufAbsoluteStart, elLen); } while(true) { while(isS(ch)) { ch = more(); } // skip additional white spaces if(ch == '>') { break; } else if(ch == '/') { if(emptyElementTag) throw new XmlPullParserException( "repeated / in tag declaration", this, null); emptyElementTag = true; ch = more(); if(ch != '>') throw new XmlPullParserException( "expected > to end empty tag not "+printable(ch), this, null); break; } else if(isNameStartChar(ch)) { ch = parseAttribute(); ch = more(); continue; } else { throw new XmlPullParserException( "start tag unexpected character "+printable(ch), this, null); } //ch = more(); // skip space } // now when namespaces were declared we can resolve them if(processNamespaces) { String uri = getNamespace(prefix); if(uri == null) { if(prefix == null) { // no prefix and no uri => use default namespace uri = NO_NAMESPACE; } else { throw new XmlPullParserException( "could not determine namespace bound to element prefix "+prefix, this, null); } } elUri[ depth ] = uri; //String uri = getNamespace(prefix); //if(uri == null && prefix == null) { // no prefix and no uri => use default namespace // uri = ""; //} // resolve attribute namespaces for (int i = 0; i < attributeCount; i++) { final String attrPrefix = attributePrefix[ i ]; if(attrPrefix != null) { final String attrUri = getNamespace(attrPrefix); if(attrUri == null) { throw new XmlPullParserException( "could not determine namespace bound to attribute prefix "+attrPrefix, this, null); } attributeUri[ i ] = attrUri; } else { attributeUri[ i ] = NO_NAMESPACE; } } //TODO //[ WFC: Unique Att Spec ] // check namespaced attribute uniqueness contraint!!! for (int i = 1; i < attributeCount; i++) { for (int j = 0; j < i; j++) { if( attributeUri[j] == attributeUri[i] && (allStringsInterned && attributeName[j].equals(attributeName[i]) || (!allStringsInterned && attributeNameHash[ j ] == attributeNameHash[ i ] && attributeName[j].equals(attributeName[i])) ) ) { // prepare data for nice error messgae? String attr1 = attributeName[j]; if(attributeUri[j] != null) attr1 = attributeUri[j]+":"+attr1; String attr2 = attributeName[i]; if(attributeUri[i] != null) attr2 = attributeUri[i]+":"+attr2; throw new XmlPullParserException( "duplicated attributes "+attr1+" and "+attr2, this, null); } } } } else { // ! processNamespaces //[ WFC: Unique Att Spec ] // check raw attribute uniqueness contraint!!! for (int i = 1; i < attributeCount; i++) { for (int j = 0; j < i; j++) { if((allStringsInterned && attributeName[j].equals(attributeName[i]) || (!allStringsInterned && attributeNameHash[ j ] == attributeNameHash[ i ] && attributeName[j].equals(attributeName[i])) ) ) { // prepare data for nice error messgae? final String attr1 = attributeName[j]; final String attr2 = attributeName[i]; throw new XmlPullParserException( "duplicated attributes "+attr1+" and "+attr2, this, null); } } } } elNamespaceCount[ depth ] = namespaceEnd; posEnd = pos; return eventType = START_TAG; } protected char parseAttribute() throws XmlPullParserException, IOException { // parse attribute // [41] Attribute ::= Name Eq AttValue // [WFC: No External Entity References] // [WFC: No < in Attribute Values] final int prevPosStart = posStart + bufAbsoluteStart; final int nameStart = pos - 1 + bufAbsoluteStart; int colonPos = -1; char ch = buf[ pos - 1 ]; if(ch == ':' && processNamespaces) throw new XmlPullParserException( "when namespaces processing enabled colon can not be at attribute name start", this, null); boolean startsWithXmlns = processNamespaces && ch == 'x'; int xmlnsPos = 0; ch = more(); while(isNameChar(ch)) { if(processNamespaces) { if(startsWithXmlns && xmlnsPos < 5) { ++xmlnsPos; if(xmlnsPos == 1) { if(ch != 'm') startsWithXmlns = false; } else if(xmlnsPos == 2) { if(ch != 'l') startsWithXmlns = false; } else if(xmlnsPos == 3) { if(ch != 'n') startsWithXmlns = false; } else if(xmlnsPos == 4) { if(ch != 's') startsWithXmlns = false; } else if(xmlnsPos == 5) { if(ch != ':') throw new XmlPullParserException( "after xmlns in attribute name must be colon" +"when namespaces are enabled", this, null); //colonPos = pos - 1 + bufAbsoluteStart; } } if(ch == ':') { if(colonPos != -1) throw new XmlPullParserException( "only one colon is allowed in attribute name" +" when namespaces are enabled", this, null); colonPos = pos - 1 + bufAbsoluteStart; } } ch = more(); } ensureAttributesCapacity(attributeCount); // --- start processing attributes String name = null; String prefix = null; // work on prefixes and namespace URI if(processNamespaces) { if(xmlnsPos < 4) startsWithXmlns = false; if(startsWithXmlns) { if(colonPos != -1) { //prefix = attributePrefix[ attributeCount ] = null; final int nameLen = pos - 2 - (colonPos - bufAbsoluteStart); if(nameLen == 0) { throw new XmlPullParserException( "namespace prefix is required after xmlns: " +" when namespaces are enabled", this, null); } name = //attributeName[ attributeCount ] = newString(buf, colonPos - bufAbsoluteStart + 1, nameLen); //pos - 1 - (colonPos + 1 - bufAbsoluteStart) } } else { if(colonPos != -1) { int prefixLen = colonPos - nameStart; prefix = attributePrefix[ attributeCount ] = newString(buf, nameStart - bufAbsoluteStart,prefixLen); //colonPos - (nameStart - bufAbsoluteStart)); int nameLen = pos - 2 - (colonPos - bufAbsoluteStart); name = attributeName[ attributeCount ] = newString(buf, colonPos - bufAbsoluteStart + 1, nameLen); //pos - 1 - (colonPos + 1 - bufAbsoluteStart)); //name.substring(0, colonPos-nameStart); } else { prefix = attributePrefix[ attributeCount ] = null; name = attributeName[ attributeCount ] = newString(buf, nameStart - bufAbsoluteStart, pos - 1 - (nameStart - bufAbsoluteStart)); } if(!allStringsInterned) { attributeNameHash[ attributeCount ] = name.hashCode(); } } } else { // retrieve name name = attributeName[ attributeCount ] = newString(buf, nameStart - bufAbsoluteStart, pos - 1 - (nameStart - bufAbsoluteStart)); ////assert name != null; if(!allStringsInterned) { attributeNameHash[ attributeCount ] = name.hashCode(); } } // [25] Eq ::= S? '=' S? while(isS(ch)) { ch = more(); } // skip additional spaces if(ch != '=') throw new XmlPullParserException( "expected = after attribute name", this, null); ch = more(); while(isS(ch)) { ch = more(); } // skip additional spaces // [10] AttValue ::= '"' ([^<&"] | Reference)* '"' // | "'" ([^<&'] | Reference)* "'" final char delimit = ch; if(delimit != '"' && delimit != '\'') throw new XmlPullParserException( "attribute value must start with quotation or apostrophe not " +printable(delimit), this, null); // parse until delimit or < and resolve Reference //[67] Reference ::= EntityRef | CharRef //int valueStart = pos + bufAbsoluteStart; boolean normalizedCR = false; usePC = false; pcStart = pcEnd; posStart = pos; while(true) { ch = more(); if(ch == delimit) { break; } if(ch == '<') { throw new XmlPullParserException( "markup not allowed inside attribute value - illegal < ", this, null); } if(ch == '&') { // extractEntityRef posEnd = pos - 1; if(!usePC) { final boolean hadCharData = posEnd > posStart; if(hadCharData) { // posEnd is already set correctly!!! joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; final char[] resolvedEntity = parseEntityRef(); // check if replacement text can be resolved !!! if(resolvedEntity == null) { if(entityRefName == null) { entityRefName = newString(buf, posStart, posEnd - posStart); } throw new XmlPullParserException( "could not resolve entity named '"+printable(entityRefName)+"'", this, null); } // write into PC replacement text - do merge for replacement text!!!! for (int i = 0; i < resolvedEntity.length; i++) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = resolvedEntity[ i ]; } } else if(ch == '\t' || ch == '\n' || ch == '\r') { // do attribute value normalization // as described in http://www.w3.org/TR/REC-xml#AVNormalize // TODO add test for it form spec ... // handle EOL normalization ... if(!usePC) { posEnd = pos - 1; if(posEnd > posStart) { joinPC(); } else { usePC = true; pcEnd = pcStart = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); if(ch != '\n' || !normalizedCR) { pc[pcEnd++] = ' '; //'\n'; } } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } } normalizedCR = ch == '\r'; } if(processNamespaces && startsWithXmlns) { String ns = null; if(!usePC) { ns = newStringIntern(buf, posStart, pos - 1 - posStart); } else { ns = newStringIntern(pc, pcStart, pcEnd - pcStart); } ensureNamespacesCapacity(namespaceEnd); int prefixHash = -1; if(colonPos != -1) { if(ns.length() == 0) { throw new XmlPullParserException( "non-default namespace can not be declared to be empty string", this, null); } // declare new namespace namespacePrefix[ namespaceEnd ] = name; if(!allStringsInterned) { prefixHash = namespacePrefixHash[ namespaceEnd ] = name.hashCode(); } } else { // declare new default namespace... namespacePrefix[ namespaceEnd ] = null; //""; //null; //TODO check FIXME Alek if(!allStringsInterned) { prefixHash = namespacePrefixHash[ namespaceEnd ] = -1; } } namespaceUri[ namespaceEnd ] = ns; // detect duplicate namespace declarations!!! final int startNs = elNamespaceCount[ depth - 1 ]; for (int i = namespaceEnd - 1; i >= startNs; --i) { if(((allStringsInterned || name == null) && namespacePrefix[ i ] == name) || (!allStringsInterned && name != null && namespacePrefixHash[ i ] == prefixHash && name.equals(namespacePrefix[ i ]) )) { final String s = name == null ? "default" : "'"+name+"'"; throw new XmlPullParserException( "duplicated namespace declaration for "+s+" prefix", this, null); } } ++namespaceEnd; } else { if(!usePC) { attributeValue[ attributeCount ] = new String(buf, posStart, pos - 1 - posStart); } else { attributeValue[ attributeCount ] = new String(pc, pcStart, pcEnd - pcStart); } ++attributeCount; } posStart = prevPosStart - bufAbsoluteStart; return ch; } protected char[] charRefOneCharBuf = new char[1]; protected char[] parseEntityRef() throws XmlPullParserException, IOException { // entity reference http://www.w3.org/TR/2000/REC-xml-20001006#NT-Reference // [67] Reference ::= EntityRef | CharRef // ASSUMPTION just after & entityRefName = null; posStart = pos; char ch = more(); if(ch == '#') { // parse character reference char charRef = 0; ch = more(); if(ch == 'x') { //encoded in hex while(true) { ch = more(); if(ch >= '0' && ch <= '9') { charRef = (char)(charRef * 16 + (ch - '0')); } else if(ch >= 'a' && ch <= 'f') { charRef = (char)(charRef * 16 + (ch - ('a' - 10))); } else if(ch >= 'A' && ch <= 'F') { charRef = (char)(charRef * 16 + (ch - ('A' - 10))); } else if(ch == ';') { break; } else { throw new XmlPullParserException( "character reference (with hex value) may not contain " +printable(ch), this, null); } } } else { // encoded in decimal while(true) { if(ch >= '0' && ch <= '9') { charRef = (char)(charRef * 10 + (ch - '0')); } else if(ch == ';') { break; } else { throw new XmlPullParserException( "character reference (with decimal value) may not contain " +printable(ch), this, null); } ch = more(); } } posEnd = pos - 1; charRefOneCharBuf[0] = charRef; if(tokenize) { text = newString(charRefOneCharBuf, 0, 1); } return charRefOneCharBuf; } else { // [68] EntityRef ::= '&' Name ';' // scan anem until ; if(!isNameStartChar(ch)) { throw new XmlPullParserException( "entity reference names can not start with character '" +printable(ch)+"'", this, null); } while(true) { ch = more(); if(ch == ';') { break; } if(!isNameChar(ch)) { throw new XmlPullParserException( "entity reference name can not contain character " +printable(ch)+"'", this, null); } } posEnd = pos - 1; // determine what name maps to final int len = posEnd - posStart; if(len == 2 && buf[posStart] == 'l' && buf[posStart+1] == 't') { if(tokenize) { text = "<"; } charRefOneCharBuf[0] = '<'; return charRefOneCharBuf; //if(paramPC || isParserTokenizing) { // if(pcEnd >= pc.length) ensurePC(); // pc[pcEnd++] = '<'; //} } else if(len == 3 && buf[posStart] == 'a' && buf[posStart+1] == 'm' && buf[posStart+2] == 'p') { if(tokenize) { text = "&"; } charRefOneCharBuf[0] = '&'; return charRefOneCharBuf; } else if(len == 2 && buf[posStart] == 'g' && buf[posStart+1] == 't') { if(tokenize) { text = ">"; } charRefOneCharBuf[0] = '>'; return charRefOneCharBuf; } else if(len == 4 && buf[posStart] == 'a' && buf[posStart+1] == 'p' && buf[posStart+2] == 'o' && buf[posStart+3] == 's') { if(tokenize) { text = "'"; } charRefOneCharBuf[0] = '\''; return charRefOneCharBuf; } else if(len == 4 && buf[posStart] == 'q' && buf[posStart+1] == 'u' && buf[posStart+2] == 'o' && buf[posStart+3] == 't') { if(tokenize) { text = "\""; } charRefOneCharBuf[0] = '"'; return charRefOneCharBuf; } else { final char[] result = lookuEntityReplacement(len); if(result != null) { return result; } } if(tokenize) text = null; return null; } } protected char[] lookuEntityReplacement(int entitNameLen) throws XmlPullParserException, IOException { if(!allStringsInterned) { final int hash = fastHash(buf, posStart, posEnd - posStart); LOOP: for (int i = entityEnd - 1; i >= 0; --i) { if(hash == entityNameHash[ i ] && entitNameLen == entityNameBuf[ i ].length) { final char[] entityBuf = entityNameBuf[ i ]; for (int j = 0; j < entitNameLen; j++) { if(buf[posStart + j] != entityBuf[j]) continue LOOP; } if(tokenize) text = entityReplacement[ i ]; return entityReplacementBuf[ i ]; } } } else { entityRefName = newString(buf, posStart, posEnd - posStart); for (int i = entityEnd - 1; i >= 0; --i) { // take advantage that interning for newStirng is enforced if(entityRefName == entityName[ i ]) { if(tokenize) text = entityReplacement[ i ]; return entityReplacementBuf[ i ]; } } } return null; } protected void parseComment() throws XmlPullParserException, IOException { // implements XML 1.0 Section 2.5 Comments //ASSUMPTION: seen ch = more(); if(seenDashDash && ch != '>') { throw new XmlPullParserException( "in comment after two dashes (--) next character must be >" +" not "+printable(ch), this, null); } if(ch == '-') { if(!seenDash) { seenDash = true; } else { seenDashDash = true; seenDash = false; } } else if(ch == '>') { if(seenDashDash) { break; // found end sequence!!!! } else { seenDashDash = false; } seenDash = false; } else { seenDash = false; } if(normalizeIgnorableWS) { if(ch == '\r') { normalizedCR = true; //posEnd = pos -1; //joinPC(); // posEnd is alreadys set if(!usePC) { posEnd = pos -1; if(posEnd > posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } } } catch(EOFException ex) { // detect EOF and create meaningful error ... throw new XmlPullParserException( "comment started on line "+curLine+" and column "+curColumn+" was not closed", this, ex); } if(tokenize) { posEnd = pos - 3; if(usePC) { pcEnd -= 2; } } } protected boolean parsePI() throws XmlPullParserException, IOException { // implements XML 1.0 Section 2.6 Processing Instructions // [16] PI ::= '' Char*)))? '?>' // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) //ASSUMPTION: seen //ch = more(); if(ch == '?') { seenQ = true; } else if(ch == '>') { if(seenQ) { break; // found end sequence!!!! } seenQ = false; } else { if(piTargetEnd == -1 && isS(ch)) { piTargetEnd = pos - 1 + bufAbsoluteStart; // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) if((piTargetEnd - piTargetStart) == 3) { if((buf[piTargetStart] == 'x' || buf[piTargetStart] == 'X') && (buf[piTargetStart+1] == 'm' || buf[piTargetStart+1] == 'M') && (buf[piTargetStart+2] == 'l' || buf[piTargetStart+2] == 'L') ) { if(piTargetStart > 3) { // posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } ch = more(); } } catch(EOFException ex) { // detect EOF and create meaningful error ... throw new XmlPullParserException( "processing instruction started on line "+curLine+" and column "+curColumn +" was not closed", this, ex); } if(piTargetEnd == -1) { piTargetEnd = pos - 2 + bufAbsoluteStart; //throw new XmlPullParserException( // "processing instruction must have PITarget name", this, null); } piTargetStart -= bufAbsoluteStart; piTargetEnd -= bufAbsoluteStart; if(tokenize) { posEnd = pos - 2; if(normalizeIgnorableWS) { --pcEnd; } } return true; } // protected final static char[] VERSION = {'v','e','r','s','i','o','n'}; // protected final static char[] NCODING = {'n','c','o','d','i','n','g'}; // protected final static char[] TANDALONE = {'t','a','n','d','a','l','o','n','e'}; // protected final static char[] YES = {'y','e','s'}; // protected final static char[] NO = {'n','o'}; protected final static char[] VERSION = "version".toCharArray(); protected final static char[] NCODING = "ncoding".toCharArray(); protected final static char[] TANDALONE = "tandalone".toCharArray(); protected final static char[] YES = "yes".toCharArray(); protected final static char[] NO = "no".toCharArray(); protected void parseXmlDecl(char ch) throws XmlPullParserException, IOException { // [23] XMLDecl ::= '' // first make sure that relative positions will stay OK preventBufferCompaction = true; bufStart = 0; // necessary to keep pos unchanged during expansion! // --- parse VersionInfo // [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"') // parse is positioned just on first S past 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && ch != '_' && ch != '.' && ch != ':' && ch != '-') { throw new XmlPullParserException( " 'z') && (ch < 'A' || ch > 'Z')) { throw new XmlPullParserException( " 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && ch != '.' && ch != '_' && ch != '-') { throw new XmlPullParserException( " as last part of ') { throw new XmlPullParserException( "expected ?> as last part of ' int bracketLevel = 0; final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; boolean normalizedCR = false; while(true) { ch = more(); if(ch == '[') ++bracketLevel; if(ch == ']') --bracketLevel; if(ch == '>' && bracketLevel == 0) break; if(normalizeIgnorableWS) { if(ch == '\r') { normalizedCR = true; //posEnd = pos -1; //joinPC(); // posEnd is alreadys set if(!usePC) { posEnd = pos -1; if(posEnd > posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } } posEnd = pos - 1; } protected void parseCDSect(boolean hadCharData) throws XmlPullParserException, IOException { // implements XML 1.0 Section 2.7 CDATA Sections // [18] CDSect ::= CDStart CData CDEnd // [19] CDStart ::= '' Char*)) // [21] CDEnd ::= ']]>' //ASSUMPTION: seen posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } } } boolean seenBracket = false; boolean seenBracketBracket = false; boolean normalizedCR = false; while(true) { // scan until it hits "]]>" ch = more(); if(ch == ']') { if(!seenBracket) { seenBracket = true; } else { seenBracketBracket = true; //seenBracket = false; } } else if(ch == '>') { if(seenBracket && seenBracketBracket) { break; // found end sequence!!!! } else { seenBracketBracket = false; } seenBracket = false; } else { if(seenBracket) { seenBracket = false; } } if(normalizeInput) { // deal with normalization issues ... if(ch == '\r') { normalizedCR = true; posStart = cdStart - bufAbsoluteStart; posEnd = pos - 1; // posEnd is alreadys set if(!usePC) { if(posEnd > posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } } } catch(EOFException ex) { // detect EOF and create meaningful error ... throw new XmlPullParserException( "CDATA section started on line "+curLine+" and column "+curColumn+" was not closed", this, ex); } if(normalizeInput) { if(usePC) { pcEnd = pcEnd - 2; } } posStart = cdStart - bufAbsoluteStart; posEnd = pos - 3; } protected void fillBuf() throws IOException, XmlPullParserException { if(reader == null) throw new XmlPullParserException( "reader must be set before parsing is started"); // see if we are in compaction area if(bufEnd > bufSoftLimit) { // expand buffer it makes sense!!!! boolean compact = bufStart > bufSoftLimit; boolean expand = false; if(preventBufferCompaction) { compact = false; expand = true; } else if(!compact) { //freeSpace if(bufStart < buf.length / 2) { // less then half buffer available forcompactin --> expand instead!!! expand = true; } else { // at least half of buffer can be reclaimed --> worthwhile effort!!! compact = true; } } // if buffer almost full then compact it if(compact) { //TODO: look on trashing // //assert bufStart > 0 System.arraycopy(buf, bufStart, buf, 0, bufEnd - bufStart); if(TRACE_SIZING) System.out.println( "TRACE_SIZING fillBuf() compacting "+bufStart +" bufEnd="+bufEnd +" pos="+pos+" posStart="+posStart+" posEnd="+posEnd +" buf first 100 chars:"+new String(buf, bufStart, bufEnd - bufStart < 100 ? bufEnd - bufStart : 100 )); } else if(expand) { final int newSize = 2 * buf.length; final char newBuf[] = new char[ newSize ]; if(TRACE_SIZING) System.out.println("TRACE_SIZING fillBuf() "+buf.length+" => "+newSize); System.arraycopy(buf, bufStart, newBuf, 0, bufEnd - bufStart); buf = newBuf; if(bufLoadFactor > 0) { bufSoftLimit = ( bufLoadFactor * buf.length ) /100; } } else { throw new XmlPullParserException("internal error in fillBuffer()"); } bufEnd -= bufStart; pos -= bufStart; posStart -= bufStart; posEnd -= bufStart; bufAbsoluteStart += bufStart; bufStart = 0; if(TRACE_SIZING) System.out.println( "TRACE_SIZING fillBuf() after bufEnd="+bufEnd +" pos="+pos+" posStart="+posStart+" posEnd="+posEnd +" buf first 100 chars:"+new String(buf, 0, bufEnd < 100 ? bufEnd : 100)); } // at least one charcter must be read or error final int len = buf.length - bufEnd > READ_CHUNK_SIZE ? READ_CHUNK_SIZE : buf.length - bufEnd; final int ret = reader.read(buf, bufEnd, len); if(ret > 0) { bufEnd += ret; if(TRACE_SIZING) System.out.println( "TRACE_SIZING fillBuf() after filling in buffer" +" buf first 100 chars:"+new String(buf, 0, bufEnd < 100 ? bufEnd : 100)); return; } if(ret == -1) { if(bufAbsoluteStart == 0 && pos == 0) { throw new EOFException("input contained no data"); } else { if(seenRoot && depth == 0) { // inside parsing epilog!!! reachedEnd = true; return; } else { StringBuffer expectedTagStack = new StringBuffer(); if(depth > 0) { //final char[] cbuf = elRawName[depth]; //final String startname = new String(cbuf, 0, elRawNameEnd[depth]); expectedTagStack.append(" - expected end tag"); if(depth > 1) { expectedTagStack.append("s"); //more than one end tag } expectedTagStack.append(" "); for (int i = depth; i > 0; i--) { String tagName = new String(elRawName[i], 0, elRawNameEnd[i]); expectedTagStack.append("'); } expectedTagStack.append(" to close"); for (int i = depth; i > 0; i--) { if(i != depth) { expectedTagStack.append(" and"); //more than one end tag } String tagName = new String(elRawName[i], 0, elRawNameEnd[i]); expectedTagStack.append(" start tag <"+tagName+">"); expectedTagStack.append(" from line "+elRawNameLine[i]); } expectedTagStack.append(", parser stopped on"); } throw new EOFException("no more data available" +expectedTagStack.toString()+getPositionDescription()); } } } else { throw new IOException("error reading input, returned "+ret); } } protected char more() throws IOException, XmlPullParserException { if(pos >= bufEnd) { fillBuf(); // this return value should be ignonored as it is used in epilog parsing ... if(reachedEnd) return (char)-1; } final char ch = buf[pos++]; //line/columnNumber if(ch == '\n') { ++lineNumber; columnNumber = 1; } else { ++columnNumber; } //System.out.print(ch); return ch; } // /** // * This function returns position of parser in XML input stream // * (how many characters were processed. // *

NOTE: this logical position and not byte offset as encodings // * such as UTF8 may use more than one byte to encode one character. // */ // public int getCurrentInputPosition() { // return pos + bufAbsoluteStart; // } protected void ensurePC(int end) { //assert end >= pc.length; final int newSize = end > READ_CHUNK_SIZE ? 2 * end : 2 * READ_CHUNK_SIZE; final char[] newPC = new char[ newSize ]; if(TRACE_SIZING) System.out.println("TRACE_SIZING ensurePC() "+pc.length+" ==> "+newSize+" end="+end); System.arraycopy(pc, 0, newPC, 0, pcEnd); pc = newPC; //assert end < pc.length; } protected void joinPC() { //assert usePC == false; //assert posEnd > posStart; final int len = posEnd - posStart; final int newEnd = pcEnd + len + 1; if(newEnd >= pc.length) ensurePC(newEnd); // add 1 for extra space for one char //assert newEnd < pc.length; System.arraycopy(buf, posStart, pc, pcEnd, len); pcEnd += len; usePC = true; } protected char requireInput(char ch, char[] input) throws XmlPullParserException, IOException { for (int i = 0; i < input.length; i++) { if(ch != input[i]) { throw new XmlPullParserException( "expected "+printable(input[i])+" in "+new String(input) +" and not "+printable(ch), this, null); } ch = more(); } return ch; } protected char requireNextS() throws XmlPullParserException, IOException { final char ch = more(); if(!isS(ch)) { throw new XmlPullParserException( "white space is required and not "+printable(ch), this, null); } return skipS(ch); } protected char skipS(char ch) throws XmlPullParserException, IOException { while(isS(ch)) { ch = more(); } // skip additional spaces return ch; } // nameStart / name lookup tables based on XML 1.1 http://www.w3.org/TR/2001/WD-xml11-20011213/ protected static final int LOOKUP_MAX = 0x400; protected static final char LOOKUP_MAX_CHAR = (char)LOOKUP_MAX; // protected static int lookupNameStartChar[] = new int[ LOOKUP_MAX_CHAR / 32 ]; // protected static int lookupNameChar[] = new int[ LOOKUP_MAX_CHAR / 32 ]; protected static boolean lookupNameStartChar[] = new boolean[ LOOKUP_MAX ]; protected static boolean lookupNameChar[] = new boolean[ LOOKUP_MAX ]; private static final void setName(char ch) //{ lookupNameChar[ (int)ch / 32 ] |= (1 << (ch % 32)); } { lookupNameChar[ ch ] = true; } private static final void setNameStart(char ch) //{ lookupNameStartChar[ (int)ch / 32 ] |= (1 << (ch % 32)); setName(ch); } { lookupNameStartChar[ ch ] = true; setName(ch); } static { setNameStart(':'); for (char ch = 'A'; ch <= 'Z'; ++ch) setNameStart(ch); setNameStart('_'); for (char ch = 'a'; ch <= 'z'; ++ch) setNameStart(ch); for (char ch = '\u00c0'; ch <= '\u02FF'; ++ch) setNameStart(ch); for (char ch = '\u0370'; ch <= '\u037d'; ++ch) setNameStart(ch); for (char ch = '\u037f'; ch < '\u0400'; ++ch) setNameStart(ch); setName('-'); setName('.'); for (char ch = '0'; ch <= '9'; ++ch) setName(ch); setName('\u00b7'); for (char ch = '\u0300'; ch <= '\u036f'; ++ch) setName(ch); } //private final static boolean isNameStartChar(char ch) { protected boolean isNameStartChar(char ch) { return (ch < LOOKUP_MAX_CHAR && lookupNameStartChar[ ch ]) || (ch >= LOOKUP_MAX_CHAR && ch <= '\u2027') || (ch >= '\u202A' && ch <= '\u218F') || (ch >= '\u2800' && ch <= '\uFFEF') ; // if(ch < LOOKUP_MAX_CHAR) return lookupNameStartChar[ ch ]; // else return ch <= '\u2027' // || (ch >= '\u202A' && ch <= '\u218F') // || (ch >= '\u2800' && ch <= '\uFFEF') // ; //return false; // return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ':' // || (ch >= '0' && ch <= '9'); // if(ch < LOOKUP_MAX_CHAR) return (lookupNameStartChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0; // if(ch <= '\u2027') return true; // //[#x202A-#x218F] // if(ch < '\u202A') return false; // if(ch <= '\u218F') return true; // // added pairts [#x2800-#xD7FF] | [#xE000-#xFDCF] | [#xFDE0-#xFFEF] | [#x10000-#x10FFFF] // if(ch < '\u2800') return false; // if(ch <= '\uFFEF') return true; // return false; // else return (supportXml11 && ( (ch < '\u2027') || (ch > '\u2029' && ch < '\u2200') ... } //private final static boolean isNameChar(char ch) { protected boolean isNameChar(char ch) { //return isNameStartChar(ch); // if(ch < LOOKUP_MAX_CHAR) return (lookupNameChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0; return (ch < LOOKUP_MAX_CHAR && lookupNameChar[ ch ]) || (ch >= LOOKUP_MAX_CHAR && ch <= '\u2027') || (ch >= '\u202A' && ch <= '\u218F') || (ch >= '\u2800' && ch <= '\uFFEF') ; //return false; // return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ':' // || (ch >= '0' && ch <= '9'); // if(ch < LOOKUP_MAX_CHAR) return (lookupNameStartChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0; //else return // else if(ch <= '\u2027') return true; // //[#x202A-#x218F] // else if(ch < '\u202A') return false; // else if(ch <= '\u218F') return true; // // added pairts [#x2800-#xD7FF] | [#xE000-#xFDCF] | [#xFDE0-#xFFEF] | [#x10000-#x10FFFF] // else if(ch < '\u2800') return false; // else if(ch <= '\uFFEF') return true; //else return false; } protected boolean isS(char ch) { return (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'); // || (supportXml11 && (ch == '\u0085' || ch == '\u2028'); } //protected boolean isChar(char ch) { return (ch < '\uD800' || ch > '\uDFFF') // ch != '\u0000' ch < '\uFFFE' //protected char printable(char ch) { return ch; } protected String printable(char ch) { if(ch == '\n') { return "\\n"; } else if(ch == '\r') { return "\\r"; } else if(ch == '\t') { return "\\t"; } else if(ch == '\'') { return "\\'"; } if(ch > 127 || ch < 32) { return "\\u"+Integer.toHexString((int)ch); } return ""+ch; } protected String printable(String s) { if(s == null) return null; final int sLen = s.length(); StringBuffer buf = new StringBuffer(sLen + 10); for(int i = 0; i < sLen; ++i) { buf.append(printable(s.charAt(i))); } s = buf.toString(); return s; } } /* * Indiana University Extreme! Lab Software License, Version 1.2 * * Copyright (C) 2003 The Trustees of Indiana University. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * 1) All redistributions of source code must retain the above * copyright notice, the list of authors in the original source * code, this list of conditions and the disclaimer listed in this * license; * * 2) All redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the disclaimer * listed in this license in the documentation and/or other * materials provided with the distribution; * * 3) Any documentation included with all redistributions must include * the following acknowledgement: * * "This product includes software developed by the Indiana * University Extreme! Lab. For further information please visit * http://www.extreme.indiana.edu/" * * Alternatively, this acknowledgment may appear in the software * itself, and wherever such third-party acknowledgments normally * appear. * * 4) The name "Indiana University" or "Indiana University * Extreme! Lab" shall not be used to endorse or promote * products derived from this software without prior written * permission from Indiana University. For written permission, * please contact http://www.extreme.indiana.edu/. * * 5) Products derived from this software may not use "Indiana * University" name nor may "Indiana University" appear in their name, * without prior written permission of the Indiana University. * * Indiana University provides no reassurances that the source code * provided does not infringe the patent or any other intellectual * property rights of any other entity. Indiana University disclaims any * liability to any recipient for claims brought by any other entity * based on infringement of intellectual property rights or otherwise. * * LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH * NO WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA * UNIVERSITY GIVES NO WARRANTIES AND MAKES NO REPRESENTATION THAT * SOFTWARE IS FREE OF INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR * OTHER PROPRIETARY RIGHTS. INDIANA UNIVERSITY MAKES NO WARRANTIES THAT * SOFTWARE IS FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP * DOORS", "WORMS", OR OTHER HARMFUL CODE. LICENSEE ASSUMES THE ENTIRE * RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR ASSOCIATED MATERIALS, * AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION GENERATED USING * SOFTWARE. */ MergeException.java000066400000000000000000000030571166327066700374710ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/mergepackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Rahul Thakur * @version $Id: MergeException.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class MergeException extends Exception { public MergeException( String message, Throwable cause ) { super( message, cause ); } public MergeException( String message ) { super( message ); } } MergeStrategy.java000066400000000000000000000033571166327066700373400ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/mergepackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.metadata.merge.support.Mergeable; /** * @author Rahul Thakur * @version $Id: MergeStrategy.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public interface MergeStrategy { /** * Merges a dominant {@link Mergeable} instance with a recessive one. * * @param dElt Dominant {@link Mergeable} instance. * @param rElt Recessive {@link Mergeable} instance. * @throws MergeException TODO */ void apply( Mergeable dElt, Mergeable rElt ) throws MergeException; } Merger.java000066400000000000000000000045501166327066700357730ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/mergepackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.io.IOException; import java.util.List; import org.jdom.Document; /** * @author Rahul Thakur * @version $Id: Merger.java 7868 2008-11-23 08:38:00Z jvanzyl $ */ public interface Merger { String ROLE = Merger.class.getName(); /** * Merge with the recessive document. * * @param dDocument the dominant document. * @param rDocument the recessive document. * @return the merged {@link Document} instance. * * @throws MergeException if there was an error in merge. */ Document merge( Document dDocument, Document rDocument ) throws MergeException; /** * Allows writing out a merged JDom Document to the specified file. * * @param mergedDocument the merged {@link Document} instance. * @param file File to write the merged contents to. * @throws IOException if there was an error while writing merged contents to the specified file. */ void writeMergedDocument( Document mergedDocument, File file ) throws IOException; void mergeDescriptors( File outputDescriptor, List descriptors ) throws IOException; } PlexusXmlMerger.java000066400000000000000000000046521166327066700376600ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/mergepackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.metadata.merge.support.PlexusRootElement; import org.jdom.Document; /** * Plexus XML merger. This is a superset of the components xml merger so can be used in its place if necessary. * * @author Rahul Thakur * @version $Id: PlexusXmlMerger.java 8174 2009-05-11 15:15:23Z jvanzyl $ */ @Component(role=Merger.class,hint="plexusXml") public class PlexusXmlMerger extends AbstractMerger { /** * @see org.codehaus.plexus.metadata.merge.Merger#merge(org.jdom.Document, org.jdom.Document) */ public Document merge( Document dDocument, Document rDocument ) throws MergeException { // TODO: Ideally we don't want to manipulate the original // dominant document but use its copy for merge. //Document mDoc = (Document) dDocument.clone(); // doesn't merge properly Document mDoc = dDocument; PlexusRootElement dCSE = new PlexusRootElement( mDoc.getRootElement() ); PlexusRootElement rCSE = new PlexusRootElement( rDocument.getRootElement() ); dCSE.merge( rCSE ); // the contents are merged into the dominant document DOM. return mDoc; } } 000077500000000000000000000000001166327066700354175ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportAbstractMergeableElement.java000066400000000000000000000162601166327066700431500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import org.codehaus.plexus.metadata.merge.MergeException; import org.codehaus.plexus.metadata.merge.MergeStrategy; import org.jdom.Content; import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: AbstractMergeableElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public abstract class AbstractMergeableElement extends AbstractMergeableSupport { public AbstractMergeableElement( Element element ) { super( element ); } /** * Detects if there was a conflict, that is the specified element was * present in both dominant and recessive element-sets. *

* This delegates to * {@link #isRecessiveElementInConflict(AbstractMergeableElement,List)}. * * @param re Recessive element. * @param eltName Element name to test for. * @return true if there was a conflict of element. * @deprecated use {@link #isRecessiveElementInConflict(AbstractMergeableElement,List)} instead. */ protected boolean isRecessiveElementInConflict( AbstractMergeableElement re, String eltName ) { // return (null != getChild (eltName) && null != re.getChild (eltName)); List l = new ArrayList(); l.add( eltName ); return isRecessiveElementInConflict( re, l ); } /** * Detects if there was a conflict, that is the specified element was * present in both dominant and recessive element-sets. *

* Use this to determine conflicts when the Dominant and Recessive element * sets are keyed with Composite keys.
* For instance: <component> is keyed on * <role> and <role-hint>. * * @param re * @param eltNameList List of elements that will be checked for values in both dominant and recessive sets. * @return */ protected boolean isRecessiveElementInConflict( AbstractMergeableElement re, List eltNameList ) { // give opportunity to subclasses to provide any custom Composite keys // for conflict checks. eltNameList = getElementNamesForConflictResolution( eltNameList ); if ( null == eltNameList || eltNameList.size() == 0 ) { return false; } // assuming the elements will conflict. for ( Iterator it = eltNameList.iterator(); it.hasNext(); ) { String eltName = (String) it.next(); String dEltValue = getChildTextTrim( eltName ); String rEltValue = re.getChildTextTrim( eltName ); if ( null == dEltValue || null == rEltValue || !dEltValue.equals( rEltValue ) ) { return false; } } return true; } /** * Determines if the Element to be merged is to be sourced from Recessive * Element set. * * @param re Recessive element. * @param eltName Element name to test for. * @return */ protected boolean mergeableElementComesFromRecessive( AbstractMergeableElement re, String eltName ) { return null == getChildText( eltName ) && null != re.getChildText( eltName ); } /** * Simply delegate to * * @see Mergeable#merge(Mergeable,org.codehaus.plexus.metadata.merge.MergeStrategy) */ public void merge( Mergeable me, MergeStrategy strategy ) throws MergeException { // TODO set up a unit test for this! strategy.apply( this, me ); } public void merge( Mergeable me ) throws MergeException { if ( !isExpectedElementType( me ) ) { // if (getLogger().isErrorEnabled) // getLogger().error ("Cannot Merge dissimilar elements. (Expected : '" + getClass ().getName () + "', found '" + me.getClass ().getName () + "')"); throw new MergeException( "Cannot Merge dissimilar elements. " + "(Expected : '" + getClass().getName() + "', found '" + me.getClass().getName() + "')" ); } // recessive Component Element. AbstractMergeableElement rce = (AbstractMergeableElement) me; Set allowedTags = new HashSet(); for ( int i = 0; i < getAllowedTags().length; i++ ) { String tagName = getAllowedTags()[i].getTagName(); allowedTags.add( tagName ); List defaultConflictChecklist = new ArrayList(); defaultConflictChecklist.add( tagName ); if ( !isRecessiveElementInConflict( rce, defaultConflictChecklist ) && mergeableElementComesFromRecessive( rce, tagName ) ) { this.addContent( (Element) rce.getChild( tagName ).clone() ); // else dominant wins in anycase! } else if ( getAllowedTags()[i].isMergeable() && isRecessiveElementInConflict( rce, defaultConflictChecklist ) ) { // this allows for merging multiple/list of elements. try { getAllowedTags()[i].createMergeable( this.getChild( tagName ) ) .merge( getAllowedTags()[i].createMergeable( rce.getChild( tagName ) ), getDefaultMergeStrategy() ); } catch ( Exception e ) { // TODO log to error throw new MergeException( "Unable to create Mergeable instance for tag " + "'" + getAllowedTags()[i] + "'.", e ); } } } for ( Iterator i = me.getElement().getChildren().iterator(); i.hasNext(); ) { Element child = (Element) i.next(); if ( !allowedTags.contains( child.getName() ) ) { // not yet merged, copy over element.addContent( (Content) child.clone() ); } } } } AbstractMergeableElementList.java000066400000000000000000000206441166327066700440050ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.codehaus.plexus.metadata.merge.MergeException; import org.jdom.Element; /** * Base class that allows for handling merging two element lists. *

* TODO Refactor and make this extend {@link AbstractMergeableElement} which is what * this actually is, but with added bits for merging child element lists. * * @author Rahul Thakur * @version $Id: AbstractMergeableElementList.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public abstract class AbstractMergeableElementList extends AbstractMergeableElement { public AbstractMergeableElementList( Element element ) { super( element ); } /** * Parses <component> elements and builds a map keyed basd on the list of composite keys specified. * * @param tagName Name of the tag that appears multiple times * @param compositeKeyList List of element/tag names to be used as composite keys to register recurring * {@link Mergeable} instances. * @return Map of {@link Mergeable} instances keyed on the composite key obtained from * {@link #getElementNamesForConflictResolution(java.util.List)} * @throws Exception if there was an error parsing and registering {@link Mergeable} instances */ protected Map parseRecurringMergeables( String tagName, List compositeKeyList, Mergeable parentElement ) throws Exception { Map mergeables = new LinkedHashMap(); List list = this.getChildren( tagName ); for ( Iterator it = list.iterator(); it.hasNext(); ) { Element ce = (Element) it.next(); // use the composite key specified by the passed in list String compositeKey = ""; for ( Iterator itr = compositeKeyList.iterator(); itr.hasNext(); ) { String key = (String) itr.next(); if ( null != ce.getChildText( key ) ) { compositeKey = compositeKey + ce.getChildText( key ); } } // create a Mergeable instance and store it in the map. DescriptorTag tag = lookupTagInstanceByName( tagName, parentElement.getAllowedTags() ); Mergeable mergeable = tag.createMergeable( ce ); // register the Mergeable instance based on composite key mergeables.put( compositeKey, mergeable ); } return mergeables; } /** * Looks up and returns an {@link DescriptorTag} instance for the * specified tag name. * * @param name key to look up the {@link DescriptorTag} instance on. * @return {@link DescriptorTag} instance whose name matches the name specified. * Returns null if no match is found. */ private DescriptorTag lookupTagInstanceByName( String name, DescriptorTag[] values ) { DescriptorTag value = null; for ( int i = 0; i < values.length && value == null; i++ ) { if ( values[i].getTagName().equals( name ) ) { value = values[i]; } } // not found! return value; } public void merge( Mergeable me ) throws MergeException { try { Map dRequirementsMap = parseRecurringMergeables( getTagNameForRecurringMergeable(), getElementNamesForConflictResolution( new ArrayList() ), me ); Map rRequirementsMap = ( (AbstractMergeableElementList) me ) .parseRecurringMergeables( getTagNameForRecurringMergeable(), getElementNamesForConflictResolution( new ArrayList() ), me ); merge( getElement(), dRequirementsMap, rRequirementsMap ); } catch ( Exception e ) { // TODO: log to error // TODO: better error message throw new MergeException( "Unable to merge Mergeable lists for element '" + getName() + "'.", e ); } } /** * Identifies the conflicting elements in the dominant and recessive * {@link Map} instance and merges as required. * * @param parent {@link Element} that is parent for the children in the dominant Map instance. Merged content is * added to this element. * @param dMap Dominant Map keyed by the composite key obtained from * {@link #getElementNamesForConflictResolution(List)} * @param rMap Recessive Map keyed by the composite key obtained from * {@link #getElementNamesForConflictResolution(List)} * @throws Exception if there was an error merging both the maps. */ protected void merge( Element parent, Map dMap, Map rMap ) throws Exception { Set dKeySet = dMap.keySet(); Set rKeySet = rMap.keySet(); // check if there are any entities to merge if ( !isMergeRequired( dKeySet, rKeySet ) ) { return; } // iterate over components and process them for ( Iterator it = dKeySet.iterator(); it.hasNext(); ) { String dKey = (String) it.next(); if ( rMap.containsKey( dKey ) ) { // conflict ! merge this component Mergeable dMeregeable = (Mergeable) dMap.get( dKey ); Mergeable rMergeable = (Mergeable) rMap.get( dKey ); dMeregeable.merge( rMergeable ); // and remove from the recessive list to mark it as merged. rMap.remove( dKey ); } } // check if any unmerged components are left in the recessive map. if ( rMap.keySet().size() > 0 ) { // add them to results for ( Iterator it = rKeySet.iterator(); it.hasNext(); ) { String rKey = (String) it.next(); // add to parent parent.addContent( (Element) ( (Mergeable) rMap.get( rKey ) ).getElement().clone() ); } } } /** * Determines if a merge operation is required for the two sets (dominant and recessive) specified. * * @param dKeySet the dominant set of elements. * @param rKeySet the recessive set of elements. * @return true if a merge operation was required. */ private boolean isMergeRequired( Set dKeySet, Set rKeySet ) { return ( dKeySet.size() > 0 || rKeySet.size() > 0 ); } /** * Allows the sub classes to provided a tag name that they expect to recurr * within them. *

* For instance:
*

    *
  • <components> expects <component> to recurr within * itself.
  • *
  • <requirements> expects <requirement> to recurr within * itself.
  • *
* * @return tag name of the {@link Mergeable} element that occurs multiple times. */ protected abstract String getTagNameForRecurringMergeable(); protected abstract List getElementNamesForConflictResolution( List defaultList ); } AbstractMergeableSupport.java000066400000000000000000000374451166327066700432430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Collection; import java.util.Iterator; import java.util.List; import org.codehaus.plexus.metadata.merge.MergeException; import org.codehaus.plexus.metadata.merge.MergeStrategy; import org.jdom.Attribute; import org.jdom.Content; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.Parent; import org.jdom.filter.Filter; /** * @author Rahul Thakur * @version $Id: AbstractMergeableSupport.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public abstract class AbstractMergeableSupport implements Mergeable { /** * Wrapped JDOM element. */ protected Element element; /** * The default merging strategy used. */ private static final MergeStrategy DEFAULT_MERGE_STRATEGY = MergeStrategies.DEEP; public AbstractMergeableSupport( Element element ) { this.element = element; } public abstract void merge( Mergeable me ) throws MergeException; /** * Determines if the passed in {@link Mergeable} was of same type as this * class. * * @param me {@link Mergeable} instance to test. * @return true if the passed in Mergeable can be merged with * the current Mergeable. */ protected abstract boolean isExpectedElementType( Mergeable me ); // ---------------------------------------------------------------------- // Methods delegated on wrapped JDOM element. // ---------------------------------------------------------------------- public Element addContent( Collection collection ) { return element.addContent( collection ); } public Element addContent( Content child ) { return element.addContent( child ); } public Element addContent( int index, Collection c ) { return element.addContent( index, c ); } public Element addContent( int index, Content child ) { return element.addContent( index, child ); } public Element addContent( String str ) { return element.addContent( str ); } public void addNamespaceDeclaration( Namespace additional ) { element.addNamespaceDeclaration( additional ); } public Object clone() { return element.clone(); } public List cloneContent() { return element.cloneContent(); } public Content detach() { return element.detach(); } public boolean equals( Object obj ) { return element.equals( obj ); } public List getAdditionalNamespaces() { return element.getAdditionalNamespaces(); } public Attribute getAttribute( String name, Namespace ns ) { return element.getAttribute( name, ns ); } public Attribute getAttribute( String name ) { return element.getAttribute( name ); } public List getAttributes() { return element.getAttributes(); } /** * @see org.jdom.Element#getAttributeValue(java.lang.String,org.jdom.Namespace,java.lang.String) */ public String getAttributeValue( String name, Namespace ns, String def ) { return element.getAttributeValue( name, ns, def ); } /** * @see org.jdom.Element#getAttributeValue(java.lang.String,org.jdom.Namespace) */ public String getAttributeValue( String name, Namespace ns ) { return element.getAttributeValue( name, ns ); } /** * @see org.jdom.Element#getAttributeValue(java.lang.String,java.lang.String) */ public String getAttributeValue( String name, String def ) { return element.getAttributeValue( name, def ); } /** * @see org.jdom.Element#getAttributeValue(java.lang.String) */ public String getAttributeValue( String name ) { return element.getAttributeValue( name ); } /** * @return * @see org.jdom.Element#getChild(java.lang.String,org.jdom.Namespace) */ public Element getChild( String name, Namespace ns ) { return element.getChild( name, ns ); } /** * @see org.jdom.Element#getChild(java.lang.String) */ public Element getChild( String name ) { return element.getChild( name ); } /** * @see org.jdom.Element#getChildren() */ public List getChildren() { return element.getChildren(); } /** * @see org.jdom.Element#getChildren(java.lang.String,org.jdom.Namespace) */ public List getChildren( String name, Namespace ns ) { return element.getChildren( name, ns ); } /** * @see org.jdom.Element#getChildren(java.lang.String) */ public List getChildren( String name ) { return element.getChildren( name ); } /** * @see org.jdom.Element#getChildText(java.lang.String,org.jdom.Namespace) */ public String getChildText( String name, Namespace ns ) { return element.getChildText( name, ns ); } /** * @see org.jdom.Element#getChildText(java.lang.String) */ public String getChildText( String name ) { return element.getChildText( name ); } /** * @see org.jdom.Element#getChildTextNormalize(java.lang.String,org.jdom.Namespace) */ public String getChildTextNormalize( String name, Namespace ns ) { return element.getChildTextNormalize( name, ns ); } /** * @see org.jdom.Element#getChildTextNormalize(java.lang.String) */ public String getChildTextNormalize( String name ) { return element.getChildTextNormalize( name ); } /** * @see org.jdom.Element#getChildTextTrim(java.lang.String,org.jdom.Namespace) */ public String getChildTextTrim( String name, Namespace ns ) { return element.getChildTextTrim( name, ns ); } /** * @see org.jdom.Element#getChildTextTrim(java.lang.String) */ public String getChildTextTrim( String name ) { return element.getChildTextTrim( name ); } /** * @see org.jdom.Element#getContent() */ public List getContent() { return element.getContent(); } /** * @see org.jdom.Element#getContent(org.jdom.filter.Filter) */ public List getContent( Filter filter ) { return element.getContent( filter ); } /** * @see org.jdom.Element#getContent(int) */ public Content getContent( int index ) { return element.getContent( index ); } /** * @return * @see org.jdom.Element#getContentSize() */ public int getContentSize() { return element.getContentSize(); } /** * @see org.jdom.Element#getDescendants() */ public Iterator getDescendants() { return element.getDescendants(); } /** * @see org.jdom.Element#getDescendants(org.jdom.filter.Filter) */ public Iterator getDescendants( Filter filter ) { return element.getDescendants( filter ); } /** * @see org.jdom.Content#getDocument() */ public Document getDocument() { return element.getDocument(); } /** * @see org.jdom.Element#getName() */ public String getName() { return element.getName(); } /** * @see org.jdom.Element#getNamespace() */ public Namespace getNamespace() { return element.getNamespace(); } /** * @see org.jdom.Element#getNamespace(java.lang.String) */ public Namespace getNamespace( String prefix ) { return element.getNamespace( prefix ); } /** * @see org.jdom.Element#getNamespacePrefix() */ public String getNamespacePrefix() { return element.getNamespacePrefix(); } /** * @see org.jdom.Element#getNamespaceURI() */ public String getNamespaceURI() { return element.getNamespaceURI(); } /** * @see org.jdom.Content#getParent() */ public Parent getParent() { return element.getParent(); } /** * @see org.jdom.Content#getParentElement() */ public Element getParentElement() { return element.getParentElement(); } /** * @see org.jdom.Element#getQualifiedName() */ public String getQualifiedName() { return element.getQualifiedName(); } /** * @see org.jdom.Element#getText() */ public String getText() { return element.getText(); } /** * @see org.jdom.Element#getTextNormalize() */ public String getTextNormalize() { return element.getTextNormalize(); } /** * @see org.jdom.Element#getTextTrim() */ public String getTextTrim() { return element.getTextTrim(); } /** * @see org.jdom.Element#getValue() */ public String getValue() { return element.getValue(); } /** * @see java.lang.Object#hashCode() */ public int hashCode() { return element.hashCode(); } /** * @see org.jdom.Element#indexOf(org.jdom.Content) */ public int indexOf( Content child ) { return element.indexOf( child ); } /** * @see org.jdom.Element#isAncestor(org.jdom.Element) */ public boolean isAncestor( Element element ) { return element.isAncestor( element ); } /** * @see org.jdom.Element#isRootElement() */ public boolean isRootElement() { return element.isRootElement(); } /** * @see org.jdom.Element#removeAttribute(org.jdom.Attribute) */ public boolean removeAttribute( Attribute attribute ) { return element.removeAttribute( attribute ); } /** * @see org.jdom.Element#removeAttribute(java.lang.String,org.jdom.Namespace) */ public boolean removeAttribute( String name, Namespace ns ) { return element.removeAttribute( name, ns ); } /** * @see org.jdom.Element#removeAttribute(java.lang.String) */ public boolean removeAttribute( String name ) { return element.removeAttribute( name ); } /** * @see org.jdom.Element#removeChild(java.lang.String,org.jdom.Namespace) */ public boolean removeChild( String name, Namespace ns ) { return element.removeChild( name, ns ); } /** * @see org.jdom.Element#removeChild(java.lang.String) */ public boolean removeChild( String name ) { return element.removeChild( name ); } /** * @see org.jdom.Element#removeChildren(java.lang.String,org.jdom.Namespace) */ public boolean removeChildren( String name, Namespace ns ) { return element.removeChildren( name, ns ); } /** * @see org.jdom.Element#removeChildren(java.lang.String) */ public boolean removeChildren( String name ) { return element.removeChildren( name ); } /** * @see org.jdom.Element#removeContent() */ public List removeContent() { return element.removeContent(); } /** * @see org.jdom.Element#removeContent(org.jdom.Content) */ public boolean removeContent( Content child ) { return element.removeContent( child ); } /** * @see org.jdom.Element#removeContent(org.jdom.filter.Filter) */ public List removeContent( Filter filter ) { return element.removeContent( filter ); } /** * @see org.jdom.Element#removeContent(int) */ public Content removeContent( int index ) { return element.removeContent( index ); } /** * @see org.jdom.Element#removeNamespaceDeclaration(org.jdom.Namespace) */ public void removeNamespaceDeclaration( Namespace additionalNamespace ) { element.removeNamespaceDeclaration( additionalNamespace ); } /** * @see org.jdom.Element#setAttribute(org.jdom.Attribute) */ public Element setAttribute( Attribute attribute ) { return element.setAttribute( attribute ); } /** * @see org.jdom.Element#setAttribute(java.lang.String,java.lang.String,org.jdom.Namespace) */ public Element setAttribute( String name, String value, Namespace ns ) { return element.setAttribute( name, value, ns ); } /** * @see org.jdom.Element#setAttribute(java.lang.String,java.lang.String) */ public Element setAttribute( String name, String value ) { return element.setAttribute( name, value ); } /** * @see org.jdom.Element#setAttributes(java.util.List) */ public Element setAttributes( List newAttributes ) { return element.setAttributes( newAttributes ); } /** * @see org.jdom.Element#setContent(java.util.Collection) */ public Element setContent( Collection newContent ) { return element.setContent( newContent ); } /** * @see org.jdom.Element#setContent(org.jdom.Content) */ public Element setContent( Content child ) { return element.setContent( child ); } /** * @see org.jdom.Element#setContent(int,java.util.Collection) */ public Parent setContent( int index, Collection collection ) { return element.setContent( index, collection ); } /** * @see org.jdom.Element#setContent(int,org.jdom.Content) */ public Element setContent( int index, Content child ) { return element.setContent( index, child ); } /** * @see org.jdom.Element#setName(java.lang.String) */ public Element setName( String name ) { return element.setName( name ); } /** * @see org.jdom.Element#setNamespace(org.jdom.Namespace) */ public Element setNamespace( Namespace namespace ) { return element.setNamespace( namespace ); } /** * @see org.jdom.Element#setText(java.lang.String) */ public Element setText( String text ) { return element.setText( text ); } /** * @see org.jdom.Element#toString() */ public String toString() { return element.toString(); } /** * Returns the wrapped up JDom {@link Element} instance. */ public Element getElement() { return this.element; } /** * Sub classes should override if they wish to provide a different * combination of composite keys for determining conflicts. */ protected List getElementNamesForConflictResolution( List defaultList ) { return defaultList; } /** * Returns the default {@link MergeStrategy} instance. */ protected MergeStrategy getDefaultMergeStrategy() { return DEFAULT_MERGE_STRATEGY; } } ComponentElement.java000066400000000000000000000054751166327066700415510ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: ComponentElement.java 8455 2009-10-01 22:10:12Z bentmann $ */ public class ComponentElement extends AbstractMergeableElement { /** * Allowed elements/tags that we can expect under this element. */ private final DescriptorTag[] allowedTags = { ROLE, ROLE_HINT, OPTIONAL, IMPLEMENTATION, FIELD_NAME, LIFECYCLE_HANDLER, DESCRIPTION, CONFIGURATION, RequirementsElement.TAG }; static final DescriptorTag TAG = new DescriptorTag( "component", true, ComponentElement.class ); static final DescriptorTag ROLE = new DescriptorTag( "role" ); static final DescriptorTag ROLE_HINT = new DescriptorTag( "role-hint" ); static final DescriptorTag OPTIONAL = new DescriptorTag( "optional" ); private static final DescriptorTag DESCRIPTION = new DescriptorTag( "description" ); private static final DescriptorTag CONFIGURATION = new DescriptorTag( "configuration" ); static final DescriptorTag FIELD_NAME = new DescriptorTag( "field-name" ); private static final DescriptorTag IMPLEMENTATION = new DescriptorTag( "implementation" ); private static final DescriptorTag LIFECYCLE_HANDLER = new DescriptorTag( "lifecycle-handler", false, null ); public ComponentElement( Element element ) { super( element ); } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof ComponentElement; } public DescriptorTag[] getAllowedTags() { return allowedTags; } } ComponentSetElement.java000066400000000000000000000033641166327066700422200ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: ComponentSetElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class ComponentSetElement extends AbstractMergeableElement { public ComponentSetElement( Element element ) { super( element ); } public DescriptorTag[] getAllowedTags() { return new DescriptorTag[]{ComponentsElement.TAG}; } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof ComponentSetElement; } } ComponentsElement.java000066400000000000000000000053651166327066700417320ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.List; import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: ComponentsElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class ComponentsElement extends AbstractMergeableElementList { static final DescriptorTag TAG = new DescriptorTag( "components", true, ComponentsElement.class ); private List conflictVerificationkeys = new ArrayList(); public ComponentsElement( Element element ) { super( element ); conflictVerificationkeys.add( ComponentElement.ROLE.getTagName() ); conflictVerificationkeys.add( ComponentElement.ROLE_HINT.getTagName() ); } public DescriptorTag[] getAllowedTags() { return new DescriptorTag[]{ComponentElement.TAG}; } protected boolean isExpectedElementType( Mergeable me ) { return ( me instanceof ComponentsElement ); } protected List getElementNamesForConflictChecks( List defaultList ) { // Allow to return custom keys for conflict checks/resolution. return this.conflictVerificationkeys; } protected String getTagNameForRecurringMergeable() { return ComponentElement.TAG.getTagName(); } protected List getElementNamesForConflictResolution( List defaultList ) { // TODO: how is this different from getElementNamesForConflictChecks? List l = new ArrayList(); l.add( ComponentElement.ROLE.getTagName() ); l.add( ComponentElement.ROLE_HINT.getTagName() ); return l; } } ConfigurationElement.java000066400000000000000000000034421166327066700424060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.jdom.Element; /** * TODO Implement merge for this. * * @author Rahul Thakur * @version $Id: ConfigurationElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class ConfigurationElement extends AbstractMergeableElement { public ConfigurationElement( Element element ) { super( element ); } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof ConfigurationElement; } public DescriptorTag[] getAllowedTags() { // TODO Implement! return new DescriptorTag[0]; } } DescriptorTag.java000066400000000000000000000120001166327066700410250ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * ======================================================================== * * Copyright 2003 The Apache Software Foundation. Code from this file * was originally imported from the Jakarta Cactus project. * * Copyright 2004-2006 Vincent Massol. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ======================================================================== */ import java.lang.reflect.Constructor; import org.jdom.Element; /** * Represents the various top-level tags in a deployment descriptor as a typesafe enumeration. * * @version $Id: DescriptorTag.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class DescriptorTag { /** * The tag name. */ private String tagName; /** * Whether multiple occurrences of the tag in the descriptor are allowed. */ private boolean multipleAllowed; /** * Class that wraps this tag and provides for merging same tags. */ private Class mergeableClass; /** * Constructor. * * @param tagName The tag name of the element */ public DescriptorTag( String tagName ) { this( tagName, false, null ); } /** * Constructor. * * @param tagName The tag name of the element * @param isMultipleAllowed Whether the element may occur multiple times in the descriptor * @deprecated Use {@link #DescriptorTag(String,boolean,Class)} instead */ public DescriptorTag( String tagName, boolean isMultipleAllowed ) { this( tagName, isMultipleAllowed, null ); } /** * Constructor. * * @param tagName The tag name of the element * @param isMultipleAllowed Whether the element may occur multiple times in the descriptor * @param mergeableClass Concrete implementation of {@link Mergeable} that is bound this tag. */ public DescriptorTag( String tagName, boolean isMultipleAllowed, Class mergeableClass ) { this.tagName = tagName; this.multipleAllowed = isMultipleAllowed; this.mergeableClass = mergeableClass; } public boolean equals( Object other ) { boolean eq = false; if ( other instanceof DescriptorTag ) { DescriptorTag tag = (DescriptorTag) other; if ( tag.getTagName().equals( this.tagName ) ) { eq = true; } } return eq; } public int hashCode() { return this.getTagName().hashCode(); } public String getTagName() { return this.tagName; } /** * Returns whether the tag may occur multiple times in the descriptor. * * @return Whether multiple occurrences are allowed */ public boolean isMultipleAllowed() { return this.multipleAllowed; } /** * Determines if a particular Tag is mergeable or not. *

* Basically means if we have a {@link Mergeable} class registered for a tag instance. * * @return true if this tag is mergeable. */ public boolean isMergeable() { return null != this.mergeableClass; } public String toString() { return getTagName(); } /** * Creates an {@link Mergeable} instance from the registered class for this * tag instance. * * @return instance of {@link Mergeable}. * @throws Exception if there was an error creating an instance. */ public Mergeable createMergeable( Element element ) throws Exception { Constructor cons = this.mergeableClass.getConstructor( new Class[] { Element.class } ); // XXX Is there a better way to determine this? if ( this.mergeableClass.getSuperclass().equals( AbstractMergeableElementList.class ) ) { return (AbstractMergeableElementList) cons.newInstance( new Object[] { element } ); } else if ( this.mergeableClass.getSuperclass().equals( AbstractMergeableElement.class ) ) { return (AbstractMergeableElement) cons.newInstance( new Object[] { element } ); } else { // TODO set up Logger // if (getLogger ().isErrorEnabled ()) // getLogger.error ( "Could not create Mergeable instance for specified class '" + this.mergeableClass + "'" ); throw new Exception( "Could not create Mergeable instance for specified class " + "'" + this.mergeableClass + "'" ); } } } MergeStrategies.java000066400000000000000000000062211166327066700413550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Collections; import java.util.List; import org.codehaus.plexus.metadata.merge.MergeException; import org.codehaus.plexus.metadata.merge.MergeStrategy; /** * Collection of available Merge Strategies.

* TODO: Revisit and factor {@link Mergeable#merge(Mergeable)} to use a {@link MergeStrategy}. * * @author Rahul Thakur * @version $Id: MergeStrategies.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class MergeStrategies { /** * {@link MergeStrategy} implementation wherein the elements are merged * down to the deepest available {@link Mergeable} instance in the DOM tree. */ public static final MergeStrategy DEEP = new MergeStrategy() { public void apply( Mergeable dElt, Mergeable rElt ) throws MergeException { dElt.merge( rElt ); } }; /** * {@link MergeStrategy} implementation wherein only the element on * which the merge operation is called is 'merged'. The merge does not * traverse the DOM tree any further. */ public static final MergeStrategy SHALLOW = new MergeStrategy() { /** * @throws MergeException * @see org.codehaus.plexus.metadata.merge.MergeStrategy#apply(Mergeable,Mergeable) */ public void apply( Mergeable dElt, Mergeable rElt ) throws MergeException { AbstractMergeableElement dame = (AbstractMergeableElement) dElt; AbstractMergeableElement rame = (AbstractMergeableElement) rElt; // check if the dominant was in conflict with recessive. List elementNames = dame.getElementNamesForConflictResolution( Collections.EMPTY_LIST ); if ( !dame.isRecessiveElementInConflict( rame, elementNames ) ) { // no conflict, simply add recessive to dominant's parent dame.getElement().addContent( rame.getElement() ); } } }; } Mergeable.java000066400000000000000000000054321166327066700401510ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.metadata.merge.MergeException; import org.codehaus.plexus.metadata.merge.MergeStrategy; import org.jdom.Element; /** * Interface that marks an implementing entity as mergeable.

* Not all the elements/tags are expected to implement this interface.
* It should be implemented by elements/tags that need to have a certain control on how elements of the same type are merged with them. * * @author Rahul Thakur * @version $Id: Mergeable.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public interface Mergeable { /** * Merges an element of same type. * * @param me Another entity that is mergeable. * @throws MergeException if there was an error merging the mergeables. */ void merge( Mergeable me ) throws MergeException; /** * Applies the passed in {@link MergeStrategy} to merge two {@link Mergeable} instance.

* * @param me Recessive {@link Mergeable} instance. * @param strategy {@link MergeStrategy} to apply for merging. * @throws MergeException if there was an error while merging. */ void merge( Mergeable me, MergeStrategy strategy ) throws MergeException; /** * Returns the wrapped up JDom {@link Element} instance that was used to create this Mergeable. * * @return the wrapped up JDom {@link Element} instance. */ Element getElement(); /** * Returns an array of tags/elements that are allowed under the current * element. * * @return the allowedTags */ DescriptorTag[] getAllowedTags(); } PlexusRootElement.java000066400000000000000000000034231166327066700417220ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: PlexusRootElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class PlexusRootElement extends AbstractMergeableElement { public PlexusRootElement( Element element ) { super( element ); } public DescriptorTag[] getAllowedTags() { // TODO: add the managers, etc return new DescriptorTag[]{ComponentsElement.TAG}; } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof PlexusRootElement; } } PlexusXmlTag.java000066400000000000000000000047301166327066700406630ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /** * All allowable tags in components.xml and their bindings to * {@link org.codehaus.plexus.metadata.merge.support.Mergeable} counterparts (if required). *

* This implementation may change.
* TODO Might be an idea factor and set up the list of allowed tags here itself. * * @author Rahul Thakur * @version $Id: PlexusXmlTag.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class PlexusXmlTag extends DescriptorTag { public static final PlexusXmlTag COMPONENT_SET = new PlexusXmlTag( "component-set", false, ComponentSetElement.class ); public static final PlexusXmlTag COMPONENTS = new PlexusXmlTag( "components", true, ComponentsElement.class ); public static final PlexusXmlTag COMPONENT = new PlexusXmlTag( "component", true, ComponentElement.class ); public static final PlexusXmlTag ROLE = new PlexusXmlTag( "role" ); public static final PlexusXmlTag ROLE_HINT = new PlexusXmlTag( "role-hint" ); public static final PlexusXmlTag FIELD_NAME = new PlexusXmlTag( "field-name" ); public static final PlexusXmlTag IMPLEMENTATION = new PlexusXmlTag( "implementation" ); public static final PlexusXmlTag LIFECYCLE_HANDLER = new PlexusXmlTag( "lifecycle-handler", false, null ); public static final PlexusXmlTag REQUIREMENTS = new PlexusXmlTag( "requirements", true, RequirementsElement.class ); public static final PlexusXmlTag CONFIGURATION = new PlexusXmlTag( "configuration", true, ConfigurationElement.class ); public static final PlexusXmlTag REQUIREMENT = new PlexusXmlTag( "requirement", true, RequirementElement.class ); /** * @param tagName * @param isMultipleAllowed * @param mergeableClass Class that wraps this tag (as JDom element) and provides for merging same tags. */ private PlexusXmlTag( String tagName, boolean isMultipleAllowed, Class mergeableClass ) { super( tagName, isMultipleAllowed, mergeableClass ); } /** * By default we don't allow multiples of same tag names. * * @param tagName */ private PlexusXmlTag( String tagName ) { super( tagName, false, null ); } } RequirementElement.java000066400000000000000000000041441166327066700420770ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.metadata.merge.MergeException; import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: RequirementElement.java 8455 2009-10-01 22:10:12Z bentmann $ */ public class RequirementElement extends AbstractMergeableElement { static final DescriptorTag TAG = new DescriptorTag( "requirement", true, RequirementElement.class ); public RequirementElement( Element element ) { super( element ); } public DescriptorTag[] getAllowedTags() { return new DescriptorTag[] { ComponentElement.ROLE, ComponentElement.ROLE_HINT, ComponentElement.FIELD_NAME, ComponentElement.OPTIONAL }; } public void merge( Mergeable me ) throws MergeException { super.merge( me ); } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof RequirementElement; } } RequirementsElement.java000066400000000000000000000047571166327066700422740ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/java/org/codehaus/plexus/metadata/merge/supportpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.List; import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: RequirementsElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class RequirementsElement extends AbstractMergeableElementList { public static final DescriptorTag TAG = new DescriptorTag( "requirements", true, RequirementsElement.class ); public RequirementsElement( Element element ) { super( element ); } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof RequirementsElement; } public DescriptorTag[] getAllowedTags() { return new DescriptorTag[]{RequirementElement.TAG}; } protected List getElementNamesForConflictResolution( List defaultList ) { // we return the keys that we know we want to lookup to identify and // resolve conflicts. List l = new ArrayList(); l.add( ComponentElement.ROLE.getTagName() ); // TODO: add this back, but a test will fail (based on a role with no hint, which shouldn't be legal) // l.add( ComponentElement.ROLE_HINT.getTagName() ); return l; } protected String getTagNameForRecurringMergeable() { return RequirementElement.TAG.getTagName(); } } plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/resources/000077500000000000000000000000001166327066700262725ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/resources/META-INF/000077500000000000000000000000001166327066700274325ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/resources/META-INF/plexus/000077500000000000000000000000001166327066700307525ustar00rootroot00000000000000components.xml000066400000000000000000000036201166327066700336030ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/main/resources/META-INF/plexus org.codehaus.plexus.metadata.gleaner.SourceComponentGleaner qdox org.codehaus.plexus.metadata.gleaner.QDoxComponentGleaner org.codehaus.plexus.metadata.ComponentDescriptorCreator org.codehaus.plexus.metadata.DefaultComponentDescriptorCreator org.codehaus.plexus.metadata.ComponentDescriptorWriter org.codehaus.plexus.metadata.DefaultComponentDescriptorWriter org.codehaus.plexus.metadata.merge.Merger componentsXml org.codehaus.plexus.metadata.merge.ComponentsXmlMerger org.codehaus.plexus.metadata.merge.Merger plexusXml org.codehaus.plexus.metadata.merge.PlexusXmlMerger org.codehaus.plexus.metadata.gleaner.ClassComponentGleaner annotation org.codehaus.plexus.metadata.gleaner.AnnotationComponentGleaner org.codehaus.plexus.metadata.MetadataGenerator org.codehaus.plexus.metadata.DefaultMetadataGenerator org.codehaus.plexus.metadata.merge.Merger componentsXml plexus-containers1.5-1.5.5/plexus-component-metadata/src/site/000077500000000000000000000000001166327066700243005ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/site/site.xml000066400000000000000000000006701166327066700257710ustar00rootroot00000000000000

plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/000077500000000000000000000000001166327066700243135ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/000077500000000000000000000000001166327066700252345ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/000077500000000000000000000000001166327066700260235ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/000077500000000000000000000000001166327066700276165ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/000077500000000000000000000000001166327066700311365ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/000077500000000000000000000000001166327066700327165ustar00rootroot00000000000000DefaultComponentDescriptorWriterTest.java000066400000000000000000000070211166327066700430450ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata; import java.io.StringWriter; import java.util.List; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.io.PlexusTools; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * Test for the {@link DefaultComponentDescriptorWriter} class. * * @version $Rev: 8157 $ $Date: 2009-04-26 18:54:37 +0200 (dim. 26 avril 2009) $ */ public class DefaultComponentDescriptorWriterTest extends PlexusTestCase { private DefaultComponentDescriptorWriter descriptorWriter; // @Override protected void setUp() throws Exception { super.setUp(); descriptorWriter = (DefaultComponentDescriptorWriter) lookup(ComponentDescriptorWriter.class); assertNotNull(descriptorWriter); } // @Override protected void tearDown() throws Exception { descriptorWriter = null; super.tearDown(); } public void testBasic() throws Exception { ComponentSetDescriptor set = new ComponentSetDescriptor(); ComponentDescriptor component = new ComponentDescriptor(); component.setImplementation("java.lang.String"); component.setRole("foo"); component.setRoleHint("bar"); component.setComponentFactory("baz"); set.addComponentDescriptor(component); StringWriter writer = new StringWriter(); descriptorWriter.writeDescriptorSet(writer, set, false); writer.flush(); writer.close(); String xml = writer.toString(); assertTrue(xml.length() != 0); PlexusConfiguration config = PlexusTools.buildConfiguration(xml); assertNotNull(config); ClassWorld classWorld = new ClassWorld( "test", Thread.currentThread().getContextClassLoader() ); ClassRealm realm = classWorld.getRealm( "test" ); org.codehaus.plexus.component.repository.ComponentSetDescriptor set2 = PlexusTools.buildComponentSet(config, realm); assertNotNull(set2); List components = set2.getComponents(); assertNotNull(components); assertEquals(1, components.size()); org.codehaus.plexus.component.repository.ComponentDescriptor component2 = (org.codehaus.plexus.component.repository.ComponentDescriptor) components.get(0); assertNotNull(component2); assertEquals(component.getRole(), component2.getRole()); assertEquals(component.getRoleHint(), component2.getRoleHint()); assertEquals(component.getComponentFactory(), component2.getComponentFactory()); // // TODO: Verify requirements and configuration too... but I'm too lazy for that right now // } } 000077500000000000000000000000001166327066700342545ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleanerAbstractClass.java000066400000000000000000000014351166327066700376530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner; /** * ??? * * @version $Id: AbstractClass.java 7702 2008-08-31 01:20:23Z jvanzyl $ */ public abstract class AbstractClass { } AbstractWithAnnoClass.java000066400000000000000000000015201166327066700413160ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner; /** * ??? * * @plexus.component role="foo" * * @version $Id: AbstractWithAnnoClass.java 7702 2008-08-31 01:20:23Z jvanzyl $ */ public abstract class AbstractWithAnnoClass { } AnnotationComponentGleanerTest.java000066400000000000000000000045101166327066700432520ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner; import java.util.List; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.metadata.gleaner.ann.AnnotatedComponent; import org.codehaus.plexus.metadata.gleaner.ann.AnnotatedComponentRole; import junit.framework.TestCase; /** * @author Eugene Kuleshov */ public class AnnotationComponentGleanerTest extends TestCase { public void testGlean() throws Exception { AnnotationComponentGleaner gleaner = new AnnotationComponentGleaner(); Class c = AnnotatedComponent.class; ComponentDescriptor descriptor = gleaner.glean(c.getName(), c.getClassLoader()); assertEquals("foo", descriptor.getComponentType()); assertEquals(AnnotatedComponentRole.class.getName(), descriptor.getRole()); List requirements = descriptor.getRequirements(); assertEquals(requirements.toString(), 2, requirements.size()); ComponentRequirement requirement = requirements.get(0); assertEquals("dependency", requirement.getFieldName()); assertEquals("default", requirement.getRoleHint()); ComponentRequirement requirement2 = requirements.get(1); assertEquals("dependency2", requirement2.getFieldName()); assertEquals("release,latest,snapshot", requirement2.getRoleHint()); PlexusConfiguration configuration = descriptor.getConfiguration(); assertEquals(1, configuration.getChildCount()); PlexusConfiguration child = configuration.getChild(0); assertEquals("param", child.getName()); assertEquals("value", child.getValue()); } } ChildComponent.java000066400000000000000000000015511166327066700400270ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner; /** * ??? * * @plexus.component role="org.codehaus.plexus.metadata.gleaner.ChildComponent" * * @version $Id: ChildComponent.java 7702 2008-08-31 01:20:23Z jvanzyl $ */ public class ChildComponent { } MyComponent.java000066400000000000000000000020421166327066700373650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner; /** * ??? * * @plexus.component role="org.codehaus.plexus.metadata.gleaner.MyComponent" role-hint="foo" * * @version $Rev: 7691 $ $Date: 2008-08-31 03:20:23 +0200 (dim. 31 août 2008) $ */ public class MyComponent { /** * @plexus.requirement */ private ChildComponent child; /** * @plexus.configuration default-value="bar" */ private String foo; } NoAnnotationsClass.java000066400000000000000000000014361166327066700407030ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner; /** * ??? * * @version $Id: NoAnnotationsClass.java 7702 2008-08-31 01:20:23Z jvanzyl $ */ public class NoAnnotationsClass { } NoAnnotationsIntf.java000066400000000000000000000014401166327066700405310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner; /** * ??? * * @version $Id: NoAnnotationsIntf.java 7702 2008-08-31 01:20:23Z jvanzyl $ */ public interface NoAnnotationsIntf { } QDoxComponentGleanerTest.java000066400000000000000000000112111166327066700420070ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package org.codehaus.plexus.metadata.gleaner; import java.io.File; import java.io.IOException; import java.util.List; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.configuration.PlexusConfiguration; import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaSource; /** * Tests for the {@link QDoxComponentGleaner} class. * * @version $Rev: 7828 $ $Date: 2008-11-14 23:07:56 +0100 (ven. 14 nov. 2008) $ */ public class QDoxComponentGleanerTest extends PlexusTestCase { private QDoxComponentGleaner gleaner; private JavaDocBuilder builder; // @Override protected void setUp() throws Exception { super.setUp(); gleaner = new QDoxComponentGleaner(); builder = new JavaDocBuilder(); } // @Override protected void tearDown() throws Exception { gleaner = null; builder = null; super.tearDown(); } private JavaSource addSource( final String name ) throws IOException { File url = new File( getBasedir(), "src/test/java/" + getClass().getPackage().getName().replace( '.', '/' ) + "/" + name ); assertTrue( url.exists() ); return builder.addSource( url ); } private JavaClass loadJavaClass( final String name ) throws IOException { JavaSource source = addSource( name ); assertNotNull( source ); JavaClass[] classes = source.getClasses(); assertNotNull( classes ); assertEquals( 1, classes.length ); assertNotNull( classes[0] ); return classes[0]; } private ComponentDescriptor glean( final String name, final String[] supporting ) throws Exception { if ( supporting != null ) { for ( String aSupporting : supporting ) { addSource( aSupporting ); } } return gleaner.glean( builder, loadJavaClass( name ) ); } private ComponentDescriptor glean( final String name ) throws Exception { return glean( name, null ); } public void testNoAnnotationsClass() throws Exception { ComponentDescriptor component = glean( "NoAnnotationsClass.java" ); assertNull( component ); } public void testAbstractClass() throws Exception { ComponentDescriptor component = glean( "AbstractClass.java" ); assertNull( component ); } /* public void testAbstractWithAnnoClass() throws Exception { ComponentDescriptor component = glean("AbstractWithAnnoClass.java"); assertNull(component); } */ public void testNoAnnotationsIntf() throws Exception { ComponentDescriptor component = glean( "NoAnnotationsIntf.java" ); assertNull( component ); } public void testMyComponent() throws Exception { addSource( "ChildComponent.java" ); ComponentDescriptor component = glean( "MyComponent.java" ); assertNotNull( component ); assertEquals( MyComponent.class.getName(), component.getRole() ); assertEquals( "foo", component.getRoleHint() ); List requirements = component.getRequirements(); assertNotNull( requirements ); assertEquals( 1, requirements.size() ); ComponentRequirement requirement = requirements.get( 0 ); assertNotNull( requirement ); assertEquals( ChildComponent.class.getName(), requirement.getRole() ); PlexusConfiguration config = component.getConfiguration(); assertNotNull( config ); assertEquals( 1, config.getChildCount() ); PlexusConfiguration child = config.getChild( 0 ); assertNotNull( child ); assertEquals( "foo", child.getName() ); assertEquals( "bar", child.getValue() ); } } 000077500000000000000000000000001166327066700350305ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/annAnnotatedComponent.java000066400000000000000000000024471166327066700415020ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/ann/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner.ann; import java.util.List; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Configuration; import org.codehaus.plexus.component.annotations.Requirement; /** * @author Eugene Kuleshov */ @Component(type="foo", role=AnnotatedComponentRole.class) public class AnnotatedComponent implements AnnotatedComponentRole { @Requirement(hint="default") @Configuration(name="param", value="value") AnnotatedComponentDependency dependency; @Requirement(role=AnnotatedComponentDependency.class, hints={"release", "latest", "snapshot"}) List dependency2; } AnnotatedComponentDependency.java000066400000000000000000000013611166327066700434730ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/ann/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner.ann; /** * @author Eugene Kuleshov */ public class AnnotatedComponentDependency { } AnnotatedComponentRole.java000066400000000000000000000013141166327066700423140ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/ann/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.metadata.gleaner.ann; public interface AnnotatedComponentRole { } 000077500000000000000000000000001166327066700337365ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/mergeComponentsXmlMergerTest.java000066400000000000000000000305521166327066700414160ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/mergepackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.util.List; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement; import org.codehaus.plexus.metadata.merge.support.AbstractMergeableElementList; import org.codehaus.plexus.metadata.merge.support.ComponentElement; import org.codehaus.plexus.metadata.merge.support.ComponentsElement; import org.codehaus.plexus.metadata.merge.support.RequirementsElement; import org.codehaus.plexus.util.FileUtils; import org.jdom.Document; import org.jdom.Element; import org.jdom.input.SAXBuilder; /** * Tests for {@link ComponentsXmlMerger}. * * @author Rahul Thakur * @version $Id: ComponentsXmlMergerTest.java 7828 2008-11-14 22:07:56Z dain $ */ public class ComponentsXmlMergerTest extends PlexusTestCase { public void testBasic() throws Exception { ComponentsXmlMerger merger = (ComponentsXmlMerger) lookup( Merger.class, "componentsXml" ); assertNotNull( merger ); } public void testComponentsXmlFileMerge() throws Exception { File dominantXml = getTestFile( "src/test/resources/org/codehaus/plexus/metadata/merge/dominant.xml" ); File recessiveXml = getTestFile( "src/test/resources/org/codehaus/plexus/metadata/merge/recessive.xml" ); Document dDoc = new SAXBuilder().build( dominantXml ); Document rDoc = new SAXBuilder().build( recessiveXml ); // ComponentsXmlMerger merger = new ComponentsXmlMerger (dDoc); Merger merger = lookup( Merger.class, "componentsXml" ); assertNotNull( merger ); merger.merge( dDoc, rDoc ); File merged_xml = getTestFile( "target/merged.xml" ); if ( merged_xml.exists() ) { FileUtils.forceDelete( merged_xml ); } merger.writeMergedDocument( dDoc, merged_xml ); assertTrue( merged_xml.exists() ); // read merged xml and verify it was merged as expected Document mDoc = new SAXBuilder().build( merged_xml ); Element mRootElt = mDoc.getRootElement(); assertTrue( mRootElt.getName().equals( "component-set" ) ); assertEquals( 1, mRootElt.getChildren( "components" ).size() ); List componentEltList = mRootElt.getChild( "components" ).getChildren( "component" ); assertEquals( 2, componentEltList.size() ); Element cElt = (Element) componentEltList.get( 0 ); assertEquals( "org.codehaus.plexus.metadata.component.IComponent", cElt.getChildTextTrim( "role" ) ); assertEquals( "org.codehaus.plexus.metadata.component.DominantComponent", cElt.getChildTextTrim( "implementation" ) ); assertEquals( "Should only have 1 description element.", 1, cElt.getChildren( "description" ).size() ); assertEquals( "Description for Dominant component", cElt.getChildTextTrim( "description" ) ); assertEquals( "Should only have 1 configuration element.", 1, cElt.getChildren( "configuration" ).size() ); // assert Merged configuration properties Element configurationElt = cElt.getChild( "configuration" ); assertNotNull( configurationElt ); assertEquals( 1, configurationElt.getChildren( "prop1" ).size() ); assertEquals( "Dominant Property1 value", configurationElt.getChildTextTrim( "prop1" ) ); assertEquals( 1, configurationElt.getChildren( "prop2" ).size() ); assertEquals( 0, configurationElt.getChildren( "prop3" ).size() ); // now for the second component cElt = (Element) componentEltList.get( 1 ); assertEquals( "org.codehaus.plexus.metadata.component.INonConflictingComponent", cElt.getChildTextTrim( "role" ) ); assertEquals( "org.codehaus.plexus.metadata.component.RecessiveComponent", cElt.getChildTextTrim( "implementation" ) ); assertEquals( 1, mRootElt.getChildren( "lifecycle-handler-manager" ).size() ); assertEquals( "org.codehaus.plexus.lifecycle.DefaultLifecycleHandlerManager", mRootElt .getChild( "lifecycle-handler-manager" ).getAttributeValue( "implementation" ) ); } public void testInvalidMergeableElements() throws Exception { // dominant Component Element AbstractMergeableElement dCE = new ComponentElement( new Element( "component" ) ); Element roleElt = new Element( "role" ); roleElt.setText( "org.codehaus.plexus.ISampleRole" ); dCE.addContent( roleElt ); AbstractMergeableElementList reqElt = new RequirementsElement( new Element( "requirement" ) ); // attempt and invalid merge try { dCE.merge( reqElt ); fail( "Expected MergeException!" ); } catch ( MergeException e ) { // do nothing. } } /** * Tests if <component> elements from two sets are being merged properly. * * @throws Exception if there was an unexpected error. */ public void testComponentsMerge() throws Exception { // dominant Components Element AbstractMergeableElement dParent = new ComponentsElement( new Element( "components" ) ); Element dCE = new Element( "component" ); dParent.addContent( dCE ); Element roleElt = new Element( "role" ); roleElt.setText( "org.codehaus.plexus.ISampleRole" ); dCE.addContent( roleElt ); Element roleHintElt = new Element( "role-hint" ); roleHintElt.setText( "sample-role-hint" ); dCE.addContent( roleHintElt ); Element implElt = new Element( "implementation" ); implElt.setText( "org.codehaus.plexus.DominantImplementation" ); dCE.addContent( implElt ); Element requirementsElt = new Element( "requirements" ); Element reqElt = new Element( "requirement" ); Element reqRoleElt = new Element( "role" ); reqRoleElt.setText( "org.codehaus.plexus.IRequiredRole" ); reqElt.addContent( reqRoleElt ); requirementsElt.addContent( reqElt ); dCE.addContent( requirementsElt ); // recessive Component Element AbstractMergeableElement rParent = new ComponentsElement( new Element( "components" ) ); Element rCE = new Element( "component" ); rParent.addContent( rCE ); roleElt = new Element( "role" ); roleElt.setText( "org.codehaus.plexus.ISampleRole" ); rCE.addContent( roleElt ); roleHintElt = new Element( "role-hint" ); roleHintElt.setText( "sample-role-hint" ); rCE.addContent( roleHintElt ); implElt = new Element( "implementation" ); implElt.setText( "org.codehaus.plexus.RecessiveImplementation" ); rCE.addContent( implElt ); Element lifecycleHandlerElt = new Element( "lifecycle-handler" ); rCE.addContent( lifecycleHandlerElt ); lifecycleHandlerElt.setText( "plexus-configurable" ); requirementsElt = new Element( "requirements" ); reqElt = new Element( "requirement" ); reqRoleElt = new Element( "role" ); reqRoleElt.setText( "org.codehaus.plexus.IRequiredRole" ); reqElt.addContent( reqRoleElt ); requirementsElt.addContent( reqElt ); Element reqRoleHintElt = new Element( "role-hint" ); reqRoleHintElt.setText( "recessive-required-role-hint" ); reqElt.addContent( reqRoleHintElt ); rCE.addContent( requirementsElt ); // attempt to merge dParent.merge( rParent ); assertEquals( 1, dParent.getChildren( "component" ).size() ); assertEquals( "org.codehaus.plexus.DominantImplementation", dParent.getChild( "component" ) .getChildText( "implementation" ) ); assertEquals( 1, dParent.getChild( "component" ).getChild( "requirements" ).getChildren( "requirement" ).size() ); } /** * This is deprecated as we dont' want to drill to merging * nested elements within a component.

* Keeping this around for testing MergeStrategy implmentation. * * @throws Exception */ public void testDeepComponentsMerge() throws Exception { // FIXME: Review this after MergeStrategies are in place. if ( true ) { return; } // dominant Component Element AbstractMergeableElement dCE = new ComponentElement( new Element( "component" ) ); Element roleElt = new Element( "role" ); roleElt.setText( "org.codehaus.plexus.ISampleRole" ); dCE.addContent( roleElt ); Element roleHintElt; // roleHintElt = new Element ("role-hint"); // roleHintElt.setText ("sample-hint"); // dCE.addContent (roleHintElt); Element implElt = new Element( "implementation" ); implElt.setText( "org.codehaus.plexus.DominantImplementation" ); dCE.addContent( implElt ); Element requirementsElt = new Element( "requirements" ); Element reqElt = new Element( "requirement" ); Element reqRoleElt = new Element( "role" ); reqRoleElt.setText( "org.codehaus.plexus.IRequiredRole" ); reqElt.addContent( reqRoleElt ); requirementsElt.addContent( reqElt ); dCE.addContent( requirementsElt ); // recessive Component Element AbstractMergeableElement rCE = new ComponentElement( new Element( "component" ) ); roleElt = new Element( "role" ); roleElt.setText( "org.codehaus.plexus.ISampleRole" ); rCE.addContent( roleElt ); roleHintElt = new Element( "role-hint" ); roleHintElt.setText( "recessive-hint" ); rCE.addContent( roleHintElt ); implElt = new Element( "implementation" ); implElt.setText( "org.codehaus.plexus.RecessiveImplementation" ); rCE.addContent( implElt ); Element lifecycleHandlerElt = new Element( "lifecycle-handler" ); rCE.addContent( lifecycleHandlerElt ); lifecycleHandlerElt.setText( "plexus-configurable" ); requirementsElt = new Element( "requirements" ); reqElt = new Element( "requirement" ); reqRoleElt = new Element( "role" ); reqRoleElt.setText( "org.codehaus.plexus.IRequiredRole" ); reqElt.addContent( reqRoleElt ); requirementsElt.addContent( reqElt ); Element reqRoleHintElt = new Element( "role-hint" ); reqRoleHintElt.setText( "recessive-required-role-hint" ); reqElt.addContent( reqRoleHintElt ); rCE.addContent( requirementsElt ); // attempt to merge dCE.merge( rCE ); // verify the merge assertTrue( null != dCE.getChild( "role" ) ); assertEquals( "org.codehaus.plexus.ISampleRole", dCE.getChildText( "role" ) ); assertTrue( null != dCE.getChild( "role-hint" ) ); assertEquals( "recessive-hint", dCE.getChildText( "role-hint" ) ); assertTrue( null != dCE.getChild( "lifecycle-handler" ) ); assertEquals( "plexus-configurable", dCE.getChildText( "lifecycle-handler" ) ); assertTrue( null != dCE.getChild( "requirements" ) ); assertEquals( 1, dCE.getChild( "requirements" ).getChildren( "requirement" ).size() ); assertEquals( "recessive-required-role-hint", ( (Element) dCE.getChild( "requirements" ) .getChildren( "requirement" ).get( 0 ) ).getChildText( "role-hint" ) ); } } plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/000077500000000000000000000000001166327066700263255ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/org/000077500000000000000000000000001166327066700271145ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/org/codehaus/000077500000000000000000000000001166327066700307075ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/org/codehaus/plexus/000077500000000000000000000000001166327066700322275ustar00rootroot00000000000000000077500000000000000000000000001166327066700337305ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/org/codehaus/plexus/metadata000077500000000000000000000000001166327066700350275ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/org/codehaus/plexus/metadata/mergedominant.xml000066400000000000000000000012001166327066700373530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/org/codehaus/plexus/metadata/merge org.codehaus.plexus.metadata.component.IComponent org.codehaus.plexus.metadata.component.DominantComponent Description for Dominant component Dominant Property1 value Dominant Property2 value org.codehaus.plexus.metadata.component.IComponentA recessive.xml000066400000000000000000000037021166327066700375430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/org/codehaus/plexus/metadata/merge org.codehaus.plexus.metadata.component.IComponent org.codehaus.plexus.metadata.component.RecessiveComponent Description for conflicting recessive component Recessive Property1 value Property3 value org.codehaus.plexus.metadata.component.IComponentA recessiveField org.codehaus.plexus.metadata.component.INonConflictingComponent org.codehaus.plexus.metadata.component.RecessiveComponent Description for non-conflicting recessive component Non conflicting Property1 value Non conflicting Property2 value org.codehaus.plexus.metadata.component.IComponentA webapp webapp Webapp plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/000077500000000000000000000000001166327066700301565ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/000077500000000000000000000000001166327066700320425ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/pom.xml000066400000000000000000000016061166327066700333620ustar00rootroot00000000000000 4.0.0 plexus-maven-test plexus-maven-plugin-test 0.1 Plexus Maven Plugin Test org.codehaus.plexus plexus-maven-plugin true descriptor plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/src/000077500000000000000000000000001166327066700326315ustar00rootroot00000000000000000077500000000000000000000000001166327066700334765ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/src/main000077500000000000000000000000001166327066700344175ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/src/main/java000077500000000000000000000000001166327066700352065ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/src/main/java/org000077500000000000000000000000001166327066700370015ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/src/main/java/org/codehaus000077500000000000000000000000001166327066700403215ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/src/main/java/org/codehaus/plexus000077500000000000000000000000001166327066700423235ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/src/main/java/org/codehaus/plexus/componentHello.java000066400000000000000000000002171166327066700442310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/src/main/java/org/codehaus/plexus/componentpackage org.codehaus.plexus.component; public interface Hello { final static String ROLE = Hello.class.getName(); void sayHello(); }HelloImpl.java000066400000000000000000000005261166327066700450560ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/resources/projects/project-01/src/main/java/org/codehaus/plexus/componentpackage org.codehaus.plexus.component; /** * @plexus.component */ public class HelloImpl implements Hello { /** * @plexus.configuration expression="${expression}" default-value="Hello World!" * @required */ private String message; public void sayHello() { System.out.print( message ); } }plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/sources/000077500000000000000000000000001166327066700257765ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/sources/Component.java000066400000000000000000000000711166327066700306010ustar00rootroot00000000000000/** * @plexus.component */ public class Component { } plexus-containers1.5-1.5.5/plexus-component-metadata/src/test/sources/Empty.java000066400000000000000000000000301166327066700277300ustar00rootroot00000000000000/* No class in here */ plexus-containers1.5-1.5.5/plexus-container-default/000077500000000000000000000000001166327066700223715ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/pom.xml000066400000000000000000000051531166327066700237120ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus plexus-containers 1.5.5 plexus-container-default Plexus :: Default Container The Plexus IoC container API and its default implementation. org.codehaus.plexus plexus-utils org.codehaus.plexus plexus-classworlds org.apache.xbean xbean-reflect com.google.collections google-collections junit junit maven-surefire-plugin once **/Test*.java **/Abstract*.java org.codehaus.modello modello-maven-plugin 1.1 src/main/mdo/components.mdo src/main/mdo/plexus.mdo 1.3.0 xsd-site pre-site xsd ${basedir}/target/generated-site/resources/xsd descriptor-site pre-site xdoc 1.0.0 plexus-containers1.5-1.5.5/plexus-container-default/src/000077500000000000000000000000001166327066700231605ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/000077500000000000000000000000001166327066700235745ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/000077500000000000000000000000001166327066700270435ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/pom.xml000066400000000000000000000013601166327066700303600ustar00rootroot00000000000000 4.0.0 plexus plexus-integrationTest-multiplePlexusXmls 1.0-SNAPSHOT plexus plexus-testFodder-componentWithPlexusXml 1.0 plexus plexus-container-default 1.0-alpha-3-SNAPSHOT test junit junit 3.8.1 test plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/000077500000000000000000000000001166327066700276325ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/000077500000000000000000000000001166327066700305565ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/java/000077500000000000000000000000001166327066700314775ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/java/org/000077500000000000000000000000001166327066700322665ustar00rootroot00000000000000000077500000000000000000000000001166327066700340025ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/java/org/codehaus000077500000000000000000000000001166327066700353225ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/java/org/codehaus/plexus000077500000000000000000000000001166327066700363015ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/java/org/codehaus/plexus/test000077500000000000000000000000001166327066700367155ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/java/org/codehaus/plexus/test/it000077500000000000000000000000001166327066700405735ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/java/org/codehaus/plexus/test/it/multiplxComponent.java000066400000000000000000000014631166327066700434040ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/java/org/codehaus/plexus/test/it/multiplxpackage org.codehaus.plexus.test.it.multiplx; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface Component { public static final String ROLE = Component.class.getName(); public String testValue(String input); } ComponentImpl.java000066400000000000000000000014661166327066700442310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/java/org/codehaus/plexus/test/it/multiplxpackage org.codehaus.plexus.test.it.multiplx; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class ComponentImpl implements Component { public String testValue( String input ) { return "test using: " + input; } } plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/resources/000077500000000000000000000000001166327066700325705ustar00rootroot00000000000000000077500000000000000000000000001166327066700336515ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/resources/META-INF000077500000000000000000000000001166327066700351715ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/resources/META-INF/plexusplexus.xml000066400000000000000000000003561166327066700372370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/main/resources/META-INF/plexus org.codehaus.plexus.test.it.multiplx.Component org.codehaus.plexus.test.it.multiplx.ComponentImpl plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/test/000077500000000000000000000000001166327066700306115ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/test/java/000077500000000000000000000000001166327066700315325ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/test/java/org/000077500000000000000000000000001166327066700323215ustar00rootroot00000000000000000077500000000000000000000000001166327066700340355ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/test/java/org/codehaus000077500000000000000000000000001166327066700353555ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/test/java/org/codehaus/plexus000077500000000000000000000000001166327066700363345ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/test/java/org/codehaus/plexus/test000077500000000000000000000000001166327066700367505ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/test/java/org/codehaus/plexus/test/it000077500000000000000000000000001166327066700406265ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/test/java/org/codehaus/plexus/test/it/multiplxComponentLookupTest.java000066400000000000000000000021341166327066700454650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/multi-plexus.xml/src/test/java/org/codehaus/plexus/test/it/multiplxpackage org.codehaus.plexus.test.it.multiplx; import org.codehaus.plexus.PlexusTestCase; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class ComponentLookupTest extends PlexusTestCase { public void testShouldFindComponentFromHereAndComponentFromDependency() throws Exception { Object fromHere = lookup(Component.ROLE); assertNotNull(fromHere); Object fromDependency = lookup("org.codehaus.plexus.test.fodder.withplx.TestComponent"); assertNotNull(fromDependency); } } plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/000077500000000000000000000000001166327066700257115ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/pom.xml000066400000000000000000000023141166327066700272260ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus.its plexus-its jar 1.0-SNAPSHOT plexus-its http://maven.apache.org org.codehaus.plexus plexus-container-default 1.0-alpha-41-SNAPSHOT junit junit 3.8.1 test org.codehaus.plexus plexus-maven-plugin 1.3.5 descriptor plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/000077500000000000000000000000001166327066700265005ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/main/000077500000000000000000000000001166327066700274245ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/main/java/000077500000000000000000000000001166327066700303455ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/main/java/org/000077500000000000000000000000001166327066700311345ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/main/java/org/codehaus/000077500000000000000000000000001166327066700327275ustar00rootroot00000000000000000077500000000000000000000000001166327066700341705ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/main/java/org/codehaus/plexus000077500000000000000000000000001166327066700347675ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/main/java/org/codehaus/plexus/itsApp.java000066400000000000000000000003551166327066700363550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/main/java/org/codehaus/plexus/itspackage org.codehaus.plexus.its; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.logging.Logger; /** @author Jason van Zyl */ public interface App { PlexusContainer getContainer(); Logger getLogger(); } DefaultApp.java000066400000000000000000000007571166327066700376700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/main/java/org/codehaus/plexus/itspackage org.codehaus.plexus.its; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.logging.Logger; /** * @plexus.component role-hint="standard" */ public class DefaultApp implements App { /** @plexus.requirement */ private PlexusContainer container; /** @plexus.requirement */ private Logger logger; public PlexusContainer getContainer() { return container; } public Logger getLogger() { return logger; } } DefaultLogEnabledApp.java000066400000000000000000000010331166327066700415710ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/main/java/org/codehaus/plexus/itspackage org.codehaus.plexus.its; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; /** * @plexus.component role-hint="log-enabled" */ public class DefaultLogEnabledApp extends AbstractLogEnabled implements App { /** @plexus.requirement */ private PlexusContainer container; public PlexusContainer getContainer() { return container; } public Logger getLogger() { return getLogger(); } }plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/test/000077500000000000000000000000001166327066700274575ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/test/java/000077500000000000000000000000001166327066700304005ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/test/java/org/000077500000000000000000000000001166327066700311675ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/test/java/org/codehaus/000077500000000000000000000000001166327066700327625ustar00rootroot00000000000000000077500000000000000000000000001166327066700342235ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/test/java/org/codehaus/plexus000077500000000000000000000000001166327066700350225ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/test/java/org/codehaus/plexus/itsAppTest.java000066400000000000000000000012261166327066700372460ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/plexus-its/src/test/java/org/codehaus/plexus/itspackage org.codehaus.plexus.its; import org.codehaus.plexus.PlexusTestCase; /** * Unit test for simple DefaultApp. */ public class AppTest extends PlexusTestCase { public void testApp() throws Exception { App app = (App) lookup( App.class.getName(), "standard" ); assertNotNull( app.getContainer() ); assertNotNull( app.getLogger() ); assertEquals( App.class.getName(), app.getLogger().getName() ); App logEnabledApp = (App) lookup( App.class.getName(), "log-enabled" ); assertNotNull( logEnabledApp ); assertEquals( App.class.getName(), app.getLogger().getName() ); } } plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/000077500000000000000000000000001166327066700260145ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/000077500000000000000000000000001166327066700331045ustar00rootroot00000000000000pom.xml000066400000000000000000000002731166327066700343440ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml 4.0.0 plexus plexus-testFodder-componentWithPlexusXml 1.0-SNAPSHOT 000077500000000000000000000000001166327066700336145ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src000077500000000000000000000000001166327066700345405ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main000077500000000000000000000000001166327066700354615ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/java000077500000000000000000000000001166327066700362505ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/java/org000077500000000000000000000000001166327066700400435ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/java/org/codehaus000077500000000000000000000000001166327066700413635ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/java/org/codehaus/plexus000077500000000000000000000000001166327066700423425ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/java/org/codehaus/plexus/test000077500000000000000000000000001166327066700436055ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/java/org/codehaus/plexus/test/fodder000077500000000000000000000000001166327066700453045ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/java/org/codehaus/plexus/test/fodder/withplxTestComponent.java000066400000000000000000000013661166327066700507570ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/java/org/codehaus/plexus/test/fodder/withplxpackage org.codehaus.plexus.test.fodder.withplx; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface TestComponent { public String testValueOf(String input); } TestComponentImpl.java000066400000000000000000000015041166327066700515730ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/java/org/codehaus/plexus/test/fodder/withplxpackage org.codehaus.plexus.test.fodder.withplx; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class TestComponentImpl implements TestComponent { public String testValueOf( String input ) { return "output from: " + input; } } 000077500000000000000000000000001166327066700365525ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/resources000077500000000000000000000000001166327066700377125ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/resources/META-INF000077500000000000000000000000001166327066700412325ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/resources/META-INF/plexusplexus.xml000066400000000000000000000003741166327066700433000ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/it/test-fodder/component-with-plexus.xml/src/main/resources/META-INF/plexus org.codehaus.plexus.test.fodder.withplx.TestComponent org.codehaus.plexus.test.fodder.withplx.TestComponentImpl plexus-containers1.5-1.5.5/plexus-container-default/src/main/000077500000000000000000000000001166327066700241045ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/000077500000000000000000000000001166327066700250255ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/000077500000000000000000000000001166327066700256145ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/000077500000000000000000000000001166327066700274075ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/000077500000000000000000000000001166327066700307275ustar00rootroot00000000000000ClassRealmUtil.java000066400000000000000000000050751166327066700344060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2009 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Queue; import java.util.Set; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; public class ClassRealmUtil { public static Set getContextRealms( ClassWorld world ) { Set realms = new LinkedHashSet(); for ( ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); classLoader != null; classLoader = classLoader.getParent() ) { if ( classLoader instanceof ClassRealm ) { realms.add( (ClassRealm) classLoader ); Queue queue = new LinkedList(); queue.add( (ClassRealm) classLoader ); while ( !queue.isEmpty() ) { ClassRealm realm = queue.remove(); Collection importRealms = realm.getImportRealms(); for ( ClassRealm importRealm : importRealms ) { if ( realms.add( importRealm ) ) { queue.add( importRealm ); } } ClassRealm parentRealm = realm.getParentRealm(); if ( parentRealm != null && realms.add( parentRealm ) ) { queue.add( parentRealm ); } } } } if ( world != null ) { for ( Iterator it = realms.iterator(); it.hasNext(); ) { ClassRealm realm = it.next(); if ( realm.getWorld() != world ) { it.remove(); } } } return realms; } } ComponentRegistry.java000066400000000000000000000051031166327066700352050ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.List; import java.util.Map; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; import org.codehaus.plexus.component.manager.ComponentManagerFactory; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; /** * @author Jason van Zyl * @author Kenney Westerhof * @author Dain Sundstrom */ public interface ComponentRegistry { void registerComponentManagerFactory( ComponentManagerFactory componentManagerFactory ); void addComponentDescriptor( ComponentDescriptor componentDescriptor ) throws CycleDetectedInComponentGraphException; ComponentDescriptor getComponentDescriptor( Class type, String role, String roleHint ); @Deprecated ComponentDescriptor getComponentDescriptor( String role, String roleHint, ClassRealm realm ); List> getComponentDescriptorList( Class type, String role ); Map> getComponentDescriptorMap( Class type, String role ); T lookup( Class type, String role, String roleHint ) throws ComponentLookupException; T lookup( ComponentDescriptor componentDescriptor ) throws ComponentLookupException; List lookupList( Class type, String role, List hints ) throws ComponentLookupException; Map lookupMap( Class type, String role, List hints ) throws ComponentLookupException; void release( Object component ) throws ComponentLifecycleException; void removeComponentRealm( ClassRealm classRealm ) throws PlexusContainerException; void dispose(); void addComponent( T component, String role, String roleHint ); }ContainerConfiguration.java000066400000000000000000000070201166327066700361640ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; import java.net.URL; import java.util.List; import java.util.Map; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.discovery.ComponentDiscoverer; import org.codehaus.plexus.component.discovery.ComponentDiscovererManager; import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; import org.codehaus.plexus.component.factory.ComponentFactoryManager; import org.codehaus.plexus.component.repository.ComponentRepository; import org.codehaus.plexus.configuration.source.ConfigurationSource; import org.codehaus.plexus.container.initialization.ContainerInitializationPhase; import org.codehaus.plexus.lifecycle.LifecycleHandler; import org.codehaus.plexus.lifecycle.LifecycleHandlerManager; /** * @author Jason van Zyl */ public interface ContainerConfiguration { ContainerConfiguration setName( String name ); String getName(); ContainerConfiguration setContext( Map context ); Map getContext(); ContainerConfiguration setClassWorld( ClassWorld classWorld ); ClassWorld getClassWorld(); ContainerConfiguration setRealm( ClassRealm realm ); ClassRealm getRealm(); // // Configuration // ContainerConfiguration setContainerConfiguration( String configuration ); String getContainerConfiguration(); ContainerConfiguration setContainerConfigurationURL( URL configuration ); URL getContainerConfigurationURL(); // Programmatic Container Initialization and Setup // Much of this setup and initialization can be completely hidden. It's probably not likely // someone will need to change these core components, but rather adding things like different // factories, and component managers. // Container initialization phases ContainerInitializationPhase[] getInitializationPhases(); // Component lookup manager // Component discoverer manager ContainerConfiguration addComponentDiscoverer( ComponentDiscoverer componentDiscoverer ); ContainerConfiguration addComponentDiscoveryListener( ComponentDiscoveryListener componentDiscoveryListener ); ContainerConfiguration setComponentDiscovererManager( ComponentDiscovererManager componentDiscovererManager ); ComponentDiscovererManager getComponentDiscovererManager(); // Component factory manager ContainerConfiguration setComponentFactoryManager( ComponentFactoryManager componentFactoryManager ); ComponentFactoryManager getComponentFactoryManager(); // Component manager manager // Component repository ContainerConfiguration setComponentRepository( ComponentRepository componentRepository ); ComponentRepository getComponentRepository(); // Component composer // Lifecycle handler manager ContainerConfiguration addLifecycleHandler( LifecycleHandler lifecycleHandler ); ContainerConfiguration setLifecycleHandlerManager( LifecycleHandlerManager lifecycleHandlerManager ); LifecycleHandlerManager getLifecycleHandlerManager(); // Configuration Sources ContainerConfiguration setConfigurationSource( ConfigurationSource configurationSource ); ConfigurationSource getConfigurationSource(); ContainerConfiguration addComponentDiscoverer( Class componentDiscoverer ); ContainerConfiguration addComponentDiscoveryListener( Class componentDiscoveryListener ); List getComponentDiscoverers(); List getComponentDiscoveryListeners(); } DefaultComponentRegistry.java000066400000000000000000000532541166327066700365240ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; import static org.codehaus.plexus.component.CastUtils.isAssignableFrom; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.Map.Entry; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.component.manager.ComponentManagerFactory; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRepository; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.lifecycle.LifecycleHandler; import org.codehaus.plexus.lifecycle.LifecycleHandlerManager; import org.codehaus.plexus.lifecycle.UndefinedLifecycleHandlerException; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; public class DefaultComponentRegistry implements ComponentRegistry { private static final String DEFAULT_INSTANTIATION_STRATEGY = "singleton"; private final MutablePlexusContainer container; private final ComponentRepository repository; private final LifecycleHandlerManager lifecycleHandlerManager; private final Logger logger; private boolean disposingComponents; private final Map componentManagerFactories = Collections.synchronizedMap( new TreeMap() ); private final Map> componentManagers = new TreeMap>(); private final Map> componentManagersByComponent = new IdentityHashMap>(); private final Map unmanagedComponents = new TreeMap(); public DefaultComponentRegistry( MutablePlexusContainer container, ComponentRepository repository, LifecycleHandlerManager lifecycleHandlerManager ) { this.container = container; this.repository = repository; this.lifecycleHandlerManager = lifecycleHandlerManager; logger = container.getLogger(); } public void dispose() { List> managers; synchronized ( this ) { managers = new ArrayList>( componentManagers.values() ); componentManagers.clear(); componentManagersByComponent.clear(); unmanagedComponents.clear(); disposingComponents = true; } // reverse sort the managers by startId Collections.sort( managers, new Comparator>() { public int compare( ComponentManager left, ComponentManager right ) { if (left.getStartId() < right.getStartId() ) { return 1; } else if (left.getStartId() == right.getStartId() ) { return 0; } else { return -1; } } }); // Call dispose callback outside of synchronized lock to avoid deadlocks try { for ( ComponentManager componentManager : managers ) { try { componentManager.dispose(); } catch ( Exception e ) { // todo dain use a monitor instead of a logger logger.error( "Error while disposing component manager. Continuing with the rest", e ); } } } finally { synchronized ( this ) { disposingComponents = false; } } } public void registerComponentManagerFactory( ComponentManagerFactory componentManagerFactory ) { componentManagerFactories.put( componentManagerFactory.getId(), componentManagerFactory ); } public void addComponentDescriptor( ComponentDescriptor componentDescriptor ) throws CycleDetectedInComponentGraphException { repository.addComponentDescriptor( componentDescriptor ); } @SuppressWarnings("unchecked") public synchronized void addComponent( T component, String role, String roleHint ) { ComponentDescriptor descriptor = new ComponentDescriptor(component.getClass(), null ); descriptor.setRole( role ); descriptor.setRoleHint( roleHint ); Key key = new Key( descriptor.getRealm(), role, roleHint ); unmanagedComponents.put( key, component ); } public ComponentDescriptor getComponentDescriptor( Class type, String role, String roleHint ) { return repository.getComponentDescriptor( type, role, roleHint ); } @Deprecated public ComponentDescriptor getComponentDescriptor( String role, String roleHint, ClassRealm realm ) { return repository.getComponentDescriptor( role, roleHint, realm ); } public Map> getComponentDescriptorMap( Class type, String role ) { return repository.getComponentDescriptorMap( type, role ); } public List> getComponentDescriptorList( Class type, String role ) { return repository.getComponentDescriptorList( type, role ); } public T lookup( Class type, String role, String roleHint ) throws ComponentLookupException { // verify arguments if ( type == null ) { throw new NullPointerException( "type is null" ); } if ( role == null ) { throw new NullPointerException( "role is null" ); } if ( roleHint == null ) { roleHint = ""; } return getComponent( type, role, roleHint, null ); } public T lookup( ComponentDescriptor componentDescriptor ) throws ComponentLookupException { return getComponent( componentDescriptor.getRoleClass(), componentDescriptor.getRole(), componentDescriptor.getRoleHint(), componentDescriptor ); } public Map lookupMap( Class type, String role, List roleHints ) throws ComponentLookupException { // verify arguments if ( type == null ) { throw new NullPointerException( "type is null" ); } if ( role == null ) { throw new NullPointerException( "role is null" ); } // if no hints provided, get all valid hints for this role Map components = new LinkedHashMap(); if ( roleHints == null ) { Map> componentDescriptors = getComponentDescriptorMap( type, role ); for ( Entry> entry : componentDescriptors.entrySet() ) { String roleHint = entry.getKey(); ComponentDescriptor componentDescriptor = entry.getValue(); // todo dain catch the exception... it isn't the callers problem when one component in a collection fails T component = getComponent( type, role, roleHint, componentDescriptor ); components.put( roleHint, component ); } } else { for ( String roleHint : roleHints ) { // todo dain catch the exception... it isn't the callers problem when one component in a collection fails T component = getComponent( type, role, roleHint, null ); components.put( roleHint, component ); } } return components; } public List lookupList( Class type, String role, List roleHints ) throws ComponentLookupException { // verify arguments if ( type == null ) { throw new NullPointerException( "type is null" ); } if ( role == null ) { throw new NullPointerException( "role is null" ); } // if no hints provided, get all valid hints for this role List components = new ArrayList(); if ( roleHints == null ) { List> componentDescriptors = getComponentDescriptorList( type, role ); for ( ComponentDescriptor componentDescriptor : componentDescriptors ) { // todo dain catch the exception... it isn't the callers problem when one component in a collection fails T component = getComponent( type, role, componentDescriptor.getRoleHint(), componentDescriptor ); components.add( component ); } } else { for ( String roleHint : roleHints ) { // todo dain catch the exception... it isn't the callers problem when one component in a collection fails T component = getComponent( type, role, roleHint, null ); components.add( component ); } } return components; } public void release( Object component ) throws ComponentLifecycleException { if ( component == null ) { return; } // get the component manager ComponentManager componentManager; synchronized ( this ) { componentManager = componentManagersByComponent.get( component ); if ( componentManager == null ) { // This needs to be tracked down but the user doesn't need to see this // during the maven bootstrap this logger is null. //logger.debug( "Component manager not found for returned component. Ignored. component=" + component ); return; } } // release the component from the manager componentManager.release( component ); // only drop the reference to this component if there are no other uses of the component // multiple uses of a component is common with singleton beans if ( componentManager.getConnections() <= 0 ) { synchronized ( this ) { componentManagersByComponent.remove( component ); } } } public void removeComponentRealm( ClassRealm classRealm ) throws PlexusContainerException { repository.removeComponentRealm( classRealm ); List> dispose = new ArrayList>(); try { synchronized ( this ) { for ( Iterator>> it = componentManagers.entrySet().iterator(); it.hasNext(); ) { Entry> entry = it.next(); Key key = entry.getKey(); ComponentManager componentManager = entry.getValue(); if ( key.realm.equals( classRealm ) ) { dispose.add( componentManager ); it.remove(); } else { componentManager.dissociateComponentRealm( classRealm ); } } } // Call dispose callback outside of synchronized lock to avoid deadlocks for ( ComponentManager componentManager : dispose ) { componentManager.dispose(); } } catch ( ComponentLifecycleException e ) { throw new PlexusContainerException( "Failed to dissociate component realm: " + classRealm.getId(), e ); } } private T getComponent( Class type, String role, String roleHint, ComponentDescriptor descriptor ) throws ComponentLookupException { // lookup for unmanaged components first T component = this.getUnmanagedComponent( role, roleHint ); // weird syntax due to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954 if ( component != null ) { return component; } ComponentManager componentManager = getComponentManager( type, role, roleHint, descriptor ); // Get instance from manager... may result in creation try { component = componentManager.getComponent(); synchronized ( this ) { componentManagersByComponent.put( component, componentManager ); } return component; } catch ( ComponentInstantiationException e ) { throw new ComponentLookupException( "Unable to lookup component '" + componentManager.getRole() + "', it could not be created.", componentManager.getRole(), componentManager.getRoleHint(), componentManager.getRealm(), e ); } catch ( ComponentLifecycleException e ) { throw new ComponentLookupException( "Unable to lookup component '" + componentManager.getRole() + "', it could not be started.", componentManager.getRole(), componentManager.getRoleHint(), componentManager.getRealm(), e ); } } @SuppressWarnings("unchecked") private synchronized T getUnmanagedComponent( String role, String roleHint ) { Set realms = getSearchRealms( true ); if ( realms != null ) { // ignore unmanaged components, they are not associated with realms // but lookup realm is provided via thread context classloader return null; } else { if ( StringUtils.isEmpty( roleHint ) ) { roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT; } return (T) unmanagedComponents.get( new Key( null, role, roleHint ) ); } } private synchronized ComponentManager getComponentManager( Class type, String role, String roleHint, ComponentDescriptor descriptor ) throws ComponentLookupException { if ( disposingComponents ) { throw new ComponentLookupException("ComponentRegistry is not active", role, roleHint ); } if ( descriptor == null ) { descriptor = getComponentDescriptor( type, role, roleHint ); } ComponentManager componentManager = null; if ( descriptor != null ) { componentManager = getComponentManager( type, role, descriptor.getRoleHint(), descriptor.getRealm() ); } else { componentManager = getComponentManager( type, role, roleHint ); } if ( componentManager == null ) { // we need to create a component manager, but first we must have a descriptor if ( descriptor == null ) { descriptor = getComponentDescriptor( type, role, roleHint ); if ( descriptor == null ) { throw new ComponentLookupException( "Component descriptor cannot be found in the component repository", role, roleHint ); } // search also into descriptor realm as the key of a created component is per descriptor realm componentManager = getComponentManager( type, role, descriptor.getRoleHint(), descriptor.getRealm() ); } if ( componentManager == null ) { componentManager = createComponentManager( descriptor, role, descriptor.getRoleHint() ); } } return componentManager; } @SuppressWarnings( "unchecked" ) private ComponentManager getComponentManager( Class type, String role, String roleHint ) { Set realms = getSearchRealms( false ); // return the component in the first realm for ( ClassRealm realm : realms ) { ComponentManager manager = componentManagers.get( new Key( realm, role, roleHint ) ); if ( manager != null && isAssignableFrom( type, manager.getType() ) ) { return (ComponentManager) manager; } } return null; } @SuppressWarnings( "unchecked" ) private ComponentManager getComponentManager( Class type, String role, String roleHint, ClassRealm realm ) { ComponentManager manager = componentManagers.get( new Key( realm, role, roleHint ) ); if ( manager != null && isAssignableFrom( type, manager.getType() ) ) { return (ComponentManager) manager; } return null; } @SuppressWarnings( "unchecked" ) private Set getSearchRealms( boolean specifiedOnly ) { // determine realms to search Set realms = ClassRealmUtil.getContextRealms( container.getClassWorld() ); if ( realms.isEmpty() ) { if ( specifiedOnly ) { return null; } realms.addAll( container.getClassWorld().getRealms() ); } return realms; } private ComponentManager createComponentManager( ComponentDescriptor descriptor, String role, String roleHint ) throws ComponentLookupException { // Get the ComponentManagerFactory String instantiationStrategy = descriptor.getInstantiationStrategy(); if ( instantiationStrategy == null ) { instantiationStrategy = DEFAULT_INSTANTIATION_STRATEGY; } ComponentManagerFactory componentManagerFactory = componentManagerFactories.get( instantiationStrategy ); if ( componentManagerFactory == null ) { throw new ComponentLookupException( "Unsupported instantiation strategy: " + instantiationStrategy, role, roleHint, descriptor.getRealm() ); } // Get the LifecycleHandler LifecycleHandler lifecycleHandler; try { lifecycleHandler = lifecycleHandlerManager.getLifecycleHandler( descriptor.getLifecycleHandler() ); } catch ( UndefinedLifecycleHandlerException e ) { throw new ComponentLookupException( "Undefined lifecycle handler: " + descriptor.getLifecycleHandler(), role, roleHint, descriptor.getRealm() ); } // Create the ComponentManager ComponentManager componentManager = componentManagerFactory.createComponentManager( container, lifecycleHandler, descriptor, role, roleHint ); // Add componentManager to indexes Key key = new Key( descriptor.getRealm(), role, roleHint ); componentManagers.put( key, componentManager ); return componentManager; } private static class Key implements Comparable { private final ClassRealm realm; private final String role; private final String roleHint; private final int hashCode; private Key( ClassRealm realm, String role, String roleHint ) { this.realm = realm; if ( role == null ) { role = "null"; } this.role = role; if ( roleHint == null ) { roleHint = "null"; } this.roleHint = roleHint; int hashCode; hashCode = ( realm != null ? realm.hashCode() : 0 ); hashCode = 31 * hashCode + role.hashCode(); hashCode = 31 * hashCode + roleHint.hashCode(); this.hashCode = hashCode; } public boolean equals( Object o ) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } Key key = (Key) o; return !( realm != null ? !realm.equals( key.realm ) : key.realm != null ) && role.equals( key.role ) && roleHint.equals( key.roleHint ); } public int hashCode() { return hashCode; } public String toString() { return realm + "/" + role + "/" + roleHint; } public int compareTo( Key o ) { int value; if ( realm != null ) { value = o.realm == null? -1 : realm.getId().compareTo( o.realm.getId() ); } else { value = o.realm == null ? 0 : 1; } if ( value == 0 ) { value = role.compareTo( o.role ); if ( value == 0 ) { value = roleHint.compareTo( o.roleHint ); } } return value; } } } DefaultContainerConfiguration.java000066400000000000000000000275201166327066700375000ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.discovery.ComponentDiscoverer; import org.codehaus.plexus.component.discovery.ComponentDiscovererManager; import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; import org.codehaus.plexus.component.discovery.DefaultComponentDiscoverer; import org.codehaus.plexus.component.discovery.DefaultComponentDiscovererManager; import org.codehaus.plexus.component.discovery.PlexusXmlComponentDiscoverer; import org.codehaus.plexus.component.factory.ComponentFactoryManager; import org.codehaus.plexus.component.factory.DefaultComponentFactoryManager; import org.codehaus.plexus.component.repository.ComponentRepository; import org.codehaus.plexus.component.repository.DefaultComponentRepository; import org.codehaus.plexus.configuration.source.ConfigurationSource; import org.codehaus.plexus.container.initialization.ContainerInitializationPhase; import org.codehaus.plexus.container.initialization.InitializeComponentDiscovererManagerPhase; import org.codehaus.plexus.container.initialization.InitializeComponentFactoryManagerPhase; import org.codehaus.plexus.container.initialization.InitializeComponentRegistryPhase; import org.codehaus.plexus.container.initialization.InitializeContainerConfigurationSourcePhase; import org.codehaus.plexus.container.initialization.InitializeLoggerManagerPhase; import org.codehaus.plexus.container.initialization.InitializeSystemPropertiesPhase; import org.codehaus.plexus.container.initialization.InitializeUserConfigurationSourcePhase; import org.codehaus.plexus.lifecycle.BasicLifecycleHandler; import org.codehaus.plexus.lifecycle.DefaultLifecycleHandlerManager; import org.codehaus.plexus.lifecycle.LifecycleHandler; import org.codehaus.plexus.lifecycle.LifecycleHandlerManager; import org.codehaus.plexus.personality.plexus.lifecycle.phase.ConfigurablePhase; import org.codehaus.plexus.personality.plexus.lifecycle.phase.ContextualizePhase; import org.codehaus.plexus.personality.plexus.lifecycle.phase.DisposePhase; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializePhase; import org.codehaus.plexus.personality.plexus.lifecycle.phase.LogDisablePhase; import org.codehaus.plexus.personality.plexus.lifecycle.phase.LogEnablePhase; import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartPhase; import org.codehaus.plexus.personality.plexus.lifecycle.phase.StopPhase; /** @author Jason van Zyl */ public class DefaultContainerConfiguration implements ContainerConfiguration { private String name; private Map context; private ClassWorld classWorld; private ClassRealm realm; private String containerConfiguration; private URL containerConfigurationURL; private ConfigurationSource configurationSource; private List componentDiscoverers = new ArrayList(); private List componentDiscoveryListeners = new ArrayList(); public ContainerConfiguration setName( String name ) { this.name = name; return this; } public ContainerConfiguration setContext( Map context ) { this.context = context; return this; } public ContainerConfiguration setClassWorld( ClassWorld classWorld ) { this.classWorld = classWorld; return this; } public ContainerConfiguration setRealm( ClassRealm realm ) { this.realm = realm; return this; } public ContainerConfiguration setContainerConfiguration( String containerConfiguration ) { this.containerConfiguration = containerConfiguration; return this; } public String getContainerConfiguration() { return containerConfiguration; } public ContainerConfiguration setContainerConfigurationURL( URL containerConfiguration ) { this.containerConfigurationURL = containerConfiguration; return this; } public URL getContainerConfigurationURL() { return containerConfigurationURL; } public String getName() { return name; } public Map getContext() { return context; } public ClassWorld getClassWorld() { return classWorld; } public ClassRealm getRealm() { return realm; } // Programmatic Container Initialization and Setup public ContainerConfiguration setInitializationPhases( ContainerInitializationPhase[] initializationPhases ) { this.initializationPhases = initializationPhases; return this; } public ContainerInitializationPhase[] getInitializationPhases() { return initializationPhases; } private ContainerInitializationPhase[] initializationPhases = { new InitializeComponentRegistryPhase(), new InitializeComponentFactoryManagerPhase(), new InitializeContainerConfigurationSourcePhase(), new InitializeLoggerManagerPhase(), new InitializeSystemPropertiesPhase(), new InitializeComponentDiscovererManagerPhase(), new InitializeUserConfigurationSourcePhase() }; // Component discoverer private ComponentDiscovererManager componentDiscovererManager; public ContainerConfiguration addComponentDiscoveryListener( ComponentDiscoveryListener componentDiscoveryListener ) { getComponentDiscovererManager().registerComponentDiscoveryListener( componentDiscoveryListener ); return this; } public ContainerConfiguration addComponentDiscoverer( ComponentDiscoverer componentDiscoverer ) { ((DefaultComponentDiscovererManager)getComponentDiscovererManager()).addComponentDiscoverer( componentDiscoverer ); return this; } public ContainerConfiguration addComponentDiscoverer( Class clazz ) { componentDiscoverers.add( clazz ); return this; } public ContainerConfiguration addComponentDiscoveryListener( Class clazz ) { componentDiscoveryListeners.add( clazz ); return this; } public List getComponentDiscoverers() { return componentDiscoverers; } public List getComponentDiscoveryListeners() { return componentDiscoveryListeners; } public ContainerConfiguration setComponentDiscovererManager( ComponentDiscovererManager componentDiscovererManager ) { this.componentDiscovererManager = componentDiscovererManager; return this; } public ComponentDiscovererManager getComponentDiscovererManager() { if ( componentDiscovererManager == null ) { componentDiscovererManager = new DefaultComponentDiscovererManager(); ((DefaultComponentDiscovererManager)componentDiscovererManager).addComponentDiscoverer( new DefaultComponentDiscoverer() ); ((DefaultComponentDiscovererManager)componentDiscovererManager).addComponentDiscoverer( new PlexusXmlComponentDiscoverer() ); } return componentDiscovererManager; } private ComponentFactoryManager componentFactoryManager; public ComponentFactoryManager getComponentFactoryManager() { if ( componentFactoryManager == null ) { componentFactoryManager = new DefaultComponentFactoryManager(); } return componentFactoryManager; } public ContainerConfiguration setComponentFactoryManager( ComponentFactoryManager componentFactoryManager ) { this.componentFactoryManager = componentFactoryManager; return this; } private ComponentRepository componentRepository; public ContainerConfiguration setComponentRepository( ComponentRepository componentRepository ) { this.componentRepository = componentRepository; return this; } public ComponentRepository getComponentRepository() { if ( componentRepository == null ) { componentRepository = new DefaultComponentRepository(); } return componentRepository; } // Lifecycle handler manager private LifecycleHandlerManager lifecycleHandlerManager; public ContainerConfiguration addLifecycleHandler( LifecycleHandler lifecycleHandler ) { getLifecycleHandlerManager().addLifecycleHandler( lifecycleHandler ); return this; } public ContainerConfiguration setLifecycleHandlerManager( LifecycleHandlerManager lifecycleHandlerManager ) { this.lifecycleHandlerManager = lifecycleHandlerManager; return this; } public LifecycleHandlerManager getLifecycleHandlerManager() { if ( lifecycleHandlerManager == null ) { lifecycleHandlerManager = new DefaultLifecycleHandlerManager(); // Plexus LifecycleHandler plexus = new BasicLifecycleHandler( "plexus" ); // Begin plexus.addBeginSegment( new LogEnablePhase() ); plexus.addBeginSegment( new ContextualizePhase() ); // plexus.addBeginSegment( new AutoConfigurePhase() ); plexus.addBeginSegment( new InitializePhase() ); plexus.addBeginSegment( new StartPhase() ); // End plexus.addEndSegment( new StopPhase() ); plexus.addEndSegment( new DisposePhase() ); plexus.addEndSegment( new LogDisablePhase() ); lifecycleHandlerManager.addLifecycleHandler( plexus ); // Basic LifecycleHandler basic = new BasicLifecycleHandler( "basic" ); // Begin basic.addBeginSegment( new LogEnablePhase() ); basic.addBeginSegment( new ContextualizePhase() ); // basic.addBeginSegment( new AutoConfigurePhase() ); basic.addBeginSegment( new InitializePhase() ); basic.addBeginSegment( new StartPhase() ); // End basic.addEndSegment( new StopPhase() ); basic.addEndSegment( new DisposePhase() ); basic.addEndSegment( new LogDisablePhase() ); lifecycleHandlerManager.addLifecycleHandler( basic ); // Plexus configurable LifecycleHandler plexusConfigurable = new BasicLifecycleHandler( "plexus-configurable" ); // Begin plexusConfigurable.addBeginSegment( new LogEnablePhase() ); plexusConfigurable.addBeginSegment( new ContextualizePhase() ); plexusConfigurable.addBeginSegment( new ConfigurablePhase() ); plexusConfigurable.addBeginSegment( new InitializePhase() ); plexusConfigurable.addBeginSegment( new StartPhase() ); // End plexusConfigurable.addEndSegment( new StopPhase() ); plexusConfigurable.addEndSegment( new DisposePhase() ); plexusConfigurable.addEndSegment( new LogDisablePhase() ); lifecycleHandlerManager.addLifecycleHandler( plexusConfigurable ); // Passive LifecycleHandler passive = new BasicLifecycleHandler( "passive" ); lifecycleHandlerManager.addLifecycleHandler( passive ); // Bootstrap LifecycleHandler bootstrap = new BasicLifecycleHandler( "bootstrap" ); bootstrap.addBeginSegment( new ContextualizePhase() ); lifecycleHandlerManager.addLifecycleHandler( bootstrap ); } return lifecycleHandlerManager; } // Configuration Sources public ContainerConfiguration setConfigurationSource( ConfigurationSource configurationSource ) { this.configurationSource = configurationSource; return this; } public ConfigurationSource getConfigurationSource() { return configurationSource; } } DefaultPlexusContainer.java000066400000000000000000000760121166327066700361510ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import static org.codehaus.plexus.PlexusConstants.PLEXUS_DEFAULT_HINT; import static org.codehaus.plexus.component.CastUtils.cast; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; import org.codehaus.plexus.component.discovery.ComponentDiscoverer; import org.codehaus.plexus.component.discovery.ComponentDiscovererManager; import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent; import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; import org.codehaus.plexus.component.factory.ComponentFactoryManager; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.io.PlexusTools; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.configuration.PlexusConfigurationMerger; import org.codehaus.plexus.configuration.source.ConfigurationSource; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.container.initialization.ContainerInitializationContext; import org.codehaus.plexus.container.initialization.ContainerInitializationPhase; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.context.ContextMapAdapter; import org.codehaus.plexus.context.DefaultContext; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.InterpolationFilterReader; import org.codehaus.plexus.util.ReaderFactory; /** * Default implementation of PlexusContainer and MutablePlexusContainer. * @author Jason van Zyl * @author Kenney Westerhof */ public class DefaultPlexusContainer extends AbstractLogEnabled implements MutablePlexusContainer { protected static final String DEFAULT_CONTAINER_NAME = "default"; protected static final String DEFAULT_REALM_NAME = "plexus.core"; /** * Arbitrary data associated with the container. Data in the container has highest precedence when configuring * a component to create. */ protected Context containerContext; protected PlexusConfiguration configuration; // todo: don't use a reader protected Reader configurationReader; protected ClassWorld classWorld; protected ClassRealm containerRealm; // ---------------------------------------------------------------------------- // Core components // ---------------------------------------------------------------------------- private ComponentRegistry componentRegistry; /** * Simple index (registry) of ComponentDiscovers and ComponentDiscoveryListener. */ protected ComponentDiscovererManager componentDiscovererManager; /** * Trivial class to look-up ComponentFactory instances in this container. */ protected ComponentFactoryManager componentFactoryManager; /** * Generic logger interface. */ protected LoggerManager loggerManager; /** * Converts a ComponentDescriptor into PlexusConfiguration. */ protected ConfigurationSource configurationSource; // ---------------------------------------------------------------------------- // // ---------------------------------------------------------------------------- // TODO: Is there a more threadpool-friendly way to do this? private ThreadLocal lookupRealm = new ThreadLocal(); public void addComponent( Object component, String role ) { addComponent( component, role, PLEXUS_DEFAULT_HINT ); } public void addComponent( T component, Class role, String roleHint ) { addComponent( component, role.getName(), roleHint ); } public void addComponent( Object component, String role, String roleHint ) { if ( roleHint == null ) { roleHint = PLEXUS_DEFAULT_HINT; } getComponentRegistry().addComponent( component, role, roleHint ); } public ClassRealm setLookupRealm( ClassRealm realm ) { ClassRealm oldRealm = lookupRealm.get(); lookupRealm.set( realm ); return oldRealm; } public ClassRealm getLookupRealm() { return lookupRealm.get(); } // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- public DefaultPlexusContainer() throws PlexusContainerException { construct( new DefaultContainerConfiguration() ); } public DefaultPlexusContainer( ContainerConfiguration c ) throws PlexusContainerException { construct( c ); } public ClassRealm createChildRealm( String id ) { try { return containerRealm.createChildRealm( id ); } catch ( DuplicateRealmException e ) { try { return classWorld.getRealm( id ); } catch ( NoSuchRealmException e1 ) { return null; } } } private void construct( ContainerConfiguration c ) throws PlexusContainerException { configurationSource = c.getConfigurationSource(); // ---------------------------------------------------------------------------- // ClassWorld // ---------------------------------------------------------------------------- classWorld = c.getClassWorld(); // Make sure we have a valid ClassWorld if ( classWorld == null ) { classWorld = new ClassWorld( DEFAULT_REALM_NAME, Thread.currentThread().getContextClassLoader() ); } containerRealm = c.getRealm(); if ( containerRealm == null ) { try { containerRealm = classWorld.getRealm( DEFAULT_REALM_NAME ); } catch ( NoSuchRealmException e ) { containerRealm = (ClassRealm) classWorld.getRealms().iterator().next(); if ( containerRealm == null ) { System.err.println( "No container realm! Expect errors." ); new Throwable().printStackTrace(); } } } setLookupRealm( containerRealm ); // ---------------------------------------------------------------------------- // Context // ---------------------------------------------------------------------------- if ( c.getContext() != null ) { containerContext = new DefaultContext( c.getContext() ); } else { containerContext = new DefaultContext(); } // ---------------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------------- InputStream in = null; if ( c.getContainerConfiguration() != null ) { in = toStream( c.getContainerConfiguration() ); } try { if ( c.getContainerConfigurationURL() != null ) { in = c.getContainerConfigurationURL().openStream(); } } catch ( IOException e ) { throw new PlexusContainerException( "Error reading configuration URL", e ); } try { configurationReader = in == null ? null : ReaderFactory.newXmlReader( in ); } catch ( IOException e ) { throw new PlexusContainerException( "Error reading configuration file", e ); } try { initialize( c ); start(); } finally { IOUtil.close( configurationReader ); } for( Class clazz : c.getComponentDiscoverers() ) { try { ComponentDiscoverer cd = (ComponentDiscoverer) lookup( clazz ); componentDiscovererManager.addComponentDiscoverer( cd ); } catch ( ComponentLookupException e ) { } } for( Class clazz : c.getComponentDiscoveryListeners() ) { try { ComponentDiscoveryListener cdl = (ComponentDiscoveryListener) lookup( clazz ); componentDiscovererManager.registerComponentDiscoveryListener( cdl ); } catch ( ComponentLookupException e ) { } } } // ---------------------------------------------------------------------------- // Lookup // ---------------------------------------------------------------------------- private Class getInterfaceClass( String role, String hint ) { ComponentDescriptor cd; if ( hint == null ) { cd = getComponentDescriptor( role ); } else { cd = getComponentDescriptor( role, hint ); } if ( cd != null ) { try { ClassRealm realm = getLookupRealm(); if ( realm != null ) { return realm.loadClass( role ); } else { ClassLoader loader = cd.getImplementationClass().getClassLoader(); if ( loader != null ) { return loader.loadClass( role ); } } } catch ( ClassNotFoundException e ) { return Object.class; } } return Object.class; } private Class getRoleClass( String role ) { return getInterfaceClass( role, null ); } private Class getRoleClass( String role, String hint ) { return getInterfaceClass( role, hint ); } public Object lookup( String role ) throws ComponentLookupException { return componentRegistry.lookup( getRoleClass( role ), role, "" ); } public Object lookup( String role, String roleHint ) throws ComponentLookupException { return componentRegistry.lookup( getRoleClass( role, roleHint ), role, roleHint ); } public T lookup( Class type ) throws ComponentLookupException { return componentRegistry.lookup( type, type.getName(), "" ); } public T lookup( Class type, String roleHint ) throws ComponentLookupException { return componentRegistry.lookup( type, type.getName(), roleHint ); } public T lookup( Class type, String role, String roleHint ) throws ComponentLookupException { return componentRegistry.lookup( type, role, roleHint ); } public T lookup( ComponentDescriptor componentDescriptor ) throws ComponentLookupException { return componentRegistry.lookup( componentDescriptor ); } public List lookupList( String role ) throws ComponentLookupException { return cast(componentRegistry.lookupList( getRoleClass( role ), role, null)); } public List lookupList( String role, List roleHints ) throws ComponentLookupException { return cast(componentRegistry.lookupList( getRoleClass( role ), role, roleHints )); } public List lookupList( Class type ) throws ComponentLookupException { return componentRegistry.lookupList( type, type.getName(), null ); } public List lookupList( Class type, List roleHints ) throws ComponentLookupException { return componentRegistry.lookupList( type, type.getName(), roleHints ); } public Map lookupMap( String role ) throws ComponentLookupException { return cast(componentRegistry.lookupMap( getRoleClass( role ), role, null )); } public Map lookupMap( String role, List roleHints ) throws ComponentLookupException { return cast(componentRegistry.lookupMap( getRoleClass( role ), role, roleHints )); } public Map lookupMap( Class type ) throws ComponentLookupException { return componentRegistry.lookupMap( type, type.getName(), null ); } public Map lookupMap( Class type, List roleHints ) throws ComponentLookupException { return componentRegistry.lookupMap( type, type.getName(), roleHints ); } // ---------------------------------------------------------------------- // Component Descriptor Lookup // ---------------------------------------------------------------------- public boolean hasComponent( String role ) { return componentRegistry.getComponentDescriptor( Object.class, role, "" ) != null; } public boolean hasComponent( String role, String roleHint ) { return componentRegistry.getComponentDescriptor( Object.class, role, roleHint ) != null; } public boolean hasComponent( Class type ) { return componentRegistry.getComponentDescriptor( type, type.getName(), "" ) != null; } public boolean hasComponent( Class type, String roleHint ) { return componentRegistry.getComponentDescriptor( type, type.getName(), roleHint ) != null; } public boolean hasComponent( Class type, String role, String roleHint ) { return componentRegistry.getComponentDescriptor( type, role, roleHint ) != null; } public ComponentDescriptor getComponentDescriptor( String role ) { return componentRegistry.getComponentDescriptor( Object.class, role, "" ); } public ComponentDescriptor getComponentDescriptor( String role, String roleHint ) { return componentRegistry.getComponentDescriptor( Object.class, role, roleHint ); } public ComponentDescriptor getComponentDescriptor( Class type, String role, String roleHint ) { return componentRegistry.getComponentDescriptor( type, role, roleHint ); } public Map> getComponentDescriptorMap( String role ) { return cast(componentRegistry.getComponentDescriptorMap( Object.class, role )); } public Map> getComponentDescriptorMap( Class type, String role ) { return componentRegistry.getComponentDescriptorMap( type, role ); } public List> getComponentDescriptorList( String role ) { return cast(componentRegistry.getComponentDescriptorList( Object.class, role )); } public List> getComponentDescriptorList( Class type, String role ) { return componentRegistry.getComponentDescriptorList( type, role ); } public void addComponentDescriptor( ComponentDescriptor componentDescriptor ) throws CycleDetectedInComponentGraphException { if ( componentDescriptor.getRealm() == null ) { componentDescriptor.setRealm( this.containerRealm ); // throw new ComponentImplementationNotFoundException( "ComponentDescriptor is missing realmId" ); } componentRegistry.addComponentDescriptor( componentDescriptor ); } // ---------------------------------------------------------------------- // Component Release // ---------------------------------------------------------------------- public void release( Object component ) throws ComponentLifecycleException { componentRegistry.release( component ); } public void releaseAll( Map components ) throws ComponentLifecycleException { for ( Object component : components.values() ) { release( component ); } } public void releaseAll( List components ) throws ComponentLifecycleException { for ( Object component : components ) { release( component ); } } // ---------------------------------------------------------------------- // Lifecycle Management // ---------------------------------------------------------------------- protected void initialize( ContainerConfiguration containerConfiguration ) throws PlexusContainerException { try { initializeConfiguration( containerConfiguration ); initializePhases( containerConfiguration ); containerContext.put( PlexusConstants.PLEXUS_KEY, this ); discoverComponents( getContainerRealm() ); PlexusConfiguration[] loadOnStartComponents = getConfiguration().getChild( "load-on-start" ).getChildren( "component" ); getLogger().debug( "Found " + loadOnStartComponents.length + " components to load on start" ); ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); try { for ( PlexusConfiguration loadOnStartComponent : loadOnStartComponents ) { String role = loadOnStartComponent.getChild( "role" ).getValue( null ); String roleHint = loadOnStartComponent.getChild( "role-hint" ).getValue( null ); if ( role == null ) { throw new PlexusContainerException( "Missing 'role' element from load-on-start." ); } if ( roleHint == null ) { roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT; } if ( roleHint.equals( "*" ) ) { getLogger().info( "Loading on start all components with [role]: " + "[" + role + "]" ); lookupList( role ); } else { getLogger().info( "Loading on start [role,roleHint]: " + "[" + role + "," + roleHint + "]" ); lookup( role, roleHint ); } } } catch ( ComponentLookupException e ) { throw new PlexusContainerException( "Error looking up load-on-start component.", e ); } finally { Thread.currentThread().setContextClassLoader( prevCl ); } } catch ( ContextException e ) { throw new PlexusContainerException( "Error processing configuration", e ); } catch ( PlexusConfigurationException e ) { throw new PlexusContainerException( "Error configuring components", e ); } catch ( IOException e ) { throw new PlexusContainerException( "Error reading configuration file", e ); } catch ( CycleDetectedInComponentGraphException e ) { throw new PlexusContainerException( "Cycle detected in component graph in the system: ", e ); } } protected void initializePhases( ContainerConfiguration containerConfiguration ) throws PlexusContainerException { ContainerInitializationPhase[] initPhases = containerConfiguration.getInitializationPhases(); ContainerInitializationContext initializationContext = new ContainerInitializationContext( this, classWorld, containerRealm, configuration, containerConfiguration ); for ( ContainerInitializationPhase phase : initPhases ) { try { phase.execute( initializationContext ); } catch ( Exception e ) { throw new PlexusContainerException( "Error initializaing container in " + phase.getClass().getName() + ".", e ); } } } protected void start() throws PlexusContainerException { // XXX this is called after initializeConfiguration - is this correct? configuration = null; } public void dispose() { try { componentRegistry.dispose(); boolean needToDisposeRealm = false; try { containerRealm.setParentRealm( null ); if ( needToDisposeRealm ) { classWorld.disposeRealm( containerRealm.getId() ); } } catch ( NoSuchRealmException e ) { getLogger().debug( "Failed to dispose realm." ); } } finally { lookupRealm.set( null ); } } public void addContextValue( Object key, Object value ) { containerContext.put( key, value ); } // ---------------------------------------------------------------------- // Misc Configuration // ---------------------------------------------------------------------- public ClassWorld getClassWorld() { return classWorld; } public void setClassWorld( ClassWorld classWorld ) { this.classWorld = classWorld; } public ClassRealm getContainerRealm() { return containerRealm; } public void setContainerRealm( ClassRealm containerRealm ) { this.containerRealm = containerRealm; } // ---------------------------------------------------------------------- // Context // ---------------------------------------------------------------------- public Context getContext() { return containerContext; } // ---------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------- // TODO: put this in a separate helper class and turn into a component if possible, too big. protected void initializeConfiguration( ContainerConfiguration c ) throws PlexusConfigurationException, ContextException, IOException { // We need an empty plexus configuration for merging. This is a function of removing the // plexus-boostrap.xml file. configuration = new XmlPlexusConfiguration( "plexus" ); if ( configurationReader != null ) { // User userConfiguration PlexusConfiguration userConfiguration = PlexusTools.buildConfiguration( "", getInterpolationConfigurationReader( configurationReader ) ); // Merger of bootstrapConfiguration and user userConfiguration configuration = PlexusConfigurationMerger.merge( userConfiguration, configuration ); } } protected Reader getInterpolationConfigurationReader( Reader reader ) { return new InterpolationFilterReader( reader, new ContextMapAdapter( containerContext ) ); } public Logger getLogger() { return super.getLogger(); } // ---------------------------------------------------------------------- // Discovery // ---------------------------------------------------------------------- public void registerComponentDiscoveryListener( ComponentDiscoveryListener listener ) { componentDiscovererManager.registerComponentDiscoveryListener( listener ); } public void removeComponentDiscoveryListener( ComponentDiscoveryListener listener ) { componentDiscovererManager.removeComponentDiscoveryListener( listener ); } // ---------------------------------------------------------------------------- // Mutable Container Interface // ---------------------------------------------------------------------------- public ComponentRegistry getComponentRegistry() { return componentRegistry; } public void setComponentRegistry( ComponentRegistry componentRegistry ) { this.componentRegistry = componentRegistry; } public ComponentDiscovererManager getComponentDiscovererManager() { return componentDiscovererManager; } public void setComponentDiscovererManager( ComponentDiscovererManager componentDiscovererManager ) { this.componentDiscovererManager = componentDiscovererManager; } public ComponentFactoryManager getComponentFactoryManager() { return componentFactoryManager; } public void setComponentFactoryManager( ComponentFactoryManager componentFactoryManager ) { this.componentFactoryManager = componentFactoryManager; } // Configuration public PlexusConfiguration getConfiguration() { return configuration; } public void setConfiguration( PlexusConfiguration configuration ) { this.configuration = configuration; } // ---------------------------------------------------------------------------- // Component Realms // ---------------------------------------------------------------------------- public ClassRealm getComponentRealm( String realmId ) { ClassRealm realm = null; try { realm = classWorld.getRealm( realmId ); } catch ( NoSuchRealmException e ) { // This should never happen: when a component is discovered, it is discovered from a realm and // it is at that point the realm id is assigned to the component descriptor. } if ( realm == null ) { // The core components need the container realm. realm = containerRealm; } return realm; } public void removeComponentRealm( ClassRealm realm ) throws PlexusContainerException { if ( getContainerRealm().getId().equals( realm.getId() ) ) { throw new IllegalArgumentException( "Cannot remove container realm: " + realm.getId() + "\n(trying to remove container realm as if it were a component realm)." ); } componentRegistry.removeComponentRealm( realm ); ClassRealm lookupRealm = getLookupRealm(); if ( ( lookupRealm != null ) && lookupRealm.getId().equals( realm.getId() ) ) { setLookupRealm( getContainerRealm() ); } } private InputStream toStream( String resource ) throws PlexusContainerException { if ( resource == null ) { return null; } String relativeResource = resource; if ( resource.startsWith( "/" ) ) { relativeResource = resource.substring( 1 ); } InputStream is = getClass().getClassLoader().getResourceAsStream( relativeResource ); if ( is == null ) { try { return new FileInputStream( resource ); } catch ( FileNotFoundException e ) { return null; } } return is; } /** * Utility method to get a default lookup realm for a component. */ public ClassRealm getLookupRealm( Object component ) { if ( component.getClass().getClassLoader() instanceof ClassRealm ) { return ( (ClassRealm) component.getClass().getClassLoader() ); } else { return getLookupRealm(); } } public void setConfigurationSource( ConfigurationSource configurationSource ) { this.configurationSource = configurationSource; } public ConfigurationSource getConfigurationSource() { return configurationSource; } public LoggerManager getLoggerManager() { // TODO Auto-generated method stub return loggerManager; } public void setLoggerManager( LoggerManager loggerManager ) { this.loggerManager = loggerManager; } // Discovery public List> discoverComponents( ClassRealm realm ) throws PlexusConfigurationException, CycleDetectedInComponentGraphException { return discoverComponents( realm, null ); } public List> discoverComponents( ClassRealm realm, Object data ) throws PlexusConfigurationException, CycleDetectedInComponentGraphException { List componentSetDescriptors = new ArrayList(); List> discoveredComponentDescriptors = new ArrayList>(); for ( ComponentDiscoverer componentDiscoverer : getComponentDiscovererManager().getComponentDiscoverers() ) { for ( ComponentSetDescriptor componentSetDescriptor : componentDiscoverer.findComponents( getContext(), realm ) ) { // Here we should collect all the urls // do the interpolation against the context // register all the components // allow interception and replacement of the components componentSetDescriptors.add( componentSetDescriptor ); // Fire the event ComponentDiscoveryEvent event = new ComponentDiscoveryEvent( componentSetDescriptor, data ); componentDiscovererManager.fireComponentDiscoveryEvent( event ); for ( ComponentDescriptor componentDescriptor : componentSetDescriptor.getComponents() ) { addComponentDescriptor( componentDescriptor ); discoveredComponentDescriptors.add( componentDescriptor ); } } } return discoveredComponentDescriptors; } } DuplicateChildContainerException.java000066400000000000000000000023031166327066700401110ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class DuplicateChildContainerException extends PlexusContainerException { private final String parent; private final String child; public DuplicateChildContainerException( String parent, String child ) { super( "Cannot create child container, because child named \'" + child + "\' already exists in parent \'" + parent + "\'." ); this.parent = parent; this.child = child; } public String getParent() { return parent; } public String getChild() { return child; } } MutablePlexusContainer.java000066400000000000000000000041511166327066700361510ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.discovery.ComponentDiscovererManager; import org.codehaus.plexus.component.factory.ComponentFactoryManager; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.source.ConfigurationSource; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; /** * @author Jason van Zyl */ public interface MutablePlexusContainer extends PlexusContainer { // Core Components ComponentRegistry getComponentRegistry(); void setComponentRegistry( ComponentRegistry componentRegistry ); ComponentDiscovererManager getComponentDiscovererManager(); void setComponentDiscovererManager( ComponentDiscovererManager componentDiscovererManager ); ComponentFactoryManager getComponentFactoryManager(); void setComponentFactoryManager( ComponentFactoryManager componentFactoryManager ); LoggerManager getLoggerManager(); void setLoggerManager( LoggerManager loggerManager ); Logger getLogger(); void setConfigurationSource( ConfigurationSource configurationSource ); ConfigurationSource getConfigurationSource(); // Configuration void setConfiguration( PlexusConfiguration configuration ); PlexusConfiguration getConfiguration(); ClassRealm getComponentRealm( String realmId ); ClassWorld getClassWorld(); } PlexusConstants.java000066400000000000000000000017071166327066700346750ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public abstract class PlexusConstants { /** Key used to retrieve the plexus container from the containerContext. */ public static final String PLEXUS_KEY = "plexus"; /** The role-hint to use for components or lookups that do not specify a role.*/ public static final String PLEXUS_DEFAULT_HINT = "default"; } PlexusContainer.java000066400000000000000000000416451166327066700346500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.List; import java.util.Map; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.context.Context; /** * PlexusContainer is the entry-point for loading and accessing other * components. */ public interface PlexusContainer { String ROLE = PlexusContainer.class.getName(); // ------------------------------------------------------------------------ // Lookup // ------------------------------------------------------------------------ /** * Looks up and returns a component object with the given unique key or role. * @param role a unique key for the desired component * @return a Plexus component object */ Object lookup( String role ) throws ComponentLookupException; /** * Looks up and returns a component object with the given unique role/role-hint combination. * @param role a non-unique key for the desired component * @param roleHint a hint for the desired component implementation * @return a Plexus component object */ Object lookup( String role, String roleHint ) throws ComponentLookupException; /** * Looks up and returns a component object with the given unique key or role. * @param type the unique type of the component within the container * @return a Plexus component object */ T lookup( Class type ) throws ComponentLookupException; /** * Looks up and returns a component object with the given unique role/role-hint combination. * @param type the non-unique type of the component * @param roleHint a hint for the desired component implementation * @return a Plexus component object */ T lookup( Class type, String roleHint ) throws ComponentLookupException; /** * Looks up and returns a component object with the given unique role/role-hint combination. * @param type the non-unique type of the component * @param role a non-unique key for the desired component * @param roleHint a hint for the desired component implementation * @return a Plexus component object */ T lookup( Class type, String role, String roleHint ) throws ComponentLookupException; /** * Looks up and returns a component object matching the given component descriptor. * @param componentDescriptor the descriptor of the component * @return a Plexus component object */ T lookup( ComponentDescriptor componentDescriptor ) throws ComponentLookupException; /** * Looks up and returns a List of component objects with the given role. * @param role a non-unique key for the desired components * @return a List of component objects */ List lookupList( String role ) throws ComponentLookupException; /** * Looks up and returns a List of component objects with the given role. * @param role a non-unique key for the desired components * @return a List of component objects */ List lookupList( String role, List roleHints ) throws ComponentLookupException; /** * Looks up and returns a List of component objects with the given role. * @param type the non-unique type of the components * @return a List of component objects */ List lookupList( Class type ) throws ComponentLookupException; /** * Looks up and returns a List of component objects with the given role. * @param type the non-unique type of the components * @return a List of component objects */ List lookupList( Class type, List roleHints ) throws ComponentLookupException; /** * Looks up and returns a Map of component objects with the given role, keyed by all available role-hints. * @param role a non-unique key for the desired components * @return a Map of component objects */ Map lookupMap( String role ) throws ComponentLookupException; /** * Looks up and returns a Map of component objects with the given role, keyed by all available role-hints. * @param role a non-unique key for the desired components * @return a Map of component objects */ Map lookupMap( String role, List roleHints ) throws ComponentLookupException; /** * Looks up and returns a Map of component objects with the given role, keyed by all available role-hints. * @param type the non-unique type of the components * @return a Map of component objects */ Map lookupMap( Class type ) throws ComponentLookupException; /** * Looks up and returns a Map of component objects with the given role, keyed by all available role-hints. * @param type the non-unique type of the components * @return a Map of component objects */ Map lookupMap( Class type, List roleHints ) throws ComponentLookupException; // ---------------------------------------------------------------------- // Component Descriptor Lookup // ---------------------------------------------------------------------- /** * Returns the ComponentDescriptor with the given component role and the default role hint. * Searches up the hierarchy until one is found, null if none is found. * @param role a unique role for the desired component's descriptor * @return the ComponentDescriptor with the given component role */ ComponentDescriptor getComponentDescriptor( String role ); /** * Returns the ComponentDescriptor with the given component role and hint. * Searches up the hierarchy until one is found, null if none is found. * @param role a unique role for the desired component's descriptor * @param roleHint a hint showing which implementation should be used * @return the ComponentDescriptor with the given component role */ ComponentDescriptor getComponentDescriptor( String role, String roleHint ); /** * Returns the ComponentDescriptor with the given component role and hint. * Searches up the hierarchy until one is found, null if none is found. * @param type the Java type of the desired component * @param role a unique role for the desired component's descriptor * @param roleHint a hint showing which implementation should be used * @return the ComponentDescriptor with the given component role */ ComponentDescriptor getComponentDescriptor( Class type, String role, String roleHint ); /** * Returns a Map of ComponentDescriptors with the given role, keyed by role-hint. Searches up the hierarchy until * all are found, an empty Map if none are found. * @param role a non-unique key for the desired components * @return a Map of component descriptors keyed by role-hint */ Map> getComponentDescriptorMap( String role ); /** * Returns a Map of ComponentDescriptors with the given role, keyed by role-hint. Searches up the hierarchy until * all are found, an empty Map if none are found. * @param type the Java type of the desired components * @param role a non-unique key for the desired components * @return a Map of component descriptors keyed by role-hint */ Map> getComponentDescriptorMap( Class type, String role ); /** * Returns a List of ComponentDescriptors with the given role. Searches up the hierarchy until all are found, an * empty List if none are found. * @param role a non-unique key for the desired components * @return a List of component descriptors */ List> getComponentDescriptorList( String role ); /** * Returns a List of ComponentDescriptors with the given role. Searches up the hierarchy until all are found, an * empty List if none are found. * @param type the Java type of the desired components * @param role a non-unique key for the desired components * @return a List of component descriptors */ List> getComponentDescriptorList( Class type, String role ); /** * Adds a component descriptor to this container. componentDescriptor should have realmId set. * @param componentDescriptor * @throws ComponentRepositoryException */ void addComponentDescriptor( ComponentDescriptor componentDescriptor ) throws CycleDetectedInComponentGraphException; /** * Releases the component from the container. This is dependent upon how the implementation manages the component, * but usually enacts some standard lifecycle shutdown procedure on the component. In every case, the component is * no longer accessible from the container (unless another is created). * @param component the plexus component object to release * @throws ComponentLifecycleException */ void release( Object component ) throws ComponentLifecycleException; /** * Releases all Mapped component values from the container. * @see PlexusContainer#release( Object component ) * @param components Map of plexus component objects to release * @throws ComponentLifecycleException */ void releaseAll( Map components ) throws ComponentLifecycleException; /** * Releases all Listed components from the container. * @see PlexusContainer#release( Object component ) * @param components List of plexus component objects to release * @throws ComponentLifecycleException */ void releaseAll( List components ) throws ComponentLifecycleException; /** * Returns true if this container has the keyed component. * @param role a non-unique key for the desired component * @return true if this container has the keyed component */ boolean hasComponent( String role ); /** * Returns true if this container has a component with the given role/role-hint. * @param role a non-unique key for the desired component * @param roleHint a hint for the desired component implementation * @return true if this container has a component with the given role/role-hint */ boolean hasComponent( String role, String roleHint ); /** * Returns true if this container has a component with the given role/role-hint. * @param type the non-unique type of the component * @return true if this container has a component with the given role/role-hint */ boolean hasComponent( Class type ); /** * Returns true if this container has a component with the given role/role-hint. * @param type the non-unique type of the component * @param roleHint a hint for the desired component implementation * @return true if this container has a component with the given role/role-hint */ boolean hasComponent( Class type, String roleHint ); /** * Returns true if this container has a component with the given role/role-hint. * @param type the non-unique type of the component * @param role a non-unique key for the desired component * @param roleHint a hint for the desired component implementation * @return true if this container has a component with the given role/role-hint */ boolean hasComponent( Class type, String role, String roleHint ); /** * Disposes of this container, which in turn disposes all of it's components. This container should also remove * itself from the container hierarchy. */ void dispose(); // ---------------------------------------------------------------------- // Context // ---------------------------------------------------------------------- /** * Add a key/value pair to this container's Context. * @param key any unique object valid to the Context's implementation * @param value any object valid to the Context's implementation */ void addContextValue( Object key, Object value ); /** * Returns this container's context. A Context is a simple data store used to hold values which may alter the * execution of the Container. * @return this container's context. */ Context getContext(); /** * Returns the Classworld's ClassRealm of this Container, which acts as the default parent for all contained * components. * @return the ClassRealm of this Container */ ClassRealm getContainerRealm(); // ---------------------------------------------------------------------- // Discovery // ---------------------------------------------------------------------- /** * Adds the listener to this container. ComponentDiscoveryListeners have the ability to respond to various * ComponentDiscoverer events. * @param listener A listener which responds to different ComponentDiscoveryEvents */ void registerComponentDiscoveryListener( ComponentDiscoveryListener listener ); /** * Removes the listener from this container. * @param listener A listener to remove */ void removeComponentDiscoveryListener( ComponentDiscoveryListener listener ); /** * Discovers components in the given realm. * @param childRealm * @param override whether to override/merge any conflicting components, where the new component takes precedence. * @return * @throws PlexusConfigurationException * @throws ComponentRepositoryException */ List> discoverComponents( ClassRealm childRealm ) throws PlexusConfigurationException, CycleDetectedInComponentGraphException; List> discoverComponents( ClassRealm realm, Object data ) throws PlexusConfigurationException, CycleDetectedInComponentGraphException; // ---------------------------------------------------------------------------- // Component/Plugin ClassRealm creation // ---------------------------------------------------------------------------- ClassRealm createChildRealm( String id ); ClassRealm getComponentRealm( String realmId ); /** * Dissociate the realm with the specified id from the container. This will * remove all components contained in the realm from the component repository. * * @param componentRealm Realm to remove from the container. */ void removeComponentRealm( ClassRealm componentRealm ) throws PlexusContainerException; /** * Returns the lookup realm for this container, which is either * the container realm or the realm set by {@see MutablePlexusContainer#setLookupRealm(ClassRealm)}. */ ClassRealm getLookupRealm(); /** * Sets the lookup realm to use for lookup calls that don't have a ClassRealm parameter. * @param realm the new realm to use. * @return The previous lookup realm. It is advised to set it back once the old-style lookups have completed. */ ClassRealm setLookupRealm(ClassRealm realm); /** * XXX ideally i'd like to place this in a plexus container specific utility class. * * Utility method to retrieve the lookup realm for a component instance. * If the component's classloader is a ClassRealm, that realm is returned, * otherwise the result of getLookupRealm is returned. * @param component * @return */ ClassRealm getLookupRealm( Object component ); void addComponent( Object component, String role ) throws CycleDetectedInComponentGraphException; /** * Adds live component instance to this container. * * Component instance is not associated with any class realm and will * be ignored during lookup is lookup realm is provided using thread context * classloader. */ void addComponent( T component, Class role, String roleHint ); } PlexusContainerException.java000066400000000000000000000027171166327066700365240ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Container execution exception. * * @author Brett Porter * @version $Id: PlexusContainerException.java 6965 2007-10-21 05:32:27Z jvanzyl $ */ public class PlexusContainerException extends Exception { private static final long serialVersionUID = 2213861902264275451L; /** * Construct a new PlexusContainerException instance. * @param message exception message * @param throwable causing exception to chain */ public PlexusContainerException( String message, Throwable throwable ) { super( message, throwable ); } /** * Construct a new PlexusContainerException instance. * @param message exception message */ public PlexusContainerException( String message ) { super( message ); } } PlexusTestCase.java000066400000000000000000000166721166327066700344430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; import java.io.InputStream; import junit.framework.TestCase; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.DefaultContext; /** * @author Jason van Zyl * @author Trygve Laugstøl * @author Michal Maczka * @version $Id: PlexusTestCase.java 8420 2009-09-18 22:56:56Z hboutemy $ */ public abstract class PlexusTestCase extends TestCase { private PlexusContainer container; private static String basedir; protected void setUp() throws Exception { basedir = getBasedir(); } protected void setupContainer() { // ---------------------------------------------------------------------------- // Context Setup // ---------------------------------------------------------------------------- DefaultContext context = new DefaultContext(); context.put( "basedir", getBasedir() ); customizeContext( context ); boolean hasPlexusHome = context.contains( "plexus.home" ); if ( !hasPlexusHome ) { File f = getTestFile( "target/plexus-home" ); if ( !f.isDirectory() ) { f.mkdir(); } context.put( "plexus.home", f.getAbsolutePath() ); } // ---------------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------------- String config = getCustomConfigurationName(); ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration() .setName( "test" ) .setContext( context.getContextData() ); if ( config != null ) { containerConfiguration.setContainerConfiguration( config ); } else { String resource = getConfigurationName( null ); containerConfiguration.setContainerConfiguration( resource ); } customizeContainerConfiguration( containerConfiguration ); try { container = new DefaultPlexusContainer( containerConfiguration ); } catch ( PlexusContainerException e ) { e.printStackTrace(); fail( "Failed to create plexus container." ); } } /** * Allow custom test case implementations do augment the default container configuration before * executing tests. * * @param containerConfiguration */ protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) { } protected void customizeContext( Context context ) { } protected PlexusConfiguration customizeComponentConfiguration() { return null; } protected void tearDown() throws Exception { if ( container != null ) { container.dispose(); container = null; } } protected PlexusContainer getContainer() { if ( container == null ) { setupContainer(); } return container; } protected InputStream getConfiguration() throws Exception { return getConfiguration( null ); } protected InputStream getConfiguration( String subname ) throws Exception { return getResourceAsStream( getConfigurationName( subname ) ); } protected String getCustomConfigurationName() { return null; } /** * Allow the retrieval of a container configuration that is based on the name * of the test class being run. So if you have a test class called org.foo.FunTest, then * this will produce a resource name of org/foo/FunTest.xml which would be used to * configure the Plexus container before running your test. * * @param subname * @return */ protected String getConfigurationName( String subname ) { return getClass().getName().replace( '.', '/' ) + ".xml"; } protected InputStream getResourceAsStream( String resource ) { return getClass().getResourceAsStream( resource ); } protected ClassLoader getClassLoader() { return getClass().getClassLoader(); } // ---------------------------------------------------------------------- // Container access // ---------------------------------------------------------------------- protected Object lookup( String componentKey ) throws Exception { return getContainer().lookup( componentKey ); } protected Object lookup( String role, String roleHint ) throws Exception { return getContainer().lookup( role, roleHint ); } protected T lookup( Class componentClass ) throws Exception { return getContainer().lookup( componentClass ); } protected T lookup( Class componentClass, String roleHint ) throws Exception { return getContainer().lookup( componentClass, roleHint ); } protected void release( Object component ) throws Exception { getContainer().release( component ); } // ---------------------------------------------------------------------- // Helper methods for sub classes // ---------------------------------------------------------------------- public static File getTestFile( String path ) { return new File( getBasedir(), path ); } public static File getTestFile( String basedir, String path ) { File basedirFile = new File( basedir ); if ( !basedirFile.isAbsolute() ) { basedirFile = getTestFile( basedir ); } return new File( basedirFile, path ); } public static String getTestPath( String path ) { return getTestFile( path ).getAbsolutePath(); } public static String getTestPath( String basedir, String path ) { return getTestFile( basedir, path ).getAbsolutePath(); } public static String getBasedir() { if ( basedir != null ) { return basedir; } basedir = System.getProperty( "basedir" ); if ( basedir == null ) { basedir = new File( "" ).getAbsolutePath(); } return basedir; } public String getTestConfiguration() { return getTestConfiguration( getClass() ); } public static String getTestConfiguration( Class clazz ) { String s = clazz.getName().replace( '.', '/' ); return s.substring( 0, s.indexOf( "$" ) ) + ".xml"; } } plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/000077500000000000000000000000001166327066700327315ustar00rootroot00000000000000CastUtils.java000066400000000000000000000034411166327066700354320ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/componentpackage org.codehaus.plexus.component; import org.apache.xbean.recipe.RecipeHelper; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @SuppressWarnings({"unchecked", "UnusedDeclaration"}) public final class CastUtils { private CastUtils() { //utility class, never constructed } public static Map cast(Map p) { return (Map) p; } public static Map cast(Map p, Class t, Class u) { return (Map) p; } public static Collection cast(Collection p) { return (Collection) p; } public static Collection cast(Collection p, Class cls) { return (Collection) p; } public static List cast(List p) { return (List) p; } public static List cast(List p, Class cls) { return (List) p; } public static Iterator cast(Iterator p) { return (Iterator) p; } public static Iterator cast(Iterator p, Class cls) { return (Iterator) p; } public static Set cast(Set p) { return (Set) p; } public static Set cast(Set p, Class cls) { return (Set) p; } public static Map.Entry cast(Map.Entry p) { return (Map.Entry) p; } public static Map.Entry cast(Map.Entry p, Class pc, Class uc) { return (Map.Entry) p; } // todo remove when recipe helper accecpts nulls public static boolean isAssignableFrom(Class expected, Class actual) { return actual != null && RecipeHelper.isAssignableFrom( expected, actual ); } } MapOrientedComponent.java000066400000000000000000000021621166327066700376100ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/componentpackage org.codehaus.plexus.component; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.repository.ComponentRequirement; import java.util.Map; public interface MapOrientedComponent { void addComponentRequirement( ComponentRequirement requirementDescriptor, Object requirementValue ) throws ComponentConfigurationException; void setComponentConfiguration( Map componentConfiguration ) throws ComponentConfigurationException; } 000077500000000000000000000000001166327066700343005ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/builderAbstractComponentBuildListener.java000066400000000000000000000023171166327066700432620ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/builder/* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.component.builder; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.classworlds.realm.ClassRealm; public abstract class AbstractComponentBuildListener implements ComponentBuildListener { public void beforeComponentCreate(ComponentDescriptor componentDescriptor, ClassRealm realm) { } public void componentCreated(ComponentDescriptor componentDescriptor, Object component, ClassRealm realm) { } public void componentConfigured(ComponentDescriptor componentDescriptor, Object component, ClassRealm realm) { } } ComponentBuildListener.java000066400000000000000000000021721166327066700415750ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/builder/* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.component.builder; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDescriptor; public interface ComponentBuildListener { void beforeComponentCreate(ComponentDescriptor componentDescriptor, ClassRealm realm ); void componentCreated(ComponentDescriptor componentDescriptor, Object component, ClassRealm realm ); void componentConfigured(ComponentDescriptor componentDescriptor, Object component, ClassRealm realm ); } ComponentBuilder.java000066400000000000000000000022301166327066700404110ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/builder/* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.component.builder; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.factory.ComponentInstantiationException; public interface ComponentBuilder { T build(ComponentDescriptor descriptor, ClassRealm realm, ComponentBuildListener listener) throws ComponentInstantiationException, ComponentLifecycleException; } XBeanComponentBuilder.java000066400000000000000000000561771166327066700413520ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/builder/* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.component.builder; import static org.apache.xbean.recipe.RecipeHelper.toClass; import org.apache.xbean.recipe.AbstractRecipe; import org.apache.xbean.recipe.ConstructionException; import org.apache.xbean.recipe.ObjectRecipe; import org.apache.xbean.recipe.Option; import org.apache.xbean.recipe.RecipeHelper; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.ComponentRegistry; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.MapOrientedComponent; import org.codehaus.plexus.component.collections.ComponentList; import org.codehaus.plexus.component.collections.ComponentMap; import org.codehaus.plexus.component.configurator.BasicComponentConfigurator; import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ComponentConfigurator; import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.composite.MapConverter; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup; import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter; import org.codehaus.plexus.component.configurator.expression.DefaultExpressionEvaluator; import org.codehaus.plexus.component.factory.ComponentFactory; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.factory.java.JavaComponentFactory; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.component.repository.ComponentRequirementList; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException; import org.codehaus.plexus.util.StringUtils; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.LinkedHashSet; public class XBeanComponentBuilder implements ComponentBuilder { private static final ThreadLocal>> STACK = new ThreadLocal>>() { protected LinkedHashSet> initialValue() { return new LinkedHashSet>(); } }; private ComponentManager componentManager; public XBeanComponentBuilder() { } public XBeanComponentBuilder(ComponentManager componentManager) { setComponentManager(componentManager); } public ComponentManager getComponentManager() { return componentManager; } public void setComponentManager(ComponentManager componentManager) { this.componentManager = componentManager; } protected MutablePlexusContainer getContainer() { return componentManager.getContainer(); } public T build( ComponentDescriptor descriptor, ClassRealm realm, ComponentBuildListener listener ) throws ComponentInstantiationException, ComponentLifecycleException { LinkedHashSet> stack = STACK.get(); if ( stack.contains( descriptor ) ) { // create list of circularity List> circularity = new ArrayList>( stack ); circularity.subList( circularity.indexOf( descriptor ), circularity.size() ); circularity.add( descriptor ); // nice circularity message String message = "Creation circularity: "; for ( ComponentDescriptor componentDescriptor : circularity ) { message += "\n\t[" + componentDescriptor.getRole() + ", " + componentDescriptor.getRoleHint() + "]"; } throw new ComponentInstantiationException( message ); } stack.add( descriptor ); try { if (listener != null) { listener.beforeComponentCreate(descriptor, realm); } T component = createComponentInstance(descriptor, realm); if (listener != null) { listener.componentCreated(descriptor, component, realm); } startComponentLifecycle(component, realm); if (listener != null) { listener.componentConfigured(descriptor, component, realm); } return component; } finally { stack.remove( descriptor ); } } protected T createComponentInstance(ComponentDescriptor descriptor, ClassRealm realm) throws ComponentInstantiationException, ComponentLifecycleException { MutablePlexusContainer container = getContainer(); if (realm == null) { realm = descriptor.getRealm(); } ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(realm); try { ObjectRecipe recipe; T instance; ComponentFactory componentFactory = container.getComponentFactoryManager().findComponentFactory(descriptor.getComponentFactory()); if (JavaComponentFactory.class.equals(componentFactory.getClass())) { // xbean-reflect will create object and do injection recipe = createObjectRecipe( null, descriptor, realm ); instance = (T) recipe.create(); } else { // todo figure out how to easily let xbean use the factory to construct the component // use object factory to construct component and then inject into that object instance = (T) componentFactory.newInstance(descriptor, realm, container); recipe = createObjectRecipe( instance, descriptor, realm ); recipe.setProperties( instance ); } // todo figure out how to easily let xbean do this map oriented stuff (if it is actually used in plexus) if ( instance instanceof MapOrientedComponent) { MapOrientedComponent mapOrientedComponent = (MapOrientedComponent) instance; processMapOrientedComponent(descriptor, mapOrientedComponent, realm); } return instance; } catch (Exception e) { throw new ComponentLifecycleException("Error constructing component " + descriptor.getHumanReadableKey(), e); } catch (LinkageError e) { throw new ComponentLifecycleException("Error constructing component " + descriptor.getHumanReadableKey(), e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } } public ObjectRecipe createObjectRecipe(T instance, ComponentDescriptor descriptor, ClassRealm realm) throws ComponentInstantiationException, PlexusConfigurationException { String factoryMethod = null; String[] constructorArgNames = null; Class[] constructorArgTypes = null; Class implClass = ( instance != null ) ? instance.getClass() : descriptor.getImplementationClass(); if ( implClass == null || implClass == Object.class ) { // if the descriptor could not load the class, it's time to report this up to the caller now try { realm.loadClass( descriptor.getImplementation() ); } catch ( ClassNotFoundException e ) { throw new ComponentInstantiationException( "Could not load implementation class for component " + descriptor.getHumanReadableKey() + " from class realm " + realm, e ); } catch ( LinkageError e ) { throw new ComponentInstantiationException( "Could not load implementation class for component " + descriptor.getHumanReadableKey() + " from class realm " + realm, e ); } } ObjectRecipe recipe = new ObjectRecipe( implClass, factoryMethod, constructorArgNames, constructorArgTypes); recipe.allow(Option.FIELD_INJECTION); recipe.allow(Option.PRIVATE_PROPERTIES); // MapOrientedComponents don't get normal injection if (!MapOrientedComponent.class.isAssignableFrom( implClass )) { for (ComponentRequirement requirement : descriptor.getRequirements() ) { String name = requirement.getFieldName(); RequirementRecipe requirementRecipe = new RequirementRecipe(descriptor, requirement, getContainer(), name == null); if (name != null) { recipe.setProperty(name, requirementRecipe); } else { recipe.setAutoMatchProperty(requirement.getRole(), requirementRecipe); } } // add configuration data if (shouldConfigure(descriptor )) { PlexusConfiguration configuration = descriptor.getConfiguration(); if (configuration != null) { for (String name : configuration.getAttributeNames()) { String value; try { value = configuration.getAttribute(name); } catch (PlexusConfigurationException e) { throw new ComponentInstantiationException("Error getting value for attribute " + name, e); } name = fromXML(name); recipe.setProperty(name, value); } for (PlexusConfiguration child : configuration.getChildren()) { String name = child.getName(); name = fromXML(name); if ( StringUtils.isNotEmpty( child.getValue( null ) ) ) { recipe.setProperty( name, child.getValue() ); } else { recipe.setProperty( name, new PlexusConfigurationRecipe( child ) ); } } } } } return recipe; } protected boolean shouldConfigure( ComponentDescriptor descriptor ) { String configuratorId = descriptor.getComponentConfigurator(); if (StringUtils.isEmpty(configuratorId)) { return true; } try { ComponentConfigurator componentConfigurator = getContainer().lookup(ComponentConfigurator.class, configuratorId); return componentConfigurator == null || componentConfigurator.getClass().equals(BasicComponentConfigurator.class); } catch (ComponentLookupException e) { } return true; } protected String fromXML(String elementName) { return StringUtils.lowercaseFirstLetter(StringUtils.removeAndHump(elementName, "-")); } protected void startComponentLifecycle(Object component, ClassRealm realm) throws ComponentLifecycleException { try { componentManager.start(component); } catch (PhaseExecutionException e) { throw new ComponentLifecycleException("Error starting component", e); } } public static class RequirementRecipe extends AbstractRecipe { private ComponentDescriptor componentDescriptor; private ComponentRequirement requirement; private MutablePlexusContainer container; private boolean autoMatch; public RequirementRecipe(ComponentDescriptor componentDescriptor, ComponentRequirement requirement, MutablePlexusContainer container, boolean autoMatch) { this.componentDescriptor = componentDescriptor; this.requirement = requirement; this.container = container; this.autoMatch = autoMatch; } public boolean canCreate(Type expectedType) { if (!autoMatch) { return true; } Class propertyType = toClass(expectedType); // Never auto match array, map or collection if (propertyType.isArray() || Map.class.isAssignableFrom(propertyType) || Collection.class.isAssignableFrom(propertyType) || requirement instanceof ComponentRequirementList) { return false; } // if the type to be created is an instance of the expected type, return true try { ComponentRegistry componentRegistry = container.getComponentRegistry(); return componentRegistry.getComponentDescriptor(propertyType, requirement.getRole(), requirement.getRoleHint()) != null; } catch (Exception e) { } return false; } @Override protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException { Class propertyType = toClass(expectedType); try { String role = requirement.getRole(); List roleHints = null; if (requirement instanceof ComponentRequirementList) { roleHints = ((ComponentRequirementList) requirement).getRoleHints(); } Object assignment; if (propertyType.isArray()) { assignment = new ArrayList(container.lookupList(role, roleHints)); } // Map.class.isAssignableFrom( clazz ) doesn't make sense, since Map.class doesn't really // have a meaningful superclass. else { if (Map.class.equals(propertyType)) { // todo this is a lazy map // get component type Type keyType = Object.class; Type valueType = Object.class; Type[] typeParameters = RecipeHelper.getTypeParameters(Collection.class, expectedType); if (typeParameters != null && typeParameters.length == 2) { if (typeParameters[0] instanceof Class) { keyType = typeParameters[0]; } if (typeParameters[1] instanceof Class) { valueType = typeParameters[1]; } } // todo verify key type is String assignment = new ComponentMap(container, toClass(valueType), role, roleHints, componentDescriptor.getHumanReadableKey()); } // List.class.isAssignableFrom( clazz ) doesn't make sense, since List.class doesn't really // have a meaningful superclass other than Collection.class, which we'll handle next. else if (List.class.equals(propertyType)) { // todo this is a lazy list // get component type Type[] typeParameters = RecipeHelper.getTypeParameters(Collection.class, expectedType); Type componentType = Object.class; if (typeParameters != null && typeParameters.length == 1 && typeParameters[0] instanceof Class) { componentType = typeParameters[0]; } assignment = new ComponentList(container, toClass( componentType ), role, roleHints, componentDescriptor.getHumanReadableKey()); } // Set.class.isAssignableFrom( clazz ) doesn't make sense, since Set.class doesn't really // have a meaningful superclass other than Collection.class, and that would make this // if-else cascade unpredictable (both List and Set extend Collection, so we'll put another // check in for Collection.class. else if (Set.class.equals(propertyType) || Collection.class.isAssignableFrom(propertyType)) { // todo why isn't this lazy as above? assignment = container.lookupMap(role, roleHints); } else if (Logger.class.equals(propertyType)) { // todo magic reference assignment = container.getLoggerManager().getLoggerForComponent(componentDescriptor.getRole()); } else if (PlexusContainer.class.equals(propertyType)) { // todo magic reference assignment = container; } else { String roleHint = requirement.getRoleHint(); assignment = container.lookup(propertyType, role, roleHint); } } return assignment; } catch (ComponentLookupException e) { if ( requirement.isOptional() ) { return null; } throw new ConstructionException("Composition failed of field " + requirement.getFieldName() + " " + "in object of type " + componentDescriptor.getImplementation() + " because the requirement " + requirement + " was missing)", e); } } @Override public String toString() { return "RequirementRecipe[fieldName=" + requirement.getFieldName() + ", role=" + componentDescriptor.getRole() + "]"; } } private class PlexusConfigurationRecipe extends AbstractRecipe { private final PlexusConfiguration child; public PlexusConfigurationRecipe(PlexusConfiguration child) { this.child = child; } public boolean canCreate(Type type) { try { ConverterLookup lookup = createConverterLookup(); lookup.lookupConverterForType(toClass(type)); return true; } catch (ComponentConfigurationException e) { return false; } } @Override protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException { try { ConverterLookup lookup = createConverterLookup(); ConfigurationConverter converter = lookup.lookupConverterForType(toClass(expectedType)); // todo this will not work for static factories ObjectRecipe caller = (ObjectRecipe) RecipeHelper.getCaller(); Class parentClass = toClass(caller.getType()); Object value = converter.fromConfiguration(lookup, child, toClass(expectedType), parentClass, Thread.currentThread().getContextClassLoader(), new DefaultExpressionEvaluator()); return value; } catch (ComponentConfigurationException e) { throw new ConstructionException("Unable to convert configuration for property " + child.getName() + " to " + toClass(expectedType).getName()); } } private ConverterLookup createConverterLookup() { ClassRealm realm = (ClassRealm) Thread.currentThread().getContextClassLoader(); ConverterLookup lookup = new DefaultConverterLookup(); lookup.registerConverter( new ClassRealmConverter(realm) ); return lookup; } } private void processMapOrientedComponent(ComponentDescriptor descriptor, MapOrientedComponent mapOrientedComponent, ClassRealm realm) throws ComponentConfigurationException, ComponentLookupException { MutablePlexusContainer container = getContainer(); for (ComponentRequirement requirement : descriptor.getRequirements()) { String role = requirement.getRole(); String hint = requirement.getRoleHint(); String mappingType = requirement.getFieldMappingType(); Object value; // if the hint is not empty (and not default), we don't care about mapping type... // it's a single-value, not a collection. if (StringUtils.isNotEmpty(hint) && !hint.equals(PlexusConstants.PLEXUS_DEFAULT_HINT)) { value = container.lookup(role, hint); } else if ("single".equals(mappingType)) { value = container.lookup(role, hint); } else if ("map".equals(mappingType)) { value = container.lookupMap(role); } else if ("set".equals(mappingType)) { value = new HashSet(container.lookupList(role)); } else { value = container.lookup(role, hint); } mapOrientedComponent.addComponentRequirement(requirement, value); } MapConverter converter = new MapConverter(); ConverterLookup converterLookup = new DefaultConverterLookup(); DefaultExpressionEvaluator expressionEvaluator = new DefaultExpressionEvaluator(); PlexusConfiguration configuration = container.getConfigurationSource().getConfiguration( descriptor ); if ( configuration != null ) { Map context = (Map) converter.fromConfiguration(converterLookup, configuration, null, null, realm, expressionEvaluator, null ); mapOrientedComponent.setComponentConfiguration( context ); } } } 000077500000000000000000000000001166327066700351705ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/collectionsAbstractComponentCollection.java000066400000000000000000000134301166327066700434760ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/collectionspackage org.codehaus.plexus.component.collections; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** @author Jason van Zyl */ // We need to have the collection notified when a new implementation of a given role has // been added to the container. We probably need some options so that we know when new // component descriptors have been added to the system, and an option to keep the collection // up-to-date when new implementations are added. // // NOTE: This includes component additions, but also component purges from the // container, as when a component realm is disposed // (and PlexusContainer.removeComponentRealm(..) is called). public abstract class AbstractComponentCollection { /** The reference to the PlexusContainer */ protected MutablePlexusContainer container; /** The type of the components held by this collection*/ protected final Class componentType; /** The role of the components we are holding in this Collection. */ protected String role; /** The role hint of the components we are holding in this Collection. */ protected List roleHints; /** The component that requires this collection of components */ protected String hostComponent; /** Used to log errors in the component lookup process. */ protected Logger logger; private ClassLoader tccl; private Collection realms; private Map> componentDescriptorMap; private final ClassWorld world; public AbstractComponentCollection( final MutablePlexusContainer container, final Class componentType, final String role, final List roleHints, final String hostComponent ) { this.container = container; this.componentType = componentType; this.role = role; this.roleHints = roleHints; this.hostComponent = hostComponent; logger = container.getLoggerManager().getLoggerForComponent( role ); world = container.getContainerRealm().getWorld(); } private boolean realmsHaveChanged() { return ( tccl != Thread.currentThread().getContextClassLoader() ) || ( realms == null ) || ( !realms.equals( world.getRealms() ) ); } protected synchronized Map> getComponentDescriptorMap() { checkUpdate(); return componentDescriptorMap; } @SuppressWarnings( "unchecked" ) protected boolean checkUpdate() { if ( componentDescriptorMap != null && !realmsHaveChanged() ) { return false; } tccl = Thread.currentThread().getContextClassLoader(); Collection fromWorld = world.getRealms(); if ( fromWorld == null || fromWorld.isEmpty() ) { realms = null; } else { realms = new HashSet( fromWorld ); } Map> componentMap = container.getComponentDescriptorMap( componentType, role ); Map> newComponentDescriptors = new HashMap>( componentMap.size() * 2 ); if ( roleHints != null && !roleHints.isEmpty() ) { for ( String roleHint : roleHints ) { ComponentDescriptor componentDescriptor = componentMap.get( roleHint ); if ( componentDescriptor != null ) { newComponentDescriptors.put( roleHint, componentDescriptor ); } } } else { newComponentDescriptors.putAll( componentMap ); } if ( componentDescriptorMap == null || !newComponentDescriptors.equals( componentDescriptorMap ) ) { componentDescriptorMap = newComponentDescriptors; return true; } return false; } protected T lookup( ComponentDescriptor componentDescriptor ) { T component = null; try { if ( componentDescriptor != null ) { component = container.lookup( componentDescriptor ); } } catch ( ComponentLookupException e ) { logger.debug( "Failed to lookup a member of active collection with role: " + role + " and role-hint: " + componentDescriptor.getRoleHint(), e ); } return component; } public synchronized void clear() { releaseAllCallback(); componentDescriptorMap = null; tccl = null; realms = null; } protected abstract void releaseAllCallback(); } ComponentList.java000066400000000000000000000165601166327066700406410ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/collectionspackage org.codehaus.plexus.component.collections; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Map.Entry; /** * @author Jason van Zyl FIXME: [jdcasey] We need to review the efficiency (in speed and memory) of this collection... */ public class ComponentList extends AbstractComponentCollection implements List { private List components; public ComponentList( MutablePlexusContainer container, Class type, String role, List roleHints, String hostComponent ) { super( container, type, role, roleHints, hostComponent ); } public int size() { return getComponentDescriptorMap().size(); } public boolean isEmpty() { return getComponentDescriptorMap().isEmpty(); } public boolean contains( Object object ) { return getList().contains( object ); } public Iterator iterator() { return getList().iterator(); } public Object[] toArray() { return getList().toArray(); } public X[] toArray( X[] ts ) { return getList().toArray( ts ); } public synchronized boolean add( T object ) { getList().add( object ); /* * PLX-352 This is strictly to support the hack in the Ant Run plugin that tries to poke in a custom converter. * We need a better way to register converters to plexus and not hit the default converter lookup directly. * throw new UnsupportedOperationException( "You cannot modify this list. This list is a requirement of " + * hostComponent + " and managed by the container." ); */ return true; } public boolean remove( Object object ) { throw new UnsupportedOperationException( "You cannot modify this list. This list is a requirement of " + hostComponent + " and managed by the container." ); } public boolean containsAll( Collection collection ) { return getList().containsAll( collection ); } public boolean addAll( Collection collection ) { throw new UnsupportedOperationException( "You cannot modify this list. This list is a requirement of " + hostComponent + " and managed by the container." ); } public boolean addAll( int i, Collection collection ) { throw new UnsupportedOperationException( "You cannot modify this list. This list is a requirement of " + hostComponent + " and managed by the container." ); } public synchronized boolean removeAll( Collection collection ) { return getList().removeAll( collection ); } public synchronized boolean retainAll( Collection collection ) { return getList().retainAll( collection ); } public boolean equals( Object o ) { if ( this == o ) { return true; } if ( !( o instanceof List ) ) { return false; } List other = (List) o; return getList().equals( other ); } public int hashCode() { return getList().hashCode(); } public T get( int i ) { return getList().get( i ); } public T set( int i, T object ) { throw new UnsupportedOperationException( "You cannot modify this list. This list is a requirement of " + hostComponent + " and managed by the container." ); } public void add( int i, T object ) { throw new UnsupportedOperationException( "You cannot modify this list. This list is a requirement of " + hostComponent + " and managed by the container." ); } public T remove( int i ) { throw new UnsupportedOperationException( "You cannot modify this list. This list is a requirement of " + hostComponent + " and managed by the container." ); } public int indexOf( Object object ) { return getList().indexOf( object ); } public int lastIndexOf( Object object ) { return getList().lastIndexOf( object ); } public ListIterator listIterator() { return getList().listIterator(); } public ListIterator listIterator( int index ) { return getList().listIterator( index ); } public List subList( int fromIndex, int toIndex ) { return getList().subList( fromIndex, toIndex ); } private synchronized List getList() { // NOTE: If we cache the component map, we have a problem with releasing any of the // components in this map...we need to be able to release them all. if ( ( components == null ) || checkUpdate() ) { List componentList = new ArrayList(); Map> descriptorMap = getComponentDescriptorMap(); if ( roleHints != null ) { // we must follow the order in roleHints for ( String roleHint : roleHints ) { ComponentDescriptor componentDescriptor = descriptorMap.get( roleHint ); T component = lookup( componentDescriptor ); if ( component != null ) { componentList.add( component ); } } } else { for ( Entry> entry : descriptorMap.entrySet() ) { ComponentDescriptor componentDescriptor = entry.getValue(); T component = lookup( componentDescriptor ); if ( component != null ) { componentList.add( component ); } } } components = componentList; } return components; } @Override protected boolean checkUpdate() { if ( super.checkUpdate() ) { components = null; return true; } return false; } protected void releaseAllCallback() { if ( components != null ) { try { container.releaseAll( components ); } catch ( ComponentLifecycleException e ) { logger.debug( "Error releasing components in active collection: " + e.getMessage(), e ); } components = null; } } } ComponentMap.java000066400000000000000000000137751166327066700404500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/collectionspackage org.codehaus.plexus.component.collections; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; /** * @author Jason van Zyl FIXME: [jdcasey] We need to review the efficiency (in speed and memory) of this collection... */ public class ComponentMap extends AbstractComponentCollection implements Map { private Map components; private Map customAdditions = new LinkedHashMap(); public ComponentMap( MutablePlexusContainer container, Class type, String role, List roleHints, String hostComponent ) { super( container, type, role, roleHints, hostComponent ); } public int size() { return getComponentDescriptorMap().size(); } public boolean isEmpty() { return getComponentDescriptorMap().isEmpty(); } public boolean containsKey( Object key ) { return getComponentDescriptorMap().containsKey( key ); } public boolean containsValue( Object value ) { return getMap().containsValue( value ); } public T get( Object k ) { return getMap().get( k ); } public synchronized T put( String key, T value ) { logger.warn( "Custom " + role + " implementations should NOT be added directly to this Map. Instead, add them as Plexus components." ); T prev = customAdditions.put( key, value ); if ( prev == null ) { prev = getComponentMap().get( key ); } return prev; } public synchronized void putAll( Map map ) { logger.warn( "Custom " + role + " implementations should NOT be added directly to this Map. Instead, add them as Plexus components." ); customAdditions.putAll( map ); } public Set keySet() { return getMap().keySet(); } public Collection values() { return getMap().values(); } public Set> entrySet() { return getMap().entrySet(); } public boolean equals( Object o ) { if ( this == o ) { return true; } if ( !( o instanceof Map ) ) { return false; } Map object = (Map) o; return getMap().equals( object ); } public int hashCode() { return getMap().hashCode(); } public synchronized T remove( Object key ) { logger.warn( "Items in this Map should NOT be removed directly. If the matching entry is a component, it will NOT be removed." ); if ( key instanceof String ) { if ( customAdditions.containsKey( key ) ) { return customAdditions.remove( key ); } } return null; } private synchronized Map getMap() { Map result = getComponentMap(); if ( !customAdditions.isEmpty() ) { result.putAll( customAdditions ); } return result; } private synchronized Map getComponentMap() { if ( ( components == null ) || checkUpdate() ) { Map componentMap = new LinkedHashMap(); Map> descriptorMap = getComponentDescriptorMap(); if ( roleHints != null ) { // we must follow the order given in roleHints for ( String roleHint : roleHints ) { ComponentDescriptor componentDescriptor = descriptorMap.get( roleHint ); T component = lookup( componentDescriptor ); if ( component != null ) { componentMap.put( roleHint, component ); } } } else { for ( Entry> entry : descriptorMap.entrySet() ) { String roleHint = entry.getKey(); ComponentDescriptor componentDescriptor = entry.getValue(); T component = lookup( componentDescriptor ); if ( component != null ) { componentMap.put( roleHint, component ); } } } components = componentMap; } return components; } @Override protected boolean checkUpdate() { if ( super.checkUpdate() ) { components = null; return true; } return false; } protected void releaseAllCallback() { if ( components != null ) { try { container.releaseAll( components ); } catch ( ComponentLifecycleException e ) { logger.debug( "Error releasing components in active collection: " + e.getMessage(), e ); } components = null; } } } 000077500000000000000000000000001166327066700352155ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/compositionCompositionResolver.java000066400000000000000000000042741166327066700421140ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.repository.ComponentDescriptor; import java.util.List; /** * @author Jason van Zyl * @author Michal Maczka * @version $Id: CompositionResolver.java 8188 2009-05-17 00:43:32Z jvanzyl $ */ public interface CompositionResolver { public static final char SEPARATOR_CHAR = ':'; /** * @param componentDescriptor * @throws CycleDetectedInComponentGraphException when cycle is detected */ void addComponentDescriptor( ComponentDescriptor componentDescriptor ) throws CycleDetectedInComponentGraphException; /** * Returns the list of names of components which are required * by the component of given role and roleHint. * The names returned are in the form role:hint, where : is defined in SEPARATOR_CHAR. * * @param role The name of the component * @param roleHint The implementation hint of the component * @return The list of components which are required by given component */ List getRequirements( String role, String roleHint ); /** * Returns the list of names of components which are using the component. * of given role and roleHint. * The names returned are in the form role:hint, where : is defined in SEPARATOR_CHAR. * * @param role The name of the component * @param roleHint The implementation hint of the component * @return The list of components which are requiring given component */ List findRequirements( String role, String roleHint ); } CycleDetectedInComponentGraphException.java000066400000000000000000000031741166327066700456010ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Thrown when component composition goes awry. * * @author Jason van Zyl * @author Michal Maczka * @version $Id: CycleDetectedInComponentGraphException.java 8188 2009-05-17 00:43:32Z jvanzyl $ */ public class CycleDetectedInComponentGraphException extends Exception { private static final long serialVersionUID = -5587124702588800322L; /** * Construct a new CompositionException instance. * * @param message The detail message for this exception. */ public CycleDetectedInComponentGraphException( String message ) { super( message ); } /** * Construct a new CompositionException instance. * * @param message The detail message for this exception. * @param throwable the root cause of the exception */ public CycleDetectedInComponentGraphException( String message, Throwable throwable ) { super( message, throwable ); } } DefaultCompositionResolver.java000066400000000000000000000063271166327066700434220ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.List; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.component.repository.ComponentRequirementList; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.dag.CycleDetectedException; import org.codehaus.plexus.util.dag.DAG; /** * @author Jason van Zyl * @author Michal Maczka * @version $Id: DefaultCompositionResolver.java 8525 2009-11-06 15:23:51Z bentmann $ */ public class DefaultCompositionResolver implements CompositionResolver { private DAG dag = new DAG(); public void addComponentDescriptor( ComponentDescriptor componentDescriptor ) throws CycleDetectedInComponentGraphException { String key = getDAGKey( componentDescriptor.getRole(), componentDescriptor.getRoleHint() ); List requirements = componentDescriptor.getRequirements(); for ( ComponentRequirement requirement : requirements ) { try { if ( requirement instanceof ComponentRequirementList ) { for ( String hint : ( (ComponentRequirementList) requirement ).getRoleHints() ) { dag.addEdge( key, getDAGKey( requirement.getRole(), hint ) ); } } else { dag.addEdge( key, getDAGKey( requirement.getRole(), requirement.getRoleHint() ) ); } } catch ( CycleDetectedException e ) { throw new CycleDetectedInComponentGraphException( "Cyclic requirement detected", e ); } } } /** * @see org.codehaus.plexus.component.composition.CompositionResolver#getRequirements(String,String) */ public List getRequirements( String role, String roleHint ) { return dag.getChildLabels( getDAGKey( role, roleHint ) ); } /** * @see org.codehaus.plexus.component.composition.CompositionResolver#findRequirements(String,String) */ public List findRequirements( String role, String roleHint ) { return dag.getParentLabels( getDAGKey( role, roleHint ) ); } private String getDAGKey( String role, String roleHint ) { return role + SEPARATOR_CHAR + ( StringUtils.isNotEmpty( roleHint ) ? roleHint : PlexusConstants.PLEXUS_DEFAULT_HINT ); } } UndefinedComponentComposerException.java000066400000000000000000000023271166327066700452370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Michal Maczka * @version $Id: UndefinedComponentComposerException.java 4778 2006-11-23 03:54:18Z jvanzyl $ */ public class UndefinedComponentComposerException extends Exception { public UndefinedComponentComposerException( String message ) { super( message ); } public UndefinedComponentComposerException( String message, Throwable cause ) { super( message, cause ); } public UndefinedComponentComposerException( Throwable cause ) { super( cause ); } } 000077500000000000000000000000001166327066700353545ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configuratorAbstractComponentConfigurator.java000066400000000000000000000132501166327066700442310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.classworlds.ClassRealmAdapter; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup; import org.codehaus.plexus.component.configurator.expression.DefaultExpressionEvaluator; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /** * @author Brett Porter * @version $Id: AbstractComponentConfigurator.java 8790 2010-09-30 19:53:25Z bentmann $ */ public abstract class AbstractComponentConfigurator implements ComponentConfigurator { /** * This is being instantiated here because there are old component factories (beanshell) that directly access * the converterLookup but do not yet state the ConverterLookup as a requirement in the component metadata. * Once these are wired up as standard components properly then we won't have to instantiate the * converter lookup here and we can let the container do it. * * @plexus.requirement */ protected ConverterLookup converterLookup = new DefaultConverterLookup(); public void configureComponent( Object component, PlexusConfiguration configuration, ClassRealm containerRealm ) throws ComponentConfigurationException { configureComponent( component, configuration, new DefaultExpressionEvaluator(), containerRealm ); } public void configureComponent( Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm ) throws ComponentConfigurationException { configureComponent( component, configuration, expressionEvaluator, containerRealm, null ); } public void configureComponent( final Object component, final PlexusConfiguration configuration, final ExpressionEvaluator expressionEvaluator, final ClassRealm containerRealm, final ConfigurationListener listener ) throws ComponentConfigurationException { // ---------------------------------------------------------------------------- // For compatibility with old ComponentFactories that use old ClassWorlds // ---------------------------------------------------------------------------- final org.codehaus.classworlds.ClassRealm cr = ClassRealmAdapter.getInstance( containerRealm ); Method method; try { try { method = getClass().getMethod( "configureComponent", Object.class, PlexusConfiguration.class, ExpressionEvaluator.class, org.codehaus.classworlds.ClassRealm.class, ConfigurationListener.class ); method.invoke( this, component, configuration, expressionEvaluator, cr, listener ); } catch ( final NoSuchMethodException e ) { method = getClass().getMethod( "configureComponent", Object.class, PlexusConfiguration.class, ExpressionEvaluator.class, org.codehaus.classworlds.ClassRealm.class ); method.invoke( this, component, configuration, expressionEvaluator, cr ); } } catch ( final InvocationTargetException e ) { if ( e.getCause() instanceof ComponentConfigurationException ) { throw (ComponentConfigurationException) e.getCause(); } else if ( e.getCause() instanceof RuntimeException ) { throw (RuntimeException) e.getCause(); } else if ( e.getCause() instanceof Error ) { throw (Error) e.getCause(); } throw new ComponentConfigurationException( "Incompatible configurator " + getClass().getName(), e ); } catch ( final Exception e ) { throw new ComponentConfigurationException( "Incompatible configurator " + getClass().getName(), e ); } } } BasicComponentConfigurator.java000066400000000000000000000054501166327066700435120ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter; import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * @author Jason van Zyl * @author Michal Maczka * @version $Id: BasicComponentConfigurator.java 6992 2007-10-23 05:31:36Z jvanzyl $ */ public class BasicComponentConfigurator extends AbstractComponentConfigurator { public void configureComponent( Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, ConfigurationListener listener ) throws ComponentConfigurationException { // ---------------------------------------------------------------------- // We should probably take into consideration the realm that the component // came from in order to load the correct classes. // ---------------------------------------------------------------------- converterLookup.registerConverter( new ClassRealmConverter( containerRealm ) ); ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); converter.processConfiguration( converterLookup, component, containerRealm, configuration, expressionEvaluator, listener ); } } ComponentConfigurationException.java000066400000000000000000000030521166327066700445700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * * * @author Jason van Zyl * * @version $Id: ComponentConfigurationException.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentConfigurationException extends Exception { private PlexusConfiguration failedConfiguration; public ComponentConfigurationException( String message ) { super( message ); } public ComponentConfigurationException( String message, Throwable cause ) { super( message, cause ); } public ComponentConfigurationException( Throwable cause ) { super( cause ); } public ComponentConfigurationException( PlexusConfiguration failedConfiguration, String message ) { super( message ); this.failedConfiguration = failedConfiguration; } public ComponentConfigurationException( PlexusConfiguration failedConfiguration, String message, Throwable cause ) { super( message, cause ); this.failedConfiguration = failedConfiguration; } public ComponentConfigurationException( PlexusConfiguration failedConfiguration, Throwable cause ) { super( cause ); this.failedConfiguration = failedConfiguration; } public void setFailedConfiguration( PlexusConfiguration failedConfiguration ) { this.failedConfiguration = failedConfiguration; } public PlexusConfiguration getFailedConfiguration() { return failedConfiguration; } } ComponentConfigurator.java000066400000000000000000000043571166327066700425550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * @author Jason van Zyl * @version $Id: ComponentConfigurator.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface ComponentConfigurator { String ROLE = ComponentConfigurator.class.getName(); void configureComponent( Object component, PlexusConfiguration configuration, ClassRealm containerRealm ) throws ComponentConfigurationException; void configureComponent( Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm ) throws ComponentConfigurationException; void configureComponent( Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, ConfigurationListener listener ) throws ComponentConfigurationException; } ConfigurationListener.java000066400000000000000000000037511166327066700425420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004-5, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * Listen for configuration changes on an object. * * @author Brett Porter * @version $Id: ConfigurationListener.java 5127 2006-12-12 03:49:50Z jvanzyl $ */ public interface ConfigurationListener { /** * Notify the listener that a field has been set using its setter. * @param fieldName the field * @param value the value set * @param target the target object */ void notifyFieldChangeUsingSetter( String fieldName, Object value, Object target ); /** * Notify the listener that a field has been set using private field injection. * @param fieldName the field * @param value the value set * @param target the target object */ void notifyFieldChangeUsingReflection( String fieldName, Object value, Object target ); } MapOrientedComponentConfigurator.java000066400000000000000000000041021166327066700446710ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.MapOrientedComponent; import org.codehaus.plexus.component.configurator.converters.composite.MapConverter; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; import java.util.Map; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class MapOrientedComponentConfigurator extends AbstractComponentConfigurator { public void configureComponent( Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, ConfigurationListener listener ) throws ComponentConfigurationException { if ( !( component instanceof MapOrientedComponent ) ) { throw new ComponentConfigurationException( "This configurator can only process implementations of " + MapOrientedComponent.class.getName() ); } MapConverter converter = new MapConverter(); Map context = (Map) converter.fromConfiguration( converterLookup, configuration, null, null, containerRealm, expressionEvaluator, listener ); ( (MapOrientedComponent) component ).setComponentConfiguration( context ); } } 000077500000000000000000000000001166327066700375465ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/convertersAbstractConfigurationConverter.java000066400000000000000000000202701166327066700465750ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converterspackage org.codehaus.plexus.component.configurator.converters; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.util.StringUtils; /** * @author Michal Maczka * @version $Id: AbstractConfigurationConverter.java 7890 2008-11-29 17:14:01Z jvanzyl $ */ public abstract class AbstractConfigurationConverter implements ConfigurationConverter { private static final String IMPLEMENTATION = "implementation"; /** * We will check if user has provided a hint which class should be used for given field. * So we will check if something like is present in configuraion. * If 'implementation' hint was provided we will try to load correspoding class * If we are unable to do so error will be reported */ protected Class getClassForImplementationHint( Class type, PlexusConfiguration configuration, ClassLoader classLoader ) throws ComponentConfigurationException { Class retValue = type; String implementation = configuration.getAttribute( IMPLEMENTATION, null ); if ( implementation != null ) { try { retValue = classLoader.loadClass( implementation ); } catch ( ClassNotFoundException e ) { String msg = "ClassNotFoundException: Class name which was explicitly given in configuration using" + " 'implementation' attribute: '" + implementation + "' cannot be loaded"; throw new ComponentConfigurationException( msg, e ); } catch ( UnsupportedClassVersionError e ) { String msg = "UnsupportedClassVersionError: Class name which was explicitly given in configuration" + " using 'implementation' attribute: '" + implementation + "' cannot be loaded"; throw new ComponentConfigurationException( msg, e ); } catch ( LinkageError e ) { String msg = "LinkageError: Class name which was explicitly given in configuration using" + " 'implementation' attribute: '" + implementation + "' cannot be loaded"; throw new ComponentConfigurationException( msg, e ); } } return retValue; } protected Class loadClass( String classname, ClassLoader classLoader ) throws ComponentConfigurationException { Class retValue; try { retValue = classLoader.loadClass( classname ); } catch ( ClassNotFoundException e ) { throw new ComponentConfigurationException( "Error loading class '" + classname + "'", e ); } return retValue; } protected Object instantiateObject( String classname, ClassLoader classLoader ) throws ComponentConfigurationException { Class clazz = loadClass( classname, classLoader ); return instantiateObject( clazz ); } protected Object instantiateObject( Class clazz ) throws ComponentConfigurationException { Object retValue; try { retValue = clazz.newInstance(); return retValue; } catch ( IllegalAccessException e ) { throw new ComponentConfigurationException( "Class '" + clazz.getName() + "' cannot be instantiated", e ); } catch ( InstantiationException e ) { throw new ComponentConfigurationException( "Class '" + clazz.getName() + "' cannot be instantiated", e ); } } // first-name --> firstName protected String fromXML( String elementName ) { return StringUtils.lowercaseFirstLetter( StringUtils.removeAndHump( elementName, "-" ) ); } // firstName --> first-name protected String toXML( String fieldName ) { return StringUtils.addAndDeHump( fieldName ); } protected Object fromExpression( PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, Class type ) throws ComponentConfigurationException { Object v = fromExpression( configuration, expressionEvaluator ); if ( v != null ) { if ( !type.isAssignableFrom( v.getClass() ) ) { String msg = "Cannot assign configuration entry '" + configuration.getName() + "' to '" + type + "' from '" + configuration.getValue( null ) + "', which is of type " + v.getClass(); throw new ComponentConfigurationException( configuration, msg ); } } return v; } protected Object fromExpression( PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator ) throws ComponentConfigurationException { Object v = null; String value = configuration.getValue( null ); if ( value != null && value.length() > 0 ) { // Object is provided by an expression // This seems a bit ugly... canConvert really should return false in this instance, but it doesn't have the // configuration to know better try { v = expressionEvaluator.evaluate( value ); } catch ( ExpressionEvaluationException e ) { String msg = "Error evaluating the expression '" + value + "' for configuration value '" + configuration.getName() + "'"; throw new ComponentConfigurationException( configuration, msg, e ); } } if ( v == null ) { value = configuration.getAttribute( "default-value", null ); if ( value != null && value.length() > 0 ) { try { v = expressionEvaluator.evaluate( value ); } catch ( ExpressionEvaluationException e ) { String msg = "Error evaluating the expression '" + value + "' for configuration value '" + configuration.getName() + "'"; throw new ComponentConfigurationException( configuration, msg, e ); } } } return v; } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator ) throws ComponentConfigurationException { return fromConfiguration( converterLookup, configuration, type, baseType, classLoader, expressionEvaluator, null ); } } ComponentValueSetter.java000066400000000000000000000201031166327066700445330ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converterspackage org.codehaus.plexus.component.configurator.converters; /* * Copyright 2005-2007 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.util.ReflectionUtils; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /** @author Kenney Westerhof */ public class ComponentValueSetter { private Object object; private String fieldName; private ConverterLookup lookup; private Method setter; private Class setterParamType; private ConfigurationConverter setterTypeConverter; private Field field; private Class fieldType; private ConfigurationConverter fieldTypeConverter; private ConfigurationListener listener; public ComponentValueSetter( String fieldName, Object object, ConverterLookup lookup ) throws ComponentConfigurationException { this( fieldName, object, lookup, null ); } public ComponentValueSetter( String fieldName, Object object, ConverterLookup lookup, ConfigurationListener listener ) throws ComponentConfigurationException { this.fieldName = fieldName; this.object = object; this.lookup = lookup; this.listener = listener; if ( object == null ) { throw new ComponentConfigurationException( "Component is null" ); } initSetter(); initField(); if ( setter == null && field == null ) { throw new ComponentConfigurationException( "Cannot find setter nor field in " + object.getClass().getName() + " for '" + fieldName + "'" ); } if ( setterTypeConverter == null && fieldTypeConverter == null ) { throw new ComponentConfigurationException( "Cannot find converter for " + setterParamType.getName() + ( fieldType != null && !fieldType.equals( setterParamType ) ? " or " + fieldType.getName() : "" ) ); } } private void initSetter() { setter = ReflectionUtils.getSetter( fieldName, object.getClass() ); if ( setter == null ) { return; } setterParamType = setter.getParameterTypes()[0]; try { setterTypeConverter = lookup.lookupConverterForType( setterParamType ); } catch ( ComponentConfigurationException e ) { // ignore, handle later } } private void initField() { field = ReflectionUtils.getFieldByNameIncludingSuperclasses( fieldName, object.getClass() ); if ( field == null ) { return; } fieldType = field.getType(); try { fieldTypeConverter = lookup.lookupConverterForType( fieldType ); } catch ( ComponentConfigurationException e ) { // ignore, handle later } } private void setValueUsingField( Object value ) throws ComponentConfigurationException { try { boolean wasAccessible = field.isAccessible(); if ( !wasAccessible ) { field.setAccessible( true ); } if ( listener != null ) { listener.notifyFieldChangeUsingReflection( fieldName, value, object ); } field.set( object, value ); if ( !wasAccessible ) { field.setAccessible( false ); } } catch ( IllegalAccessException e ) { throw new ComponentConfigurationException( "Cannot access field: " + field, e ); } catch ( IllegalArgumentException e ) { throw new ComponentConfigurationException( "Cannot assign value '" + value + "' (type: " + value.getClass() + ") to " + field, e ); } } private void setValueUsingSetter( Object value ) throws ComponentConfigurationException { if ( setterParamType == null || setter == null ) { throw new ComponentConfigurationException( "No setter found" ); } String exceptionInfo = object.getClass().getName() + "." + setter.getName() + "( " + setterParamType.getClass().getName() + " )"; if ( listener != null ) { listener.notifyFieldChangeUsingSetter( fieldName, value, object ); } try { setter.invoke( object, new Object[]{value} ); } catch ( IllegalAccessException e ) { throw new ComponentConfigurationException( "Cannot access method: " + exceptionInfo, e ); } catch ( IllegalArgumentException e ) { throw new ComponentConfigurationException( "Invalid parameter supplied while setting '" + value + "' to " + exceptionInfo, e ); } catch ( InvocationTargetException e ) { throw new ComponentConfigurationException( "Setter " + exceptionInfo + " threw exception when called with parameter '" + value + "': " + e.getTargetException().getMessage(), e ); } } public void configure( PlexusConfiguration config, ClassLoader classLoader, ExpressionEvaluator evaluator ) throws ComponentConfigurationException { Object value = null; // try setter converter + method first if ( setterTypeConverter != null ) { try { value = setterTypeConverter.fromConfiguration( lookup, config, setterParamType, object.getClass(), classLoader, evaluator, listener ); if ( value != null ) { setValueUsingSetter( value ); return; } } catch ( ComponentConfigurationException e ) { if ( fieldTypeConverter == null || fieldTypeConverter.getClass().equals( setterTypeConverter.getClass() ) ) { throw e; } } } // try setting field using value found with method // converter, if present. ComponentConfigurationException savedEx = null; if ( value != null ) { try { setValueUsingField( value ); return; } catch ( ComponentConfigurationException e ) { savedEx = e; } } // either no value or setting went wrong. Try // new converter. value = fieldTypeConverter.fromConfiguration( lookup, config, fieldType, object.getClass(), classLoader, evaluator, listener ); if ( value != null ) { setValueUsingField( value ); } // FIXME: need this? else if ( savedEx != null ) { throw savedEx; } } } ConfigurationConverter.java000066400000000000000000000065741166327066700451240ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converterspackage org.codehaus.plexus.component.configurator.converters; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; public interface ConfigurationConverter { boolean canConvert( Class type ); /** * @param converterLookup Repository of available converters * @param configuration * @param type the type of object to read * @param baseType the type of object the the source is * @param classLoader ClassLoader which should be used for loading classes * @param expressionEvaluator the expression evaluator to use for expressions * @return the object * @throws ComponentConfigurationException * @todo a better way, instead of baseType, would be to pass in a factory for new classes that could be based from the given package */ Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator ) throws ComponentConfigurationException; /** * @param converterLookup Repository of available converters * @param configuration * @param type the type of object to read * @param baseType the type of object the the source is * @param classLoader ClassLoader which should be used for loading classes * @param expressionEvaluator the expression evaluator to use for expressions * @return the object * @throws ComponentConfigurationException * @todo a better way, instead of baseType, would be to pass in a factory for new classes that could be based from the given package */ Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException; } 000077500000000000000000000000001166327066700406275ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicAbstractBasicConverter.java000066400000000000000000000133601166327066700460720ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.component.configurator.expression.TypeAwareExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * @version $Id: AbstractBasicConverter.java 8514 2009-10-22 10:25:03Z bentmann $ */ public abstract class AbstractBasicConverter extends AbstractConfigurationConverter { protected abstract Object fromString( String str ) throws ComponentConfigurationException; protected Object fromExpression( PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, Class type ) throws ComponentConfigurationException { Object v = null; String value = configuration.getValue( null ); if ( value != null && value.length() > 0 ) { // Object is provided by an expression // This seems a bit ugly... canConvert really should return false in this instance, but it doesn't have the // configuration to know better try { if ( expressionEvaluator instanceof TypeAwareExpressionEvaluator ) { v = ( (TypeAwareExpressionEvaluator) expressionEvaluator ).evaluate( value, type ); } else { v = expressionEvaluator.evaluate( value ); } } catch ( ExpressionEvaluationException e ) { String msg = "Error evaluating the expression '" + value + "' for configuration value '" + configuration.getName() + "'"; throw new ComponentConfigurationException( configuration, msg, e ); } } if ( v == null ) { value = configuration.getAttribute( "default-value", null ); if ( value != null && value.length() > 0 ) { try { if ( expressionEvaluator instanceof TypeAwareExpressionEvaluator ) { v = ( (TypeAwareExpressionEvaluator) expressionEvaluator ).evaluate( value, type ); } else { v = expressionEvaluator.evaluate( value ); } } catch ( ExpressionEvaluationException e ) { String msg = "Error evaluating the expression '" + value + "' for configuration value '" + configuration.getName() + "'"; throw new ComponentConfigurationException( configuration, msg, e ); } } } /* * NOTE: We don't check the type here which would be ugly to do correctly (e.g. value=Short -> type=int), the * reflective setter/field injection will fail by itself when the type didn't match. */ return v; } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { if ( configuration.getChildCount() > 0 ) { throw new ComponentConfigurationException( "When configuring a basic element the configuration cannot " + "contain any child elements. " + "Configuration element '" + configuration.getName() + "'." ); } Object retValue = fromExpression( configuration, expressionEvaluator, type ); if ( retValue instanceof String ) { try { retValue = fromString( (String) retValue ); } catch ( ComponentConfigurationException e ) { if ( e.getFailedConfiguration() == null ) { e.setFailedConfiguration( configuration ); } throw e; } } return retValue; } } BooleanConverter.java000066400000000000000000000027771166327066700447560ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class BooleanConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( boolean.class ) || type.equals( Boolean.class ); } public Object fromString( String str ) { return str.equals( "true" ) ? Boolean.TRUE : Boolean.FALSE; } } ByteConverter.java000066400000000000000000000027551166327066700442760ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class ByteConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( byte.class ) || type.equals( Byte.class ); } public Object fromString( String str ) { return new Byte( (byte) Integer.parseInt( str ) ); } } CharConverter.java000066400000000000000000000027501166327066700442430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class CharConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( char.class ) || type.equals( Character.class ); } public Object fromString( String str ) { return new Character( str.charAt( 0 ) ); } } ClassConverter.java000066400000000000000000000024741166327066700444360ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; /** * @author Brett Porter */ public class ClassConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( Class.class ); } public Object fromString( String str ) throws ComponentConfigurationException { try { return Class.forName( str ); } catch ( ClassNotFoundException e ) { throw new ComponentConfigurationException( "Unable to find class in conversion", e ); } } } Converter.java000066400000000000000000000031261166327066700434430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * Translates the String representation of a class into * an instance of the class and vice versa * */ public interface Converter { boolean canConvert( Class type ); /** * Parses a given String and return * * @param str String representation of the class * @return an instance of the class */ Object fromString( String str ); String toString( Object obj ); } DateConverter.java000066400000000000000000000042541166327066700442440ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateConverter extends AbstractBasicConverter { /*** * @todo DateFormat is not thread safe! */ private static final DateFormat[] formats = { new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.S a" ), new SimpleDateFormat( "yyyy-MM-dd HH:mm:ssa" ) }; public boolean canConvert( Class type ) { return type.equals( Date.class ); } public Object fromString( String str ) { for ( int i = 0; i < formats.length; i++ ) { try { return formats[i].parse( str ); } catch ( ParseException e ) { // no worries, let's try the next format. } } return null; } public String toString( Object obj ) { Date date = (Date) obj; return formats[0].format( date ); } } DoubleConverter.java000066400000000000000000000027361166327066700446040ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class DoubleConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( double.class ) || type.equals( Double.class ); } public Object fromString( String str ) { return Double.valueOf( str ); } } EnumConverter.java000066400000000000000000000060611166327066700442710ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * @author Benjamin Bentmann */ public class EnumConverter extends AbstractConfigurationConverter { public boolean canConvert( Class type ) { return type.isEnum(); } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { if ( configuration.getChildCount() > 0 ) { throw new ComponentConfigurationException( "When configuring a basic element the configuration cannot " + "contain any child elements. " + "Configuration element '" + configuration.getName() + "'." ); } Object retValue = fromExpression( configuration, expressionEvaluator ); if ( retValue instanceof String ) { try { retValue = Enum.valueOf( type, (String) retValue ); } catch ( RuntimeException e ) { throw new ComponentConfigurationException( "Cannot assign value " + retValue + " to property " + configuration.getName() + " of " + baseType.getName() + ": " + e.getMessage(), e ); } } return retValue; } } FileConverter.java000066400000000000000000000054301166327066700442430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; import java.io.File; /** * @author Brett Porter */ public class FileConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( File.class ); } public Object fromString( String str ) { str = str.replace( '\\', File.separatorChar ).replace( '/', File.separatorChar ); return new File( str ); } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { File f = (File) super.fromConfiguration( converterLookup, configuration, type, baseType, classLoader, expressionEvaluator, listener ); if ( f != null ) { // Hmmm... is this cheating? Can't think of a better way right now return expressionEvaluator.alignToBaseDirectory( f ); } else { return null; } } } FloatConverter.java000066400000000000000000000027321166327066700444330ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class FloatConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( float.class ) || type.equals( Float.class ); } public Object fromString( String str ) { return Float.valueOf( str ); } } IntConverter.java000066400000000000000000000034661166327066700441250ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; import org.codehaus.plexus.component.configurator.ComponentConfigurationException; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class IntConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( int.class ) || type.equals( Integer.class ); } public Object fromString( String str ) throws ComponentConfigurationException { try { return Integer.valueOf( str ); } catch ( NumberFormatException e ) { throw new ComponentConfigurationException( "Not a number: '" + str + "'", e ); } } } LongConverter.java000066400000000000000000000027261166327066700442700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class LongConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( long.class ) || type.equals( Long.class ); } public Object fromString( String str ) { return Long.valueOf( str ); } } ShortConverter.java000066400000000000000000000027321166327066700444650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class ShortConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( short.class ) || type.equals( Short.class ); } public Object fromString( String str ) { return Short.valueOf( str ); } } StringBufferConverter.java000066400000000000000000000027131166327066700457650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class StringBufferConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( StringBuffer.class ); } public Object fromString( String str ) { return new StringBuffer( str ); } } StringConverter.java000066400000000000000000000026541166327066700446370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class StringConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( String.class ); } public Object fromString( String str ) { return str; } } UriConverter.java000066400000000000000000000026701166327066700441260ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basic/* * Copyright (C) 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.plexus.component.configurator.converters.basic; import java.net.URI; import java.net.URISyntaxException; import org.codehaus.plexus.component.configurator.ComponentConfigurationException; /** * Converter for {@link URI} objects. * * @version $Id: UriConverter.java 6935 2007-10-06 08:15:56Z user57 $ */ public class UriConverter extends AbstractBasicConverter { public boolean canConvert(final Class type) { assert type != null; return type.equals(URI.class); } public Object fromString(final String str) throws ComponentConfigurationException { assert str != null; try { return new URI(str); } catch (URISyntaxException e) { throw new ComponentConfigurationException("Unable to convert to URI: " + str, e); } } }UrlConverter.java000066400000000000000000000036071166327066700441320ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/basicpackage org.codehaus.plexus.component.configurator.converters.basic; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import java.net.MalformedURLException; import java.net.URL; /** * @author Brett Porter */ public class UrlConverter extends AbstractBasicConverter { public boolean canConvert( Class type ) { return type.equals( URL.class ); } public Object fromString( String str ) throws ComponentConfigurationException { try { return new URL( str ); } catch ( MalformedURLException e ) { throw new ComponentConfigurationException( "Unable to convert '" + str + "' to an URL", e ); } } } 000077500000000000000000000000001166327066700415505ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/compositeArrayConverter.java000066400000000000000000000133431166327066700453650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/compositepackage org.codehaus.plexus.component.configurator.converters.composite; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.util.StringUtils; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; /** * @author Kenney Westerhof * @version $Id: ArrayConverter.java 8005 2009-01-04 19:41:09Z bentmann $ */ public class ArrayConverter extends AbstractConfigurationConverter { public boolean canConvert( Class type ) { return type.isArray(); } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { Object retValue = fromExpression( configuration, expressionEvaluator, type ); if ( retValue != null ) { return retValue; } List values = new ArrayList(); for ( int i = 0; i < configuration.getChildCount(); i++ ) { PlexusConfiguration childConfiguration = configuration.getChild( i ); String configEntry = childConfiguration.getName(); String name = fromXML( configEntry ); Class childType = getClassForImplementationHint( null, childConfiguration, classLoader ); // check if the name is a fully qualified classname if ( childType == null && name.indexOf( '.' ) > 0 ) { try { childType = classLoader.loadClass( name ); } catch ( ClassNotFoundException e ) { // doesn't exist - continue processing } } if ( childType == null ) { // try to find the class in the package of the baseType // (which is the component being configured) String baseTypeName = baseType.getName(); int lastDot = baseTypeName.lastIndexOf( '.' ); String className; if ( lastDot == -1 ) { className = name; } else { String basePackage = baseTypeName.substring( 0, lastDot ); className = basePackage + "." + StringUtils.capitalizeFirstLetter( name ); } try { childType = classLoader.loadClass( className ); } catch ( ClassNotFoundException e ) { // doesn't exist, continue processing } } // finally just try the component type of the array if ( childType == null ) { childType = type.getComponentType(); } ConfigurationConverter converter = converterLookup.lookupConverterForType( childType ); Object object = converter.fromConfiguration( converterLookup, childConfiguration, childType, baseType, classLoader, expressionEvaluator, listener ); values.add( object ); } try { return values.toArray( (Object[]) Array.newInstance( type.getComponentType(), 0 ) ); } catch ( ArrayStoreException e ) { throw new ComponentConfigurationException( "Cannot assign configuration values to array of type " + type.getComponentType().getName() + ": " + values ); } } } CollectionConverter.java000066400000000000000000000170551166327066700464060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/compositepackage org.codehaus.plexus.component.configurator.converters.composite; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.util.StringUtils; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; /** * @author Michal Maczka * @version $Id: CollectionConverter.java 8004 2009-01-04 18:39:40Z bentmann $ */ public class CollectionConverter extends AbstractConfigurationConverter { public boolean canConvert( Class type ) { return Collection.class.isAssignableFrom( type ) && !Map.class.isAssignableFrom( type ); } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { Object retValue = fromExpression( configuration, expressionEvaluator, type ); if ( retValue != null ) { return retValue; } Class implementation = getClassForImplementationHint( null, configuration, classLoader ); if ( implementation != null ) { retValue = instantiateObject( implementation ); } else { // we can have 2 cases here: // - provided collection class which is not abstract // like Vector, ArrayList, HashSet - so we will just instantantiate it // - we have an abtract class so we have to use default collection type int modifiers = type.getModifiers(); if ( Modifier.isAbstract( modifiers ) ) { retValue = getDefaultCollection( type ); } else { try { retValue = type.newInstance(); } catch ( IllegalAccessException e ) { String msg = "An attempt to convert configuration entry " + configuration.getName() + "' into " + type + " object failed: " + e.getMessage(); throw new ComponentConfigurationException( msg, e ); } catch ( InstantiationException e ) { String msg = "An attempt to convert configuration entry " + configuration.getName() + "' into " + type + " object failed: " + e.getMessage(); throw new ComponentConfigurationException( msg, e ); } } } // now we have collection and we have to add some objects to it for ( int i = 0; i < configuration.getChildCount(); i++ ) { PlexusConfiguration c = configuration.getChild( i ); //Object o = null; String configEntry = c.getName(); String name = fromXML( configEntry ); Class childType = getClassForImplementationHint( null, c, classLoader ); if ( childType == null && name.indexOf( '.' ) > 0 ) { try { childType = classLoader.loadClass( name ); } catch ( ClassNotFoundException e ) { // not found, continue processing } } if ( childType == null ) { // Some classloaders don't create Package objects for classes // so we have to resort to slicing up the class name String baseTypeName = baseType.getName(); int lastDot = baseTypeName.lastIndexOf( '.' ); String className; if ( lastDot == -1 ) { className = name; } else { String basePackage = baseTypeName.substring( 0, lastDot ); className = basePackage + "." + StringUtils.capitalizeFirstLetter( name ); } try { childType = classLoader.loadClass( className ); } catch ( ClassNotFoundException e ) { if ( c.getChildCount() == 0 ) { // If no children, try a String. // TODO: If we had generics we could try that instead - or could the component descriptor list an impl? childType = String.class; } else { throw new ComponentConfigurationException( "Error loading class '" + className + "'", e ); } } } ConfigurationConverter converter = converterLookup.lookupConverterForType( childType ); Object object = converter.fromConfiguration( converterLookup, c, childType, baseType, classLoader, expressionEvaluator, listener ); Collection collection = (Collection) retValue; collection.add( object ); } return retValue; } protected Collection getDefaultCollection( Class collectionType ) { Collection retValue = null; if ( List.class.isAssignableFrom( collectionType ) ) { retValue = new ArrayList(); } else if ( SortedSet.class.isAssignableFrom( collectionType ) ) { retValue = new TreeSet(); } else if ( Set.class.isAssignableFrom( collectionType ) ) { retValue = new HashSet(); } return retValue; } } MapConverter.java000066400000000000000000000064701166327066700450270ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/compositepackage org.codehaus.plexus.component.configurator.converters.composite; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; import java.util.Map; import java.util.Properties; import java.util.TreeMap; /** * Converter for java.util.Properties. * * @author Michal Maczka * @version $Id: MapConverter.java 7285 2008-04-14 20:27:40Z jdcasey $ */ public class MapConverter extends AbstractConfigurationConverter { public boolean canConvert( Class type ) { return Map.class.isAssignableFrom( type ) && !Properties.class.isAssignableFrom( type ); } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { Object retValue; String expression = configuration.getValue( null ); if ( expression == null ) { expression = configuration.getAttribute( "default-value", null ); } if ( expression == null ) { Map map = new TreeMap(); PlexusConfiguration[] children = configuration.getChildren(); for ( int i = 0; i < children.length; i++ ) { PlexusConfiguration child = children[i]; String name = child.getName(); map.put( name, fromExpression( child, expressionEvaluator ) ); } retValue = map; } else { retValue = fromExpression( configuration, expressionEvaluator ); } return retValue; } } ObjectWithFieldsConverter.java000066400000000000000000000135571166327066700475070ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/compositepackage org.codehaus.plexus.component.configurator.converters.composite; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.ComponentValueSetter; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; import java.util.Collection; import java.util.Dictionary; import java.util.Map; /** * @author Michal Maczka * @version $Id: ObjectWithFieldsConverter.java 8512 2009-10-21 23:15:04Z bentmann $ */ public class ObjectWithFieldsConverter extends AbstractConfigurationConverter { public boolean canConvert( Class type ) { boolean retValue = true; if ( Dictionary.class.isAssignableFrom( type ) ) { retValue = false; } else if ( Map.class.isAssignableFrom( type ) ) { retValue = false; } else if ( Collection.class.isAssignableFrom( type ) ) { retValue = false; } return retValue; } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { Object retValue = fromExpression( configuration, expressionEvaluator, type ); if ( retValue == null ) { try { // it is a "composite" - we compose it from its children. It does not have a value of its own Class implementation = getClassForImplementationHint( type, configuration, classLoader ); if ( type == implementation && type.isInterface() && configuration.getChildCount() <= 0 ) { return null; } retValue = instantiateObject( implementation ); processConfiguration( converterLookup, retValue, classLoader, configuration, expressionEvaluator, listener ); } catch ( ComponentConfigurationException e ) { if ( e.getFailedConfiguration() == null ) { e.setFailedConfiguration( configuration ); } throw e; } } return retValue; } public void processConfiguration( ConverterLookup converterLookup, Object object, ClassLoader classLoader, PlexusConfiguration configuration ) throws ComponentConfigurationException { processConfiguration( converterLookup, object, classLoader, configuration, null ); } public void processConfiguration( ConverterLookup converterLookup, Object object, ClassLoader classLoader, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator ) throws ComponentConfigurationException { processConfiguration( converterLookup, object, classLoader, configuration, expressionEvaluator, null ); } public void processConfiguration( ConverterLookup converterLookup, Object object, ClassLoader classLoader, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { int items = configuration.getChildCount(); for ( int i = 0; i < items; i++ ) { PlexusConfiguration childConfiguration = configuration.getChild( i ); String elementName = childConfiguration.getName(); ComponentValueSetter valueSetter = new ComponentValueSetter( fromXML( elementName ), object, converterLookup, listener ); valueSetter.configure( childConfiguration, classLoader, expressionEvaluator ); } } } PlexusConfigurationConverter.java000066400000000000000000000047701166327066700503230ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/compositepackage org.codehaus.plexus.component.configurator.converters.composite; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * Converter for org.codehaus.plexus.configuration.PlexusConfiguration * * @author Michal Maczka * @version $Id: PlexusConfigurationConverter.java 6064 2007-03-13 12:39:55Z trygvis $ */ public class PlexusConfigurationConverter extends AbstractConfigurationConverter { public boolean canConvert( Class type ) { return PlexusConfiguration.class.isAssignableFrom( type ); } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { return configuration; } } PropertiesConverter.java000066400000000000000000000100111166327066700464300ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/compositepackage org.codehaus.plexus.component.configurator.converters.composite; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; import java.util.Properties; /** * Converter for java.util.Properties. * * @author Michal Maczka * @version $Id: PropertiesConverter.java 8516 2009-10-26 12:54:02Z bentmann $ */ public class PropertiesConverter extends AbstractConfigurationConverter { public boolean canConvert( Class type ) { return Properties.class.isAssignableFrom( type ); } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { Object retValueInterpolated = fromExpression( configuration, expressionEvaluator, type ); if ( retValueInterpolated != null ) { return retValueInterpolated; } String element = configuration.getName(); Properties retValue = new Properties(); PlexusConfiguration[] children = configuration.getChildren( "property" ); if ( children != null && children.length > 0 ) { for ( int i = 0; i < children.length; i++ ) { PlexusConfiguration child = children[i]; addEntry( retValue, element, child, expressionEvaluator ); } } return retValue; } private void addEntry( Properties properties, String element, PlexusConfiguration property, ExpressionEvaluator expressionEvaluator ) throws ComponentConfigurationException { Object name = fromExpression( property.getChild( "name" ), expressionEvaluator ); if ( name == null ) { String msg = "Trying to convert the configuration element: '" + element + "', missing child element 'name' for property."; throw new ComponentConfigurationException( msg ); } Object value = fromExpression( property.getChild( "value" ), expressionEvaluator ); if ( value == null ) { properties.setProperty( name.toString(), "" ); } else { properties.setProperty( name.toString(), value.toString() ); } } } 000077500000000000000000000000001166327066700410575ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/lookupConverterLookup.java000066400000000000000000000032111166327066700450600ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/lookuppackage org.codehaus.plexus.component.configurator.converters.lookup; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter; /** @version $Id: ConverterLookup.java 7828 2008-11-14 22:07:56Z dain $ */ public interface ConverterLookup { void registerConverter( ConfigurationConverter converter ); ConfigurationConverter lookupConverterForType( Class type ) throws ComponentConfigurationException; } DefaultConverterLookup.java000066400000000000000000000152561166327066700464010ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/lookuppackage org.codehaus.plexus.component.configurator.converters.lookup; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.basic.BooleanConverter; import org.codehaus.plexus.component.configurator.converters.basic.ByteConverter; import org.codehaus.plexus.component.configurator.converters.basic.CharConverter; import org.codehaus.plexus.component.configurator.converters.basic.DateConverter; import org.codehaus.plexus.component.configurator.converters.basic.DoubleConverter; import org.codehaus.plexus.component.configurator.converters.basic.EnumConverter; import org.codehaus.plexus.component.configurator.converters.basic.FileConverter; import org.codehaus.plexus.component.configurator.converters.basic.FloatConverter; import org.codehaus.plexus.component.configurator.converters.basic.IntConverter; import org.codehaus.plexus.component.configurator.converters.basic.LongConverter; import org.codehaus.plexus.component.configurator.converters.basic.ShortConverter; import org.codehaus.plexus.component.configurator.converters.basic.StringBufferConverter; import org.codehaus.plexus.component.configurator.converters.basic.StringConverter; import org.codehaus.plexus.component.configurator.converters.basic.UriConverter; import org.codehaus.plexus.component.configurator.converters.basic.UrlConverter; import org.codehaus.plexus.component.configurator.converters.composite.ArrayConverter; import org.codehaus.plexus.component.configurator.converters.composite.CollectionConverter; import org.codehaus.plexus.component.configurator.converters.composite.MapConverter; import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter; import org.codehaus.plexus.component.configurator.converters.composite.PlexusConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.composite.PropertiesConverter; import java.util.List; import java.util.Map; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; public class DefaultConverterLookup implements ConverterLookup { private final List converters = new ArrayList(); private final List customConverters = new CopyOnWriteArrayList(); private final Map, ConfigurationConverter> converterMap = new ConcurrentHashMap, ConfigurationConverter>(); public DefaultConverterLookup() { registerDefaultBasicConverters(); registerDefaultCompositeConverters(); } public synchronized void registerConverter( ConfigurationConverter converter ) { customConverters.add( converter ); } protected void registerDefaultConverter( ConfigurationConverter converter ) { converters.add( converter ); } public ConfigurationConverter lookupConverterForType( Class type ) throws ComponentConfigurationException { ConfigurationConverter retValue = converterMap.get( type ); if ( retValue == null ) { if ( customConverters != null ) { retValue = findConverterForType( customConverters, type ); } if ( retValue == null ) { retValue = findConverterForType( converters, type ); } if ( retValue == null ) { // this is highly irregular throw new ComponentConfigurationException( "Configuration converter lookup failed for type: " + type ); } converterMap.put( type, retValue ); } return retValue; } private ConfigurationConverter findConverterForType( List converters, Class type ) { for ( ConfigurationConverter converter : converters ) { if ( converter.canConvert( type ) ) { return converter; } } return null; } private void registerDefaultBasicConverters() { registerDefaultConverter( new BooleanConverter() ); registerDefaultConverter( new ByteConverter() ); registerDefaultConverter( new CharConverter() ); registerDefaultConverter( new DoubleConverter() ); registerDefaultConverter( new FloatConverter() ); registerDefaultConverter( new IntConverter() ); registerDefaultConverter( new LongConverter() ); registerDefaultConverter( new ShortConverter() ); registerDefaultConverter( new StringBufferConverter() ); registerDefaultConverter( new StringConverter() ); registerDefaultConverter( new DateConverter() ); registerDefaultConverter( new FileConverter() ); registerDefaultConverter( new UrlConverter() ); registerDefaultConverter( new UriConverter() ); registerDefaultConverter( new EnumConverter() ); } private void registerDefaultCompositeConverters() { registerDefaultConverter( new MapConverter() ); registerDefaultConverter( new ArrayConverter() ); registerDefaultConverter( new CollectionConverter() ); registerDefaultConverter( new PropertiesConverter() ); registerDefaultConverter( new PlexusConfigurationConverter() ); // this converter should be always registred as the last one registerDefaultConverter( new ObjectWithFieldsConverter() ); } } 000077500000000000000000000000001166327066700411665ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/specialClassRealmConverter.java000066400000000000000000000062541166327066700457560ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/specialpackage org.codehaus.plexus.component.configurator.converters.special; import org.codehaus.classworlds.ClassRealmAdapter; import org.codehaus.classworlds.ClassRealmReverseAdapter; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter; import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * ConfigurationConverter to set up ClassRealm component fields. * * @author Kenney Westerhof */ public class ClassRealmConverter extends AbstractConfigurationConverter { public static final String ROLE = ConfigurationConverter.class.getName(); private ClassRealm classRealm; /** * Constructs this ClassRealmConverter with the given ClassRealm. * If there's a way to automatically configure this component * using the current classrealm, this method can go away. * * @param classRealm */ public ClassRealmConverter( ClassRealm classRealm ) { setClassRealm( classRealm ); } @Deprecated public ClassRealmConverter( final org.codehaus.classworlds.ClassRealm classRealm ) { setClassRealm( classRealm ); } public void setClassRealm( final ClassRealm classRealm ) { this.classRealm = classRealm; } @Deprecated public void setClassRealm( final org.codehaus.classworlds.ClassRealm classRealm ) { if ( classRealm.getClassLoader() instanceof ClassRealm ) { setClassRealm( (ClassRealm) classRealm.getClassLoader() ); } else { setClassRealm( ClassRealmReverseAdapter.getInstance( classRealm ) ); } } public boolean canConvert( Class type ) { // backwards compatibility for old ClassWorld fields return org.codehaus.classworlds.ClassRealm.class.isAssignableFrom( type ) || ClassRealm.class.isAssignableFrom( type ); } public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { Object retValue = fromExpression( configuration, expressionEvaluator, type ); if ( retValue == null ) { retValue = classRealm; } // backwards compatibility for old ClassWorld fields if ( retValue instanceof ClassRealm && org.codehaus.classworlds.ClassRealm.class.isAssignableFrom( type ) ) { retValue = ClassRealmAdapter.getInstance( (ClassRealm) retValue ); } return retValue; } } 000077500000000000000000000000001166327066700375535ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/expressionDefaultExpressionEvaluator.java000066400000000000000000000023671166327066700457550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/expressionpackage org.codehaus.plexus.component.configurator.expression; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; /** * Evaluate an expression. * * @author Brett Porter * @version $Id: DefaultExpressionEvaluator.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public class DefaultExpressionEvaluator implements ExpressionEvaluator { /** * Evaluate an expression. * * @param expression the expression * @return the value of the expression */ public Object evaluate( String expression ) { return expression; } public File alignToBaseDirectory( File file ) { return file; } } ExpressionEvaluationException.java000066400000000000000000000022471166327066700464710ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/expressionpackage org.codehaus.plexus.component.configurator.expression; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Exception that occurs during the evaluation of an expression. * * @author Brett Porter * @version $Id: ExpressionEvaluationException.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public class ExpressionEvaluationException extends Exception { public ExpressionEvaluationException( String message ) { super( message ); } public ExpressionEvaluationException( String message, Throwable cause ) { super( message, cause ); } } ExpressionEvaluator.java000066400000000000000000000026401166327066700444420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/expressionpackage org.codehaus.plexus.component.configurator.expression; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; /** * Evaluate an expression. * * @author Brett Porter * @version $Id: ExpressionEvaluator.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public interface ExpressionEvaluator { String ROLE = ExpressionEvaluator.class.getName(); /** * Evaluate an expression. * * @param expression the expression * @return the value of the expression */ Object evaluate( String expression ) throws ExpressionEvaluationException; /** * Align a given path to the base directory that can be evaluated by this expression evaluator, if known. * * @param file the file * @return the aligned file */ File alignToBaseDirectory( File file ); } TypeAwareExpressionEvaluator.java000066400000000000000000000030011166327066700462540ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/expressionpackage org.codehaus.plexus.component.configurator.expression; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Evaluate an expression. * * @author Brett Porter * @version $Id: TypeAwareExpressionEvaluator.java 8347 2009-08-20 17:37:19Z bentmann $ */ public interface TypeAwareExpressionEvaluator extends ExpressionEvaluator { /** * Evaluate an expression. The optional type provided to this method is a hint (not a requirement) for the evaluator * to resolve the expression to a compatible value. The evaluator is not expected to perform any conversion but * rather filter out incompatible values from its result. * * @param expression the expression * @param type The expected type of expression result, may be {@code null}. * @return the value of the expression */ Object evaluate( String expression, Class type ) throws ExpressionEvaluationException; } 000077500000000000000000000000001166327066700346615ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoveryAbstractResourceBasedComponentDiscoverer.java000066400000000000000000000067701166327066700456610ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.io.Reader; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.List; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextMapAdapter; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.InterpolationFilterReader; import org.codehaus.plexus.util.ReaderFactory; //TODO: this should be a default strategy of searching through classloaders. a discoverer should really not have to be // concerned finding a particular resource and how to turn it into a set of component descriptors. /** * @author Jason van Zyl */ public abstract class AbstractResourceBasedComponentDiscoverer implements ComponentDiscoverer { protected abstract String getComponentDescriptorLocation(); protected abstract ComponentSetDescriptor createComponentDescriptors( Reader reader, String source, ClassRealm realm ) throws PlexusConfigurationException; public List findComponents( Context context, ClassRealm realm ) throws PlexusConfigurationException { List componentSetDescriptors = new ArrayList(); Enumeration resources; try { resources = realm.getResources( getComponentDescriptorLocation() ); } catch ( IOException e ) { throw new PlexusConfigurationException( "Unable to retrieve resources for: " + getComponentDescriptorLocation() + " in class realm: " + realm.getId() ); } for ( URL url : Collections.list( resources )) { Reader reader = null; try { URLConnection conn = url.openConnection(); conn.setUseCaches( false ); conn.connect(); reader = ReaderFactory.newXmlReader( conn.getInputStream() ); InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( reader, new ContextMapAdapter( context ) ); ComponentSetDescriptor componentSetDescriptor = createComponentDescriptors( interpolationFilterReader, url.toString(), realm ); componentSetDescriptors.add( componentSetDescriptor ); } catch ( IOException ex ) { throw new PlexusConfigurationException( "Error reading configuration " + url, ex ); } finally { IOUtil.close( reader ); } } return componentSetDescriptors; } } AnnotationBasedComponentDiscoverer.java000066400000000000000000000004111166327066700445020ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /** * Component discoverer which relies on annotation information to define component definitions. * * @author jvanzyl */ public interface AnnotationBasedComponentDiscoverer extends ComponentDiscoverer { } ComponentDiscoverer.java000066400000000000000000000021631166327066700415160ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import java.util.List; /** * @author Jason van Zyl */ public interface ComponentDiscoverer { List findComponents( Context context, ClassRealm classRealm ) throws PlexusConfigurationException; } ComponentDiscovererManager.java000066400000000000000000000026131166327066700430110ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.List; import java.util.Map; /** * ComponentDiscovererManager is a simple index (registry) of ComponentDiscovers and ComponentDiscoveryListener. */ public interface ComponentDiscovererManager { void addComponentDiscoverer( ComponentDiscoverer componentDiscoverer ); List getComponentDiscoverers(); // todo dain change this to Set (requires change to maven) Map getComponentDiscoveryListeners(); void registerComponentDiscoveryListener( ComponentDiscoveryListener listener); void removeComponentDiscoveryListener( ComponentDiscoveryListener listener ); void fireComponentDiscoveryEvent( ComponentDiscoveryEvent event ); } ComponentDiscoveryEvent.java000066400000000000000000000035441166327066700423660ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.repository.ComponentSetDescriptor; /** * Signals to a ComponentDiscoveryListener that an event has taken place * involving a set of components. It is up to the Listener to decide what * to do with that information. */ public class ComponentDiscoveryEvent { private ComponentSetDescriptor componentSetDescriptor; private Object data; /** * Constructs a ComponentDiscoveryEvent with a set of * ComponentDescriptors. * @param componentSetDescriptor a set of ComponentDescriptors */ public ComponentDiscoveryEvent( ComponentSetDescriptor componentSetDescriptor ) { this.componentSetDescriptor = componentSetDescriptor; } public ComponentDiscoveryEvent( ComponentSetDescriptor componentSetDescriptor, Object data ) { this.componentSetDescriptor = componentSetDescriptor; this.data = data; } /** * Returns this event's set of ComponentDescriptors. * @return this event's set of ComponentDescriptors */ public ComponentSetDescriptor getComponentSetDescriptor() { return componentSetDescriptor; } public Object getData() { return data; } } ComponentDiscoveryListener.java000066400000000000000000000020101166327066700430550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * A listener which responds in some way to component discovery by a PlexusContainer. */ public interface ComponentDiscoveryListener { /** * Signals to this listener that a component has been discovered. * @param event the event that signals what components have been discovered */ void componentDiscovered( ComponentDiscoveryEvent event ); } DefaultComponentDiscoverer.java000066400000000000000000000066321166327066700430300ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.component.repository.io.PlexusTools; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.classworlds.realm.ClassRealm; import java.io.Reader; import java.util.ArrayList; import java.util.List; /** * @author Jason van Zyl */ public class DefaultComponentDiscoverer extends AbstractResourceBasedComponentDiscoverer { public String getComponentDescriptorLocation() { return "META-INF/plexus/components.xml"; } public ComponentSetDescriptor createComponentDescriptors( Reader componentDescriptorReader, String source, ClassRealm realm ) throws PlexusConfigurationException { PlexusConfiguration componentDescriptorConfiguration = PlexusTools.buildConfiguration( source, componentDescriptorReader ); ComponentSetDescriptor componentSetDescriptor = new ComponentSetDescriptor(); List> componentDescriptors = new ArrayList>(); PlexusConfiguration[] componentConfigurations = componentDescriptorConfiguration.getChild( "components" ).getChildren( "component" ); for ( PlexusConfiguration componentConfiguration : componentConfigurations ) { ComponentDescriptor componentDescriptor; try { componentDescriptor = PlexusTools.buildComponentDescriptor( componentConfiguration, realm ); } catch ( PlexusConfigurationException e ) { // This is not the most accurate of exceptions as the only real case where this exception // will be thrown is when the implementation class of the component sited cannot be loaded. // In the case where role and implementation classes do not exist then we just shouldn't // create the component descriptor. All information should be taken from annotations which // will be correct, so in the case we can't load the class it must be coming from and older // hand written descriptor which is incorrect. continue; } componentDescriptor.setSource( source ); componentDescriptor.setComponentType( "plexus" ); componentDescriptor.setComponentSetDescriptor( componentSetDescriptor ); componentDescriptors.add( componentDescriptor ); } componentSetDescriptor.setComponents( componentDescriptors ); componentSetDescriptor.setSource( source ); return componentSetDescriptor; } } DefaultComponentDiscovererManager.java000066400000000000000000000050001166327066700443070ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.Map; import java.util.LinkedHashMap; public class DefaultComponentDiscovererManager implements ComponentDiscovererManager { private final List componentDiscoverers = new ArrayList(); // todo dain change this to LinkedHashSet (requires change to maven) private final Map listeners = new LinkedHashMap(); public synchronized void addComponentDiscoverer( ComponentDiscoverer discoverer ) { componentDiscoverers.add( discoverer ); } // todo this is not thread safe... we are returning the raw collection public synchronized List getComponentDiscoverers() { return componentDiscoverers; } // Listeners // todo this is not thread safe... we are returning the raw collection public synchronized Map getComponentDiscoveryListeners() { return listeners; } public synchronized void registerComponentDiscoveryListener( ComponentDiscoveryListener listener ) { if ( !listeners.containsKey( listener ) ) { listeners.put( listener, new Object() ); } } public synchronized void removeComponentDiscoveryListener( ComponentDiscoveryListener listener ) { listeners.remove( listener ); } public void fireComponentDiscoveryEvent( ComponentDiscoveryEvent event ) { Set listeners; synchronized ( this ) { listeners = this.listeners.keySet(); } for ( ComponentDiscoveryListener listener : listeners ) { listener.componentDiscovered( event ); } } } DiscoveryListenerDescriptor.java000066400000000000000000000017671166327066700432530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * * @version $Id: DiscoveryListenerDescriptor.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DiscoveryListenerDescriptor { private String role; private String roleHint; public String getRole() { return role; } public String getRoleHint() { return roleHint; } } PlexusXmlComponentDiscoverer.java000066400000000000000000000055161166327066700434050ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ import java.io.Reader; import java.util.Arrays; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.component.repository.io.PlexusTools; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; public class PlexusXmlComponentDiscoverer extends AbstractResourceBasedComponentDiscoverer { public String getComponentDescriptorLocation() { return "META-INF/plexus/plexus.xml"; } @Override protected ComponentSetDescriptor createComponentDescriptors( Reader reader, String source, ClassRealm realm ) throws PlexusConfigurationException { ComponentSetDescriptor componentSetDescriptor = new ComponentSetDescriptor(); PlexusConfiguration configuration = PlexusTools.buildConfiguration( source, reader ); if ( configuration != null ) { PlexusConfiguration[] componentConfigurations = configuration.getChild( "components" ).getChildren( "component" ); for ( PlexusConfiguration componentConfiguration : componentConfigurations ) { ComponentDescriptor componentDescriptor; try { componentDescriptor = PlexusTools.buildComponentDescriptor( componentConfiguration, realm ); if ( componentDescriptor == null ) { continue; } } catch ( PlexusConfigurationException e ) { throw new PlexusConfigurationException( "Cannot build component descriptor from resource found in:\n" + Arrays.asList( realm.getURLs() ), e ); } componentDescriptor.setComponentType( "plexus" ); componentDescriptor.setComponentSetDescriptor( componentSetDescriptor ); componentSetDescriptor.addComponentDescriptor( componentDescriptor ); } } return componentSetDescriptor; } } ResourceBasedComponentDiscoverer.java000066400000000000000000000005321166327066700441630ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /** * Component discoverer which relies on the metadata for the components residing in a resource that * can be found in a classloader. * * @author jvanzyl */ public interface ResourceBasedComponentDiscoverer extends ComponentDiscoverer { String getComponentDescriptorLocation(); } 000077500000000000000000000000001166327066700343215ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/factoryAbstractComponentFactory.java000066400000000000000000000035601166327066700421460ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.classworlds.ClassRealmAdapter; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDescriptor; /** * * * @author Jason van Zyl * * @version $Id: AbstractComponentFactory.java 8477 2009-10-16 22:00:16Z bentmann $ */ public abstract class AbstractComponentFactory implements ComponentFactory { // This is for backward compatibility private String id; public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container ) throws ComponentInstantiationException { // for backward-compatibility with the old component factories delegate to the old-style method return newInstance( componentDescriptor, ClassRealmAdapter.getInstance( classRealm ), container ); } protected Object newInstance( ComponentDescriptor componentDescriptor, org.codehaus.classworlds.ClassRealm classRealm, PlexusContainer container ) throws ComponentInstantiationException { throw new IllegalStateException( getClass().getName() + " does not implement component creation." ); } } ComponentFactory.java000066400000000000000000000025671166327066700404700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDescriptor; /** A ServiceFactory is responsible for instantiating a component. * * @author Jason van Zyl * @author Michal Maczka * * @version $Id: ComponentFactory.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface ComponentFactory { /** Component role. */ static String ROLE = ComponentFactory.class.getName(); String getId(); Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container ) throws ComponentInstantiationException; } ComponentFactoryManager.java000066400000000000000000000016461166327066700417600ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ComponentFactoryManager.java 6975 2007-10-21 08:35:34Z jvanzyl $ */ public interface ComponentFactoryManager { ComponentFactory findComponentFactory( String id ) throws UndefinedComponentFactoryException; } ComponentInstantiationException.java000066400000000000000000000023121166327066700435500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Michal Maczka * * @version $Id: ComponentInstantiationException.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public class ComponentInstantiationException extends Exception { public ComponentInstantiationException( String message ) { super( message ); } public ComponentInstantiationException( String message, Throwable cause ) { super( message, cause ); } public ComponentInstantiationException( Throwable cause ) { super( cause ); } } DefaultComponentFactoryManager.java000066400000000000000000000041111166327066700432530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.factory.java.JavaComponentFactory; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; /** * @author Jason van Zyl * @version $Id: DefaultComponentFactoryManager.java 7828 2008-11-14 22:07:56Z dain $ */ public class DefaultComponentFactoryManager implements ComponentFactoryManager, Contextualizable { private ComponentFactory defaultComponentFactory = new JavaComponentFactory(); private PlexusContainer container; public ComponentFactory findComponentFactory( String id ) throws UndefinedComponentFactoryException { if ( id == null || id.equals( "java" ) ) { return defaultComponentFactory; } try { return container.lookup( ComponentFactory.class, id ); } catch ( ComponentLookupException e ) { throw new UndefinedComponentFactoryException( "Specified component factory cannot be found: " + id ); } } public void contextualize( Context context ) throws ContextException { container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); } } UndefinedComponentFactoryException.java000066400000000000000000000022601166327066700441570ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: UndefinedComponentFactoryException.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class UndefinedComponentFactoryException extends Exception { public UndefinedComponentFactoryException( String message ) { super( message ); } public UndefinedComponentFactoryException( String message, Throwable cause ) { super( message, cause ); } public UndefinedComponentFactoryException( Throwable cause ) { super( cause ); } } 000077500000000000000000000000001166327066700352425ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/javaJavaComponentFactory.java000066400000000000000000000105271166327066700422060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/javapackage org.codehaus.plexus.component.factory.java; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.factory.AbstractComponentFactory; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import java.lang.reflect.Modifier; /** * Component Factory for components written in Java Language which have default no parameter constructor * * @author Jason van Zyl * @author Michal Maczka * @version $Id: JavaComponentFactory.java 7847 2008-11-18 14:17:16Z jvanzyl $ */ public class JavaComponentFactory extends AbstractComponentFactory { public String getId() { return "java"; } public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container ) throws ComponentInstantiationException { Class implementationClass = null; try { String implementation = componentDescriptor.getImplementation(); implementationClass = classRealm.loadClass( implementation ); int modifiers = implementationClass.getModifiers(); if ( Modifier.isInterface( modifiers ) ) { throw new ComponentInstantiationException( "Cannot instantiate implementation '" + implementation + "' because the class is a interface." ); } if ( Modifier.isAbstract( modifiers ) ) { throw new ComponentInstantiationException( "Cannot instantiate implementation '" + implementation + "' because the class is abstract." ); } Object instance = implementationClass.newInstance(); return instance; } catch ( InstantiationException e ) { //PLXAPI: most probably cause of this is the implementation class not having // a default constructor. throw makeException( classRealm, componentDescriptor, implementationClass, e ); } catch ( ClassNotFoundException e ) { throw makeException( classRealm, componentDescriptor, implementationClass, e ); } catch ( IllegalAccessException e ) { throw makeException( classRealm, componentDescriptor, implementationClass, e ); } catch ( LinkageError e ) { throw makeException( classRealm, componentDescriptor, implementationClass, e ); } } private ComponentInstantiationException makeException( ClassRealm componentClassRealm, ComponentDescriptor componentDescriptor, Class implementationClass, Throwable e ) { // ---------------------------------------------------------------------- // Display the realm when there is an error, We should probably return a string here so we // can incorporate this into the error message for easy debugging. // ---------------------------------------------------------------------- String msg; if ( componentClassRealm == null ) { msg = "classRealm is null for " + componentDescriptor; } else { msg = "Could not instantiate component: " + componentDescriptor.getHumanReadableKey() + " realm: " + componentClassRealm.getId(); } return new ComponentInstantiationException( msg, e ); } } 000077500000000000000000000000001166327066700342645ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/managerAbstractComponentManager.java000066400000000000000000000153221166327066700420530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.builder.AbstractComponentBuildListener; import org.codehaus.plexus.component.builder.ComponentBuilder; import org.codehaus.plexus.component.builder.XBeanComponentBuilder; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.lifecycle.LifecycleHandler; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; public abstract class AbstractComponentManager implements ComponentManager { protected final MutablePlexusContainer container; private final ClassRealm realm; protected final ComponentDescriptor componentDescriptor; private final Class type; private final String role; private final String roleHint; protected final ComponentBuilder builder = new XBeanComponentBuilder(this); private final LifecycleHandler lifecycleHandler; /** * Contains a mapping from singleton instances to the realms * they were used to configure with. This realm will be used to * call all lifecycle methods. * @return a synchronized map, make sure to synchronize the map when iterating. */ protected final Map componentContextRealms = Collections.synchronizedMap(new HashMap()); private int connections; private long startId; public AbstractComponentManager( MutablePlexusContainer container, LifecycleHandler lifecycleHandler, ComponentDescriptor componentDescriptor, String role, String roleHint) { if ( container == null ) { throw new NullPointerException( "container is null" ); } this.container = container; if ( lifecycleHandler == null ) { throw new NullPointerException( "lifecycleHandler is null" ); } this.lifecycleHandler = lifecycleHandler; if ( componentDescriptor == null ) { throw new NullPointerException( "componentDescriptor is null" ); } this.componentDescriptor = componentDescriptor; if ( role == null ) { throw new NullPointerException( "role is null" ); } this.role = role; if ( roleHint == null ) { throw new NullPointerException( "roleHint is null" ); } this.roleHint = roleHint; this.realm = componentDescriptor.getRealm(); this.type = componentDescriptor.getImplementationClass(); } public ComponentDescriptor getComponentDescriptor() { return componentDescriptor; } public Class getType() { return type; } public ClassRealm getRealm() { return realm; } public String getRole() { return role; } public String getRoleHint() { return roleHint; } public LifecycleHandler getLifecycleHandler() { return lifecycleHandler; } protected void incrementConnectionCount() { connections++; } protected void decrementConnectionCount() { connections--; } protected boolean connected() { return connections > 0; } public int getConnections() { return connections; } // ---------------------------------------------------------------------- // Lifecylce Management // ---------------------------------------------------------------------- public void start( Object component ) throws PhaseExecutionException { startId = NEXT_START_ID.getAndIncrement(); getLifecycleHandler().start( component, this, componentDescriptor.getRealm() ); } /** * @deprecated for internal use only.. will be removed */ public long getStartId() { return startId; } protected T createComponentInstance() throws ComponentInstantiationException, ComponentLifecycleException { return builder.build(componentDescriptor, realm, new AbstractComponentBuildListener() { public void componentCreated( ComponentDescriptor componentDescriptor, Object component, ClassRealm realm) { componentContextRealms.put( component, realm ); } }); } protected void endComponentLifecycle( Object component ) throws ComponentLifecycleException { ClassRealm contextRealm = componentContextRealms.remove( component ); if ( contextRealm == null ) { contextRealm = container.getLookupRealm( component ); } try { getLifecycleHandler().end( component, this, contextRealm ); } catch ( PhaseExecutionException e ) { throw new ComponentLifecycleException( "Error ending component lifecycle", e ); } } public MutablePlexusContainer getContainer() { return container; } public Logger getLogger() { return container.getLogger(); } public void dissociateComponentRealm( ClassRealm realm ) throws ComponentLifecycleException { synchronized ( componentContextRealms ) { for ( Iterator> iterator = componentContextRealms.entrySet().iterator(); iterator.hasNext(); ) { Entry entry = iterator.next(); ClassRealm componentRealm = entry.getValue(); if ( componentRealm.getId().equals( realm.getId() ) ) { iterator.remove(); } } } } } ComponentManager.java000066400000000000000000000050131166327066700403630ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.lifecycle.LifecycleHandler; import java.util.concurrent.atomic.AtomicLong; /** * Manages a component manager. * Determines when a component is shutdown, and when it's started up. Each * manager deals with only one component class, though may handle multiple * instances of this class. * * @author Jason van Zyl * * @version $Id: ComponentManager.java 8061 2009-01-19 23:33:12Z dain $ */ public interface ComponentManager { String ROLE = ComponentManager.class.getName(); /** * @deprecated for internal use only.. will be removed */ AtomicLong NEXT_START_ID = new AtomicLong( 1 ); int getConnections(); /** * @deprecated use start instead */ LifecycleHandler getLifecycleHandler(); void dispose() throws ComponentLifecycleException; void release( Object component ) throws ComponentLifecycleException; T getComponent() throws ComponentInstantiationException, ComponentLifecycleException; ComponentDescriptor getComponentDescriptor(); Class getType(); String getRole(); String getRoleHint(); MutablePlexusContainer getContainer(); void dissociateComponentRealm( ClassRealm realm ) throws ComponentLifecycleException; ClassRealm getRealm(); void start(Object component) throws PhaseExecutionException; /** * @deprecated for internal use only.. will be removed */ long getStartId(); }ComponentManagerFactory.java000066400000000000000000000017451166327066700417230ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.lifecycle.LifecycleHandler; public interface ComponentManagerFactory { /** * Gets the unique identifier of this ComponentManagerFactory. This id is the instantiation strategy specified * in a component descriptor. * @return the unique identifier and instantiation strategy name */ String getId(); /** * Creates a new component manager for the specified component descriptor. */ ComponentManager createComponentManager( MutablePlexusContainer container, LifecycleHandler lifecycleHandler, ComponentDescriptor componentDescriptor, String role, String roleHint ); } PerLookupComponentManager.java000066400000000000000000000042501166327066700422260ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.lifecycle.LifecycleHandler; /** * Creates a new component manager for every lookup * * @author Jason van Zyl * * @version $Id: PerLookupComponentManager.java 7858 2008-11-20 03:48:11Z dain $ */ public class PerLookupComponentManager extends AbstractComponentManager { public PerLookupComponentManager( MutablePlexusContainer container, LifecycleHandler lifecycleHandler, ComponentDescriptor componentDescriptor, String role, String roleHint ) { super( container, lifecycleHandler, componentDescriptor, role, roleHint ); } public void dispose() { } public T getComponent( ) throws ComponentInstantiationException, ComponentLifecycleException { T component = createComponentInstance(); return component; } public void release( Object component ) throws ComponentLifecycleException { decrementConnectionCount(); endComponentLifecycle( component ); // non cleanup map references for per-lookup cause leak componentContextRealms.remove( component ); } } PerLookupComponentManagerFactory.java000066400000000000000000000017001166327066700435530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.lifecycle.LifecycleHandler; public class PerLookupComponentManagerFactory implements ComponentManagerFactory { public String getId() { return "per-lookup"; } @SuppressWarnings({"RawUseOfParameterizedType"}) public ComponentManager createComponentManager( MutablePlexusContainer container, LifecycleHandler lifecycleHandler, ComponentDescriptor componentDescriptor, String role, String roleHint ) { return new PerLookupComponentManager( container, lifecycleHandler, componentDescriptor, role, roleHint ); } } SingletonComponentManager.java000066400000000000000000000045411166327066700422530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.lifecycle.LifecycleHandler; /** * This ensures a component is only used as a singleton, and is only shutdown when the container * shuts down. * * @author Jason van Zyl */ public class SingletonComponentManager extends AbstractComponentManager { private T singleton; public SingletonComponentManager( MutablePlexusContainer container, LifecycleHandler lifecycleHandler, ComponentDescriptor componentDescriptor, String role, String roleHint ) { super( container, lifecycleHandler, componentDescriptor, role, roleHint ); } public synchronized void release( Object component ) throws ComponentLifecycleException { if ( singleton == component ) { dispose(); } } public synchronized void dispose() throws ComponentLifecycleException { if ( singleton != null ) { endComponentLifecycle( singleton ); singleton = null; } } public synchronized T getComponent( ) throws ComponentInstantiationException, ComponentLifecycleException { if ( singleton == null ) { singleton = createComponentInstance(); } incrementConnectionCount(); return singleton; } } SingletonComponentManagerFactory.java000066400000000000000000000016771166327066700436120ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.lifecycle.LifecycleHandler; public class SingletonComponentManagerFactory implements ComponentManagerFactory { public String getId() { return "singleton"; } @SuppressWarnings({"RawUseOfParameterizedType"}) public ComponentManager createComponentManager( MutablePlexusContainer container, LifecycleHandler lifecycleHandler, ComponentDescriptor componentDescriptor, String role, String roleHint ) { return new SingletonComponentManager( container, lifecycleHandler, componentDescriptor, role, roleHint ); } } UndefinedComponentManagerException.java000066400000000000000000000017011166327066700440640ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * @version $Id: UndefinedComponentManagerException.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class UndefinedComponentManagerException extends Exception { public UndefinedComponentManagerException( String message ) { super( message ); } } 000077500000000000000000000000001166327066700350715ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repositoryComponentDependency.java000066400000000000000000000062071166327066700417020ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This represents a project which this component depends upon to function * properly, for example, a required jar file. See Apache Maven for an * example of a dependency in action. * * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: ComponentDependency.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentDependency { private static final String DEAULT_DEPENDENCY_TYPE = "jar"; private String groupId; private String artifactId; private String type = DEAULT_DEPENDENCY_TYPE; private String version; /** * Gets a key for an artifact, which is an alias for a specific * project timeline in a group. * @return a key for an artifact */ public String getArtifactId() { return artifactId; } /** * Sets the dependency's artifact ID. * @param artifactId the artifact ID */ public void setArtifactId(String artifactId) { this.artifactId = artifactId; } /** * Gets a key for a group, which represents a set of artifacts timelines. * @return a key for a group */ public String getGroupId() { return groupId; } /** * Sets the dependency's group ID. * @param groupId the group ID */ public void setGroupId(String groupId) { this.groupId = groupId; } /** * Gets the type of dependency, for example a "jar". * @return the type of dependency */ public String getType() { return type; } /** * Sets the dependency project's type. * @param type the dependency's type */ public void setType(String type) { this.type = type; } /** * Returns a specific point in a project's timeline. * i.e. version 1, or 2.1.4 * @return a specific point in a project's timeline */ public String getVersion() { return version; } /** * Sets the point in a project's development timeline * @param version the project's version */ public void setVersion(String version) { this.version = version; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append( "groupId = " ).append( groupId ). append( ", artifactId = " ).append( artifactId ). append( ", version = " ).append( version ). append( ", type = " ).append( type ); return sb.toString(); } } ComponentDescriptor.java000066400000000000000000000437211166327066700417440ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.configuration.PlexusConfiguration; import java.util.ArrayList; import java.util.List; import java.util.Arrays; import java.util.Collections; /** * Component instantiation description. * * @author Jason van Zyl * @author bob mcwhirter * @author Michal Maczka * @version $Id: ComponentDescriptor.java 8476 2009-10-09 13:41:39Z bentmann $ */ public class ComponentDescriptor { private String alias = null; private String role = null; private Class roleClass; private String roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT; private String implementation; private Class implementationClass; private String version; private String componentType; private PlexusConfiguration configuration; private String instantiationStrategy; private String lifecycleHandler; private String componentProfile; private final List requirements = new ArrayList(); private String componentFactory; private String componentComposer; private String componentConfigurator; private String description; private ClassRealm realm; // ---------------------------------------------------------------------- // These two fields allow for the specification of an isolated class realm // and dependencies that might be specified in a component configuration // setup by a user i.e. this is here to allow isolation for components // that are not picked up by the discovery mechanism. // ---------------------------------------------------------------------- private boolean isolatedRealm; // ---------------------------------------------------------------------- private ComponentSetDescriptor componentSetDescriptor; private String source; // ---------------------------------------------------------------------- // Instance methods // ---------------------------------------------------------------------- public ComponentDescriptor() { } public ComponentDescriptor( Class implementationClass, ClassRealm realm ) { this.implementationClass = implementationClass; this.implementation = implementationClass.getName(); this.realm = realm; } /** * The location this information came from (descriptor file URI). */ public void setSource( String source ) { this.source = source; } /** * The location this information came from (descriptor file URI). */ public String getSource() { return source; } /** * Returns a human-friendly key, suitable for display. * * @return a human-friendly key */ public String getHumanReadableKey() { StringBuffer key = new StringBuffer(); key.append( "role: '" ).append( getRole() ).append( "'" ); key.append( ", implementation: '" ).append( getImplementation() ).append( "'" ); if ( roleHint != null ) { key.append( ", role hint: '" ).append( getRoleHint() ).append( "'" ); } if ( alias != null ) { key.append( ", alias: '" ).append( getAlias() ).append( "'" ); } return key.toString(); } /** * Returns an alias for this component. An alias as an alternate name other than the normal key. * * @return an alias for this component */ public String getAlias() { return alias; } /** * Sets the alias for this component. * * @param alias alternate name to set */ public void setAlias( String alias ) { this.alias = alias; } /** * Returns the role of this component. * * @return the role of this component */ public String getRole() { return role; } public Class getRoleClass() { attemptRoleLoad(); if (roleClass == null) { return (Class) Object.class; } return roleClass; } private void attemptRoleLoad() { if ( roleClass == null && getRole() != null && getRealm() != null ) { try { roleClass = getRealm().loadClass( getRole() ); Thread.currentThread(); } catch ( Throwable ignored ) { Thread.currentThread(); } } } /** * Sets the role of this component. * * @param role this component's role */ public void setRole( String role ) { this.role = role; // reload role class roleClass = null; attemptRoleLoad(); } public void setRoleClass( Class roleClass ) { this.roleClass = roleClass; if (roleClass == null) { role = null; } else { role = roleClass.getName(); } } /** * Returns the role-hint of this component. * * @return the role-hint of this component */ public String getRoleHint() { return roleHint; } /** * Sets the role-hint of this component. Pasing null will set the hint to the default value. * * @param roleHint this component's role-hint */ public void setRoleHint( String roleHint ) { if ( ( roleHint == null ) || roleHint.trim().equals( "" ) ) { this.roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT; } else { this.roleHint = roleHint; } } /** * Returns the implementation of this componet. Implementation is a string denoting a FQCN in normal Java * components, or some other name or file for other component factory implementations. * * @return the implementation of this componet's role. */ public String getImplementation() { return implementation; } /** * Sets the implementation of this componet. * * @param implementation string denoting a FQCN in normal Java components, or some other name or file for other * component factory implementations */ public void setImplementation( String implementation ) { this.implementation = implementation; // reload implementation class implementationClass = null; attemptImplementationLoad(); } /** * Returns the implementation class of this componet, or null if the implementation class can not be loaded. * * @return the implementation of this componet's role. */ public Class getImplementationClass() { attemptImplementationLoad(); if (implementationClass == null) { return (Class) Object.class; } return implementationClass; } private void attemptImplementationLoad() { if ( implementationClass == null && getImplementation() != null && getRealm() != null ) { try { implementationClass = getRealm().loadClass( getImplementation() ); Thread.currentThread(); } catch ( Throwable ignored ) { Thread.currentThread(); } } } public void setImplementationClass( Class implementationClass ) { this.implementationClass = implementationClass; if (implementationClass == null) { implementation = null; } else { implementation = implementationClass.getName(); } } /** * Returns a specific point in a components's project timeline. i.e. version 1, or 2.1.4 * * @return a specific point in a components's project timeline */ public String getVersion() { return version; } /** * Sets the point in a components's project development timeline * * @param version the components's version */ public void setVersion( String version ) { this.version = version; } /** * Returns the type of this component. * * @return the type of this component */ public String getComponentType() { return componentType; } /** * Sets this component's type. * * @param componentType the type to set */ public void setComponentType( String componentType ) { this.componentType = componentType; } /** * Returns the type of instantiation strategy for this component. * * @return the type of instantiation strategy for this component */ public String getInstantiationStrategy() { return instantiationStrategy; } /** * Returns configuration values defined for this component. * * @return configuration values defined for this component */ public PlexusConfiguration getConfiguration() { return configuration; } /** * Sets the configuration hierarchy for this component. * * @param configuration the configuration hierarchy to set */ public void setConfiguration( PlexusConfiguration configuration ) { this.configuration = configuration; } /** * Returns true if this component has a configuration. * * @return true if this component has a configuration */ public boolean hasConfiguration() { return configuration != null; } /** * Returns the lifecycle-handler for this component. * * @return the lifecycle-handler for this component */ public String getLifecycleHandler() { return lifecycleHandler; } /** * Sets the lifecycle-handler for this component. For example, "basic", "passive", "bootstrap". * * @param lifecycleHandler the lifecycle handler string to set */ public void setLifecycleHandler( String lifecycleHandler ) { this.lifecycleHandler = lifecycleHandler; } public String getComponentProfile() { return componentProfile; } public void setComponentProfile( String componentProfile ) { this.componentProfile = componentProfile; } /** * Add a project requirement to this component. * * @param requirement the requirement to add */ public void addRequirement( ComponentRequirement requirement ) { this.requirements.add( requirement ); } /** * Add a project requirement to this component. * * @param requirement the requirement to add */ public void addRequirement( ComponentRequirement... requirement ) { this.requirements.addAll( Arrays.asList( requirement )); } /** * Adds a list of requirements to this component. * * @param requirements the requirements to add */ public void addRequirements( List requirements ) { this.requirements.addAll( requirements ); } /** * Remove a project requirement from this component. * * @param requirement the requirement to remove */ public void removeRequirement( ComponentRequirement... requirement ) { this.requirements.removeAll( Arrays.asList( requirement )); } /** * Removes a list of requirements from this component. * * @param requirements the requirements to remove */ public void removeRequirements( List requirements ) { this.requirements.removeAll( requirements ); } /** * Returns all project requirements of this component. * * @return all project requirements of this component */ public List getRequirements() { return Collections.unmodifiableList( requirements ); } /** * Returns an id of the factory used to create this component. * * @return an id of the factory used to create this component */ public String getComponentFactory() { return componentFactory; } /** * Sets the id of the factory to use to create this component. For example, "jruby" will use a JRuby factory. * * @param componentFactory */ public void setComponentFactory( String componentFactory ) { this.componentFactory = componentFactory; } /** * Returns the ID of the type of composer this component will use. For example, "setter" or "field" for the * different types of dependency injection. * * @return the ID of the type of composer this component will use */ public String getComponentComposer() { return componentComposer; } /** * Sets a representation of the composer this component uses. * * @param componentComposer string representation of the composer to use */ public void setComponentComposer( String componentComposer ) { this.componentComposer = componentComposer; } /** * Return a human-readable description of this component. * * @return a human-readable description of this component */ public String getDescription() { return description; } /** * Sets a description of this component for users to read. * * @param description a human-readable description of this component */ public void setDescription( String description ) { this.description = description; } /** * Sets the instantiation-strategy for this component. For example, "container". * * @param instantiationStrategy */ public void setInstantiationStrategy( String instantiationStrategy ) { this.instantiationStrategy = instantiationStrategy; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- /** * Returns true if this may be in an isolated classrealm. * * @return true if this may be in an isolated classrealm */ public boolean isIsolatedRealm() { return isolatedRealm; } /** * Sets the component set descriptor of components and dependencies for this component. * * @param componentSetDescriptor the component set descriptor of components and dependencies */ public void setComponentSetDescriptor( ComponentSetDescriptor componentSetDescriptor ) { this.componentSetDescriptor = componentSetDescriptor; } /** * Returns the component set descriptor. * * @return the component set descriptor */ public ComponentSetDescriptor getComponentSetDescriptor() { return componentSetDescriptor; } /** * Sets that this component may be in an isolated classrealm. * * @param isolatedRealm true if this component may be in an isolated classrealm */ public void setIsolatedRealm( boolean isolatedRealm ) { this.isolatedRealm = isolatedRealm; } /** * Returns the type of component configurator for this project. For example "basic" for normal, or "map-oriented" * for map oriented components. * * @return the type of component configurator for this project */ public String getComponentConfigurator() { return componentConfigurator; } /** * Sets the type of component configurator for this project. * * @param componentConfigurator */ public void setComponentConfigurator( String componentConfigurator ) { this.componentConfigurator = componentConfigurator; } /** * The ClassRealm that this component lives under. * * @return ClassRealm that this component lives under */ public ClassRealm getRealm() { return realm; } /** * Set the ClassRealm that this component lives under. * * @param realm the ClassRealm that this component lives under */ public void setRealm( ClassRealm realm ) { this.realm = realm; // reload implementation class implementationClass = null; attemptImplementationLoad(); // reload role class roleClass = null; attemptRoleLoad(); } public String toString() { return getClass().getName() + " [role: '" + getRole() + "', hint: '" + getRoleHint() + "', realm: " + ( realm == null ? "NULL" : "'" + realm + "'" ) + "]"; } // Component identity established here! public boolean equals( Object other ) { if ( this == other ) { return true; } if ( !( other instanceof ComponentDescriptor ) ) { return false; } ComponentDescriptor that = (ComponentDescriptor) other; return eq( getRole(), that.getRole() ) && eq( getRoleHint(), that.getRoleHint() ) && eq( getRealm(), that.getRealm() ); } private static boolean eq( T o1, T o2 ) { return ( o1 != null ) ? o1.equals( o2 ) : o2 == null; } public int hashCode() { int hash = 17; hash = hash * 31 + hash( getRole() ); hash = hash * 31 + hash( getRoleHint() ); hash = hash * 31 + hash( getRealm() ); return hash; } private static int hash( Object obj ) { return ( obj != null ) ? obj.hashCode() : 0; } } ComponentRepository.java000066400000000000000000000030711166327066700417770ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException; import java.util.List; import java.util.Map; public interface ComponentRepository { void addComponentDescriptor( ComponentDescriptor componentDescriptor ) throws CycleDetectedInComponentGraphException; ComponentDescriptor getComponentDescriptor( Class type, String role, String roleHint ); @Deprecated ComponentDescriptor getComponentDescriptor( String role, String roleHint, ClassRealm realm ); Map> getComponentDescriptorMap( Class type, String role ); List> getComponentDescriptorList( Class type, String role ); void removeComponentRealm( ClassRealm classRealm ); } ComponentRequirement.java000066400000000000000000000117331166327066700421240ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This represents a component this is required by another component. * * @author Michal Maczka * @version $Id: ComponentRequirement.java 8525 2009-11-06 15:23:51Z bentmann $ */ public class ComponentRequirement { private String role; private String roleHint = ""; private String fieldName; private String fieldMappingType; private boolean optional; /** * Returns the field name that this component requirement will inject. * @return the field name that this component requirement will inject */ public String getFieldName() { return fieldName; } /** * Sets the name of the field that will be populated by the required * component. * @param fieldName the name of the field to be populated */ public void setFieldName( String fieldName ) { this.fieldName = fieldName; } /** * Returns the role of the required component. * @return the role of the required component */ public String getRole() { return role; } /** * Sets the role of the require component. * @param role the required component's role */ public void setRole( String role ) { this.role = role; } /** * Returns the role-hint of the required component. * @return the role-hint of the required component */ public String getRoleHint() { return roleHint; } /** * Sets the role-hint of the require component. * Passing null or an empty string will match any available implementation. * @param roleHint the required component's role-hint */ public void setRoleHint( String roleHint ) { this.roleHint = ( roleHint != null ) ? roleHint : ""; } /** * Returns the type of the field this component requirement will inject. * @return the type of the field this component requirement will inject */ public String getFieldMappingType() { return fieldMappingType; } /** * Sets the type of the field that will be populated by the required * component. * @param fieldType the type of the field to be populated */ public void setFieldMappingType( String fieldType ) { this.fieldMappingType = fieldType; } /** * Whether this component requirement is optional and needs not be satisfied * * @return {@code true} if the requested component may be missing, {@code false} if the component is mandatory. * @since 1.3.0 */ public boolean isOptional() { return optional; } /** * Controls whether a failure to satisfy this requirement can be tolerated by host component or whether construction * of the host component should also fail. * * @param optional {@code true} if the requested component may be missing, {@code false} if the component is * mandatory. * @since 1.3.0 */ public void setOptional( boolean optional ) { this.optional = optional; } public String toString() { return "ComponentRequirement{" + "role='" + getRole() + "'" + ", " + "roleHint='" + getRoleHint() + "', " + "fieldName='" + getFieldName() + "'" + "}"; } /** * Returns a human-friendly key, suitable for display. * @return a human-friendly key */ public String getHumanReadableKey() { StringBuffer key = new StringBuffer(); key.append( "role: '").append( getRole() ).append( "'" ); if ( getRoleHint() != null ) { key.append( ", role-hint: '" ).append( getRoleHint() ).append( "'. " ); } if ( getFieldName() != null ) { key.append( ", field name: '" ).append( getFieldName() ).append( "' " ); } return key.toString(); } public boolean equals( Object other ) { if ( other instanceof ComponentRequirement ) { String myId = role + ":" + roleHint; ComponentRequirement req = (ComponentRequirement) other; String otherId = req.role + ":" + req.roleHint; return myId.equals( otherId ); } return false; } public int hashCode() { return ( role + ":" + roleHint ).hashCode(); } } ComponentRequirementList.java000066400000000000000000000015261166327066700427570ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; import java.util.List; /** * Created by IntelliJ IDEA. * * @author Andrew Williams * @version $Id: ComponentRequirementList.java 7828 2008-11-14 22:07:56Z dain $ * @since 1.0 */ public class ComponentRequirementList extends ComponentRequirement { private List roleHints; public List getRoleHints() { return roleHints; } public void setRoleHints(List roleHints) { this.roleHints = roleHints; } public String getRoleHint() { StringBuffer buffer = new StringBuffer(); for ( String hint : roleHints ) { if (buffer.length() > 0) { buffer.append(","); } buffer.append(hint); } return buffer.toString(); } } ComponentSetDescriptor.java000066400000000000000000000107301166327066700424120ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.List; /** * Contains a set of ComponentDescriptors and the set's dependencies. * * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: ComponentSetDescriptor.java 7828 2008-11-14 22:07:56Z dain $ */ public class ComponentSetDescriptor { // This field is not currently used in Maven, or Plexus private String id; /** The source location of this component source descriptor */ private String source; /** Flag to indicate whether this component should be loaded in a realm/classloader of its own. */ private boolean isolatedRealm; /** The component descriptors that can be found within this component set descriptor. */ private final List> components = new ArrayList>(); /** The dependencies that are required by the set of components found in this component set descriptor. */ private final List dependencies = new ArrayList(); /** * Returns a list of components in this set. * @return a list of components */ public List> getComponents() { return components; } /** * Add a new ComponentDescriptor to this set. * @param cd the ComponentDescriptor to add */ public void addComponentDescriptor( ComponentDescriptor cd ) { components.add( cd ); } /** * Sets a List of components as this set's contents. * @param components the List of components to set */ public void setComponents( List> components ) { this.components.clear(); this.components.addAll(components); } /** * Returns a List of dependencies of this set of components. * @return a List of dependencies of this set of components */ public List getDependencies() { return dependencies; } /** * Add a depenency to this set's contents. * @param cd the ComponentDependency to add */ public void addDependency( ComponentDependency cd ) { dependencies.add( cd ); } /** * Sets a List of dependencies as this set's component dependencies. * @param dependencies the List of components to set */ public void setDependencies( List dependencies ) { this.dependencies.clear(); this.dependencies.addAll(dependencies); } /** * Sets that this set of components may be in an isolated classrealm. * @param isolatedRealm true if this set of components may be in an * isolated classrealm */ public void setIsolatedRealm( boolean isolatedRealm ) { this.isolatedRealm = isolatedRealm; } /** * Returns true if this set may be in an isolated classrealm. * @return true if this set may be in an isolated classrealm */ public boolean isIsolatedRealm() { return isolatedRealm; } /** * Returns the identifier of this set. * @return the identifier of this set */ public String getId() { return id; } /** * Sets the identifier of this set. * @param id the identifier to set */ public void setId( String id ) { this.id = id; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append( "Component Descriptor: " ); for ( ComponentDescriptor cd : components ) { sb.append( cd.getHumanReadableKey() ).append( "\n" ); } sb.append( "---" ); return sb.toString(); } public String getSource() { return source; } public void setSource( String source ) { this.source = source; } } DefaultComponentRepository.java000066400000000000000000000205131166327066700433040ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import static org.codehaus.plexus.component.CastUtils.isAssignableFrom; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; import org.codehaus.plexus.ClassRealmUtil; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; import org.codehaus.plexus.component.composition.CompositionResolver; import org.codehaus.plexus.component.composition.DefaultCompositionResolver; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.StringUtils; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; /** * @author Jason van Zyl */ public class DefaultComponentRepository extends AbstractLogEnabled implements ComponentRepository { private final Map>>> index = new LinkedHashMap>>>(); private final CompositionResolver compositionResolver = new DefaultCompositionResolver(); public DefaultComponentRepository() { } // ---------------------------------------------------------------------- // Accessors // ---------------------------------------------------------------------- private Multimap> getComponentDescriptors( String role ) { // verify arguments if ( role == null ) { throw new NullPointerException( "role is null" ); } // determine realms to search Set realms = ClassRealmUtil.getContextRealms( null ); if ( realms.isEmpty() ) { realms.addAll( index.keySet() ); } // Get all valid component descriptors Multimap> roleHintIndex = LinkedHashMultimap.create(); for ( ClassRealm realm : realms ) { SortedMap>> roleIndex = index.get( realm ); if (roleIndex != null) { Multimap> descriptors = roleIndex.get( role ); if ( descriptors != null ) { roleHintIndex.putAll( descriptors ); } } } return Multimaps.unmodifiableMultimap( roleHintIndex ); } public ComponentDescriptor getComponentDescriptor( Class type, String role, String roleHint ) { Multimap> roleHintIndex = getComponentDescriptors( role ); Collection> descriptors; if ( StringUtils.isNotEmpty( roleHint ) ) { // specific role hint -> get only those descriptors = roleHintIndex.get( roleHint ); } else { // missing role hint -> get all (wildcard) Collection> allDescriptors = new ArrayList>(); descriptors = roleHintIndex.get( PlexusConstants.PLEXUS_DEFAULT_HINT ); if ( descriptors != null ) { allDescriptors.addAll( descriptors ); } for ( String hint : roleHintIndex.keySet() ) { descriptors = roleHintIndex.get( hint ); if ( descriptors != null ) { allDescriptors.addAll( descriptors ); } } descriptors = allDescriptors; } for ( ComponentDescriptor descriptor : descriptors ) { Class implClass = descriptor.getImplementationClass(); if ( isAssignableFrom( type, implClass ) ) { return (ComponentDescriptor) descriptor; } else if ( Object.class == implClass && role.equals( type.getName() ) ) { return (ComponentDescriptor) descriptor; } } return null; } public Map> getComponentDescriptorMap( Class type, String role ) { Map> descriptors = new TreeMap>(); for ( ComponentDescriptor descriptor : getComponentDescriptors( role ).values() ) { if ( !descriptors.containsKey( descriptor.getRoleHint() ) ) { if ( isAssignableFrom( type, descriptor.getImplementationClass() ) ) { descriptors.put( descriptor.getRoleHint(), (ComponentDescriptor) descriptor ); } } } return descriptors; } public List> getComponentDescriptorList( Class type, String role ) { List> descriptors = new ArrayList>(); for ( ComponentDescriptor descriptor : getComponentDescriptors( role ).values() ) { if ( isAssignableFrom( type, descriptor.getImplementationClass() ) ) { descriptors.add( (ComponentDescriptor) descriptor ); } } return descriptors; } @Deprecated public ComponentDescriptor getComponentDescriptor( String role, String roleHint, ClassRealm realm ) { // find all realms from our realm to the root realm Set realms = new HashSet(); for ( ClassRealm r = realm; r != null; r = r.getParentRealm() ) { realms.add( r ); } // get the component descriptors by roleHint for ( ComponentDescriptor componentDescriptor : getComponentDescriptors( role ).get( roleHint ) ) { // return the first descriptor from our target realms if ( realms.contains( componentDescriptor.getRealm() ) ) { return componentDescriptor; } } return null; } public void removeComponentRealm( ClassRealm classRealm ) { index.remove( classRealm ); } // ---------------------------------------------------------------------- // Lifecylce Management // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // Component Descriptor processing. // ---------------------------------------------------------------------- public void addComponentDescriptor( ComponentDescriptor componentDescriptor ) throws CycleDetectedInComponentGraphException { ClassRealm classRealm = componentDescriptor.getRealm(); SortedMap>> roleIndex = index.get( classRealm ); if (roleIndex == null) { roleIndex = new TreeMap>>(); index.put(classRealm, roleIndex); } String role = componentDescriptor.getRole(); Multimap> roleHintIndex = roleIndex.get( role ); if ( roleHintIndex == null ) { roleHintIndex = LinkedHashMultimap.create(); roleIndex.put( role, roleHintIndex ); } roleHintIndex.put( componentDescriptor.getRoleHint(), componentDescriptor ); compositionResolver.addComponentDescriptor( componentDescriptor ); } } 000077500000000000000000000000001166327066700370675ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/exceptionComponentConfigurationException.java000066400000000000000000000030641166327066700463060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/exceptionpackage org.codehaus.plexus.component.repository.exception; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Exception that is thrown when the class(es) required for a component * implementation are not available. * * @author Jason van Zyl * @version $Id: ComponentConfigurationException.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentConfigurationException extends Exception { private static final long serialVersionUID = -921278352685045303L; /** * Construct a new ComponentConfigurationException instance. * @param message exception message */ public ComponentConfigurationException( String message ) { super( message ); } /** * Construct a new ComponentConfigurationException instance. * @param message exception message * @param cause causing exception to chain */ public ComponentConfigurationException( String message, Throwable cause ) { super( message, cause ); } } ComponentDescriptorUnmarshallingException.java000066400000000000000000000031601166327066700503370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/exceptionpackage org.codehaus.plexus.component.repository.exception; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Exception that is thrown when the class(es) required for a component * implementation are not available. * * @author Jason van Zyl * @version $Id: ComponentDescriptorUnmarshallingException.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentDescriptorUnmarshallingException extends Exception { private static final long serialVersionUID = 6991583130117543536L; /** * Construct a new ComponentDescriptorUnmarshallingException instance. * @param message exception message */ public ComponentDescriptorUnmarshallingException( String message ) { super( message ); } /** * Construct a new ComponentDescriptorUnmarshallingException instance. * @param message exception message * @param cause causing exception to chain */ public ComponentDescriptorUnmarshallingException( String message, Throwable cause ) { super( message, cause ); } } ComponentImplementationNotFoundException.java000066400000000000000000000031561166327066700501430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/exceptionpackage org.codehaus.plexus.component.repository.exception; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Exception that is thrown when the class(es) required for a component * implementation are not available. * * @author Jason van Zyl * * @version $Id: ComponentImplementationNotFoundException.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentImplementationNotFoundException extends Exception { private static final long serialVersionUID = -9171668987729438489L; /** * Construct a new ComponentImplementationNotFoundException instance. * @param message exception message */ public ComponentImplementationNotFoundException( String message ) { super( message ); } /** * Construct a new ComponentImplementationNotFoundException instance. * @param message exception message * @param cause causing exception to chain */ public ComponentImplementationNotFoundException( String message, Throwable cause ) { super( message, cause ); } } ComponentLifecycleException.java000066400000000000000000000030331166327066700453720ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/exceptionpackage org.codehaus.plexus.component.repository.exception; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Exception that is thrown when the class(es) required for a component * implementation are not available. * * @author Jason van Zyl * @version $Id: ComponentLifecycleException.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentLifecycleException extends Exception { private static final long serialVersionUID = 146489359157036908L; /** * Construct a new ComponentLifecycleException instance. * @param message exception message */ public ComponentLifecycleException( String message ) { super( message ); } /** * Construct a new ComponentLifecycleException instance. * @param message exception message * @param cause causing exception to chain */ public ComponentLifecycleException( String message, Throwable cause ) { super( message, cause ); } } ComponentLookupException.java000066400000000000000000000054371166327066700447560ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/exceptionpackage org.codehaus.plexus.component.repository.exception; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import org.codehaus.plexus.classworlds.realm.ClassRealm; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * The exception which is thrown by a component repository when * the requested component cannot be found. * * @author Jason van Zyl * @version $Id: ComponentLookupException.java 8506 2009-10-20 15:30:13Z bentmann $ */ public class ComponentLookupException extends Exception { private String LS = System.getProperty( "line.separator" ); private String role; private String roleHint; private ClassRealm realm; public ComponentLookupException( String message, String role, String roleHint ) { super( message ); this.role = role; this.roleHint = roleHint; } public ComponentLookupException( String message, String role, String roleHint, Throwable cause ) { super( message, cause ); this.role = role; this.roleHint = roleHint; } public ComponentLookupException( String message, String role, String roleHint, ClassRealm realm ) { super( message ); this.role = role; this.roleHint = roleHint; this.realm = realm; } public ComponentLookupException( String message, String role, String roleHint, ClassRealm realm, Throwable cause ) { super( message, cause ); this.role = role; this.roleHint = roleHint; this.realm = realm; } public String getMessage() { StringBuffer sb = new StringBuffer() .append( super.getMessage() ).append( LS ) .append( " role: ").append( role ).append( LS ) .append( " roleHint: ").append( roleHint ).append( LS ) .append( "classRealm: "); if ( realm != null ) { sb.append( realm.getId() ).append( LS ); ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); PrintStream ps = new PrintStream( os ); realm.display( ps ); sb.append( os.toString() ); } else { sb.append( "none specified" ); } return sb.toString(); } } ComponentManagerImplementationNotFoundException.java000066400000000000000000000032241166327066700514320ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/exceptionpackage org.codehaus.plexus.component.repository.exception; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Exception that is thrown when the class(es) required for a component * implementation are not available. * * @author Jason van Zyl * @version $Id: ComponentManagerImplementationNotFoundException.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentManagerImplementationNotFoundException extends Exception { private static final long serialVersionUID = 2365017114180373632L; /** * Construct a new ComponentManagerImplementationNotFoundException instance. * @param message exception message */ public ComponentManagerImplementationNotFoundException( String message ) { super( message ); } /** * Construct a new ComponentManagerImplementationNotFoundException instance. * @param message exception message * @param cause causing exception to chain */ public ComponentManagerImplementationNotFoundException( String message, Throwable cause ) { super( message, cause ); } } ComponentProfileException.java000066400000000000000000000030211166327066700450700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/exceptionpackage org.codehaus.plexus.component.repository.exception; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Exception that is thrown when the class(es) required for a component * implementation are not available. * * @author Jason van Zyl * @version $Id: ComponentProfileException.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentProfileException extends Exception { private static final long serialVersionUID = -4099483467183306853L; /** * Construct a new ComponentProfileException instance. * @param message exception message */ public ComponentProfileException( String message ) { super( message ); } /** * Construct a new ComponentProfileException instance. * @param message exception message * @param cause causing exception to chain */ public ComponentProfileException( String message, Throwable cause ) { super( message, cause ); } } ComponentRepositoryException.java000066400000000000000000000030421166327066700456520ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/exceptionpackage org.codehaus.plexus.component.repository.exception; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Exception that is thrown when the class(es) required for a component * implementation are not available. * * @author Jason van Zyl * @version $Id: ComponentRepositoryException.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentRepositoryException extends Exception { private static final long serialVersionUID = 3698017788731736736L; /** * Construct a new ComponentRepositoryException instance. * @param message exception message */ public ComponentRepositoryException( String message ) { super( message ); } /** * Construct a new ComponentRepositoryException instance. * @param message exception message * @param cause causing exception to chain */ public ComponentRepositoryException( String message, Throwable cause ) { super( message, cause ); } } 000077500000000000000000000000001166327066700355005ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/ioPlexusTools.java000066400000000000000000000252071166327066700406520ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/iopackage org.codehaus.plexus.component.repository.io; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.io.PrintStream; import java.io.Reader; import java.io.StringReader; import java.util.LinkedList; import java.util.List; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDependency; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.component.repository.ComponentRequirementList; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.configuration.io.XmlPlexusConfigurationReader; /** * @author Jason van Zyl */ public class PlexusTools { public static PlexusConfiguration buildConfiguration( String resourceName, Reader configuration ) throws PlexusConfigurationException { try { XmlPlexusConfigurationReader reader = new XmlPlexusConfigurationReader(); PlexusConfiguration result = reader.read( configuration ); return result; } catch ( PlexusConfigurationException e ) { throw new PlexusConfigurationException( "PlexusConfigurationException building configuration from: " + resourceName, e ); } catch ( IOException e ) { throw new PlexusConfigurationException( "IO error building configuration from: " + resourceName, e ); } } public static PlexusConfiguration buildConfiguration( String configuration ) throws PlexusConfigurationException { return buildConfiguration( "", new StringReader( configuration ) ); } public static ComponentDescriptor buildComponentDescriptor( String configuration, ClassRealm realm ) throws PlexusConfigurationException { return buildComponentDescriptor( buildConfiguration( configuration ), realm ); } public static ComponentDescriptor buildComponentDescriptor( PlexusConfiguration configuration ) throws PlexusConfigurationException { return buildComponentDescriptorImpl( configuration, null ); } public static ComponentDescriptor buildComponentDescriptor( PlexusConfiguration configuration, ClassRealm realm ) throws PlexusConfigurationException { if ( realm == null ) { throw new NullPointerException( "realm is null" ); } return buildComponentDescriptorImpl( configuration, realm ); } private static ComponentDescriptor buildComponentDescriptorImpl( PlexusConfiguration configuration, ClassRealm realm ) throws PlexusConfigurationException { String implementation = configuration.getChild( "implementation" ).getValue(); if (implementation == null) { throw new PlexusConfigurationException( "implementation is null" ); } ComponentDescriptor cd; try { if ( realm != null ) { Class implementationClass = realm.loadClass( implementation ); cd = new ComponentDescriptor(implementationClass, realm); } else { cd = new ComponentDescriptor(); cd.setImplementation( implementation ); } } catch ( Throwable e ) { throw new PlexusConfigurationException("Can not load implementation class " + implementation + " from realm " + realm, e); } cd.setRole( configuration.getChild( "role" ).getValue() ); cd.setRoleHint( configuration.getChild( "role-hint" ).getValue() ); cd.setVersion( configuration.getChild( "version" ).getValue() ); cd.setComponentType( configuration.getChild( "component-type" ).getValue() ); cd.setInstantiationStrategy( configuration.getChild( "instantiation-strategy" ).getValue() ); cd.setLifecycleHandler( configuration.getChild( "lifecycle-handler" ).getValue() ); cd.setComponentProfile( configuration.getChild( "component-profile" ).getValue() ); cd.setComponentComposer( configuration.getChild( "component-composer" ).getValue() ); cd.setComponentConfigurator( configuration.getChild( "component-configurator" ).getValue() ); cd.setComponentFactory( configuration.getChild( "component-factory" ).getValue() ); cd.setDescription( configuration.getChild( "description" ).getValue() ); cd.setAlias( configuration.getChild( "alias" ).getValue() ); String s = configuration.getChild( "isolated-realm" ).getValue(); if ( s != null ) { cd.setIsolatedRealm( s.equals( "true" ) ? true : false ); } // ---------------------------------------------------------------------- // Here we want to look for directives for inlining external // configurations. we probably want to take them from files or URLs. // ---------------------------------------------------------------------- cd.setConfiguration( configuration.getChild( "configuration" ) ); // ---------------------------------------------------------------------- // Requirements // ---------------------------------------------------------------------- PlexusConfiguration[] requirements = configuration.getChild( "requirements" ).getChildren( "requirement" ); for ( int i = 0; i < requirements.length; i++ ) { PlexusConfiguration requirement = requirements[i]; ComponentRequirement cr; PlexusConfiguration[] hints = requirement.getChild( "role-hints" ).getChildren( "role-hint" ); if ( hints != null && hints.length > 0 ) { cr = new ComponentRequirementList(); List hintList = new LinkedList(); for ( PlexusConfiguration hint : hints ) { hintList.add( hint.getValue() ); } ( (ComponentRequirementList) cr ).setRoleHints( hintList ); } else { cr = new ComponentRequirement(); cr.setRoleHint( requirement.getChild( "role-hint" ).getValue() ); } cr.setRole( requirement.getChild( "role" ).getValue() ); cr.setOptional( Boolean.parseBoolean( requirement.getChild( "optional" ).getValue() ) ); cr.setFieldName( requirement.getChild( "field-name" ).getValue() ); cd.addRequirement( cr ); } return cd; } public static ComponentSetDescriptor buildComponentSet( PlexusConfiguration c ) throws PlexusConfigurationException { return buildComponentSet( c, null ); } public static ComponentSetDescriptor buildComponentSet( PlexusConfiguration c, ClassRealm realm ) throws PlexusConfigurationException { ComponentSetDescriptor csd = new ComponentSetDescriptor(); // ---------------------------------------------------------------------- // Components // ---------------------------------------------------------------------- PlexusConfiguration[] components = c.getChild( "components" ).getChildren( "component" ); for ( int i = 0; i < components.length; i++ ) { PlexusConfiguration component = components[i]; csd.addComponentDescriptor( buildComponentDescriptorImpl( component, realm ) ); } // ---------------------------------------------------------------------- // Dependencies // ---------------------------------------------------------------------- PlexusConfiguration[] dependencies = c.getChild( "dependencies" ).getChildren( "dependency" ); for ( int i = 0; i < dependencies.length; i++ ) { PlexusConfiguration d = dependencies[i]; ComponentDependency cd = new ComponentDependency(); cd.setArtifactId( d.getChild( "artifact-id" ).getValue() ); cd.setGroupId( d.getChild( "group-id" ).getValue() ); String type = d.getChild( "type" ).getValue(); if(type != null) { cd.setType( type ); } cd.setVersion( d.getChild( "version" ).getValue() ); csd.addDependency( cd ); } return csd; } public static void writeConfiguration( PrintStream out, PlexusConfiguration configuration ) throws PlexusConfigurationException { writeConfiguration( out, configuration, "" ); } private static void writeConfiguration( PrintStream out, PlexusConfiguration configuration, String indent ) throws PlexusConfigurationException { out.print( indent + "<" + configuration.getName() ); String[] atts = configuration.getAttributeNames(); if ( atts.length > 0 ) { for ( int i = 0; i < atts.length; i++ ) { out.print( "\n" + indent + " " + atts[i] + "='" + configuration.getAttribute( atts[i] ) + "'" ); } } PlexusConfiguration[] pc = configuration.getChildren(); if ( ( configuration.getValue() != null && configuration.getValue().trim().length() > 0 ) || pc.length > 0 ) { out.print( ">" + ( configuration.getValue() == null ? "" : configuration.getValue().trim() ) ); if ( pc.length > 0 ) { out.println(); for ( int i = 0; i < pc.length; i++ ) { writeConfiguration( out, pc[i], indent + " " ); } out.print( indent ); } out.println( "" ); } else { out.println( "/>" ); } } } plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/000077500000000000000000000000001166327066700335765ustar00rootroot00000000000000DefaultPlexusConfiguration.java000066400000000000000000000140431166327066700417010ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configurationpackage org.codehaus.plexus.configuration; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /** * @version $Id: DefaultPlexusConfiguration.java 8346 2009-08-20 16:46:39Z bentmann $ */ public class DefaultPlexusConfiguration implements PlexusConfiguration { private String name; private String value; private Map attributes; private Map> childMap; private List childList; protected DefaultPlexusConfiguration() { this( "configuration" ); } protected DefaultPlexusConfiguration( String name ) { this( name, null ); } protected DefaultPlexusConfiguration( String name, String value ) { super(); this.name = name; this.value = value; this.attributes = new LinkedHashMap(); this.childMap = new LinkedHashMap>(); this.childList = new ArrayList(); } // ---------------------------------------------------------------------- // Name handling // ---------------------------------------------------------------------- public String getName() { return name; } public void setName( String name ) { this.name = name; } // ---------------------------------------------------------------------- // Value handling // ---------------------------------------------------------------------- public String getValue() { return value; } public String getValue( String defaultValue ) { String value = getValue(); if ( value == null ) { value = defaultValue; } return value; } public void setValue( String val ) { value = val; } public PlexusConfiguration setValueAndGetSelf( String val ) { setValue( val ); return this; } // ---------------------------------------------------------------------- // Attribute handling // ---------------------------------------------------------------------- public void setAttribute( String name, String value ) { attributes.put( name, value ); } public String getAttribute( String name ) { return attributes.get( name ); } public String getAttribute( String name, String defaultValue ) { String value = getAttribute( name ); if ( value == null ) { value = defaultValue; } return value; } public String[] getAttributeNames() { return attributes.keySet().toArray( new String[attributes.size()] ); } // ---------------------------------------------------------------------- // Child handling // ---------------------------------------------------------------------- public PlexusConfiguration getChild( String name ) { return getChild( name, true ); } public PlexusConfiguration getChild( int i ) { return childList.get( i ); } public PlexusConfiguration getChild( String name, boolean createChild ) { List childs = childMap.get( name ); boolean noneFound = ( childs == null || childs.size() == 0 ); if ( noneFound && createChild ) { addChild( name ); return getChild( name, false ); } else if ( noneFound && !createChild ) { return null; } else { return childs.get( 0 ); } } public PlexusConfiguration[] getChildren() { return childList.toArray( new PlexusConfiguration[childList.size()] ); } public PlexusConfiguration[] getChildren( String name ) { List childs = new ArrayList(); List childList = childMap.get( name ); if ( childList != null ) { childs.addAll( childList ); } return childs.toArray( new PlexusConfiguration[childs.size()] ); } public void addChild( PlexusConfiguration child ) { childList.add( child ); List children = childMap.get( child.getName() ); if ( children == null ) { childMap.put( child.getName(), children = new ArrayList() ); } children.add( child ); } public PlexusConfiguration addChild( String name ) { // we are using reflection to try to create same class childs as parent is, // since many Maven and Maven plugins stuff casts the incoming result of this call // to the evil XmlPlexusConfiguration PlexusConfiguration child = null; try { child = getClass().newInstance(); child.setName( name ); } catch ( Exception e ) { // we have a PlexusConfiguration that has no constructor(name) child = new DefaultPlexusConfiguration( name ); } addChild( child ); return this; } public PlexusConfiguration addChild( String name, String value ) { PlexusConfiguration child = new DefaultPlexusConfiguration( name, value ); addChild( child ); return this; } public int getChildCount() { return this.childList.size(); } } PlexusComponentDescriptorMerger.java000066400000000000000000000076651166327066700427440ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configurationpackage org.codehaus.plexus.configuration; import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * * @author Kenney Westerhof * */ public class PlexusComponentDescriptorMerger { /** * Merges override and target, where target is updated with override. */ public static void merge( ComponentDescriptor override, ComponentDescriptor target ) { if ( override.getImplementation() != null ) { target.setImplementation( override.getImplementation() ); } mergeRequirements( override, target ); mergeConfiguration( override, target ); // TODO: other getters/setters. } private static void mergeConfiguration( ComponentDescriptor override, ComponentDescriptor target ) { // try to parse the override dom. If this fails, do not update anything and keep // the original target configuration. Xpp3Dom overrideDom; try { overrideDom = Xpp3DomBuilder.build( new StringReader( override.getConfiguration().toString() ) ); } catch ( XmlPullParserException e1 ) { return; } catch ( IOException e1 ) { return; } // try to parse the target dom. if this fails, replace it with the override configuration, // dom, otherwise merge it. Xpp3Dom targetDom = null; if ( target.getConfiguration() != null ) { try { targetDom = Xpp3DomBuilder.build( new StringReader( target.getConfiguration().toString() ) ); } catch ( XmlPullParserException e1 ) { } catch ( IOException e1 ) { } } if ( targetDom != null ) { Xpp3Dom.mergeXpp3Dom( overrideDom, targetDom ); } else { targetDom = overrideDom; } target.setConfiguration( new XmlPlexusConfiguration( targetDom ) ); } private static void mergeRequirements( ComponentDescriptor override, ComponentDescriptor target ) { List toAdd = new ArrayList(); List toRemove = new ArrayList(); for ( ComponentRequirement sourceReq : override.getRequirements() ) { for ( ComponentRequirement targetReq : target.getRequirements() ) { // if a fieldName is specified, only override target requirements // that also have a fieldname. if ( sourceReq.getFieldName() != null ) { if ( sourceReq.getFieldName().equals( targetReq.getFieldName() ) ) { toRemove.add( targetReq ); toAdd.add( sourceReq ); break; } } else if ( targetReq.getFieldName() == null ) { // no fieldnames specified - just check for the role; hints may be // overriden too. if ( sourceReq.getRole().equals( targetReq.getRole() ) ) { toRemove.add( targetReq ); toAdd.add( sourceReq ); } } } } target.removeRequirements( toRemove ); target.addRequirements( toAdd ); } } PlexusConfiguration.java000066400000000000000000000130711166327066700403740ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configurationpackage org.codehaus.plexus.configuration; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * A configuration data hierarchy for configuring aspects of plexus. For * example, to populate a ComponentDescriptor. Implementation of * PlexusConfiguration may be populated by any means, for example, by XML file. */ public interface PlexusConfiguration { // ---------------------------------------------------------------------- // Name handling // ---------------------------------------------------------------------- /** * Returns the name of this configuration. * @return the name of this configuration */ String getName(); /** * Sets the name of this configuration. * @param name */ void setName(String name); // ---------------------------------------------------------------------- // Value handling // ---------------------------------------------------------------------- /** * Returns the value of this configuration. * @return the value of this configuration * @throws PlexusConfigurationException */ String getValue() throws PlexusConfigurationException; /** * Returns the value of this configuration, or default if one cannot be * found. * @param defaultValue value to return if none is found * @return the value of this configuration */ String getValue( String defaultValue ); /** * Set the value of a configuration element. * @param value * @return */ void setValue( String value ); /** * Set the value of a configuration element and return the PlexusConfiguration object * so that further operations can be carried out. * @param value * @return */ PlexusConfiguration setValueAndGetSelf( String value ); // ---------------------------------------------------------------------- // Attribute handling // ---------------------------------------------------------------------- /** * Sets an attribute on this configuration. * @param name * @param value */ void setAttribute( String name, String value ); /** * Returns an array of attribute names. * @return an array of attribute names */ String[] getAttributeNames(); /** * Returns the value of the named attribute. * @return the value of the named attribute * @throws PlexusConfigurationException */ String getAttribute( String paramName ) throws PlexusConfigurationException; /** * Returns the value of the named attribute, or default if one cannot be * found. * @param defaultValue value to return if none is found * @return the value of the named attribute */ String getAttribute( String name, String defaultValue ); // ---------------------------------------------------------------------- // Child handling // ---------------------------------------------------------------------- /** * Returns the child configuration of the given name. * @param child the name of the child to return * @return the child configuration of the given name */ PlexusConfiguration getChild( String child ); /** * Returns the child configuration at the given location. * @param i the position of the child under this configuration * @return the child configuration at the given location */ PlexusConfiguration getChild( int i ); /** * Returns the child configuration of the given name. * @param child the name of the child to return * @param createChild true if a new child should be create, if none found * @return the child configuration of the given name, or new child if * created */ PlexusConfiguration getChild( String child, boolean createChild ); /** * Returns an array of all child configurations. * @return an array of all child configurations */ PlexusConfiguration[] getChildren(); /** * Returns an array of all child configurations with the given name. * @param name the name of the children configurations to return * @return an array of all child configurations with the given name */ PlexusConfiguration[] getChildren( String name ); /** * Adds a configuration under this configuration, which acts as * a parent. * @param configuration the child configuration to add */ void addChild( PlexusConfiguration configuration ); /** * Add a child element with a given name and return the newly created element. * @param name * @return */ PlexusConfiguration addChild( String name ); /** * Add a child element with a given name, and given value and return the * newly created element. * @param name * @return */ PlexusConfiguration addChild( String name, String value ); /** * Returns the number of directly children under this configuration. * @return the number of directly children under this configuration. */ int getChildCount(); } PlexusConfigurationException.java000066400000000000000000000026551166327066700422610ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configurationpackage org.codehaus.plexus.configuration; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Exception that is thrown when an expected configuration value encounters * problems loading correctly. */ public class PlexusConfigurationException extends Exception { private static final long serialVersionUID = 7559886640184983689L; /** * Construct a new PlexusConfigurationException instance. * @param message exception message */ public PlexusConfigurationException( String message ) { this( message, null ); } /** * Construct a new PlexusConfigurationException instance. * @param message exception message * @param throwable causing exception to chain */ public PlexusConfigurationException( String message, Throwable throwable ) { super( message, throwable ); } } PlexusConfigurationMerger.java000066400000000000000000000344441166327066700415450ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configurationpackage org.codehaus.plexus.configuration; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @todo This merger explicity uses the XML implementation of the plexus configuration but * it must work for configurations coming from any source. */ public class PlexusConfigurationMerger { // -----------------------------------+----------------------------------------------------------------- // E L E M E N T | // -----------------------------------+----------------------------------------------------------------- // load-on-start | user // -----------------------------------+----------------------------------------------------------------- // system-properties | user // -----------------------------------+----------------------------------------------------------------- // configurations-directory | user // -----------------------------------+----------------------------------------------------------------- // logging | user wins // -----------------------------------+----------------------------------------------------------------- // component-repository | user wins // -----------------------------------+----------------------------------------------------------------- // resources | user wins, but system resources show through // -----------------------------------+----------------------------------------------------------------- // component-manager-manager | user wins, but system resources show through // -----------------------------------+----------------------------------------------------------------- // component-discoverer-manager | user wins, but system resources show through // -----------------------------------+----------------------------------------------------------------- // component-factory-manager | user wins, but system resources show through // -----------------------------------+----------------------------------------------------------------- // lifecycle-handler-manager | user wins, but system lifecycles show through // -----------------------------------+----------------------------------------------------------------- // component-composer-manager | user wins, but system lifecycles show through // -----------------------------------+----------------------------------------------------------------- // components | user // -----------------------------------+----------------------------------------------------------------- public static PlexusConfiguration merge( PlexusConfiguration user, PlexusConfiguration system ) { PlexusConfiguration mergedConfiguration = new XmlPlexusConfiguration( "plexus" ); // ---------------------------------------------------------------------- // Load on start // ---------------------------------------------------------------------- PlexusConfiguration loadOnStart = user.getChild( "load-on-start" ); if ( loadOnStart.getChildCount() != 0 ) { mergedConfiguration.addChild( loadOnStart ); } // ---------------------------------------------------------------------- // System properties // ---------------------------------------------------------------------- PlexusConfiguration systemProperties = user.getChild( "system-properties" ); if ( systemProperties.getChildCount() != 0 ) { mergedConfiguration.addChild( systemProperties ); } // ---------------------------------------------------------------------- // Configurations directory // ---------------------------------------------------------------------- PlexusConfiguration[] configurationsDirectories = user.getChildren( "configurations-directory" ); if ( configurationsDirectories.length != 0 ) { for ( int i = 0; i < configurationsDirectories.length; i++ ) { mergedConfiguration.addChild( configurationsDirectories[i] ); } } // ---------------------------------------------------------------------- // Logging // ---------------------------------------------------------------------- PlexusConfiguration logging = user.getChild( "logging" ); if ( logging.getChildCount() != 0 ) { mergedConfiguration.addChild( logging ); } else { mergedConfiguration.addChild( system.getChild( "logging" ) ); } // ---------------------------------------------------------------------- // Container initialization phases // ---------------------------------------------------------------------- mergedConfiguration.addChild( system.getChild( "container-initialization") ); mergedConfiguration.addChild( system.getChild( "component-lookup-manager") ); // ---------------------------------------------------------------------- // Component repository // ---------------------------------------------------------------------- PlexusConfiguration componentRepository = user.getChild( "component-repository" ); if ( componentRepository.getChildCount() != 0 ) { mergedConfiguration.addChild( componentRepository ); } else { mergedConfiguration.addChild( system.getChild( "component-repository" ) ); } // ---------------------------------------------------------------------- // Resources // ---------------------------------------------------------------------- copyResources( system, mergedConfiguration ); copyResources( user, mergedConfiguration ); // ---------------------------------------------------------------------- // Component manager manager // ---------------------------------------------------------------------- PlexusConfiguration componentManagerManager = user.getChild( "component-manager-manager" ); if ( componentManagerManager.getChildCount() != 0 ) { mergedConfiguration.addChild( componentManagerManager ); copyComponentManagers( system.getChild( "component-manager-manager" ), componentManagerManager ); } else { mergedConfiguration.addChild( system.getChild( "component-manager-manager" ) ); } // ---------------------------------------------------------------------- // Component discoverer manager // ---------------------------------------------------------------------- PlexusConfiguration componentDiscovererManager = user.getChild( "component-discoverer-manager" ); if ( componentDiscovererManager.getChildCount() != 0 ) { mergedConfiguration.addChild( componentDiscovererManager ); copyComponentDiscoverers( system.getChild( "component-discoverer-manager" ), componentDiscovererManager ); } else { mergedConfiguration.addChild( system.getChild( "component-discoverer-manager" ) ); } // ---------------------------------------------------------------------- // Component factory manager // ---------------------------------------------------------------------- PlexusConfiguration componentFactoryManager = user.getChild( "component-factory-manager" ); if ( componentFactoryManager.getChildCount() != 0 ) { mergedConfiguration.addChild( componentFactoryManager ); copyComponentFactories( system.getChild( "component-factory-manager" ), componentFactoryManager ); } else { mergedConfiguration.addChild( system.getChild( "component-factory-manager" ) ); } // ---------------------------------------------------------------------- // Lifecycle handler managers // ---------------------------------------------------------------------- PlexusConfiguration lifecycleHandlerManager = user.getChild( "lifecycle-handler-manager" ); if ( lifecycleHandlerManager.getChildCount() != 0 ) { mergedConfiguration.addChild( lifecycleHandlerManager ); copyLifecycles( system.getChild( "lifecycle-handler-manager" ), lifecycleHandlerManager ); } else { mergedConfiguration.addChild( system.getChild( "lifecycle-handler-manager" ) ); } // ---------------------------------------------------------------------- // Component factory manager // ---------------------------------------------------------------------- PlexusConfiguration componentComposerManager = user.getChild( "component-composer-manager" ); if ( componentComposerManager.getChildCount() != 0 ) { mergedConfiguration.addChild( componentComposerManager ); copyComponentComposers( system.getChild( "component-composer-manager" ), componentComposerManager ); } else { mergedConfiguration.addChild( system.getChild( "component-composer-manager" ) ); } // ---------------------------------------------------------------------- // Components // ---------------------------------------------------------------------- // We grab the system components first and then add the user defined // components so that user defined components will win. When component // descriptors are processed the last definition wins because the component // descriptors are stored in a Map in the component repository. // ---------------------------------------------------------------------- PlexusConfiguration components = system.getChild( "components" ); mergedConfiguration.addChild( components ); copyComponents( user.getChild( "components" ), components ); return mergedConfiguration; } private static void copyResources( PlexusConfiguration source, PlexusConfiguration destination ) { PlexusConfiguration handlers[] = source.getChild( "resources" ).getChildren(); PlexusConfiguration dest = destination.getChild( "resources" ); for ( int i = 0; i < handlers.length; i++ ) { dest.addChild( handlers[i] ); } } private static void copyComponentManagers( PlexusConfiguration source, PlexusConfiguration destination ) { try { PlexusConfiguration id = destination.getChild( "default-component-manager-id" ); String sid = source.getChild( "default-component-manager-id" ).getValue(); if ( id.getValue() == null ) { id.setValue( sid ); } } catch ( PlexusConfigurationException e ) { // do nothing } PlexusConfiguration handlers[] = source.getChild( "component-managers" ).getChildren( "component-manager" ); PlexusConfiguration dest = destination.getChild( "component-managers" ); for ( int i = 0; i < handlers.length; i++ ) { dest.addChild( handlers[i] ); } } private static void copyComponentDiscoverers( PlexusConfiguration source, PlexusConfiguration destination ) { PlexusConfiguration handlers[] = source.getChild( "component-discoverers" ).getChildren( "component-discoverer" ); PlexusConfiguration dest = destination.getChild( "component-discoverers" ); for ( int i = 0; i < handlers.length; i++ ) { dest.addChild( handlers[i] ); } } private static void copyComponentFactories( PlexusConfiguration source, PlexusConfiguration destination ) { PlexusConfiguration handlers[] = source.getChild( "component-factories" ).getChildren( "component-factory" ); PlexusConfiguration dest = destination.getChild( "component-factories" ); for ( int i = 0; i < handlers.length; i++ ) { dest.addChild( handlers[i] ); } } private static void copyComponentComposers( PlexusConfiguration source, PlexusConfiguration destination ) { try { PlexusConfiguration id = destination.getChild( "default-component-composer-id" ); String sid = source.getChild( "default-component-composer-id" ).getValue(); if ( id.getValue() == null ) { id.setValue( sid ); } } catch ( PlexusConfigurationException e ) { // do nothing } PlexusConfiguration composers[] = source.getChild( "component-composers" ).getChildren( "component-composer" ); PlexusConfiguration dest = destination.getChild( "component-composers" ); for ( int i = 0; i < composers.length; i++ ) { dest.addChild( composers[i] ); } } private static void copyLifecycles( PlexusConfiguration source, PlexusConfiguration destination ) { PlexusConfiguration handlers[] = source.getChild( "lifecycle-handlers" ).getChildren( "lifecycle-handler" ); PlexusConfiguration dest = destination.getChild( "lifecycle-handlers" ); for ( int i = 0; i < handlers.length; i++ ) { dest.addChild( handlers[i] ); } } private static void copyComponents( PlexusConfiguration source, PlexusConfiguration destination ) { PlexusConfiguration components[] = source.getChildren( "component" ); for ( int i = 0; i < components.length; i++ ) { destination.addChild( components[i] ); } } } PlexusConfigurationResourceException.java000066400000000000000000000015031166327066700437600ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configurationpackage org.codehaus.plexus.configuration; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class PlexusConfigurationResourceException extends Exception { public PlexusConfigurationResourceException( String message ) { super( message ); } } 000077500000000000000000000000001166327066700341265ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/ioPlexusConfigurationReader.java000066400000000000000000000010651166327066700421260ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/iopackage org.codehaus.plexus.configuration.io; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; public interface PlexusConfigurationReader { public PlexusConfiguration read( Reader reader ) throws IOException, PlexusConfigurationException; public PlexusConfiguration read( InputStream inputStream ) throws IOException, PlexusConfigurationException; } PlexusConfigurationWriter.java000066400000000000000000000006711166327066700422020ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/iopackage org.codehaus.plexus.configuration.io; import java.io.IOException; import java.io.OutputStream; import java.io.Writer; import org.codehaus.plexus.configuration.PlexusConfiguration; public interface PlexusConfigurationWriter { void write( Writer writer, PlexusConfiguration configuration ) throws IOException; void write( OutputStream outputStream, PlexusConfiguration configuration ) throws IOException; } XmlPlexusConfigurationReader.java000066400000000000000000000024561166327066700426140ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/iopackage org.codehaus.plexus.configuration.io; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; public class XmlPlexusConfigurationReader implements PlexusConfigurationReader { public PlexusConfiguration read( InputStream inputStream ) throws IOException, PlexusConfigurationException { return read( new InputStreamReader( inputStream ) ); } public PlexusConfiguration read( Reader reader ) throws IOException, PlexusConfigurationException { try { Xpp3Dom dom = Xpp3DomBuilder.build( reader ); return new XmlPlexusConfiguration( dom ); } catch ( XmlPullParserException e ) { throw new PlexusConfigurationException( "Failed to parse configuration resource!\nError was: \'" + e.getLocalizedMessage() + "\'", e ); } } } XmlPlexusConfigurationWriter.java000066400000000000000000000055571166327066700426730ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/iopackage org.codehaus.plexus.configuration.io; import org.codehaus.plexus.configuration.PlexusConfiguration; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; public class XmlPlexusConfigurationWriter implements PlexusConfigurationWriter { public void write( OutputStream outputStream, PlexusConfiguration configuration ) throws IOException { write( new OutputStreamWriter( outputStream ), configuration ); } public void write( Writer writer, PlexusConfiguration configuration ) throws IOException { int depth = 0; display( configuration, writer, depth ); } private void display( PlexusConfiguration c, Writer w, int depth ) throws IOException { int count = c.getChildCount(); if ( count == 0 ) { displayTag( c, w, depth ); } else { indent( depth, w ); w.write( '<' ); w.write( c.getName() ); attributes( c, w ); w.write( '>' ); w.write( '\n' ); for ( int i = 0; i < count; i++ ) { PlexusConfiguration child = c.getChild( i ); display( child, w, depth + 1 ); } indent( depth, w ); w.write( '<' ); w.write( '/' ); w.write( c.getName() ); w.write( '>' ); w.write( '\n' ); } } private void displayTag( PlexusConfiguration c, Writer w, int depth ) throws IOException { String value = c.getValue( null ); if ( value != null ) { indent( depth, w ); w.write( '<' ); w.write( c.getName() ); attributes( c, w ); w.write( '>' ); w.write( c.getValue( null ) ); w.write( '<' ); w.write( '/' ); w.write( c.getName() ); w.write( '>' ); w.write( '\n' ); } else { indent( depth, w ); w.write( '<' ); w.write( c.getName() ); attributes( c, w ); w.write( '/' ); w.write( '>' ); w.write( "\n" ); } } private void attributes( PlexusConfiguration c, Writer w ) throws IOException { String[] names = c.getAttributeNames(); for ( int i = 0; i < names.length; i++ ) { w.write( ' ' ); w.write( names[i] ); w.write( '=' ); w.write( '"' ); w.write( c.getAttribute( names[i], null ) ); w.write( '"' ); } } private void indent( int depth, Writer w ) throws IOException { for ( int i = 0; i < depth; i++ ) { w.write( ' ' ); } } } 000077500000000000000000000000001166327066700350175ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/sourceChainedConfigurationSource.java000066400000000000000000000030131166327066700431230ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/sourcepackage org.codehaus.plexus.configuration.source; import java.util.Iterator; import java.util.List; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * A configuration source that delegates to any number of underlying configuration sources. If you are an application * author and want to create a custom source of configuration for the components in your application then you would most * likely want to create a chained configuration source where you can decide the order of processing, but still have the * container perform its default behavior. * * @author Jason van Zyl */ public class ChainedConfigurationSource implements ConfigurationSource { private List configurationSources; public ChainedConfigurationSource( List configurationSources ) { this.configurationSources = configurationSources; } public PlexusConfiguration getConfiguration( ComponentDescriptor componentDescriptor ) { for ( Iterator i = configurationSources.iterator(); i.hasNext(); ) { ConfigurationSource configurationSource = (ConfigurationSource) i.next(); PlexusConfiguration configuration = configurationSource.getConfiguration( componentDescriptor ); if ( configuration != null ) { return configuration; } } return null; } public List getConfigurationSources() { return configurationSources; } } ConfigurationSource.java000066400000000000000000000015311166327066700416520ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/sourcepackage org.codehaus.plexus.configuration.source; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * A source for component configurations which may reside outside the configuration within a component descriptor. A * common usecase for this is to create a unified configuration for a set of components. For an application it is more * convenient to present the user with a single configuration, instead of making users work directly with a Plexus * configuration file which exposes component details including implementation, and wiring information. * * @author Jason van Zyl */ public interface ConfigurationSource { String ROLE = ConfigurationSource.class.getName(); PlexusConfiguration getConfiguration( ComponentDescriptor componentDescriptor ); } ContainerConfigurationSource.java000066400000000000000000000010561166327066700435170ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/sourcepackage org.codehaus.plexus.configuration.source; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; /** @author Jason van Zyl */ public class ContainerConfigurationSource implements ConfigurationSource { public PlexusConfiguration getConfiguration( ComponentDescriptor componentDescriptor ) { if ( componentDescriptor.hasConfiguration() ) { return componentDescriptor.getConfiguration(); } return null; } } 000077500000000000000000000000001166327066700343175ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/xmlXmlPlexusConfiguration.java000066400000000000000000000045501166327066700416570ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/configuration/xmlpackage org.codehaus.plexus.configuration.xml; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.io.StringWriter; import org.codehaus.plexus.configuration.DefaultPlexusConfiguration; import org.codehaus.plexus.configuration.io.XmlPlexusConfigurationWriter; import org.codehaus.plexus.util.xml.Xpp3Dom; /** * @version $Id: XmlPlexusConfiguration.java 8345 2009-08-20 16:36:28Z bentmann $ */ public class XmlPlexusConfiguration extends DefaultPlexusConfiguration { public XmlPlexusConfiguration() { super(); } public XmlPlexusConfiguration( String name ) { super( name ); } public XmlPlexusConfiguration( String name, String value ) { super( name, value ); } public XmlPlexusConfiguration( Xpp3Dom dom ) { super( dom.getName(), dom.getValue() ); // attrs String[] attributes = dom.getAttributeNames(); for ( int i = 0; i < attributes.length; i++ ) { setAttribute( attributes[i], dom.getAttribute( attributes[i] ) ); } // children int childCount = dom.getChildCount(); for ( int i = 0; i < childCount; i++ ) { addChild( new XmlPlexusConfiguration( dom.getChild( i ) ) ); } } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- public String toString() { StringWriter sw = new StringWriter(); XmlPlexusConfigurationWriter xw = new XmlPlexusConfigurationWriter(); try { xw.write( sw, this ); } catch ( IOException e ) { // will not happen with StringWriter } return sw.toString(); } } plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/000077500000000000000000000000001166327066700327115ustar00rootroot00000000000000000077500000000000000000000000001166327066700356615ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationAbstractContainerInitializationPhase.java000066400000000000000000000014461166327066700460300ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl */ public abstract class AbstractContainerInitializationPhase implements ContainerInitializationPhase { } AbstractCoreComponentInitializationPhase.java000066400000000000000000000021451166327066700466560ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** @author Jason van Zyl */ public abstract class AbstractCoreComponentInitializationPhase extends AbstractContainerInitializationPhase { public void execute( ContainerInitializationContext context ) throws ContainerInitializationException { initializeCoreComponent( context ); } protected abstract void initializeCoreComponent( ContainerInitializationContext context ) throws ContainerInitializationException; } ContainerInitializationContext.java000066400000000000000000000044561166327066700447340ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * @author Jason van Zyl */ public class ContainerInitializationContext { private DefaultPlexusContainer container; ClassWorld classWorld; ClassRealm containerRealm; PlexusConfiguration containerXmlConfiguration; ContainerConfiguration containerConfiguration; public ContainerInitializationContext( DefaultPlexusContainer container, ClassWorld classWorld, ClassRealm containerRealm, PlexusConfiguration configuration, ContainerConfiguration containerConfiguration ) { this.container = container; this.classWorld = classWorld; this.containerRealm = containerRealm; this.containerXmlConfiguration = configuration; this.containerConfiguration = containerConfiguration; } public DefaultPlexusContainer getContainer() { return container; } public ClassWorld getClassWorld() { return classWorld; } public ClassRealm getContainerRealm() { return containerRealm; } public PlexusConfiguration getContainerXmlConfiguration() { return containerXmlConfiguration; } public ContainerConfiguration getContainerConfiguration() { return containerConfiguration; } } ContainerInitializationException.java000066400000000000000000000021611166327066700452350ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl */ public class ContainerInitializationException extends Exception { public ContainerInitializationException( String id ) { super( id ); } public ContainerInitializationException( String id, Throwable throwable ) { super( id, throwable ); } public ContainerInitializationException( Throwable throwable ) { super( throwable ); } } ContainerInitializationPhase.java000066400000000000000000000016321166327066700443410ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl */ public interface ContainerInitializationPhase { String ROLE = ContainerInitializationPhase.class.getName(); void execute( ContainerInitializationContext context ) throws ContainerInitializationException; } InitializeComponentDiscovererManagerPhase.java000066400000000000000000000042361166327066700470170ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.discovery.ComponentDiscovererManager; import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; /** * @author Jason van Zyl */ public class InitializeComponentDiscovererManagerPhase extends AbstractCoreComponentInitializationPhase { public void initializeCoreComponent( ContainerInitializationContext context ) throws ContainerInitializationException { ComponentDiscovererManager componentDiscovererManager = context.getContainerConfiguration().getComponentDiscovererManager(); context.getContainer().setComponentDiscovererManager( componentDiscovererManager ); for ( ComponentDiscoveryListener listener : componentDiscovererManager.getComponentDiscoveryListeners().keySet() ) { try { // This is a hack until we have completely live components context.getContainer().addComponent( listener, listener.getClass().getName() ); context.getContainer().getComponentDiscovererManager().removeComponentDiscoveryListener( listener ); ComponentDiscoveryListener cdl = context.getContainer().lookup( listener.getClass() ); context.getContainer().getComponentDiscovererManager().registerComponentDiscoveryListener( cdl ); } catch ( Exception e ) { throw new ContainerInitializationException( "Error initializing component discovery listener.", e ); } } } } InitializeComponentFactoryManagerPhase.java000066400000000000000000000037151166327066700463220ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.component.factory.ComponentFactoryManager; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; /** * @author Jason van Zyl */ public class InitializeComponentFactoryManagerPhase extends AbstractCoreComponentInitializationPhase { public void initializeCoreComponent( ContainerInitializationContext context ) throws ContainerInitializationException { ComponentFactoryManager componentFactoryManager = context.getContainerConfiguration().getComponentFactoryManager(); if ( componentFactoryManager instanceof Contextualizable ) { //TODO: this is wrong here jvz. context.getContainer().getContext().put( PlexusConstants.PLEXUS_KEY, context.getContainer() ); try { ( (Contextualizable) componentFactoryManager).contextualize( context.getContainer().getContext() ); } catch ( ContextException e ) { throw new ContainerInitializationException( "Error contextualization component factory manager.", e ); } } context.getContainer().setComponentFactoryManager( componentFactoryManager ); } } InitializeComponentRegistryPhase.java000066400000000000000000000101361166327066700452230ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.repository.ComponentRepository; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.io.PlexusTools; import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException; import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; import org.codehaus.plexus.component.manager.PerLookupComponentManagerFactory; import org.codehaus.plexus.component.manager.SingletonComponentManagerFactory; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.DefaultComponentRegistry; import org.codehaus.plexus.ComponentRegistry; import org.codehaus.plexus.lifecycle.LifecycleHandlerManager; /** * @author Jason van Zyl */ public class InitializeComponentRegistryPhase implements ContainerInitializationPhase { public void execute( ContainerInitializationContext context ) throws ContainerInitializationException { ComponentRepository repository = getComponentRepository( context ); LifecycleHandlerManager lifecycleHandlerManager = getLifecycleHandlerManager( context ); ComponentRegistry componentRegistry = new DefaultComponentRegistry( context.getContainer(), repository, lifecycleHandlerManager ); componentRegistry.registerComponentManagerFactory( new PerLookupComponentManagerFactory() ); componentRegistry.registerComponentManagerFactory( new SingletonComponentManagerFactory() ); context.getContainer().setComponentRegistry( componentRegistry ); } private ComponentRepository getComponentRepository( ContainerInitializationContext context ) throws ContainerInitializationException { ComponentRepository repository = context.getContainerConfiguration().getComponentRepository(); // Add the components defined in the container xml configuration try { PlexusConfiguration configuration = context.getContainerXmlConfiguration(); PlexusConfiguration[] componentConfigurations = configuration.getChild( "components" ).getChildren( "component" ); for ( PlexusConfiguration componentConfiguration : componentConfigurations ) { ComponentDescriptor componentDescriptor = PlexusTools.buildComponentDescriptor( componentConfiguration, context.getContainer().getContainerRealm() ); componentDescriptor.setRealm( context.getContainer().getContainerRealm() ); repository.addComponentDescriptor( componentDescriptor ); } } catch ( PlexusConfigurationException e ) { throw new ContainerInitializationException( "Error initializing component repository: " + "Cannot unmarshall component descriptor: ", e ); } catch ( CycleDetectedInComponentGraphException e ) { throw new ContainerInitializationException( "A cycle has been detected in the components of the system: ", e ); } return repository; } private LifecycleHandlerManager getLifecycleHandlerManager( ContainerInitializationContext context ) { LifecycleHandlerManager lifecycleHandlerManager = context.getContainerConfiguration().getLifecycleHandlerManager(); lifecycleHandlerManager.initialize(); return lifecycleHandlerManager; } }InitializeContainerConfigurationSourcePhase.java000066400000000000000000000033711166327066700473660ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.configuration.source.ConfigurationSource; import org.codehaus.plexus.configuration.source.ContainerConfigurationSource; /** * @author Jason van Zyl * @author cstamas */ public class InitializeContainerConfigurationSourcePhase extends AbstractCoreComponentInitializationPhase { public void initializeCoreComponent( ContainerInitializationContext context ) throws ContainerInitializationException { ConfigurationSource configurationSource = context.getContainer().getConfigurationSource(); // ---------------------------------------------------------------------- // The configurationSource may have been set programmatically so we need // to check. If it hasn't then we will add the default container config source. // ---------------------------------------------------------------------- if ( configurationSource == null ) { // adding default source for container to enable lookups context.getContainer().setConfigurationSource( new ContainerConfigurationSource() ); } } } InitializeLoggerManagerPhase.java000066400000000000000000000062471166327066700442520ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; import org.codehaus.plexus.logging.console.ConsoleLoggerManager; /** @author Jason van Zyl */ public class InitializeLoggerManagerPhase extends AbstractCoreComponentInitializationPhase { public void initializeCoreComponent( ContainerInitializationContext context ) throws ContainerInitializationException { LoggerManager loggerManager = context.getContainer().getLoggerManager(); // ---------------------------------------------------------------------- // The logger manager may have been set programmatically so we need // to check. If it hasn't then we will try to look up a logger manager // that may have been specified in the plexus.xml file. If that doesn't // work then we'll programmatcially stuff in the console logger. // ---------------------------------------------------------------------- if ( loggerManager == null ) { try { loggerManager = context.getContainer().lookup( LoggerManager.class ); } catch ( ComponentLookupException e ) { ComponentDescriptor cd = new ComponentDescriptor(); cd.setRole( LoggerManager.ROLE ); cd.setRoleHint( PlexusConstants.PLEXUS_DEFAULT_HINT ); cd.setImplementation( ConsoleLoggerManager.class.getName() ); try { context.getContainer().addComponentDescriptor( cd ); } catch ( CycleDetectedInComponentGraphException cre ) { throw new ContainerInitializationException( "Error setting up logging manager.", cre ); } loggerManager = new ConsoleLoggerManager( "info" ); } context.getContainer().setLoggerManager( loggerManager ); } Logger logger = loggerManager.getLoggerForComponent( PlexusContainer.class.getName() ); context.getContainer().enableLogging( logger ); } } InitializeSystemPropertiesPhase.java000066400000000000000000000033751166327066700451000ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.configuration.PlexusConfiguration; /** * @author Jason van Zyl */ public class InitializeSystemPropertiesPhase extends AbstractContainerInitializationPhase { public void execute( ContainerInitializationContext context ) throws ContainerInitializationException { PlexusConfiguration[] systemProperties = context.getContainerXmlConfiguration().getChild( "system-properties" ).getChildren( "property" ); for ( int i = 0; i < systemProperties.length; ++i ) { String name = systemProperties[i].getAttribute( "name", null ); String value = systemProperties[i].getAttribute( "value", null ); if ( name == null ) { throw new ContainerInitializationException( "Missing 'name' attribute in 'property' tag. " ); } if ( value == null ) { throw new ContainerInitializationException( "Missing 'value' attribute in 'property' tag. " ); } System.getProperties().setProperty( name, value ); } } } InitializeUserConfigurationSourcePhase.java000066400000000000000000000102511166327066700463550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/container/initializationpackage org.codehaus.plexus.container.initialization; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.List; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException; import org.codehaus.plexus.configuration.source.ChainedConfigurationSource; import org.codehaus.plexus.configuration.source.ConfigurationSource; /** * @author Jason van Zyl * @author cstamas */ public class InitializeUserConfigurationSourcePhase extends AbstractCoreComponentInitializationPhase { public void initializeCoreComponent( ContainerInitializationContext context ) throws ContainerInitializationException { ConfigurationSource existingConfigurationSource = context.getContainer().getConfigurationSource(); try { // is the user overriding the ConfigurationSource (role-hint: default) or only extending it? if ( context.getContainer().hasComponent( ConfigurationSource.class, PlexusConstants.PLEXUS_DEFAULT_HINT ) ) { // overriding ConfigurationSource cs = context.getContainer().lookup( ConfigurationSource.class ); // swap the user provided configuration source with current one context.getContainer().setConfigurationSource( cs ); } else { // extending List userConfigurationSources = context.getContainer().lookupList( ConfigurationSource.class ); if ( userConfigurationSources.size() > 0 ) { List configurationSources = new ArrayList( userConfigurationSources.size() + 1 ); // adding user provied ones to be able to interfere configurationSources.addAll( userConfigurationSources ); // at the end adding the container source, to make sure config will be returned // from plexus.xml if no user interference is given configurationSources.add( existingConfigurationSource ); ConfigurationSource configurationSource = new ChainedConfigurationSource( configurationSources ); context.getContainer().setConfigurationSource( configurationSource ); } // register the default source, either the chained or the existing one as default ComponentDescriptor cd = new ComponentDescriptor(); cd.setRole( ConfigurationSource.ROLE ); cd.setRoleHint( PlexusConstants.PLEXUS_DEFAULT_HINT ); cd.setImplementationClass( context.getContainer().getConfigurationSource().getClass() ); try { context.getContainer().addComponentDescriptor( cd ); } catch ( CycleDetectedInComponentGraphException cre ) { throw new ContainerInitializationException( "Error setting up configuration source.", cre ); } } } catch ( ComponentLookupException e ) { throw new ContainerInitializationException( "Error setting up user configuration source.", e ); } } } plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/context/000077500000000000000000000000001166327066700324135ustar00rootroot00000000000000Context.java000066400000000000000000000047371166327066700346360ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/contextpackage org.codehaus.plexus.context; import java.util.Map; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Context is a Map of arbitrary data associated with the container. */ public interface Context { /** * Returns true if this context contains a value for the specified key. * * @param key the key to search * @return true if the key was found; false otherwise */ boolean contains( Object key ); /** * Returns the value of the key. If the key can't be found it will throw a exception. * * @param key the key of the value to look up. * @return returns the value associated with the key * @throws ContextException if the key doesn't exist */ Object get( Object key ) throws ContextException; /** * Utility method to retrieve containerContext data. * The returned Map is an unmodifiable view. * @return the containerContext data * @since 1.0-alpha-18 */ Map getContextData(); /** * Adds the item to the containerContext. * * @param key the key of the item * @param value the item * @throws IllegalStateException if this context is read-only */ public void put( Object key, Object value ) throws IllegalStateException; // todo [dain] this isn't needed anymore since containers are no longer nestable /** * Hides the item in the containerContext. * After remove(key) has been called, a get(key) * will always fail, even if the parent containerContext * has such a mapping. * * @param key the items key * @throws IllegalStateException if this context is read-only */ void hide( Object key ) throws IllegalStateException; /** * Make the containerContext read-only. * Any attempt to write to the containerContext via put() * will result in an IllegalStateException. */ void makeReadOnly(); } ContextException.java000066400000000000000000000033431166327066700365050ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/contextpackage org.codehaus.plexus.context; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Exception signalling a badly formed Context. * * This can be thrown by Context object when a entry is not * found. It can also be thrown manually in contextualize() * when Component detects a malformed containerContext value. * * @author Avalon Development Team * @version CVS $Revision: 6965 $ $Date: 2007-10-21 07:32:27 +0200 (dim. 21 oct. 2007) $ */ public class ContextException extends Exception { private static final long serialVersionUID = 2030206863811644180L; /** * Construct a new ContextException instance. * * @param message The detail message for this exception. */ public ContextException( final String message ) { this( message, null ); } /** * Construct a new ContextException instance. * * @param message The detail message for this exception. * @param throwable the root cause of the exception */ public ContextException( final String message, final Throwable throwable ) { super( message, throwable ); } } ContextMapAdapter.java000066400000000000000000000023441166327066700365650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/contextpackage org.codehaus.plexus.context; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.HashMap; public class ContextMapAdapter extends HashMap { private Context context; public ContextMapAdapter( Context context ) { this.context = context; } public Object get( Object key ) { try { Object value = context.get( key ); if ( value instanceof String ) { return value; } else { return null; } } catch ( ContextException e ) { return null; } } } DefaultContext.java000066400000000000000000000112711166327066700361320ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/contextpackage org.codehaus.plexus.context; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Collections; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicBoolean; /** * Default implementation of Context. * * This implementation is a static hierarchial store. It has the normal get() * and put methods. The hide method will hide a property. When * a property has been hidden the containerContext will not search in the parent containerContext for the value. * * @author Avalon Development Team * @version $Id: DefaultContext.java 8061 2009-01-19 23:33:12Z dain $ */ public class DefaultContext implements Context { /** * Context data. */ private final ConcurrentMap contextData = new ConcurrentHashMap(); /** * Is the containerContext read only. */ private final AtomicBoolean readOnly = new AtomicBoolean(false); /** * Create an empty Context. */ public DefaultContext() { } /** * Create a Context with specified data. The specified data is copied into the context so any subsequent updates * to supplied map are not reflected in this context. Additionally, changes to this context are not reflected in * the specified map. * * @param contextData the containerContext data */ public DefaultContext( Map contextData ) { if ( contextData == null ) { throw new NullPointerException( "contextData is null" ); } // check for nulls in key and value for ( Entry entry : contextData.entrySet() ) { Object key = entry.getKey(); Object value = entry.getValue(); if ( key == null ) { throw new IllegalArgumentException( "Key is null" ); } if ( value != null ) { this.contextData.put( key, value ); } } } public boolean contains( Object key ) { Object data = contextData.get( key ); return data != null; } public Object get( Object key ) throws ContextException { Object data = contextData.get( key ); if ( data == null ) { // There is no data for the key throw new ContextException( "Unable to resolve context key: " + key ); } return data; } public void put( Object key, Object value ) throws IllegalStateException { checkWriteable(); // check for a null key if (key == null) { throw new IllegalArgumentException("Key is null"); } if ( value == null ) { contextData.remove( key ); } else { contextData.put( key, value ); } } public void hide( Object key ) throws IllegalStateException { checkWriteable(); contextData.remove( key ); } /** * Utility method to retrieve containerContext data * * @return the containerContext data */ public Map getContextData() { return Collections.unmodifiableMap( contextData ); } /** * Make the containerContext read-only. * Any attempt to write to the containerContext via put() * will result in an IllegalStateException. */ public void makeReadOnly() { readOnly.set( true ); } /** * Utility method to check if containerContext is writeable and if not throw exception. * * @throws java.lang.IllegalStateException if containerContext is read only */ protected void checkWriteable() throws IllegalStateException { if ( readOnly.get() ) { throw new IllegalStateException( "Context is read only and can not be modified" ); } } public String toString() { return contextData.toString(); } } plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/000077500000000000000000000000001166327066700326665ustar00rootroot00000000000000AbstractLifecycleHandler.java000066400000000000000000000071561166327066700403440ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/lifecyclepackage org.codehaus.plexus.lifecycle; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.Phase; import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public abstract class AbstractLifecycleHandler implements LifecycleHandler { private List beginSegment; private List endSegment; // ---------------------------------------------------------------------- // Begin Segment // ---------------------------------------------------------------------- public void addBeginSegment( Phase phase ) { if ( beginSegment == null ) { beginSegment = new ArrayList(); } beginSegment.add( phase ); } public List getBeginSegment() { return beginSegment; } public void addEndSegment( Phase phase ) { if ( endSegment == null ) { endSegment = new ArrayList(); } endSegment.add( phase ); } public List getEndSegment() { return endSegment; } // ---------------------------------------------------------------------- // Lifecylce Management // ---------------------------------------------------------------------- /** * @deprecated */ public void start( Object component, ComponentManager manager ) throws PhaseExecutionException { start( component, manager, manager.getContainer().getLookupRealm( component ) ); } /** * Start a component's lifecycle. */ public void start( Object component, ComponentManager manager, ClassRealm realm ) throws PhaseExecutionException { if ( segmentIsEmpty( getBeginSegment() ) ) { return; } for ( Iterator i = getBeginSegment().iterator(); i.hasNext(); ) { Phase phase = (Phase) i.next(); phase.execute( component, manager, realm ); } } /** * End a component's lifecycle. * @deprecated */ public void end( Object component, ComponentManager manager ) throws PhaseExecutionException { end( component, manager, manager.getContainer().getLookupRealm( component ) ); } /** * End a component's lifecycle. */ public void end( Object component, ComponentManager manager, ClassRealm contextRealm ) throws PhaseExecutionException { if ( segmentIsEmpty( getEndSegment() ) ) { return; } for ( Iterator i = getEndSegment().iterator(); i.hasNext(); ) { Phase phase = (Phase) i.next(); phase.execute( component, manager, contextRealm ); } } private boolean segmentIsEmpty( List segment ) { if ( segment == null || segment.size() == 0 ) { return true; } return false; } } BasicLifecycleHandler.java000066400000000000000000000020051166327066700376060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/lifecyclepackage org.codehaus.plexus.lifecycle; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class BasicLifecycleHandler extends AbstractLifecycleHandler { protected String id; public BasicLifecycleHandler( String id ) { this.id = id; } public String getId() { return id; } /** @see org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable#initialize */ public void initialize() { } } DefaultLifecycleHandlerManager.java000066400000000000000000000036761166327066700414630ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/lifecyclepackage org.codehaus.plexus.lifecycle; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; /** * @author Jason van Zyl * @version $Id: DefaultLifecycleHandlerManager.java 7797 2008-10-28 17:41:43Z dain $ */ public class DefaultLifecycleHandlerManager implements LifecycleHandlerManager { private final ConcurrentMap lifecycleHandlers = new ConcurrentHashMap(); private String defaultLifecycleHandlerId = "plexus"; public void addLifecycleHandler( LifecycleHandler lifecycleHandler ) { lifecycleHandlers.put( lifecycleHandler.getId(), lifecycleHandler ); } public void initialize() { for ( LifecycleHandler lifecycleHandler : lifecycleHandlers.values() ) { lifecycleHandler.initialize(); } } public LifecycleHandler getLifecycleHandler( String id ) throws UndefinedLifecycleHandlerException { if ( id == null ) { id = defaultLifecycleHandlerId; } LifecycleHandler lifecycleHandler = lifecycleHandlers.get( id ); if ( lifecycleHandler == null ) { throw new UndefinedLifecycleHandlerException( "Specified lifecycle handler cannot be found: " + id ); } return lifecycleHandler; } } LifecycleHandler.java000066400000000000000000000037761166327066700366640ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/lifecyclepackage org.codehaus.plexus.lifecycle; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.Phase; import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException; public interface LifecycleHandler { String getId(); void addBeginSegment( Phase phase ); void addEndSegment( Phase phase ); /** * @deprecated */ void start( Object component, ComponentManager manager ) throws PhaseExecutionException; void start( Object component, ComponentManager manager, ClassRealm realm ) throws PhaseExecutionException; /** * @deprecated */ void end( Object component, ComponentManager manager ) throws PhaseExecutionException; /** * * @param component * @param manager * @param componentContextRealm the realm used to create the component, which may not be the component's realm; this * component could have requirements that were satisfied using components from this realm. It could be * used to lookup the same manager components that were used to start the component. * @throws PhaseExecutionException */ void end( Object component, ComponentManager manager, ClassRealm componentContextRealm ) throws PhaseExecutionException; void initialize(); } LifecycleHandlerManager.java000066400000000000000000000021151166327066700401410ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/lifecyclepackage org.codehaus.plexus.lifecycle; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * LifecycleHandlerManager is a simple index (registry) of LifecycleHandler instances. * * @author Jason van Zyl * * @version $Id: LifecycleHandlerManager.java 7797 2008-10-28 17:41:43Z dain $ */ public interface LifecycleHandlerManager { void initialize(); void addLifecycleHandler( LifecycleHandler lifecycleHandler ); LifecycleHandler getLifecycleHandler( String id ) throws UndefinedLifecycleHandlerException; } UndefinedLifecycleHandlerException.java000066400000000000000000000014731166327066700423550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/lifecyclepackage org.codehaus.plexus.lifecycle; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class UndefinedLifecycleHandlerException extends Exception { public UndefinedLifecycleHandlerException( String message ) { super( message ); } } 000077500000000000000000000000001166327066700337075ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/phaseAbstractPhase.java000066400000000000000000000025031166327066700372760ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/phasepackage org.codehaus.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException; public abstract class AbstractPhase implements Phase { /** Execute the phase. */ public abstract void execute( Object component, ComponentManager manager, ClassRealm realm ) throws PhaseExecutionException; /** * @deprecated */ public final void execute( Object component, ComponentManager manager ) throws PhaseExecutionException { execute( component, manager, manager.getContainer().getLookupRealm( component ) ); } } Phase.java000066400000000000000000000020321166327066700356070ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/phasepackage org.codehaus.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException; public interface Phase { /** Execute the phase. */ public void execute( Object component, ComponentManager manager, ClassRealm realm ) throws PhaseExecutionException; } plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/logging/000077500000000000000000000000001166327066700323555ustar00rootroot00000000000000AbstractLogEnabled.java000066400000000000000000000033121166327066700366200ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: AbstractLogEnabled.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public abstract class AbstractLogEnabled implements LogEnabled { private Logger logger; public void enableLogging( Logger logger ) { this.logger = logger; } protected Logger getLogger() { return logger; } protected void setupLogger( Object component ) { setupLogger( component, logger ); } protected void setupLogger( Object component, String subCategory ) { if ( subCategory == null ) { throw new IllegalStateException( "Logging category must be defined." ); } Logger logger = this.logger.getChildLogger( subCategory ); setupLogger( component, logger ); } protected void setupLogger( Object component, Logger logger ) { if ( component instanceof LogEnabled ) { ( (LogEnabled) component ).enableLogging( logger ); } } } AbstractLogger.java000066400000000000000000000056001166327066700360450ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * LICENSE */ /** * @author Trygve Laugstøl * @version $Id: AbstractLogger.java 6965 2007-10-21 05:32:27Z jvanzyl $ */ public abstract class AbstractLogger implements Logger { private int threshold; private String name; public AbstractLogger( int threshold, String name ) { if ( !isValidThreshold( threshold ) ) { throw new IllegalArgumentException( "Threshold " + threshold + " is not valid" ); } this.threshold = threshold; this.name = name; } public int getThreshold() { return threshold; } public void setThreshold( int threshold ) { this.threshold = threshold; } public String getName() { return name; } public void debug( String message ) { debug( message, null ); } public boolean isDebugEnabled() { return threshold <= LEVEL_DEBUG; } public void info( String message ) { info( message, null ); } public boolean isInfoEnabled() { return threshold <= LEVEL_INFO; } public void warn( String message ) { warn( message, null ); } public boolean isWarnEnabled() { return threshold <= LEVEL_WARN; } public void error( String message ) { error( message, null ); } public boolean isErrorEnabled() { return threshold <= LEVEL_ERROR; } public void fatalError( String message ) { fatalError( message, null ); } public boolean isFatalErrorEnabled() { return threshold <= LEVEL_FATAL; } protected boolean isValidThreshold( int threshold ) { if ( threshold == LEVEL_DEBUG ) { return true; } if ( threshold == LEVEL_INFO ) { return true; } if ( threshold == LEVEL_WARN ) { return true; } if ( threshold == LEVEL_ERROR ) { return true; } if ( threshold == LEVEL_FATAL ) { return true; } if ( threshold == LEVEL_DISABLED ) { return true; } return false; } } AbstractLoggerManager.java000066400000000000000000000035641166327066700373470ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: AbstractLoggerManager.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public abstract class AbstractLoggerManager implements LoggerManager { /** */ public AbstractLoggerManager() { } public void setThreshold( String role, int threshold ) { setThreshold( role, null, threshold ); } public int getThreshold( String role ) { return getThreshold( role, null ); } public Logger getLoggerForComponent( String role ) { return getLoggerForComponent( role, null ); } public void returnComponentLogger( String role ) { returnComponentLogger( role, null ); } /** * Creates a string key useful as keys in Map's. * * @param role The component role. * @param roleHint The component role hint. * @return Returns a string thats useful as a key for components. */ protected String toMapKey( String role, String roleHint ) { if ( roleHint == null ) { return role; } else { return role + ":" + roleHint; } } } BaseLoggerManager.java000066400000000000000000000116721166327066700364550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Map; /** * Base class for all LoggerManagers which use cache of Loggers. * * @author Michal Maczka * @version $Id: BaseLoggerManager.java 7789 2008-10-13 22:54:22Z bentmann $ */ public abstract class BaseLoggerManager extends AbstractLoggerManager implements Initializable { /** */ private Map loggerCache = new HashMap(); private String threshold = "info"; private int currentThreshold; public void initialize() { currentThreshold = parseThreshold( threshold ); if ( currentThreshold == -1 ) { currentThreshold = Logger.LEVEL_DEBUG; } } protected int parseThreshold( String text ) { text = text.trim().toLowerCase( Locale.ENGLISH ); if ( text.equals( "debug" ) ) { return Logger.LEVEL_DEBUG; } else if ( text.equals( "info" ) ) { return Logger.LEVEL_INFO; } else if ( text.equals( "warn" ) ) { return Logger.LEVEL_WARN; } else if ( text.equals( "error" ) ) { return Logger.LEVEL_ERROR; } else if ( text.equals( "fatal" ) ) { return Logger.LEVEL_FATAL; } return -1; } /** * Sets the threshold for all new loggers. It will NOT affect the existing loggers. *

* This is usually only set once while the logger manager is configured. * * @param currentThreshold The new threshold. */ public void setThreshold( int currentThreshold ) { this.currentThreshold = currentThreshold; } /** * Sets the threshold for all new loggers. It will NOT affect the existing loggers. *

* This is usually only set once while the logger manager is configured. * * @param currentThreshold The new threshold. */ public void setThresholds( int currentThreshold ) { this.currentThreshold = currentThreshold; for ( Iterator logs = loggerCache.values().iterator(); logs.hasNext(); ) { Logger logger = (Logger) logs.next(); logger.setThreshold( currentThreshold ); } } /** * Returns the current threshold for all new loggers. * * @return Returns the current threshold for all new loggers. */ public int getThreshold() { return currentThreshold; } public void setThreshold( String role, String roleHint, int threshold ) { AbstractLogger logger; String key = toMapKey( role, roleHint ); logger = ( AbstractLogger ) loggerCache.get( key ); if ( logger == null ) { return; // nothing to do } logger.setThreshold( threshold ); } public int getThreshold( String role, String roleHint ) { AbstractLogger logger; String key = toMapKey( role, roleHint ); logger = ( AbstractLogger ) loggerCache.get( key ); if ( logger == null ) { return Logger.LEVEL_DEBUG; // does not return null because that could create a NPE } return logger.getThreshold(); } public Logger getLoggerForComponent( String role, String roleHint ) { Logger logger; String key = toMapKey( role, roleHint ); logger = ( Logger ) loggerCache.get( key ); if ( logger != null ) { return logger; } logger = createLogger( key ); loggerCache.put( key, logger ); return logger; } protected abstract Logger createLogger( String key ); public void returnComponentLogger( String role, String roleHint ) { Object obj; String key = toMapKey( role, roleHint ); obj = loggerCache.remove( key ); if ( obj == null ) { // TODO: use a logger! System.err.println( "There was no such logger '" + key + "' " + hashCode() + "." ); } } public int getActiveLoggerCount() { return loggerCache.size(); } public String getThresholdAsString() { return threshold; } } LogEnabled.java000066400000000000000000000014371166327066700351420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @version $Id: LogEnabled.java 6965 2007-10-21 05:32:27Z jvanzyl $ */ public interface LogEnabled { void enableLogging( Logger logger ); } Logger.java000066400000000000000000000037431166327066700343670ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: Logger.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Logger { /** Typecode for debugging messages. */ int LEVEL_DEBUG = 0; /** Typecode for informational messages. */ int LEVEL_INFO = 1; /** Typecode for warning messages. */ int LEVEL_WARN = 2; /** Typecode for error messages. */ int LEVEL_ERROR = 3; /** Typecode for fatal error messages. */ int LEVEL_FATAL = 4; /** Typecode for disabled log levels. */ int LEVEL_DISABLED = 5; void debug( String message ); void debug( String message, Throwable throwable ); boolean isDebugEnabled(); void info( String message ); void info( String message, Throwable throwable ); boolean isInfoEnabled(); void warn( String message ); void warn( String message, Throwable throwable ); boolean isWarnEnabled(); void error( String message ); void error( String message, Throwable throwable ); boolean isErrorEnabled(); void fatalError( String message ); void fatalError( String message, Throwable throwable ); boolean isFatalErrorEnabled(); Logger getChildLogger( String name ); int getThreshold(); void setThreshold( int threshold ); String getName(); } LoggerManager.java000066400000000000000000000040411166327066700356520ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: LoggerManager.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface LoggerManager { String ROLE = LoggerManager.class.getName(); /** * Sets the threshold for all new loggers. It will NOT affect the existing loggers. * * This is usually only set once while the logger manager is configured. * * @param threshold The new threshold. */ void setThreshold( int threshold ); /** * Returns the current threshold for all new loggers. * * @return Returns the current threshold for all new loggers. */ int getThreshold(); /** * Sets the threshold for all loggers. It affects all the existing loggers * as well as future loggers. * * @param threshold The new threshold. */ void setThresholds( int threshold ); // The new stuff void setThreshold( String role, int threshold ); void setThreshold( String role, String roleHint, int threshold ); int getThreshold( String role ); int getThreshold( String role, String roleHint ); Logger getLoggerForComponent( String role ); Logger getLoggerForComponent( String role, String roleHint ); void returnComponentLogger( String role ); void returnComponentLogger( String role, String hint ); int getActiveLoggerCount(); } 000077500000000000000000000000001166327066700337405ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/logging/consoleConsoleLogger.java000066400000000000000000000057061166327066700373550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/logging/consolepackage org.codehaus.plexus.logging.console; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.logging.AbstractLogger; import org.codehaus.plexus.logging.Logger; /** * Logger sending everything to the standard output streams. * This is mainly for the cases when you have a utility that * does not have a logger to supply. * * @author Avalon Development Team * @version $Id: ConsoleLogger.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public final class ConsoleLogger extends AbstractLogger { public ConsoleLogger( int threshold, String name ) { super( threshold, name ); } public void debug( String message, Throwable throwable ) { if ( isDebugEnabled() ) { System.out.print( "[DEBUG] " ); System.out.println( message ); if ( null != throwable ) { throwable.printStackTrace( System.out ); } } } public void info( String message, Throwable throwable ) { if ( isInfoEnabled() ) { System.out.print( "[INFO] " ); System.out.println( message ); if ( null != throwable ) { throwable.printStackTrace( System.out ); } } } public void warn( String message, Throwable throwable ) { if ( isWarnEnabled() ) { System.out.print( "[WARNING] " ); System.out.println( message ); if ( null != throwable ) { throwable.printStackTrace( System.out ); } } } public void error( String message, Throwable throwable ) { if ( isErrorEnabled() ) { System.out.print( "[ERROR] " ); System.out.println( message ); if ( null != throwable ) { throwable.printStackTrace( System.out ); } } } public void fatalError( String message, Throwable throwable ) { if ( isFatalErrorEnabled() ) { System.out.print( "[FATAL ERROR] " ); System.out.println( message ); if ( null != throwable ) { throwable.printStackTrace( System.out ); } } } public Logger getChildLogger( String name ) { return this; } } ConsoleLoggerManager.java000066400000000000000000000154301166327066700406430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/logging/consolepackage org.codehaus.plexus.logging.console; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.logging.AbstractLoggerManager; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Map; /** * This is a simple logger manager that will only write the logging statements to the console. * * Sample configuration: *

 * 
 *   org.codehaus.plexus.logging.ConsoleLoggerManager
 *   
 *     DEBUG
 *   
 * 
 * 
* * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: ConsoleLoggerManager.java 7789 2008-10-13 22:54:22Z bentmann $ */ public class ConsoleLoggerManager extends AbstractLoggerManager implements LoggerManager, Initializable { /** * Message of this level or higher will be logged. * * This field is set by the plexus container thus the name is 'threshold'. The field * currentThreshold contains the current setting of the threshold. */ private String threshold = "info"; private int currentThreshold; private Map loggers; /** The number of active loggers in use. */ private int loggerCount; private boolean bootTimeLogger = false; public ConsoleLoggerManager() { } /** * This special constructor is called directly when the container is bootstrapping itself. */ public ConsoleLoggerManager( String threshold ) { this.threshold = threshold; bootTimeLogger = true; initialize(); } public void initialize() { debug( "Initializing ConsoleLoggerManager: " + this.hashCode() + "." ); // if ( !bootTimeLogger ) // new Throwable().printStackTrace(System.err); currentThreshold = parseThreshold( threshold ); if ( currentThreshold == -1 ) { debug( "Could not parse the threshold level: '" + threshold + "', setting to debug." ); currentThreshold = Logger.LEVEL_DEBUG; } loggers = new HashMap(); } public void setThreshold( int currentThreshold ) { this.currentThreshold = currentThreshold; } public void setThresholds( int currentThreshold ) { this.currentThreshold = currentThreshold; for ( Iterator logs = loggers.values().iterator(); logs.hasNext(); ) { Logger logger = (Logger) logs.next(); logger.setThreshold( currentThreshold ); } } /** * @return Returns the threshold. */ public int getThreshold() { return currentThreshold; } // new stuff public void setThreshold( String role, String roleHint, int threshold ) { ConsoleLogger logger; String name; name = toMapKey( role, roleHint ); logger = (ConsoleLogger)loggers.get( name ); if(logger == null) { debug( "Trying to set the threshold of a unknown logger '" + name + "'." ); return; // nothing to do } logger.setThreshold( threshold ); } public int getThreshold( String role, String roleHint ) { ConsoleLogger logger; String name; name = toMapKey( role, roleHint ); logger = (ConsoleLogger)loggers.get( name ); if(logger == null) { debug( "Trying to get the threshold of a unknown logger '" + name + "'." ); return Logger.LEVEL_DEBUG; // does not return null because that could create a NPE } return logger.getThreshold(); } public Logger createLogger(int threshold, String name) { return new ConsoleLogger( threshold, name ); } public Logger getLoggerForComponent( String role, String roleHint ) { Logger logger; String name; name = toMapKey( role, roleHint ); logger = (Logger)loggers.get( name ); if ( logger != null ) return logger; debug( "Creating logger '" + name + "' " + this.hashCode() + "." ); logger = createLogger( getThreshold(), name ); loggers.put( name, logger ); return logger; } public void returnComponentLogger( String role, String roleHint ) { Object obj; String name; name = toMapKey( role, roleHint ); obj = loggers.remove( name ); if ( obj == null ) { debug( "There was no such logger '" + name + "' " + this.hashCode() + "."); } else { debug( "Removed logger '" + name + "' " + this.hashCode() + "."); } } public int getActiveLoggerCount() { return loggers.size(); } private int parseThreshold( String text ) { text = text.trim().toLowerCase( Locale.ENGLISH ); if ( text.equals( "debug" ) ) { return ConsoleLogger.LEVEL_DEBUG; } else if ( text.equals( "info" ) ) { return ConsoleLogger.LEVEL_INFO; } else if ( text.equals( "warn" ) ) { return ConsoleLogger.LEVEL_WARN; } else if ( text.equals( "error" ) ) { return ConsoleLogger.LEVEL_ERROR; } else if ( text.equals( "fatal" ) ) { return ConsoleLogger.LEVEL_FATAL; } return -1; } private String decodeLogLevel( int logLevel ) { switch(logLevel) { case ConsoleLogger.LEVEL_DEBUG: return "debug"; case ConsoleLogger.LEVEL_INFO: return "info"; case ConsoleLogger.LEVEL_WARN: return "warn"; case ConsoleLogger.LEVEL_ERROR: return "error"; case ConsoleLogger.LEVEL_FATAL: return "fatal"; case ConsoleLogger.LEVEL_DISABLED: return "disabled"; default: return "unknown"; } } /** * Remove this method and all references when this code is verified. * * @param msg */ private void debug( String msg ) { // if ( !bootTimeLogger ) // System.out.println( "[Console] " + msg ); } } plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/000077500000000000000000000000001166327066700333005ustar00rootroot00000000000000000077500000000000000000000000001166327066700345415ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus000077500000000000000000000000001166327066700365005ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle000077500000000000000000000000001166327066700376005ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phaseAutoConfigurePhase.java000066400000000000000000000053161166327066700442030ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ComponentConfigurator; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; import org.codehaus.plexus.util.StringUtils; public class AutoConfigurePhase extends AbstractPhase { public static final String DEFAULT_CONFIGURATOR_ID = "default"; public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) throws PhaseExecutionException { try { ComponentDescriptor descriptor = manager.getComponentDescriptor(); String configuratorId = descriptor.getComponentConfigurator(); if ( StringUtils.isEmpty( configuratorId ) ) { configuratorId = DEFAULT_CONFIGURATOR_ID; } ComponentConfigurator componentConfigurator = manager.getContainer().lookup( ComponentConfigurator.class, configuratorId ); PlexusConfiguration configuration = manager.getContainer().getConfigurationSource().getConfiguration( descriptor ); if ( configuration != null ) { ClassRealm realm = manager.getRealm(); componentConfigurator.configureComponent( object, configuration, realm ); } } catch ( ComponentLookupException e ) { throw new PhaseExecutionException( "Unable to auto-configure component as its configurator could not be found", e ); } catch ( ComponentConfigurationException e ) { throw new PhaseExecutionException( "Unable to auto-configure component", e ); } } } Configurable.java000066400000000000000000000020221166327066700430370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; /** * Configures a component. * * @author Dan Diephouse */ public interface Configurable { void configure( PlexusConfiguration configuration ) throws PlexusConfigurationException; } ConfigurablePhase.java000066400000000000000000000027651166327066700440360ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class ConfigurablePhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) throws PhaseExecutionException { if ( object instanceof Configurable ) { try { ( (Configurable) object ).configure( manager.getComponentDescriptor().getConfiguration() ); } catch ( PlexusConfigurationException e ) { throw new PhaseExecutionException( "Error occurred during phase execution", e ); } } } } Contextualizable.java000066400000000000000000000017521166327066700437650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; /** * @author Jason van Zyl * @version $Id: Contextualizable.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Contextualizable { public void contextualize( Context context ) throws ContextException; } ContextualizePhase.java000066400000000000000000000033621166327066700442660ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class ContextualizePhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) throws PhaseExecutionException { if ( object instanceof Contextualizable ) { Context context = manager.getContainer().getContext(); ClassRealm origRealm = manager.getContainer().setLookupRealm( lookupRealm ); try { ( (Contextualizable) object ).contextualize( context ); } catch ( ContextException e ) { throw new PhaseExecutionException( "Unable to contextualize component", e ); } finally { manager.getContainer().setLookupRealm( origRealm ); } } } } Disposable.java000066400000000000000000000015161166327066700425330ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: Disposable.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Disposable { public void dispose(); } DisposePhase.java000066400000000000000000000021451166327066700430340ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class DisposePhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) { if ( object instanceof Disposable ) { ( (Disposable) object ).dispose(); } } } Initializable.java000066400000000000000000000015761166327066700432340ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: Initializable.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Initializable { public void initialize() throws InitializationException; } InitializationException.java000066400000000000000000000022101166327066700453040ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Indicates a problem occurred when initialising a component. * * @author Brett Porter * @version $Id: InitializationException.java 6965 2007-10-21 05:32:27Z jvanzyl $ */ public class InitializationException extends Exception { public InitializationException( String message ) { super( message ); } public InitializationException( String message, Throwable cause ) { super( message, cause ); } } InitializePhase.java000066400000000000000000000025541166327066700435330ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class InitializePhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) throws PhaseExecutionException { if ( object instanceof Initializable ) { try { ( (Initializable) object ).initialize(); } catch ( InitializationException e ) { throw new PhaseExecutionException( "Error initialising component", e ); } } } } LogDisablePhase.java000066400000000000000000000031631166327066700434340ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2007 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.logging.LoggerManager; /** * @author Trygve Laugstøl * @version $Id: LogDisablePhase.java 7858 2008-11-20 03:48:11Z dain $ */ public class LogDisablePhase extends AbstractPhase { public void execute( Object object, ComponentManager componentManager, ClassRealm lookupRealm ) throws PhaseExecutionException { if ( object instanceof LogEnabled ) { LoggerManager loggerManager = componentManager.getContainer().getLoggerManager(); loggerManager.returnComponentLogger( componentManager.getRole(), componentManager.getRoleHint() ); } } } LogEnablePhase.java000066400000000000000000000032021166327066700432510ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2007 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; public class LogEnablePhase extends AbstractPhase { public void execute( Object object, ComponentManager componentManager, ClassRealm lookupRealm ) throws PhaseExecutionException { if ( object instanceof LogEnabled ) { LogEnabled logEnabled = (LogEnabled) object; LoggerManager loggerManager = componentManager.getContainer().getLoggerManager(); Logger logger = loggerManager.getLoggerForComponent( componentManager.getRole(), componentManager.getRoleHint() ); logEnabled.enableLogging( logger ); } } } PhaseExecutionException.java000066400000000000000000000021001166327066700452370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Describes an error that has occurred during the execution of a phase. * * @author Brett Porter * @version $Id: PhaseExecutionException.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public class PhaseExecutionException extends Exception { public PhaseExecutionException( String message, Throwable throwable ) { super( message, throwable ); } } PlexusContainerLocator.java000066400000000000000000000050471166327066700451200ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import java.util.List; import java.util.Map; /** * A ServiceLocator for PlexusContainer. * * @author Dan Diephouse */ public class PlexusContainerLocator implements ServiceLocator { private PlexusContainer container; public PlexusContainerLocator( PlexusContainer container ) { this.container = container; } public Object lookup( String role ) throws ComponentLookupException { return container.lookup( role ); } public Object lookup( String role, String roleHint ) throws ComponentLookupException { return container.lookup( role, roleHint ); } public Map lookupMap( String role ) throws ComponentLookupException { return container.lookupMap( role ); } public List lookupList( String role ) throws ComponentLookupException { return container.lookupList( role ); } public void release( Object component ) throws ComponentLifecycleException { container.release( component ); } public void releaseAll( Map components ) throws ComponentLifecycleException { container.releaseAll( components ); } public void releaseAll( List components ) throws ComponentLifecycleException { container.releaseAll( components ); } public boolean hasComponent( String componentKey ) { return container.hasComponent( componentKey ); } public boolean hasComponent( String role, String roleHint ) { return container.hasComponent( role, roleHint ); } } ResumePhase.java000066400000000000000000000021451166327066700426660ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class ResumePhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) { if ( object instanceof Suspendable ) { ( (Suspendable) object ).resume(); } } } ServiceLocator.java000066400000000000000000000043721166327066700433750ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import java.util.List; import java.util.Map; /** * Provides services to components by means of a lookup. * * @author Dan Diephouse */ public interface ServiceLocator { //---------------------------------------------------------------------- // Component lookup // ---------------------------------------------------------------------- Object lookup( String componentKey ) throws ComponentLookupException; Object lookup( String role, String roleHint ) throws ComponentLookupException; Map lookupMap( String role ) throws ComponentLookupException; List lookupList( String role ) throws ComponentLookupException; //---------------------------------------------------------------------- // Component release // ---------------------------------------------------------------------- void release( Object component ) throws ComponentLifecycleException; void releaseAll( Map components ) throws ComponentLifecycleException; void releaseAll( List components ) throws ComponentLifecycleException; // ---------------------------------------------------------------------- // Component discovery // ---------------------------------------------------------------------- boolean hasComponent( String componentKey ); boolean hasComponent( String role, String roleHint ); } Serviceable.java000066400000000000000000000015731166327066700426750ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Indicates that a class wants a hold on a ServiceLocator. * * @author Dan Diephouse */ public interface Serviceable { void service( ServiceLocator locator ); } ServiceablePhase.java000066400000000000000000000023771166327066700436610ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class ServiceablePhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) { if ( object instanceof Serviceable ) { PlexusContainer container = manager.getContainer(); ( (Serviceable) object ).service( new PlexusContainerLocator(container) ); } } } StartPhase.java000066400000000000000000000025201166327066700425200ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class StartPhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) throws PhaseExecutionException { if ( object instanceof Startable ) { try { ( (Startable) object ).start(); } catch ( StartingException e ) { throw new PhaseExecutionException( "Error starting component", e ); } } } } Startable.java000066400000000000000000000014511166327066700423650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface Startable { void start() throws StartingException; void stop() throws StoppingException; } StartingException.java000066400000000000000000000021451166327066700441170ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Error occuring while starting a component. * * @author Brett Porter * @version $Id: StartingException.java 6965 2007-10-21 05:32:27Z jvanzyl $ */ public class StartingException extends Exception { public StartingException( String message ) { super( message ); } public StartingException( String message, Throwable cause ) { super( message, cause ); } } StopPhase.java000066400000000000000000000025161166327066700423550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class StopPhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) throws PhaseExecutionException { if ( object instanceof Startable ) { try { ( (Startable) object ).stop(); } catch ( StoppingException e ) { throw new PhaseExecutionException( "Error stopping component", e ); } } } } StoppingException.java000066400000000000000000000021451166327066700441270ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Error occuring while starting a component. * * @author Brett Porter * @version $Id: StoppingException.java 6965 2007-10-21 05:32:27Z jvanzyl $ */ public class StoppingException extends Exception { public StoppingException( String message ) { super( message ); } public StoppingException( String message, Throwable cause ) { super( message, cause ); } } SuspendPhase.java000066400000000000000000000021471166327066700430510ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class SuspendPhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) { if ( object instanceof Suspendable ) { ( (Suspendable) object ).suspend(); } } } Suspendable.java000066400000000000000000000013551166327066700427140ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/java/org/codehaus/plexus/personality/plexus/lifecycle/phasepackage org.codehaus.plexus.personality.plexus.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface Suspendable { void suspend(); void resume(); } plexus-containers1.5-1.5.5/plexus-container-default/src/main/mdo/000077500000000000000000000000001166327066700246635ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/mdo/components.mdo000066400000000000000000000217431166327066700275600ustar00rootroot00000000000000 plexus-components PlexusComponents This is a documentation for the Plexus Components descriptor: META-INF/plexus/components.xml.

An XSD is available at http://plexus.codehaus.org/xsd/components-1.3.0.xsd.

]]>
ComponentSetDescriptor javadoc.]]> 1.0.0+ components 1.0.0+ ComponentDescriptor * The component descriptors that can be found within this component set descriptor. dependencies 1.0.0+ ComponentDependency * The dependencies that are required by the set of components found in this component set descriptor. ComponentDescriptor javadoc.]]> 1.0.0+ role 1.0.0+ String the role of this component. role-hint 1.0.0+ String the role-hint of this component. implementation 1.0.0+ String the implementation of this component. Implementation is a string denoting a FQCN in normal Java components, or some other name or file for other component factory implementations. version 1.0.0+ String a specific point in a components's project timeline. i.e. version 1, or 2.1.4 component-type 1.0.0+ String the type of this component. instantiation-strategy 1.0.0+ String the type of instantiation strategy for this component: one of "per-lookup", "singleton", "keep-alive" or "poolable". singleton lifecycle-handler 1.0.0+ String the lifecycle-handler for this component. For example, "basic", "passive", "bootstrap". component-profile 1.0.0+ String component-composer 1.0.0+ String the ID of the type of composer this component will use. For example, "setter" or "field" for the different types of dependency injection. component-configurator 1.0.0+ String the type of component configurator for this project. For example "basic" for normal, or "map-oriented" for map oriented components. component-factory 1.0.0+ String an id of the factory used to create this component. For example, "jruby" will use a JRuby factory. description 1.0.0+ String a human-readable description of this component. alias 1.0.0+ String an alias for this component. An alias is as an alternate name other than the normal key. isolated-realm 1.0.0+ boolean true if this may be in an isolated classrealm. configuration 1.0.0+ DOM configuration values defined for this component. requirements 1.0.0+ ComponentRequirement * project requirements to this component. ComponentRequirement This represents a component that is required by another component. 1.0.0+ role 1.0.0+ String the role of the required component. field-name 1.0.0+ String the name of the field that will be populated by the required component. role-hint 1.0.0+ String the role-hint of the required component. default role-hints 1.0.0+ String * the role-hints of the required component. optional 1.3.0+ boolean Controls whether a failure to satisfy this requirement can be tolerated by host component or whether construction of the host component should also fail. ComponentDependency 1.0.0+ artifact-id 1.0.0+ String the dependency's artifact ID. group-id 1.0.0+ String the dependency's group ID. type 1.0.0+ String the type of dependency, for example a "jar". version 1.0.0+ String the point in a project's development timeline
plexus-containers1.5-1.5.5/plexus-container-default/src/main/mdo/plexus.mdo000066400000000000000000000155311166327066700267110ustar00rootroot00000000000000 plexus-configuration PlexusConfiguration This is a Work In Progress for a documentation for the Plexus Container descriptor: META-INF/plexus/plexus.xml.

An XSD will be available at http://plexus.codehaus.org/xsd/plexus-1.3.0.xsd.

Note that since plexus.xml is a superset of components.xml, this documentation only focuses on elements only available in plexus.xml.

]]>
PlexusDescriptor see org.codehaus.plexus.configuration.PlexusConfigurationMerger 1.0.0+ load-on-start 1.0.0+ TBD DOM system-properties 1.0.0+ TBD DOM configurations-directory 1.0.0+ TBD DOM logging 1.0.0+ TBD DOM component-repository 1.0.0+ TBD DOM resources 1.0.0+ TBD DOM component-manager-manager 1.0.0+ TBD DOM component-discoverer-manager 1.0.0+ TBD ComponentDiscovererManager component-factory-manager 1.0.0+ TBD DOM lifecycle-handler-manager 1.0.0+ TBD DOM component-composer-manager 1.0.0+ TBD DOM components 1.0.0+ DOM components.xml.]]> ComponentDiscovererManager org.codehaus.plexus.component.discovery.ComponentDiscovererManager source javadoc.]]> 1.0.0+ implementation 1.0.0+ Implementation class. String listeners 1.0.0+ * ComponentDiscoveryListener component-discoverers 1.0.0+ * ComponentDiscoverer ComponentDiscoveryListener org.codehaus.plexus.component.discovery.ComponentDiscoveryListener source javadoc.]]> 1.0.0+ implementation 1.0.0+ Implementation class. String configuration 1.0.0+ Configuration of the class. Content ComponentDiscoverer org.codehaus.plexus.component.discovery.ComponentDiscoverer source javadoc.]]> 1.0.0+ implementation 1.0.0+ Implementation class. String configuration 1.0.0+ Configuration of the class. Content
plexus-containers1.5-1.5.5/plexus-container-default/src/main/resources/000077500000000000000000000000001166327066700261165ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/resources/META-INF/000077500000000000000000000000001166327066700272565ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/resources/META-INF/plexus/000077500000000000000000000000001166327066700305765ustar00rootroot00000000000000components.xml000066400000000000000000000011261166327066700334260ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/main/resources/META-INF/plexus org.codehaus.plexus.component.configurator.BasicComponentConfigurator org.codehaus.plexus.component.configurator.ComponentConfigurator basic org.codehaus.plexus.component.configurator.MapOrientedComponentConfigurator org.codehaus.plexus.component.configurator.ComponentConfigurator map-oriented plexus-containers1.5-1.5.5/plexus-container-default/src/site/000077500000000000000000000000001166327066700241245ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/site/apt/000077500000000000000000000000001166327066700247105ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/site/apt/index.apt000066400000000000000000000022771166327066700265350ustar00rootroot00000000000000 ----- plexus-container-default ----- HervĂ© Boutemy ----- 2009-10-06 ----- Overview <<>> is Plexus' (IoC) container. It is composed of: * its public API: the root class is <<<{{{./apidocs/org/codehaus/plexus/PlexusContainer.html}org.codehaus.plexus.PlexusContainer}}>>>, * its default implementation: the root class is <<<{{{./apidocs/org/codehaus/plexus/DefaultPlexusContainer.html}org.codehaus.plexus.DefaultPlexusContainer}}>>>. [] Default implementation reads configuration in XML files: * multiple <<<{{{./plexus-components.html}META-INF/plexus/components.xml}}>>> files that declare components, * one <<<{{{./plexus-configuration.html}META-INF/plexus/plexus.xml}}>>> file that can be used to configure the plexus container and runtime in addition to declaring components. [] But it is not limited to these files: Plexus container is by nature very extensible, it can be configured programmatically too or extended to read configuration from any source. It is used for example in Maven 2 to read plugins configuration from <<>> and instanciate Mojos downloaded from Maven repositories. plexus-containers1.5-1.5.5/plexus-container-default/src/site/site.xml000066400000000000000000000006751166327066700256220ustar00rootroot00000000000000 plexus-containers1.5-1.5.5/plexus-container-default/src/test/000077500000000000000000000000001166327066700241375ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/000077500000000000000000000000001166327066700250605ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/000077500000000000000000000000001166327066700256475ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/000077500000000000000000000000001166327066700274425ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/000077500000000000000000000000001166327066700307625ustar00rootroot00000000000000DefaultComponentLookupManagerTest.java000066400000000000000000000021171166327066700403430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexuspackage org.codehaus.plexus; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.test.ComponentA; /** * @author Trygve Laugstøl * @version $Id: DefaultComponentLookupManagerTest.java 7828 2008-11-14 22:07:56Z dain $ */ public class DefaultComponentLookupManagerTest extends PlexusTestCase { public void testLookupsWithAndWithoutRoleHint() throws Exception { String resource = getConfigurationName( "components.xml" ); System.out.println( "resource = " + resource ); assertNotNull( resource ); ContainerConfiguration c = new DefaultContainerConfiguration() .setName( "test" ) .setContainerConfiguration( resource ); DefaultPlexusContainer container = new DefaultPlexusContainer( c ); try { container.lookup( ComponentA.class ); fail( "Expected exception" ); } catch ( ComponentLookupException e ) { // expected } } } DyanamicComponentKungFuTest.java000066400000000000000000000067431166327066700371500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; /** * This is the start of the sketch which outlines some of the things * I would like to do with components during runtime. * * @author Jason van Zyl * * @version $Id: DyanamicComponentKungFuTest.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DyanamicComponentKungFuTest extends TestCase { /** * Component additions during container operation. * * 1. Add a component at runtime * -> Additions could be made by specifying an URL which will be compatible with Wagon * and specifically Maven's way of using Wagon. * * 2. Configure the dynamically added component * -> We need to be able to deal with different flavours of components but we can focus * on Plexus components to start with. But some components may have meta information * and some may not like pico components. But one of the first flavours I want to * support is phoenix components because I specifically need the FTP server. * * 3. Let the component perform its role * * 4. Suspend the component * a) Define the criteria for which we can suspend a component * -> When there are no client connections? * -> Even when there are no connections and a client tries to obtain a connection what do we do? * -> If we are in desperate need to suspend the component, say for urgent security requirement, and * clients simply won't bugger off what do we do? * * 5. Reconfigure the component * * 6. Resume the component * * 7. Let the component perform its role * * 8. Release the component */ public void testAdditionOfComponentDuringContainerOperation() throws Exception { } /** * Component replacement during container operation. * * This will force the design of a mechanism where the components communicate * with one another via a connector. In order for components to be replaced * dynamically the components cannot be directly coupled to one another. * * How to decide if a component is a suitable replacement given the versions * of the specifications of the component and any required components if the * component is a composite component. * * Definitely need to simulate the connection (a MockConnection) during * runtime to make sure that in the event something goes wrong the container * can just refuse to allow the component substitution. This shouldn't be trial * and error but until much field testing has occurred I'm sure there will be * instances where miscalculations happen simply due to lack of experience and * usage with dynamic component replacement. */ public void testComponentReplacementDuringContainerOperation() throws Exception { } } PlexusTestCaseTest.java000066400000000000000000000060201166327066700353200ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexuspackage org.codehaus.plexus; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; import org.codehaus.plexus.component.discovery.DiscoveredComponent; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.test.DefaultLoadOnStartService; import java.io.File; /** * @author Jason van Zyl * @version $Id: PlexusTestCaseTest.java 7828 2008-11-14 22:07:56Z dain $ */ public class PlexusTestCaseTest extends TestCase { private String basedir; public void setUp() { basedir = System.getProperty( "basedir" ); if ( basedir == null ) { basedir = new File( "." ).getAbsolutePath(); } } public void testPlexusTestCase() throws Exception { PlexusTestCase tc = new PlexusTestCase() { }; tc.setUp(); try { tc.lookup( DiscoveredComponent.class, "unknown" ); fail( "Expected ComponentLookupException." ); } catch ( ComponentLookupException ex ) { assertTrue( true ); } // This component is discovered from src/test/META-INF/plexus/components.xml DiscoveredComponent component = tc.lookup( DiscoveredComponent.class ); assertNotNull( component ); assertNotNull( tc.getClassLoader() ); tc.tearDown(); } public void testLoadOnStartComponents() throws Exception { PlexusTestCase tc = new PlexusTestCase() { protected String getCustomConfigurationName() { return PlexusTestCase.getTestConfiguration( getClass() ); } }; tc.setupContainer(); // Assert that the load on start component has started. assertTrue( "The load on start components haven't been started.", DefaultLoadOnStartService.isStarted ); tc.tearDown(); } public void testGetFile() { File file = PlexusTestCase.getTestFile( "pom.xml" ); assertTrue( file.exists() ); file = PlexusTestCase.getTestFile( basedir, "pom.xml" ); assertTrue( file.exists() ); } public void testGetPath() { File file = new File( PlexusTestCase.getTestPath( "pom.xml" ) ); assertTrue( file.exists() ); file = new File( PlexusTestCase.getTestPath( basedir, "pom.xml" ) ); assertTrue( file.exists() ); } } plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/000077500000000000000000000000001166327066700327645ustar00rootroot00000000000000MapOrientedComponentProcessingTest.java000066400000000000000000000054001166327066700425360ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/componentpackage org.codehaus.plexus.component; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Map; import junit.framework.TestCase; import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.logging.LoggerManager; public class MapOrientedComponentProcessingTest extends TestCase { public void testShouldFindAndInitializeMapOrientedComponent() throws Exception { PlexusContainer embedder = new DefaultPlexusContainer(); ComponentDescriptor descriptor = new ComponentDescriptor(TestMapOrientedComponent.class, embedder.getContainerRealm()); descriptor.setRole( TestMapOrientedComponent.ROLE ); descriptor.setImplementation( TestMapOrientedComponent.ROLE ); descriptor.setComponentComposer( "map-oriented" ); descriptor.setComponentConfigurator( "map-oriented" ); ComponentRequirement requirement = new ComponentRequirement(); requirement.setFieldName( "testRequirement" ); requirement.setRole( LoggerManager.ROLE ); descriptor.addRequirement( requirement ); PlexusConfiguration param = new XmlPlexusConfiguration( "testParameter" ); param.setValue( "testValue" ); PlexusConfiguration configuration = new XmlPlexusConfiguration( "configuration" ); configuration.addChild( param ); descriptor.setConfiguration( configuration ); embedder.addComponentDescriptor( descriptor ); TestMapOrientedComponent component = embedder.lookup( TestMapOrientedComponent.class ); Map context = component.getContext(); assertTrue( "requirement (LogManager) missing from containerContext.", ( context.get( "testRequirement" ) instanceof LoggerManager ) ); assertEquals( "parameter missing from containerContext.", "testValue", context.get( "testParameter" ) ); } } PlexusTestCaseTest.java000066400000000000000000000014231166327066700373240ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/componentpackage org.codehaus.plexus.component; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; public class PlexusTestCaseTest extends PlexusTestCase { private static final String CUSTOM_PROPERTY = "custom.property"; private static final String CUSTOM_VALUE = "custom.value"; @Override protected void customizeContext( Context context ) { super.customizeContext( context ); context.put( CUSTOM_PROPERTY, CUSTOM_VALUE ); } public void testCustomizeContext() throws ContextException { String value = (String) getContainer().getContext().get( CUSTOM_PROPERTY ); assertEquals( CUSTOM_VALUE, value ); } } TestMapOrientedComponent.java000066400000000000000000000025501166327066700405040ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/componentpackage org.codehaus.plexus.component; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.component.repository.ComponentRequirement; import java.util.Map; import java.util.TreeMap; public class TestMapOrientedComponent implements MapOrientedComponent { public static final String ROLE = TestMapOrientedComponent.class.getName(); private Map context = new TreeMap(); public void addComponentRequirement( ComponentRequirement requirementDescriptor, Object requirementValue ) { context.put( requirementDescriptor.getFieldName(), requirementValue ); } public void setComponentConfiguration( Map componentConfiguration ) { context.putAll( componentConfiguration ); } public Map getContext() { return context; } } 000077500000000000000000000000001166327066700352505ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionAbstractComponent.java000066400000000000000000000016731166327066700415500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: AbstractComponent.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class AbstractComponent implements Component { private ComponentA componentA; public ComponentA getComponentA() { return componentA; } } AbstractCompositionResolverTest.java000066400000000000000000000175371166327066700445010ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.io.PlexusTools; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import java.util.List; /** * * * @author Jason van Zyl * * @version $Id: AbstractCompositionResolverTest.java 8155 2009-04-26 01:22:53Z jvanzyl $ */ public abstract class AbstractCompositionResolverTest extends TestCase { /** * * @return */ protected abstract CompositionResolver getCompositionResolver(); // ------------------------------------------------------------------------ // // +-------+ +-------+ // | c1 | --------> | c2 | // +-------+ +-------+ // | // | // V // +-------+ // | c3 | // +-------+ // // ------------------------------------------------------------------------ public void testSimpleComponentResolution() throws Exception { String cc1 = "" + " java.lang.String" + " c1" + " " + " " + " c2" + " " + " " + " c3" + " " + " " + ""; String cc2 = "" + " java.lang.String" + " c2" + ""; String cc3 = "" + " java.lang.String" + " c3" + ""; ClassWorld classWorld = new ClassWorld( "test", Thread.currentThread().getContextClassLoader() ); ClassRealm realm = classWorld.getRealm( "test" ); CompositionResolver compositionResolver = getCompositionResolver(); ComponentDescriptor c1 = PlexusTools.buildComponentDescriptor( cc1, realm ); ComponentDescriptor c2 = PlexusTools.buildComponentDescriptor( cc2, realm ); ComponentDescriptor c3 = PlexusTools.buildComponentDescriptor( cc3, realm ); compositionResolver.addComponentDescriptor( c1 ); compositionResolver.addComponentDescriptor( c2 ); compositionResolver.addComponentDescriptor( c3 ); List dependencies = compositionResolver.getRequirements( c1.getRole(), c1.getRoleHint() ); assertEquals( 2, dependencies.size() ); assertTrue( dependencies.contains( c2.getRole() + CompositionResolver.SEPARATOR_CHAR + c2.getRoleHint() ) ); assertTrue( dependencies.contains( c3.getRole() + CompositionResolver.SEPARATOR_CHAR + c2.getRoleHint() ) ); assertEquals( 2, dependencies.size() ); } // ------------------------------------------------------------------------ // // +-------+ +-------+ // | c1 | --------> | c2 | // +-------+ +-------+ // | // | // V // +-------+ +-------+ // | c3 | --------> | c4 | // +-------+ +-------+ // | // | // V // +-------+ // | c5 | // +-------+ // // ------------------------------------------------------------------------ public void testComplexComponentResolution() throws Exception { String cc1 = "" + " java.lang.String" + " c1" + " " + " " + " c2" + " " + " " + " c3" + " " + " " + ""; String cc2 = "" + " java.lang.String" + " c2" + ""; String cc3 = "" + " java.lang.String" + " c3" + " " + " " + " c4" + " " + " " + " c5" + " " + " " + ""; String cc4 = "" + " java.lang.String" + " c4" + ""; String cc5 = "" + " java.lang.String" + " c5" + ""; ClassWorld classWorld = new ClassWorld( "test", Thread.currentThread().getContextClassLoader() ); ClassRealm realm = classWorld.getRealm( "test" ); CompositionResolver compositionResolver = getCompositionResolver(); ComponentDescriptor c1 = PlexusTools.buildComponentDescriptor( cc1, realm ); ComponentDescriptor c2 = PlexusTools.buildComponentDescriptor( cc2, realm ); ComponentDescriptor c3 = PlexusTools.buildComponentDescriptor( cc3, realm ); ComponentDescriptor c4 = PlexusTools.buildComponentDescriptor( cc4, realm ); ComponentDescriptor c5 = PlexusTools.buildComponentDescriptor( cc5, realm ); compositionResolver.addComponentDescriptor( c1 ); compositionResolver.addComponentDescriptor( c2 ); compositionResolver.addComponentDescriptor( c3 ); compositionResolver.addComponentDescriptor( c4 ); compositionResolver.addComponentDescriptor( c5 ); List dependencies = compositionResolver.getRequirements( c1.getRole(), c1.getRoleHint() ); assertEquals( 2, dependencies.size() ); // I just leave this at the moment as I am just 99% sure that this is not needed and not // correct. compositionResolver.getComponentDependencies() should return only direct dependencies // // I will need to add a method like getSortedComponents() // which will do topological sort of DAG and return list of ordered component which can be used // by ComponentComposer. // Possibility of checking if there are cycles probably also must be exposed in API (DAG has it alredy) // and it should be used // I can implement cycle detecting from single node (source) as after adding new component // we don't have to probably check entire graph but we will probably have to check // if there are cycles. /** // c5 must come before c3 assertTrue( dependencies.indexOf( "c5" ) < dependencies.indexOf( "c3" ) ); // c4 must come before c3 assertTrue( dependencies.indexOf( "c4" ) < dependencies.indexOf( "c3" ) ); */ } } Component.java000066400000000000000000000014451166327066700400610ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: Component.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Component { } ComponentA.java000066400000000000000000000015651166327066700401650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ComponentA.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface ComponentA { String ROLE = ComponentA.class.getName(); ComponentB getComponentB(); } ComponentB.java000066400000000000000000000015151166327066700401610ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ComponentB.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface ComponentB { ComponentC getComponentC(); } ComponentC.java000066400000000000000000000014461166327066700401650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ComponentC.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface ComponentC { } ComponentD.java000066400000000000000000000014461166327066700401660ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ComponentD.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface ComponentD { } ComponentE.java000066400000000000000000000014461166327066700401670ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ComponentE.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface ComponentE { } ComponentF.java000066400000000000000000000036241166327066700401700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.List; import java.util.Map; /** * @author Michal Maczka * @version $Id: ComponentF.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public class ComponentF { private ComponentA componentA; private ComponentB componentB; private ComponentC[] componentC; private List componentD; private Map componentE; public ComponentA getComponentA() { return componentA; } public void setComponentA( ComponentA componentA ) { this.componentA = componentA; } public ComponentB getComponentB() { return componentB; } public void setComponentB( ComponentB componentB ) { this.componentB = componentB; } public ComponentC[] getComponentC() { return componentC; } public void setComponentC( ComponentC[] componentC ) { this.componentC = componentC; } public List getComponentD() { return componentD; } public void setComponentD( List componentD ) { this.componentD = componentD; } public Map getComponentE() { return componentE; } public void setComponentE( Map componentE ) { this.componentE = componentE; } } ComponentRealmCompositionTest.java000066400000000000000000000141131166327066700441220ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; import org.codehaus.plexus.PlexusTestCase; import static org.codehaus.plexus.PlexusConstants.PLEXUS_DEFAULT_HINT; import org.codehaus.plexus.classworlds.realm.ClassRealm; import java.io.File; import java.net.URL; import java.util.Map; import java.util.List; import java.util.TreeMap; /** @author Jason van Zyl */ public class ComponentRealmCompositionTest extends PlexusTestCase { // // Component archives // private static final String PLUGIN_0_JAR = "src/test/test-components/plugin0-1.0-SNAPSHOT.jar"; private static final String PLUGIN_1_JAR = "src/test/test-components/plugin1-1.0-SNAPSHOT.jar"; private static final String COMPONENT_A_JAR = "src/test/test-components/component-a-1.0-SNAPSHOT.jar"; private static final String COMPONENT_B_JAR = "src/test/test-components/component-b-1.0-SNAPSHOT.jar"; private static final String COMPONENT_C_JAR = "src/test/test-components/component-c-1.0-SNAPSHOT.jar"; private static final String ARCHIVER_JAR = "src/test/test-components/plexus-archiver-1.0-alpha-8.jar"; // // Component roles // private static final String PLUGIN_0_ROLE = "org.codehaus.plexus.plugins.Plugin0"; private static final String PLUGIN_1_ROLE = "org.codehaus.plexus.plugins.Plugin1"; // // Component realms // private static final String PLUGIN_0_REALM = "plugin0Realm"; private static final String PLUGIN_1_REALM = "plugin1Realm"; protected void setUp() throws Exception { super.setUp(); // Create ClassRealm plugin0 with plugin0 -> A, plugin0 -> B createClassRealm( PLUGIN_0_REALM, PLUGIN_0_JAR, COMPONENT_A_JAR, COMPONENT_B_JAR, ARCHIVER_JAR ); // Create ClassRealm plugin1 with plugin1 -> A, plugin1 -> C createClassRealm( PLUGIN_1_REALM, PLUGIN_1_JAR, COMPONENT_A_JAR, COMPONENT_C_JAR, ARCHIVER_JAR ); } /* * We are testing that when the same component implementation exists in more then one * realm and components depend on those implementations, that the right realm is used * to wire up the components. * * An example of this in practice are Maven plugins where each plugin is loaded into * a separate realm and the plugin may have dependencies on other components. We want * to make sure that a requirement, say a JarArchiver, for a given component, say the * maven-jar-plugin, is wired up with a JarArchiver taken from the same realm as the * maven-jar-plugin and not a different realm. */ public void testCompositionWhereTheSameImplementationExistsInDifferentRealms() throws Exception { // Plugin0 getContainer().lookup( PLUGIN_0_ROLE ); // Plugin1 getContainer().lookup( PLUGIN_1_ROLE ); // Plugin0(alt) getContainer().lookup( PLUGIN_0_ROLE, "alt" ); // Plugin1(alt) getContainer().lookup( PLUGIN_1_ROLE, "alt" ); } public void testThatASingletonComponentIntheCoreRealmWhenLookedUpInComponentRealmsYieldsTheSameInstance() throws Exception { } public void testMultiRealmLookupMap() throws Exception { Map plugin0Map = getContainer().lookupMap( PLUGIN_0_ROLE ); assertNotNull("plugin0Map is null", plugin0Map ); assertNotNull("plugin0Map does not contain a DefaultPlugin0", plugin0Map.get( PLEXUS_DEFAULT_HINT)); assertNotNull("plugin0Map does not contain a AltPlugin0", plugin0Map.get( "alt")); assertEquals("Expected only 2 components in plugin0Map", 2, plugin0Map.size()); Map plugin1Map = getContainer().lookupMap( PLUGIN_1_ROLE ); assertNotNull("plugin1Map is null", plugin1Map); assertNotNull("plugin1Map does not contain a DefaultPlugin1", plugin1Map.get( PLEXUS_DEFAULT_HINT)); assertNotNull("plugin1Map does not contain a AltPlugin1", plugin1Map.get( "alt")); assertEquals("Expected only 2 components in plugin1Map", 2, plugin1Map.size()); } public void testMultiRealmLookupList() throws Exception { List plugin0List = getContainer().lookupList( PLUGIN_0_ROLE ); assertNotNull("plugin0List is null", plugin0List ); Map plugin0Map = mapByClassSimpleName( plugin0List ); assertNotNull("plugin0List does not contain a DefaultPlugin0", plugin0Map.get( "DefaultPlugin0")); assertNotNull("plugin0List does not contain a AltPlugin0", plugin0Map.get( "AltPlugin0")); assertEquals("Expected only 2 components in plugin0Map", 2, plugin0Map.size()); List plugin1List = getContainer().lookupList( PLUGIN_1_ROLE ); assertNotNull("plugin1List is null", plugin1List ); Map plugin1Map = mapByClassSimpleName( plugin1List ); assertNotNull("plugin1List does not contain a DefaultPlugin1", plugin1Map.get( "DefaultPlugin1")); assertNotNull("plugin1List does not contain a AltPlugin1", plugin1Map.get( "AltPlugin1")); assertEquals("Expected only 2 components in plugin0Map", 2, plugin1Map.size()); } private ClassRealm createClassRealm(String id, String... jars) throws Exception { // create the realm ClassRealm classRealm = getContainer().createChildRealm( id ); // populate the realm for ( String jar : jars ) { File file = new File(jar); assertTrue( jar + " is not a file", file.isFile() ); URL url = file.toURI().toURL(); classRealm.addURL( url ); } // descover all component definitions in the realm and register them with the repository getContainer().discoverComponents( classRealm ); return classRealm; } private Map mapByClassSimpleName(List objects) { Map map = new TreeMap(); for ( Object object : objects ) { map.put(object.getClass().getSimpleName(), object); } return map; } } ComponentWithSeveralFieldsOfTheSameType.java000066400000000000000000000020731166327066700457620ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Trygve Laugstøl * @version $Id: ComponentWithSeveralFieldsOfTheSameType.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public class ComponentWithSeveralFieldsOfTheSameType { private ComponentE one; private ComponentE two; public ComponentE getOne() { return one; } public ComponentE getTwo() { return two; } } DefaultComponent.java000066400000000000000000000015151166327066700413640ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: DefaultComponent.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultComponent extends AbstractComponent { } DefaultComponentA.java000066400000000000000000000020671166327066700414700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: DefaultComponentA.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultComponentA implements ComponentA { private ComponentB componentB; private String host; private String port; // Just so we can retrieve the value of componentB for testing. */ public ComponentB getComponentB() { return componentB; } } DefaultComponentB.java000066400000000000000000000021421166327066700414630ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * * @version $Id: DefaultComponentB.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultComponentB implements ComponentB { private ComponentC componentC; public ComponentC getComponentC() { return componentC; } public void setComponentC( ComponentC componentC ) { System.out.println( "Setting componentC:" + componentC ); this.componentC = componentC; } } DefaultComponentC.java000066400000000000000000000015121166327066700414640ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: DefaultComponentC.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultComponentC implements ComponentC { } DefaultComponentComposerManagerTest.java000066400000000000000000000026511166327066700452310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusTestCase; /** * @author Michal Maczka * @version $Id: DefaultComponentComposerManagerTest.java 7828 2008-11-14 22:07:56Z dain $ */ public class DefaultComponentComposerManagerTest extends PlexusTestCase { protected String getCustomConfigurationName() { return "org/codehaus/plexus/component/composition/components.xml"; } public void testComposition() throws Exception { ComponentA componentA = lookup( ComponentA.class ); assertNotNull( componentA ); ComponentB componentB = componentA.getComponentB(); assertNotNull( componentB ); ComponentC componentC = componentB.getComponentC(); assertNotNull( componentC ); } } DefaultCompositionResolverTest.java000066400000000000000000000017561166327066700443160ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/compositionpackage org.codehaus.plexus.component.composition; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: DefaultCompositionResolverTest.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultCompositionResolverTest extends AbstractCompositionResolverTest { protected CompositionResolver getCompositionResolver() { return new DefaultCompositionResolver(); } } 000077500000000000000000000000001166327066700354075ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorAbstractComponent.java000066400000000000000000000026641166327066700417100ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * * * @author Jason van Zyl * * @version $Id: AbstractComponent.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class AbstractComponent implements Component { private String name; public String getName() { return name; } } AbstractComponentConfiguratorTest.java000066400000000000000000001003231166327066700451220ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.io.StringReader; import java.lang.annotation.ElementType; import java.net.URI; import java.net.URL; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.Vector; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.component.configurator.expression.TypeAwareExpressionEvaluator; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.io.PlexusTools; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; /** * @author Michal Maczka * @version $Id: AbstractComponentConfiguratorTest.java 8622 2010-01-30 18:56:56Z bentmann $ */ public abstract class AbstractComponentConfiguratorTest extends PlexusTestCase { protected void configureComponent(Object component, ComponentDescriptor descriptor, ClassRealm realm) throws Exception { ComponentConfigurator cc = getComponentConfigurator(); cc.configureComponent( component, descriptor.getConfiguration(), realm ); } protected void configureComponent(Object component, ComponentDescriptor descriptor, ClassRealm realm, ExpressionEvaluator expressionEvaluator) throws Exception { ComponentConfigurator cc = getComponentConfigurator(); cc.configureComponent( component, descriptor.getConfiguration(), expressionEvaluator, realm ); } protected abstract ComponentConfigurator getComponentConfigurator() throws Exception; public void testComponentConfigurator() throws Exception { String xml = "" + " true" + " 64" + " -128" + " -1" + " 1" + " 2" + " 3" + " X" + " foo" + " test.txt" + " http://www.apache.org/" + " http://maven.apache.org/" + " " + " jason" + " tess" + " " + " " + " jason" + " " + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ConfigurableComponent component = new ConfigurableComponent(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration(configuration); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent(component, descriptor, realm); assertEquals( "check boolean value", true, component.getBooleanValue() ); assertEquals( "check byte value", 64, component.getByteValue() ); assertEquals( "check short value", -128, component.getShortValue() ); assertEquals( "check integer value", -1, component.getIntValue() ); assertEquals( "check float value", 1.0f, component.getFloatValue(), 0.001f ); assertEquals( "check long value", 2L, component.getLongValue() ); assertEquals( "check double value", 3.0, component.getDoubleValue(), 0.001 ); assertEquals( 'X', component.getCharValue() ); assertEquals( "foo", component.getStringValue() ); assertEquals( new File( "test.txt" ), component.getFileValue() ); assertEquals( new URI( "http://www.apache.org/" ), component.getUriValue() ); assertEquals( new URL( "http://maven.apache.org/" ), component.getUrlValue() ); List list = component.getImportantThings(); assertEquals( 2, list.size() ); assertEquals( "jason", ( (ImportantThing) list.get( 0 ) ).getName() ); assertEquals( "tess", ( (ImportantThing) list.get( 1 ) ).getName() ); // Embedded Configuration PlexusConfiguration c = component.getConfiguration(); assertEquals( "jason", c.getChild( "name" ).getValue() ); } public void testComponentConfiguratorWithAComponentThatProvidesSettersForConfiguration() throws Exception { String xml = "" + " 0" + " 1" + " 2" + " 3" + " foo" + " " + " jason" + " tess" + " " + " " + " jason" + " " + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithSetters component = new ComponentWithSetters(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration(configuration); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent(component, descriptor, realm); assertEquals( "check integer value", 0, component.getIntValue() ); assertTrue( component.intValueSet ); assertEquals( "check float value", 1.0f, component.getFloatValue(), 0.001f ); assertTrue( component.floatValueSet ); assertEquals( "check long value", 2L, component.getLongValue() ); assertTrue( component.longValueSet ); assertEquals( "check double value", 3.0, component.getDoubleValue(), 0.001 ); assertTrue( component.doubleValueSet ); assertEquals( "foo", component.getStringValue() ); assertTrue( component.stringValueSet ); List list = component.getImportantThings(); assertEquals( 2, list.size() ); assertEquals( "jason", ( (ImportantThing) list.get( 0 ) ).getName() ); assertEquals( "tess", ( (ImportantThing) list.get( 1 ) ).getName() ); assertTrue( component.importantThingsValueSet ); // Embedded Configuration PlexusConfiguration c = component.getConfiguration(); assertEquals( "jason", c.getChild( "name" ).getValue() ); assertTrue( component.configurationValueSet ); } public void testComponentConfigurationWhereFieldsToConfigureResideInTheSuperclass() throws Exception { String xml = "" + " jason" + "
bollywood
" + "
"; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); DefaultComponent component = new DefaultComponent(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration(configuration); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent(component, descriptor, realm); assertEquals( "jason", component.getName() ); assertEquals( "bollywood", component.getAddress() ); } public void testComponentConfigurationWhereFieldsAreCollections() throws Exception { String xml = "" + " " + " " + " life" + " " + " " + " " + " " + " life" + " " + " " + " " + " " + " life" + " " + " " + " " + " abc" + " def" + " " + " abc" + " abc" + // TODO: implement List etc.. // "" + // " 12" + // " 34" + // "" + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithCollectionFields component = new ComponentWithCollectionFields(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration(configuration); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent(component, descriptor, realm); Vector vector = component.getVector(); assertEquals( "life", ( (ImportantThing) vector.get( 0 ) ).getName() ); assertEquals( 1, vector.size() ); Set set = component.getHashSet(); assertEquals( 1, set.size() ); Object[] setContents = set.toArray(); assertEquals( "life", ( (ImportantThing) setContents[0] ).getName() ); List list = component.getList(); assertEquals( list.getClass(), LinkedList.class ); assertEquals( "life", ( (ImportantThing) list.get( 0 ) ).getName() ); assertEquals( 1, list.size() ); List stringList = component.getStringList(); assertEquals( "abc", (String) stringList.get( 0 ) ); assertEquals( "def", (String) stringList.get( 1 ) ); assertEquals( 2, stringList.size() ); set = component.getSet(); assertEquals( 1, set.size() ); set = component.getSortedSet(); assertEquals( 1, set.size() ); } public void testComponentConfigurationWhereFieldsAreArrays() throws Exception { String xml = "" + " " + " value1" + " value2" + " " + " " + " 42" + " 69" + " " + " " + " Hello" + " World!" + " " + " " + " some string" + " something important" + " 303" + " " + " " + " http://foo.com/bar" + " file://localhost/c:/windows" + " " + " " + " c:/windows" + " /usr/local/bin/foo.sh" + " " + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithArrayFields component = new ComponentWithArrayFields(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration(configuration); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent(component, descriptor, realm); String[] stringArray = component.getStringArray(); assertEquals( 2, stringArray.length ); assertEquals( "value1", stringArray[0] ); assertEquals( "value2", stringArray[1] ); Integer[] integerArray = component.getIntegerArray(); assertEquals( 2, integerArray.length ); assertEquals( new Integer( 42 ), integerArray[0] ); assertEquals( new Integer( 69 ), integerArray[1] ); ImportantThing[] importantThingArray = component.getImportantThingArray(); assertEquals( 2, importantThingArray.length ); assertEquals( "Hello", importantThingArray[0].getName() ); assertEquals( "World!", importantThingArray[1].getName() ); Object[] objectArray = component.getObjectArray(); assertEquals( 3, objectArray.length ); assertEquals( "some string", objectArray[0] ); assertEquals( "something important", ( (ImportantThing) objectArray[1] ).getName() ); assertEquals( new Integer( 303 ), objectArray[2] ); URL[] urls = component.getUrlArray(); assertEquals( new URL( "http://foo.com/bar" ), urls[0] ); assertEquals( new URL( "file://localhost/c:/windows" ), urls[1] ); File[] files = component.getFileArray(); assertEquals( new File( "c:/windows" ), files[0] ); assertEquals( new File( "/usr/local/bin/foo.sh" ), files[1] ); } public void testComponentConfigurationWithCompositeFields() throws Exception { String xml = "" + " " + " I am not abstract!" + " " + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithCompositeFields component = new ComponentWithCompositeFields(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration(configuration); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent(component, descriptor, realm); assertNotNull( component.getThing() ); assertEquals( "I am not abstract!", component.getThing().getName() ); } public void testInvalidComponentConfiguration() throws Exception { String xml = "theName"; try { PlexusTools.buildConfiguration( "", new StringReader( xml ) ); fail( "Should have caused an error because of the invalid XML." ); } catch ( PlexusConfigurationException e ) { // Error should be caught here. } catch ( Exception e ) { fail( "Should have caught the invalid plexus configuration exception." ); } } public void testComponentConfigurationWithPropertiesFields() throws Exception { String xml = "" + " " + " " + " firstname" + " michal" + " " + " " + " lastname" + " maczka" + " " + " " + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithPropertiesField component = new ComponentWithPropertiesField(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration(configuration); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent(component, descriptor, realm); Properties properties = component.getSomeProperties(); assertNotNull( properties ); assertEquals( "michal", properties.get( "firstname" ) ); assertEquals( "maczka", properties.get( "lastname" ) ); } public void testComponentConfigurationWithPropertiesFieldsWithExpression() throws Exception { String xml = "" + " ${injectedProperties} " + ""; final Properties propertiesInterpolated = new Properties(); propertiesInterpolated.put( "firstname", "olivier" ); propertiesInterpolated.put( "lastname", "lamy" ); ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator() { public Object evaluate( String expression ) { return propertiesInterpolated; } public File alignToBaseDirectory( File file ) { return null; } }; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithPropertiesField component = new ComponentWithPropertiesField(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration(configuration); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent(component, descriptor, realm, expressionEvaluator); Properties properties = component.getSomeProperties(); assertNotNull( properties ); assertEquals( "olivier", properties.get( "firstname" ) ); assertEquals( "lamy", properties.get( "lastname" ) ); } public void testComponentConfigurationWithPropertiesFieldsWithExpressions() throws Exception { String xml = "" + "" // + "${theName}${theValue}" // + "empty" // + "" + ""; final Properties values = new Properties(); values.put( "${theName}", "test" ); values.put( "${theValue}", "PASSED" ); ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator() { public Object evaluate( String expression ) { return values.containsKey( expression ) ? values.get( expression ) : expression; } public File alignToBaseDirectory( File file ) { return null; } }; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithPropertiesField component = new ComponentWithPropertiesField(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration( configuration ); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent( component, descriptor, realm, expressionEvaluator ); Properties properties = component.getSomeProperties(); assertNotNull( properties ); assertEquals( "PASSED", properties.get( "test" ) ); assertEquals( "", properties.get( "empty" ) ); } public void testComponentConfigurationWithMapField() throws Exception { String xml = "" + " " + " Kenney" + " Westerhof" + " " + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithMapField component = new ComponentWithMapField(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration(configuration); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent(component, descriptor, realm); Map map = component.getMap(); assertNotNull( map ); assertEquals( "Kenney", map.get( "firstName" ) ); assertEquals( "Westerhof", map.get( "lastName" ) ); } public void testComponentConfigurationWhereFieldIsBadArray() throws Exception { String xml = "" // + " string" // + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithArrayFields component = new ComponentWithArrayFields(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration( configuration ); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); try { configureComponent( component, descriptor, realm ); fail( "Configuration did not fail" ); } catch ( ComponentConfigurationException e ) { // expected e.printStackTrace(); } } public void testComponentConfigurationWhereFieldIsEnum() throws Exception { String xml = "" // + " TYPE" // + " ONE" // + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithEnumFields component = new ComponentWithEnumFields(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration( configuration ); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent( component, descriptor, realm ); assertEquals( ElementType.TYPE, component.getSimpleEnum() ); assertEquals( ComponentWithEnumFields.NestedEnum.ONE, component.getNestedEnum() ); } public void testComponentConfigurationWithAmbiguousExpressionValue() throws Exception { String xml = "" // + "
${address}
" // + "
"; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); DefaultComponent component = new DefaultComponent(); ExpressionEvaluator expressionEvaluator = new TypeAwareExpressionEvaluator() { public Object evaluate( String expression ) throws ExpressionEvaluationException { return evaluate( expression, null ); } public File alignToBaseDirectory( File file ) { return null; } public Object evaluate( String expression, Class type ) throws ExpressionEvaluationException { if ( String.class == type ) { return "PASSED"; } else { return Boolean.FALSE; } } }; ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration( configuration ); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent( component, descriptor, realm, expressionEvaluator ); assertEquals( "PASSED", component.getAddress() ); } public void testComponentConfigurationWithPrimitiveValueConversion() throws Exception { String xml = "" // + " ${primitive}" // + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ConfigurableComponent component = new ConfigurableComponent(); ExpressionEvaluator expressionEvaluator = new TypeAwareExpressionEvaluator() { public Object evaluate( String expression ) throws ExpressionEvaluationException { return evaluate( expression, null ); } public File alignToBaseDirectory( File file ) { return null; } public Object evaluate( String expression, Class type ) throws ExpressionEvaluationException { // java.lang.Short -> short -> int return new Short( (short) 23 ); } }; ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration( configuration ); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent( component, descriptor, realm, expressionEvaluator ); assertEquals( 23, component.getIntValue() ); } public void testComponentConfigurationWithEmptyContentForBasicField() throws Exception { String xml = "" // + "
" // + "
"; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); DefaultComponent component = new DefaultComponent(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration( configuration ); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent( component, descriptor, realm ); assertEquals( null, component.getAddress() ); } public void testComponentConfigurationWithEmptyContentForCompositeField() throws Exception { String xml = "" // + " " // + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithCompositeFields component = new ComponentWithCompositeFields(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration( configuration ); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent( component, descriptor, realm ); assertNotNull( component.getBean() ); } public void testComponentConfigurationWithUnresolvedExpressionContentForCompositeFieldOfNonInstantiatableType() throws Exception { String xml = "" // + " ${null-valued-expression}" // + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithCompositeFields component = new ComponentWithCompositeFields(); ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator() { public Object evaluate( String expression ) throws ExpressionEvaluationException { return null; } public File alignToBaseDirectory( File file ) { return null; } }; ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration( configuration ); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent( component, descriptor, realm, expressionEvaluator ); assertEquals( null, component.getThing() ); } public void testComponentConfiguratorFileNormalizesSeparator() throws Exception { String xml = "" + " dir/test.txt" + " dir\\test.txt" + ""; PlexusConfiguration configuration = PlexusTools.buildConfiguration( "", new StringReader( xml ) ); ComponentWithArrayFields component = new ComponentWithArrayFields(); ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setRole( "role" ); descriptor.setImplementation( component.getClass().getName() ); descriptor.setConfiguration(configuration); ClassWorld classWorld = new ClassWorld(); ClassRealm realm = classWorld.newRealm( "test", getClass().getClassLoader() ); configureComponent(component, descriptor, realm); assertEquals( new File( "dir", "test.txt" ), component.getFileArray()[0] ); assertEquals( new File( "dir", "test.txt" ), component.getFileArray()[1] ); } } AbstractThing.java000066400000000000000000000023231166327066700410070ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public abstract class AbstractThing { } BasicComponentConfiguratorTest.java000066400000000000000000000026371166327066700444110ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class BasicComponentConfiguratorTest extends AbstractComponentConfiguratorTest { protected ComponentConfigurator getComponentConfigurator() throws Exception { return new BasicComponentConfigurator(); } } Component.java000066400000000000000000000024701166327066700402170ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * * * @author Jason van Zyl * * @version $Id: Component.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Component { } ComponentWithArrayFields.java000066400000000000000000000043471166327066700432060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.net.URL; /** * @author Kenney Westerhof * @version $Id: ComponentWithArrayFields.java 5127 2006-12-12 03:49:50Z jvanzyl $ */ public class ComponentWithArrayFields { private String[] stringArray; private Integer[] integerArray; private ImportantThing[] importantThingArray; private Object[] objectArray; private AbstractThing[] abstractArray; private URL[] urlArray; private File[] fileArray; public String [] getStringArray() { return stringArray; } public Integer [] getIntegerArray() { return integerArray; } public ImportantThing [] getImportantThingArray() { return importantThingArray; } public Object [] getObjectArray() { return objectArray; } public AbstractThing [] getAbstractThingArray() { return abstractArray; } public URL[] getUrlArray() { return urlArray; } public File[] getFileArray() { return fileArray; } } ComponentWithCollectionFields.java000066400000000000000000000040571166327066700442210ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.SortedSet; import java.util.Vector; /** * @author Michal Maczka * @version $Id: ComponentWithCollectionFields.java 8004 2009-01-04 18:39:40Z bentmann $ */ public class ComponentWithCollectionFields { private Vector vector; private HashSet hashSet; private List list; private List stringList; private Set set; private SortedSet sortedSet; public Vector getVector() { return vector; } public HashSet getHashSet() { return hashSet; } public List getList() { return list; } public List getStringList() { return stringList; } public Set getSet() { return set; } public SortedSet getSortedSet() { return sortedSet; } } ComponentWithCompositeFields.java000066400000000000000000000031321166327066700440610ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * * @author Michal Maczka * * @version $Id: ComponentWithCompositeFields.java 8512 2009-10-21 23:15:04Z bentmann $ */ public class ComponentWithCompositeFields { private ThingInterface thing; private DefaultComponent bean; public ThingInterface getThing() { return thing; } public DefaultComponent getBean() { return bean; } } ComponentWithEnumFields.java000066400000000000000000000031141166327066700430230ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.lang.annotation.ElementType; /** * @author Benjamin Bentmann */ public class ComponentWithEnumFields { public enum NestedEnum { ONE, TWO, THREE, } private NestedEnum nestedEnum; private ElementType simpleEnum; public NestedEnum getNestedEnum() { return nestedEnum; } public ElementType getSimpleEnum() { return simpleEnum; } } ComponentWithMapField.java000066400000000000000000000027311166327066700424550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Map; /** * * @author Michal Maczka * * @version $Id: ComponentWithMapField.java 5127 2006-12-12 03:49:50Z jvanzyl $ */ public class ComponentWithMapField { private Map map; public Map getMap() { return map; } } ComponentWithPropertiesField.java000066400000000000000000000030351166327066700440720ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Properties; /** * * @author Michal Maczka * * @version $Id: ComponentWithPropertiesField.java 5127 2006-12-12 03:49:50Z jvanzyl $ */ public class ComponentWithPropertiesField { private Properties someProperties; public Properties getSomeProperties() { return someProperties; } } ComponentWithSetters.java000066400000000000000000000073021166327066700424240ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.configuration.PlexusConfiguration; import java.util.List; /** * * * @author Jason van Zyl * * @version $Id: ComponentWithSetters.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentWithSetters { private int intValueVariable; private float floatValueVariable; private long longValueVariable; private double doubleValueVariable; private String stringValueVariable; private List importantThingsVariable; private PlexusConfiguration configurationVariable; public int getIntValue() { return intValueVariable; } public float getFloatValue() { return floatValueVariable; } public long getLongValue() { return longValueVariable; } public double getDoubleValue() { return doubleValueVariable; } public String getStringValue() { return stringValueVariable; } public List getImportantThings() { return importantThingsVariable; } public PlexusConfiguration getConfiguration() { return configurationVariable; } // ---------------------------------------------------------------------- // setters // ---------------------------------------------------------------------- boolean intValueSet; boolean floatValueSet; boolean longValueSet; boolean doubleValueSet; boolean stringValueSet; boolean importantThingsValueSet; boolean configurationValueSet; public void setIntValue( int intValue ) { this.intValueVariable = intValue; intValueSet = true; } public void setFloatValue( float floatValue ) { this.floatValueVariable = floatValue; floatValueSet = true; } public void setLongValue( long longValue ) { this.longValueVariable = longValue; longValueSet = true; } public void setDoubleValue( double doubleValue ) { this.doubleValueVariable = doubleValue; doubleValueSet = true; } public void setStringValue( String stringValue ) { this.stringValueVariable = stringValue; stringValueSet = true; } public void setImportantThings( List importantThings ) { this.importantThingsVariable = importantThings; importantThingsValueSet = true; } public void setConfiguration( PlexusConfiguration configuration ) { this.configurationVariable = configuration; configurationValueSet = true; } } ConfigurableComponent.java000066400000000000000000000056261166327066700425460ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.configuration.PlexusConfiguration; import java.io.File; import java.net.URI; import java.net.URL; import java.util.List; /** * * * @author Jason van Zyl * * @version $Id: ConfigurableComponent.java 7783 2008-10-13 21:56:51Z bentmann $ */ public class ConfigurableComponent { private boolean booleanValue; private byte byteValue; private short shortValue; private int intValue; private float floatValue; private long longValue; private double doubleValue; private char charValue; private String stringValue; private File fileValue; private URI uriValue; private URL urlValue; private List importantThings; private PlexusConfiguration configuration; public boolean getBooleanValue() { return booleanValue; } public int getByteValue() { return byteValue; } public int getShortValue() { return shortValue; } public int getIntValue() { return intValue; } public float getFloatValue() { return floatValue; } public long getLongValue() { return longValue; } public double getDoubleValue() { return doubleValue; } public char getCharValue() { return charValue; } public String getStringValue() { return stringValue; } public File getFileValue() { return fileValue; } public URI getUriValue() { return uriValue; } public URL getUrlValue() { return urlValue; } public List getImportantThings() { return importantThings; } public PlexusConfiguration getConfiguration() { return configuration; } } DefaultComponent.java000066400000000000000000000027001166327066700415200ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * * * @author Jason van Zyl * * @version $Id: DefaultComponent.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultComponent extends AbstractComponent { private String address; public String getAddress() { return address; } } ImportantThing.java000066400000000000000000000027061166327066700412260ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * * * @author Jason van Zyl * * @version $Id: ImportantThing.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ImportantThing extends AbstractThing implements ThingInterface { private String name; public String getName() { return name; } } ThingInterface.java000066400000000000000000000023451166327066700411500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public interface ThingInterface { String getName(); } XBeanComponentConfiguratorTest.java000066400000000000000000000064171166327066700443650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/configuratorpackage org.codehaus.plexus.component.configurator; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.builder.XBeanComponentBuilder; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.apache.xbean.recipe.ConstructionException; import org.apache.xbean.recipe.ObjectRecipe; import org.apache.xbean.recipe.ExecutionContext; import org.apache.xbean.recipe.DefaultExecutionContext; public class XBeanComponentConfiguratorTest extends AbstractComponentConfiguratorTest { @Override protected void configureComponent(Object component, ComponentDescriptor descriptor, ClassRealm realm) throws Exception { XBeanComponentBuilder componentBuilder = new XBeanComponentBuilder(); ObjectRecipe recipe = componentBuilder.createObjectRecipe( component, descriptor, realm); // need a caller context ExecutionContext executionContext = new DefaultExecutionContext(); executionContext.push(new ObjectRecipe(component.getClass())); // call the recipie setProperties directly, but setup the thead state first ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(realm); ExecutionContext.setContext(executionContext); try { recipe.setProperties( component ); } catch ( ConstructionException e ) { throw new ComponentConfigurationException( "Failed to configure component", e ); } finally { ExecutionContext.setContext(null); Thread.currentThread().setContextClassLoader(oldClassLoader); } } protected void configureComponent(Object component, ComponentDescriptor descriptor, ClassRealm realm, ExpressionEvaluator expressionEvaluator) throws Exception { this.configureComponent(component, descriptor, realm); } public void testComponentConfigurationWithPropertiesFieldsWithExpression() throws Exception { // expression evalator is not supported since it is not used by normal AutoConfigurePhase } public void testComponentConfigurationWithPropertiesFieldsWithExpressions() throws Exception { // expression evalator is not supported since it is not used by normal AutoConfigurePhase } public void testComponentConfigurationWithAmbiguousExpressionValue() throws Exception { // expression evalator is not supported since it is not used by normal AutoConfigurePhase } public void testComponentConfigurationWithPrimitiveValueConversion() throws Exception { // expression evalator is not supported since it is not used by normal AutoConfigurePhase } public void testComponentConfigurationWithUnresolvedExpressionContentForCompositeFieldOfNonInstantiatableType() throws Exception { // expression evalator is not supported since it is not used by normal AutoConfigurePhase } protected ComponentConfigurator getComponentConfigurator() throws Exception { // this should never be called because the configureComponent is overridden throw new UnsupportedOperationException(); } } 000077500000000000000000000000001166327066700347145ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/discoveryComponentDiscovererTest.java000066400000000000000000000056131166327066700424140ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.context.DefaultContext; import java.io.File; import java.util.List; import java.util.Map; import java.util.TreeMap; /** * @author Jason van Zyl * * @version $Id: ComponentDiscovererTest.java 8155 2009-04-26 01:22:53Z jvanzyl $ */ public class ComponentDiscovererTest extends PlexusTestCase { public void testDefaultComponentDiscoverer() throws Exception { ComponentDiscoverer componentDiscoverer = new DefaultComponentDiscoverer(); ClassWorld classWorld = new ClassWorld(); ClassRealm core = classWorld.newRealm( "core" ); File testClasses = new File( getBasedir(), "target/test-classes" ); core.addURL( testClasses.toURL() ); File classes = new File( getBasedir(), "target/classes" ); core.addURL( classes.toURL() ); List componentSetDescriptors = componentDiscoverer.findComponents( new DefaultContext(), core ); ComponentDescriptor componentDescriptor = byImplementation(componentSetDescriptors).get( "org.codehaus.plexus.component.discovery.DefaultDiscoveredComponent" ); assertNotNull("componentDescriptor is null", componentDescriptor ); assertEquals( "org.codehaus.plexus.component.discovery.DiscoveredComponent", componentDescriptor.getRole() ); assertEquals( "org.codehaus.plexus.component.discovery.DefaultDiscoveredComponent", componentDescriptor.getImplementation() ); } private static Map> byImplementation(List descriptorSets) { TreeMap> index = new TreeMap>(); for ( ComponentSetDescriptor descriptorSet : descriptorSets ) { for ( ComponentDescriptor descriptor : descriptorSet.getComponents() ) { index.put(descriptor.getImplementation(), descriptor); } } return index; } } DefaultDiscoveredComponent.java000066400000000000000000000015441166327066700430420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: DefaultDiscoveredComponent.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultDiscoveredComponent implements DiscoveredComponent { } DiscoveredComponent.java000066400000000000000000000015561166327066700415400ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/discoverypackage org.codehaus.plexus.component.discovery; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: DiscoveredComponent.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface DiscoveredComponent { String ROLE = DiscoveredComponent.class.getName(); } 000077500000000000000000000000001166327066700343545ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factoryComponent.java000066400000000000000000000014721166327066700371650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Michal Maczka * @version $Id: Component.java 4778 2006-11-23 03:54:18Z jvanzyl $ */ public interface Component { } ComponentImplA.java000066400000000000000000000014731166327066700401110ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ComponentImplA.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ComponentImplA implements Component { } ComponentImplB.java000066400000000000000000000015101166327066700401020ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Michal Maczka * @version $Id: ComponentImplB.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public class ComponentImplB { } ComponentImplC.java000066400000000000000000000015211166327066700401050ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Michal Maczka * @version $Id: ComponentImplC.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public abstract class ComponentImplC { } DiscoveredComponentFactoryTest.java000066400000000000000000000043131166327066700433620ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.component.repository.ComponentDescriptor; public class DiscoveredComponentFactoryTest extends PlexusTestCase { public void testShouldFindComponentFactoriesDefinedInBothPlexusXmlAndComponentsXml() throws Exception { assertNotNull( "Cannot find test component factory from plexus.xml test resource.", lookup( ComponentFactory.class, "testFactory1" ) ); assertNotNull( "Cannot find test component factory from components.xml test resource.", lookup( ComponentFactory.class, "testFactory2" ) ); } public void testShouldInstantiateComponentUsingFactoryDiscoveredInPlexusXml() throws Exception { } public void testShouldInstantiateComponentUsingFactoryDiscoveredInComponentsXml() throws Exception { lookupTestComponent( "testFactory2" ); } private void lookupTestComponent( String factoryId ) throws Exception { ComponentDescriptor descriptor = new ComponentDescriptor(); descriptor.setComponentFactory( factoryId ); descriptor.setRole( "role" ); descriptor.setRoleHint( "hint" ); descriptor.setImplementation( "something interesting" ); getContainer().addComponentDescriptor( descriptor ); Object component = lookup( "role", "hint" ); assertTrue( component instanceof TestFactoryResultComponent ); assertEquals( factoryId, ( (TestFactoryResultComponent) component ).getFactoryId() ); } } TestComponentFactory1.java000066400000000000000000000022731166327066700414360ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDescriptor; public class TestComponentFactory1 implements ComponentFactory { public String getId() { return "testFactory1"; } public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container ) throws ComponentInstantiationException { return new TestFactoryResultComponent(getId()); } } TestComponentFactory2.java000066400000000000000000000022731166327066700414370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDescriptor; public class TestComponentFactory2 implements ComponentFactory { public String getId() { return "testFactory2"; } public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container ) throws ComponentInstantiationException { return new TestFactoryResultComponent(getId()); } } TestFactoryResultComponent.java000066400000000000000000000016301166327066700425500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factorypackage org.codehaus.plexus.component.factory; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class TestFactoryResultComponent { private final String factoryId; public TestFactoryResultComponent( String factoryId ) { this.factoryId = factoryId; } public String getFactoryId() { return factoryId; } } 000077500000000000000000000000001166327066700352755ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factory/javaJavaComponentFactoryTest.java000066400000000000000000000103021166327066700430700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factory/javapackage org.codehaus.plexus.component.factory.java; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.DefaultContainerConfiguration; import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.component.factory.Component; import org.codehaus.plexus.component.factory.ComponentImplA; import org.codehaus.plexus.component.factory.ComponentImplB; import org.codehaus.plexus.component.factory.ComponentImplC; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.ComponentDescriptor; /** * @author Jason van Zyl * @author Michal Maczka * @version $Id: JavaComponentFactoryTest.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class JavaComponentFactoryTest extends TestCase { public void testComponentCreation() throws Exception { JavaComponentFactory factory = new JavaComponentFactory(); ComponentDescriptor componentDescriptor = new ComponentDescriptor(); componentDescriptor.setRole( Component.class.getName() ); componentDescriptor.setImplementation( ComponentImplA.class.getName() ); ClassWorld classWorld = new ClassWorld(); classWorld.newRealm( "core", Thread.currentThread().getContextClassLoader() ); PlexusContainer container = new DefaultPlexusContainer( containerConfiguration( classWorld )); Object component = factory.newInstance( componentDescriptor, classWorld.getRealm( "core" ), container ); assertNotNull( component ); } public void testComponentCreationWithNotMatchingRoleAndImplemenation() throws Exception { JavaComponentFactory factory = new JavaComponentFactory(); ComponentDescriptor componentDescriptor = new ComponentDescriptor(); componentDescriptor.setRole( Component.class.getName() ); componentDescriptor.setImplementation( ComponentImplB.class.getName() ); ClassWorld classWorld = new ClassWorld(); classWorld.newRealm( "core", Thread.currentThread().getContextClassLoader() ); PlexusContainer container = new DefaultPlexusContainer( containerConfiguration( classWorld )); factory.newInstance( componentDescriptor, classWorld.getRealm( "core" ), container ); } public void testInstanciationOfAAbstractComponent() throws Exception { JavaComponentFactory factory = new JavaComponentFactory(); ComponentDescriptor componentDescriptor = new ComponentDescriptor(); componentDescriptor.setRole( Component.class.getName() ); componentDescriptor.setImplementation( ComponentImplC.class.getName() ); ClassWorld classWorld = new ClassWorld(); classWorld.newRealm( "core", Thread.currentThread().getContextClassLoader() ); PlexusContainer container = new DefaultPlexusContainer( containerConfiguration( classWorld ) ); try { factory.newInstance( componentDescriptor, classWorld.getRealm( "core" ), container ); fail( "Expected ComponentInstantiationException when instanciating a abstract class." ); } catch( ComponentInstantiationException ex ) { assertTrue( true ); } } private ContainerConfiguration containerConfiguration( ClassWorld classWorld ) { ContainerConfiguration c = new DefaultContainerConfiguration() .setClassWorld( classWorld ); return c; } } 000077500000000000000000000000001166327066700360105ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factory/nonjavaNonJavaComponentFactory.java000066400000000000000000000014471166327066700434300ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factory/nonjavapackage org.codehaus.plexus.component.factory.nonjava; import org.codehaus.plexus.component.factory.ComponentFactory; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.PlexusContainer; /** @author Jason van Zyl */ public class NonJavaComponentFactory implements ComponentFactory { public String getId() { return "nonjava"; } public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container ) throws ComponentInstantiationException { return "component"; } } NonJavaComponentFactoryTest.java000066400000000000000000000007261166327066700442670ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/factory/nonjavapackage org.codehaus.plexus.component.factory.nonjava; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.component.factory.ComponentFactory; /** @author Jason van Zyl */ public class NonJavaComponentFactoryTest extends PlexusTestCase { public void testNonJavaComponentFactory() throws Exception { ComponentFactory factory = lookup( ComponentFactory.class, "nonjava" ); assertNotNull( factory ); } } 000077500000000000000000000000001166327066700343175ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/managerClassicSingletonComponentManagerTest.java000066400000000000000000000012561166327066700444500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; import org.codehaus.plexus.PlexusTestCase; /** * @author Ben Walding * @version $Id: ClassicSingletonComponentManagerTest.java 7828 2008-11-14 22:07:56Z dain $ */ public class ClassicSingletonComponentManagerTest extends PlexusTestCase { public void testSequentialLookupsReturnTheSameInstance() throws Exception { Component a = lookup( Component.class ); Component b = lookup( Component.class ); Component c = lookup( Component.class ); Component d = lookup( Component.class ); assertTrue( a == b ); assertTrue( a == c ); assertTrue( a == d ); } } Component.java000066400000000000000000000002311166327066700371200ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; /** @author Jason van Zyl */ public interface Component { String ROLE = Component.class.getName(); } DefaultComponent.java000066400000000000000000000002101166327066700404220ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; /** @author Jason van Zyl */ public class DefaultComponent implements Component { } SlowComponent.java000066400000000000000000000025611166327066700377750ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; /** * A slow starting component that checks that sleeps during its Start phase. * * Configuration: * delay - number of milliseconds to sleep during start() * @author Ben Walding * @version $Id: SlowComponent.java 5451 2007-01-17 02:36:27Z jvanzyl $ */ public class SlowComponent implements Startable { public static final String ROLE = SlowComponent.class.getName(); /* Number of ms to sleep during start() */ private long delay; public void start() { try { Thread.sleep( delay ); } catch ( InterruptedException e ) { } } public void stop() { } } SlowComponentClassicSingletonComponentManagerTest.java000066400000000000000000000064311166327066700472000ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/managerpackage org.codehaus.plexus.component.manager; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusTestCase; /** * @author Ben Walding * @version $Id: SlowComponentClassicSingletonComponentManagerTest.java 7876 2008-11-23 14:39:51Z bentmann $ */ public class SlowComponentClassicSingletonComponentManagerTest extends PlexusTestCase { public void testThreads1() throws Exception { test( 1 ); } /** * Tests that multiple concurrent threads don't acquire different components. */ public void testThreads1000() throws Exception { test( 1000 ); } private void test( int count ) throws Exception { ComponentLookupThread components[] = new ComponentLookupThread[ count ]; //Create them for ( int i = 0; i < count; i++ ) { components[ i ] = new ComponentLookupThread( getContainer() ); } //Start them for ( int i = 0; i < count; i++ ) { components[i].start(); } //Wait for them to finish for ( int i = 0; i < count; i++ ) { components[i].join( 10000 ); } //Get master component SlowComponent masterComponent = lookup( SlowComponent.class ); //Verify them for ( int i = 0; i < count; i++ ) { assertSame( i + ":" + components[i].getComponent() + " == " + masterComponent, masterComponent, components[i].getComponent() ); } } class ComponentLookupThread extends Thread { final PlexusContainer container; private SlowComponent component; public ComponentLookupThread( PlexusContainer container ) { /* * NOTE: A high priority seems to increase the likelihood of exhibiting missing synchronization. */ setPriority( MAX_PRIORITY ); this.container = container; } public void run() { try { // DefaultPlexusContainer.setLookupRealm( lookupRealm ); SlowComponent tmpComponent = container.lookup( SlowComponent.class ); synchronized ( this ) { this.component = tmpComponent; } } catch ( Exception e ) { container.getLookupRealm().display(); e.printStackTrace(); } } public SlowComponent getComponent() { synchronized ( this ) { return component; } } } } 000077500000000000000000000000001166327066700345555ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/registryDefaultComponentRegistryTest.java000066400000000000000000000035371166327066700432700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/registrypackage org.codehaus.plexus.component.registry; import junit.framework.TestCase; import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; public class DefaultComponentRegistryTest extends TestCase { public void testConcurrentDisposeAndLookup() throws Exception { final PlexusContainer plexus = new DefaultPlexusContainer(); ComponentDescriptor descriptor = new ComponentDescriptor( TestSynchronizedComponent.class, plexus.getContainerRealm() ); descriptor.setRole( TestSynchronizedComponent.class.getCanonicalName() ); descriptor.setImplementation( TestSynchronizedComponent.class.getCanonicalName() ); plexus.addComponentDescriptor( descriptor ); TestSynchronizedComponent component = plexus.lookup( TestSynchronizedComponent.class ); class LookupThread extends Thread { private TestSynchronizedComponent component; @Override public synchronized void run() { try { this.component = plexus.lookup( TestSynchronizedComponent.class ); } catch ( ComponentLookupException e ) { // expected } } public synchronized TestSynchronizedComponent getComponent() { return component; } } LookupThread lookupThread = new LookupThread(); component.setLookupThread( lookupThread ); plexus.dispose(); assertNull( lookupThread.getComponent() ); } } TestSynchronizedComponent.java000066400000000000000000000016111166327066700426210ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/registrypackage org.codehaus.plexus.component.registry; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException; public class TestSynchronizedComponent implements Startable { private Thread lookupThread; public synchronized void start() throws StartingException { } public synchronized void stop() throws StoppingException { lookupThread.start(); try { lookupThread.join(); } catch ( InterruptedException e ) { throw new StoppingException( "Can't stop lookupThread", e ); } } public synchronized void setLookupThread( Thread lookupThread ) { this.lookupThread = lookupThread; } } 000077500000000000000000000000001166327066700351245ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/repositoryComponentDescriptorTest.java000066400000000000000000000062031166327066700426310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; import org.codehaus.plexus.component.repository.io.PlexusTools; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import java.util.List; /** * * * @author Jason van Zyl * * @version $Id: ComponentDescriptorTest.java 8155 2009-04-26 01:22:53Z jvanzyl $ */ public class ComponentDescriptorTest extends TestCase { public void testSimpleComponentResolution() throws Exception { String cc1 = "" + " java.lang.String" + " c1" + " role-hint" + " component-profile" + " " + " " + " c2" + " " + " " + " c3" + " " + " " + ""; ClassWorld classWorld = new ClassWorld( "test", Thread.currentThread().getContextClassLoader() ); ClassRealm realm = classWorld.getRealm( "test" ); ComponentDescriptor c1 = PlexusTools.buildComponentDescriptor( cc1, realm ); assertEquals( "c1", c1.getRole() ); assertEquals( "role-hint", c1.getRoleHint() ); assertEquals( "component-profile", c1.getComponentProfile() ); List requirements = c1.getRequirements(); assertEquals( 2, requirements.size() ); boolean containsC2 = false; boolean containsC3 = false; for ( ComponentRequirement requirement : requirements ) { if ( requirement.getRole().equals( "c2" ) ) { containsC2 = true; } else if ( requirement.getRole().equals( "c3" ) ) { containsC3 = true; } } assertTrue( containsC2 ); assertTrue( containsC3 ); } public void testShouldNotBeEqualWhenRolesAreSameButHintsAreDifferent() { ComponentDescriptor desc = new ComponentDescriptor(); desc.setRole("one"); desc.setRoleHint("one"); ComponentDescriptor desc2 = new ComponentDescriptor(); desc2.setRole("one"); desc2.setRoleHint("two"); assertFalse(desc.equals(desc2)); } } ComponentRequirementTest.java000066400000000000000000000023331166327066700430130ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; /** * @author Michal Maczka * @version $Id: ComponentRequirementTest.java 4779 2006-11-23 04:09:31Z jvanzyl $ */ public class ComponentRequirementTest extends TestCase { public void testComponentRequirement() { ComponentRequirement requirement = new ComponentRequirement(); requirement.setFieldName( "field" ); requirement.setRole( "role" ); assertEquals( "field", requirement.getFieldName() ); assertEquals( "role", requirement.getRole() ); } } ComponentSetTest.java000066400000000000000000000067221166327066700412540ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; import org.codehaus.plexus.component.repository.io.PlexusTools; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import java.util.List; /** * * * @author Jason van Zyl * * @version $Id: ComponentSetTest.java 8155 2009-04-26 01:22:53Z jvanzyl $ */ public class ComponentSetTest extends TestCase { public void testSimpleComponentResolution() throws Exception { String xml = "" + " " + " " + " java.lang.String" + " c1" + " role-hint" + " component-profile" + " " + " " + " c2" + " " + " " + " c3" + " " + " " + " " + " " + " " + " " + " plexus" + " wedgy" + " 1.0" + " " + " " + ""; ClassWorld classWorld = new ClassWorld( "test", Thread.currentThread().getContextClassLoader() ); ClassRealm realm = classWorld.getRealm( "test" ); ComponentSetDescriptor cs = PlexusTools.buildComponentSet( PlexusTools.buildConfiguration( xml ), realm ); ComponentDescriptor c1 = cs.getComponents().get( 0 ); assertEquals( "c1", c1.getRole() ); assertEquals( "role-hint", c1.getRoleHint() ); assertEquals( "component-profile", c1.getComponentProfile() ); List requirements = c1.getRequirements(); assertEquals( 2, requirements.size() ); boolean containsC2 = false; boolean containsC3 = false; for ( ComponentRequirement requirement : requirements ) { if ( requirement.getRole().equals( "c2" ) ) { containsC2 = true; } else if ( requirement.getRole().equals( "c3" ) ) { containsC3 = true; } } assertTrue( containsC2 ); assertTrue( containsC3 ); ComponentDependency d1 = cs.getDependencies().get( 0 ); assertEquals( "plexus", d1.getGroupId() ); assertEquals( "wedgy", d1.getArtifactId() ); assertEquals( "1.0", d1.getVersion() ); } } DefaultComponentRepositoryTest.java000066400000000000000000000020561166327066700442010ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/component/repositorypackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; /** * * * @author Jason van Zyl * * @version $Id: DefaultComponentRepositoryTest.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultComponentRepositoryTest extends TestCase { private static String configuration = "" + ""; public void testDefaultComponentRepository() { } } plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/000077500000000000000000000000001166327066700336315ustar00rootroot00000000000000ConfigurationResourceExceptionTest.java000066400000000000000000000021171166327066700434540ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configurationpackage org.codehaus.plexus.configuration; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; /** * * * @author Jason van Zyl * * @version $Id: ConfigurationResourceExceptionTest.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ConfigurationResourceExceptionTest extends TestCase { public void testException() { PlexusConfigurationResourceException e = new PlexusConfigurationResourceException( "bad doggy!" ); assertEquals( "bad doggy!", e.getMessage() ); } } ConfigurationTestHelper.java000066400000000000000000000053761166327066700412370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configurationpackage org.codehaus.plexus.configuration; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; import org.codehaus.plexus.component.repository.io.PlexusTools; import java.io.StringReader; /** * @author Jason van Zyl * @version $Id: ConfigurationTestHelper.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public abstract class ConfigurationTestHelper extends TestCase { public static PlexusConfiguration getTestConfiguration() throws Exception { return PlexusTools.buildConfiguration( "", new StringReader( ConfigurationTestHelper.getXmlConfiguration() ) ); } public static String getXmlConfiguration() { return "" + "" + "" + "string" + "0" + "not-a-number" + "true" + "false" + "not-a-boolean" + ""; } public static void testConfiguration( PlexusConfiguration c ) throws Exception { // Exercise all value/attribute retrieval methods. // Values // TODO: uncomment once maven can test the latest plexus-utils // assertNull( c.getChild( "singleton" ).getValue( null ) ); // String assertEquals( "string", c.getValue( "string" ) ); assertEquals( "string", c.getChild( "string" ).getValue() ); assertEquals( "string", c.getChild( "ne-string" ).getValue( "string" ) ); assertNull( c.getChild( "not-existing" ).getValue( null ) ); assertEquals( "''", "'" + c.getChild( "empty-element" ).getValue() + "'" ); assertEquals( "", c.getChild( "empty-element" ).getValue( null ) ); // Attributes assertEquals( "string", c.getChild( "string" ).getAttribute( "string" )); assertEquals( "attribute", c.getChild( "singleton" ).getAttribute( "attribute" )); } } DefaultPlexusConfigurationTest.java000066400000000000000000000105021166327066700425700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configurationpackage org.codehaus.plexus.configuration; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; /** * @author Ran Tene * @version $Id: DefaultPlexusConfigurationTest.java 7854 2008-11-18 22:33:53Z bentmann $ */ public final class DefaultPlexusConfigurationTest extends TestCase { private DefaultPlexusConfiguration configuration; public void setUp() { configuration = new DefaultPlexusConfiguration( "a" ); } public void testWithHelper() throws Exception { PlexusConfiguration c = ConfigurationTestHelper.getTestConfiguration(); ConfigurationTestHelper.testConfiguration( c ); } public void testGetValue() throws Exception { String orgValue = "Original String"; configuration.setValue( orgValue ); assertEquals( orgValue, configuration.getValue() ); } public void testGetAttribute() throws Exception { String key = "key"; String value = "original value"; String defaultStr = "default"; configuration.setAttribute( key, value ); assertEquals( value, configuration.getAttribute( key, defaultStr ) ); assertEquals( defaultStr, configuration.getAttribute( "newKey", defaultStr ) ); } public void testGetChild() throws Exception { DefaultPlexusConfiguration child = (DefaultPlexusConfiguration) configuration.getChild( "child" ); assertNotNull( child ); child.setValue( "child value" ); assertEquals( 1, configuration.getChildCount() ); child = (DefaultPlexusConfiguration) configuration.getChild( "child" ); assertNotNull( child ); assertEquals( "child value", child.getValue() ); assertEquals( 1, configuration.getChildCount() ); } public void testToString() throws Exception { // TODO: this currently works since getTestConfiguration() invokes PlexusTools.buildConfiguration() // and it returns XmlPlexusConfiguration actually. PlexusConfiguration c = ConfigurationTestHelper.getTestConfiguration(); assertEquals( "string\n", c.getChild( "string" ).toString() ); // TODO: uncomment once maven can test the latest plexus-utils assertEquals( "\n", c.getChild( "singleton" ).toString() ); } public void testProgrammaticConfigurationCreation() throws Exception { String viewRoot = "/path/to/viewRoot"; PlexusConfiguration c = new DefaultPlexusConfiguration( "configuration" ).addChild( "viewRoot", viewRoot ); assertEquals( viewRoot, c.getChild( "viewRoot" ).getValue() ); } public void testChildOrdering() throws Exception { PlexusConfiguration child0 = new DefaultPlexusConfiguration( "child" ); PlexusConfiguration child1 = new DefaultPlexusConfiguration( "child" ); PlexusConfiguration child2 = new DefaultPlexusConfiguration( "special-child" ); PlexusConfiguration child3 = new DefaultPlexusConfiguration( "child" ); PlexusConfiguration child4 = new DefaultPlexusConfiguration( "child" ); configuration.addChild( child0 ); configuration.addChild( child1 ); configuration.addChild( child2 ); configuration.addChild( child3 ); configuration.addChild( child4 ); assertEquals( 5, configuration.getChildCount() ); assertSame( child0, configuration.getChild( 0 ) ); assertSame( child1, configuration.getChild( 1 ) ); assertSame( child2, configuration.getChild( 2 ) ); assertSame( child3, configuration.getChild( 3 ) ); assertSame( child4, configuration.getChild( 4 ) ); } } 000077500000000000000000000000001166327066700341615ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/ioXmlPlexusConfigurationReaderTest.java000066400000000000000000000012251166327066700435000ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/iopackage org.codehaus.plexus.configuration.io; import java.io.StringReader; import junit.framework.TestCase; import org.codehaus.plexus.configuration.ConfigurationTestHelper; import org.codehaus.plexus.configuration.PlexusConfiguration; public class XmlPlexusConfigurationReaderTest extends TestCase { public void testRead() throws Exception { StringReader sr = new StringReader( ConfigurationTestHelper.getXmlConfiguration() ); XmlPlexusConfigurationReader reader = new XmlPlexusConfigurationReader(); PlexusConfiguration c = reader.read( sr ); ConfigurationTestHelper.testConfiguration( c ); } } XmlPlexusConfigurationWriterTest.java000066400000000000000000000020171166327066700435520ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/iopackage org.codehaus.plexus.configuration.io; import java.io.StringReader; import java.io.StringWriter; import junit.framework.TestCase; import org.codehaus.plexus.configuration.ConfigurationTestHelper; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; public class XmlPlexusConfigurationWriterTest extends TestCase { public void testWrite() throws Exception { PlexusConfiguration c = ConfigurationTestHelper.getTestConfiguration(); XmlPlexusConfigurationWriter cw = new XmlPlexusConfigurationWriter(); StringWriter writer = new StringWriter(); cw.write( writer, c ); Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( writer.toString() ) ); XmlPlexusConfiguration c1 = new XmlPlexusConfiguration( dom ); ConfigurationTestHelper.testConfiguration( c1 ); } } 000077500000000000000000000000001166327066700350525ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/sourceADummyConfigurationSource.java000066400000000000000000000006031166327066700430210ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/sourcepackage org.codehaus.plexus.configuration.source; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; public class ADummyConfigurationSource implements ConfigurationSource { public PlexusConfiguration getConfiguration( ComponentDescriptor componentDescriptor ) { return null; } } AnotherDummyConfigurationSource.java000066400000000000000000000006771166327066700442540ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/sourcepackage org.codehaus.plexus.configuration.source; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; public class AnotherDummyConfigurationSource implements ConfigurationSource { private ConfigurationSource configurationSource; public PlexusConfiguration getConfiguration( ComponentDescriptor componentDescriptor ) { return null; } } DefaultConfigurationSourceTest.java000066400000000000000000000012131166327066700440470ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/sourcepackage org.codehaus.plexus.configuration.source; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.PlexusTestCase; public class DefaultConfigurationSourceTest extends PlexusTestCase { public void testBasic() throws Exception { // we have no plexus.xml, so the container should use the "default" source, // which is ContainerConfigurationSource ConfigurationSource cs = ( (MutablePlexusContainer) getContainer() ).getConfigurationSource(); assertNotNull( cs ); assertEquals( ContainerConfigurationSource.class.getName(), cs.getClass().getName() ); } } ExtendingConfigurationSourceTest.java000066400000000000000000000023111166327066700444100ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/sourcepackage org.codehaus.plexus.configuration.source; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.PlexusTestCase; public class ExtendingConfigurationSourceTest extends PlexusTestCase { public void testBasic() throws Exception { // we have plexus.xml with two configSources, so the container should use the "chained" case, // which is ChainedConfigurationSource with 3 elem in list: the plexusDefaultConfig source, // and the two user provided, in this order: ADummyConfigurationSource, AnotherDummyConfigurationSource ConfigurationSource cs = ( (MutablePlexusContainer) getContainer() ).getConfigurationSource(); assertNotNull( cs ); assertEquals( ChainedConfigurationSource.class.getName(), cs.getClass().getName() ); ChainedConfigurationSource ccs = (ChainedConfigurationSource) cs; // we have 3 config sources overall assertEquals( 3, ccs.getConfigurationSources().size() ); // and the last in the source list is container source assertEquals( ContainerConfigurationSource.class.getName(), ccs .getConfigurationSources().get( 2 ).getClass().getName() ); } } OverridingConfigurationSourceTest.java000066400000000000000000000012441166327066700445770ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/sourcepackage org.codehaus.plexus.configuration.source; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.PlexusTestCase; public class OverridingConfigurationSourceTest extends PlexusTestCase { public void testBasic() throws Exception { // we have plexus.xml with configSource that overrides the Plexus default one, so the container // should use it instead of the "default" one ConfigurationSource cs = ( (MutablePlexusContainer) getContainer() ).getConfigurationSource(); assertNotNull( cs ); assertEquals( ADummyConfigurationSource.class.getName(), cs.getClass().getName() ); } } 000077500000000000000000000000001166327066700343525ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/xmlXmlPlexusConfigurationTest.java000066400000000000000000000063621166327066700425550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/configuration/xmlpackage org.codehaus.plexus.configuration.xml; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; import org.codehaus.plexus.configuration.ConfigurationTestHelper; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * @author Ran Tene * @version $Id: XmlPlexusConfigurationTest.java 7187 2008-01-26 20:55:42Z cstamas $ */ public final class XmlPlexusConfigurationTest extends TestCase { private XmlPlexusConfiguration configuration; public void setUp() { configuration = new XmlPlexusConfiguration( "a" ); } public void testWithHelper() throws Exception { PlexusConfiguration c = ConfigurationTestHelper.getTestConfiguration(); ConfigurationTestHelper.testConfiguration( c ); } public void testGetValue() throws Exception { String orgValue = "Original String"; configuration.setValue( orgValue ); assertEquals( orgValue, configuration.getValue() ); } public void testGetAttribute() throws Exception { String key = "key"; String value = "original value"; String defaultStr = "default"; configuration.setAttribute( key, value ); assertEquals( value, configuration.getAttribute( key, defaultStr ) ); assertEquals( defaultStr, configuration.getAttribute( "newKey", defaultStr ) ); } public void testGetChild() throws Exception { PlexusConfiguration child = (XmlPlexusConfiguration) configuration.getChild( "child" ); assertNotNull( child ); child.setValue( "child value" ); assertEquals( 1, configuration.getChildCount() ); child = (XmlPlexusConfiguration) configuration.getChild( "child" ); assertNotNull( child ); assertEquals( "child value", child.getValue() ); assertEquals( 1, configuration.getChildCount() ); } public void testToString() throws Exception { PlexusConfiguration c = ConfigurationTestHelper.getTestConfiguration(); assertEquals( "string\n", c.getChild( "string" ).toString() ); // TODO: uncomment once maven can test the latest plexus-utils // assertEquals( "\n", c.getChild( "singleton" ).toString() ); } public void testProgrammaticConfigurationCreation() throws Exception { String viewRoot = "/path/to/viewRoot"; PlexusConfiguration c = new XmlPlexusConfiguration( "configuration" ) .addChild( "viewRoot", viewRoot ); assertEquals( viewRoot, c.getChild( "viewRoot" ).getValue() ); } } plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/context/000077500000000000000000000000001166327066700324465ustar00rootroot00000000000000ContextMapAdapterTest.java000066400000000000000000000044311166327066700374570ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/contextpackage org.codehaus.plexus.context; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.InterpolationFilterReader; import java.io.StringReader; import java.io.StringWriter; /** * Generated by JUnitDoclet, a tool provided by ObjectFab GmbH under LGPL. * Please see www.junitdoclet.org, www.gnu.org and www.objectfab.de for * informations about the tool, the licence and the authors. */ public class ContextMapAdapterTest extends TestCase { public ContextMapAdapterTest( String name ) { super( name ); } public void testInterpolation() throws Exception { DefaultContext context = new DefaultContext(); context.put( "name", "jason" ); context.put( "occupation", "exotic dancer" ); ContextMapAdapter adapter = new ContextMapAdapter( context ); assertEquals( "jason", (String) adapter.get( "name" ) ); assertEquals( "exotic dancer", (String) adapter.get( "occupation" ) ); assertNull( adapter.get( "foo" ) ); } public void testInterpolationWithContext() throws Exception { DefaultContext context = new DefaultContext(); context.put( "name", "jason" ); context.put( "noun", "asshole" ); String foo = "${name} is an ${noun}. ${not.interpolated}"; InterpolationFilterReader reader = new InterpolationFilterReader( new StringReader( foo ), new ContextMapAdapter( context ) ); StringWriter writer = new StringWriter(); IOUtil.copy( reader, writer ); String bar = writer.toString(); assertEquals( "jason is an asshole. ${not.interpolated}", bar ); } } DefaultContextTest.java000066400000000000000000000072431166327066700370310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/contextpackage org.codehaus.plexus.context; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.AssertionFailedError; import junit.framework.TestCase; import java.util.HashMap; import java.util.Map; /** * TestCase for Context. * * @author Berin Loritsch * @author Leo Sutic */ public class DefaultContextTest extends TestCase { public DefaultContextTest( String name ) { super( name ); } public void testContextCreationWithMap() throws Exception { Map map = new HashMap(); map.put( "name", "jason" ); DefaultContext context = new DefaultContext( map ); assertEquals( "jason", (String) context.get( "name" ) ); assertEquals( map, context.getContextData() ); // Test removal context.put( "name", null ); // There is no data and no parent containerContext. try { context.get( "name" ); } catch ( ContextException e ) { // do nothing } } public void testAddContext() throws Exception { DefaultContext context = new DefaultContext(); context.put( "key1", "value1" ); assertTrue( "value1".equals( context.get( "key1" ) ) ); context.put( "key1", "" ); assertTrue( "".equals( context.get( "key1" ) ) ); context.put( "key1", "value1" ); context.makeReadOnly(); try { context.put( "key1", "" ); throw new AssertionFailedError( "You are not allowed to change a value after it has been made read only" ); } catch ( IllegalStateException ise ) { assertTrue( "Value is null", "value1".equals( context.get( "key1" ) ) ); } } public void testHiddenItems() throws ContextException { // initalize DefaultContext context = new DefaultContext(); context.put( "test", "test" ); // verify inital state assertTrue( "test".equals( context.get( "test" ) ) ); // hide value and verify context.hide( "test" ); try { context.get( "test" ); fail( "The item \"test\" was hidden in the child containerContext, but could still be retrieved via get()." ); } catch ( ContextException ce ) { assertTrue( true ); } // reset to inital state and verify context.put( "test", "test" ); assertTrue( "test".equals( context.get( "test" ) ) ); // mark context read-only and verify that item can not be hidden context.makeReadOnly(); try { context.hide( "test" ); fail( "hide() did not throw an exception, even though the containerContext is supposed to be read-only." ); } catch ( IllegalStateException ise ) { assertTrue( true ); } // verify state did not change in failed hide() invocation assertTrue( "test".equals( context.get( "test" ) ) ); } } plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/hierarchy/000077500000000000000000000000001166327066700327405ustar00rootroot00000000000000PlexusHierarchyTest.java000066400000000000000000000000001166327066700374710ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/hierarchyPlexusTestService.java000066400000000000000000000000001166327066700371530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/hierarchyTestServiceImpl.java000066400000000000000000000000001166327066700365740ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/hierarchyplexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/logging/000077500000000000000000000000001166327066700324105ustar00rootroot00000000000000AbstractLoggerManagerTest.java000066400000000000000000000161471166327066700402430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusTestCase; /** * Abtract base class for testing implementations of the {@link LoggerManager} * and {@link Logger} interfaces. * * @author Mark H. Wilkinson * @author Trygve Laugstøl * @version $Revision: 4778 $ */ public abstract class AbstractLoggerManagerTest extends PlexusTestCase { protected abstract LoggerManager createLoggerManager() throws Exception; public void testSetThreshold() throws Exception { LoggerManager manager; Logger logger1, logger2; manager = createLoggerManager(); manager.setThreshold( Logger.LEVEL_FATAL ); logger1 = manager.getLoggerForComponent( "role1", "roleHint1" ); assertEquals( Logger.LEVEL_FATAL, logger1.getThreshold() ); manager.setThreshold( Logger.LEVEL_DEBUG ); logger2 = manager.getLoggerForComponent( "role2", "roleHint2" ); assertEquals( Logger.LEVEL_FATAL, logger1.getThreshold() ); assertEquals( Logger.LEVEL_DEBUG, logger2.getThreshold() ); } /** * There is only one logger instance pr component even if looked up more that once. */ public void testActiveLoggerCount() throws Exception { LoggerManager manager; Logger b, c1_1, c1_2, c2; manager = getManager( Logger.LEVEL_FATAL ); assertEquals(0, manager.getActiveLoggerCount()); b = manager.getLoggerForComponent( "b" ); assertNotNull( b ); assertEquals(1, manager.getActiveLoggerCount()); c1_1 = manager.getLoggerForComponent( "c", "1" ); c1_2 = manager.getLoggerForComponent( "c", "1" ); assertNotNull( c1_1 ); assertNotNull( c1_2 ); assertSame( c1_1, c1_2 ); assertEquals(2, manager.getActiveLoggerCount()); c2 = manager.getLoggerForComponent( "c", "2" ); assertNotNull( c2 ); assertEquals(3, manager.getActiveLoggerCount()); manager.returnComponentLogger( "c", "1" ); assertEquals(2, manager.getActiveLoggerCount()); manager.returnComponentLogger( "c", "2" ); manager.returnComponentLogger( "c", "2" ); manager.returnComponentLogger( "c", "1" ); assertEquals(1, manager.getActiveLoggerCount()); manager.returnComponentLogger( "b" ); assertEquals(0, manager.getActiveLoggerCount()); } public void testDebugLevelConfiguration() throws Exception { LoggerManager manager = getManager( Logger.LEVEL_DEBUG ); Logger logger = extractLogger( manager ); checkDebugLevel( logger ); logger = extractLogger( manager ); checkDebugLevel( logger ); } public void testInfoLevelConfiguration() throws Exception { LoggerManager manager = getManager( Logger.LEVEL_INFO ); Logger logger = extractLogger( manager ); checkInfoLevel( logger ); logger = extractLogger( manager ); checkInfoLevel( logger ); } public void testWarnLevelConfiguration() throws Exception { LoggerManager manager = getManager( Logger.LEVEL_WARN ); Logger logger = extractLogger( manager ); checkWarnLevel( logger ); logger = extractLogger( manager ); checkWarnLevel( logger ); } public void testErrorLevelConfiguration() throws Exception { LoggerManager manager = getManager( Logger.LEVEL_ERROR ); Logger logger = extractLogger( manager ); checkErrorLevel( logger ); logger = extractLogger( manager ); checkErrorLevel( logger ); } public void testFatalLevelConfiguration() throws Exception { LoggerManager manager = getManager( Logger.LEVEL_FATAL ); Logger logger = extractLogger( manager ); checkFatalLevel( logger ); logger = extractLogger( manager ); checkFatalLevel( logger ); } private LoggerManager getManager( int threshold ) throws Exception { LoggerManager manager = createLoggerManager(); manager.setThreshold( threshold ); assertNotNull( manager ); return manager; } /* private Logger extractRootLogger( LoggerManager manager ) { Logger logger = manager.getRootLogger(); assertNotNull( logger ); return logger; } */ private Logger extractLogger( LoggerManager manager ) { Logger logger = manager.getLoggerForComponent( "foo" ); assertNotNull( logger ); assertEquals( "foo", logger.getName() ); return logger; } private void checkDebugLevel( Logger logger ) { assertTrue( "debug enabled", logger.isDebugEnabled() ); assertTrue( "info enabled", logger.isInfoEnabled() ); assertTrue( "warn enabled", logger.isWarnEnabled() ); assertTrue( "error enabled", logger.isErrorEnabled() ); assertTrue( "fatal enabled", logger.isFatalErrorEnabled() ); } private void checkInfoLevel( Logger logger ) { assertFalse( "debug disabled", logger.isDebugEnabled() ); assertTrue( "info enabled", logger.isInfoEnabled() ); assertTrue( "warn enabled", logger.isWarnEnabled() ); assertTrue( "error enabled", logger.isErrorEnabled() ); assertTrue( "fatal enabled", logger.isFatalErrorEnabled() ); } private void checkWarnLevel( Logger logger ) { assertFalse( "debug disabled", logger.isDebugEnabled() ); assertFalse( "info disabled", logger.isInfoEnabled() ); assertTrue( "warn enabled", logger.isWarnEnabled() ); assertTrue( "error enabled", logger.isErrorEnabled() ); assertTrue( "fatal enabled", logger.isFatalErrorEnabled() ); } private void checkErrorLevel( Logger logger ) { assertFalse( "debug disabled", logger.isDebugEnabled() ); assertFalse( "info disabled", logger.isInfoEnabled() ); assertFalse( "warn disabled", logger.isWarnEnabled() ); assertTrue( "error enabled", logger.isErrorEnabled() ); assertTrue( "fatal enabled", logger.isFatalErrorEnabled() ); } private void checkFatalLevel( Logger logger ) { assertFalse( "debug disabled", logger.isDebugEnabled() ); assertFalse( "info disabled", logger.isInfoEnabled() ); assertFalse( "warn disabled", logger.isWarnEnabled() ); assertFalse( "error disabled", logger.isErrorEnabled() ); assertTrue( "fatal enabled", logger.isFatalErrorEnabled() ); } } CustomLoggerManagerTest.java000066400000000000000000000023371166327066700377460ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusTestCase; //TODO: this test will get nuked, this needs to be done programmatically /** * @author Trygve Laugstøl * @version $Id: CustomLoggerManagerTest.java 7828 2008-11-14 22:07:56Z dain $ */ public class CustomLoggerManagerTest extends PlexusTestCase { public void testBasic() throws Exception { LoggerManager manager = lookup( LoggerManager.class ); assertNotNull( manager ); assertEquals( MockLoggerManager.class.getName(), manager.getClass().getName() ); } } LogEnabledTest.java000066400000000000000000000061601166327066700360330ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; /** * * @author Peter Donald * @version $Revision: 4779 $ $Date: 2006-11-23 05:09:31 +0100 (jeu. 23 nov. 2006) $ */ public class LogEnabledTest extends TestCase { public void testGetLogger() throws Exception { MockLogEnabled logEnabled = new MockLogEnabled(); MockLogger logger = new MockLogger( "base" ); logEnabled.enableLogging( logger ); assertEquals( "logger", logger, logEnabled.getLogger() ); } public void testSetupLoggerOnLogEnabled() throws Exception { MockLogEnabled logEnabled = new MockLogEnabled(); MockLogEnabled childLogEnabled = new MockLogEnabled(); MockLogger logger = new MockLogger( "base" ); logEnabled.enableLogging( logger ); logEnabled.setupLogger( childLogEnabled ); assertEquals( "logEnabled.logger", logger, logEnabled.getLogger() ); assertEquals( "childLogEnabled.logger", logger, childLogEnabled.getLogger() ); } public void testSetupLoggerOnNonLogEnabled() throws Exception { MockLogEnabled logEnabled = new MockLogEnabled(); MockLogger logger = new MockLogger( "base" ); logEnabled.enableLogging( logger ); logEnabled.setupLogger( new Object() ); } public void testSetupLoggerWithNameOnLogEnabled() throws Exception { MockLogEnabled logEnabled = new MockLogEnabled(); MockLogEnabled childLogEnabled = new MockLogEnabled(); MockLogger logger = new MockLogger( "base" ); logEnabled.enableLogging( logger ); logEnabled.setupLogger( childLogEnabled, "child" ); assertEquals( "logEnabled.logger", logger, logEnabled.getLogger() ); assertEquals( "childLogEnabled.logger.name", "base.child", ( (MockLogger) childLogEnabled.getLogger() ).getName() ); } public void testSetupLoggerWithNullName() throws Exception { MockLogEnabled logEnabled = new MockLogEnabled(); MockLogEnabled childLogEnabled = new MockLogEnabled(); MockLogger logger = new MockLogger( "base" ); logEnabled.enableLogging( logger ); try { logEnabled.setupLogger( childLogEnabled, (String) null ); } catch ( IllegalStateException npe ) { return; } fail( "Expected to fail setting up child logger with null name" ); } } MockLogEnabled.java000066400000000000000000000015501166327066700360030ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * @author Peter Donald * @version $Revision: 4779 $ $Date: 2006-11-23 05:09:31 +0100 (jeu. 23 nov. 2006) $ */ class MockLogEnabled extends AbstractLogEnabled { } MockLogger.java000066400000000000000000000043311166327066700352260ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * @author Peter Donald * @version $Revision: 4779 $ $Date: 2006-11-23 05:09:31 +0100 (jeu. 23 nov. 2006) $ */ class MockLogger implements Logger { private final String m_name; MockLogger( String name ) { m_name = name; } public String getName() { return m_name; } public Logger getChildLogger( final String name ) { return new MockLogger( getName() + "." + name ); } public void debug( String message ) { } public void debug( String message, Throwable throwable ) { } public boolean isDebugEnabled() { return false; } public void info( String message ) { } public void info( String message, Throwable throwable ) { } public boolean isInfoEnabled() { return false; } public void warn( String message ) { } public void warn( String message, Throwable throwable ) { } public boolean isWarnEnabled() { return false; } public boolean isFatalErrorEnabled() { return false; } public void fatalError( String message ) { } public void fatalError( String message, Throwable throwable ) { } public void error( String message ) { } public void error( String message, Throwable throwable ) { } public boolean isErrorEnabled() { return false; } public int getThreshold() { return 0; } public void setThreshold( int threshold ) { } } MockLoggerManager.java000066400000000000000000000034761166327066700365320ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/loggingpackage org.codehaus.plexus.logging; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Trygve Laugstøl * @version $Id: MockLoggerManager.java 4778 2006-11-23 03:54:18Z jvanzyl $ */ public class MockLoggerManager implements LoggerManager { public void setThreshold(int threshold) { } public void setThresholds(int threshold) { } public int getThreshold() { return 0; } public void setThreshold(String role, int threshold) { } public void setThreshold(String role, String roleHint, int threshold) { } public int getThreshold(String role) { return 0; } public int getThreshold(String role, String roleHint) { return 0; } public Logger getLoggerForComponent(String role) { return new MockLogger(role.getClass().getName()); } public Logger getLoggerForComponent(String role, String roleHint) { return new MockLogger(role.getClass().getName() + ":" + roleHint); } public void returnComponentLogger(String role) { } public void returnComponentLogger(String role, String hint) { } public int getActiveLoggerCount() { return 0; } } 000077500000000000000000000000001166327066700337735ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/logging/consoleConsoleLoggerManagerTest.java000066400000000000000000000032021166327066700415300ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/logging/consolepackage org.codehaus.plexus.logging.console; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.logging.AbstractLoggerManagerTest; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; /** * Test for {@link org.codehaus.plexus.logging.console.ConsoleLoggerManager} and * {@link org.codehaus.plexus.logging.console.ConsoleLogger}. * * @author Mark H. Wilkinson * @version $Revision: 7828 $ */ public final class ConsoleLoggerManagerTest extends AbstractLoggerManagerTest { protected LoggerManager createLoggerManager() throws Exception { return lookup(LoggerManager.class); } public void testSetAllThresholds() throws Exception { LoggerManager manager = createLoggerManager(); manager.setThreshold( Logger.LEVEL_ERROR ); Logger logger = manager.getLoggerForComponent( "test" ); assertEquals( logger.getThreshold(), Logger.LEVEL_ERROR ); manager.setThresholds( Logger.LEVEL_DEBUG ); assertEquals( logger.getThreshold(), Logger.LEVEL_DEBUG ); } } ConsoleLoggerTest.java000066400000000000000000000070221166327066700402410ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/logging/consolepackage org.codehaus.plexus.logging.console; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; import org.codehaus.plexus.util.StringUtils; import java.io.ByteArrayOutputStream; import java.io.PrintStream; /** * @author Jason van Zyl * * @version $Id: ConsoleLoggerTest.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ConsoleLoggerTest extends TestCase { public void testConsoleLogger() { ConsoleLogger logger = new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG, "test" ); assertTrue( logger.isDebugEnabled() ); assertTrue( logger.isInfoEnabled() ); assertTrue( logger.isWarnEnabled() ); assertTrue( logger.isErrorEnabled() ); assertTrue( logger.isFatalErrorEnabled() ); // Save the original print stream. PrintStream original = System.out; Throwable t = new Throwable( "throwable" ); ByteArrayOutputStream os = new ByteArrayOutputStream(); PrintStream consoleStream = new PrintStream( os ); System.setOut( consoleStream ); logger.debug( "debug" ); assertEquals( "[DEBUG] debug", getMessage( consoleStream, os ) ); logger.debug( "debug", t ); assertEquals( "[DEBUG] debug", getMessage( consoleStream, os ) ); os = new ByteArrayOutputStream(); consoleStream = new PrintStream( os ); System.setOut( consoleStream ); logger.info( "info" ); assertEquals( "[INFO] info", getMessage( consoleStream, os ) ); logger.info( "info", t ); assertEquals( "[INFO] info", getMessage( consoleStream, os ) ); os = new ByteArrayOutputStream(); consoleStream = new PrintStream( os ); System.setOut( consoleStream ); logger.warn( "warn" ); assertEquals( "[WARNING] warn", getMessage( consoleStream, os ) ); logger.warn( "warn", t ); assertEquals( "[WARNING] warn", getMessage( consoleStream, os ) ); os = new ByteArrayOutputStream(); consoleStream = new PrintStream( os ); System.setOut( consoleStream ); logger.error( "error" ); assertEquals( "[ERROR] error", getMessage( consoleStream, os ) ); logger.error( "error", t ); assertEquals( "[ERROR] error", getMessage( consoleStream, os ) ); os = new ByteArrayOutputStream(); consoleStream = new PrintStream( os ); System.setOut( consoleStream ); logger.fatalError( "error" ); assertEquals( "[FATAL ERROR] error", getMessage( consoleStream, os ) ); logger.fatalError( "error", t ); assertEquals( "[FATAL ERROR] error", getMessage( consoleStream, os ) ); // Set the original print stream. System.setOut( original ); } private String getMessage( PrintStream consoleStream, ByteArrayOutputStream os ) { consoleStream.flush(); consoleStream.close(); return StringUtils.chopNewline( os.toString() ); } } plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/000077500000000000000000000000001166327066700317415ustar00rootroot00000000000000AbstractStartableComponent.java000066400000000000000000000041041166327066700400140ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException; import junit.framework.Assert; import static junit.framework.Assert.assertTrue; public class AbstractStartableComponent implements StartableComponent, Startable { public int startOrder; public int stopOrder; public AbstractStartableComponent component1; public AbstractStartableComponent component2; public void start() throws StartingException { startOrder = startGenerator.getAndIncrement(); } public void stop() throws StoppingException { stopOrder = stopGenerator.getAndIncrement(); } public void assertStartOrderCorrect() { if ( component1 != null ) { assertTrue( "This component started before injected component1", startOrder > component1.startOrder ); } if ( component2 != null ) { assertTrue( "This component started before injected component2", startOrder > component2.startOrder ); } // assert children are correct if ( component1 != null ) { component1.assertStartOrderCorrect(); } if ( component2 != null ) { component2.assertStartOrderCorrect(); } } public void assertStopOrderCorrect() { if ( component1 != null ) { assertTrue( "This component stopped after injected component1", stopOrder < component1.stopOrder ); } if ( component2 != null ) { assertTrue( "This component stopped after injected component2", stopOrder < component2.stopOrder ); } // assert children are correct if ( component1 != null ) { component1.assertStopOrderCorrect(); } if ( component2 != null ) { component2.assertStopOrderCorrect(); } } } Action.java000066400000000000000000000014161166327066700337440ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: Action.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Action { } AddUserAction.java000066400000000000000000000014561166327066700352200ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: AddUserAction.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class AddUserAction implements Action { } CircularComponent.java000066400000000000000000000002051166327066700361510ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; public interface CircularComponent { static String ROLE = CircularComponent.class.getName(); }Component.java000066400000000000000000000016771166327066700345020ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.test.map.Activity; /** * * * @author Jason van Zyl * * @version $Id: Component.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Component { static String ROLE = Component.class.getName(); String getHost(); int getPort(); Activity getActivity(); } ComponentA.java000066400000000000000000000015101166327066700345650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface ComponentA { static String ROLE = ComponentA.class.getName(); ComponentB getComponentB(); ComponentC getComponentC(); String getHost(); int getPort(); } ComponentB.java000066400000000000000000000013331166327066700345710ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface ComponentB { static String ROLE = ComponentB.class.getName(); } ComponentC.java000066400000000000000000000013741166327066700345770ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface ComponentC { static String ROLE = ComponentC.class.getName(); ComponentD getComponentD(); } ComponentD.java000066400000000000000000000013621166327066700345750ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface ComponentD { static String ROLE = ComponentD.class.getName(); String getName(); } ComponentManager.java000066400000000000000000000014211166327066700357600ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.List; import java.util.Map; public interface ComponentManager { List getList(); Map getMap(); } ComponentWithRoleDefault.java000066400000000000000000000012621166327066700374530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class ComponentWithRoleDefault { } ConcreteThing.java000066400000000000000000000012731166327066700352640ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class ConcreteThing implements Thing { } CountInstancesComponent.java000066400000000000000000000021741166327066700373540ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Component counts number of created instances of it. * * @author Piotr Tabor */ public class CountInstancesComponent { public static String ROLE = CountInstancesComponent.class.getName(); private static int instances = 0; public CountInstancesComponent() { instances++; } public static void reset() { instances = 0; } public static int getInstancesCount() { return instances; } } DefaultCircularComponent.java000066400000000000000000000016051166327066700374630ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException; public class DefaultCircularComponent implements CircularComponent, Startable { private PlexusContainer container; private String lookup; private CircularComponent requirement; public void start() throws StartingException { try { if (lookup != null) { container.lookup( CircularComponent.class, lookup ); } } catch ( Exception e ) { throw new StartingException("failed", e); } } public void stop() throws StoppingException { } }DefaultComponent.java000066400000000000000000000020011166327066700357650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.test.map.Activity; public class DefaultComponent implements Component { private String host; private int port; private Activity activity; public Activity getActivity() { return activity; } public String getHost() { return host; } public int getPort() { return port; } } DefaultComponentA.java000066400000000000000000000025351166327066700361020ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @component.role org.codehaus.plexus.test.ComponentA * @component.requirement org.codehaus.plexus.test.ComponentB * @component.requirement org.codehaus.plexus.test.ComponentC * @component.version 1.0 */ public class DefaultComponentA implements ComponentA { private ComponentB componentB; private ComponentC componentC; /** @default localhost */ private String host; /** @default 10000 */ private int port; public ComponentB getComponentB() { return componentB; } public ComponentC getComponentC() { return componentC; } public String getHost() { return host; } public int getPort() { return port; } } DefaultComponentB.java000066400000000000000000000013451166327066700361010ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @component.version 2.0 */ public class DefaultComponentB implements ComponentB { } DefaultComponentC.java000066400000000000000000000014641166327066700361040ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class DefaultComponentC implements ComponentC { private ComponentD componentD; public ComponentD getComponentD() { return componentD; } } DefaultComponentD.java000066400000000000000000000014321166327066700361000ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class DefaultComponentD implements ComponentD { private String name; public String getName() { return name; } } DefaultComponentManager.java000066400000000000000000000016751166327066700373000ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.List; import java.util.Map; public class DefaultComponentManager implements ComponentManager { private List list; private Map map; public List getList() { return list; } public Map getMap() { return map; } } DefaultComponentWithOptionalRequirement.java000066400000000000000000000014031166327066700425550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class DefaultComponentWithOptionalRequirement extends DefaultComponent { public Object optionalComponent; } DefaultLoadOnStartService.java000066400000000000000000000020661166327066700375510ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; /** * * * @author Jason van Zyl * * @version $Id: DefaultLoadOnStartService.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultLoadOnStartService implements LoadOnStartService, Startable { public static boolean isStarted = false; public void start() { isStarted = true; } public void stop() { } } DefaultLoadOnStartServiceWithRoleHint.java000066400000000000000000000015521166327066700420510ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: DefaultLoadOnStartServiceWithRoleHint.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultLoadOnStartServiceWithRoleHint implements LoadOnStartService { } DefaultServiceB.java000066400000000000000000000034061166327066700355370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; /** * A simple native plexus component. */ public class DefaultServiceB extends AbstractLogEnabled implements ServiceB, Contextualizable, Initializable, Startable { public boolean enableLogging; public boolean contextualize; public boolean initialize; public boolean start; public boolean stop; public void enableLogging( Logger logger ) { enableLogging = true; } public void contextualize( Context context ) throws ContextException { contextualize = true; } public void initialize() { initialize = true; } public void start() { start = true; } public void stop() { stop = true; } } DefaultServiceC.java000066400000000000000000000017251166327066700355420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; public class DefaultServiceC implements ServiceC, Startable { public boolean started = false; public boolean stopped = false; public void start() { started = true; } public void stop() { stopped = true; } } DefaultServiceD.java000066400000000000000000000013001166327066700355300ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class DefaultServiceD implements ServiceD { } DefaultServiceE.java000066400000000000000000000035561166327066700355500ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; /** * A simple native plexus component implementing the manual configuration phase. */ public class DefaultServiceE extends AbstractLogEnabled implements ServiceE, Contextualizable, Initializable, Startable { public boolean enableLogging; public boolean configured; public boolean contextualize; public boolean initialize; public boolean start; public boolean stop; public boolean serviced; public void enableLogging( Logger logger ) { enableLogging = true; } public void contextualize( Context context ) throws ContextException { contextualize = true; } public void initialize() { initialize = true; } public void start() { start = true; } public void stop() { stop = true; } } DefaultServiceH.java000066400000000000000000000031701166327066700355430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.test.lifecycle.phase.Eeny; import org.codehaus.plexus.test.lifecycle.phase.Meeny; import org.codehaus.plexus.test.lifecycle.phase.Miny; import org.codehaus.plexus.test.lifecycle.phase.Mo; /** This component implements the custom lifecycle defined by the phases * * Eeny * Meeny * Miny * Mo * */ public class DefaultServiceH extends AbstractLogEnabled implements ServiceH, Eeny, Meeny, Miny, Mo { public boolean eeny; public boolean meeny; public boolean miny; public boolean mo; // ---------------------------------------------------------------------- // Lifecycle Management // ---------------------------------------------------------------------- public void eeny() { eeny = true; } public void meeny() { meeny = true; } public void miny() { miny = true; } public void mo() { mo = true; } } DefaultStartableComponentA.java000066400000000000000000000001661166327066700377420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; public class DefaultStartableComponentA extends AbstractStartableComponent { } DefaultStartableComponentB.java000066400000000000000000000001661166327066700377430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; public class DefaultStartableComponentB extends AbstractStartableComponent { } DefaultStartableComponentC.java000066400000000000000000000001661166327066700377440ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; public class DefaultStartableComponentC extends AbstractStartableComponent { } DefaultStartableComponentD.java000066400000000000000000000001661166327066700377450ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; public class DefaultStartableComponentD extends AbstractStartableComponent { } DefaultStartableComponentE.java000066400000000000000000000001661166327066700377460ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; public class DefaultStartableComponentE extends AbstractStartableComponent { } DefaultThingUser.java000066400000000000000000000013331166327066700357420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class DefaultThingUser implements ThingUser { public Thing thing; } LiveComponent.java000066400000000000000000000012471166327066700353130ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class LiveComponent { } LoadOnStartService.java000066400000000000000000000015331166327066700362420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: LoadOnStartService.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface LoadOnStartService { String ROLE = LoadOnStartService.class.getName(); } LoadOnStartServiceWithRoleHint.java000066400000000000000000000015771166327066700405530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: LoadOnStartServiceWithRoleHint.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface LoadOnStartServiceWithRoleHint { String ROLE = LoadOnStartServiceWithRoleHint.class.getName(); } PlexusContainerTest.java000066400000000000000000000676131166327066700365250ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; import junit.framework.TestCase; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.DefaultContainerConfiguration; import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.discovery.DiscoveredComponent; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.lifecycle.BasicLifecycleHandler; import org.codehaus.plexus.lifecycle.LifecycleHandler; import org.codehaus.plexus.test.lifecycle.phase.EenyPhase; import org.codehaus.plexus.test.lifecycle.phase.MeenyPhase; import org.codehaus.plexus.test.lifecycle.phase.MinyPhase; import org.codehaus.plexus.test.lifecycle.phase.MoPhase; import org.codehaus.plexus.test.list.Pipeline; import org.codehaus.plexus.test.list.Valve; import org.codehaus.plexus.test.list.ValveFour; import org.codehaus.plexus.test.list.ValveOne; import org.codehaus.plexus.test.list.ValveThree; import org.codehaus.plexus.test.list.ValveTwo; import org.codehaus.plexus.test.map.Activity; import org.codehaus.plexus.test.map.ActivityManager; public class PlexusContainerTest extends TestCase { private String basedir; private ClassLoader classLoader; private String configuration; private DefaultPlexusContainer container; public PlexusContainerTest( String name ) { super( name ); } public void setUp() throws Exception { basedir = System.getProperty( "basedir" ); classLoader = getClass().getClassLoader(); configuration = "/" + getClass().getName().replace( '.', '/' ) + ".xml"; assertNotNull( classLoader ); // ---------------------------------------------------------------------------- // Context // ---------------------------------------------------------------------------- Map context = new HashMap(); context.put( "basedir", basedir ); context.put( "plexus.home", basedir + "/target/plexus-home" ); LifecycleHandler arbitrary = new BasicLifecycleHandler( "arbitrary" ); arbitrary.addBeginSegment( new EenyPhase() ); arbitrary.addBeginSegment( new MeenyPhase() ); arbitrary.addBeginSegment( new MinyPhase() ); arbitrary.addBeginSegment( new MoPhase() ); ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration() .setName( "test" ) .setContext( context ) .setContainerConfiguration( configuration ) .addLifecycleHandler( arbitrary ); container = new DefaultPlexusContainer( containerConfiguration ); } public void tearDown() throws Exception { container.dispose(); container = null; } public void testDefaultPlexusContainerSetup() throws Exception { assertEquals( "bar", System.getProperty( "foo" ) ); } // ---------------------------------------------------------------------- // Test the native plexus lifecycle. Note that the configuration for // this TestCase supplies its own lifecycle, so this test verifies that // the native lifecycle is available after configuration merging. // ---------------------------------------------------------------------- public void testNativeLifecyclePassage() throws Exception { DefaultServiceB serviceB = (DefaultServiceB) container.lookup( ServiceB.class ); // Make sure the component is alive. assertNotNull( serviceB ); // Make sure the component went through all the lifecycle phases assertEquals( true, serviceB.enableLogging ); assertEquals( true, serviceB.contextualize ); assertEquals( true, serviceB.initialize ); assertEquals( true, serviceB.start ); assertEquals( false, serviceB.stop ); container.release( serviceB ); assertEquals( true, serviceB.stop ); } public void testConfigurableLifecyclePassage() throws Exception { DefaultServiceE serviceE = (DefaultServiceE) container.lookup( ServiceE.class ); // Make sure the component is alive. assertNotNull( serviceE ); // Make sure the component went through all the lifecycle phases assertEquals( true, serviceE.enableLogging ); assertEquals( true, serviceE.contextualize ); assertEquals( true, serviceE.initialize ); assertEquals( true, serviceE.start ); assertEquals( false, serviceE.stop ); container.release( serviceE ); assertEquals( true, serviceE.stop ); } /* * Check that we can get references to a single component with a role * hint. */ public void testSingleComponentLookupWithRoleHint() throws Exception { // Retrieve an instance of component c. DefaultServiceC serviceC1 = (DefaultServiceC) container.lookup( ServiceC.class, "first-instance" ); // Make sure the component is alive. assertNotNull( serviceC1 ); assertTrue( serviceC1.started ); assertFalse( serviceC1.stopped ); // Retrieve a second reference to the same component. DefaultServiceC serviceC2 = (DefaultServiceC) container.lookup( ServiceC.class, "first-instance" ); // Make sure component is alive. assertNotNull( serviceC2 ); assertTrue( serviceC2.started ); assertFalse( serviceC2.stopped ); // Let's make sure it gave us back the same component. assertSame( serviceC1, serviceC2 ); container.release( serviceC1 ); // The component should still be alive. assertTrue( serviceC2.started ); assertTrue( serviceC2.stopped ); container.release( serviceC2 ); // The component should now have been stopped. assertTrue( serviceC2.started ); assertTrue( serviceC2.stopped ); } /* * Check that distinct components with the same implementation are managed correctly. */ public void testMultipleSingletonComponentInstances() throws Exception { // Retrieve an instance of component c. DefaultServiceC serviceC1 = (DefaultServiceC) container.lookup( ServiceC.class, "first-instance" ); // Make sure the component is alive. assertNotNull( serviceC1 ); assertTrue( serviceC1.started ); assertFalse( serviceC1.stopped ); // Retrieve an instance of component c, with a different role hint. // This should give us a different component instance. DefaultServiceC serviceC2 = (DefaultServiceC) container.lookup( ServiceC.class, "second-instance" ); // Make sure component is alive. assertNotNull( serviceC2 ); assertTrue( serviceC2.started ); assertFalse( serviceC2.stopped ); // The components should be distinct. assertNotSame( serviceC1, serviceC2 ); container.release( serviceC1 ); // The first component should now have been stopped, the second // one should still be alive. assertTrue( serviceC1.started ); assertTrue( serviceC1.stopped ); assertTrue( serviceC2.started ); assertFalse( serviceC2.stopped ); container.release( serviceC2 ); // The second component should now have been stopped. assertTrue( serviceC2.started ); assertTrue( serviceC2.stopped ); } // ---------------------------------------------------------------------- // Test using an arbitrary component lifecycle handler // ---------------------------------------------------------------------- public void testArbitraryLifecyclePassageUsingFourArbitraryPhases() throws Exception { // Retrieve an manager of component H. DefaultServiceH serviceH = (DefaultServiceH) container.lookup( ServiceH.class ); // Make sure the component is alive. assertNotNull( serviceH ); // Make sure the component went through all the lifecycle phases assertEquals( true, serviceH.eeny ); assertEquals( true, serviceH.meeny ); assertEquals( true, serviceH.miny ); assertEquals( true, serviceH.mo ); container.release( serviceH ); } public void testLookupAll() throws Exception { Map components = container.lookupMap( ServiceC.class ); assertNotNull( components ); assertEquals( 2, components.size() ); ServiceC component = components.get( "first-instance" ); assertNotNull( component ); component = components.get( "second-instance" ); assertNotNull( component ); container.releaseAll( components ); } public void testAutomatedComponentConfigurationUsingXStreamPoweredComponentConfigurator() throws Exception { Component component = container.lookup( Component.class ); assertNotNull( component ); assertNotNull( component.getActivity() ); assertEquals( "localhost", component.getHost() ); assertEquals( 10000, component.getPort() ); } public void testAutomatedComponentComposition() throws Exception { ComponentA componentA = container.lookup( ComponentA.class ); assertNotNull( componentA ); assertEquals( "localhost", componentA.getHost() ); assertEquals( 10000, componentA.getPort() ); ComponentB componentB = componentA.getComponentB(); assertNotNull( componentB ); ComponentC componentC = componentA.getComponentC(); assertNotNull( componentC ); ComponentD componentD = componentC.getComponentD(); assertNotNull( componentD ); assertEquals( "jason", componentD.getName() ); } public void testComponentCompositionWhereTargetFieldIsAMap() throws Exception { ActivityManager am = container.lookup( ActivityManager.class ); Activity one = am.getActivity( "one" ); assertNotNull( one ); // repeated retrieval from map should not cause re-lookup even if instantiation strategy is per-lookup assertSame( one, am.getActivity( "one" ) ); assertFalse( one.getState() ); am.execute( "one" ); assertTrue( one.getState() ); Activity two = am.getActivity( "two" ); assertNotNull( two ); assertFalse( two.getState() ); am.execute( "two" ); assertTrue( two.getState() ); } public void testComponentCompositionWhereTargetFieldIsAPartialMap() throws Exception { ActivityManager am = container.lookup( ActivityManager.class, "slim" ); assertEquals( 1, am.getActivityCount() ); Activity one = am.getActivity( "one" ); assertNotNull( one ); assertFalse( one.getState() ); am.execute( "one" ); assertTrue( one.getState() ); } public void testComponentCompositionWhereTargetFieldIsAList() throws Exception { Pipeline pipeline = container.lookup( Pipeline.class ); List valves = pipeline.getValves(); for ( int i = 0; i < valves.size(); i++ ) { // repeated retrieval from list should not cause re-lookup even if instantiation strategy is per-lookup assertSame( valves.get( i ), valves.get( i ) ); } assertFalse( ( (Valve) valves.get( 0 ) ).getState() ); assertFalse( ( (Valve) valves.get( 1 ) ).getState() ); pipeline.execute(); assertTrue( ( (Valve) valves.get( 0 ) ).getState() ); assertTrue( ( (Valve) valves.get( 1 ) ).getState() ); } public void testComponentCompositionWhereTargetFieldIsAPartialList() throws Exception { Pipeline pipeline = container.lookup( Pipeline.class, "slim" ); List valves = pipeline.getValves(); assertEquals( valves.size(), 1 ); assertFalse( ( (Valve) valves.get( 0 ) ).getState() ); pipeline.execute(); assertTrue( ( (Valve) valves.get( 0 ) ).getState() ); } public void testComponentCompositionWhereTargetFieldAMapThatMustRetainTheOrderOfComponentsGivenASetOfRoleHints() throws Exception { Pipeline pipeline = container.lookup( Pipeline.class, "chubby" ); Map valveMap = pipeline.getValveMap(); List valves = new ArrayList( valveMap.values() ); assertEquals( "Expecting three valves.", 4, valves.size() ); assertTrue( "Expecting valve one.", valves.get(0) instanceof ValveOne ); assertTrue( "Expecting valve two.", valves.get(1) instanceof ValveTwo ); assertTrue( "Expecting valve three.", valves.get(2) instanceof ValveThree ); assertTrue( "Expecting valve four.", valves.get(3) instanceof ValveFour ); } public void testLookupOfComponentThatShouldBeDiscovered() throws Exception { DiscoveredComponent discoveredComponent = container.lookup( DiscoveredComponent.class ); assertNotNull( discoveredComponent ); } public void testStartableComponentSnake() throws Exception { StartableComponent ca = container.lookup( StartableComponent.class, "A-snake" ); assertNotNull( ca ); ca.assertStartOrderCorrect(); container.dispose(); ca.assertStopOrderCorrect(); } public void testStartableComponentTree() throws Exception { StartableComponent ca = container.lookup( StartableComponent.class, "A-tree" ); assertNotNull( ca ); ca.assertStartOrderCorrect(); container.dispose(); ca.assertStopOrderCorrect(); } public void testLookupCircularity() throws Exception { try { container.lookup( CircularComponent.class, "A" ); fail("Expected ComponentLookupException due to circularity"); } catch ( ComponentLookupException e ) { // todo actually test nested exception is as expected when } } public void testAddComponent() throws Exception { LiveComponent live = new LiveComponent(); container.addComponent( live, LiveComponent.class.getName() ); LiveComponent c = container.lookup( LiveComponent.class ); assertSame( live, c ); } public void testComponentOverride() throws Exception { assertNotNull( container.lookup( Component.class ) ); Component live = new Component() { public Activity getActivity() { return null; } public String getHost() { return null; } public int getPort() { return 0; } }; container.addComponent( live, Component.class, null ); assertSame( live, container.lookup( Component.class ) ); } public void testUpdateOfActiveComponentCollectionUponChangeOfThreadContextClassLoader() throws Exception { ComponentManager manager = container.lookup( ComponentManager.class ); Map map = manager.getMap(); assertNotNull( map ); assertEquals( 0, map.size() ); List list = manager.getList(); assertNotNull( list ); assertEquals( 0, list.size() ); /* * Below we're creating two realms which basically contain the same components, only their bytecode/version * differs. When we switch the thread's context class loader, the active component collections in the component * manager must accurately reflect the components from the current realm (and not from a previous realm). */ ClassRealm realmA = container.createChildRealm( "realm-a" ); realmA.addURL( new File( "src/test/test-components/component-a-1.0-SNAPSHOT.jar" ).toURI().toURL() ); container.discoverComponents( realmA ); ClassRealm realmB = container.createChildRealm( "realm-b" ); realmB.addURL( new File( "src/test/test-components/component-a-2.0-SNAPSHOT.jar" ).toURI().toURL() ); container.discoverComponents( realmB ); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( realmA ); map = manager.getMap(); assertNotNull( map ); assertEquals( 1, map.size() ); assertSame( realmA, map.values().iterator().next().getClass().getClassLoader() ); list = manager.getList(); assertNotNull( list ); assertEquals( 1, list.size() ); assertSame( realmA, list.iterator().next().getClass().getClassLoader() ); Thread.currentThread().setContextClassLoader( realmB ); map = manager.getMap(); assertNotNull( map ); assertEquals( 1, map.size() ); assertSame( realmB, map.values().iterator().next().getClass().getClassLoader() ); list = manager.getList(); assertNotNull( list ); assertEquals( 1, list.size() ); assertSame( realmB, list.iterator().next().getClass().getClassLoader() ); } finally { Thread.currentThread().setContextClassLoader( oldClassLoader ); } } public void testUpdateOfActiveComponentCollectionUponChangeOfThreadContextClassLoaderFromParentToChildRealm() throws Exception { ComponentManager manager = container.lookup( ComponentManager.class ); Map map = manager.getMap(); assertNotNull( map ); assertEquals( 0, map.size() ); List list = manager.getList(); assertNotNull( list ); assertEquals( 0, list.size() ); /* * Below we're creating two realms which basically contain the same components, only their bytecode/version * differs. The realms form a parent-child relationship where the child imports the component role from the * parent. When we first load from the parent and then switch the thread's context class loader to the child, * the active component collections in the component manager must accurately reflect the components from the * current realm (and not from a previous realm). */ ClassRealm realmA = container.createChildRealm( "realm-a" ); realmA.addURL( new File( "src/test/test-components/component-a-1.0-SNAPSHOT.jar" ).toURI().toURL() ); container.discoverComponents( realmA ); ClassRealm realmB = realmA.createChildRealm( "realm-b" ); realmB.importFrom( realmA, "org.codehaus.plexus.components.A" ); realmB.importFromParent( "nothing" ); realmB.addURL( new File( "src/test/test-components/component-a-2.0-SNAPSHOT.jar" ).toURI().toURL() ); container.discoverComponents( realmB ); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( realmA ); map = manager.getMap(); assertNotNull( map ); assertEquals( 1, map.size() ); assertSame( realmA, map.values().iterator().next().getClass().getClassLoader() ); list = manager.getList(); assertNotNull( list ); assertEquals( 1, list.size() ); assertSame( realmA, list.iterator().next().getClass().getClassLoader() ); Thread.currentThread().setContextClassLoader( realmB ); map = manager.getMap(); assertNotNull( map ); assertEquals( 1, map.size() ); assertSame( realmB, map.values().iterator().next().getClass().getClassLoader() ); list = manager.getList(); assertNotNull( list ); assertEquals( 1, list.size() ); assertSame( realmB, list.iterator().next().getClass().getClassLoader() ); } finally { Thread.currentThread().setContextClassLoader( oldClassLoader ); } } public void testComponentLookupFromParentRealmOfImportedRealms() throws Exception { ComponentManager manager = container.lookup( ComponentManager.class ); Map map = manager.getMap(); assertNotNull( map ); assertEquals( 0, map.size() ); List list = manager.getList(); assertNotNull( list ); assertEquals( 0, list.size() ); URL componentUrl = new File( "src/test/test-components/component-a-1.0-SNAPSHOT.jar" ).toURI().toURL(); ClassRealm realmP = container.createChildRealm( "parent-of-imported-realm" ); realmP.addURL( componentUrl ); container.discoverComponents( realmP ); ClassRealm realmI = realmP.createChildRealm( "imported-realm" ); ClassRealm realmL = container.createChildRealm( "lookup-realm" ); realmL.importFrom( realmI, "org.something" ); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( realmL ); map = manager.getMap(); assertNotNull( map ); assertEquals( 1, map.size() ); assertSame( realmP, map.values().iterator().next().getClass().getClassLoader() ); list = manager.getList(); assertNotNull( list ); assertEquals( 1, list.size() ); assertSame( realmP, list.iterator().next().getClass().getClassLoader() ); } finally { Thread.currentThread().setContextClassLoader( oldClassLoader ); } } public void testOptionalComponentRequirement() throws Exception { DefaultComponentWithOptionalRequirement ca = (DefaultComponentWithOptionalRequirement) container.lookup( Component.class, "with-optional" ); assertNotNull( ca ); assertNotNull( ca.getActivity() ); assertNull( ca.optionalComponent ); } public void testLookupOfComponentThatHasARequirementWithoutRoleHintAndTheOneAndOnlyImplHasNoDefaultHint() throws Exception { DefaultThingUser component = (DefaultThingUser) container.lookup( ThingUser.class ); assertNotNull( component.thing ); } public void testSingleLookupWithAndWithoutRoleHint() throws Exception { ComponentWithRoleDefault withRoleHint = container.lookup( ComponentWithRoleDefault.class, "default" ); ComponentWithRoleDefault withoutRoleHint = container.lookup( ComponentWithRoleDefault.class ); assertSame( withRoleHint, withoutRoleHint ); } public void testLookupUponChangeOfThreadContextClassLoaderFromParentToChildRealm() throws Exception { /* * Below we're creating two realms which basically contain the same components, only their bytecode/version * differs. The realms form a parent-child relationship where the child imports the component role from the * parent. When we first lookup from the parent and then switch the thread's context class loader to the child, * the second lookup must accurately reflect the components from the current realm (and not from a previous * realm). */ ClassRealm realmA = container.createChildRealm( "realm-a" ); realmA.addURL( new File( "src/test/test-components/component-a-1.0-SNAPSHOT.jar" ).toURI().toURL() ); container.discoverComponents( realmA ); ClassRealm realmB = realmA.createChildRealm( "realm-b" ); realmB.importFrom( realmA, "org.codehaus.plexus.components.A" ); realmB.importFromParent( "nothing" ); realmB.addURL( new File( "src/test/test-components/component-a-2.0-SNAPSHOT.jar" ).toURI().toURL() ); container.discoverComponents( realmB ); Class role = realmA.loadClass( "org.codehaus.plexus.components.A" ); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( realmA ); Object comp1 = container.lookup( role, "default" ); Thread.currentThread().setContextClassLoader( realmB ); Object comp2 = container.lookup( role, "default" ); assertNotNull( comp1 ); assertNotNull( comp2 ); assertNotSame( comp1, comp2 ); assertSame( realmA, comp1.getClass().getClassLoader() ); assertSame( realmB, comp2.getClass().getClassLoader() ); } finally { Thread.currentThread().setContextClassLoader( oldClassLoader ); } } public void testSafeConcurrentAccessToActiveComponentCollection() throws Exception { ComponentManager manager = container.lookup( ComponentManager.class ); final Map map = manager.getMap(); assertNotNull( map ); assertEquals( 0, map.size() ); final List list = manager.getList(); assertNotNull( list ); assertEquals( 0, list.size() ); final AtomicBoolean go = new AtomicBoolean( false ); final List exceptions = new CopyOnWriteArrayList(); Thread[] threads = new Thread[64]; final CountDownLatch latch = new CountDownLatch( threads.length ); for ( int i = 0; i < threads.length; i++ ) { threads[i] = new Thread() { @Override public void run() { try { ClassRealm realm = container.createChildRealm( "realm-" + UUID.randomUUID().toString() ); realm.addURL( new File( "src/test/test-components/component-a-1.0-SNAPSHOT.jar" ).toURI().toURL() ); container.discoverComponents( realm ); Thread.currentThread().setContextClassLoader( realm ); while ( !go.get() ) { // just wait } for ( int j = 0; j < 1000; j++ ) { // this just must not die with some exception for ( Object value : map.values() ) { value.toString(); } for ( Object value : list ) { value.toString(); } } } catch ( Exception e ) { e.printStackTrace(); exceptions.add( e ); } finally { latch.countDown(); } } }; threads[i].start(); } go.set( true ); latch.await(); assertTrue( exceptions.toString(), exceptions.isEmpty() ); } } ServiceB.java000066400000000000000000000013271166327066700342320ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface ServiceB { static String ROLE = ServiceB.class.getName(); } ServiceC.java000066400000000000000000000013271166327066700342330ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface ServiceC { static String ROLE = ServiceC.class.getName(); } ServiceD.java000066400000000000000000000013271166327066700342340ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface ServiceD { static String ROLE = ServiceD.class.getName(); } ServiceE.java000066400000000000000000000013271166327066700342350ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface ServiceE { static String ROLE = ServiceE.class.getName(); } ServiceH.java000066400000000000000000000013271166327066700342400ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface ServiceH { static String ROLE = ServiceH.class.getName(); } SimpleLifecycleHandler.java000066400000000000000000000017671166327066700371070ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.lifecycle.AbstractLifecycleHandler; /** * * * @author Jason van Zyl * * @version $Id: SimpleLifecycleHandler.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class SimpleLifecycleHandler extends AbstractLifecycleHandler { public String getId() { return "simple"; } public void initialize() { } } StartableComponent.java000066400000000000000000000005731166327066700363360ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; import java.util.concurrent.atomic.AtomicInteger; public interface StartableComponent { static String ROLE = StartableComponent.class.getName(); AtomicInteger startGenerator = new AtomicInteger( 1 ); AtomicInteger stopGenerator = new AtomicInteger( 1 ); void assertStartOrderCorrect(); void assertStopOrderCorrect(); } Thing.java000066400000000000000000000012421166327066700335750ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface Thing { } ThingUser.java000066400000000000000000000012461166327066700344400ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/testpackage org.codehaus.plexus.test; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public interface ThingUser { } 000077500000000000000000000000001166327066700336215ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/lifecycle000077500000000000000000000000001166327066700347215ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/lifecycle/phaseEeny.java000066400000000000000000000014521166327066700364660ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/lifecycle/phasepackage org.codehaus.plexus.test.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: Eeny.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Eeny { void eeny(); } EenyPhase.java000066400000000000000000000021051166327066700374430ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/lifecycle/phasepackage org.codehaus.plexus.test.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class EenyPhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) { if ( object instanceof Eeny ) { ( (Eeny) object ).eeny(); } } } Meeny.java000066400000000000000000000014551166327066700366460ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/lifecycle/phasepackage org.codehaus.plexus.test.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: Meeny.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Meeny { void meeny(); } MeenyPhase.java000066400000000000000000000021111166327066700376150ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/lifecycle/phasepackage org.codehaus.plexus.test.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class MeenyPhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) { if ( object instanceof Meeny ) { ( (Meeny) object ).meeny(); } } } Miny.java000066400000000000000000000014521166327066700365020ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/lifecycle/phasepackage org.codehaus.plexus.test.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: Miny.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Miny { void miny(); } MinyPhase.java000066400000000000000000000021051166327066700374570ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/lifecycle/phasepackage org.codehaus.plexus.test.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class MinyPhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) { if ( object instanceof Miny ) { ( (Miny) object ).miny(); } } } Mo.java000066400000000000000000000014441166327066700361420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/lifecycle/phasepackage org.codehaus.plexus.test.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: Mo.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Mo { void mo(); } MoPhase.java000066400000000000000000000020751166327066700371240ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/lifecycle/phasepackage org.codehaus.plexus.test.lifecycle.phase; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.manager.ComponentManager; import org.codehaus.plexus.lifecycle.phase.AbstractPhase; public class MoPhase extends AbstractPhase { public void execute( Object object, ComponentManager manager, ClassRealm lookupRealm ) { if ( object instanceof Mo ) { ( (Mo) object ).mo(); } } } plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/list/000077500000000000000000000000001166327066700327145ustar00rootroot00000000000000AbstractValve.java000066400000000000000000000017241166327066700362450ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/listpackage org.codehaus.plexus.test.list; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: AbstractValve.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public abstract class AbstractValve implements Valve { private boolean state; public boolean getState() { return state; } public void execute() { state = true; } } DefaultPipeline.java000066400000000000000000000023331166327066700365530ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/listpackage org.codehaus.plexus.test.list; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Iterator; import java.util.List; import java.util.Map; /** * * * @author Jason van Zyl * * @version $Id: DefaultPipeline.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultPipeline implements Pipeline { private List valves; private Map valveMap; public void execute() { for ( Iterator i = valves.iterator(); i.hasNext(); ) { ((Valve) i.next()).execute(); } } public List getValves() { return valves; } public Map getValveMap() { return valveMap; } } Pipeline.java000066400000000000000000000016651166327066700352550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/listpackage org.codehaus.plexus.test.list; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.List; import java.util.Map; /** * @author Jason van Zyl * * @version $Id: Pipeline.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Pipeline { static String ROLE = Pipeline.class.getName(); void execute(); List getValves(); Map getValveMap(); } Valve.java000066400000000000000000000015571166327066700345650ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/listpackage org.codehaus.plexus.test.list; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: Valve.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Valve { static String ROLE = Valve.class.getName(); void execute(); boolean getState(); } ValveFour.java000066400000000000000000000014551166327066700354160ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/listpackage org.codehaus.plexus.test.list; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ValveFour.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ValveFour extends AbstractValve { }ValveOne.java000066400000000000000000000014551166327066700352240ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/listpackage org.codehaus.plexus.test.list; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ValveOne.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ValveOne extends AbstractValve { } ValveThree.java000066400000000000000000000014571166327066700355540ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/listpackage org.codehaus.plexus.test.list; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ValveThree.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ValveThree extends AbstractValve { }ValveTwo.java000066400000000000000000000014551166327066700352540ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/listpackage org.codehaus.plexus.test.list; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ValveTwo.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ValveTwo extends AbstractValve { } plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/map/000077500000000000000000000000001166327066700325165ustar00rootroot00000000000000AbstractActivity.java000066400000000000000000000017341166327066700365670ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/mappackage org.codehaus.plexus.test.map; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: AbstractActivity.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public abstract class AbstractActivity implements Activity { private boolean state; public boolean getState() { return state; } public void execute() { state = true; } } Activity.java000066400000000000000000000015671166327066700351070ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/mappackage org.codehaus.plexus.test.map; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: Activity.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface Activity { static String ROLE = Activity.class.getName(); void execute(); boolean getState(); } ActivityManager.java000066400000000000000000000017071166327066700363760ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/mappackage org.codehaus.plexus.test.map; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ActivityManager.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public interface ActivityManager { static String ROLE = ActivityManager.class.getName(); void execute( String id ); Activity getActivity( String id ); int getActivityCount(); } ActivityOne.java000066400000000000000000000014651166327066700355460ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/mappackage org.codehaus.plexus.test.map; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ActivityOne.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ActivityOne extends AbstractActivity { } ActivityTwo.java000066400000000000000000000014651166327066700355760ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/mappackage org.codehaus.plexus.test.map; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * * * @author Jason van Zyl * * @version $Id: ActivityTwo.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class ActivityTwo extends AbstractActivity { } DefaultActivityManager.java000066400000000000000000000022231166327066700376750ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/mappackage org.codehaus.plexus.test.map; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Map; /** * * * @author Jason van Zyl * * @version $Id: DefaultActivityManager.java 7089 2007-11-25 15:19:06Z jvanzyl $ */ public class DefaultActivityManager implements ActivityManager { private Map activities; public void execute( String id ) { getActivity( id ).execute(); } public Activity getActivity( String id ) { return (Activity) activities.get( id ); } public int getActivityCount() { return activities.size(); } } NoComponentsMapTest.java000066400000000000000000000021531166327066700372230ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/java/org/codehaus/plexus/test/mappackage org.codehaus.plexus.test.map; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusTestCase; /** * @author Trygve Laugstøl * @version $Id: NoComponentsMapTest.java 7828 2008-11-14 22:07:56Z dain $ */ public class NoComponentsMapTest extends PlexusTestCase { public void testNoComponents() throws Exception { ActivityManager manager; manager = lookup( ActivityManager.class ); assertEquals( 0, manager.getActivityCount() ); } } plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/000077500000000000000000000000001166327066700261515ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/META-INF/000077500000000000000000000000001166327066700273115ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/META-INF/plexus/000077500000000000000000000000001166327066700306315ustar00rootroot00000000000000components.xml000066400000000000000000000012761166327066700334670ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/META-INF/plexus org.codehaus.plexus.component.discovery.DiscoveredComponent org.codehaus.plexus.component.discovery.DefaultDiscoveredComponent org.codehaus.plexus.component.factory.ComponentFactory testFactory2 org.codehaus.plexus.component.factory.TestComponentFactory2 plexus monkey 1.0 plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/META-INF/plexus/plexus.xml000066400000000000000000000007451166327066700327010ustar00rootroot00000000000000 org.codehaus.plexus.component.factory.ComponentFactory testFactory1 org.codehaus.plexus.component.factory.TestComponentFactory1 org.codehaus.plexus.test.CountInstancesComponent org.codehaus.plexus.test.CountInstancesComponent plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/application/000077500000000000000000000000001166327066700304545ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/application/components.xml000066400000000000000000000023141166327066700333630ustar00rootroot00000000000000 server two three four one two three configuration-mapping.xml000066400000000000000000000023371166327066700354240ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/application 8080 localhost Santa Claus santa@northpole.com email Email irc Irc one one one plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/application/sentinel.xml000066400000000000000000000010371166327066700330200ustar00rootroot00000000000000 8080 localhost Santa Claus santa@northpole.com email Email irc Irc one one one inline-configuration.properties000066400000000000000000000000441166327066700343310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resourcesfirst-name=andrew last-name=williamsplexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/inline-configuration.xml000066400000000000000000000001241166327066700330130ustar00rootroot00000000000000 jason van zyl plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/000077500000000000000000000000001166327066700267405ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/000077500000000000000000000000001166327066700305335ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/000077500000000000000000000000001166327066700320535ustar00rootroot00000000000000PlexusTestCaseTest.xml000066400000000000000000000005621166327066700362750ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus org.codehaus.plexus.test.LoadOnStartService org.codehaus.plexus.test.LoadOnStartService org.codehaus.plexus.test.DefaultLoadOnStartService 000077500000000000000000000000001166327066700337765ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component000077500000000000000000000000001166327066700363415ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/composition000077500000000000000000000000001166327066700402005ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/composition/autowireAutowireCompositionTest.xml000066400000000000000000000007211166327066700456050ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/composition/autowire org.codehaus.plexus.component.composition.autowire.One org.codehaus.plexus.component.composition.autowire.DefaultOne org.codehaus.plexus.component.composition.autowire.Two org.codehaus.plexus.component.composition.autowire.DefaultTwo components.xml000066400000000000000000000042361166327066700412550ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/composition org.codehaus.plexus.component.composition.ComponentA org.codehaus.plexus.component.composition.DefaultComponentA field org.codehaus.plexus.component.composition.ComponentB localhost 10000 org.codehaus.plexus.component.composition.ComponentB org.codehaus.plexus.component.composition.DefaultComponentB setter org.codehaus.plexus.component.composition.ComponentC org.codehaus.plexus.component.composition.ComponentC org.codehaus.plexus.component.composition.DefaultComponentC 000077500000000000000000000000001166327066700376475ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/composition/setterSetterCompositionTest.xml000066400000000000000000000017621166327066700447310ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/composition/setter org.codehaus.plexus.component.composition.setter.Component org.codehaus.plexus.component.composition.setter.ChildComponent setter org.codehaus.plexus.component.composition.ComponentA org.codehaus.plexus.component.composition.ComponentB org.codehaus.plexus.component.composition.ComponentA org.codehaus.plexus.component.composition.DefaultComponentA org.codehaus.plexus.component.composition.ComponentB org.codehaus.plexus.component.composition.DefaultComponentB 000077500000000000000000000000001166327066700354455ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/factory000077500000000000000000000000001166327066700371015ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/factory/nonjavaNonJavaComponentFactoryTest.xml000066400000000000000000000004561166327066700452370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/factory/nonjava org.codehaus.plexus.component.factory.ComponentFactory nonjava org.codehaus.plexus.component.factory.nonjava.NonJavaComponentFactory 000077500000000000000000000000001166327066700354105ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/managerClassicSingletonComponentManagerTest.xml000066400000000000000000000004011166327066700454070ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/manager org.codehaus.plexus.component.manager.Component org.codehaus.plexus.component.manager.DefaultComponent SlowComponentClassicSingletonComponentManagerTest.xml000066400000000000000000000005121166327066700501420ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/component/manager org.codehaus.plexus.component.manager.SlowComponent org.codehaus.plexus.component.manager.SlowComponent 300 components.xml000066400000000000000000000007261166327066700347100ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus org.codehaus.plexus.test.ComponentA one org.codehaus.plexus.test.DefaultComponentA org.codehaus.plexus.test.ComponentA two org.codehaus.plexus.test.DefaultComponentA 000077500000000000000000000000001166327066700346435ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/configurationavalon.xml000066400000000000000000000142051166327066700366470ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/configuration ${foo.home}/jars ${my.home}/resources user-conf-dir logging-implementation INFO org.codehaus.plexus.personality.avalon.AvalonComponentRepository frankie custom custom avalon avalon Avalon Lifecycle Handler org.codehaus.plexus.ServiceA org.codehaus.plexus.DefaultServiceA org.codehaus.plexus.ServiceB org.codehaus.plexus.DefaultServiceB org.codehaus.plexus.ServiceC first-instance org.codehaus.plexus.DefaultServiceC org.codehaus.plexus.ServiceC second-instance org.codehaus.plexus.DefaultServiceC org.codehaus.plexus.ServiceE org.codehaus.plexus.DefaultServiceE per-lookup org.codehaus.plexus.ServiceG org.codehaus.plexus.DefaultServiceG singleton org.codehaus.plexus.ServiceH org.codehaus.plexus.DefaultServiceH arbitrary org.codehaus.plexus.LoadOnStartService org.codehaus.plexus.DefaultLoadOnStartService org.codehaus.plexus.LoadOnStartServiceWithRoleHint role-hint org.codehaus.plexus.DefaultLoadOnStartServiceWithRoleHint org.codehaus.plexus.ConfigureService org.codehaus.plexus.DefaultConfigureService singleton 1 2 000077500000000000000000000000001166327066700361435ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/configuration/sourceExtendingConfigurationSourceTest.xml000066400000000000000000000013751166327066700453710ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/configuration/source org.codehaus.plexus.configuration.source.ConfigurationSource dummy org.codehaus.plexus.configuration.source.ADummyConfigurationSource org.codehaus.plexus.configuration.source.ConfigurationSource anotherDummy org.codehaus.plexus.configuration.source.AnotherDummyConfigurationSource org.codehaus.plexus.configuration.source.ConfigurationSource dummy OverridingConfigurationSourceTest.xml000066400000000000000000000004611166327066700455470ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/configuration/source org.codehaus.plexus.configuration.source.ConfigurationSource default org.codehaus.plexus.configuration.source.ADummyConfigurationSource plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/embed/000077500000000000000000000000001166327066700331275ustar00rootroot00000000000000EmbedderTest.xml000066400000000000000000000010341166327066700361370ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/embed ${basedir}/test-input org.codehaus.plexus.embed.MockComponent default org.codehaus.plexus.embed.MockComponent org.codehaus.plexus.embed.MockComponent foo org.codehaus.plexus.embed.MockComponent 000077500000000000000000000000001166327066700337525ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/hierarchyChildPlexusOne.xml000066400000000000000000000023201166327066700373570ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/hierarchy org.codehaus.plexus.logging.console.ConsoleLoggerManager ERROR org.codehaus.plexus.hierarchy.PlexusTestService default org.codehaus.plexus.hierarchy.TestServiceImpl three blind mice org.codehaus.plexus.hierarchy.PlexusTestService hinted org.codehaus.plexus.hierarchy.TestServiceImpl plexus one overriding hinted service org.codehaus.plexus.hierarchy.PlexusTestService local org.codehaus.plexus.hierarchy.TestServiceImpl plexus one local service ChildPlexusTwo.xml000066400000000000000000000015751166327066700374220ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/hierarchy org.codehaus.plexus.logging.console.ConsoleLoggerManager ERROR org.codehaus.plexus.hierarchy.PlexusTestService default org.codehaus.plexus.hierarchy.TestServiceImpl see how they run org.codehaus.plexus.hierarchy.PlexusTestService local org.codehaus.plexus.hierarchy.TestServiceImpl plexus two local service PlexusHierarchyTest.xml000066400000000000000000000043431166327066700404570ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/hierarchy org.codehaus.plexus.logging.console.ConsoleLoggerManager ERROR org.codehaus.plexus.PlexusContainerManager default org.codehaus.plexus.SimplePlexusContainerManager org/codehaus/plexus/hierarchy/ChildPlexusOne.xml plexus-name ChildPlexusOne org.codehaus.plexus.PlexusContainerManager two org.codehaus.plexus.SimplePlexusContainerManager org/codehaus/plexus/hierarchy/ChildPlexusTwo.xml plexus-name ChildPlexusTwo org.codehaus.plexus.hierarchy.PlexusTestService default org.codehaus.plexus.hierarchy.TestServiceImpl cheesy default service org.codehaus.plexus.hierarchy.PlexusTestService hinted org.codehaus.plexus.hierarchy.TestServiceImpl hinted default service org.codehaus.plexus.hierarchy.PlexusTestService global org.codehaus.plexus.hierarchy.TestServiceImpl globally visible service plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/logging/000077500000000000000000000000001166327066700335015ustar00rootroot00000000000000CustomLoggerManagerTest.xml000066400000000000000000000003451166327066700407130ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/logging org.codehaus.plexus.logging.LoggerManager org.codehaus.plexus.logging.MockLoggerManager 000077500000000000000000000000001166327066700350645ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/logging/consoleConsoleLoggerManagerTest.xml000066400000000000000000000011101166327066700424740ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/logging/console org.codehaus.plexus.logging.LoggerManager org.codehaus.plexus.logging.console.ConsoleLoggerManager basic per-lookup fatal plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/test/000077500000000000000000000000001166327066700330325ustar00rootroot00000000000000PlexusContainerTest.xml000066400000000000000000000401041166327066700374570ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/test ${basedir}/src/test-input/configurations-directory org.codehaus.plexus.test.ServiceB org.codehaus.plexus.test.DefaultServiceB org.codehaus.plexus.test.ServiceC first-instance org.codehaus.plexus.test.DefaultServiceC org.codehaus.plexus.test.ServiceC second-instance org.codehaus.plexus.test.DefaultServiceC org.codehaus.plexus.test.ServiceD org.codehaus.plexus.test.DefaultServiceD org.codehaus.plexus.test.ServiceE org.codehaus.plexus.test.DefaultServiceE plexus-configurable org.codehaus.plexus.test.ServiceH org.codehaus.plexus.test.DefaultServiceH arbitrary org.codehaus.plexus.test.LoadOnStartService org.codehaus.plexus.test.DefaultLoadOnStartService org.codehaus.plexus.test.LoadOnStartServiceWithRoleHint role-hint org.codehaus.plexus.test.DefaultLoadOnStartServiceWithRoleHint org.codehaus.plexus.logging.LoggerManager org.codehaus.plexus.logging.console.ConsoleLoggerManager basic fatal org.codehaus.plexus.test.Component org.codehaus.plexus.test.DefaultComponent org.codehaus.plexus.test.map.Activity one localhost 10000 org.codehaus.plexus.test.Component org.codehaus.plexus.test.DefaultComponentWithOptionalRequirement with-optional org.codehaus.plexus.test.map.Activity one activity org.codehaus.plexus.test.NonAvailableComponent missing optionalComponent true org.codehaus.plexus.test.ComponentA org.codehaus.plexus.test.DefaultComponentA org.codehaus.plexus.test.ComponentB org.codehaus.plexus.test.ComponentC localhost 10000 org.codehaus.plexus.test.ComponentB org.codehaus.plexus.test.DefaultComponentB org.codehaus.plexus.test.ComponentC org.codehaus.plexus.test.DefaultComponentC org.codehaus.plexus.test.ComponentD org.codehaus.plexus.test.ComponentD org.codehaus.plexus.test.DefaultComponentD jason org.codehaus.plexus.test.map.ActivityManager org.codehaus.plexus.test.map.DefaultActivityManager org.codehaus.plexus.test.map.Activity activities org.codehaus.plexus.test.map.ActivityManager slim org.codehaus.plexus.test.map.DefaultActivityManager org.codehaus.plexus.test.map.Activity activities one org.codehaus.plexus.test.map.Activity one org.codehaus.plexus.test.map.ActivityOne per-lookup org.codehaus.plexus.test.map.Activity two org.codehaus.plexus.test.map.ActivityTwo org.codehaus.plexus.test.list.Pipeline default org.codehaus.plexus.test.list.DefaultPipeline org.codehaus.plexus.test.list.Valve valves org.codehaus.plexus.test.list.Pipeline slim org.codehaus.plexus.test.list.DefaultPipeline org.codehaus.plexus.test.list.Valve valves one org.codehaus.plexus.test.list.Pipeline chubby org.codehaus.plexus.test.list.DefaultPipeline org.codehaus.plexus.test.list.Valve valveMap one two three four org.codehaus.plexus.test.list.Valve four org.codehaus.plexus.test.list.ValveFour org.codehaus.plexus.test.list.Valve three org.codehaus.plexus.test.list.ValveThree org.codehaus.plexus.test.list.Valve two org.codehaus.plexus.test.list.ValveTwo org.codehaus.plexus.test.list.Valve one org.codehaus.plexus.test.list.ValveOne per-lookup org.codehaus.plexus.test.ComponentManager org.codehaus.plexus.test.DefaultComponentManager org.codehaus.plexus.components.A list org.codehaus.plexus.components.A map org.codehaus.plexus.logging.LoggerManager org.codehaus.plexus.logging.console.ConsoleLoggerManager basic fatal org.codehaus.plexus.test.Component ComponentMissingRequirements org.codehaus.plexus.test.DefaultComponent NonExistingComponent org.codehaus.plexus.test.StartableComponent A-snake org.codehaus.plexus.test.DefaultStartableComponentA org.codehaus.plexus.test.StartableComponent B-snake component1 org.codehaus.plexus.test.StartableComponent B-snake org.codehaus.plexus.test.DefaultStartableComponentB org.codehaus.plexus.test.StartableComponent C-snake component1 org.codehaus.plexus.test.StartableComponent C-snake org.codehaus.plexus.test.DefaultStartableComponentC org.codehaus.plexus.test.StartableComponent D-snake component1 org.codehaus.plexus.test.StartableComponent D-snake org.codehaus.plexus.test.DefaultStartableComponentD org.codehaus.plexus.test.StartableComponent E-snake component1 org.codehaus.plexus.test.StartableComponent E-snake org.codehaus.plexus.test.DefaultStartableComponentE org.codehaus.plexus.test.StartableComponent A-tree org.codehaus.plexus.test.DefaultStartableComponentA org.codehaus.plexus.test.StartableComponent B-tree component1 org.codehaus.plexus.test.StartableComponent C-tree component2 org.codehaus.plexus.test.StartableComponent B-tree org.codehaus.plexus.test.DefaultStartableComponentB org.codehaus.plexus.test.StartableComponent D-tree component1 org.codehaus.plexus.test.StartableComponent E-tree component2 org.codehaus.plexus.test.StartableComponent C-tree org.codehaus.plexus.test.DefaultStartableComponentC org.codehaus.plexus.test.StartableComponent D-tree org.codehaus.plexus.test.DefaultStartableComponentD org.codehaus.plexus.test.StartableComponent E-tree org.codehaus.plexus.test.DefaultStartableComponentE org.codehaus.plexus.test.CircularComponent A org.codehaus.plexus.test.DefaultCircularComponent org.codehaus.plexus.test.CircularComponent B requirement org.codehaus.plexus.test.CircularComponent B org.codehaus.plexus.test.DefaultCircularComponent org.codehaus.plexus.PlexusContainer container A org.codehaus.plexus.test.Thing concrete org.codehaus.plexus.test.ConcreteThing org.codehaus.plexus.test.ThingUser org.codehaus.plexus.test.DefaultThingUser org.codehaus.plexus.test.Thing thing org.codehaus.plexus.test.ComponentWithRoleDefault org.codehaus.plexus.test.ComponentWithRoleDefault default plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/test/map/000077500000000000000000000000001166327066700336075ustar00rootroot00000000000000NoComponentsMapTest.xml000066400000000000000000000020061166327066700401700ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/org/codehaus/plexus/test/map org.codehaus.plexus.logging.console.ConsoleLoggerManager INFO org.codehaus.plexus.test.map.ActivityManager org.codehaus.plexus.test.map.DefaultActivityManager org.codehaus.plexus.test.map.Activity activities plexus-containers1.5-1.5.5/plexus-container-default/src/test/resources/test.txt000066400000000000000000000000161166327066700276660ustar00rootroot00000000000000This is a testplexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/000077500000000000000000000000001166327066700303765ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a/000077500000000000000000000000001166327066700326165ustar00rootroot00000000000000pom.xml000066400000000000000000000055771166327066700340720ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a 4.0.0 org.codehaus.plexus.components component-a 1.0-SNAPSHOT component-a org.codehaus.plexus plexus-maven-plugin 1.3.3 descriptor plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a/src/000077500000000000000000000000001166327066700334055ustar00rootroot00000000000000000077500000000000000000000000001166327066700342525ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a/src/main000077500000000000000000000000001166327066700351735ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a/src/main/java000077500000000000000000000000001166327066700357625ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a/src/main/java/org000077500000000000000000000000001166327066700375555ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a/src/main/java/org/codehaus000077500000000000000000000000001166327066700410755ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a/src/main/java/org/codehaus/plexus000077500000000000000000000000001166327066700432625ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a/src/main/java/org/codehaus/plexus/componentsA.java000066400000000000000000000001301166327066700442770ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a/src/main/java/org/codehaus/plexus/componentspackage org.codehaus.plexus.components; public interface A { public void hello(); } DefaultA.java000066400000000000000000000003031166327066700456060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-a/src/main/java/org/codehaus/plexus/componentspackage org.codehaus.plexus.components; /** * @plexus.component */ public class DefaultA implements A { public void hello() { System.out.println( "Hello World!" ); } } plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b/000077500000000000000000000000001166327066700326175ustar00rootroot00000000000000pom.xml000066400000000000000000000055771166327066700340730ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b 4.0.0 org.codehaus.plexus.components component-b 1.0-SNAPSHOT component-b org.codehaus.plexus plexus-maven-plugin 1.3.3 descriptor plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b/src/000077500000000000000000000000001166327066700334065ustar00rootroot00000000000000000077500000000000000000000000001166327066700342535ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b/src/main000077500000000000000000000000001166327066700351745ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b/src/main/java000077500000000000000000000000001166327066700357635ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b/src/main/java/org000077500000000000000000000000001166327066700375565ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b/src/main/java/org/codehaus000077500000000000000000000000001166327066700410765ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b/src/main/java/org/codehaus/plexus000077500000000000000000000000001166327066700432635ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b/src/main/java/org/codehaus/plexus/componentsB.java000066400000000000000000000001301166327066700443010ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b/src/main/java/org/codehaus/plexus/componentspackage org.codehaus.plexus.components; public interface B { public void hello(); } DefaultB.java000066400000000000000000000003031166327066700456100ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-b/src/main/java/org/codehaus/plexus/componentspackage org.codehaus.plexus.components; /** * @plexus.component */ public class DefaultB implements B { public void hello() { System.out.println( "Hello World!" ); } } plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c/000077500000000000000000000000001166327066700326205ustar00rootroot00000000000000pom.xml000066400000000000000000000055771166327066700340740ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c 4.0.0 org.codehaus.plexus.components component-c 1.0-SNAPSHOT component-c org.codehaus.plexus plexus-maven-plugin 1.3.3 descriptor plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c/src/000077500000000000000000000000001166327066700334075ustar00rootroot00000000000000000077500000000000000000000000001166327066700342545ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c/src/main000077500000000000000000000000001166327066700351755ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c/src/main/java000077500000000000000000000000001166327066700357645ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c/src/main/java/org000077500000000000000000000000001166327066700375575ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c/src/main/java/org/codehaus000077500000000000000000000000001166327066700410775ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c/src/main/java/org/codehaus/plexus000077500000000000000000000000001166327066700432645ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c/src/main/java/org/codehaus/plexus/componentsC.java000066400000000000000000000001301166327066700443030ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c/src/main/java/org/codehaus/plexus/componentspackage org.codehaus.plexus.components; public interface C { public void hello(); } DefaultC.java000066400000000000000000000003031166327066700456120ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/component-c/src/main/java/org/codehaus/plexus/componentspackage org.codehaus.plexus.components; /** * @plexus.component */ public class DefaultC implements C { public void hello() { System.out.println( "Hello World!" ); } } plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/000077500000000000000000000000001166327066700317545ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/pom.xml000066400000000000000000000041231166327066700332710ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus.components plugin0 1.0-SNAPSHOT org.codehaus.plexus.components component-a 1.0-SNAPSHOT org.codehaus.plexus.components component-b 1.0-SNAPSHOT org.codehaus.plexus plexus-archiver 1.0-alpha-7 org.codehaus.plexus plexus-container-default 1.0-beta-2-SNAPSHOT org.codehaus.plexus plexus-maven-plugin 1.3.3 descriptor plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/src/000077500000000000000000000000001166327066700325435ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/src/main/000077500000000000000000000000001166327066700334675ustar00rootroot00000000000000000077500000000000000000000000001166327066700343315ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/src/main/java000077500000000000000000000000001166327066700351205ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/src/main/java/org000077500000000000000000000000001166327066700367135ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/src/main/java/org/codehaus000077500000000000000000000000001166327066700402335ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/src/main/java/org/codehaus/plexus000077500000000000000000000000001166327066700417145ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/src/main/java/org/codehaus/plexus/pluginsAltPlugin0.java000066400000000000000000000030601166327066700445350ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/src/main/java/org/codehaus/plexus/pluginspackage org.codehaus.plexus.plugins; import org.codehaus.plexus.components.A; import org.codehaus.plexus.components.B; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.archiver.manager.ArchiverManager; /** * @plexus.component role-hint="alt" */ public class AltPlugin0 implements Plugin0, Contextualizable { /** @plexus.requirement */ private A a; /** @plexus.requirement */ private B b; /** @plexus.requirement */ private ArchiverManager archiverManager; public void hello() { System.out.println( "Hello World!" ); } // ---------------------------------------------------------------------------- // Lifecycle // ---------------------------------------------------------------------------- public void contextualize( Context context ) throws ContextException { PlexusContainer container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); try { archiverManager = (ArchiverManager) container.lookup( ArchiverManager.ROLE ); } catch ( ComponentLookupException e ) { throw new ContextException( "Error retrieving ArchiverManager instance: " + e.getMessage(), e ); } } } DefaultPlugin0.java000066400000000000000000000030441166327066700454030ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/src/main/java/org/codehaus/plexus/pluginspackage org.codehaus.plexus.plugins; import org.codehaus.plexus.components.A; import org.codehaus.plexus.components.B; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.archiver.manager.ArchiverManager; /** * @plexus.component */ public class DefaultPlugin0 implements Plugin0, Contextualizable { /** @plexus.requirement */ private A a; /** @plexus.requirement */ private B b; /** @plexus.requirement */ private ArchiverManager archiverManager; public void hello() { System.out.println( "Hello World!" ); } // ---------------------------------------------------------------------------- // Lifecycle // ---------------------------------------------------------------------------- public void contextualize( Context context ) throws ContextException { PlexusContainer container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); try { archiverManager = (ArchiverManager) container.lookup( ArchiverManager.ROLE ); } catch ( ComponentLookupException e ) { throw new ContextException( "Error retrieving ArchiverManager instance: " + e.getMessage(), e ); } } } Plugin0.java000066400000000000000000000001331166327066700440720ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin0/src/main/java/org/codehaus/plexus/pluginspackage org.codehaus.plexus.plugins; public interface Plugin0 { public void hello(); } plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/000077500000000000000000000000001166327066700317555ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/pom.xml000066400000000000000000000063371166327066700333030ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus.components plugin1 1.0-SNAPSHOT org.codehaus.plexus.components component-a 1.0-SNAPSHOT org.codehaus.plexus.components component-c 1.0-SNAPSHOT org.codehaus.plexus plexus-maven-plugin 1.3.3 descriptor plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/src/000077500000000000000000000000001166327066700325445ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/src/main/000077500000000000000000000000001166327066700334705ustar00rootroot00000000000000000077500000000000000000000000001166327066700343325ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/src/main/java000077500000000000000000000000001166327066700351215ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/src/main/java/org000077500000000000000000000000001166327066700367145ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/src/main/java/org/codehaus000077500000000000000000000000001166327066700402345ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/src/main/java/org/codehaus/plexus000077500000000000000000000000001166327066700417155ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/src/main/java/org/codehaus/plexus/pluginsAltPlugin1.java000066400000000000000000000006311166327066700445400ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/src/main/java/org/codehaus/plexus/pluginspackage org.codehaus.plexus.plugins; import org.codehaus.plexus.components.A; import org.codehaus.plexus.components.C; /** * @plexus.component role-hint="alt" */ public class AltPlugin1 implements Plugin1 { /** @plexus.requirement */ private A a; /** @plexus.requirement */ private C c; public void hello() { System.out.println( "Hello World!" ); } } DefaultPlugin1.java000066400000000000000000000006151166327066700454060ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/src/main/java/org/codehaus/plexus/pluginspackage org.codehaus.plexus.plugins; import org.codehaus.plexus.components.A; import org.codehaus.plexus.components.C; /** * @plexus.component */ public class DefaultPlugin1 implements Plugin1 { /** @plexus.requirement */ private A a; /** @plexus.requirement */ private C c; public void hello() { System.out.println( "Hello World!" ); } } Plugin1.java000066400000000000000000000001331166327066700440740ustar00rootroot00000000000000plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/plugin1/src/main/java/org/codehaus/plexus/pluginspackage org.codehaus.plexus.plugins; public interface Plugin1 { public void hello(); } plexus-containers1.5-1.5.5/plexus-container-default/src/test/test-component-builds/pom.xml000066400000000000000000000011351166327066700317130ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus.components component-parent 1.0-SNAPSHOT pom component-a component-b component-c plugin0 plugin1 plexus-containers1.5-1.5.5/pom.xml000066400000000000000000000100261166327066700167630ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus plexus 2.0.7 plexus-containers 1.5.5 pom Plexus Containers Plexus IoC Container core with companion tools. plexus-component-annotations plexus-component-metadata plexus-component-javadoc plexus-container-default scm:svn:https://svn.codehaus.org/plexus/plexus-containers/tags/plexus-containers-1.5.5 scm:svn:https://svn.codehaus.org/plexus/plexus-containers/tags/plexus-containers-1.5.5 http://fisheye.codehaus.org/browse/plexus/plexus-containers/tags/plexus-containers-1.5.5 2.2.2 1.4.5 3.4 UTF-8 org.codehaus.plexus plexus-container-default ${project.version} org.codehaus.plexus plexus-component-annotations ${project.version} org.codehaus.plexus plexus-component-metadata ${project.version} org.codehaus.plexus plexus-classworlds ${classWorldsVersion} org.codehaus.plexus plexus-utils ${plexusUtilsVersion} org.apache.xbean xbean-reflect ${xbeanReflectVersion} com.thoughtworks.qdox qdox 1.9.2 jdom jdom 1.0 org.apache.maven maven-plugin-api 2.0.9 org.apache.maven maven-model 2.0.9 org.apache.maven maven-project 2.0.9 com.google.collections google-collections 1.0 junit junit 3.8.2 maven-compiler-plugin 1.5 1.5 ${project.build.sourceEncoding} plexus-containers1.5-1.5.5/src/000077500000000000000000000000001166327066700162365ustar00rootroot00000000000000plexus-containers1.5-1.5.5/src/site/000077500000000000000000000000001166327066700172025ustar00rootroot00000000000000plexus-containers1.5-1.5.5/src/site/apt/000077500000000000000000000000001166327066700177665ustar00rootroot00000000000000plexus-containers1.5-1.5.5/src/site/apt/history.apt000066400000000000000000000061671166327066700222070ustar00rootroot00000000000000 ----- Plexus Containers History ----- Hervé Boutemy ----- 2009-10-03 ----- Plexus Containers History Plexus Containers structure has evolved over time. This document tracks most notable changes around its main module - {{{./plexus-container-default}plexus-container-default}}. *----------------+--------------+------------------------+ | <> | <> | <> | *----------------+--------------+------------------------+ | 1.0-alpha-1 | 2005-01-18 | groupId is plexus, plexus-container-default is child of plexus-containers but not a module | *----------------+--------------+------------------------+ | 1.0-alpha-2 | 2005-04-02 | plexus-containers has plexus-container-artifact and plexus-container-default modules *----------------+--------------+------------------------+ | 1.0-alpha-4 | 2005-06-22 | plexus-containers' version is 1.0, only plexus-container-default is released *----------------+--------------+------------------------+ | 1.0-alpha-6 | 2005-06-22 | plexus-containers' version is 1.0.2, only plexus-container-default is released *----------------+--------------+------------------------+ | 1.0-alpha-7 | 2005-10-03 | plexus-container-default's groupId changed to org.codehaus.plexus, only plexus-container-default is released *----------------+--------------+------------------------+ | 1.0-alpha-9 | 2005-12-07 | plexus-containers' groupId changed to org.codehaus.plexus with version 1.0.3, only plexus-container-default is released *----------------+--------------+------------------------+ | 1.0-alpha-10 | 2006-10-01 | plexus-containers' version is 1.0.6 with plexus-container-default as single module *----------------+--------------+------------------------+ | 1.0-alpha-11 | 2006-11-23 | plexus-containers' version is 1.0.7-alpha-1, with a new plexus-component-api *----------------+--------------+------------------------+ | 1.0-alpha-14 | 2006-12-13 | plexus-containers has now the same version as its plexus-component-api and plexus-container-default modules *----------------+--------------+------------------------+ | 1.0-alpha-33 | 2007-10-16 | addition of {{{./plexus-component-annotations}plexus-component-annotations}} *----------------+--------------+------------------------+ | 1.0-alpha-34 | 2007-10-23 | removal of plexus-component-api, which has been merged into plexus-container-default *----------------+--------------+------------------------+ | 1.0-beta-1 | 2008-09-30 | addition of {{{./plexus-component-metadata}plexus-component-metadata}}, which supersedes {{{/plexus-tools/plexus-cdc/}Plexus Component Descriptor Creator}} and {{{/plexus-maven-plugin}Plexus Maven Plugin}} *----------------+--------------+------------------------+ | 1.0-beta-3.0.1 | 2008-12-01 | addition of {{{./plexus-component-javadoc}plexus-component-javadoc}}, which was previously known as {{{/plexus-tools/plexus-javadoc/}plexus-javadoc in plexus-tools}} *----------------+--------------+------------------------+ | 1.0.0 | 2009-06-19 | no structure change, but the long expected 1.0.0 release... *----------------+--------------+------------------------+ plexus-containers1.5-1.5.5/src/site/apt/index.apt000066400000000000000000000015261166327066700216070ustar00rootroot00000000000000 ----- plexus-containers ----- Hervé Boutemy ----- 2009-10-06 ----- Overview <<>> is Plexus' (IoC) container and companion tools: * {{{./plexus-container-default}plexus-container-default}} is the IoC container itself, * {{{./plexus-component-metadata}plexus-component-metadata}} is a Maven plugin to generate plexus <<<{{{./plexus-container-default/plexus-components.html}component.xml}}>>> from source annotations, * {{{./plexus-component-annotations}plexus-component-annotations}} provides the Java 5 annotations for plexus components, * {{{./plexus-component-javadoc}plexus-component-javadoc}} provides javadoc taglets to add plexus documentation to javadoc. [] <<>>' structure has evolved over time: see {{{./history.html}history}} to understand its changes.plexus-containers1.5-1.5.5/src/site/site.xml000066400000000000000000000004651166327066700206750ustar00rootroot00000000000000