Search in sources :

Example 1 with EarPluginException

use of org.apache.maven.plugins.ear.EarPluginException in project maven-plugins by apache.

the class ArtifactTypeMappingServiceTest method testConfigWithSameCustomType.

public void testConfigWithSameCustomType() {
    try {
        XmlPlexusConfiguration rootConfig = new XmlPlexusConfiguration("dummy");
        XmlPlexusConfiguration childConfig = new XmlPlexusConfiguration(ArtifactTypeMappingService.ARTIFACT_TYPE_MAPPING_ELEMENT);
        childConfig.setAttribute("type", "generic");
        childConfig.setAttribute("mapping", "rar");
        XmlPlexusConfiguration childConfig2 = new XmlPlexusConfiguration(ArtifactTypeMappingService.ARTIFACT_TYPE_MAPPING_ELEMENT);
        childConfig.setAttribute("type", "generic");
        childConfig.setAttribute("mapping", "ejb");
        rootConfig.addChild(childConfig);
        rootConfig.addChild(childConfig2);
        ArtifactTypeMappingService service = new ArtifactTypeMappingService();
        service.configure(rootConfig);
        fail("Should have failed");
    } catch (EarPluginException e) {
    // OK
    } catch (PlexusConfigurationException e) {
        e.printStackTrace();
        fail("Unexpected " + e.getMessage());
    }
}
Also used : PlexusConfigurationException(org.codehaus.plexus.configuration.PlexusConfigurationException) EarPluginException(org.apache.maven.plugins.ear.EarPluginException) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) ArtifactTypeMappingService(org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)

Example 2 with EarPluginException

use of org.apache.maven.plugins.ear.EarPluginException in project maven-plugins by apache.

the class ArtifactTypeMappingServiceTest method getDefaultService.

protected ArtifactTypeMappingService getDefaultService() {
    try {
        ArtifactTypeMappingService service = new ArtifactTypeMappingService();
        service.configure(new XmlPlexusConfiguration("dummy"));
        return service;
    } catch (EarPluginException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (PlexusConfigurationException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    // Won't occur
    return null;
}
Also used : PlexusConfigurationException(org.codehaus.plexus.configuration.PlexusConfigurationException) EarPluginException(org.apache.maven.plugins.ear.EarPluginException) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) ArtifactTypeMappingService(org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)

Example 3 with EarPluginException

use of org.apache.maven.plugins.ear.EarPluginException in project maven-plugins by apache.

the class ArtifactTypeMappingService method configure.

/**
 * @param plexusConfiguration {@link PlexusConfiguration}
 * @throws EarPluginException {@link EarPluginException}
 * @throws PlexusConfigurationException {@link PlexusConfigurationException}
 */
public void configure(final PlexusConfiguration plexusConfiguration) throws EarPluginException, PlexusConfigurationException {
    // No user defined configuration
    if (plexusConfiguration == null) {
        return;
    }
    // Inject users configuration
    final PlexusConfiguration[] artifactTypeMappings = plexusConfiguration.getChildren(ARTIFACT_TYPE_MAPPING_ELEMENT);
    for (PlexusConfiguration artifactTypeMapping : artifactTypeMappings) {
        final String customType = artifactTypeMapping.getAttribute(TYPE_ATTRIBUTE);
        final String mapping = artifactTypeMapping.getAttribute(MAPPING_ATTRIBUTE);
        if (customType == null) {
            throw new EarPluginException("Invalid artifact type mapping, type attribute should be set.");
        } else if (mapping == null) {
            throw new EarPluginException("Invalid artifact type mapping, mapping attribute should be set.");
        } else if (!EarModuleFactory.isStandardArtifactType(mapping)) {
            throw new EarPluginException("Invalid artifact type mapping, mapping[" + mapping + "] must be a standard Ear artifact type[" + EarModuleFactory.getStandardArtifactTypes() + "]");
        } else if (customMappings.containsKey(customType)) {
            throw new EarPluginException("Invalid artifact type mapping, type[" + customType + "] is already registered.");
        } else {
            // Add the custom mapping
            customMappings.put(customType, mapping);
            // Register the custom mapping to its standard type
            List<String> typeMapping = typeMappings.get(mapping);
            typeMapping.add(customType);
        }
    }
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) EarPluginException(org.apache.maven.plugins.ear.EarPluginException) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with EarPluginException

use of org.apache.maven.plugins.ear.EarPluginException in project maven-plugins by apache.

the class ArtifactTypeMappingServiceTest method testConfigWithNoMapping.

public void testConfigWithNoMapping() {
    try {
        XmlPlexusConfiguration rootConfig = new XmlPlexusConfiguration("dummy");
        XmlPlexusConfiguration childConfig = new XmlPlexusConfiguration(ArtifactTypeMappingService.ARTIFACT_TYPE_MAPPING_ELEMENT);
        childConfig.setAttribute("type", "generic");
        rootConfig.addChild(childConfig);
        ArtifactTypeMappingService service = new ArtifactTypeMappingService();
        service.configure(rootConfig);
        fail("Should have failed");
    } catch (EarPluginException e) {
    // OK
    } catch (PlexusConfigurationException e) {
        e.printStackTrace();
        fail("Unexpected " + e.getMessage());
    }
}
Also used : PlexusConfigurationException(org.codehaus.plexus.configuration.PlexusConfigurationException) EarPluginException(org.apache.maven.plugins.ear.EarPluginException) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) ArtifactTypeMappingService(org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)

Example 5 with EarPluginException

use of org.apache.maven.plugins.ear.EarPluginException in project maven-plugins by apache.

the class ArtifactTypeMappingServiceTest method testConfigWithNoType.

public void testConfigWithNoType() {
    try {
        XmlPlexusConfiguration rootConfig = new XmlPlexusConfiguration("dummy");
        XmlPlexusConfiguration childConfig = new XmlPlexusConfiguration(ArtifactTypeMappingService.ARTIFACT_TYPE_MAPPING_ELEMENT);
        childConfig.setAttribute("mapping", "ejb");
        rootConfig.addChild(childConfig);
        ArtifactTypeMappingService service = new ArtifactTypeMappingService();
        service.configure(rootConfig);
        fail("Should have failed");
    } catch (EarPluginException e) {
    // OK
    } catch (PlexusConfigurationException e) {
        e.printStackTrace();
        fail("Unexpected " + e.getMessage());
    }
}
Also used : PlexusConfigurationException(org.codehaus.plexus.configuration.PlexusConfigurationException) EarPluginException(org.apache.maven.plugins.ear.EarPluginException) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) ArtifactTypeMappingService(org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)

Aggregations

EarPluginException (org.apache.maven.plugins.ear.EarPluginException)7 ArtifactTypeMappingService (org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)6 PlexusConfigurationException (org.codehaus.plexus.configuration.PlexusConfigurationException)6 XmlPlexusConfiguration (org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)6 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PlexusConfiguration (org.codehaus.plexus.configuration.PlexusConfiguration)1