Skip to main content



      Home
Home » Archived » Maven Integration (M2E) » Problem with m2eclipse Ecore Pom model
Problem with m2eclipse Ecore Pom model [message #27776] Mon, 01 June 2009 11:11 Go to next message
Eclipse UserFriend
I have tried to update pom.xml using m2eclipse Ecore Pom model
(pre-maven-3 branch).
I have started with the following file:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<packaging>war</packaging>
<name>Test</name>
<version>0.0.1-SNAPSHOT</version>
</project>

and wanted to get the following file:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<packaging>war</packaging>
<name>Test</name>
<version>0.0.1-SNAPSHOT</version>

<build>
<sourceDirectory>src</sourceDirectory>
<outputDirectory>bin</outputDirectory>
<resources>
<resource>
<directory>/src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
artifactId>maven-war-plugin</artifactId>
<configuration>
</configuration>
</plugin>
</plugins>
</build>
</project>

The following code creates the correct file, but the file can't be
removed (Eclipse returns "The xxx/pom.xml file has unsaved changes"):

IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME);
MavenModelManager modelManager =
MavenPlugin.getDefault().getMavenModelManager();
PomResourceImpl pomResource = modelManager.loadResource(pom);
Model projectDocument = (Model)pomResource.getContents().get(0);
Build build = projectDocument.getBuild();
if (build == null) {
build = PomFactory.eINSTANCE.createBuild();
}
String outputDirectory = javaProject.getOutputLocation().toString();
build.setOutputDirectory(outputDirectory);
IClasspathEntry[] entries = javaProject.getRawClasspath();
String sourceDirectory = null;
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
sourceDirectory = entries[i].getPath().toString();
build.setSourceDirectory(sourceDirectory);
}
}
EList<Plugin> plugins = build.getPlugins();
Plugin plugin = PomFactory.eINSTANCE.createPlugin();
plugin.setGroupId("org.apache.maven.plugins");
plugin.setArtifactId("maven-war-plugin");
Configuration configuration = PomFactory.eINSTANCE.createConfiguration();
plugin.setConfiguration(configuration);
plugins.add(plugin);
EList<Resource> resources = build.getResources();
Resource resource = PomFactory.eINSTANCE.createResource();
if (sourceDirectory != null) {
resource.setDirectory(sourceDirectory);
}
EList<String> excludes = resource.getExcludes();
excludes.add("**/*.java");
resources.add(resource);

projectDocument.setBuild(build);
try {
pomResource.save(null);
} catch (IOException e) {
throw new Exception(...);
}
pomResource.unload();

I suppose pomResource.unload is obliged because it releases the WTP's
DOMModel (SSESyncResource.doUnload()).
SSESyncResource.doUnload() releases DOMModel, but doesn't release EMF
resources.
In my opinion, this method needs to be as follows:
@Override
protected void doUnload() {
super.doUnload(); // added to release EMF resources
domModel.releaseFromEdit();
}

In this case all the resources are released, the file can be removed,
but the file isn't created correctly because of a problem in the
synchronization between WTP DOMModel and EMF Ecore Model.
The created file doesn't contain the "plugins" and "resources" elements.

I believe this issue is the cause of a lot of issues in m2eclipse
(especially in the Maven Pom Editor)

A workaround for me is to use Maven Pom model
(org.apache.maven.model.Model).

