Search in sources :

Example 1 with Location

use of org.apache.maven.shared.io.location.Location in project maven-plugins by apache.

the class RelativeFileLocatorStrategy method resolve.

@Override
public Location resolve(String locationSpecification, MessageHolder messageHolder) {
    File file = new File(basedir, locationSpecification);
    messageHolder.addInfoMessage("Searching for file location: " + file.getAbsolutePath());
    Location location = null;
    if (file.exists()) {
        location = new FileLocation(file, locationSpecification);
    } else {
        messageHolder.addMessage("File: " + file.getAbsolutePath() + " does not exist.");
    }
    return location;
}
Also used : FileLocation(org.apache.maven.shared.io.location.FileLocation) File(java.io.File) FileLocation(org.apache.maven.shared.io.location.FileLocation) Location(org.apache.maven.shared.io.location.Location)

Example 2 with Location

use of org.apache.maven.shared.io.location.Location in project maven-plugins by apache.

the class PrefixedClasspathLocatorStrategyTest method testResolvePrefixWithLeadingSlashAndWithTrailingSlash.

public void testResolvePrefixWithLeadingSlashAndWithTrailingSlash() {
    MessageHolder mh = new DefaultMessageHolder();
    LocatorStrategy ls = new PrefixedClasspathLocatorStrategy("/assemblies/");
    Location location = ls.resolve("empty.xml", mh);
    assertNotNull(location);
    assertEquals(0, mh.size());
}
Also used : DefaultMessageHolder(org.apache.maven.shared.io.logging.DefaultMessageHolder) MessageHolder(org.apache.maven.shared.io.logging.MessageHolder) DefaultMessageHolder(org.apache.maven.shared.io.logging.DefaultMessageHolder) LocatorStrategy(org.apache.maven.shared.io.location.LocatorStrategy) Location(org.apache.maven.shared.io.location.Location)

Example 3 with Location

use of org.apache.maven.shared.io.location.Location in project maven-plugins by apache.

the class PrefixedClasspathLocatorStrategyTest method testResolvePrefixWithoutLeadingSlashAndWithoutTrailingSlash.

public void testResolvePrefixWithoutLeadingSlashAndWithoutTrailingSlash() {
    MessageHolder mh = new DefaultMessageHolder();
    LocatorStrategy ls = new PrefixedClasspathLocatorStrategy("assemblies");
    Location location = ls.resolve("empty.xml", mh);
    assertNotNull(location);
    assertEquals(0, mh.size());
}
Also used : DefaultMessageHolder(org.apache.maven.shared.io.logging.DefaultMessageHolder) MessageHolder(org.apache.maven.shared.io.logging.MessageHolder) DefaultMessageHolder(org.apache.maven.shared.io.logging.DefaultMessageHolder) LocatorStrategy(org.apache.maven.shared.io.location.LocatorStrategy) Location(org.apache.maven.shared.io.location.Location)

Example 4 with Location

use of org.apache.maven.shared.io.location.Location 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 5 with Location

use of org.apache.maven.shared.io.location.Location in project maven-plugins by apache.

the class DefaultAssemblyReader method addAssemblyFromDescriptor.

private Assembly addAssemblyFromDescriptor(final String spec, final Locator locator, final AssemblerConfigurationSource configSource, final List<Assembly> assemblies) throws AssemblyReadException, InvalidAssemblerConfigurationException {
    final Location location = locator.resolve(spec);
    if (location == null) {
        if (configSource.isIgnoreMissingDescriptor()) {
            getLogger().debug("Ignoring missing assembly descriptor with ID '" + spec + "' per configuration.\nLocator output was:\n\n" + locator.getMessageHolder().render());
            return null;
        } else {
            throw new AssemblyReadException("Error locating assembly descriptor: " + spec + "\n\n" + locator.getMessageHolder().render());
        }
    }
    Reader r = null;
    try {
        r = ReaderFactory.newXmlReader(location.getInputStream());
        File dir = null;
        if (location.getFile() != null) {
            dir = location.getFile().getParentFile();
        }
        final Assembly assembly = readAssembly(r, spec, dir, configSource);
        r.close();
        r = null;
        assemblies.add(assembly);
        return assembly;
    } catch (final IOException e) {
        throw new AssemblyReadException("Error reading assembly descriptor: " + spec, e);
    } finally {
        IOUtil.close(r);
    }
}
Also used : 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) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) Location(org.apache.maven.shared.io.location.Location)

Aggregations

Location (org.apache.maven.shared.io.location.Location)7 LocatorStrategy (org.apache.maven.shared.io.location.LocatorStrategy)4 DefaultMessageHolder (org.apache.maven.shared.io.logging.DefaultMessageHolder)4 MessageHolder (org.apache.maven.shared.io.logging.MessageHolder)4 File (java.io.File)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 AssemblyXpp3Reader (org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader)2 ComponentXpp3Reader (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader)2 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1 AssemblyExpressionEvaluator (org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator)1 Assembly (org.apache.maven.plugins.assembly.model.Assembly)1 Component (org.apache.maven.plugins.assembly.model.Component)1 ClasspathResourceLocatorStrategy (org.apache.maven.shared.io.location.ClasspathResourceLocatorStrategy)1 FileLocation (org.apache.maven.shared.io.location.FileLocation)1 FileLocatorStrategy (org.apache.maven.shared.io.location.FileLocatorStrategy)1 Locator (org.apache.maven.shared.io.location.Locator)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1