Search in sources :

Example 1 with PomResourceImpl

use of org.eclipse.m2e.model.edit.pom.util.PomResourceImpl in project m2e-core-tests by tesla.

the class ExcludeArtifactRefactoringTest method loadResource.

public static PomResourceImpl loadResource(IFile pomFile) throws CoreException {
    String path = pomFile.getFullPath().toOSString();
    URI uri = URI.createPlatformResourceURI(path, true);
    try {
        Resource resource = new PomResourceFactoryImpl().createResource(uri);
        resource.load(new HashMap());
        return (PomResourceImpl) resource;
    } catch (Exception ex) {
        String msg = NLS.bind("Can't load model {0}", pomFile);
        throw new CoreException(new Status(IStatus.ERROR, "test", -1, msg, ex));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) Resource(org.eclipse.emf.ecore.resource.Resource) PomResourceFactoryImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceFactoryImpl) URI(org.eclipse.emf.common.util.URI) PomResourceImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceImpl) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException)

Example 2 with PomResourceImpl

use of org.eclipse.m2e.model.edit.pom.util.PomResourceImpl in project m2e-core-tests by tesla.

the class MavenModelEditTest method testOneRoundtrip.

@Test
public void testOneRoundtrip() throws Exception {
    PomResourceImpl resource = loadModel("one.xml");
    assertEquals(loadFile("one.xml"), MavenModelUtil.toString(resource));
    resource.unload();
}
Also used : PomResourceImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceImpl) Test(org.junit.Test)

Example 3 with PomResourceImpl

use of org.eclipse.m2e.model.edit.pom.util.PomResourceImpl in project m2e-core-tests by tesla.

the class MavenModelEditTest method testAttributeRoundtrip.

@Test
public void testAttributeRoundtrip() throws Exception {
    PomResourceImpl resource = loadModel("attr.xml");
    assertEquals(loadFile("attr.xml"), MavenModelUtil.toString(resource));
    resource.unload();
}
Also used : PomResourceImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceImpl) Test(org.junit.Test)

Example 4 with PomResourceImpl

use of org.eclipse.m2e.model.edit.pom.util.PomResourceImpl in project m2e-core-tests by tesla.

the class MavenModelUtil method createResource.

// XXX find if there is a way around this without creating resources in workspace
public static PomResourceImpl createResource(IProject project, String pomFileName, String content) throws Exception {
    IProgressMonitor monitor = new NullProgressMonitor();
    ByteArrayInputStream is = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
    IFile pomFile = project.getFile(pomFileName);
    if (!pomFile.exists()) {
        pomFile.create(is, true, monitor);
    } else {
        pomFile.setContents(is, true, false, monitor);
    }
    // ProjectResourceSet
    String path = pomFile.getFullPath().toOSString();
    URI uri = URI.createPlatformResourceURI(path, true);
    PomResourceFactoryImpl factory = new PomResourceFactoryImpl();
    PomResourceImpl resource = (PomResourceImpl) factory.createResource(uri);
    resource.load(Collections.EMPTY_MAP);
    return resource;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) PomResourceFactoryImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceFactoryImpl) URI(org.eclipse.emf.common.util.URI) PomResourceImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceImpl)

Example 5 with PomResourceImpl

use of org.eclipse.m2e.model.edit.pom.util.PomResourceImpl in project m2e-core-tests by tesla.

the class MavenModelEditTest method testXpp3domRoundtrip.

// XXX restore properties tests
// public void testPropertiesRemove() throws Exception {
// PomResourceImpl resource = loadModel("properties.xml");
// Model model = resource.getModel();
// 
// Properties properties = model.getProperties();
// 
// XmlCursor cursor = properties.newCursor();
// // model.getProperties().remove("wagonVersion");
// boolean found = cursor.toChild(URI, "wagonVersion");
// assertTrue(found);
// 
// cursor.removeXml();
// 
// assertEquals(loadFile("properties_remove.xml"), MavenModelUtil.toString(resource));
// }
// 
// public void testPropertiesNew() throws Exception {
// PomResourceImpl resource = loadModel("attr.xml");
// Model model = resource.getModel();
// 
// Properties properties = model.getProperties();
// 
// if(properties==null) {
// properties = model.addNewProperties();
// 
// XmlCursor newCursor = properties.newCursor();
// newCursor.insertChars("  ");
// newCursor.toEndToken();
// newCursor.insertChars("\n  ");
// newCursor.toNextToken();
// newCursor.insertChars("\n");
// newCursor.dispose();
// }
// 
// XmlCursor cursor = properties.newCursor();
// cursor.toFirstContentToken();
// cursor.insertChars("\n    ");
// cursor.insertElementWithText("plexusVersion", URI, "1.0-alpha-30");
// cursor.insertChars("\n    ");
// cursor.insertElementWithText("wagonVersion", URI, "1.0-beta-2");
// cursor.dispose();
// 
// assertEquals(loadFile("properties_new.xml"), MavenModelUtil.toString(resource));
// }
@Test
public void testXpp3domRoundtrip() throws Exception {
    PomResourceImpl resource = loadModel("xpp3dom.xml");
    assertEquals(loadFile("xpp3dom.xml"), MavenModelUtil.toString(resource));
    resource.unload();
}
Also used : PomResourceImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceImpl) Test(org.junit.Test)

Aggregations

PomResourceImpl (org.eclipse.m2e.model.edit.pom.util.PomResourceImpl)20 Test (org.junit.Test)16 Model (org.eclipse.m2e.model.edit.pom.Model)12 URI (org.eclipse.emf.common.util.URI)3 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)3 PomResourceFactoryImpl (org.eclipse.m2e.model.edit.pom.util.PomResourceFactoryImpl)3 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 Dependency (org.eclipse.m2e.model.edit.pom.Dependency)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Parent (org.eclipse.m2e.model.edit.pom.Parent)1 PartInitException (org.eclipse.ui.PartInitException)1