001: package org.apache.maven.lifecycle;
002:
003: import org.apache.maven.lifecycle.binding.LegacyLifecycleMappingParser;
004: import org.apache.maven.lifecycle.binding.LegacyLifecycleParsingTestComponent;
005: import org.apache.maven.lifecycle.mapping.LifecycleMapping;
006: import org.apache.maven.lifecycle.model.BuildBinding;
007: import org.apache.maven.lifecycle.model.LifecycleBindings;
008: import org.apache.maven.lifecycle.model.MojoBinding;
009: import org.codehaus.plexus.PlexusTestCase;
010:
011: import java.util.List;
012:
013: public class LegacyLifecycleMappingParserTest extends PlexusTestCase {
014:
015: private LegacyLifecycleParsingTestComponent testComponent;
016:
017: private LifecycleMapping testMapping;
018:
019: private LifecycleMapping testMapping2;
020:
021: private LegacyLifecycleMappingParser parser;
022:
023: public void setUp() throws Exception {
024: super .setUp();
025:
026: parser = (LegacyLifecycleMappingParser) lookup(
027: LegacyLifecycleMappingParser.ROLE, "default");
028:
029: testComponent = (LegacyLifecycleParsingTestComponent) lookup(
030: LegacyLifecycleParsingTestComponent.ROLE, "default");
031: testMapping = (LifecycleMapping) lookup(LifecycleMapping.ROLE,
032: "test-mapping");
033: testMapping2 = (LifecycleMapping) lookup(LifecycleMapping.ROLE,
034: "test-mapping2");
035: }
036:
037: public void tearDown() throws Exception {
038: release(testComponent);
039: release(testMapping);
040: release(testMapping2);
041:
042: super .tearDown();
043: }
044:
045: public void testParseDefaultMappings_UsingExistingDefaultMappings()
046: throws LifecycleSpecificationException {
047: List lifecycles = testComponent.getLifecycles();
048: LifecycleBindings bindings = parser
049: .parseDefaultMappings(lifecycles);
050:
051: // <clean>org.apache.maven.plugins:maven-clean-plugin:clean</clean>
052: List cleanPhase = bindings.getCleanBinding().getClean()
053: .getBindings();
054: assertEquals(1, cleanPhase.size());
055:
056: MojoBinding binding = (MojoBinding) cleanPhase.get(0);
057: assertMojo("org.apache.maven.plugins", "maven-clean-plugin",
058: "clean", binding);
059:
060: // <site>org.apache.maven.plugins:maven-site-plugin:site</site>
061: List sitePhase = bindings.getSiteBinding().getSite()
062: .getBindings();
063: assertEquals(1, sitePhase.size());
064:
065: binding = (MojoBinding) sitePhase.get(0);
066: assertMojo("org.apache.maven.plugins", "maven-site-plugin",
067: "site", binding);
068:
069: // <site-deploy>org.apache.maven.plugins:maven-site-plugin:deploy</site-deploy>
070: List siteDeployPhase = bindings.getSiteBinding()
071: .getSiteDeploy().getBindings();
072: assertEquals(1, siteDeployPhase.size());
073:
074: binding = (MojoBinding) siteDeployPhase.get(0);
075: assertMojo("org.apache.maven.plugins", "maven-site-plugin",
076: "deploy", binding);
077: }
078:
079: private void assertMojo(String groupId, String artifactId,
080: String goal, MojoBinding binding) {
081: assertEquals(groupId, binding.getGroupId());
082: assertEquals(artifactId, binding.getArtifactId());
083: assertEquals(goal, binding.getGoal());
084: }
085:
086: public void testParseMappings_SparselyPopulatedMappings()
087: throws LifecycleSpecificationException {
088: LifecycleBindings bindings = parser.parseMappings(testMapping,
089: "test-mapping");
090:
091: BuildBinding bb = bindings.getBuildBinding();
092: assertNotNull(bb);
093:
094: // <phases>
095: // <package>org.apache.maven.plugins:maven-site-plugin:attach-descriptor</package>
096: // <install>org.apache.maven.plugins:maven-install-plugin:install</install>
097: // <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
098: // </phases>
099: // <optional-mojos>
100: // <optional-mojo>org.apache.maven.plugins:maven-site-plugin:attach-descriptor</optional-mojo>
101: // </optional-mojos>
102: List mojos = bb.getCreatePackage().getBindings();
103:
104: assertEquals(1, mojos.size());
105: assertMojo("org.apache.maven.plugins", "maven-site-plugin",
106: "attach-descriptor", (MojoBinding) mojos.get(0));
107: assertTrue(((MojoBinding) mojos.get(0)).isOptional());
108:
109: mojos = bb.getInstall().getBindings();
110:
111: assertEquals(1, mojos.size());
112: assertMojo("org.apache.maven.plugins", "maven-install-plugin",
113: "install", (MojoBinding) mojos.get(0));
114: assertFalse(((MojoBinding) mojos.get(0)).isOptional());
115:
116: mojos = bb.getDeploy().getBindings();
117:
118: assertEquals(1, mojos.size());
119: assertMojo("org.apache.maven.plugins", "maven-deploy-plugin",
120: "deploy", (MojoBinding) mojos.get(0));
121: assertFalse(((MojoBinding) mojos.get(0)).isOptional());
122: }
123:
124: public void testParseMappings_MappingsWithTwoBindingsInOnePhase()
125: throws LifecycleSpecificationException {
126: LifecycleBindings bindings = parser.parseMappings(testMapping2,
127: "test-mapping2");
128:
129: BuildBinding bb = bindings.getBuildBinding();
130: assertNotNull(bb);
131:
132: // <phases>
133: // <package>org.apache.maven.plugins:maven-site-plugin:attach-descriptor</package>
134: // <install>org.apache.maven.plugins:maven-install-plugin:install</install>
135: // <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
136: // </phases>
137: // <optional-mojos>
138: // <optional-mojo>org.apache.maven.plugins:maven-site-plugin:attach-descriptor</optional-mojo>
139: // </optional-mojos>
140: List mojos = bb.getCreatePackage().getBindings();
141:
142: assertEquals(2, mojos.size());
143: assertMojo("org.apache.maven.plugins", "maven-site-plugin",
144: "attach-descriptor", (MojoBinding) mojos.get(0));
145: assertTrue(((MojoBinding) mojos.get(0)).isOptional());
146: assertMojo("org.apache.maven.plugins", "maven-clean-plugin",
147: "clean", (MojoBinding) mojos.get(1));
148:
149: mojos = bb.getInstall().getBindings();
150:
151: assertEquals(1, mojos.size());
152: assertMojo("org.apache.maven.plugins", "maven-install-plugin",
153: "install", (MojoBinding) mojos.get(0));
154: assertFalse(((MojoBinding) mojos.get(0)).isOptional());
155:
156: mojos = bb.getDeploy().getBindings();
157:
158: assertEquals(1, mojos.size());
159: assertMojo("org.apache.maven.plugins", "maven-deploy-plugin",
160: "deploy", (MojoBinding) mojos.get(0));
161: assertFalse(((MojoBinding) mojos.get(0)).isOptional());
162: }
163:
164: }
|