You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2006/06/27 16:06:52 UTC
svn commit: r417461 - in /cocoon/trunk/tools/cocoon-maven-eclipse-plugin: ./
src/main/java/org/apache/maven/plugin/eclipse/
src/main/java/org/apache/maven/plugin/eclipse/writers/
src/main/resources/org/apache/maven/plugin/eclipse/
Author: reinhard
Date: Tue Jun 27 07:06:52 2006
New Revision: 417461
URL: http://svn.apache.org/viewvc?rev=417461&view=rev
Log:
keep the Bundle-Classpath property in sync with the POM by rewritting the manifest; fix some path problems; better namings for variables; some javadocs; add information on branching
Added:
cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java
Modified:
cocoon/trunk/tools/cocoon-maven-eclipse-plugin/revision.txt
cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java
cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java
cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
Modified: cocoon/trunk/tools/cocoon-maven-eclipse-plugin/revision.txt
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-eclipse-plugin/revision.txt?rev=417461&r1=417460&r2=417461&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-eclipse-plugin/revision.txt (original)
+++ cocoon/trunk/tools/cocoon-maven-eclipse-plugin/revision.txt Tue Jun 27 07:06:52 2006
@@ -1,3 +1,4 @@
+--------------------------------------------------------------------------
2006-06-21: merge with Revision 415916 (Reinhard)
--------------------------------------------------------------------------
Author: reinhard
@@ -11,4 +12,11 @@
Added:
cocoon/trunk/tools/cocoon-maven-eclipse-plugin/
- copied from r396512, maven/plugins/trunk/maven-eclipse-plugin/
---------------------------------------------------------------------------
\ No newline at end of file
+--------------------------------------------------------------------------
+
+merge command for cocoon-maven-eclipse-plugin:
+TBD
+svn merge -r [last-revision]:HEAD http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-eclipse-plugin
+
+merge command for maven-eclipse-plugin:
+svn merge -r 396513:HEAD http://svn.apache.org/repos/asf/cocoon/trunk/tools/cocoon-maven-eclipse-plugin
\ No newline at end of file
Modified: cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java?rev=417461&r1=417460&r2=417461&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java (original)
+++ cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java Tue Jun 27 07:06:52 2006
@@ -28,6 +28,7 @@
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.eclipse.writers.EclipseClasspathWriter;
+import org.apache.maven.plugin.eclipse.writers.EclipseOSGiManifestWriter;
import org.apache.maven.plugin.eclipse.writers.EclipseProjectWriter;
import org.apache.maven.plugin.eclipse.writers.EclipseSettingsWriter;
import org.apache.maven.plugin.eclipse.writers.EclipseWtpComponentWriter;
@@ -225,13 +226,30 @@
private boolean isJavaProject;
/**
- * Is it an PDE project?
+ * Is it an PDE project? If yes, the plugin adds the necessary natures and build commands to
+ * the .project file. Additionally it copies all libraries to a project local directory and
+ * references them instead of referencing the files in the local Maven repository. It's also
+ * ensured that the "Bundle-Classpath" in META-INF/MANIFEST.MF is synchronized.
*
* @parameter expression="${eclipse.pde}" default-value="false"
*/
private boolean pde;
/**
+ * The relative path of the manifest file
+ *
+ * @parameter expression="${eclipse.manifestFile}" default-value="${basedir}/META-INF/MANIFEST.MF"
+ */
+ private String manifestFile;
+
+ /**
+ * The directory of local libraries
+ *
+ * @parameter expression="${eclipse.pdeLibDir}" default-value="lib"
+ */
+ private String pdeLibDir;
+
+ /**
* Getter for <code>buildcommands</code>.
* @return Returns the buildcommands.
*/
@@ -540,9 +558,17 @@
classpathContainers,
localRepository,
buildOutputDirectory,
- pde );
+ pde,
+ pdeLibDir);
}
+ if ( pde )
+ {
+ this.getLog().info("The Maven Eclipse plugin runs in 'pde'-mode.");
+ new EclipseOSGiManifestWriter( getLog(), eclipseProjectDir, project, deps ).write( new File(this.manifestFile),
+ pdeLibDir );
+ }
+
getLog().info( Messages.getString( "EclipsePlugin.wrote", new Object[] { //$NON-NLS-1$
project.getArtifactId(), eclipseProjectDir.getAbsolutePath() } ) );
}
@@ -591,6 +617,10 @@
{
classpathContainers = new ArrayList();
classpathContainers.add( COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER );
+ if( this.pde )
+ {
+// classpathContainers.add( )
+ }
}
private void fillDefaultBuilders( String packaging )
Modified: cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java?rev=417461&r1=417460&r2=417461&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java (original)
+++ cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java Tue Jun 27 07:06:52 2006
@@ -1,5 +1,17 @@
-/**
- *
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.maven.plugin.eclipse.writers;
Modified: cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java?rev=417461&r1=417460&r2=417461&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java (original)
+++ cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java Tue Jun 27 07:06:52 2006
@@ -73,11 +73,31 @@
private static final String ATTR_PATH = "path"; //$NON-NLS-1$
/**
- * Attribute for kind - Container (con), Variable (var)..etc.
+ * Attribute name of kind - Container (con), Variable (var)..etc.
*/
private static final String ATTR_KIND = "kind"; //$NON-NLS-1$
/**
+ * Attribute value for kind: var
+ */
+ private static final String ATTR_VAR = "var"; //$NON-NLS-1$
+
+ /**
+ * Attribute value for kind: lib
+ */
+ private static final String ATTR_LIB = "lib"; //$NON-NLS-1$
+
+ /**
+ * Attribute value for kind: src
+ */
+ private static final String ATTR_SRC = "src"; //$NON-NLS-1$
+
+ /**
+ * Attribute value for kind: src
+ */
+ private static final String ATTR_CON = "con"; //$NON-NLS-1$
+
+ /**
* Element for classpathentry.
*/
private static final String ELT_CLASSPATHENTRY = "classpathentry"; //$NON-NLS-1$
@@ -91,11 +111,6 @@
* File name that stores project classpath settings.
*/
private static final String FILE_DOT_CLASSPATH = ".classpath"; //$NON-NLS-1$
-
- /**
- * Directory name that contains the OSGi libs within the project
- */
- private static final String LIB_DIR = "lib"; //$NON-NLS-1$
public EclipseClasspathWriter( Log log, File eclipseProjectDir, MavenProject project, IdeDependency[] deps )
{
@@ -103,7 +118,7 @@
}
public void write( File projectBaseDir, EclipseSourceDir[] sourceDirs, List classpathContainers,
- ArtifactRepository localRepository, File buildOutputDirectory, boolean rcp )
+ ArtifactRepository localRepository, File buildOutputDirectory, boolean inPdeMode, String pdeLibDir )
throws MojoExecutionException
{
@@ -161,7 +176,7 @@
for ( Iterator it = classpathContainers.iterator(); it.hasNext(); )
{
writer.startElement( ELT_CLASSPATHENTRY );
- writer.addAttribute( ATTR_KIND, "con" ); //$NON-NLS-1$
+ writer.addAttribute( ATTR_KIND, ATTR_CON );
writer.addAttribute( ATTR_PATH, (String) it.next() );
writer.endElement(); // name
}
@@ -176,7 +191,7 @@
if ( dep.isAddedToClasspath() )
{
- addDependency( writer, dep, localRepository, rcp );
+ addDependency( writer, dep, localRepository, projectBaseDir, inPdeMode, pdeLibDir );
}
}
@@ -186,8 +201,8 @@
}
- private void addDependency( XMLWriter writer, IdeDependency dep, ArtifactRepository localRepository, boolean rcp )
- throws MojoExecutionException
+ private void addDependency( XMLWriter writer, IdeDependency dep, ArtifactRepository localRepository,
+ File projectBaseDir, boolean inPdeMode, String pdeLibDir ) throws MojoExecutionException
{
String path;
@@ -198,7 +213,7 @@
if ( dep.isReferencedProject() )
{
path = "/" + dep.getArtifactId(); //$NON-NLS-1$
- kind = "src"; //$NON-NLS-1$
+ kind = ATTR_SRC;
}
else
{
@@ -220,50 +235,48 @@
new Object[] { dep.getArtifactId(), path } ) );
}
- kind = "lib"; //$NON-NLS-1$
+ kind = ATTR_LIB;
}
else
{
File localRepositoryFile = new File( localRepository.getBasedir() );
- if ( dep.isOSGiBundle() && rcp )
- {
- // do nothing as required bundles need to be added to the Eclipse target platform
- return;
- }
- else if ( !dep.isOSGiBundle() && rcp ) // && !dep.isTestDependency() && !dep.isProvided() )
+ // if the dependency is not provided and the plugin runs in "pde mode", the dependency is
+ // added to the Bundle-Classpath:
+ if (inPdeMode && !dep.isProvided())
{
- try {
- File libsDir = new File(LIB_DIR);
- if(!libsDir.exists())
+ try
+ {
+ // TODO problem with reactor build
+ File libsDir = new File( projectBaseDir, pdeLibDir );
+ if (!libsDir.exists())
{
- libsDir.mkdirs();
- }
- FileUtils.copyFileToDirectory(dep.getFile(), libsDir);
-
- }
- catch (IOException e)
- {
- throw new MojoExecutionException(Messages.getString( "EclipsePlugin.cantcopyartifact",
- dep.getArtifactId() ));
- }
- path = LIB_DIR + "/" + dep.getFile().getName();
- kind = "lib";
- }
+ libsDir.mkdirs();
+ }
+ FileUtils.copyFileToDirectory(dep.getFile(), libsDir);
+
+ }
+ catch (IOException e)
+ {
+ throw new MojoExecutionException(Messages.getString("EclipsePlugin.cantcopyartifact",
+ dep.getArtifactId()));
+ }
+ path = pdeLibDir + "/" + dep.getFile().getName();
+ kind = ATTR_LIB;
+ }
+
else
{
-
-
String fullPath = artifactPath.getPath();
- path = "M2_REPO/" //$NON-NLS-1$
+ path = M2_REPO + "/" //$NON-NLS-1$
+ IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, new File( fullPath ), false );
- kind = "var"; //$NON-NLS-1$
+ kind = ATTR_VAR; //$NON-NLS-1$
}
if ( dep.getSourceAttachment() != null )
{
- sourcepath = "M2_REPO/" //$NON-NLS-1$
+ sourcepath = M2_REPO + "/" //$NON-NLS-1$
+ IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, dep.getSourceAttachment(), false );
}
@@ -279,13 +292,13 @@
}
- writer.startElement( "classpathentry" ); //$NON-NLS-1$
- writer.addAttribute( "kind", kind ); //$NON-NLS-1$
- writer.addAttribute( "path", path ); //$NON-NLS-1$
+ writer.startElement( ELT_CLASSPATHENTRY );
+ writer.addAttribute( ATTR_KIND, kind );
+ writer.addAttribute( ATTR_PATH, path );
if ( sourcepath != null )
{
- writer.addAttribute( "sourcepath", sourcepath ); //$NON-NLS-1$
+ writer.addAttribute( ATTR_SOURCEPATH, sourcepath );
}
else if ( javadocpath != null )
{
Added: cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java?rev=417461&view=auto
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java (added)
+++ cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java Tue Jun 27 07:06:52 2006
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.maven.plugin.eclipse.writers;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.Messages;
+import org.apache.maven.plugin.ide.IdeDependency;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * The <code>EclipseOSGiManifestWriter</code> ensures that value of the "Bundle-Classpath" property
+ * in META-INF/MANIFEST.MF is synchronized with the POM by adding all dependencies that don't have the
+ * scope provided.
+ */
+public class EclipseOSGiManifestWriter extends AbstractEclipseResourceWriter
+{
+
+ public final static String ENTRY_BUNDLE_CLASSPATH = "Bundle-ClassPath:";
+
+ public EclipseOSGiManifestWriter(Log log, File eclipseProjectDir, MavenProject project, IdeDependency[] deps)
+ {
+ super( log, eclipseProjectDir, project, deps );
+ }
+
+ public void write(File manifestFile, String libdir) throws MojoExecutionException
+ {
+ // check for existence
+ if( !manifestFile.exists() )
+ {
+ throw new MojoExecutionException( Messages.getString( "nomanifestfile",
+ manifestFile.getAbsolutePath() ) );
+ }
+
+ StringBuffer manifestSb = rewriteManifest(manifestFile, libdir);
+ try
+ {
+// IOUtils.write( manifestSb.toString(), new FileOutputStream( new File( manifestFile.getAbsoluteFile() + "_") ) );
+ IOUtils.write( manifestSb.toString(), new FileOutputStream( manifestFile ) );
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new MojoExecutionException( Messages.getString( "cantwritetofile",
+ manifestFile.getAbsolutePath()));
+ } catch (IOException e)
+ {
+ throw new MojoExecutionException( Messages.getString( "cantwritetofile",
+ manifestFile.getAbsolutePath()), e);
+ }
+ }
+
+ protected StringBuffer rewriteManifest(File manifestFile, String libdir) throws MojoExecutionException
+ {
+ boolean inBundleClasspathEntry = false;
+ StringBuffer manifestSb = new StringBuffer();
+ try {
+ BufferedReader in = new BufferedReader(new FileReader(manifestFile));
+ String str;
+ while ((str = in.readLine()) != null) {
+ if(inBundleClasspathEntry && str.indexOf(":") > -1) {
+ inBundleClasspathEntry = false;
+ manifestSb.append(str + "\n");
+ }
+ else if(str.indexOf(ENTRY_BUNDLE_CLASSPATH) > -1)
+ {
+ inBundleClasspathEntry = true;
+ }
+ else if(inBundleClasspathEntry)
+ {
+ // skip it
+ }
+ else
+ {
+ manifestSb.append(str + "\n");
+ }
+ }
+ in.close();
+ } catch (IOException e)
+ {
+ throw new MojoExecutionException(Messages.getString("cantreadfile", manifestFile.getAbsolutePath()));
+ }
+ manifestSb.append(addBundleClasspathEntries(libdir));
+ // OSGi manifest headers need to end with a line break
+ manifestSb.append("\n");
+ return manifestSb;
+ }
+
+ /**
+ * Add all libraries that don't have the scope "provided" to the "Bundle-Classpath".
+ */
+ protected String addBundleClasspathEntries(String libdir)
+ {
+ StringBuffer bundleClasspathSb = new StringBuffer();
+ if( this.deps != null ) {
+ bundleClasspathSb.append(ENTRY_BUNDLE_CLASSPATH);
+ int countAddedLibs = 0;
+ for( int i = 0; i < this.deps.length; i++ )
+ {
+ if( !this.deps[i].isProvided() )
+ {
+ if( countAddedLibs != 0 )
+ {
+ // TODO problems with line endings might appear
+ bundleClasspathSb.append(",\n");
+ }
+ bundleClasspathSb.append(" " + libdir + "/" + this.deps[i].getFile().getName() + "");
+ countAddedLibs++;
+ }
+ }
+ }
+ return bundleClasspathSb.toString();
+ }
+
+}
Modified: cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java?rev=417461&r1=417460&r2=417461&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java (original)
+++ cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java Tue Jun 27 07:06:52 2006
@@ -1,5 +1,3 @@
-package org.apache.maven.plugin.eclipse.writers;
-
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
@@ -15,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.apache.maven.plugin.eclipse.writers;
import java.io.File;
import java.io.FileOutputStream;
Modified: cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties?rev=417461&r1=417460&r2=417461&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties (original)
+++ cocoon/trunk/tools/cocoon-maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties Tue Jun 27 07:06:52 2006
@@ -33,4 +33,8 @@
EclipseCleanMojo.deletingFile=Deleting file: {0}
EclipseCleanMojo.deletingDirectory=Deleting directory: {0}
EclipseCleanMojo.failedtodelete=Failed to delete {0} file: {0}
-EclipseCleanMojo.nofilefound=No {0} file found
\ No newline at end of file
+EclipseCleanMojo.nofilefound=No {0} file found
+
+EclipseOSGiManifestWriter.nomanifestfile=The references manifest file doesn''t exist: {0}
+
+IdeDependency.cantreadfile=Unable to read file: {0}
\ No newline at end of file