Search in sources :

Example 1 with LocatorStrategy

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

the class DefaultAssemblyReader method readAssemblies.

@Override
public List<Assembly> readAssemblies(final AssemblerConfigurationSource configSource) throws AssemblyReadException, InvalidAssemblerConfigurationException {
    final Locator locator = new Locator();
    final List<LocatorStrategy> strategies = new ArrayList<LocatorStrategy>();
    strategies.add(new RelativeFileLocatorStrategy(configSource.getBasedir()));
    strategies.add(new FileLocatorStrategy());
    final List<LocatorStrategy> refStrategies = new ArrayList<LocatorStrategy>();
    refStrategies.add(new PrefixedClasspathLocatorStrategy("/assemblies/"));
    final List<Assembly> assemblies = new ArrayList<Assembly>();
    final String[] descriptors = configSource.getDescriptors();
    final String[] descriptorRefs = configSource.getDescriptorReferences();
    final File descriptorSourceDirectory = configSource.getDescriptorSourceDirectory();
    if ((descriptors != null) && (descriptors.length > 0)) {
        locator.setStrategies(strategies);
        for (String descriptor1 : descriptors) {
            getLogger().info("Reading assembly descriptor: " + descriptor1);
            addAssemblyFromDescriptor(descriptor1, locator, configSource, assemblies);
        }
    }
    if ((descriptorRefs != null) && (descriptorRefs.length > 0)) {
        locator.setStrategies(refStrategies);
        for (String descriptorRef : descriptorRefs) {
            addAssemblyForDescriptorReference(descriptorRef, configSource, assemblies);
        }
    }
    if ((descriptorSourceDirectory != null) && descriptorSourceDirectory.isDirectory()) {
        // CHECKSTYLE_OFF: LineLength
        locator.setStrategies(Collections.<LocatorStrategy>singletonList(new RelativeFileLocatorStrategy(descriptorSourceDirectory)));
        // CHECKSTYLE_ON: LineLength
        final DirectoryScanner scanner = new DirectoryScanner();
        scanner.setBasedir(descriptorSourceDirectory);
        scanner.setIncludes(new String[] { "**/*.xml" });
        scanner.addDefaultExcludes();
        scanner.scan();
        final String[] paths = scanner.getIncludedFiles();
        for (String path : paths) {
            addAssemblyFromDescriptor(path, locator, configSource, assemblies);
        }
    }
    if (assemblies.isEmpty()) {
        if (configSource.isIgnoreMissingDescriptor()) {
            getLogger().debug("Ignoring missing assembly descriptors per configuration. " + "See messages above for specifics.");
        } else {
            throw new AssemblyReadException("No assembly descriptors found.");
        }
    }
    // check unique IDs
    final Set<String> ids = new HashSet<String>();
    for (final Assembly assembly : assemblies) {
        if (!ids.add(assembly.getId())) {
            getLogger().warn("The assembly id " + assembly.getId() + " is used more than once.");
        }
    }
    return assemblies;
}
Also used : FileLocatorStrategy(org.apache.maven.shared.io.location.FileLocatorStrategy) ArrayList(java.util.ArrayList) ClasspathResourceLocatorStrategy(org.apache.maven.shared.io.location.ClasspathResourceLocatorStrategy) LocatorStrategy(org.apache.maven.shared.io.location.LocatorStrategy) FileLocatorStrategy(org.apache.maven.shared.io.location.FileLocatorStrategy) Locator(org.apache.maven.shared.io.location.Locator) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) HashSet(java.util.HashSet)

Example 2 with LocatorStrategy

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

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

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

the class PrefixedClasspathLocatorStrategyTest method testResolvePrefixWithoutLeadingSlashAndWithTrailingSlash.

public void testResolvePrefixWithoutLeadingSlashAndWithTrailingSlash() {
    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 5 with LocatorStrategy

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

the class PrefixedClasspathLocatorStrategyTest method testResolvePrefixWithLeadingSlashAndWithoutTrailingSlash.

public void testResolvePrefixWithLeadingSlashAndWithoutTrailingSlash() {
    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)

Aggregations

LocatorStrategy (org.apache.maven.shared.io.location.LocatorStrategy)5 Location (org.apache.maven.shared.io.location.Location)4 DefaultMessageHolder (org.apache.maven.shared.io.logging.DefaultMessageHolder)4 MessageHolder (org.apache.maven.shared.io.logging.MessageHolder)4 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Assembly (org.apache.maven.plugins.assembly.model.Assembly)1 ClasspathResourceLocatorStrategy (org.apache.maven.shared.io.location.ClasspathResourceLocatorStrategy)1 FileLocatorStrategy (org.apache.maven.shared.io.location.FileLocatorStrategy)1 Locator (org.apache.maven.shared.io.location.Locator)1 DirectoryScanner (org.codehaus.plexus.util.DirectoryScanner)1