Search in sources :

Example 1 with PlexusConfigurationException

use of org.codehaus.plexus.configuration.PlexusConfigurationException 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 PlexusConfigurationException

use of org.codehaus.plexus.configuration.PlexusConfigurationException 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 PlexusConfigurationException

use of org.codehaus.plexus.configuration.PlexusConfigurationException in project maven-plugins by apache.

the class AbstractEarMojo method execute.

/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
    getLog().debug("Resolving artifact type mappings ...");
    ArtifactTypeMappingService typeMappingService;
    try {
        typeMappingService = new ArtifactTypeMappingService();
        typeMappingService.configure(artifactTypeMappings);
    } catch (EarPluginException e) {
        throw new MojoExecutionException("Failed to initialize artifact type mappings", e);
    } catch (PlexusConfigurationException e) {
        throw new MojoExecutionException("Invalid artifact type mappings configuration", e);
    }
    getLog().debug("Initializing JBoss configuration if necessary ...");
    try {
        initializeJbossConfiguration();
    } catch (EarPluginException e) {
        throw new MojoExecutionException("Failed to initialize JBoss configuration", e);
    }
    getLog().debug("Initializing ear execution context");
    EarExecutionContext earExecutionContext = new EarExecutionContext(project, mainArtifactId, defaultLibBundleDir, jbossConfiguration, outputFileNameMapping, typeMappingService);
    if (useBaseVersion != null) {
        getLog().warn("Using useBaseVersion not yet fixed.");
    // earExecutionContext.getOutputFileNameMapping().setUseBaseVersion( useBaseVersion );
    }
    getLog().debug("Resolving ear modules ...");
    List<EarModule> allModules = new ArrayList<EarModule>();
    try {
        if (modules != null && modules.length > 0) {
            // Let's validate user-defined modules
            EarModule module;
            for (EarModule module1 : modules) {
                module = module1;
                getLog().debug("Resolving ear module[" + module + "]");
                module.setEarExecutionContext(earExecutionContext);
                module.resolveArtifact(project.getArtifacts());
                allModules.add(module);
            }
        }
        // Let's add other modules
        Set<Artifact> artifacts = project.getArtifacts();
        for (Artifact artifact : artifacts) {
            // since it's used for transitive deps only.
            if ("pom".equals(artifact.getType())) {
                continue;
            }
            // Artifact is not yet registered and it has not test scope, nor is it optional
            ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_COMPILE_PLUS_RUNTIME);
            if (!isArtifactRegistered(artifact, allModules) && !artifact.isOptional() && filter.include(artifact)) {
                EarModule module = EarModuleFactory.newEarModule(artifact, javaEEVersion, defaultLibBundleDir, includeLibInApplicationXml, typeMappingService);
                module.setEarExecutionContext(earExecutionContext);
                allModules.add(module);
            }
        }
    } catch (EarPluginException e) {
        throw new MojoExecutionException("Failed to initialize ear modules", e);
    }
    // Now we have everything let's built modules which have not been excluded
    ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
    allJarModules = new ArrayList<JarModule>();
    earModules = new ArrayList<EarModule>();
    for (EarModule earModule : allModules) {
        if (earModule.isExcluded()) {
            getLog().debug("Skipping ear module[" + earModule + "]");
        } else {
            if (earModule instanceof JarModule) {
                allJarModules.add((JarModule) earModule);
            }
            if (filter.include(earModule.getArtifact())) {
                earModules.add(earModule);
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JavaEEVersion(org.apache.maven.plugins.ear.util.JavaEEVersion) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) PlexusConfigurationException(org.codehaus.plexus.configuration.PlexusConfigurationException) ArtifactTypeMappingService(org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)

Example 4 with PlexusConfigurationException

use of org.codehaus.plexus.configuration.PlexusConfigurationException 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 PlexusConfigurationException

use of org.codehaus.plexus.configuration.PlexusConfigurationException 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

ArtifactTypeMappingService (org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)7 PlexusConfigurationException (org.codehaus.plexus.configuration.PlexusConfigurationException)7 EarPluginException (org.apache.maven.plugins.ear.EarPluginException)6 XmlPlexusConfiguration (org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)6 ArrayList (java.util.ArrayList)1 Artifact (org.apache.maven.artifact.Artifact)1 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 JavaEEVersion (org.apache.maven.plugins.ear.util.JavaEEVersion)1