Search in sources :

Example 11 with ExcludeArtifactRefactoring

use of org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring in project m2e-core-tests by tesla.

the class ExcludeArtifactRefactoringTest method createRefactoring.

private static ExcludeArtifactRefactoring createRefactoring(IFile pomFile, ArtifactKey[] keys, IFile exclusionPoint) throws CoreException {
    ExcludeArtifactRefactoring refactoring = new ExcludeArtifactRefactoring(keys);
    IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(pomFile, true, monitor);
    ParentGatherer g = new ParentGatherer(facade);
    List<ParentHierarchyEntry> hierarchy = g.getParentHierarchy(monitor);
    refactoring.setHierarchy(hierarchy);
    ParentHierarchyEntry exclusionModel = null;
    for (ParentHierarchyEntry model : hierarchy) {
        if (exclusionPoint.equals(model.getResource())) {
            exclusionModel = model;
            break;
        }
    }
    if (exclusionModel == null) {
        fail("Exclusion point is not present in project parent hierarchy");
    }
    refactoring.setExclusionPoint(exclusionModel);
    return refactoring;
}
Also used : ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) ParentGatherer(org.eclipse.m2e.core.ui.internal.util.ParentGatherer) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) ExcludeArtifactRefactoring(org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring)

Example 12 with ExcludeArtifactRefactoring

use of org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring in project m2e-core-tests by tesla.

the class ExcludeArtifactRefactoringTest method testMultipleArtifactKeySinglePom.

/*
   * A single pom with multiple exclusions
   */
@Test
public void testMultipleArtifactKeySinglePom() throws Exception {
    IProject project = importProjects(EXCLUDE_PATH, new String[] { "noParent/pom.xml" }, new ResolverConfiguration())[0];
    waitForJobsToComplete();
    new FindEditorRunnable(project.getFile("pom.xml")).open();
    ExcludeArtifactRefactoring refactoring = createRefactoring(project.getFile("pom.xml"), new ArtifactKey[] { VALID, VALID2 });
    RefactoringStatus status = refactoring.checkInitialConditions(monitor);
    assertTrue("Expected OK status from checkInitialConditions: " + status.toString(), status.isOK());
    status = refactoring.checkFinalConditions(monitor);
    assertTrue("Expected OK status from checkFinalConditions: " + status.toString(), status.isOK());
    Change change = refactoring.createChange(monitor);
    assertTrue(change.isEnabled());
    assertTrue("Expected change to affect pom.xml", isAffected(project.getFile("pom.xml"), change));
    Change undo = change.perform(monitor);
    assertNotNull("Undo Operation", undo);
    assertTrue("pom has exclusion set", hasExclusionSet(editor, ROOT, VALID));
    assertTrue("pom has exclusion set", hasExclusionSet(editor, ROOT, VALID2));
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) DocumentChange(org.eclipse.ltk.core.refactoring.DocumentChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) IProject(org.eclipse.core.resources.IProject) ExcludeArtifactRefactoring(org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring) Test(org.junit.Test)

Example 13 with ExcludeArtifactRefactoring

use of org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring in project m2e-core-tests by tesla.

the class ExcludeArtifactRefactoringTest method testArtifactsInMultiplePom.

/*
   * A pom with a workspace parent with exclusions in both
   */
@Test
public void testArtifactsInMultiplePom() throws Exception {
    IProject[] projects = importProjects(EXCLUDE_PATH + "/workspaceParent2", new String[] { "workspaceParent2Module/pom.xml", "workspaceParent2Project/pom.xml" }, new ResolverConfiguration());
    waitForJobsToComplete();
    IProject module = getProject(projects, "workspaceParent2Module");
    new FindEditorRunnable(module.getFile("pom.xml")).open();
    ExcludeArtifactRefactoring refactoring = createRefactoring(module.getFile("pom.xml"), new ArtifactKey[] { VALID, VALID3 });
    RefactoringStatus status = refactoring.checkInitialConditions(monitor);
    assertTrue("Expected OK status from checkInitialConditions: " + status.toString(), status.isOK());
    status = refactoring.checkFinalConditions(monitor);
    assertTrue("Expected OK status from checkFinalConditions: " + status.toString(), status.isOK());
    Change change = refactoring.createChange(monitor);
    assertTrue(change.isEnabled());
    assertTrue("Expected change to affect pom.xml", isAffected(module.getFile("pom.xml"), change));
    Change undo = change.perform(monitor);
    assertNotNull("Undo Operation", undo);
    assertTrue("pom has exclusion set", hasExclusionSet(editor, ROOT, VALID));
    assertTrue("pom has exclusion set", hasExclusionSet(editor, ROOT2, VALID3));
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) DocumentChange(org.eclipse.ltk.core.refactoring.DocumentChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) IProject(org.eclipse.core.resources.IProject) ExcludeArtifactRefactoring(org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring) Test(org.junit.Test)

Aggregations

ExcludeArtifactRefactoring (org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring)13 IProject (org.eclipse.core.resources.IProject)12 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)12 ResolverConfiguration (org.eclipse.m2e.core.project.ResolverConfiguration)12 Test (org.junit.Test)12 Change (org.eclipse.ltk.core.refactoring.Change)11 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)11 DocumentChange (org.eclipse.ltk.core.refactoring.DocumentChange)11 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)11 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)1 ParentGatherer (org.eclipse.m2e.core.ui.internal.util.ParentGatherer)1 ParentHierarchyEntry (org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry)1