diff --git a/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/LifecycleMappingMetadataPrioritiesTest.java b/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/LifecycleMappingMetadataPrioritiesTest.java index 663ed3732..43c640167 100644 --- a/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/LifecycleMappingMetadataPrioritiesTest.java +++ b/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/LifecycleMappingMetadataPrioritiesTest.java @@ -17,6 +17,7 @@ public class LifecycleMappingMetadataPrioritiesTest extends AbstractLifecycleMappingTest { + // Tests lifecycle mapping declared in default lifecycle mapping metadata public void testDefaultMetadataSource() throws Exception { LifecycleMappingMetadataSource defaultMetadata = loadLifecycleMappingMetadataSource("projects/lifecyclemapping/lifecycleMappingMetadata/LifecycleMappingMetadataPrioritiesTest/defaultMetadata.xml"); @@ -133,4 +134,5 @@ public void testParent() throws Exception { WorkspaceHelpers.assertLifecycleIdErrorMarkerAttributes(marker, "no such lifecycle mapping for test-packaging-a - override"); } + } diff --git a/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/PluginExecutionMetadataPrioritiesTest.java b/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/PluginExecutionMetadataPrioritiesTest.java index f7bb83bdf..090e1b45d 100644 --- a/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/PluginExecutionMetadataPrioritiesTest.java +++ b/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/PluginExecutionMetadataPrioritiesTest.java @@ -19,6 +19,12 @@ @SuppressWarnings("restriction") public class PluginExecutionMetadataPrioritiesTest extends AbstractLifecycleMappingTest { + protected void tearDown() throws Exception { + super.tearDown(); + // ensure there is no workspace lifecycle mapping + setWorkspaceLifecycleMappingMetadataSource(""); + } + public void testDefaultMetadataSource() throws Exception { LifecycleMappingMetadataSource defaultMetadata = loadLifecycleMappingMetadataSource("projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest/defaultMetadata.xml"); LifecycleMappingFactory.setDefaultLifecycleMappingMetadataSource(defaultMetadata); @@ -159,4 +165,151 @@ public void testParent() throws Exception { WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, expectedErrorMessage, null /*lineNumber*/, project); } + + // Workspace mappings override plugin mappings + public void testWorkspace() throws Exception { + + // now set the lifecycle mapping in the workspace. + setWorkspaceLifecycleMappingMetadataSource( + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " org.eclipse.m2e.test.lifecyclemapping\n" + + " test-lifecyclemapping-plugin\n" + + " [1.0.0,)\n" + + " \n" + + " test-goal-for-eclipse-extension2\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""); + + LifecycleMappingMetadataSource defaultMetadata = loadLifecycleMappingMetadataSource("projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest/defaultMetadata.xml"); + LifecycleMappingFactory.setDefaultLifecycleMappingMetadataSource(defaultMetadata); + + IMavenProjectFacade facade = importMavenProject( + "projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest", + "testDefaultMetadataSource/pom.xml"); + assertNotNull("Expected not null MavenProjectFacade", facade); + IProject project = facade.getProject(); + List errorMarkers = WorkspaceHelpers.findErrorMarkers(project); + assertNotNull(errorMarkers); + assertEquals(WorkspaceHelpers.toString(errorMarkers), 2, errorMarkers.size()); + + // should still have lifecycle errors + String expectedErrorMessage = "Plugin execution not covered by lifecycle configuration: org.eclipse.m2e.test.lifecyclemapping:test-lifecyclemapping-plugin:1.0.0:test-goal-1 (execution: default-test-goal-1, phase: process-resources)"; + WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, expectedErrorMessage, + 11 /*lineNumber*/, project); + + // should not have any plugin execution errors + expectedErrorMessage = "Project configurator \"missing default project configurator id for test-lifecyclemapping-plugin:test-goal-1\" is not available. To enable full functionality, install the project configurator and run Maven->Update Project Configuration."; + WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, + expectedErrorMessage, null /*lineNumber*/, project); + } + // Embedded metadata should override Workspace mappings + public void testPomOverridesWorkspace() throws Exception { + + // now set the lifecycle mapping in the workspace. + setWorkspaceLifecycleMappingMetadataSource( + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " org.eclipse.m2e.test.lifecyclemapping\n" + + " test-lifecyclemapping-plugin\n" + + " [1.0.0,)\n" + + " \n" + + " test-goal-for-eclipse-extension2\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " no such project configurator id for test-lifecyclemapping-plugin:test-goal-for-eclipse-extension2 - embedded from pom\n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""); + + IMavenProjectFacade parentFacade = importMavenProject( + "projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest", + "testParent/pom.xml"); + assertNotNull("Expected not null MavenProjectFacade", parentFacade); + IProject project = parentFacade.getProject(); + WorkspaceHelpers.assertNoErrors(project); + + // parent pom should have no errors even though bad metadata is in the workspace mappings + IMavenProjectFacade facade = importMavenProject( + "projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest", + "testParent/useParent/pom.xml"); + assertNotNull("Expected not null MavenProjectFacade", facade); + project = facade.getProject(); + List errorMarkers = WorkspaceHelpers.findErrorMarkers(project); + assertNotNull(errorMarkers); + assertEquals(WorkspaceHelpers.toString(errorMarkers), 2, errorMarkers.size()); + String expectedErrorMessage = "Plugin execution not covered by lifecycle configuration: org.eclipse.m2e.test.lifecyclemapping:test-lifecyclemapping-plugin:1.0.0:test-goal-1 (execution: default-test-goal-1, phase: process-resources)"; + IMarker marker = WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, + expectedErrorMessage, null /*lineNumber*/, project); + SourceLocation causeLocation = new SourceLocation(parentFacade.getMavenProject().getFile().getAbsolutePath(), + WorkspaceHelpers.getModelId(parentFacade.getMavenProject()), 11, 7, 14); + WorkspaceHelpers.assertMarkerLocation(new SourceLocation(5, 3, 10, causeLocation), marker); + expectedErrorMessage = "Project configurator \"no such project configurator id for test-lifecyclemapping-plugin:test-goal-1 - parent\" is not available. To enable full functionality, install the project configurator and run Maven->Update Project Configuration."; + marker = WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, expectedErrorMessage, + null /*lineNumber*/, project); + WorkspaceHelpers.assertMarkerLocation(new SourceLocation(5, 3, 10, causeLocation), marker); + } + + // metadata from workspace should override eclipse extension metadata + public void testWorkspaceOverridesEclipseExtensions() throws Exception { + // now set the lifecycle mapping in the workspace. + setWorkspaceLifecycleMappingMetadataSource( + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " org.eclipse.m2e.test.lifecyclemapping\n" + + " test-lifecyclemapping-plugin\n" + + " [1.0.0,)\n" + + " \n" + + " test-goal-for-eclipse-extension2\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " no such project configurator id for test-lifecyclemapping-plugin:test-goal-for-eclipse-extension2 - workspace\n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""); + LifecycleMappingMetadataSource defaultMetadata = loadLifecycleMappingMetadataSource("projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest/defaultMetadata.xml"); + LifecycleMappingFactory.setDefaultLifecycleMappingMetadataSource(defaultMetadata); + + IMavenProjectFacade facade = importMavenProject( + "projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest", + "testEclipseExtension/pom.xml"); + assertNotNull("Expected not null MavenProjectFacade", facade); + IProject project = facade.getProject(); + + // should have an error since workspace overrides with bad lifecycle data + String expectedErrorMessage = "Plugin execution not covered by lifecycle configuration: org.eclipse.m2e.test.lifecyclemapping:test-lifecyclemapping-plugin:1.0.0:test-goal-for-eclipse-extension2 (execution: default-test-goal-for-eclipse-extension2, phase: compile)"; + WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, expectedErrorMessage, + 11 /*lineNumber*/, project); + + expectedErrorMessage = "Project configurator \"no such project configurator id for test-lifecyclemapping-plugin:test-goal-for-eclipse-extension2 - workspace\" is not available. To enable full functionality, install the project configurator and run Maven->Update Project Configuration."; + IMarker marker = WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, + expectedErrorMessage, 11 /*lineNumber*/, project); + WorkspaceHelpers + .assertConfiguratorErrorMarkerAttributes( + marker, + "no such project configurator id for test-lifecyclemapping-plugin:test-goal-for-eclipse-extension2 - workspace"); + } } diff --git a/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/WorkspaceMappingsFileTest.java b/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/WorkspaceMappingsFileTest.java new file mode 100644 index 000000000..b529446a7 --- /dev/null +++ b/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/WorkspaceMappingsFileTest.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2012 VMware, Inc + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Eisenberg - Work on Bug 350414 + *******************************************************************************/ + +package org.eclipse.m2e.tests.lifecycle; + +import org.eclipse.m2e.tests.common.AbstractLifecycleMappingTest; + + +/** + * Tests for changing the workspace lifecycle mappings file + * WorkspaceMappingsFileTest + * + * @author andrew + */ +public class WorkspaceMappingsFileTest extends AbstractLifecycleMappingTest { + + protected void tearDown() throws Exception { + mavenConfiguration.setWorkspaceMappingsFile(null); + super.tearDown(); + } + + public void testIsDefault() throws Exception { + assertEquals(mavenConfiguration.getDefaultWorkspaceMappingsFile(), + mavenConfiguration.getWorkspaceMappingsFile()); + } + + public void testChangeFromDefault() throws Exception { + String newFile = "foo"; + mavenConfiguration.setWorkspaceMappingsFile(newFile); + assertEquals(newFile, + mavenConfiguration.getWorkspaceMappingsFile()); + } + public void testChangeToDefault() throws Exception { + String newFile = "foo"; + mavenConfiguration.setWorkspaceMappingsFile(newFile); + mavenConfiguration.setWorkspaceMappingsFile(null); + assertEquals(mavenConfiguration.getDefaultWorkspaceMappingsFile(), + mavenConfiguration.getWorkspaceMappingsFile()); + } + + public void testChangeText() throws Exception { + String origText = mavenConfiguration.getWorkspaceMappings(); + String newText = "blah!"; + mavenConfiguration.setWorkspaceMappings(newText); + assertEquals(newText, mavenConfiguration.getWorkspaceMappings()); + mavenConfiguration.setWorkspaceMappings(origText); + assertEquals(origText, mavenConfiguration.getWorkspaceMappings()); + } +}