Search in sources :

Example 1 with MavenPomEditor

use of org.eclipse.m2e.editor.pom.MavenPomEditor in project m2e-core-tests by tesla.

the class ExcludeArtifactRefactoringTest method hasExclusionSet.

/*
   * The editor has the given exclusion set
   */
protected static boolean hasExclusionSet(MavenPomEditor editor, final ArtifactKey dependencyKey, final ArtifactKey excluded) throws Exception {
    final boolean[] found = new boolean[1];
    found[0] = false;
    performOnDOMDocument(new OperationTuple(editor.getDocument(), document -> {
        Element dep = findChild(findChild(document.getDocumentElement(), DEPENDENCIES), DEPENDENCY, childEquals(GROUP_ID, dependencyKey.getGroupId()), childEquals(ARTIFACT_ID, dependencyKey.getArtifactId()), childEquals(VERSION, dependencyKey.getVersion()));
        if (dep != null) {
            Element exclusion = findChild(findChild(dep, EXCLUSIONS), EXCLUSION, childEquals(GROUP_ID, excluded.getGroupId()), childEquals(ARTIFACT_ID, excluded.getArtifactId()));
            found[0] = exclusion != null;
        }
    }, true));
    return found[0];
}
Also used : ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) ParentGatherer(org.eclipse.m2e.core.ui.internal.util.ParentGatherer) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) ExcludeArtifactRefactoring(org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring) CoreException(org.eclipse.core.runtime.CoreException) IStatus(org.eclipse.core.runtime.IStatus) PomEdits.performOnDOMDocument(org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument) ARTIFACT_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID) PartInitException(org.eclipse.ui.PartInitException) After(org.junit.After) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) AbstractMavenProjectTestCase(org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase) PomEdits.childEquals(org.eclipse.m2e.core.ui.internal.editing.PomEdits.childEquals) Assert.fail(org.junit.Assert.fail) Change(org.eclipse.ltk.core.refactoring.Change) PomResourceImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceImpl) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) NLS(org.eclipse.osgi.util.NLS) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) EXCLUSIONS(org.eclipse.m2e.core.ui.internal.editing.PomEdits.EXCLUSIONS) Status(org.eclipse.core.runtime.Status) Display(org.eclipse.swt.widgets.Display) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DocumentChange(org.eclipse.ltk.core.refactoring.DocumentChange) List(java.util.List) Resource(org.eclipse.emf.ecore.resource.Resource) Model(org.eclipse.m2e.model.edit.pom.Model) EXCLUSION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.EXCLUSION) DEPENDENCY(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY) Dependency(org.eclipse.m2e.model.edit.pom.Dependency) Exclusion(org.eclipse.m2e.model.edit.pom.Exclusion) URI(org.eclipse.emf.common.util.URI) HashMap(java.util.HashMap) ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IDocument(org.eclipse.jface.text.IDocument) IProject(org.eclipse.core.resources.IProject) VERSION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.VERSION) GROUP_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.GROUP_ID) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) PomEdits.findChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChild) IFile(org.eclipse.core.resources.IFile) PomResourceFactoryImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceFactoryImpl) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) DEPENDENCIES(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES) Element(org.w3c.dom.Element) StructuredModelManager(org.eclipse.wst.sse.core.StructuredModelManager) ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) MavenPlugin(org.eclipse.m2e.core.MavenPlugin) Assert.assertEquals(org.junit.Assert.assertEquals) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) Element(org.w3c.dom.Element)

Example 2 with MavenPomEditor

use of org.eclipse.m2e.editor.pom.MavenPomEditor in project m2e-core by eclipse-m2e.

the class M2EEditorTest method testEffectivePomRendersWithoutException.

@Test
public void testEffectivePomRendersWithoutException() throws CoreException, IOException {
    try (InputStream in = new ByteArrayInputStream(("<project>\n" + "  <modelVersion>4.0.0</modelVersion>\n" + "  <groupId>com.mycompany.app</groupId>\n" + "  <artifactId>my-app</artifactId>\n" + "  <version>1</version>\n" + "</project>").getBytes())) {
        IProject project = createProject("basic", in);
        MavenPomEditor editor = (MavenPomEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), new FileEditorInput(project.getFile("pom.xml")), MavenPomEditor.EDITOR_ID);
        boolean[] done = { false };
        Job.getJobManager().addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                if (event.getJob().getClass().getSimpleName().contains("LoadEffective")) {
                    done[0] = true;
                }
            }
        });
        List<IStatus> allStatus = new ArrayList<>();
        Platform.getLog(Platform.getBundle("org.eclipse.text")).addLogListener((status, plugin) -> allStatus.add(status));
        editor.loadEffectivePOM();
        ITextEditor effectivePomEditor = editor.getEffectivePomSourcePage();
        assertTrue(DisplayHelper.waitForCondition(Display.getDefault(), 3000, () -> done[0]));
        assertEquals(List.of(), allStatus);
        IDocument document = effectivePomEditor.getDocumentProvider().getDocument(effectivePomEditor.getEditorInput());
        assertTrue(document.get().contains("my-app"));
        assertFalse(document.get().contains("Loading"));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ArrayList(java.util.ArrayList) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProject(org.eclipse.core.resources.IProject) MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) ByteArrayInputStream(java.io.ByteArrayInputStream) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 3 with MavenPomEditor

