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