diff --git a/plexus-component-metadata/pom.xml b/plexus-component-metadata/pom.xml index fdad1ae5e..e290dbfb2 100644 --- a/plexus-component-metadata/pom.xml +++ b/plexus-component-metadata/pom.xml @@ -16,10 +16,6 @@ A Maven plugin to generate Plexus Components descriptors from source javadoc tags and Java 5 class annotations. - - org.codehaus.plexus - plexus-container-default - org.codehaus.plexus plexus-component-annotations @@ -36,6 +32,11 @@ org.jdom jdom2 + + org.eclipse.sisu + org.eclipse.sisu.plexus + provided + org.apache.maven maven-plugin-api @@ -63,6 +64,11 @@ 3.8.2 provided + + junit + junit + test + diff --git a/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentDescriptor.java b/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentDescriptor.java deleted file mode 100644 index bc1d6af3a..000000000 --- a/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentDescriptor.java +++ /dev/null @@ -1,704 +0,0 @@ -package 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). - * @param source Set the {@link #source}. - */ - public void setSource( String source ) - { - this.source = source; - } - - /** - * The location this information came from (descriptor file URI). - * @return The {@link #source} - */ - public String getSource() - { - return source; - } - - /** - * Returns a human-friendly key, suitable for display. - * - * @return a human-friendly key - */ - public String getHumanReadableKey() - { - StringBuilder key = new StringBuilder(); - - 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 (Class)roleClass; - } - - private void attemptRoleLoad() - { - if ( roleClass == null && role != null && realm != null ) - { - try - { - roleClass = (Class) 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 = (Class) 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 The component factory. - */ - 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 The strategy. - */ - 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 The component configurator. - */ - 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; - } -} diff --git a/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentRequirement.java b/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentRequirement.java deleted file mode 100644 index 8196b2db3..000000000 --- a/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentRequirement.java +++ /dev/null @@ -1,187 +0,0 @@ -package 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() - { - StringBuilder key = new StringBuilder(); - - 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(); - } -} diff --git a/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentRequirementList.java b/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentRequirementList.java deleted file mode 100644 index f09341218..000000000 --- a/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentRequirementList.java +++ /dev/null @@ -1,43 +0,0 @@ -package 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() - { - StringBuilder buffer = new StringBuilder(); - for ( String hint : roleHints ) - { - if (buffer.length() > 0) - { - buffer.append(","); - } - - buffer.append(hint); - - } - - return buffer.toString(); - } -} diff --git a/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentSetDescriptor.java b/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentSetDescriptor.java deleted file mode 100644 index f4f8f2fd8..000000000 --- a/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/ComponentSetDescriptor.java +++ /dev/null @@ -1,164 +0,0 @@ -package 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() - { - StringBuilder sb = new StringBuilder(); - - 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; - } -} diff --git a/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/README.txt b/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/README.txt deleted file mode 100644 index 601b1586b..000000000 --- a/plexus-component-metadata/src/main/java/org/codehaus/plexus/component/repository/README.txt +++ /dev/null @@ -1,3 +0,0 @@ -This 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. \ No newline at end of file diff --git a/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/DefaultComponentDescriptorWriterTest.java b/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/DefaultComponentDescriptorWriterTest.java index 8fdc743ee..4c27b34ee 100644 --- a/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/DefaultComponentDescriptorWriterTest.java +++ b/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/DefaultComponentDescriptorWriterTest.java @@ -17,20 +17,23 @@ package org.codehaus.plexus.metadata; import java.io.File; +import java.io.StringReader; import java.io.StringWriter; import java.util.Collections; +import java.util.LinkedList; 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.component.repository.*; import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.codehaus.plexus.configuration.PlexusConfigurationException; +import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.metadata.merge.ComponentsXmlMerger; import org.codehaus.plexus.metadata.merge.Merger; import org.codehaus.plexus.metadata.merge.PlexusXmlMerger; +import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.input.SAXBuilder; @@ -80,20 +83,19 @@ public void testBasic() throws Exception { assertTrue(xml.length() != 0); - PlexusConfiguration config = PlexusTools.buildConfiguration(xml); + PlexusConfiguration config = new XmlPlexusConfiguration(Xpp3DomBuilder.build(new StringReader(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); + ComponentSetDescriptor set2 = buildComponentSet(config, realm); assertNotNull(set2); - List components = set2.getComponents(); + 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); + ComponentDescriptor component2 = components.get(0); assertNotNull(component2); assertEquals(component.getRole(), component2.getRole()); @@ -106,7 +108,7 @@ public void testBasic() throws Exception { } public void testComponentsOrder() throws Exception { - MetadataGenerator generator = (MetadataGenerator) lookup(MetadataGenerator.class); + MetadataGenerator generator = lookup(MetadataGenerator.class); assertNotNull(generator); MetadataGenerationRequest request = new MetadataGenerationRequest(); @@ -141,4 +143,112 @@ public void testComponentsOrder() throws Exception { assertEquals("Component 5 role", Merger.class.getName(), components.get(4).getChild("role").getText()); assertEquals("Component 5 impl", PlexusXmlMerger.class.getName(), components.get(4).getChild("implementation").getText()); } + + // TODO copied from PlexusTools.buildConfiguration() - find a better way to do this + // we have duplication here, but we don't want to depend on plexus-container-default + // similar code in AnnotationComponentGleaner.glean() and QDoxComponentGleaner.findRequirements() + private static ComponentSetDescriptor buildComponentSet( PlexusConfiguration c, ClassRealm realm ) + throws PlexusConfigurationException + { + ComponentSetDescriptor csd = new ComponentSetDescriptor(); + for (PlexusConfiguration component : c.getChild( "components" ).getChildren( "component" )) { + csd.addComponentDescriptor(buildComponentDescriptorImpl(component, realm)); + } + + for (PlexusConfiguration d : c.getChild( "dependencies" ).getChildren( "dependency" )) { + 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; + } + + 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")); + } + + // ---------------------------------------------------------------------- + // 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 + // ---------------------------------------------------------------------- + for (PlexusConfiguration requirement : configuration.getChild( "requirements" ) + .getChildren( "requirement" )) { + 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; + } } diff --git a/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/AnnotationComponentGleanerTest.java b/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/AnnotationComponentGleanerTest.java index 291f9e1e7..e152526a2 100644 --- a/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/AnnotationComponentGleanerTest.java +++ b/plexus-component-metadata/src/test/java/org/codehaus/plexus/metadata/gleaner/AnnotationComponentGleanerTest.java @@ -20,6 +20,7 @@ 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.metadata.gleaner.ann.AnnotatedComponent; import org.codehaus.plexus.metadata.gleaner.ann.AnnotatedComponentRole; @@ -48,7 +49,9 @@ public void testGlean() throws Exception { ComponentRequirement requirement2 = requirements.get(1); assertEquals("dependency2", requirement2.getFieldName()); - assertEquals("release,latest,snapshot", requirement2.getRoleHint()); + assertTrue(requirement2 instanceof ComponentRequirementList); + assertEquals("release,latest,snapshot", + String.join(",", ((ComponentRequirementList) requirement2).getRoleHints())); PlexusConfiguration configuration = descriptor.getConfiguration(); assertEquals(1, configuration.getChildCount()); diff --git a/pom.xml b/pom.xml index 6dd127c1c..45bd3a4b9 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,12 @@ plexus-container-default ${project.version} + + org.eclipse.sisu + org.eclipse.sisu.plexus + + 0.3.0.M1 + org.codehaus.plexus plexus-component-annotations