use of org.eclipse.m2e.editor.pom.MavenPomEditor in project m2e-core by eclipse-m2e.

the class EditorTest method testEditorOpenOnSourcePage.

@Test
public void testEditorOpenOnSourcePage() throws CoreException {
    IPreferenceStore preferenceStore = M2EUIPluginActivator.getDefault().getPreferenceStore();
    preferenceStore.setValue(MavenPreferenceConstants.P_DEFAULT_POM_EDITOR_PAGE, true);
    project = ResourcesPlugin.getWorkspace().getRoot().getProject("test" + System.currentTimeMillis());
    project.create(null);
    project.open(null);
    IFile pomFile = project.getFile("pom.xml");
    pomFile.create(getClass().getResourceAsStream("pom.xml"), true, null);
    MavenPomEditor editor = (MavenPomEditor) page.openEditor(new FileEditorInput(pomFile), MavenPomEditor.EDITOR_ID);
    Assert.assertNotNull(editor.getSourcePage());
    Assert.assertEquals(editor.getSourcePage(), editor.getActiveEditor());
}
Also used : IFile(org.eclipse.core.resources.IFile) MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Test(org.junit.Test)

Example 4 with MavenPomEditor

use of org.eclipse.m2e.editor.pom.MavenPomEditor in project m2e-core by eclipse-m2e.

the class M2EEditorTest method testOpenPomEditor.

@Test
public void testOpenPomEditor() throws Exception {
    IProject project = null;
    try (InputStream stream = getClass().getResourceAsStream("pom.xml")) {
        project = createProject("basic", stream);
        IProjectDescription desc = project.getDescription();
        desc.setNatureIds(new String[] { IMavenConstants.NATURE_ID });
        project.setDescription(desc, monitor);
        refreshMavenProject(project);
    }
    waitForJobsToComplete();
    MavenPomEditor editor = (MavenPomEditor) new OpenPomAction().openPomEditor("org.apache.commons", "commons-math3", "3.2", MavenPlugin.getMavenProjectRegistry().getProject(project).getMavenProject(), new NullProgressMonitor());
    assertNotEquals(-1, editor.getActivePage());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IProjectDescription(org.eclipse.core.resources.IProjectDescription) OpenPomAction(org.eclipse.m2e.core.ui.internal.actions.OpenPomAction) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 5 with MavenPomEditor

use of org.eclipse.m2e.editor.pom.MavenPomEditor in project m2e-core by eclipse-m2e.

the class M2EEditorTest method testDeleteResourceClosesEditor.

@Test
public void testDeleteResourceClosesEditor() throws Exception {
    IProject project = null;
    try (InputStream stream = getClass().getResourceAsStream("pom.xml")) {
        project = createProject("basic", stream);
    }
    waitForJobsToComplete();
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    assertEquals(0, page.getEditorReferences().length);
    IEditorPart editor = IDE.openEditor(page, project.getFile("pom.xml"));
    assertTrue(editor instanceof MavenPomEditor);
    assertEquals(1, page.getEditorReferences().length);
    project.getFile("pom.xml").delete(true, null);
    assertTrue(DisplayHelper.waitForCondition(Display.getDefault(), 5000, () -> page.getEditorReferences().length == 0));
}
Also used : MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

MavenPomEditor (org.eclipse.m2e.editor.pom.MavenPomEditor)6 Test (org.junit.Test)6 IProject (org.eclipse.core.resources.IProject)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 FileEditorInput (org.eclipse.ui.part.FileEditorInput)3 IFile (org.eclipse.core.resources.IFile)2 IStatus (org.eclipse.core.runtime.IStatus)2 IDocument (org.eclipse.jface.text.IDocument)2 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)2 OpenPomAction (org.eclipse.m2e.core.ui.internal.actions.OpenPomAction)2 IEditorPart (org.eclipse.ui.IEditorPart)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MavenProject (org.apache.maven.project.MavenProject)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1