Search in sources :

Example 1 with AssemblyExpressionEvaluator

use of org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator in project maven-plugins by apache.

the class DefaultAssemblyReader method mergeComponentsWithMainAssembly.

/**
     * Add the contents of all included components to main assembly
     *
     * @param assembly The assembly
     * @param assemblyDir The assembly directory
     * @param transformer The component interpolator
     * @throws AssemblyReadException .
     */
protected void mergeComponentsWithMainAssembly(final Assembly assembly, final File assemblyDir, final AssemblerConfigurationSource configSource, ComponentXpp3Reader.ContentTransformer transformer) throws AssemblyReadException {
    final Locator locator = new Locator();
    if (assemblyDir != null && assemblyDir.exists() && assemblyDir.isDirectory()) {
        locator.addStrategy(new RelativeFileLocatorStrategy(assemblyDir));
    }
    // allow absolute paths in componentDescriptor... MASSEMBLY-486
    locator.addStrategy(new RelativeFileLocatorStrategy(configSource.getBasedir()));
    locator.addStrategy(new FileLocatorStrategy());
    locator.addStrategy(new ClasspathResourceLocatorStrategy());
    final AssemblyExpressionEvaluator aee = new AssemblyExpressionEvaluator(configSource);
    final List<String> componentLocations = assembly.getComponentDescriptors();
    for (String location : componentLocations) {
        // allow expressions in path to component descriptor... MASSEMBLY-486
        try {
            location = aee.evaluate(location).toString();
        } catch (final Exception eee) {
            getLogger().error("Error interpolating componentDescriptor: " + location, eee);
        }
        final Location resolvedLocation = locator.resolve(location);
        if (resolvedLocation == null) {
            throw new AssemblyReadException("Failed to locate component descriptor: " + location);
        }
        Component component = null;
        Reader reader = null;
        try {
            reader = new InputStreamReader(resolvedLocation.getInputStream());
            component = new ComponentXpp3Reader(transformer).read(reader);
        } catch (final IOException e) {
            throw new AssemblyReadException("Error reading component descriptor: " + location + " (resolved to: " + resolvedLocation.getSpecification() + ")", e);
        } catch (final XmlPullParserException e) {
            throw new AssemblyReadException("Error reading component descriptor: " + location + " (resolved to: " + resolvedLocation.getSpecification() + ")", e);
        } finally {
            IOUtil.close(reader);
        }
        mergeComponentWithAssembly(component, assembly);
    }
}
Also used : AssemblyExpressionEvaluator(org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator) InputStreamReader(java.io.InputStreamReader) FileLocatorStrategy(org.apache.maven.shared.io.location.FileLocatorStrategy) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) AssemblyXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader) IOException(java.io.IOException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) Locator(org.apache.maven.shared.io.location.Locator) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) Component(org.apache.maven.plugins.assembly.model.Component) ClasspathResourceLocatorStrategy(org.apache.maven.shared.io.location.ClasspathResourceLocatorStrategy) Location(org.apache.maven.shared.io.location.Location)

Example 2 with AssemblyExpressionEvaluator

use of org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator in project maven-plugins by apache.

the class DefaultAssemblyArchiver method configureComponent.

private void configureComponent(final Object component, final Xpp3Dom config, final AssemblerConfigurationSource configSource) throws ComponentLookupException, ComponentConfigurationException {
    final ComponentConfigurator configurator = container.lookup(ComponentConfigurator.class, "basic");
    final ConfigurationListener listener = new DebugConfigurationListener(getLogger());
    final ExpressionEvaluator expressionEvaluator = new AssemblyExpressionEvaluator(configSource);
    final XmlPlexusConfiguration configuration = new XmlPlexusConfiguration(config);
    final Object[] containerRealm = getContainerRealm();
    /*
         * NOTE: The signature of configureComponent() has changed in Maven 3.x, the reflection prevents a linkage error
         * and makes the code work with both Maven 2 and 3.
         */
    try {
        final Method configureComponent = ComponentConfigurator.class.getMethod("configureComponent", Object.class, PlexusConfiguration.class, ExpressionEvaluator.class, (Class<?>) containerRealm[1], ConfigurationListener.class);
        configureComponent.invoke(configurator, component, configuration, expressionEvaluator, containerRealm[0], listener);
    } catch (final NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (final IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (final InvocationTargetException e) {
        if (e.getCause() instanceof ComponentConfigurationException) {
            throw (ComponentConfigurationException) e.getCause();
        }
        throw new RuntimeException(e.getCause());
    }
}
Also used : DebugConfigurationListener(org.apache.maven.plugin.DebugConfigurationListener) AssemblyExpressionEvaluator(org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator) ComponentConfigurator(org.codehaus.plexus.component.configurator.ComponentConfigurator) Method(java.lang.reflect.Method) AssemblyExpressionEvaluator(org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator) InvocationTargetException(java.lang.reflect.InvocationTargetException) DebugConfigurationListener(org.apache.maven.plugin.DebugConfigurationListener) ConfigurationListener(org.codehaus.plexus.component.configurator.ConfigurationListener) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Aggregations

AssemblyExpressionEvaluator (org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 DebugConfigurationListener (org.apache.maven.plugin.DebugConfigurationListener)1 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1 Component (org.apache.maven.plugins.assembly.model.Component)1 AssemblyXpp3Reader (org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader)1 ComponentXpp3Reader (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader)1 ClasspathResourceLocatorStrategy (org.apache.maven.shared.io.location.ClasspathResourceLocatorStrategy)1 FileLocatorStrategy (org.apache.maven.shared.io.location.FileLocatorStrategy)1 Location (org.apache.maven.shared.io.location.Location)1 Locator (org.apache.maven.shared.io.location.Locator)1 ComponentConfigurationException (org.codehaus.plexus.component.configurator.ComponentConfigurationException)1 ComponentConfigurator (org.codehaus.plexus.component.configurator.ComponentConfigurator)1 ConfigurationListener (org.codehaus.plexus.component.configurator.ConfigurationListener)1 ExpressionEvaluator (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)1 XmlPlexusConfiguration (org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)1