/* * ======================================================================== * * Copyright 2005 Vincent Massol. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ======================================================================== */ package org.codehaus.cargo.maven2; import java.io.File; import java.util.Iterator; import java.util.List; import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.cargo.container.configuration.LocalConfiguration; import org.codehaus.cargo.generic.configuration.ConfigurationFactory; import org.codehaus.cargo.generic.configuration.ConfigurationType; import org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory; /** * Holds configuration data for the <configuration> tag used to configure * the plugin in the pom.xml file. * * @version $Id: $ */ public class Configuration { private String type = ConfigurationType.STANDALONE.getType(); private Class implementation; private File dir; private List properties; private List ears; private List wars; public ConfigurationType getType() { return ConfigurationType.toType(this.type); } public File getDir() { return this.dir; } public List getProperties() { return this.properties; } public List getEars() { return this.ears; } public List getWars() { return this.wars; } public Class getImplementation() { return this.implementation; } public org.codehaus.cargo.container.configuration.Configuration createConfiguration( String containerId) throws MojoExecutionException { ConfigurationFactory factory = new DefaultConfigurationFactory(); if (getImplementation() != null) { factory.registerConfiguration(containerId, getType(), getImplementation()); } // Only use the dir if specified org.codehaus.cargo.container.configuration.Configuration configuration; if (getDir() == null) { configuration = factory.createConfiguration(containerId, getType()); } else { configuration = factory.createConfiguration(containerId, getType(), getDir().toURI()); } // Set all container properties Iterator itProperties = getProperties().iterator(); while (itProperties.hasNext()) { Property property = (Property) itProperties.next(); configuration.setProperty(property.getName(), property.getValue()); } // Add static deployables for local configurations if (configuration instanceof LocalConfiguration) { addStaticDeployables(containerId, (LocalConfiguration) configuration); } return configuration; } /** * Add static deployables to the configuration. * * @param containerId the container id to which to deploy to * @param configuration the local configuration to which to add Deployables to */ private void addStaticDeployables(String containerId, LocalConfiguration configuration) throws MojoExecutionException { // Add WAR deployables (if defined) if (getWars() != null) { Iterator itWars = getWars().iterator(); while (itWars.hasNext()) { War war = (War) itWars.next(); configuration.addDeployable(war.createWAR(containerId)); } } // Add EAR deployables (if defined) if (getEars() != null) { Iterator itEars = getEars().iterator(); while (itEars.hasNext()) { Ear ear = (Ear) itEars.next(); configuration.addDeployable(ear.createEAR(containerId)); } } } }