/** * {@inheritDoc} * * @see org.codehaus.cargo.container.configuration.LocalConfiguration#configure(LocalContainer) */ public void doConfigure(LocalContainer container) throws Exception { try { setupConfigurationDir(); getResourceUtils() .copyResource(RESOURCE_PATH + "cargocpc.war", new File(getHome(), "cargocpc.war")); if (container.getOutput() != null) { activateLogging(container); } } catch (Exception e) { throw new ContainerException( "Failed to create a " + container.getName() + " container configuration", e); } }
/** * {@inheritDoc} * * @see org.codehaus.cargo.maven2.AbstractCargoMojo#doExecute() */ public void doExecute() throws MojoExecutionException { Container container = createContainer(); if (!container.getType().isLocal()) { throw new MojoExecutionException("Only local containers can be started"); } LocalContainer localContainer = (LocalContainer) container; addAutoDeployDeployable(localContainer); localContainer.start(); if (this.wait) { getLog().info("Press Ctrl-C to stop the container..."); ContainerUtils.waitTillContainerIsStopped(localContainer); } }
/** * If the project's packaging is war, ear or ejb and there is no deployer specified and the user * has not defined the auto-deployable inside the <code><deployables></code> element, then * add the generated artifact to the list of deployables to deploy statically. * * <p>Note that the reason we check that a deployer element has not been specified is because if * it has then the auto deployable will be deployed by the specified deployer. * * @param container the local container to which to add the project's artifact * @throws MojoExecutionException if an error occurs */ protected void addAutoDeployDeployable(LocalContainer container) throws MojoExecutionException { if ((getDeployerElement() == null) && (getCargoProject().getPackaging() != null) && getCargoProject().isJ2EEPackaging()) { // Has the auto-deployable already been specified as part of the <deployables> config // element? if ((getConfigurationElement() == null) || (getConfigurationElement().getDeployables() == null) || !containsAutoDeployable(getConfigurationElement().getDeployables())) { LocalConfiguration configuration = container.getConfiguration(); configuration.addDeployable(createAutoDeployDeployable(container)); } } }
/** Test the creation of a container with one deployable. */ public void testMakeContainerWithOneDeployable() { CargoTask task = new CargoTask(); task.setContainerId("resin2x"); task.setType(ContainerType.INSTALLED); ConfigurationElement configurationElement = task.createConfiguration(); configurationElement.setType("standalone"); DeployableElement warElement = new DeployableElement(); warElement.setType(DeployableType.WAR.getType()); warElement.setFile("some/war"); configurationElement.addConfiguredDeployable(warElement); configurationElement.setHome("somewhere"); LocalContainer container = (LocalContainer) task.makeContainer(); assertEquals( Resin2xStandaloneLocalConfiguration.class.getName(), container.getConfiguration().getClass().getName()); assertEquals(1, container.getConfiguration().getDeployables().size()); Deployable deployable = container.getConfiguration().getDeployables().get(0); assertEquals(WAR.class.getName(), deployable.getClass().getName()); assertEquals("some/war", deployable.getFile()); }