You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by fg...@apache.org on 2005/12/31 12:43:44 UTC
svn commit: r360271 - in
/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse:
EclipseUtils.java writers/AbstractWtpResourceWriter.java
writers/EclipseWtpSettingsWriter.java
Author: fgiust
Date: Sat Dec 31 03:43:33 2005
New Revision: 360271
URL: http://svn.apache.org/viewcvs?rev=360271&view=rev
Log:
more WTP 1.0 fixes, set correct version for web and java facets
Modified:
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpSettingsWriter.java
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java?rev=360271&r1=360270&r2=360271&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java Sat Dec 31 03:43:33 2005
@@ -430,31 +430,27 @@
}
/**
- * Extracts the
+ * Extracts the version of the first matching dependencyin the given list.
*
- * @param artifactNames
- * artifact names to compare against for extracting version
- * @param artifacts
- * Collection of dependencies for our project
- * @param offset
- * start position to extract version
- * @param len
- * expected length of the version sub-string
+ * @param artifactNames artifact names to compare against for extracting version
+ * @param artifacts Collection of dependencies for our project
+ * @param len expected length of the version sub-string
* @return
*/
- public static String getDependencyVersion( List artifactNames, Set artifacts, int offset, int len )
+ public static String getDependencyVersion( String[] artifactNames, Set artifacts, int len )
{
for ( Iterator itr = artifacts.iterator(); itr.hasNext(); )
{
Artifact artifact = (Artifact) itr.next();
- for ( Iterator itArtNames = artifactNames.iterator(); itArtNames.hasNext(); )
+ for ( int j = 0; j < artifactNames.length; j++ )
{
- String name = (String) itArtNames.next();
+ String name = artifactNames[j];
if ( name.equals( artifact.getArtifactId() ) )
- return StringUtils.substring( artifact.getVersion(), offset, len );
+ {
+ return StringUtils.substring( artifact.getVersion(), 0, len );
+ }
}
}
- // shouldn't be the case.
- return "";
+ return null;
}
}
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java?rev=360271&r1=360270&r2=360271&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java Sat Dec 31 03:43:33 2005
@@ -4,7 +4,6 @@
package org.apache.maven.plugin.eclipse.writers;
import java.io.File;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -23,8 +22,8 @@
/**
* Base class to hold common constants used by extending classes.
- *
* @author <a href="mailto:rahul.thakur.xdev@gmail.com">Rahul Thakur</a>
+ * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
*/
public abstract class AbstractWtpResourceWriter
extends AbstractEclipseResourceWriter
@@ -114,27 +113,7 @@
writer.startElement( ELT_VERSION ); //$NON-NLS-1$
- // defaults to 2.4, try to detect real version from dependencies
- String servletVersion = "2.4"; //$NON-NLS-1$
- List artifactNames = new ArrayList();
- artifactNames.add( "servlet-api" );
- artifactNames.add( "servletapi" );
- artifactNames.add( "geronimo-spec-servlet" );
- String version = EclipseUtils.getDependencyVersion( artifactNames, project.getArtifacts(), 0, 3 );
- if ( version.trim().equals( "" ) )
- {
- // none of the above specified matched, try geronimo-spec-j2ee
- artifactNames.clear();
- artifactNames.add( "geronimo-spec-j2ee" );
- version = EclipseUtils.getDependencyVersion( artifactNames, project.getArtifacts(), 0, 3 );
- if ( !version.trim().equals( "" ) )
- {
- String j2eeMinorVersion = StringUtils.substring( version, 2, 3 );
- servletVersion = "2." + j2eeMinorVersion;
- }
- }
-
- writer.writeText( servletVersion );
+ writer.writeText( resolveServletVersion() );
writer.endElement();
// use finalName as context root only if it has been explicitely set
@@ -155,8 +134,8 @@
writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.ejb" ); //$NON-NLS-1$ //$NON-NLS-2$
writer.startElement( ELT_VERSION ); //$NON-NLS-1$
- writer.writeText( "2.1" ); //$NON-NLS-1$
- // @todo this is the default, find real ejb version from dependencies
+ writer.writeText( resolveEjbVersion() ); //$NON-NLS-1$
+
writer.endElement();
writer.startElement( ELT_PROPERTY ); //$NON-NLS-1$
@@ -171,8 +150,7 @@
writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.ear" ); //$NON-NLS-1$ //$NON-NLS-2$
writer.startElement( ELT_VERSION ); //$NON-NLS-1$
- writer.writeText( "1.3" ); //$NON-NLS-1$
- // @todo 1.3 is the default
+ writer.writeText( resolveJ2eeVersion() ); //$NON-NLS-1$
writer.endElement();
}
else
@@ -279,4 +257,50 @@
}
}
}
+
+ protected String resolveServletVersion()
+ {
+ String[] artifactNames = new String[] { "servlet-api", "servletapi", "geronimo-spec-servlet" };
+
+ String version = EclipseUtils.getDependencyVersion( artifactNames, getProject().getArtifacts(), 3 );
+ if ( version == null )
+ {
+ // none of the above specified matched, try geronimo-spec-j2ee
+ artifactNames = new String[] { "geronimo-spec-j2ee" };
+ version = EclipseUtils.getDependencyVersion( artifactNames, getProject().getArtifacts(), 3 );
+ if ( version != null )
+ {
+ String j2eeMinorVersion = StringUtils.substring( version, 2, 3 );
+ version = "2." + j2eeMinorVersion;
+ }
+ }
+ return version == null ? "2.4" : version;
+ }
+
+ protected String resolveEjbVersion()
+ {
+ String version = null;
+ // @todo this is the default, find real ejb version from dependencies
+
+ return version == null ? "2.1" : version;
+ }
+
+ protected String resolveJ2eeVersion()
+ {
+ String version = null;
+ // @todo this is the default, find real j2ee version from dependencies
+ return version == null ? "1.3" : version;
+ }
+
+ protected String resolveJavaVersion()
+ {
+ String version = EclipseUtils.getPluginSetting( getProject(), "maven-compiler-plugin", "target", null );
+ if ( version == null )
+ {
+ EclipseUtils.getPluginSetting( getProject(), "maven-compiler-plugin", "source", null );
+ }
+
+ return version == null ? "1.4" : version;
+ }
+
}
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpSettingsWriter.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpSettingsWriter.java?rev=360271&r1=360270&r2=360271&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpSettingsWriter.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpSettingsWriter.java Sat Dec 31 03:43:33 2005
@@ -38,10 +38,10 @@
import org.codehaus.plexus.util.xml.XMLWriter;
/**
- * Creates a .settings folder for Eclipse WTP 1.xRCx release and writes out the
- * configuration under it.
+ * Creates a .settings folder for Eclipse WTP 1.xRCx release and writes out the configuration under it.
*
* @author <a href="mailto:rahul.thakur.xdev@gmail.com">Rahul Thakur</a>
+ * @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a>
* @version $Id$
*/
public class EclipseWtpSettingsWriter
@@ -69,13 +69,12 @@
private static final String ELT_FACETED_PROJECT = "faceted-project";
/**
- * The .settings folder for Web Tools Project 1.xRCx release.
+ * The .settings folder for Web Tools Project 1.x release.
*/
private static final String DIR_WTP_SETTINGS = ".settings";
/**
- * File name where the WTP component settings will be stored for our Eclipse
- * Project.
+ * File name where the WTP component settings will be stored for our Eclipse Project.
*/
private static final String FILE_DOT_COMPONENT = ".component";
@@ -193,10 +192,9 @@
// write out properties.
writer.startElement( ELT_PROPERTY );
writer.addAttribute( ATTR_NAME, "java-output-path" );
- // writer.addAttribute (ATTR_VALUE, "/" +
- // EclipseUtils.toRelativeAndFixSeparator (getProject ().getBasedir (),
- // buildOutputDirectory, false));
- writer.addAttribute( ATTR_VALUE, "/build/classes/" );
+ writer.addAttribute( ATTR_VALUE, "/"
+ + EclipseUtils.toRelativeAndFixSeparator( getProject().getBasedir(), buildOutputDirectory, false ) );
+
// close elements
writer.endElement(); // property
writer.startElement( ELT_PROPERTY );
@@ -226,7 +224,7 @@
writer.endElement(); // fixed
writer.startElement( ELT_INSTALLED );
writer.addAttribute( ATTR_FACET, FACET_JST_WEB );
- writer.addAttribute( ATTR_VERSION, "2.4" );
+ writer.addAttribute( ATTR_VERSION, resolveServletVersion() );
writer.endElement(); // installed
}
else if ( "ejb".equalsIgnoreCase( packaging ) )
@@ -236,7 +234,7 @@
writer.endElement(); // fixed
writer.startElement( ELT_INSTALLED );
writer.addAttribute( ATTR_FACET, FACET_JST_EJB );
- writer.addAttribute( ATTR_VERSION, "2.1" );
+ writer.addAttribute( ATTR_VERSION, resolveEjbVersion() );
writer.endElement(); // installed
}
else if ( "ear".equalsIgnoreCase( packaging ) )
@@ -246,24 +244,22 @@
writer.endElement(); // fixed
writer.startElement( ELT_INSTALLED );
writer.addAttribute( ATTR_FACET, FACET_JST_EAR );
- writer.addAttribute( ATTR_VERSION, "1.4" );
+ writer.addAttribute( ATTR_VERSION, resolveJ2eeVersion() );
writer.endElement(); // installed
}
+
// common installed element
writer.startElement( ELT_INSTALLED );
writer.addAttribute( ATTR_FACET, FACET_JST_JAVA );
- writer.addAttribute( ATTR_VERSION, "1.4" );
+ writer.addAttribute( ATTR_VERSION, resolveJavaVersion() );
writer.endElement(); // installed
writer.endElement(); // faceted-project
}
/**
- * Patch that overrides the default implementation for super{@link #writeWarOrEarResources(XMLWriter, MavenProject, List, ArtifactRepository)}
- * to patch issue of referring to external libs by WTP.<br>
+ * Patch fpr WTP 1.0, external libraries are not copied to deployed app.
* See <a
* href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=116783">https://bugs.eclipse.org/bugs/show_bug.cgi?id=116783</a>
- * <br>
- * TODO: Remove this method definition the issue is addressed in WTP.
*/
protected void copyExternalDependencies( XMLWriter writer, MavenProject project, List referencedReactorArtifacts,
ArtifactRepository localRepository )