You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ian Carr <ic...@cmicroci.plus.com> on 2008/08/12 19:27:56 UTC

[eclipse:eclipse plugin] Additional classpath entries

Hi,
	I have been trying to configure a set of Eclipse projects using the
eclipse:eclipse plugin. The projects are used both as OSGI/PDE plugins and
at the same time jar's for consumption by generic maven projects use. This
has been somewhat of a struggle due to the differences in dependency
handling in the two environments! 

I started off by trying to use the <pde>true<pde> setting in the
configuration. Which almost set's up the projects as I want them but not
quite, it tries to configure the manifest itself. Unfortunately the entries
it attempts to place in there are not what I need (my project name is not a
valid id, and the classpath it generates is not what I want or in my case
valid. The file also contains blank lines which result in errors in the
eclipse environment.)

In fact I would prefer to be able to disable the manifest generation and use
my manually produced one. Perhaps a flag could be added to control this
behaviour?

I then fell back to trying to configure the Nature, Builder etc entries
myself. And almost got there with the current eclipse plugin. Using the copy
dependency jar's trick from the help pages
(http://maven.apache.org/plugins/maven-eclipse-plugin/pde.html).

The only remaining problem I then had was that the copied dependency jar's
are not added to the classpath of the generated project meaning that each
time I run eclipse:eclipse I have to manually add back the classpath
entries.

To work around this problem I have patched up a copy of the latest
EclipsePlugin to add an additionalClasspathEntries element. I am using this
as a generic way to add any entry into the classpath file much like adding a
builder or nature into the project file. With this I can automatically add
the missing entries for the dependencies copied into the project root,
making the PDE tool happy!

I believe this may be generally useful to other users, and so am attaching
the patch (against 2.5.1) code here. 

I would also like to ask the development team whether this or a similar
facility could be added to the current plugin? I believe this is needed even
when using the pde flag approach, if the dependencies are copied into the
project directories where PDE/Eclipse expects them.

Many thanks to the team for the excellent tool, which saves me significant
amounts of time and effort!

Ian

My pom entries:
______________________

<plugin>
	<!-- Make it a PDE project but leave my manifest alone! -->
	<artifactId>maven-eclipse-plugin</artifactId>
	<configuration>
		<downloadSources>true</downloadSources>
		<additionalBuildcommands>
			<buildCommand>
				<name>org.eclipse.pde.ManifestBuilder</name>
			</buildCommand>
			<buildCommand>
				<name>org.eclipse.pde.SchemaBuilder</name>
			</buildCommand>
		</additionalBuildcommands>
		<additionalProjectnatures>
	
<projectnature>org.eclipse.pde.PluginNature</projectnature>
		</additionalProjectnatures>
		<classpathContainers>
	
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.
internal.debug.ui.launcher.StandardVMType/J2SE-1.5</classpathContainer>
	
<classpathContainer>org.eclipse.pde.core.requiredPlugins</classpathContainer
>
		</classpathContainers>


<!-- the forced entries using the patch-->
		<additionalClasspathEntries>
			<ClasspathEntry>
				<kind>lib</kind>
				<path>asm-3.1.jar</path>
			</ClasspathEntry>

		</additionalClasspathEntries>
<!-- the the forced entries using the patch -->

		<!-- Don't want the repository based entries for the
dependencies -->
		<excludes>
			<exclude>org.antlr:antlr-runtime</exclude>
			<exclude>org.antlr:stringtemplate</exclude>
			<exclude>fsl.asm:asm</exclude>
			<exclude>imc.metaform:metaform-parsers</exclude>
		</excludes>
	</configuration>
</plugin>

The Patch:
___________________

Index: src/main/java/org/apache/maven/plugin/eclipse/ClasspathEntry.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/ClasspathEntry.java
(revision 0)
+++ src/main/java/org/apache/maven/plugin/eclipse/ClasspathEntry.java
(revision 0)
@@ -0,0 +1,31 @@
+package org.apache.maven.plugin.eclipse;
+
+public class ClasspathEntry {
+	private String kind;
+	private String path;
+	private String sourcepath;
+
+	public String getKind() {
+		return kind;
+	}
+
+	public void setKind(String kind) {
+		this.kind = kind;
+	}
+
+	public String getPath() {
+		return path;
+	}
+
+	public void setPath(String path) {
+		this.path = path;
+	}
+
+	public String getSourcepath() {
+		return sourcepath;
+	}
+
+	public void setSourcepath(String sourcepath) {
+		this.sourcepath = sourcepath;
+	}
+}
Index: src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
(revision 684270)
+++ src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
(working copy)
@@ -228,6 +228,23 @@
     private List additionalBuildcommands;
 
     /**
+     * List of eclipse classpath entries to be added to the default ones.:
+     * 
+     * <pre>
+     * &lt;additionalClasspathEntries&gt;
+     *    &lt;ClasspathEntry&gt;
+     *      &lt;kind&gt;lib,con,output,src;/kind&gt;
+     *      &lt;path&gt;the path to add&lt;/path&gt;
+     *      &lt;sourcepath&gt;optional path path to the source of the
entry&lt;/path&gt;
+     *    &lt;/ClasspathEntry&gt;
+     * &lt;/additionalClasspathEntries&gt;
+     * </pre>
+     * 
+     * @parameter
+     */
+    private List additionalClasspathEntries;
+    
+    /**
      * List of container classpath entries. By default the
<code>org.eclipse.jdt.launching.JRE_CONTAINER</code>
      * classpath container is added. Configuration example:
      * 
@@ -1079,6 +1096,7 @@
         }
 
         config.setBuildCommands( new LinkedList( convertedBuildCommands )
);
+        config.setAdditionalClasspathEntries(additionalClasspathEntries);
 
         config.setBuildOutputDirectory( buildOutputDirectory );
         config.setClasspathContainers( classpathContainers );
Index:
src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter
.java
===================================================================
---
src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter
.java	(revision 684270)
+++
src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter
.java	(working copy)
@@ -33,6 +33,7 @@
 
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.eclipse.BuildCommand;
+import org.apache.maven.plugin.eclipse.ClasspathEntry;
 import org.apache.maven.plugin.eclipse.Constants;
 import org.apache.maven.plugin.eclipse.EclipseSourceDir;
 import org.apache.maven.plugin.eclipse.Messages;
@@ -358,6 +359,36 @@
                 }
             }
         }
+        
+        // any additional 'classpathentry' elements we were given
+        List entries = config.getAdditionalClasspathEntries();
+        if (entries != null)
+        {
+	        for ( Iterator it = entries.iterator(); it.hasNext(); )
+	        {
+	        	ClasspathEntry entry = (ClasspathEntry) it.next();
+	        	
+	        	String kind = entry.getKind();
+	        	if (kind == null || kind.length() == 0){
+	        		log.warn( Messages.getString(
"ClasspathEntry kind is null, skipping entry") ); //$NON-NLS-1$
+	        		continue;
+	        	}
+	        	String path = entry.getPath();
+	        	if (path == null || path.length() == 0){
+	        		log.warn( Messages.getString(
"ClasspathEntry path is null, skipping entry") ); //$NON-NLS-1$
+	        		continue;
+	        	}
+	        	String sourcepath = entry.getSourcepath();
+	        	
+	        	writer.startElement(ELT_CLASSPATHENTRY);

+	        	writer.addAttribute(ATTR_KIND, entry.getKind());
+	        	writer.addAttribute(ATTR_PATH, entry.getPath());
+	        	if (sourcepath != null && sourcepath.length() > 0){
+	        		writer.addAttribute(ATTR_SOURCEPATH,
sourcepath);
+	        	}
+	        	writer.endElement();
+	        }
+        }
 
         writer.endElement();
 
Index:
src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.ja
va
===================================================================
---
src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.ja
va	(revision 684270)
+++
src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.ja
va	(working copy)
@@ -147,6 +147,11 @@
 
     private WorkspaceConfiguration workspaceConfiguration;
 
+    /**
+     * The additionalClasspathEntries
+     */
+	private List additionalClasspathEntries;
+
     public WorkspaceConfiguration getWorkspaceConfiguration()
     {
         return workspaceConfiguration;
@@ -583,4 +588,20 @@
         return orderedDeps;
     }
 
+    /**
+     * Setter for additional 'classpathentry' elements to add
+     * @param additionalClasspathEntries the set of additional classpath
entries
+     */
+	public void setAdditionalClasspathEntries(List
additionalClasspathEntries) {
+		this.additionalClasspathEntries =
additionalClasspathEntries;		
+	}
+
+	/**
+	 * Getter for the additional 'classpathentry' elements to add
+	 * @return the value
+	 */
+	public List getAdditionalClasspathEntries() {
+		return additionalClasspathEntries;
+	}
+
 }

No virus found in this outgoing message.
Checked by AVG - http://www.avg.com 
Version: 8.0.138 / Virus Database: 270.6.1/1607 - Release Date: 12/08/2008
07:19


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org