Search in sources :

Example 11 with PomResourceImpl

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

the class RenameRefactoring method checkInitialConditions.

@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    PomResourceImpl resource = AbstractPomRefactoring.loadResource(file);
    try {
        Model model = (Model) resource.getContents().get(0);
        this.oldArtifactId = model.getArtifactId();
        this.oldGroupId = model.getGroupId();
        this.oldVersion = model.getVersion();
    } finally {
        resource.unload();
    }
    RefactoringStatus res = new RefactoringStatus();
    return res;
}
Also used : Model(org.eclipse.m2e.model.edit.pom.Model) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) PomResourceImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceImpl)

Example 12 with PomResourceImpl

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

the class AbstractPomRefactoring 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);
        log.error(msg, ex);
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, -1, msg, ex));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) 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) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException)

Example 13 with PomResourceImpl

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

the class MavenModelEditTest method testManyChange.

@Test
public void testManyChange() throws Exception {
    PomResourceImpl resource = loadModel("many.xml");
    Model model = resource.getModel();
    // Dependency dependency = model.getDependencies().getDependencyArray(0);
    Dependency dependency = model.getDependencies().get(0);
    dependency.setArtifactId("changed-maven-lifecycle");
    assertEquals(loadFile("many_change.xml"), MavenModelUtil.toString(resource));
    resource.unload();
}
Also used : Model(org.eclipse.m2e.model.edit.pom.Model) Dependency(org.eclipse.m2e.model.edit.pom.Dependency) PomResourceImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceImpl) Test(org.junit.Test)

Example 14 with PomResourceImpl

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

the class MavenModelEditTest method testManybuildinRoundtrip.

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

Example 15 with PomResourceImpl

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

the class MavenModelEditTest method testManyRoundtrip.

@Test
public void testManyRoundtrip() throws Exception {
    PomResourceImpl resource = loadModel("many.xml");
    assertEquals(loadFile("many.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