Snjeza
Re: Problem with m2eclipse Ecore Pom model [message #27858 is a reply to message #27776] Mon, 01 June 2009 13:43 Go to previous message
Eclipse UserFriend
Hi Snjezana,

That does look wrong, doesn't it?

I'm going to add the call in on the branch and see what happens with the
integration tests.



Rich

Snjezana Peco wrote:
> I have tried to update pom.xml using m2eclipse Ecore Pom model
> (pre-maven-3 branch).
> I have started with the following file:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd">
> <modelVersion>4.0.0</modelVersion>
> <groupId>test</groupId>
> <artifactId>test</artifactId>
> <packaging>war</packaging>
> <name>Test</name>
> <version>0.0.1-SNAPSHOT</version>
> </project>
>
> and wanted to get the following file:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd">
>
> <modelVersion>4.0.0</modelVersion>
> <groupId>test</groupId>
> <artifactId>test</artifactId>
> <packaging>war</packaging>
> <name>Test</name>
> <version>0.0.1-SNAPSHOT</version>
>
> <build>
> <sourceDirectory>src</sourceDirectory>
> <outputDirectory>bin</outputDirectory>
> <resources>
> <resource>
> <directory>/src</directory>
> <excludes>
> <exclude>**/*.java</exclude>
> </excludes>
> </resource>
> </resources>
> <plugins>
> <plugin>
> artifactId>maven-war-plugin</artifactId>
> <configuration>
> </configuration>
> </plugin>
> </plugins>
> </build>
> </project>
>
> The following code creates the correct file, but the file can't be
> removed (Eclipse returns "The xxx/pom.xml file has unsaved changes"):
>
> IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME);
> MavenModelManager modelManager =
> MavenPlugin.getDefault().getMavenModelManager();
> PomResourceImpl pomResource = modelManager.loadResource(pom);
> Model projectDocument =
> (Model)pomResource.getContents().get(0);
> Build build = projectDocument.getBuild();
> if (build == null) {
> build = PomFactory.eINSTANCE.createBuild();
> }
> String outputDirectory =
> javaProject.getOutputLocation().toString();
> build.setOutputDirectory(outputDirectory);
> IClasspathEntry[] entries = javaProject.getRawClasspath();
> String sourceDirectory = null;
> for (int i = 0; i < entries.length; i++) {
> if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
> sourceDirectory = entries[i].getPath().toString();
> build.setSourceDirectory(sourceDirectory);
> }
> }
> EList<Plugin> plugins = build.getPlugins();
> Plugin plugin = PomFactory.eINSTANCE.createPlugin();
> plugin.setGroupId("org.apache.maven.plugins");
> plugin.setArtifactId("maven-war-plugin");
> Configuration configuration =
> PomFactory.eINSTANCE.createConfiguration();
> plugin.setConfiguration(configuration);
> plugins.add(plugin);
> EList<Resource> resources = build.getResources();
> Resource resource = PomFactory.eINSTANCE.createResource();
> if (sourceDirectory != null) {
> resource.setDirectory(sourceDirectory);
> }
> EList<String> excludes = resource.getExcludes();
> excludes.add("**/*.java");
> resources.add(resource);
>
> projectDocument.setBuild(build);
> try {
> pomResource.save(null);
> } catch (IOException e) {
> throw new Exception(...);
> }
> pomResource.unload();
>
> I suppose pomResource.unload is obliged because it releases the WTP's
> DOMModel (SSESyncResource.doUnload()).
> SSESyncResource.doUnload() releases DOMModel, but doesn't release EMF
> resources.
> In my opinion, this method needs to be as follows:
> @Override
> protected void doUnload() {
> super.doUnload(); // added to release EMF resources
> domModel.releaseFromEdit();
> }
>
> In this case all the resources are released, the file can be removed,
> but the file isn't created correctly because of a problem in the
> synchronization between WTP DOMModel and EMF Ecore Model.
> The created file doesn't contain the "plugins" and "resources" elements.
>
> I believe this issue is the cause of a lot of issues in m2eclipse
> (especially in the Maven Pom Editor)
>
> A workaround for me is to use Maven Pom model
> (org.apache.maven.model.Model).
>
> Snjeza
Previous Topic:Question or suggestion: sorting dependencies?
Next Topic:multiple maven modules in one eclipse project
Goto Forum:
  


Current Time: Fri Jul 04 02:24:58 EDT 2025

Powered by FUDForum. Page generated in 0.15137 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top