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];
}
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"));
}
}
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());
}
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());
}
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));
}
Aggregations