You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ah...@apache.org on 2007/11/02 03:17:02 UTC
svn commit: r591192 [2/4] - in /maven/plugins/branches/MECLIPSE-333/src:
main/java/org/apache/maven/plugin/eclipse/
main/java/org/apache/maven/plugin/eclipse/writers/
main/java/org/apache/maven/plugin/eclipse/writers/rad/
main/java/org/apache/maven/plu...
Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadManifestWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadManifestWriter.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadManifestWriter.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadManifestWriter.java Thu Nov 1 19:16:57 2007
@@ -41,13 +41,10 @@
import org.apache.maven.project.MavenProject;
/**
- * Create or adapt the manifest files for the RAD6 runtime dependencys.
- * attention these will not be used for the real ear these are just to get the
- * runtime enviorment using the maven dependencies.
- *
- * WARNING: The manifest resources added here will not have the benefit of the dependencies
- * of the project, since that's not provided in the setup() apis, one of the locations from which
- * this writer is used in the RadPlugin.
+ * Create or adapt the manifest files for the RAD6 runtime dependencys. attention these will not be used for the real
+ * ear these are just to get the runtime enviorment using the maven dependencies. WARNING: The manifest resources added
+ * here will not have the benefit of the dependencies of the project, since that's not provided in the setup() apis, one
+ * of the locations from which this writer is used in the RadPlugin.
*
* @author <a href="mailto:nir@cfc.at">Richard van Nieuwenhoven </a>
*/
@@ -59,12 +56,11 @@
private static final String META_INF_DIRECTORY = "META-INF";
- private static final String WEBAPP_RESOURCE_DIR = "src" + File.separatorChar + "main" + File.separatorChar
- + "webapp";
+ private static final String WEBAPP_RESOURCE_DIR =
+ "src" + File.separatorChar + "main" + File.separatorChar + "webapp";
/**
- * Search the project for the existing META-INF directory where the manifest
- * should be located.
+ * Search the project for the existing META-INF directory where the manifest should be located.
*
* @return the apsolute path to the META-INF directory
*/
@@ -72,10 +68,10 @@
{
String metaInfBaseDirectory = null;
- if ( config.getProject().equals( Constants.PROJECT_PACKAGING_WAR ) )
+ if ( config.getProject().getPackaging().equals( Constants.PROJECT_PACKAGING_WAR ) )
{
- metaInfBaseDirectory = config.getProject().getBasedir().getAbsolutePath() + File.separatorChar
- + WEBAPP_RESOURCE_DIR;
+ metaInfBaseDirectory =
+ config.getProject().getBasedir().getAbsolutePath() + File.separatorChar + WEBAPP_RESOURCE_DIR;
log.debug( "Attempting to use: " + metaInfBaseDirectory + " for location of META-INF in war project." );
@@ -108,20 +104,14 @@
}
/**
- * Write the manifest files use an existing one it it exists (it will be
- * overwritten!! in a war use webapp/META-INF else use the generated rad6
- * sourcefolder
+ * Write the manifest files use an existing one it it exists (it will be overwritten!! in a war use webapp/META-INF
+ * else use the generated rad6 sourcefolder
*
- * @see AbstractWtpResourceWriter#write(EclipseSourceDir[],
- * ArtifactRepository, File)
- * @param sourceDirs
- * all eclipse source directorys
- * @param localRepository
- * the local reposetory
- * @param buildOutputDirectory
- * build output directory (target)
- * @throws MojoExecutionException
- * when writing the config files was not possible
+ * @see AbstractWtpResourceWriter#write(EclipseSourceDir[], ArtifactRepository, File)
+ * @param sourceDirs all eclipse source directorys
+ * @param localRepository the local reposetory
+ * @param buildOutputDirectory build output directory (target)
+ * @throws MojoExecutionException when writing the config files was not possible
*/
public void write()
throws MojoExecutionException
@@ -137,8 +127,9 @@
Manifest manifest = createNewManifest();
- File manifestFile = new File( metaInfBaseDirectory + File.separatorChar + META_INF_DIRECTORY
- + File.separatorChar + MANIFEST_MF_FILENAME );
+ File manifestFile =
+ new File( metaInfBaseDirectory + File.separatorChar + META_INF_DIRECTORY + File.separatorChar +
+ MANIFEST_MF_FILENAME );
System.out.println( "MANIFEST LOCATION: " + manifestFile );
@@ -161,8 +152,8 @@
}
catch ( Exception e )
{
- log.error( Messages.getString( "EclipsePlugin.cantwritetofile", new Object[] { metaInfBaseDirectory
- + File.separatorChar + MANIFEST_MF_FILENAME } ) );
+ log.error( Messages.getString( "EclipsePlugin.cantwritetofile", new Object[] { metaInfBaseDirectory +
+ File.separatorChar + MANIFEST_MF_FILENAME } ) );
}
}
@@ -190,7 +181,8 @@
if ( !foundMetaInfBaseDirectory )
{
- EclipseSourceDir dir = new EclipseSourceDir( metaInfBaseDirectory, null, true, false, null, null, false );
+ EclipseSourceDir dir =
+ new EclipseSourceDir( metaInfBaseDirectory, null, true, false, null, null, false );
EclipseSourceDir[] newSourceDirs = new EclipseSourceDir[sourceDirs.length + 1];
newSourceDirs[sourceDirs.length] = dir;
@@ -203,14 +195,11 @@
}
/**
- * Add one dependency to the black seperated classpath stringbuffer. Wenn
- * the project is available in the reactor (current build) then the project
- * is used else the jar representing the artifact.
+ * Add one dependency to the black seperated classpath stringbuffer. Wenn the project is available in the reactor
+ * (current build) then the project is used else the jar representing the artifact.
*
- * @param classpath
- * existing classpath to append
- * @param dependency
- * dependency to append as jar or as project
+ * @param classpath existing classpath to append
+ * @param dependency dependency to append as jar or as project
*/
private void addDependencyToClassPath( StringBuffer classpath, IdeDependency dependency )
{
@@ -235,16 +224,12 @@
}
/**
- * Check if the two manifests are equal. Manifest.equal can not be used
- * because of the special case the Classpath entr, witch must be comaired
- * sorted so that a different oder in the classpath does not result in "not
- * equal". This not not realy correct but in this case it is more important
- * to reduce the number of version-controll files.
+ * Check if the two manifests are equal. Manifest.equal can not be used because of the special case the Classpath
+ * entr, witch must be comaired sorted so that a different oder in the classpath does not result in "not equal".
+ * This not not realy correct but in this case it is more important to reduce the number of version-controll files.
*
- * @param manifest
- * the new manifest
- * @param existingManifest
- * to compaire the new one with
+ * @param manifest the new manifest
+ * @param existingManifest to compaire the new one with
* @return are the manifests equal
*/
private boolean areManifestsEqual( Manifest manifest, Manifest existingManifest )
@@ -272,8 +257,8 @@
newValue = orderClasspath( newValue );
existingValue = orderClasspath( existingValue );
}
- if ( ( newValue == null || !newValue.equals( existingValue ) )
- && ( existingValue == null || !existingValue.equals( newValue ) ) )
+ if ( ( newValue == null || !newValue.equals( existingValue ) ) &&
+ ( existingValue == null || !existingValue.equals( newValue ) ) )
{
return false;
}
@@ -282,8 +267,7 @@
}
/**
- * Convert all dependencies in a blank seperated list of jars and projects
- * representing the classpath.
+ * Convert all dependencies in a blank seperated list of jars and projects representing the classpath.
*
* @return the blank separeted classpath string
*/
@@ -314,11 +298,9 @@
}
/**
- * Aphabeticaly sort the classpath. Do this by splitting it up, sort the
- * entries and gleue them together again.
+ * Aphabeticaly sort the classpath. Do this by splitting it up, sort the entries and gleue them together again.
*
- * @param newValue
- * classpath to sort
+ * @param newValue classpath to sort
* @return the sorted classpath
*/
private String orderClasspath( String newValue )
@@ -337,11 +319,9 @@
/**
* Read and parse the existing manifest file.
*
- * @param manifestFile
- * file
+ * @param manifestFile file
* @return the read manifest
- * @throws IOException
- * if the file could not be read
+ * @throws IOException if the file could not be read
*/
private Manifest readExistingManifest( File manifestFile )
throws IOException
@@ -359,16 +339,13 @@
}
/**
- * Verify is the manifest sould be overwritten this sould take in account
- * that the manifest should only be written if the contents of the classpath
- * was changed not the order. The classpath sorting oder should be ignored.
+ * Verify is the manifest sould be overwritten this sould take in account that the manifest should only be written
+ * if the contents of the classpath was changed not the order. The classpath sorting oder should be ignored.
*
- * @param manifest
- * the newly created classpath
- * @param manifestFile
- * the file where the manifest
+ * @param manifest the newly created classpath
+ * @param manifestFile the file where the manifest
* @return if the new manifest file must be written
- * @throws MojoExecutionException
+ * @throws MojoExecutionException
*/
private boolean shouldNewManifestFileBeWritten( Manifest manifest, File manifestFile )
throws MojoExecutionException
@@ -384,8 +361,8 @@
}
catch ( Exception e )
{
- throw new MojoExecutionException( Messages.getString( "EclipseCleanMojo.nofilefound", manifestFile
- .getAbsolutePath() ), e );
+ throw new MojoExecutionException( Messages.getString( "EclipseCleanMojo.nofilefound",
+ manifestFile.getAbsolutePath() ), e );
}
return true;
}
Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/AbstractWtpResourceWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/AbstractWtpResourceWriter.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/AbstractWtpResourceWriter.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/AbstractWtpResourceWriter.java Thu Nov 1 19:16:57 2007
@@ -18,8 +18,11 @@
*/
package org.apache.maven.plugin.eclipse.writers.wtp;
+import java.io.File;
+
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.Constants;
import org.apache.maven.plugin.eclipse.Messages;
import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter;
import org.apache.maven.plugin.ide.IdeDependency;
@@ -28,17 +31,18 @@
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.XMLWriter;
-import java.io.File;
-
/**
* 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 AbstractEclipseWriter
+public abstract class AbstractWtpResourceWriter
+ extends AbstractEclipseWriter
{
+ private static final String ELT_DEPENDENCY_OBJECT = "dependent-object"; //$NON-NLS-1$
+
private static final String ELT_DEPENDENCY_TYPE = "dependency-type"; //$NON-NLS-1$
private static final String ATTR_HANDLE = "handle"; //$NON-NLS-1$
@@ -73,25 +77,22 @@
protected static final String ELT_PROJECT_MODULES = "project-modules"; //$NON-NLS-1$
- protected static final String ARTIFACT_MAVEN_WAR_PLUGIN = "maven-war-plugin"; //$NON-NLS-1$
-
- protected static final String ARTIFACT_MAVEN_EAR_PLUGIN = "maven-ear-plugin"; //$NON-NLS-1$
-
/**
* @param project
* @param writer
* @throws MojoExecutionException
*/
protected void writeModuleTypeAccordingToPackaging( MavenProject project, XMLWriter writer,
- File buildOutputDirectory ) throws MojoExecutionException
+ File buildOutputDirectory )
+ throws MojoExecutionException
{
- if ( "war".equals( config.getPackaging() ) ) //$NON-NLS-1$
+ if ( Constants.PROJECT_PACKAGING_WAR.equals( config.getPackaging() ) ) //$NON-NLS-1$
{
writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.web" ); //$NON-NLS-1$
writer.startElement( ELT_VERSION );
- writer.writeText( JeeUtils.resolveServletVersion(project) );
+ writer.writeText( JeeUtils.resolveServletVersion( project ) );
writer.endElement();
String contextRoot = config.getContextName();
@@ -101,29 +102,28 @@
writer.addAttribute( ATTR_VALUE, contextRoot );
writer.endElement();
}
- else if ( "ejb".equals( config.getPackaging() ) ) //$NON-NLS-1$
+ else if ( Constants.PROJECT_PACKAGING_EJB.equals( config.getPackaging() ) ) //$NON-NLS-1$
{
writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.ejb" ); //$NON-NLS-1$
writer.startElement( ELT_VERSION );
- writer.writeText( JeeUtils.resolveEjbVersion(project) );
+ writer.writeText( JeeUtils.resolveEjbVersion( project ) );
writer.endElement();
writer.startElement( ELT_PROPERTY );
writer.addAttribute( ATTR_NAME, "java-output-path" ); //$NON-NLS-1$
writer.addAttribute( ATTR_VALUE, "/" + //$NON-NLS-1$
- IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory,
- false ) );
+ IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory, false ) );
writer.endElement();
}
- else if ( "ear".equals( config.getPackaging() ) ) //$NON-NLS-1$
+ else if ( Constants.PROJECT_PACKAGING_EAR.equals( config.getPackaging() ) ) //$NON-NLS-1$
{
writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.ear" ); //$NON-NLS-1$
writer.startElement( ELT_VERSION );
- writer.writeText( JeeUtils.resolveJeeVersion(project) );
+ writer.writeText( JeeUtils.resolveJeeVersion( project ) );
writer.endElement();
}
else
@@ -134,8 +134,7 @@
writer.startElement( ELT_PROPERTY );
writer.addAttribute( ATTR_NAME, "java-output-path" ); //$NON-NLS-1$
writer.addAttribute( ATTR_VALUE, "/" + //$NON-NLS-1$
- IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory,
- false ) );
+ IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory, false ) );
writer.endElement();
}
}
@@ -149,10 +148,12 @@
* @param basedir
* @throws MojoExecutionException
*/
- protected void addDependency( XMLWriter writer, IdeDependency dep, ArtifactRepository localRepository, File basedir, String deployPath )
+ protected void addDependency( XMLWriter writer, IdeDependency dep, ArtifactRepository localRepository,
+ File basedir, String deployPath )
throws MojoExecutionException
{
String handle;
+ String dependentObject = null;
if ( dep.isReferencedProject() )
{
@@ -162,6 +163,14 @@
// </dependent-module>
handle = "module:/resource/" + dep.getEclipseProjectName() + "/" + dep.getEclipseProjectName(); //$NON-NLS-1$ //$NON-NLS-2$
+ if ( Constants.PROJECT_PACKAGING_EJB.equals( dep.getType() ) )
+ {
+ dependentObject = "EjbModule_";
+ }
+ else if ( Constants.PROJECT_PACKAGING_WAR.equals( dep.getType() ) )
+ {
+ dependentObject = "WebModule_";
+ }
}
else
{
@@ -183,27 +192,34 @@
if ( dep.isSystemScoped() )
{
- handle =
- "module:/classpath/lib/" //$NON-NLS-1$
- + IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(),
- repoFile, false );
+ handle = "module:/classpath/lib/" //$NON-NLS-1$
+ +
+ IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), repoFile, false );
}
else
{
File localRepositoryFile = new File( localRepository.getBasedir() );
handle = "module:/classpath/var/M2_REPO/" //$NON-NLS-1$
- + IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, repoFile, false );
+ +
+ IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, repoFile, false );
}
}
writer.startElement( ELT_DEPENDENT_MODULE );
- writer.addAttribute( "archiveName",dep.getEclipseProjectName()+"."+dep.getType());
+ writer.addAttribute( "archiveName", dep.getEclipseProjectName() + "." + dep.getType() );
writer.addAttribute( ATTR_DEPLOY_PATH, deployPath ); //$NON-NLS-1$
writer.addAttribute( ATTR_HANDLE, handle );
+ if ( dependentObject != null && config.getWtpVersion() >= 2.0f )
+ {
+ writer.startElement( ELT_DEPENDENCY_OBJECT );
+ writer.writeText( dependentObject + System.identityHashCode( dep ) );
+ writer.endElement();
+ }
+
writer.startElement( ELT_DEPENDENCY_TYPE );
writer.writeText( "uses" ); //$NON-NLS-1$
writer.endElement();
@@ -214,12 +230,12 @@
protected void writeWarOrEarResources( XMLWriter writer, MavenProject project, ArtifactRepository localRepository )
throws MojoExecutionException
{
- // use /WEB-INF/lib for war projects and / or the configured defaultLibBundleDir for ear projects
- String deployDir = IdeUtils.getPluginSetting( config.getProject(), ARTIFACT_MAVEN_EAR_PLUGIN,
- "defaultLibBundleDir",
- "/" );
-
- if (project.getPackaging().equals("war"))
+ // use /WEB-INF/lib for war projects and / or the configured defaultLibBundleDir for ear projects
+ String deployDir =
+ IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN, "defaultLibBundleDir",
+ "/" );
+
+ if ( project.getPackaging().equals( Constants.PROJECT_PACKAGING_WAR ) )
{
deployDir = "/WEB-INF/lib";
}
@@ -230,9 +246,10 @@
String type = dep.getType();
// NB war is needed for ear projects, we suppose nobody adds a war dependency to a war/jar project
- // exclude test and provided and system dependencies outside the project
- if ( ( !dep.isTestDependency() && !dep.isProvided() && !dep.isSystemScopedOutsideProject(project))
- && ( "jar".equals( type ) || "ejb".equals( type ) || "ejb-client".equals( type ) || "war".equals( type ) ) ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ // exclude test and provided and system dependencies outside the project
+ if ( ( !dep.isTestDependency() && !dep.isProvided() && !dep.isSystemScopedOutsideProject( project ) ) &&
+ ( Constants.PROJECT_PACKAGING_JAR.equals( type ) || Constants.PROJECT_PACKAGING_EJB.equals( type ) ||
+ "ejb-client".equals( type ) || Constants.PROJECT_PACKAGING_WAR.equals( type ) ) ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
{
addDependency( writer, dep, localRepository, config.getProject().getBasedir(), deployDir );
}
Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpApplicationXMLWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpApplicationXMLWriter.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpApplicationXMLWriter.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpApplicationXMLWriter.java Thu Nov 1 19:16:57 2007
@@ -12,8 +12,11 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.Constants;
import org.apache.maven.plugin.eclipse.EclipseSourceDir;
import org.apache.maven.plugin.ide.IdeDependency;
+import org.apache.maven.plugin.ide.IdeUtils;
+import org.apache.maven.plugin.ide.JeeUtils;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
@@ -23,496 +26,590 @@
import org.codehaus.plexus.util.xml.Xpp3DomWriter;
/**
- * This writer creates the application.xml and the .modulemaps files for RAD6
- * the the META-INF directory in the project root. this is where RAD6 requires
- * the files to be. These will be independent of the real application.xml witch
- * will be generated the stad. maven way.
+ * This writer creates the application.xml and the .modulemaps files for RAD6 the the META-INF directory in the project
+ * root. this is where RAD6 requires the files to be. These will be independent of the real application.xml witch will
+ * be generated the stad. maven way.
*
* @author <a href="mailto:nir@cfc.at">Richard van Nieuwenhoven</a>
*/
-public class EclipseWtpApplicationXMLWriter extends AbstractWtpResourceWriter {
- private static final String APPLICATION_XML_APPLICATION = "application";
+public class EclipseWtpApplicationXMLWriter
+ extends AbstractWtpResourceWriter
+{
- private static final String APPLICATION_XML_CONTEXT_ROOT = "context-root";
+ private static final String APPLICATION_XML_APPLICATION = "application";
- private static final String APPLICATION_XML_DESCRIPTION = "description";
+ private static final String APPLICATION_XML_CONTEXT_ROOT = "context-root";
- private static final String APPLICATION_XML_DISPLAY_NAME = "display-name";
+ private static final String APPLICATION_XML_DESCRIPTION = "description";
- private static final String APPLICATION_XML_FILENAME = "application.xml";
-
- private static final String APPLICATION_XML_MODULE = "module";
-
- private static final String APPLICATION_XML_WEB = "web";
-
- private static final String APPLICATION_XML_WEB_URI = "web-uri";
-
- private static final String HREF = "href";
-
- private static final String ID = "id";
-
- private static final String MODULEMAP_EARPROJECT_MAP = "modulemap:EARProjectMap";
-
- private static final String MODULEMAPS_APPLICATION_EJB_MODULE = "application:EjbModule";
-
- private static final String MODULEMAPS_APPLICATION_WEB_MODULE = "application:WebModule";
-
- private static final String MODULEMAPS_FILENAME = ".modulemaps";
-
- private static final String MODULEMAPS_MAPPINGS = "mappings";
-
- private static final String MODULEMAPS_PROJECT_NAME = "projectName";
-
- private static final String MODULEMAPS_UTILITY_JARMAPPINGS = "utilityJARMappings";
-
- private static final String URI = "uri";
-
- private static final String VERSION = "version";
-
- private static final String XMI_ID = "xmi:id";
-
- private static final String XMI_TYPE = "xmi:type";
-
- private static final String XMI_VERSION = "xmi:version";
-
- private static final String XMLNS = "xmlns";
-
- private static final String XMLNS_APPLICATION = "xmlns:application";
-
- private static final String XMLNS_MODULEMAP = "xmlns:modulemap";
-
- private static final String XMLNS_SCHEMA_LOCATION = "xmlns:schemaLocation";
-
- private static final String XMLNS_XMI = "xmlns:xmi";
-
- private static final String XMLNS_XSI = "xmlns:xsi";
-
- private Xpp3Dom[] applicationXmlDomChildren;
-
- private Xpp3Dom[] modulemapsXmlDomChildren;
-
- private Xpp3Dom[] webModulesFromPoms;
-
- /**
- * write the application.xml and the .modulemaps file to the META-INF
- * directory.
- *
- * @see AbstractWtpResourceWriter#write(EclipseSourceDir[],
- * ArtifactRepository, File)
- * @throws MojoExecutionException
- * when writing the config files was not possible
- */
- public void write() throws MojoExecutionException {
- String packaging = this.config.getProject().getPackaging();
- if ("ear".equalsIgnoreCase(packaging)) {
- File applicationXmlFile = new File(this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar" + File.separator + "META-INF" + File.separator
- + EclipseWtpApplicationXMLWriter.APPLICATION_XML_FILENAME);
- // create the directory structiure for eclipse deployment
- applicationXmlFile.getParentFile().mkdirs();
- // copy all deployment files to the eclipse deployment
- copyApplicationFiles();
- // delete any existing application.xml so that it will be
- // overwritten.
- applicationXmlFile.delete();
-
- Xpp3Dom applicationXmlDom = readXMLFile(applicationXmlFile);
- if (applicationXmlDom == null) {
- applicationXmlDom = createNewApplicationXml();
- }
- this.applicationXmlDomChildren = applicationXmlDom.getChildren(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE);
-
- File modulemapsXmlFile = new File(this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar" + File.separator + "META-INF" + File.separator
- + EclipseWtpApplicationXMLWriter.MODULEMAPS_FILENAME);
- Xpp3Dom modulemapsXmlDom = readXMLFile(modulemapsXmlFile);
- if (modulemapsXmlDom == null) {
- modulemapsXmlDom = createNewModulemaps();
- }
- this.modulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
-
- this.webModulesFromPoms = ((Xpp3Dom) ((org.apache.maven.model.Plugin) this.config.getProject().getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-ear-plugin"))
- .getConfiguration()).getChild("modules").getChildren("webModule");
-
- IdeDependency[] deps = this.config.getDeps();
- for (int index = 0; index < deps.length; index++) {
- updateApplicationXml(applicationXmlDom, modulemapsXmlDom, deps[index]);
- }
-
- removeUnusedEntries(applicationXmlDom, modulemapsXmlDom);
-
- writePrettyXmlFile(applicationXmlFile, applicationXmlDom);
- writePrettyXmlFile(modulemapsXmlFile, modulemapsXmlDom);
- }
- }
-
- /**
- * Copy all files from application directory to the target eclipseEar
- * directory.
- *
- * @throws MojoExecutionException
- * wenn an error occures during file copieing
- */
- private void copyApplicationFiles() throws MojoExecutionException {
- try {
- File applicationDirectory = new File(this.config.getEclipseProjectDirectory(), "src" + File.separator + "main" + File.separator + "application");
- File eclipseApplicationDirectory = new File(this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar");
- copyDirectoryStructure(applicationDirectory, eclipseApplicationDirectory);
- } catch (IOException e) {
- throw new MojoExecutionException("could not copy files the the eclipseEar directory", e);
- }
- }
-
- /**
- * Copies a entire directory structure without scm files.
- *
- * Note:
- * <ul>
- * <li>It will include empty directories.
- * <li>The <code>sourceDirectory</code> must exists.
- * </ul>
- *
- * @param sourceDirectory
- * @param destinationDirectory
- * @throws IOException
- */
- public static void copyDirectoryStructure(File sourceDirectory, File destinationDirectory) throws IOException {
- if (!sourceDirectory.exists()) {
- return;
- }
-
- File[] files = sourceDirectory.listFiles();
-
- String sourcePath = sourceDirectory.getAbsolutePath();
-
- for (int i = 0; i < files.length; i++) {
- File file = files[i];
-
- String dest = file.getAbsolutePath();
-
- dest = dest.substring(sourcePath.length() + 1);
-
- File destination = new File(destinationDirectory, dest);
-
- if (file.isFile()) {
- destination = destination.getParentFile();
-
- FileUtils.copyFileToDirectory(file, destination);
- } else if (file.isDirectory() && !file.getName().equals(".svn") && !file.getName().equals("CVS")) {
- if (!destination.exists() && !destination.mkdirs()) {
- throw new IOException("Could not create destination directory '" + destination.getAbsolutePath() + "'.");
- }
-
- copyDirectoryStructure(file, destination);
- }
- }
- }
-
- /**
- * there is no existing application.xml file so create a new one.
- *
- * @return the domtree representing the contents of application.xml
- */
- private Xpp3Dom createNewApplicationXml() {
- Xpp3Dom result = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_APPLICATION);
- result.setAttribute(EclipseWtpApplicationXMLWriter.ID, "Application_ID");
- result.setAttribute(EclipseWtpApplicationXMLWriter.VERSION, "1.4");
- result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS, "http://java.sun.com/xml/ns/j2ee");
- result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS_XSI, "http://www.w3.org/2001/XMLSchema-instance");
- result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS_SCHEMA_LOCATION, "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd");
- result.addChild(new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_DESCRIPTION));
- Xpp3Dom name = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_DISPLAY_NAME);
- name.setValue(this.config.getEclipseProjectName());
- result.addChild(name);
- return result;
- }
-
- /**
- * there is no existing .modulemaps file so create a new one.
- *
- * @return the domtree representing the contents of the .modulemaps file
- */
- private Xpp3Dom createNewModulemaps() {
- Xpp3Dom result = new Xpp3Dom(EclipseWtpApplicationXMLWriter.MODULEMAP_EARPROJECT_MAP);
- result.setAttribute(EclipseWtpApplicationXMLWriter.XMI_VERSION, "2.0");
- result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS_XMI, "http://www.omg.org/XMI");
- result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS_APPLICATION, "application.xmi");
- result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS_MODULEMAP, "modulemap.xmi");
- result.setAttribute(EclipseWtpApplicationXMLWriter.XMI_ID, "EARProjectMap_" + System.identityHashCode(this));
- return result;
- }
-
- /**
- * find an existing module entry in the application.xml file by looking up
- * the id in the modulemaps file and then using that to locate the entry in
- * the application.xml file.
- *
- * @param applicationXmlDom
- * application.xml dom tree
- * @param mapping
- * .modulemaps dom tree
- * @return dom tree representing the module
- */
- private Xpp3Dom findModuleInApplicationXml(Xpp3Dom applicationXmlDom, Xpp3Dom mapping) {
- String id = getIdFromMapping(mapping);
- Xpp3Dom[] children = applicationXmlDom.getChildren();
- for (int index = 0; index < children.length; index++) {
- String childId = children[index].getAttribute(EclipseWtpApplicationXMLWriter.ID);
- if (childId != null && childId.equals(id)) {
- return children[index];
- }
- }
- return null;
- }
-
- /**
- * find an artifact in the modulemaps dom tree, if it is missing create a
- * new entry in the modulemaps dom tree.
- *
- * @param dependency
- * dependency to find
- * @param modulemapXmlDom
- * dom-tree of modulemaps
- * @return dom-tree representing the artifact
- */
- private Xpp3Dom findOrCreateArtifact(IdeDependency dependency, Xpp3Dom modulemapXmlDom) {
- // first try to find it
- Xpp3Dom[] children = modulemapXmlDom.getChildren();
- for (int index = 0; index < children.length; index++) {
- if (children[index].getAttribute(EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME).equals(dependency.getEclipseProjectName())) {
- if ((dependency.getType().equals("ejb") || dependency.getType().equals("ejb3")) && children[index].getName().equals(EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS)
- && children[index].getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE).getAttribute(EclipseWtpApplicationXMLWriter.XMI_TYPE).equals(EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_EJB_MODULE)) {
- return children[index];
- } else if (dependency.getType().equals("war") && children[index].getName().equals(EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS)
- && children[index].getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE).getAttribute(EclipseWtpApplicationXMLWriter.XMI_TYPE).equals(EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_WEB_MODULE)) {
- return children[index];
- } else if (dependency.getType().equals("jar") && children[index].getName().equals(EclipseWtpApplicationXMLWriter.MODULEMAPS_UTILITY_JARMAPPINGS)) {
- return children[index];
- } else {
- modulemapXmlDom.removeChild(index);
- break;
- }
- }
- }
- // ok, its missing (or it changed type). create a new one based on its
- // type
- long id = System.identityHashCode(dependency);
- if (dependency.getType().equals("ejb") || dependency.getType().equals("ejb3")) {
- Xpp3Dom mapping = new Xpp3Dom(EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS);
- mapping.setAttribute(EclipseWtpApplicationXMLWriter.XMI_ID, "ModuleMapping_" + id);
- mapping.setAttribute(EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME, dependency.getEclipseProjectName());
- Xpp3Dom module = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE);
- module.setAttribute(EclipseWtpApplicationXMLWriter.XMI_TYPE, EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_EJB_MODULE);
- module.setAttribute(EclipseWtpApplicationXMLWriter.HREF, "META-INF/application.xml#EjbModule_" + id);
- mapping.addChild(module);
- modulemapXmlDom.addChild(mapping);
- return mapping;
- } else if (dependency.getType().equals("war")) {
- Xpp3Dom mapping = new Xpp3Dom(EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS);
- mapping.setAttribute(EclipseWtpApplicationXMLWriter.XMI_ID, "ModuleMapping_" + id);
- mapping.setAttribute(EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME, dependency.getEclipseProjectName());
- Xpp3Dom module = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE);
- module.setAttribute(EclipseWtpApplicationXMLWriter.XMI_TYPE, EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_WEB_MODULE);
- module.setAttribute(EclipseWtpApplicationXMLWriter.HREF, "META-INF/application.xml#WebModule_" + id);
- mapping.addChild(module);
- modulemapXmlDom.addChild(mapping);
- return mapping;
- } else {
- Xpp3Dom utilityJARMapping = new Xpp3Dom(EclipseWtpApplicationXMLWriter.MODULEMAPS_UTILITY_JARMAPPINGS);
- utilityJARMapping.setAttribute(EclipseWtpApplicationXMLWriter.XMI_ID, "UtilityJARMapping_" + id);
- utilityJARMapping.setAttribute(EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME, dependency.getEclipseProjectName());
- utilityJARMapping.setAttribute(EclipseWtpApplicationXMLWriter.URI, dependency.getEclipseProjectName() + ".jar");
- modulemapXmlDom.addChild(utilityJARMapping);
- return utilityJARMapping;
- }
- }
-
- /**
- * get the id from the href of a modulemap.
- *
- * @param mapping
- * the dom-tree of modulemaps
- * @return module identifier
- */
- private String getIdFromMapping(Xpp3Dom mapping) {
- if (mapping.getChildCount() < 1) {
- return "";
- }
- String href = mapping.getChild(0).getAttribute(EclipseWtpApplicationXMLWriter.HREF);
- String id = href.substring(href.indexOf('#') + 1);
- return id;
- }
-
- /**
- * mark the domtree entry as handled (all not handled ones will be deleted).
- *
- * @param xpp3Dom
- * dom element to mark handled
- */
- private void handled(Xpp3Dom xpp3Dom) {
- for (int index = 0; index < this.applicationXmlDomChildren.length; index++) {
- if (this.applicationXmlDomChildren[index] == xpp3Dom) {
- this.applicationXmlDomChildren[index] = null;
- }
- }
- for (int index = 0; index < this.modulemapsXmlDomChildren.length; index++) {
- if (this.modulemapsXmlDomChildren[index] == xpp3Dom) {
- this.modulemapsXmlDomChildren[index] = null;
- }
- }
- }
-
- /**
- * read an xml file (application.xml or .modulemaps).
- *
- * @param xmlFile
- * an xmlfile
- * @return dom-tree representing the file contents
- */
- private Xpp3Dom readXMLFile(File xmlFile) {
- try {
+ private static final String APPLICATION_XML_DISPLAY_NAME = "display-name";
+
+ private static final String APPLICATION_XML_FILENAME = "application.xml";
+
+ private static final String APPLICATION_XML_MODULE = "module";
+
+ private static final String APPLICATION_XML_WEB = "web";
+
+ private static final String APPLICATION_XML_WEB_URI = "web-uri";
+
+ private static final String HREF = "href";
+
+ private static final String ID = "id";
+
+ private static final String MODULEMAP_EARPROJECT_MAP = "modulemap:EARProjectMap";
+
+ private static final String MODULEMAPS_APPLICATION_EJB_MODULE = "application:EjbModule";
+
+ private static final String MODULEMAPS_APPLICATION_WEB_MODULE = "application:WebModule";
+
+ private static final String MODULEMAPS_FILENAME = ".modulemaps";
+
+ private static final String MODULEMAPS_MAPPINGS = "mappings";
+
+ private static final String MODULEMAPS_PROJECT_NAME = "projectName";
+
+ private static final String MODULEMAPS_UTILITY_JARMAPPINGS = "utilityJARMappings";
+
+ private static final String URI = "uri";
+
+ private static final String VERSION = "version";
+
+ private static final String XMI_ID = "xmi:id";
+
+ private static final String XMI_TYPE = "xmi:type";
+
+ private static final String XMI_VERSION = "xmi:version";
+
+ private static final String XMLNS = "xmlns";
+
+ private static final String XMLNS_APPLICATION = "xmlns:application";
+
+ private static final String XMLNS_MODULEMAP = "xmlns:modulemap";
+
+ private static final String XMLNS_SCHEMA_LOCATION = "xmlns:schemaLocation";
+
+ private static final String XMLNS_XMI = "xmlns:xmi";
+
+ private static final String XMLNS_XSI = "xmlns:xsi";
+
+ private Xpp3Dom[] applicationXmlDomChildren;
+
+ private Xpp3Dom[] modulemapsXmlDomChildren;
+
+ private Xpp3Dom[] webModulesFromPoms;
+
+ /**
+ * write the application.xml and the .modulemaps file to the META-INF directory.
+ *
+ * @see AbstractWtpResourceWriter#write(EclipseSourceDir[], ArtifactRepository, File)
+ * @throws MojoExecutionException when writing the config files was not possible
+ */
+ public void write()
+ throws MojoExecutionException
+ {
+ String packaging = this.config.getProject().getPackaging();
+ if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) )
+ {
+ File applicationXmlFile =
+ new File( this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar" +
+ File.separator + "META-INF" + File.separator +
+ EclipseWtpApplicationXMLWriter.APPLICATION_XML_FILENAME );
+ // create the directory structiure for eclipse deployment
+ applicationXmlFile.getParentFile().mkdirs();
+ // copy all deployment files to the eclipse deployment
+ copyApplicationFiles();
+ // delete any existing application.xml so that it will be
+ // overwritten.
+ applicationXmlFile.delete();
+
+ Xpp3Dom applicationXmlDom = readXMLFile( applicationXmlFile );
+ if ( applicationXmlDom == null )
+ {
+ applicationXmlDom = createNewApplicationXml();
+ }
+ this.applicationXmlDomChildren =
+ applicationXmlDom.getChildren( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE );
+
+ File modulemapsXmlFile =
+ new File( this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar" +
+ File.separator + "META-INF" + File.separator + EclipseWtpApplicationXMLWriter.MODULEMAPS_FILENAME );
+ Xpp3Dom modulemapsXmlDom = readXMLFile( modulemapsXmlFile );
+ if ( modulemapsXmlDom == null )
+ {
+ modulemapsXmlDom = createNewModulemaps();
+ }
+ this.modulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
+
+ this.webModulesFromPoms =
+ IdeUtils.getPluginConfigurationDom( config.getProject(), JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN,
+ new String[] { "modules", "webModule" } );
+
+ IdeDependency[] deps = this.config.getDeps();
+ for ( int index = 0; index < deps.length; index++ )
+ {
+ updateApplicationXml( applicationXmlDom, modulemapsXmlDom, deps[index] );
+ }
+
+ removeUnusedEntries( applicationXmlDom, modulemapsXmlDom );
+
+ writePrettyXmlFile( applicationXmlFile, applicationXmlDom );
+ writePrettyXmlFile( modulemapsXmlFile, modulemapsXmlDom );
+ }
+ }
+
+ /**
+ * Copy all files from application directory to the target eclipseEar directory.
+ *
+ * @throws MojoExecutionException wenn an error occures during file copieing
+ */
+ private void copyApplicationFiles()
+ throws MojoExecutionException
+ {
+ try
+ {
+ File applicationDirectory =
+ new File( this.config.getEclipseProjectDirectory(), "src" + File.separator + "main" + File.separator +
+ "application" );
+ File eclipseApplicationDirectory =
+ new File( this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar" );
+ copyDirectoryStructure( applicationDirectory, eclipseApplicationDirectory );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "could not copy files the the eclipseEar directory", e );
+ }
+ }
+
+ /**
+ * Copies a entire directory structure without scm files. Note:
+ * <ul>
+ * <li>It will include empty directories.
+ * <li>The <code>sourceDirectory</code> must exists.
+ * </ul>
+ *
+ * @param sourceDirectory
+ * @param destinationDirectory
+ * @throws IOException
+ */
+ public static void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
+ throws IOException
+ {
+ if ( !sourceDirectory.exists() )
+ {
+ return;
+ }
+
+ File[] files = sourceDirectory.listFiles();
+
+ String sourcePath = sourceDirectory.getAbsolutePath();
+
+ for ( int i = 0; i < files.length; i++ )
+ {
+ File file = files[i];
+
+ String dest = file.getAbsolutePath();
+
+ dest = dest.substring( sourcePath.length() + 1 );
+
+ File destination = new File( destinationDirectory, dest );
+
+ if ( file.isFile() )
+ {
+ destination = destination.getParentFile();
+
+ FileUtils.copyFileToDirectory( file, destination );
+ }
+ else if ( file.isDirectory() && !file.getName().equals( ".svn" ) && !file.getName().equals( "CVS" ) )
+ {
+ if ( !destination.exists() && !destination.mkdirs() )
+ {
+ throw new IOException( "Could not create destination directory '" + destination.getAbsolutePath() +
+ "'." );
+ }
+
+ copyDirectoryStructure( file, destination );
+ }
+ }
+ }
+
+ /**
+ * there is no existing application.xml file so create a new one.
+ *
+ * @return the domtree representing the contents of application.xml
+ */
+ private Xpp3Dom createNewApplicationXml()
+ {
+ Xpp3Dom result = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_APPLICATION );
+ result.setAttribute( EclipseWtpApplicationXMLWriter.ID, "Application_ID" );
+ result.setAttribute( EclipseWtpApplicationXMLWriter.VERSION, "1.4" );
+ result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS, "http://java.sun.com/xml/ns/j2ee" );
+ result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS_XSI, "http://www.w3.org/2001/XMLSchema-instance" );
+ result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS_SCHEMA_LOCATION,
+ "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" );
+ result.addChild( new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_DESCRIPTION ) );
+ Xpp3Dom name = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_DISPLAY_NAME );
+ name.setValue( this.config.getEclipseProjectName() );
+ result.addChild( name );
+ return result;
+ }
+
+ /**
+ * there is no existing .modulemaps file so create a new one.
+ *
+ * @return the domtree representing the contents of the .modulemaps file
+ */
+ private Xpp3Dom createNewModulemaps()
+ {
+ Xpp3Dom result = new Xpp3Dom( EclipseWtpApplicationXMLWriter.MODULEMAP_EARPROJECT_MAP );
+ result.setAttribute( EclipseWtpApplicationXMLWriter.XMI_VERSION, "2.0" );
+ result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS_XMI, "http://www.omg.org/XMI" );
+ result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS_APPLICATION, "application.xmi" );
+ result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS_MODULEMAP, "modulemap.xmi" );
+ result.setAttribute( EclipseWtpApplicationXMLWriter.XMI_ID, "EARProjectMap_" + System.identityHashCode( this ) );
+ return result;
+ }
+
+ /**
+ * find an existing module entry in the application.xml file by looking up the id in the modulemaps file and then
+ * using that to locate the entry in the application.xml file.
+ *
+ * @param applicationXmlDom application.xml dom tree
+ * @param mapping .modulemaps dom tree
+ * @return dom tree representing the module
+ */
+ private Xpp3Dom findModuleInApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom mapping )
+ {
+ String id = getIdFromMapping( mapping );
+ Xpp3Dom[] children = applicationXmlDom.getChildren();
+ for ( int index = 0; index < children.length; index++ )
+ {
+ String childId = children[index].getAttribute( EclipseWtpApplicationXMLWriter.ID );
+ if ( childId != null && childId.equals( id ) )
+ {
+ return children[index];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * find an artifact in the modulemaps dom tree, if it is missing create a new entry in the modulemaps dom tree.
+ *
+ * @param dependency dependency to find
+ * @param modulemapXmlDom dom-tree of modulemaps
+ * @return dom-tree representing the artifact
+ */
+ private Xpp3Dom findOrCreateArtifact( IdeDependency dependency, Xpp3Dom modulemapXmlDom )
+ {
+ // first try to find it
+ Xpp3Dom[] children = modulemapXmlDom.getChildren();
+ for ( int index = 0; index < children.length; index++ )
+ {
+ if ( children[index].getAttribute( EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME ).equals(
+ dependency.getEclipseProjectName() ) )
+ {
+ if ( ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB ) || dependency.getType().equals(
+ "ejb3" ) ) &&
+ children[index].getName().equals( EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS ) &&
+ children[index].getChild( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE ).getAttribute(
+ EclipseWtpApplicationXMLWriter.XMI_TYPE ).equals(
+ EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_EJB_MODULE ) )
+ {
+ return children[index];
+ }
+ else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR ) &&
+ children[index].getName().equals( EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS ) &&
+ children[index].getChild( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE ).getAttribute(
+ EclipseWtpApplicationXMLWriter.XMI_TYPE ).equals(
+ EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_WEB_MODULE ) )
+ {
+ return children[index];
+ }
+ else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_JAR ) &&
+ children[index].getName().equals( EclipseWtpApplicationXMLWriter.MODULEMAPS_UTILITY_JARMAPPINGS ) )
+ {
+ return children[index];
+ }
+ else
+ {
+ modulemapXmlDom.removeChild( index );
+ break;
+ }
+ }
+ }
+ // ok, its missing (or it changed type). create a new one based on its
+ // type
+ long id = System.identityHashCode( dependency );
+ if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB ) || dependency.getType().equals( "ejb3" ) )
+ {
+ Xpp3Dom mapping = new Xpp3Dom( EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS );
+ mapping.setAttribute( EclipseWtpApplicationXMLWriter.XMI_ID, "ModuleMapping_" + id );
+ mapping.setAttribute( EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME,
+ dependency.getEclipseProjectName() );
+ Xpp3Dom module = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE );
+ module.setAttribute( EclipseWtpApplicationXMLWriter.XMI_TYPE,
+ EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_EJB_MODULE );
+ module.setAttribute( EclipseWtpApplicationXMLWriter.HREF, "META-INF/application.xml#EjbModule_" + id );
+ mapping.addChild( module );
+ modulemapXmlDom.addChild( mapping );
+ return mapping;
+ }
+ else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR ) )
+ {
+ Xpp3Dom mapping = new Xpp3Dom( EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS );
+ mapping.setAttribute( EclipseWtpApplicationXMLWriter.XMI_ID, "ModuleMapping_" + id );
+ mapping.setAttribute( EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME,
+ dependency.getEclipseProjectName() );
+ Xpp3Dom module = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE );
+ module.setAttribute( EclipseWtpApplicationXMLWriter.XMI_TYPE,
+ EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_WEB_MODULE );
+ module.setAttribute( EclipseWtpApplicationXMLWriter.HREF, "META-INF/application.xml#WebModule_" + id );
+ mapping.addChild( module );
+ modulemapXmlDom.addChild( mapping );
+ return mapping;
+ }
+ else
+ {
+ Xpp3Dom utilityJARMapping = new Xpp3Dom( EclipseWtpApplicationXMLWriter.MODULEMAPS_UTILITY_JARMAPPINGS );
+ utilityJARMapping.setAttribute( EclipseWtpApplicationXMLWriter.XMI_ID, "UtilityJARMapping_" + id );
+ utilityJARMapping.setAttribute( EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME,
+ dependency.getEclipseProjectName() );
+ utilityJARMapping.setAttribute( EclipseWtpApplicationXMLWriter.URI, dependency.getEclipseProjectName() +
+ ".jar" );
+ modulemapXmlDom.addChild( utilityJARMapping );
+ return utilityJARMapping;
+ }
+ }
+
+ /**
+ * get the id from the href of a modulemap.
+ *
+ * @param mapping the dom-tree of modulemaps
+ * @return module identifier
+ */
+ private String getIdFromMapping( Xpp3Dom mapping )
+ {
+ if ( mapping.getChildCount() < 1 )
+ {
+ return "";
+ }
+ String href = mapping.getChild( 0 ).getAttribute( EclipseWtpApplicationXMLWriter.HREF );
+ String id = href.substring( href.indexOf( '#' ) + 1 );
+ return id;
+ }
+
+ /**
+ * read an xml file (application.xml or .modulemaps).
+ *
+ * @param xmlFile an xmlfile
+ * @return dom-tree representing the file contents
+ */
+ private Xpp3Dom readXMLFile( File xmlFile )
+ {
+ try
+ {
Reader reader = new InputStreamReader( new FileInputStream( xmlFile ), "UTF-8" );
Xpp3Dom applicationXmlDom = Xpp3DomBuilder.build( reader );
- return applicationXmlDom;
- } catch (FileNotFoundException e) {
- return null;
- } catch (Exception e) {
- this.log.error("cantreadfile" + xmlFile.getAbsolutePath());
- // this will trigger creating a new file
- return null;
- }
- }
-
- /**
- * delete all unused entries from the dom-trees.
- *
- * @param applicationXmlDom
- * dom-tree of application.xml
- * @param modulemapsXmlDom
- * dom-tree of modulemaps
- */
- private void removeUnusedEntries(Xpp3Dom applicationXmlDom, Xpp3Dom modulemapsXmlDom) {
- for (int index = 0; index < this.modulemapsXmlDomChildren.length; index++) {
- if (this.modulemapsXmlDomChildren[index] != null) {
- Xpp3Dom[] newModulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
- for (int newIndex = 0; newIndex < newModulemapsXmlDomChildren.length; newIndex++) {
- if (newModulemapsXmlDomChildren[newIndex] == this.modulemapsXmlDomChildren[index]) {
- modulemapsXmlDom.removeChild(newIndex);
- break;
- }
- }
- }
- }
- for (int index = 0; index < this.applicationXmlDomChildren.length; index++) {
- if (this.applicationXmlDomChildren[index] != null) {
- Xpp3Dom[] newApplicationXmlDomChildren = applicationXmlDom.getChildren();
- for (int newIndex = 0; newIndex < newApplicationXmlDomChildren.length; newIndex++) {
- if (newApplicationXmlDomChildren[newIndex] == this.applicationXmlDomChildren[index]) {
- applicationXmlDom.removeChild(newIndex);
- break;
- }
- }
- }
- }
- }
-
- /**
- * update the application.xml and the .modulemaps file for a specified
- * dependency.all WAR an EJB dependencies will go in both files all others
- * only in the modulemaps files. Webapplications contextroots are corrected
- * to the contextRoot specified in the pom.
- *
- * @param applicationXmlDom
- * dom-tree of application.xml
- * @param modulemapXmlDom
- * dom-tree of modulemaps
- * @param dependency
- * the eclipse dependency to handle
- */
- private void updateApplicationXml(Xpp3Dom applicationXmlDom, Xpp3Dom modulemapXmlDom, IdeDependency dependency) {
- if (dependency.isTestDependency() || dependency.isProvided() || dependency.isSystemScopedOutsideProject(this.config.getProject()))
+ return applicationXmlDom;
+ }
+ catch ( FileNotFoundException e )
+ {
+ return null;
+ }
+ catch ( Exception e )
+ {
+ this.log.error( "cantreadfile" + xmlFile.getAbsolutePath() );
+ // this will trigger creating a new file
+ return null;
+ }
+ }
+
+ /**
+ * mark the domtree entry as handled (all not handled ones will be deleted).
+ *
+ * @param xpp3Dom dom element to mark handled
+ */
+ private void handled( Xpp3Dom xpp3Dom )
+ {
+ for ( int index = 0; index < this.applicationXmlDomChildren.length; index++ )
+ {
+ if ( this.applicationXmlDomChildren[index] == xpp3Dom )
+ {
+ this.applicationXmlDomChildren[index] = null;
+ }
+ }
+ for ( int index = 0; index < this.modulemapsXmlDomChildren.length; index++ )
+ {
+ if ( this.modulemapsXmlDomChildren[index] == xpp3Dom )
+ {
+ this.modulemapsXmlDomChildren[index] = null;
+ }
+ }
+ }
+
+ /**
+ * delete all unused entries from the dom-trees.
+ *
+ * @param applicationXmlDom dom-tree of application.xml
+ * @param modulemapsXmlDom dom-tree of modulemaps
+ */
+ private void removeUnusedEntries( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapsXmlDom )
+ {
+ for ( int index = 0; index < this.modulemapsXmlDomChildren.length; index++ )
+ {
+ if ( this.modulemapsXmlDomChildren[index] != null )
+ {
+ Xpp3Dom[] newModulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
+ for ( int newIndex = 0; newIndex < newModulemapsXmlDomChildren.length; newIndex++ )
+ {
+ if ( newModulemapsXmlDomChildren[newIndex] == this.modulemapsXmlDomChildren[index] )
+ {
+ modulemapsXmlDom.removeChild( newIndex );
+ break;
+ }
+ }
+ }
+ }
+ for ( int index = 0; index < this.applicationXmlDomChildren.length; index++ )
+ {
+ if ( this.applicationXmlDomChildren[index] != null )
+ {
+ Xpp3Dom[] newApplicationXmlDomChildren = applicationXmlDom.getChildren();
+ for ( int newIndex = 0; newIndex < newApplicationXmlDomChildren.length; newIndex++ )
+ {
+ if ( newApplicationXmlDomChildren[newIndex] == this.applicationXmlDomChildren[index] )
+ {
+ applicationXmlDom.removeChild( newIndex );
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * update the application.xml and the .modulemaps file for a specified dependency.all WAR an EJB dependencies will
+ * go in both files all others only in the modulemaps files. Webapplications contextroots are corrected to the
+ * contextRoot specified in the pom.
+ *
+ * @param applicationXmlDom dom-tree of application.xml
+ * @param modulemapXmlDom dom-tree of modulemaps
+ * @param dependency the eclipse dependency to handle
+ */
+ private void updateApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapXmlDom, IdeDependency dependency )
+ {
+ if ( dependency.isTestDependency() || dependency.isProvided() ||
+ dependency.isSystemScopedOutsideProject( this.config.getProject() ) )
{
return;
}
- Xpp3Dom mapping = findOrCreateArtifact(dependency, modulemapXmlDom);
- handled(mapping);
- if (dependency.getType().equals("ejb") || dependency.getType().equals("ejb3") ) {
- Xpp3Dom module = findModuleInApplicationXml(applicationXmlDom, mapping);
- if (module == null) {
- module = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE);
- module.setAttribute(EclipseWtpApplicationXMLWriter.ID, getIdFromMapping(mapping));
- Xpp3Dom ejb = new Xpp3Dom("ejb");
- ejb.setValue(dependency.getEclipseProjectName() + ".jar");
- module.addChild(ejb);
- applicationXmlDom.addChild(module);
- } else {
- handled(module);
- module.getChild("ejb").setValue(dependency.getEclipseProjectName() + ".jar");
- }
- } else if (dependency.getType().equals("war")) {
- String contextRootInPom = getContextRootFor(dependency.getEclipseProjectName());
- Xpp3Dom module = findModuleInApplicationXml(applicationXmlDom, mapping);
- if (module == null) {
- module = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE);
- module.setAttribute(EclipseWtpApplicationXMLWriter.ID, getIdFromMapping(mapping));
- Xpp3Dom web = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB);
- Xpp3Dom webUri = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB_URI);
- webUri.setValue(dependency.getEclipseProjectName() + ".war");
- Xpp3Dom contextRoot = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_CONTEXT_ROOT);
- contextRoot.setValue(contextRootInPom);
- web.addChild(webUri);
- web.addChild(contextRoot);
- module.addChild(web);
- applicationXmlDom.addChild(module);
- } else {
- handled(module);
- module.getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB).getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB_URI).setValue(dependency.getEclipseProjectName() + ".war");
- module.getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB).getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_CONTEXT_ROOT).setValue(contextRootInPom);
- }
- }
- }
-
- /**
- * Find the contextRoot specified in the pom and convert it into contectroot
- * for the application.xml.
- *
- * @param artifactId
- * the artifactid to search
- * @return string with the context root
- */
- private String getContextRootFor(String artifactId) {
- for (int index = 0; index < this.webModulesFromPoms.length; index++) {
- if (this.webModulesFromPoms[index].getChild("artifactId").getValue().equals(artifactId)) {
- return new File(this.webModulesFromPoms[index].getChild("contextRoot").getValue()).getName();
- }
- }
- return artifactId;
- }
-
- /**
- * write back a domtree to a xmlfile and use the pretty print for it so that
- * it is human readable.
- *
- * @param xmlFile
- * file to write to
- * @param xmlDomTree
- * dom-tree to write
- * @throws MojoExecutionException
- * if the file could not be written
- */
- private void writePrettyXmlFile(File xmlFile, Xpp3Dom xmlDomTree) throws MojoExecutionException {
- Xpp3Dom original = readXMLFile(xmlFile);
- if (original != null && original.equals(xmlDomTree)) {
- this.log.info("Rad6CleanMojo.unchanged" + xmlFile.getAbsolutePath());
- return;
- }
- Writer w = null;
- xmlFile.getParentFile().mkdirs();
- try {
- w = new OutputStreamWriter( new FileOutputStream(xmlFile), "UTF-8" );
- } catch (IOException ex) {
- throw new MojoExecutionException("Rad6Plugin.erroropeningfile", ex); //$NON-NLS-1$
- }
- XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null);
- Xpp3DomWriter.write(writer, xmlDomTree);
- IOUtil.close(w);
- }
+ Xpp3Dom mapping = findOrCreateArtifact( dependency, modulemapXmlDom );
+ handled( mapping );
+ if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB ) || dependency.getType().equals( "ejb3" ) )
+ {
+ Xpp3Dom module = findModuleInApplicationXml( applicationXmlDom, mapping );
+ if ( module == null )
+ {
+ module = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE );
+ module.setAttribute( EclipseWtpApplicationXMLWriter.ID, getIdFromMapping( mapping ) );
+ Xpp3Dom ejb = new Xpp3Dom( "ejb" );
+ ejb.setValue( dependency.getEclipseProjectName() + ".jar" );
+ module.addChild( ejb );
+ applicationXmlDom.addChild( module );
+ }
+ else
+ {
+ handled( module );
+ module.getChild( "ejb" ).setValue( dependency.getEclipseProjectName() + ".jar" );
+ }
+ }
+ else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR ) )
+ {
+ String contextRootInPom = getContextRootFor( dependency );
+ Xpp3Dom module = findModuleInApplicationXml( applicationXmlDom, mapping );
+ if ( module == null )
+ {
+ module = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE );
+ module.setAttribute( EclipseWtpApplicationXMLWriter.ID, getIdFromMapping( mapping ) );
+ Xpp3Dom web = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB );
+ Xpp3Dom webUri = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB_URI );
+ webUri.setValue( dependency.getEclipseProjectName() + ".war" );
+ Xpp3Dom contextRoot = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_CONTEXT_ROOT );
+ contextRoot.setValue( contextRootInPom );
+ web.addChild( webUri );
+ web.addChild( contextRoot );
+ module.addChild( web );
+ applicationXmlDom.addChild( module );
+ }
+ else
+ {
+ handled( module );
+ module.getChild( EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB ).getChild(
+ EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB_URI ).setValue(
+ dependency.getEclipseProjectName() +
+ ".war" );
+ module.getChild( EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB ).getChild(
+ EclipseWtpApplicationXMLWriter.APPLICATION_XML_CONTEXT_ROOT ).setValue(
+ contextRootInPom );
+ }
+ }
+ }
+
+ /**
+ * Find the contextRoot specified in the pom and convert it into contectroot for the application.xml.
+ *
+ * @param dependency the artifact to search
+ * @return string with the context root
+ */
+ private String getContextRootFor( IdeDependency dependency )
+ {
+ String artifactId = dependency.getArtifactId();
+ String groupId = dependency.getGroupId();
+ for ( int index = 0; index < this.webModulesFromPoms.length; index++ )
+ {
+ Xpp3Dom webGroupId = this.webModulesFromPoms[index].getChild( "groupId" );
+ Xpp3Dom webArtifactId = this.webModulesFromPoms[index].getChild( "artifactId" );
+ Xpp3Dom webContextRoot = this.webModulesFromPoms[index].getChild( "contextRoot" );
+
+ if ( webContextRoot != null && webArtifactId != null && webArtifactId.getValue().equals( artifactId ) &&
+ webGroupId != null && webGroupId.getValue().equals( groupId ) )
+ {
+ return webContextRoot.getValue();
+ }
+ }
+ // no configuration found back to maven-ear-plugin default
+ return dependency.getArtifactId();
+ }
+
+ /**
+ * write back a domtree to a xmlfile and use the pretty print for it so that it is human readable.
+ *
+ * @param xmlFile file to write to
+ * @param xmlDomTree dom-tree to write
+ * @throws MojoExecutionException if the file could not be written
+ */
+ private void writePrettyXmlFile( File xmlFile, Xpp3Dom xmlDomTree )
+ throws MojoExecutionException
+ {
+ Xpp3Dom original = readXMLFile( xmlFile );
+ if ( original != null && original.equals( xmlDomTree ) )
+ {
+ this.log.info( "Rad6CleanMojo.unchanged" + xmlFile.getAbsolutePath() );
+ return;
+ }
+ Writer w = null;
+ xmlFile.getParentFile().mkdirs();
+ try
+ {
+ w = new OutputStreamWriter( new FileOutputStream( xmlFile ), "UTF-8" );
+ }
+ catch ( IOException ex )
+ {
+ throw new MojoExecutionException( "Rad6Plugin.erroropeningfile", ex ); //$NON-NLS-1$
+ }
+ XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null );
+ Xpp3DomWriter.write( writer, xmlDomTree );
+ IOUtil.close( w );
+ }
+
}
Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponent15Writer.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponent15Writer.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponent15Writer.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponent15Writer.java Thu Nov 1 19:16:57 2007
@@ -21,8 +21,9 @@
import org.codehaus.plexus.util.xml.XMLWriter;
/**
- * Component writer for WTP 1.5. File name has changed in WTP 1.5rc2 and the <code>project-version</code> attribute has
- * been added. These ones are the only differences
+ * Component writer for WTP 1.5. File name has changed in WTP 1.5rc2 and the <code>project-version</code> attribute
+ * has been added. These ones are the only differences
+ *
* @author Fabrizio Giustina
* @version $Id$
*/
@@ -32,6 +33,7 @@
/**
* File name where the WTP component settings will be stored for our Eclipse Project.
+ *
* @return <code>org.eclipse.wst.common.component</code>
*/
protected String getComponentFileName()
@@ -41,11 +43,19 @@
/**
* Version number added to component configuration.
+ *
* @return <code>1.0</code>
*/
protected String getProjectVersion()
{
- return "1.5.0"; //$NON-NLS-1$
+ if ( this.config.getWtpVersion() < 2.0f )
+ {
+ return "1.5.0"; //$NON-NLS-1$
+ }
+ else
+ {
+ return "2.0"; //$NON-NLS-1$
+ }
}
/**
Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponentWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponentWriter.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponentWriter.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponentWriter.java Thu Nov 1 19:16:57 2007
@@ -18,24 +18,26 @@
*/
package org.apache.maven.plugin.eclipse.writers.wtp;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.Constants;
import org.apache.maven.plugin.eclipse.EclipseSourceDir;
import org.apache.maven.plugin.eclipse.Messages;
import org.apache.maven.plugin.ide.IdeUtils;
+import org.apache.maven.plugin.ide.JeeUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-
/**
* Creates a .settings folder for Eclipse WTP 1.x 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$
@@ -56,6 +58,7 @@
/**
* File name where the WTP component settings will be stored for our Eclipse Project.
+ *
* @return <code>.component</code>
*/
protected String getComponentFileName()
@@ -65,6 +68,7 @@
/**
* Version number added to component configuration.
+ *
* @return <code>1.0</code>
*/
protected String getProjectVersion()
@@ -86,7 +90,9 @@
Writer w;
try
{
- w = new OutputStreamWriter( new FileOutputStream( new File( settingsDir, getComponentFileName() ) ), "UTF-8" );
+ w =
+ new OutputStreamWriter( new FileOutputStream( new File( settingsDir, getComponentFileName() ) ),
+ "UTF-8" );
}
catch ( IOException ex )
{
@@ -96,19 +102,19 @@
// create a .component file and write out to it
XMLWriter writer = new PrettyPrintXMLWriter( w );
- writeModuleTypeComponent( writer, config.getPackaging(), config.getBuildOutputDirectory(), config
- .getSourceDirs(), config.getLocalRepository() );
+ writeModuleTypeComponent( writer, config.getPackaging(), config.getBuildOutputDirectory(),
+ config.getSourceDirs(), config.getLocalRepository() );
IOUtil.close( w );
}
/**
* Writes out the module type settings for a Web Tools Project to a component file.
- *
+ *
* @param writer
* @param packaging
* @param buildOutputDirectory
- * @param sourceDirs
+ * @param sourceDirs
* @param localRepository
* @throws MojoExecutionException
*/
@@ -124,52 +130,59 @@
}
writer.startElement( ELT_WB_MODULE );
- //we should use the eclipse project name as the deploy name.
+ // we should use the eclipse project name as the deploy name.
writer.addAttribute( ATTR_DEPLOY_NAME, this.config.getEclipseProjectName() );
// deploy-path is "/" for utility and ejb projects, "/WEB-INF/classes" for webapps
String target = "/"; //$NON-NLS-1$
- if ( "war".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+ if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
{
target = "/WEB-INF/classes"; //$NON-NLS-1$
- File warSourceDirectory = new File( IdeUtils.getPluginSetting( config.getProject(), ARTIFACT_MAVEN_WAR_PLUGIN,
- "warSourceDirectory", //$NON-NLS-1$
- config.getProject().getBasedir()+"/src/main/webapp" ) ); //$NON-NLS-1$
-
+ File warSourceDirectory =
+ new File( IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
+ "warSourceDirectory", //$NON-NLS-1$
+ config.getProject().getBasedir() + "/src/main/webapp" ) ); //$NON-NLS-1$
+
writeContextRoot( writer );
writer.startElement( ELT_WB_RESOURCE );
writer.addAttribute( ATTR_DEPLOY_PATH, "/" ); //$NON-NLS-1$
- writer.addAttribute( ATTR_SOURCE_PATH, IdeUtils
- .toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), warSourceDirectory, false ) );
+ writer.addAttribute( ATTR_SOURCE_PATH,
+ IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(),
+ warSourceDirectory, false ) );
writer.endElement();
// @todo is this really needed?
writer.startElement( ELT_PROPERTY );
writer.addAttribute( ATTR_NAME, "java-output-path" ); //$NON-NLS-1$
writer.addAttribute( ATTR_VALUE, "/" //$NON-NLS-1$
- + IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory, false ) );
+ +
+ IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory, false ) );
writer.endElement(); // property
}
- else if ( "ear".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+ else if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
{
-
- String defaultApplicationXML = config.getWtpapplicationxml()?"/target/eclipseEar":"/src/main/application";
-
- String earSourceDirectory = IdeUtils.getPluginSetting( config.getProject(), ARTIFACT_MAVEN_EAR_PLUGIN,
- "earSourceDirectory", //$NON-NLS-1$
- config.getProject().getBasedir()+defaultApplicationXML); //$NON-NLS-1$
+
+ String defaultApplicationXML =
+ config.getWtpapplicationxml() ? "/target/eclipseEar" : "/src/main/application";
+
+ String earSourceDirectory =
+ IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN,
+ "earSourceDirectory", //$NON-NLS-1$
+ config.getProject().getBasedir() + defaultApplicationXML ); //$NON-NLS-1$
writer.startElement( ELT_WB_RESOURCE );
writer.addAttribute( ATTR_DEPLOY_PATH, "/" ); //$NON-NLS-1$
- writer.addAttribute( ATTR_SOURCE_PATH, IdeUtils
- .toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), new File( earSourceDirectory ), false ) );
+ writer.addAttribute( ATTR_SOURCE_PATH,
+ IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(),
+ new File( earSourceDirectory ), false ) );
writer.endElement();
}
- if ( "war".equalsIgnoreCase( packaging ) || "ear".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$ //$NON-NLS-2$
+ if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ) ||
+ Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$ //$NON-NLS-2$
{
// write out the dependencies.
writeWarOrEarResources( writer, config.getProject(), localRepository );
Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpFacetsWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpFacetsWriter.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpFacetsWriter.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpFacetsWriter.java Thu Nov 1 19:16:57 2007
@@ -18,14 +18,6 @@
*/
package org.apache.maven.plugin.eclipse.writers.wtp;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.eclipse.Messages;
-import org.apache.maven.plugin.ide.IdeUtils;
-import org.apache.maven.plugin.ide.JeeUtils;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -34,6 +26,15 @@
import java.util.Iterator;
import java.util.Map.Entry;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.Constants;
+import org.apache.maven.plugin.eclipse.Messages;
+import org.apache.maven.plugin.ide.IdeUtils;
+import org.apache.maven.plugin.ide.JeeUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
/**
* Creates a .settings folder for Eclipse WTP 1.x release and writes out the configuration under it.
*
@@ -117,37 +118,37 @@
writer.startElement( ELT_FIXED );
writer.addAttribute( ATTR_FACET, FACET_JST_JAVA );
writer.endElement(); // element fixed
- if ( "war".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+ if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
{
writer.startElement( ELT_FIXED );
writer.addAttribute( ATTR_FACET, FACET_JST_WEB );
writer.endElement(); // fixed
writer.startElement( ELT_INSTALLED );
writer.addAttribute( ATTR_FACET, FACET_JST_WEB );
- writer.addAttribute( ATTR_VERSION, JeeUtils.resolveServletVersion(config.getProject()) );
+ writer.addAttribute( ATTR_VERSION, JeeUtils.resolveServletVersion( config.getProject() ) );
writer.endElement(); // installed
}
- else if ( "ejb".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+ else if ( Constants.PROJECT_PACKAGING_EJB.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
{
writer.startElement( ELT_FIXED );
writer.addAttribute( ATTR_FACET, FACET_JST_EJB );
writer.endElement(); // fixed
writer.startElement( ELT_INSTALLED );
writer.addAttribute( ATTR_FACET, FACET_JST_EJB );
- writer.addAttribute( ATTR_VERSION, JeeUtils.resolveEjbVersion(config.getProject()) );
+ writer.addAttribute( ATTR_VERSION, JeeUtils.resolveEjbVersion( config.getProject() ) );
writer.endElement(); // installed
}
- else if ( "ear".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+ else if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
{
writer.startElement( ELT_FIXED );
writer.addAttribute( ATTR_FACET, FACET_JST_EAR );
writer.endElement(); // fixed
writer.startElement( ELT_INSTALLED );
writer.addAttribute( ATTR_FACET, FACET_JST_EAR );
- writer.addAttribute( ATTR_VERSION, JeeUtils.resolveJeeVersion(config.getProject()) );
+ writer.addAttribute( ATTR_VERSION, JeeUtils.resolveJeeVersion( config.getProject() ) );
writer.endElement(); // installed
}
- else if ( "jar".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+ else if ( Constants.PROJECT_PACKAGING_JAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
{
writer.startElement( ELT_FIXED );
writer.addAttribute( ATTR_FACET, FACET_JST_UTILITY );
@@ -161,14 +162,14 @@
// common installed element
writer.startElement( ELT_INSTALLED );
writer.addAttribute( ATTR_FACET, FACET_JST_JAVA );
- writer.addAttribute( ATTR_VERSION, IdeUtils.resolveJavaVersion(config.getProject()) );
+ writer.addAttribute( ATTR_VERSION, IdeUtils.resolveJavaVersion( config.getProject() ) );
writer.endElement(); // installed
-
+
writeAdditionalProjectFacets( writer );
-
+
writer.endElement(); // faceted-project
}
-
+
/**
* Writes out any additional project facets specified in the plugin configuration
*
@@ -181,7 +182,7 @@
{
return;
}
-
+
Iterator facetIterator = config.getProjectFacets().entrySet().iterator();
while ( facetIterator.hasNext() )
{