+ foo
+
+
+foo
+
+
Index: org.maven.ide.eclipse.wtp.tests/projects/MNGECLIPSE-688/jee1/war/src/main/webapp/WEB-INF/web.xml
===================================================================
--- org.maven.ide.eclipse.wtp.tests/projects/MNGECLIPSE-688/jee1/war/src/main/webapp/WEB-INF/web.xml (revision 0)
+++ org.maven.ide.eclipse.wtp.tests/projects/MNGECLIPSE-688/jee1/war/src/main/webapp/WEB-INF/web.xml (revision 0)
@@ -0,0 +1,10 @@
+
+
+
+ foo
+
+
Index: org.maven.ide.eclipse.wtp.tests/src/org/maven/ide/eclipse/wtp/WTPProjectConfiguratorTest.java
===================================================================
--- org.maven.ide.eclipse.wtp.tests/src/org/maven/ide/eclipse/wtp/WTPProjectConfiguratorTest.java (revision 1148)
+++ org.maven.ide.eclipse.wtp.tests/src/org/maven/ide/eclipse/wtp/WTPProjectConfiguratorTest.java (working copy)
@@ -8,6 +8,7 @@
package org.maven.ide.eclipse.wtp;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IClasspathContainer;
@@ -15,12 +16,16 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jst.common.project.facet.JavaFacetUtils;
+import org.eclipse.jst.j2ee.internal.J2EEConstants;
+import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
import org.eclipse.jst.j2ee.web.project.facet.WebFacetUtils;
import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.maven.ide.eclipse.MavenPlugin;
@@ -36,6 +41,11 @@
*/
public class WTPProjectConfiguratorTest extends AsbtractMavenProjectTestCase {
private static final IProjectFacetVersion DEFAULT_WEB_VERSION = WebFacetUtils.WEB_23;
+ public static final IProjectFacet EJB_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.EJB);
+ public static final IProjectFacet UTILITY_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.UTILITY);
+ public static final IProjectFacetVersion UTILITY_10 = UTILITY_FACET.getVersion("1.0");
+ public static final IProjectFacet EAR_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.ENTERPRISE_APPLICATION);
+ private static final IProjectFacetVersion DEFAULT_EAR_FACET = IJ2EEFacetConstants.ENTERPRISE_APPLICATION_13;
public void testSimple01_import() throws Exception {
IProject project = importProject("projects/simple/p01/pom.xml", new ResolverConfiguration());
@@ -151,4 +161,70 @@
IVirtualReference[] references = core.getReferences();
assertTrue(references == null || references.length == 0);
}
+
+
+ public void testMNGECLIPSE688_defaultEjb() throws Exception {
+ IProject project = importProject("projects/MNGECLIPSE-688/ejb1/pom.xml", new ResolverConfiguration());
+
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project);
+ assertNotNull(facetedProject);
+ assertTrue(facetedProject.hasProjectFacet(JavaFacetUtils.JAVA_FACET));
+ //Defaut ejb project should have 2.1 project facet
+ assertEquals(IJ2EEFacetConstants.EJB_21, facetedProject.getInstalledVersion(EJB_FACET));
+
+ IFile ejbJar = project.getFile("src/main/resources/META-INF/ejb-jar.xml");
+ assertNotNull(ejbJar);
+ //TODO check DTD
+ }
+
+ public void testMNGECLIPSE688_Ejb_30() throws Exception {
+ IProject project = importProject("projects/MNGECLIPSE-688/ejb2/pom.xml", new ResolverConfiguration());
+
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project);
+ assertNotNull(facetedProject);
+ assertTrue(facetedProject.hasProjectFacet(JavaFacetUtils.JAVA_FACET));
+ assertEquals(JavaFacetUtils.JAVA_50, facetedProject.getInstalledVersion(JavaFacetUtils.JAVA_FACET));
+ assertEquals(IJ2EEFacetConstants.EJB_30, facetedProject.getInstalledVersion(EJB_FACET));
+
+ //ejb-jar file should have been created in the custom resources directory
+ IFile ejbJar = project.getFile("ejbModule/META-INF/ejb-jar.xml");
+ assertNotNull(ejbJar);
+ //TODO check DTD
+ }
+
+ public void testMNGECLIPSE688_Jee1() throws Exception {
+ IProject[] projects = importProjects("projects/MNGECLIPSE-688/jee1/", new String[] {"pom.xml", "core/pom.xml", "ejb/pom.xml", "war/pom.xml", "ear/pom.xml"}, new ResolverConfiguration());
+
+ waitForJobsToComplete();
+
+ assertEquals(5, projects.length);
+ IProject core = projects[1];
+ IProject ejb = projects[2];
+ IProject war = projects[3];
+ IProject ear = projects[4];
+
+
+ IFacetedProject fpEjb = ProjectFacetsManager.create(ejb);
+ assertNotNull(fpEjb);
+ assertTrue(fpEjb.hasProjectFacet(JavaFacetUtils.JAVA_FACET));
+ assertEquals(IJ2EEFacetConstants.EJB_21, fpEjb.getInstalledVersion(EJB_FACET));
+
+ IFacetedProject fpWar = ProjectFacetsManager.create(war);
+ assertNotNull(fpWar);
+ assertTrue(fpWar.hasProjectFacet(JavaFacetUtils.JAVA_FACET));
+ assertEquals(WebFacetUtils.WEB_24, fpWar.getInstalledVersion(WebFacetUtils.WEB_FACET));
+
+ IFacetedProject fpEar = ProjectFacetsManager.create(ear);
+ assertNotNull(fpEar);
+ assertFalse(fpEar.hasProjectFacet(JavaFacetUtils.JAVA_FACET)); //Ears don't have java facet
+ assertEquals(DEFAULT_EAR_FACET, fpEar.getInstalledVersion(EAR_FACET));
+
+ IFacetedProject fpCore = ProjectFacetsManager.create(core);
+ assertNotNull(fpCore);
+ assertTrue(fpCore.hasProjectFacet(JavaFacetUtils.JAVA_FACET));
+ assertEquals(UTILITY_10, fpCore.getInstalledVersion(UTILITY_FACET));
}
+
+
+
+}
Index: org.maven.ide.eclipse.wtp/META-INF/MANIFEST.MF
===================================================================
--- org.maven.ide.eclipse.wtp/META-INF/MANIFEST.MF (revision 1148)
+++ org.maven.ide.eclipse.wtp/META-INF/MANIFEST.MF (working copy)
@@ -18,5 +18,7 @@
org.eclipse.wst.common.modulecore,
org.eclipse.jst.j2ee,
org.eclipse.jst.j2ee.core,
- org.maven.ide.eclipse.jdt
+ org.maven.ide.eclipse.jdt,
+ org.eclipse.jst.j2ee.ejb,
+ org.eclipse.core.commands
Bundle-Vendor: Sonatype, Inc.
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/AbstractProjectConfiguratorDelegate.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/AbstractProjectConfiguratorDelegate.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/AbstractProjectConfiguratorDelegate.java (revision 0)
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.wtp;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.common.project.facet.JavaFacetUtils;
+import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
+import org.maven.ide.eclipse.MavenPlugin;
+import org.maven.ide.eclipse.jdt.BuildPathManager;
+import org.maven.ide.eclipse.project.IMavenProjectFacade;
+import org.maven.ide.eclipse.project.MavenProjectManager;
+import org.maven.ide.eclipse.project.MavenProjectUtils;
+
+
+/**
+ * AbstractProjectConfiguratorDelegate
+ *
+ * @author Igor Fedorenko
+ * @author Fred Bricon
+ */
+@SuppressWarnings("restriction")
+abstract class AbstractProjectConfiguratorDelegate implements IProjectConfiguratorDelegate {
+
+
+ protected final MavenProjectManager projectManager;
+
+ AbstractProjectConfiguratorDelegate() {
+ this.projectManager = MavenPlugin.getDefault().getMavenProjectManager();
+ }
+
+ protected List getWorkspaceDependencies(IProject project, MavenProject mavenProject) {
+ Set projects = new HashSet();
+ List dependencies = new ArrayList();
+ @SuppressWarnings("unchecked")
+ Set artifacts = mavenProject.getArtifacts();
+ for(Artifact artifact : artifacts) {
+ IMavenProjectFacade dependency = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(),
+ artifact.getVersion());
+ if(Artifact.SCOPE_COMPILE.equals(artifact.getScope()) && dependency != null
+ && !dependency.getProject().equals(project) && dependency.getFullPath(artifact.getFile()) != null
+ && projects.add(dependency.getProject())) {
+ dependencies.add(dependency);
+ }
+ }
+ return dependencies;
+ }
+
+ protected void configureWtpUtil(IProject project, IProgressMonitor monitor) throws CoreException {
+ //Adding utility facet on JEE projects is not allowed
+ if (J2EEProjectUtilities.isJEEProject(project)){
+ return;
+ }
+
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
+ Set actions = new LinkedHashSet();
+ installJavaFacet(actions, project, facetedProject);
+
+ if(!facetedProject.hasProjectFacet(WTPFacetsUtil.UTILITY_FACET)) {
+ actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, WTPFacetsUtil.UTILITY_10, null));
+ } else if(!facetedProject.hasProjectFacet(WTPFacetsUtil.UTILITY_10)) {
+ actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, WTPFacetsUtil.UTILITY_10, null));
+ }
+
+ facetedProject.modify(actions, monitor);
+ }
+
+ protected void installJavaFacet(Set actions, IProject project, IFacetedProject facetedProject) {
+ IProjectFacetVersion javaFv = JavaFacetUtils.compilerLevelToFacet(JavaFacetUtils.getCompilerLevel(project));
+ if(!facetedProject.hasProjectFacet(JavaFacetUtils.JAVA_FACET)) {
+ actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, javaFv, null));
+ } else if(!facetedProject.hasProjectFacet(javaFv)) {
+ actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, javaFv, null));
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Set getTestRoots(IProject project, MavenProject mavenProject) {
+ Set testRoots = new HashSet();
+ testRoots.addAll(Arrays.asList(MavenProjectUtils.getSourceLocations(project, mavenProject.getTestCompileSourceRoots())));
+ testRoots.addAll(Arrays.asList(MavenProjectUtils.getResourceLocations(project, mavenProject.getTestResources())));
+ return testRoots;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void removeTestFolderLinks(IProject project, MavenProject mavenProject, IProgressMonitor monitor,
+ String folder) throws CoreException {
+ IVirtualComponent component = ComponentCore.createComponent(project);
+ IVirtualFolder jsrc = component.getRootFolder().getFolder(folder);
+ for(IPath location : getTestRoots(project, mavenProject)) {
+ jsrc.removeLink(location, 0, monitor);
+ }
+ }
+
+ // XXX consider adding getContainerAttributes to ClasspathConfigurator
+ protected void addContainerAttribute(IProject project, IClasspathAttribute attribute, IProgressMonitor monitor)
+ throws JavaModelException {
+ IJavaProject javaProject = JavaCore.create(project);
+ IClasspathEntry[] cp = javaProject.getRawClasspath();
+ for(int i = 0; i < cp.length; i++ ) {
+ if(IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind()
+ && BuildPathManager.isMaven2ClasspathContainer(cp[i].getPath())) {
+ LinkedHashMap attrs = new LinkedHashMap();
+ for(IClasspathAttribute attr : cp[i].getExtraAttributes()) {
+ attrs.put(attr.getName(), attr);
+ }
+ attrs.put(attribute.getName(), attribute);
+ IClasspathAttribute[] newAttrs = attrs.values().toArray(new IClasspathAttribute[attrs.size()]);
+ cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newAttrs, cp[i].isExported());
+ break;
+ }
+ }
+ javaProject.setRawClasspath(cp, monitor);
+ }
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/ArtifactHelper.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/ArtifactHelper.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/ArtifactHelper.java (revision 0)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.wtp;
+
+import org.apache.maven.artifact.Artifact;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ *
+ * Helper for Maven artifacts
+ *
+ * @author Fred Bricon
+ */
+//XXX Should probably be refactored to another Maven helper class.
+public class ArtifactHelper {
+
+ /**
+ * Returns an artifact's path relative to the local repository
+ */
+ //XXX Does maven API provide that kind of feature?
+ public static IPath getLocalRepoRelativePath(Artifact artifact) {
+ if (artifact == null) {
+ throw new IllegalArgumentException("artifact must not be null");
+ }
+
+ // M2_REPO is different from local repo set during tests
+ // IPath m2repo = JavaCore.getClasspathVariable(IMavenConstants.M2_REPO); //always set
+ // IPath absolutePath = new Path(artifact.getFile().getAbsolutePath());
+ // IPath relativePath = absolutePath.removeFirstSegments(m2repo.segmentCount()).makeRelative().setDevice(null);
+ // return relativePath;
+
+ String prefix = artifact.getGroupId().replace('.', IPath.SEPARATOR) + IPath.SEPARATOR + artifact.getArtifactId() + IPath.SEPARATOR + artifact.getVersion();
+ String fullPath = artifact.getFile().getAbsolutePath().replace('\\', IPath.SEPARATOR); //relocated artifact expose their new jar location
+ return new Path(fullPath.substring(fullPath.lastIndexOf(prefix))); //Should work for stupid repo locations like c:\junit\junit\3.8.1\localrepo\junit\junit\3.8.1\junit-3.8.1.jar
+ }
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/AbstractEarModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/AbstractEarModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/AbstractEarModule.java (revision 0)
@@ -0,0 +1,262 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * A base implementation of an {@link EarModule}.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: AbstractEarModule.java 543037 2007-05-31 03:40:51Z snicoll $
+ */
+public abstract class AbstractEarModule
+ implements EarModule
+{
+
+ protected static final String MODULE_ELEMENT = "module";
+
+ protected static final String JAVA_MODULE = "java";
+
+ protected static final String ALT_DD = "alt-dd";
+
+ private String uri;
+
+ private Artifact artifact;
+
+ // Those are set by the configuration
+
+ private String groupId;
+
+ private String artifactId;
+
+ private String classifier;
+
+ protected String bundleDir;
+
+ protected String bundleFileName;
+
+ protected Boolean excluded = Boolean.FALSE;
+
+ protected Boolean unpack = null;
+
+ protected String altDeploymentDescriptor;
+
+ /**
+ * Empty constructor to be used when the module
+ * is built based on the configuration.
+ */
+ public AbstractEarModule()
+ {
+ }
+
+ /**
+ * Creates an ear module from the artifact.
+ *
+ * @param a the artifact
+ */
+ public AbstractEarModule( Artifact a, String bundleFileName )
+ {
+ this.artifact = a;
+ this.groupId = a.getGroupId();
+ this.artifactId = a.getArtifactId();
+ this.classifier = a.getClassifier();
+ this.bundleDir = null;
+ this.bundleFileName = bundleFileName;
+ }
+
+
+ public Artifact getArtifact()
+ {
+ return artifact;
+ }
+
+ public String getUri()
+ {
+ if ( uri == null )
+ {
+ if ( getBundleDir() == null )
+ {
+ uri = getBundleFileName();
+ }
+ else
+ {
+ uri = getBundleDir() + getBundleFileName();
+ }
+ }
+ return uri;
+ }
+
+ /**
+ * Returns the artifact's groupId.
+ *
+ * @return the group Id
+ */
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ /**
+ * Returns the artifact's Id.
+ *
+ * @return the artifact Id
+ */
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ /**
+ * Returns the artifact's classifier.
+ *
+ * @return the artifact classifier
+ */
+ public String getClassifier()
+ {
+ return classifier;
+ }
+
+ /**
+ * Returns the bundle directory. If null, the module
+ * is bundled in the root of the EAR.
+ *
+ * @return the custom bundle directory
+ */
+ public String getBundleDir()
+ {
+ if ( bundleDir != null )
+ {
+ bundleDir = cleanBundleDir( bundleDir );
+ }
+ return bundleDir;
+ }
+
+ /**
+ * Returns the bundle file name. If null, the artifact's
+ * file name is returned.
+ *
+ * @return the bundle file name
+ */
+ public String getBundleFileName()
+ {
+ return bundleFileName;
+ }
+
+
+ /**
+ * The alt-dd element specifies an optional URI to the post-assembly version
+ * of the deployment descriptor file for a particular Java EE module. The URI
+ * must specify the full pathname of the deployment descriptor file relative
+ * to the application's root directory.
+ *
+ * @return the alternative deployment descriptor for this module
+ *
+ * @since JavaEE 5
+ */
+ public String getAltDeploymentDescriptor()
+ {
+ return altDeploymentDescriptor;
+ }
+
+ /**
+ * Specify whether this module should be excluded or not.
+ *
+ * @return true if this module should be skipped, false otherwise
+ */
+ public boolean isExcluded()
+ {
+ return excluded.booleanValue();
+ }
+
+ public Boolean shouldUnpack()
+ {
+ return unpack;
+ }
+
+
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append( getType() ).append( ":" ).append( groupId ).append( ":" ).append( artifactId );
+ if ( classifier != null )
+ {
+ sb.append( ":" ).append( classifier );
+ }
+ if ( artifact != null )
+ {
+ sb.append( ":" ).append( artifact.getVersion() );
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Cleans the bundle directory so that it might be used
+ * properly.
+ *
+ * @param bundleDir the bundle directory to clean
+ * @return the cleaned bundle directory
+ */
+ static String cleanBundleDir( String bundleDir )
+ {
+ if ( bundleDir == null )
+ {
+ return bundleDir;
+ }
+
+ // Using slashes
+ bundleDir = bundleDir.replace( '\\', '/' );
+
+ // Remove '/' prefix if any so that directory is a relative path
+ if ( bundleDir.startsWith( "/" ) )
+ {
+ bundleDir = bundleDir.substring( 1, bundleDir.length() );
+ }
+
+ if ( bundleDir.length() > 0 && !bundleDir.endsWith( "/" ) )
+ {
+ // Adding '/' suffix to specify a directory structure if it is not empty
+ bundleDir = bundleDir + "/";
+ }
+
+ return bundleDir;
+ }
+
+ /**
+ * Specify if the objects are both null or both equal.
+ *
+ * @param first the first object
+ * @param second the second object
+ * @return true if parameters are either both null or equal
+ */
+ static boolean areNullOrEqual( Object first, Object second )
+ {
+ if ( first != null )
+ {
+ return first.equals( second );
+ }
+ else
+ {
+ return second == null;
+ }
+ }
+
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/AbstractEarMojo.txt
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/AbstractEarMojo.txt (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/AbstractEarMojo.txt (revision 0)
@@ -0,0 +1,286 @@
+package org.apache.maven.plugin.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.ear.util.ArtifactTypeMappingService;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.PlexusConfigurationException;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A base class for EAR-processing related tasks.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: AbstractEarMojo.java 555758 2007-07-12 20:59:45Z snicoll $
+ */
+public abstract class AbstractEarMojo
+ extends AbstractMojo
+{
+
+ /**
+ * Directory where the deployment descriptor file(s) will be auto-generated.
+ *
+ * @parameter expression="${project.build.directory}"
+ */
+ protected String generatedDescriptorLocation;
+
+ /**
+ * The maven project.
+ */
+ protected MavenProject project;
+
+ /**
+ * The ear modules configuration.
+ */
+ private EarModule[] modules;
+
+ /**
+ * The artifact type mappings.
+ *
+ * @parameter
+ */
+ protected PlexusConfiguration artifactTypeMappings;
+
+ /**
+ * The default bundle dir for libraries.
+ *
+ * @parameter alias="defaultJavaBundleDir"
+ */
+ private String defaultLibBundleDir;
+
+ /**
+ * The file name mapping to use for all dependencies included
+ * in the EAR file.
+ *
+ * @parameter
+ */
+ private String fileNameMapping;
+
+ /**
+ * Directory that resources are copied to during the build.
+ *
+ * @parameter expression="${project.build.directory}/${project.build.finalName}"
+ * @required
+ */
+ private File workDirectory;
+
+ /**
+ * The JBoss specific configuration.
+ *
+ * @parameter
+ */
+ private PlexusConfiguration jboss;
+
+ /**
+ * The id to use to define the main artifact (e.g. the artifact without
+ * a classifier) when there is multiple candidates.
+ *
+ * @parameter
+ */
+ private String mainArtifactId = "none";
+
+ private List earModules;
+
+ private List allModules;
+
+ private JbossConfiguration jbossConfiguration;
+
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ getLog().debug( "Resolving artifact type mappings ..." );
+ try
+ {
+ ArtifactTypeMappingService.getInstance().configure( artifactTypeMappings );
+ }
+ catch ( EarPluginException e )
+ {
+ throw new MojoExecutionException( "Failed to initialize artifact type mappings", e );
+ }
+ catch ( PlexusConfigurationException e )
+ {
+ throw new MojoExecutionException( "Invalid artifact type mappings configuration", e );
+ }
+
+ getLog().debug( "Initializing JBoss configuration if necessary ..." );
+ try
+ {
+ initializeJbossConfiguration();
+ }
+ catch ( EarPluginException e )
+ {
+ throw new MojoExecutionException( "Failed to initialize JBoss configuration", e );
+ }
+
+ getLog().debug( "Initializing ear execution context" );
+ EarExecutionContext.getInstance().initialize( project, mainArtifactId, defaultLibBundleDir, jbossConfiguration,
+ fileNameMapping );
+
+ getLog().debug( "Resolving ear modules ..." );
+ allModules = new ArrayList();
+ try
+ {
+ if ( modules != null && modules.length > 0 )
+ {
+ // Let's validate user-defined modules
+ EarModule module = null;
+
+ for ( int i = 0; i < modules.length; i++ )
+ {
+ module = modules[i];
+ getLog().debug( "Resolving ear module[" + module + "]" );
+ module.resolveArtifact( project.getArtifacts() );
+ allModules.add( module );
+ }
+ }
+
+ // Let's add other modules
+ Set artifacts = project.getArtifacts();
+ for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
+ {
+ Artifact artifact = (Artifact) iter.next();
+
+ // If the artifact's type is POM, ignore and continue
+ // since it's used for transitive deps only.
+ if ( "pom".equals( artifact.getType() ) )
+ {
+ continue;
+ }
+
+ // Artifact is not yet registered and it has neither test, nor a
+ // provided scope, not is it optional
+ ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
+ if ( !isArtifactRegistered( artifact, allModules ) && !artifact.isOptional() &&
+ filter.include( artifact ) )
+ {
+ EarModule module = EarModuleFactory.newEarModule( artifact, defaultLibBundleDir );
+ allModules.add( module );
+ }
+ }
+ }
+ catch ( EarPluginException e )
+ {
+ throw new MojoExecutionException( "Failed to initialize ear modules", e );
+ }
+
+ // Now we have everything let's built modules which have not been excluded
+ earModules = new ArrayList();
+ for ( Iterator iter = allModules.iterator(); iter.hasNext(); )
+ {
+ EarModule earModule = (EarModule) iter.next();
+ if ( earModule.isExcluded() )
+ {
+ getLog().debug( "Skipping ear module[" + earModule + "]" );
+ }
+ else
+ {
+ earModules.add( earModule );
+ }
+ }
+
+ }
+
+ protected List getModules()
+ {
+ if ( earModules == null )
+ {
+ throw new IllegalStateException( "Ear modules have not been initialized" );
+ }
+ return earModules;
+ }
+
+ protected MavenProject getProject()
+ {
+ return project;
+ }
+
+ protected File getWorkDirectory()
+ {
+ return workDirectory;
+ }
+
+ protected JbossConfiguration getJbossConfiguration()
+ {
+ return jbossConfiguration;
+ }
+
+ private static boolean isArtifactRegistered( Artifact a, List currentList )
+ {
+ Iterator i = currentList.iterator();
+ while ( i.hasNext() )
+ {
+ EarModule em = (EarModule) i.next();
+ if ( em.getArtifact().equals( a ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Initializes the JBoss configuration.
+ *
+ * @throws EarPluginException if the configuration is invalid
+ */
+ private void initializeJbossConfiguration()
+ throws EarPluginException
+ {
+ if ( jboss == null )
+ {
+ jbossConfiguration = null;
+ }
+ else
+ {
+ try
+ {
+ String version = jboss.getChild( JbossConfiguration.VERSION ).getValue();
+ if ( version == null )
+ {
+ getLog().info( "JBoss version not set, using JBoss 4 by default" );
+ version = JbossConfiguration.VERSION_4;
+ }
+ final String securityDomain = jboss.getChild( JbossConfiguration.SECURITY_DOMAIN ).getValue();
+ final String unauthenticatedPrincipal =
+ jboss.getChild( JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL ).getValue();
+ final String loaderRepository = jboss.getChild( JbossConfiguration.LOADER_REPOSITORY ).getValue();
+ final String jmxName = jboss.getChild( JbossConfiguration.JMX_NAME ).getValue();
+ final String moduleOrder = jboss.getChild( JbossConfiguration.MODULE_ORDER ).getValue();
+ jbossConfiguration = new JbossConfiguration( version, securityDomain, unauthenticatedPrincipal, jmxName,
+ loaderRepository, moduleOrder );
+ }
+ catch ( PlexusConfigurationException e )
+ {
+ throw new EarPluginException( "Invalid JBoss configuration", e );
+ }
+ }
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/ArtifactRepository.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/ArtifactRepository.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/ArtifactRepository.java (revision 0)
@@ -0,0 +1,174 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * An artifact repository used to resolve {@link org.maven.ide.eclipse.wtp.earmodules.EarModule}.
+ * This is a Java 5 port of org.apache.maven.plugin.ear.ArtifactRepository from maven-ear-plugin
+ *
+ * @author Stephane Nicoll
+ * @version $Id: ArtifactRepository.java 522047 2007-03-24 16:09:22Z snicoll $
+ */
+public class ArtifactRepository
+{
+ private final Set artifacts;
+
+ private final String mainArtifactId;
+
+ private final ArtifactTypeMappingService artifactTypeMappingService;
+
+ /**
+ * Creates a new repository wih the specified artifacts.
+ *
+ * @param artifacts the artifacts
+ * @param mainArtifactId the id to use for the main artifact (no classifier)
+ */
+ public ArtifactRepository( Set artifacts, String mainArtifactId, ArtifactTypeMappingService artifactTypeMappingService )
+ {
+ this.artifacts = artifacts;
+ this.mainArtifactId = mainArtifactId;
+ this.artifactTypeMappingService = artifactTypeMappingService;
+ }
+
+ /**
+ * Returns the artifact with the specified parameters.
+ *
+ * If the artifact is classified and is the only one with the specified
+ * groupI, artifactId and type, it will be returned.
+ *
+ * If the artifact is classified and is not the only one with the specified
+ * groupI, artifactId and type, it returns null.
+ *
+ * If the artifact is not found, it returns null.
+ *
+ * @param groupId the group id
+ * @param artifactId the artifact id
+ * @param type the type
+ * @param classifier the classifier
+ * @return the artifact or null if no artifact were found
+ */
+ public Artifact getUniqueArtifact( String groupId, String artifactId, String type, String classifier )
+ {
+ final Set candidates = getArtifacts( groupId, artifactId, type );
+ if ( candidates.isEmpty() )
+ {
+ return null;
+ }
+ else if ( candidates.size() == 1 && classifier == null )
+ {
+ return candidates.iterator().next();
+ }
+ else if ( classifier != null )
+ {
+ for ( Artifact a : artifacts)
+ {
+ if ( a.getClassifier() == null && classifier.equals( mainArtifactId ) )
+ {
+ return a;
+ }
+ else if ( classifier.equals( a.getClassifier() ) )
+ {
+ return a;
+ }
+ }
+ }
+ // All other cases, classifier is null and more than one candidate ; artifact not found
+ return null;
+ }
+
+ /**
+ * Returns the artifact with the specified parameters.
+ *
+ * If the artifact is classified and is the only one with the specified
+ * groupI, artifactId and type, it will be returned.
+ *
+ * If the artifact is classified and is not the only one with the specified
+ * groupI, artifactId and type, it returns null.
+ *
+ * If the artifact is not found, it returns null.
+ *
+ * @param groupId the group id
+ * @param artifactId the artifact id
+ * @param type the type
+ * @return the artifact or null if no artifact were found
+ */
+ public Artifact getUniqueArtifact( String groupId, String artifactId, String type )
+ {
+ return getUniqueArtifact( groupId, artifactId, type, null );
+ }
+
+ /**
+ * Returns the artifacts with the specified parameters.
+ *
+ * @param groupId the group id
+ * @param artifactId the artifact id
+ * @param type the type
+ * @return the artifacts or an empty set if no artifact were found
+ */
+ public Set getArtifacts( String groupId, String artifactId, String type )
+ {
+ final Set result = new TreeSet();
+ for (Artifact a : artifacts)
+ {
+ // If the groupId, the artifactId and if the
+ // artifact's type is known, then we have found a candidate.
+ if ( a.getGroupId().equals( groupId ) && a.getArtifactId().equals( artifactId ) &&
+ artifactTypeMappingService.isMappedToType( type, a.getType() ) )
+ {
+ result.add( a );
+ }
+ }
+ return result;
+ }
+
+ public Artifact resolveArtifact( String groupId, String artifactId, String type, String classifier)
+ throws EarPluginException
+{
+ // If the artifact is already set no need to resolve it
+ // Make sure that at least the groupId and the artifactId are specified
+ if ( groupId == null || artifactId == null )
+ {
+ throw new IllegalArgumentException(
+ "Could not resolve artifact[" + groupId + ":" + artifactId + ":" + type + "]" );
+ }
+ Artifact artifact = getUniqueArtifact( groupId, artifactId, type, classifier );
+ // Artifact has not been found
+ if ( artifact == null )
+ {
+ Set candidates = getArtifacts( groupId, artifactId, type );
+ if ( candidates.size() > 1 )
+ {
+ throw new EarPluginException( "Artifact[" + this + "] has " + candidates.size() +
+ " candidates, please provide a classifier." );
+ }
+ else
+ {
+ throw new EarPluginException( "Artifact[" + this + "] " + "is not a dependency of the project." );
+ }
+ }
+ return artifact;
+ }
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/ArtifactTypeMappingService.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/ArtifactTypeMappingService.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/ArtifactTypeMappingService.java (revision 0)
@@ -0,0 +1,168 @@
+
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+
+/**
+ * Allows to map custom artifact type to standard type.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: EarModule.java 332974 2005-11-13 12:42:44Z snicoll $
+ */
+public class ArtifactTypeMappingService {
+ static final String ARTIFACT_TYPE_MAPPING_ELEMENT = "artifactTypeMapping";
+
+ static final String TYPE_ATTRIBUTE = "type";
+
+ static final String MAPPING_ATTRIBUTE = "mapping";
+
+ public final static List standardArtifactTypes = new ArrayList(10);
+
+ static {
+ standardArtifactTypes.add("jar");
+ standardArtifactTypes.add("ejb");
+ standardArtifactTypes.add("ejb3");
+ standardArtifactTypes.add("par");
+ standardArtifactTypes.add("ejb-client");
+ standardArtifactTypes.add("rar");
+ standardArtifactTypes.add("war");
+ standardArtifactTypes.add("sar");
+ standardArtifactTypes.add("wsr");
+ standardArtifactTypes.add("har");
+ }
+
+ // A standard type to a list of customType
+ private Map> typeMappings;
+
+ // The user-defined mapping for direct access
+ private Map customMappings;
+
+ public ArtifactTypeMappingService(Xpp3Dom plexusConfiguration) throws EarPluginException {
+ // Initializes the typeMappings with default values
+ init();
+
+ // No user defined configuration
+ if(plexusConfiguration == null) {
+ return;
+ }
+
+ // Inject users configuration
+ final Xpp3Dom[] artifactTypeMappings = plexusConfiguration.getChildren(ARTIFACT_TYPE_MAPPING_ELEMENT);
+
+ for(Xpp3Dom artifactTypeMapping : artifactTypeMappings) {
+ final String customType = artifactTypeMapping.getAttribute(TYPE_ATTRIBUTE);
+ final String mapping = artifactTypeMapping.getAttribute(MAPPING_ATTRIBUTE);
+
+ if(customType == null) {
+ throw new EarPluginException("Invalid artifact type mapping, type attribute should be set.");
+ } else if(mapping == null) {
+ throw new EarPluginException("Invalid artifact type mapping, mapping attribute should be set.");
+ } else if(!isStandardArtifactType(mapping)) {
+ throw new EarPluginException("Invalid artifact type mapping, mapping[" + mapping
+ + "] must be a standard Ear artifact type[" + getStandardArtifactTypes() + "]");
+ } else if(customMappings.containsKey(customType)) {
+ throw new EarPluginException("Invalid artifact type mapping, type[" + customType + "] is already registered.");
+ } else {
+ // Add the custom mapping
+ customMappings.put(customType, mapping);
+
+ // Register the custom mapping to its standard type
+ List typeMapping = typeMappings.get(mapping);
+ typeMapping.add(customType);
+ }
+ }
+ }
+
+ /**
+ * Specify whether the customType could be mapped to the standardType.
+ *
+ * @param standardType the standard type (ejb, jar, war, ...)
+ * @param customType a user-defined type
+ * @return true if the customType could be mapped to the standard type
+ */
+ public boolean isMappedToType(final String standardType, final String customType) {
+ if(!isStandardArtifactType(standardType)) {
+ throw new IllegalStateException("Artifact type[" + standardType + "] is not a standard Ear artifact type["
+ + getStandardArtifactTypes() + "]");
+ }
+ final List typeMappings = this.typeMappings.get(standardType);
+ return typeMappings.contains(customType);
+
+ }
+
+ /**
+ * Returns the standard type for the specified type. If the specified type is already a standard type, the
+ * orignal type is returned.
+ *
+ * @param type a type
+ * @return the standard type (ejb, jar, war, ...) for this type
+ */
+ public String getStandardType(final String type) throws UnknownArtifactTypeException {
+ if(type == null) {
+ throw new IllegalStateException("custom type could not be null.");
+ } else if(getStandardArtifactTypes().contains(type)) {
+ return type;
+ } else if(!customMappings.containsKey(type)) {
+ throw new UnknownArtifactTypeException("Unknown artifact type[" + type + "]");
+ } else {
+ return customMappings.get(type);
+ }
+ }
+
+ private void init() {
+ this.typeMappings = new HashMap> ();
+ this.customMappings = new HashMap ();
+
+ // Initialize the mapping with the standard artifact types
+ for (String type : getStandardArtifactTypes()) {
+ List typeMapping = new ArrayList();
+ typeMapping.add(type);
+ this.typeMappings.put(type, typeMapping);
+ }
+ }
+
+ /**
+ * Returns a list of standard artifact types.
+ *
+ * @return the standard artifact types
+ */
+ public static List getStandardArtifactTypes() {
+ return standardArtifactTypes;
+ }
+
+ /**
+ * Specify whether the specified type is standard artifact type.
+ *
+ * @param type the type to check
+ * @return true if the specified type is a standard artifact type
+ */
+ public static boolean isStandardArtifactType(final String type) {
+ return standardArtifactTypes.contains(type);
+ }
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EarModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EarModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EarModule.java (revision 0)
@@ -0,0 +1,91 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The ear module interface.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: EarModule.java 543037 2007-05-31 03:40:51Z snicoll $
+ */
+public interface EarModule
+{
+
+ /**
+ * Returns the {@link Artifact} representing this module.
+ *
+ * Note that this might return null till the
+ * module has been resolved.
+ *
+ * @return the artifact
+ * @see #resolveArtifact(java.util.Set)
+ */
+ public Artifact getArtifact();
+
+ /**
+ * Returns the URI for this module.
+ *
+ * @return the URI
+ */
+ public String getUri();
+
+ /**
+ * Returns the type associated to the module.
+ *
+ * @return the artifact's type of the module
+ */
+ public String getType();
+
+ /**
+ * Specify whether this module should be excluded or not.
+ *
+ * @return true if this module should be skipped, false otherwise
+ */
+ public boolean isExcluded();
+
+ /**
+ * Specify whether this module should be unpacked in the
+ * EAR archive or not.
+ *
+ * Returns null if no configuration was specified so that
+ * defaulting may apply.
+ *
+ * @return true if this module should be bundled unpacked, false otherwise
+ */
+ public Boolean shouldUnpack();
+
+ /**
+ * The alt-dd element specifies an optional URI to the post-assembly version
+ * of the deployment descriptor file for a particular Java EE module. The URI
+ * must specify the full pathname of the deployment descriptor file relative
+ * to the application's root directory.
+ *
+ * @return the alternative deployment descriptor for this module
+ *
+ * @since JavaEE 5
+ */
+ public String getAltDeploymentDescriptor();
+
+ public String getBundleDir();
+
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EarModuleFactory.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EarModuleFactory.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EarModuleFactory.java (revision 0)
@@ -0,0 +1,183 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.maven.ide.eclipse.wtp.earmodules.output.FileNameMapping;
+import org.maven.ide.eclipse.wtp.earmodules.output.FileNameMappingFactory;
+
+/**
+ * Builds an {@link EarModule} based on an Artifact.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: EarModuleFactory.java 492260 2007-01-03 19:24:55Z snicoll $
+ */
+public final class EarModuleFactory
+{
+ private ArtifactTypeMappingService artifactTypeMappingService;
+ private FileNameMapping fileNameMapping;
+ private ArtifactRepository artifactRepository;
+
+ private EarModuleFactory(ArtifactTypeMappingService artifactTypeMappingService, FileNameMapping fileNameMapping, ArtifactRepository artifactRepository) {
+ this.artifactTypeMappingService = artifactTypeMappingService;
+ this.artifactRepository = artifactRepository;
+ this.fileNameMapping = fileNameMapping;
+ }
+
+ public static EarModuleFactory createEarModuleFactory(ArtifactTypeMappingService artifactTypeMappingService, FileNameMapping fileNameMapping, String mainArtifactId, Set artifacts) throws EarPluginException {
+ if (artifactTypeMappingService == null) {
+ artifactTypeMappingService = new ArtifactTypeMappingService(null);
+ }
+ if (fileNameMapping == null) {
+ fileNameMapping = FileNameMappingFactory.INSTANCE.getDefaultFileNameMapping();
+ }
+ ArtifactRepository artifactRepository = new ArtifactRepository(artifacts, mainArtifactId, artifactTypeMappingService);
+
+ return new EarModuleFactory(artifactTypeMappingService, fileNameMapping, artifactRepository );
+ }
+
+ /**
+ * Creates a new {@link EarModule} based on the
+ * specified {@link Artifact} and the specified
+ * execution configuration.
+ *
+ * @param artifact the artifact
+ * @param defaultLibBundleDir the default bundle dir for {@link JarModule}
+ * @return an ear module for this artifact
+ */
+ public EarModule newEarModule( Artifact artifact, String defaultLibBundleDir)
+ throws UnknownArtifactTypeException
+ {
+ // Get the standard artifact type based on default config and user-defined mapping(s)
+ final String artifactType = artifactTypeMappingService.getStandardType( artifact.getType());
+ String bundleFileName = fileNameMapping.mapFileName( artifact );//FIXME doesn't work for projects!
+
+ if ( "jar".equals( artifactType ) )
+ {
+ return new JarModule( artifact, bundleFileName, defaultLibBundleDir );
+ }
+ else if ( "ejb".equals( artifactType ) )
+ {
+ return new EjbModule( artifact, bundleFileName);
+ }
+ else if ( "ejb3".equals( artifactType ) )
+ {
+ return new Ejb3Module( artifact, bundleFileName );
+ }
+ else if ( "par".equals( artifactType ) )
+ {
+ return new ParModule( artifact, bundleFileName );
+ }
+ else if ( "ejb-client".equals( artifactType ) )
+ {
+ return new EjbClientModule( artifact, null, bundleFileName );
+ }
+ else if ( "rar".equals( artifactType ) )
+ {
+ return new RarModule( artifact, bundleFileName );
+ }
+ else if ( "war".equals( artifactType ) )
+ {
+ return new WebModule( artifact, bundleFileName );
+ }
+ else if ( "sar".equals( artifactType ) )
+ {
+ return new SarModule( artifact, bundleFileName );
+ }
+ else if ( "wsr".equals( artifactType ) )
+ {
+ return new WsrModule( artifact, bundleFileName );
+ }
+ else if ( "har".equals( artifactType ) )
+ {
+ return new HarModule( artifact, bundleFileName );
+ }
+ else
+ {
+ throw new IllegalStateException( "Could not handle artifact type[" + artifactType + "]" );
+ }
+ }
+
+ //XXX needs to be implemented
+ public EarModule newEarModule(Xpp3Dom domModule, String defaultLib) throws EarPluginException {
+ String groupId= domModule.getChild("groupId").getValue();
+ String artifactId= domModule.getChild("artifactId").getValue();
+ String type= domModule.getChild("type").getValue();
+ String classifier= domModule.getChild("classifier").getValue();
+
+ Artifact artifact = artifactRepository.resolveArtifact(groupId, artifactId, type, classifier);
+
+ // Get the standard artifact type based on default config and user-defined mapping(s)
+ final String artifactType = domModule.getName();
+
+ //XXX need to create earmodules from xpp3dom
+ /*
+ if ( "jarModule".equals( artifactType ) || "javaModule".equals( artifactType ))
+ {
+ return new JarModule( artifact, defaultLib);
+ }
+ else if ( "ejbModule".equals( artifactType ) )
+ {
+ return new EjbModule( artifact );
+ }
+ else if ( "ejb3Module".equals( artifactType ) )
+ {
+ return new Ejb3Module( artifact );
+ }
+ else if ( "parModule".equals( artifactType ) )
+ {
+ return new ParModule( artifact );
+ }
+ else if ( "ejbClientModule".equals( artifactType ) )
+ {
+ return new EjbClientModule( artifact, null );
+ }
+ else if ( "rarModule".equals( artifactType ) )
+ {
+ return new RarModule( artifact );
+ }
+ else if ( "warModule".equals( artifactType ) )
+ {
+ return new WebModule( artifact );
+ }
+ else if ( "sarModule".equals( artifactType ) )
+ {
+ return new SarModule( artifact );
+ }
+ else if ( "wsrModule".equals( artifactType ) )
+ {
+ return new WsrModule( artifact );
+ }
+ else if ( "harModule".equals( artifactType ) )
+ {
+ return new HarModule( artifact );
+ }
+ else
+ {
+ throw new IllegalStateException( "Could not handle artifact type[" + artifactType + "]" );
+ }
+ */
+
+ return newEarModule(artifact, defaultLib);
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EarPluginException.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EarPluginException.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EarPluginException.java (revision 0)
@@ -0,0 +1,58 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.maven.ide.eclipse.core.IMavenConstants;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * The base exception of the EAR plugin.
+ *
+ * @author Stephane Nicoll
+ * @author Fred Bricon
+ */
+public class EarPluginException
+ extends CoreException
+{
+
+ private static final String DEFAULT_MESSAGE = "Error in ear plugin configuration";
+
+ public EarPluginException()
+ {
+ super(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, DEFAULT_MESSAGE));
+ }
+
+ public EarPluginException( String message )
+ {
+ super(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, message));
+ }
+
+ public EarPluginException( Throwable cause )
+ {
+ super(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, DEFAULT_MESSAGE, cause));
+ }
+
+ public EarPluginException( String message, Throwable cause )
+ {
+ super(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, message, cause));
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/Ejb3Module.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/Ejb3Module.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/Ejb3Module.java (revision 0)
@@ -0,0 +1,44 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for an Ejb3 module.
+ *
+ * @author Stephane Nicoll
+ * @author $Author: $ (last edit)
+ * @version $Revision: $
+ */
+public class Ejb3Module
+ extends EjbModule
+{
+
+ public Ejb3Module( Artifact a, String bundleFileName )
+ {
+ super( a, bundleFileName );
+ }
+
+ public String getType()
+ {
+ return "ejb3";
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EjbClientModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EjbClientModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EjbClientModule.java (revision 0)
@@ -0,0 +1,42 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for an ejb client module.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: EjbClientModule.java 492260 2007-01-03 19:24:55Z snicoll $
+ */
+public class EjbClientModule
+ extends JarModule
+{
+
+ public EjbClientModule(Artifact artifact, String defaultLibBundleDir, String bundleFileName)
+ {
+ super( artifact, defaultLibBundleDir, bundleFileName );
+ }
+
+ public String getType()
+ {
+ return "ejb-client";
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EjbModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EjbModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/EjbModule.java (revision 0)
@@ -0,0 +1,44 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for an EJB module.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: EjbModule.java 543037 2007-05-31 03:40:51Z snicoll $
+ */
+public class EjbModule
+ extends AbstractEarModule
+{
+ protected static final String EJB_MODULE = "ejb";
+
+ public EjbModule( Artifact a, String bundleFileName )
+ {
+ super( a, bundleFileName);
+ }
+
+ public String getType()
+ {
+ return "ejb";
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/HarModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/HarModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/HarModule.java (revision 0)
@@ -0,0 +1,43 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for a JBoss Hibernate archive.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: HarModule.java 485857 2006-12-11 20:34:39Z snicoll $
+ */
+public class HarModule
+ extends AbstractEarModule
+ implements JbossEarModule
+{
+ public HarModule( Artifact a, String bundleFileName )
+ {
+ super( a, bundleFileName );
+ }
+
+ public String getType()
+ {
+ return "har";
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/JarModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/JarModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/JarModule.java (revision 0)
@@ -0,0 +1,67 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for a non J2EE module such as
+ * third party libraries.
+ *
+ * Such module is not incorporated in the generated application.xml
+ * but some application servers support it. To include it in the generated
+ * deployment descriptor anyway, set the includeInApplicationXml
+ * boolean flag.
+ *
+ * This class deprecates {@link org.apache.maven.plugin.ear.JavaModule}.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: JarModule.java 543037 2007-05-31 03:40:51Z snicoll $
+ */
+public class JarModule
+ extends AbstractEarModule
+{
+ private Boolean includeInApplicationXml = Boolean.FALSE;
+
+ public JarModule()
+ {
+ super();
+ }
+
+ public JarModule( Artifact a, String defaultLibBundleDir, String bundleFileName )
+ {
+ super( a, bundleFileName );
+ setLibBundleDir( defaultLibBundleDir );
+
+ }
+
+ public String getType()
+ {
+ return "jar";
+ }
+
+ private void setLibBundleDir( String defaultLibBundleDir )
+ {
+ if ( defaultLibBundleDir != null && bundleDir == null )
+ {
+ this.bundleDir = defaultLibBundleDir;
+ }
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/JbossEarModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/JbossEarModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/JbossEarModule.java (revision 0)
@@ -0,0 +1,32 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+
+/**
+ * Represents a JBoss specific ear module.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: JbossEarModule.java 485857 2006-12-11 20:34:39Z snicoll $
+ */
+public interface JbossEarModule
+{
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/FileNameMapping.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/FileNameMapping.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/FileNameMapping.java (revision 0)
@@ -0,0 +1,42 @@
+package org.maven.ide.eclipse.wtp.earmodules.output;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * Maps file name {@link Artifact}.
+ *
+ * TODO: it might be easier to use a token-based approach instead.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: FileNameMapping.java 485857 2006-12-11 20:34:39Z snicoll $
+ */
+public interface FileNameMapping
+{
+
+ /**
+ * Returns the file name of the specified artifact.
+ *
+ * @param a the artifact
+ * @return the name of the file for the specified artifact
+ */
+ String mapFileName(final Artifact a);
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/FileNameMappingFactory.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/FileNameMappingFactory.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/FileNameMappingFactory.java (revision 0)
@@ -0,0 +1,106 @@
+package org.maven.ide.eclipse.wtp.earmodules.output;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Provides access to {@link FileNameMapping} implementations.
+ *
+ * Two basic implementations are provided by default:
+ *
+ *
standard: the default implementation
+ *
full: an implementation that maps to a 'full' file name, i.e. containing the groupId
+ *
+ *
+ * @author Stephane Nicoll
+ * @version $Id: FileNameMappingFactory.java 485857 2006-12-11 20:34:39Z snicoll $
+ */
+public class FileNameMappingFactory
+{
+ public static final String STANDARD_FILE_NAME_MAPPING = "standard";
+
+ public static final String FULL_FILE_NAME_MAPPING = "full";
+
+ public static final FileNameMappingFactory INSTANCE = new FileNameMappingFactory();
+
+ private final Map mappings;
+
+ private FileNameMappingFactory()
+ {
+ mappings = new HashMap();
+ mappings.put( STANDARD_FILE_NAME_MAPPING, new StandardFileNameMapping() );
+ mappings.put( FULL_FILE_NAME_MAPPING, new FullFileNameMapping() );
+ }
+
+ public FileNameMapping getDefaultFileNameMapping()
+ {
+ return getFileNameMapping( STANDARD_FILE_NAME_MAPPING );
+ }
+
+ /**
+ * Returns the file name mapping implementation based on a logical name
+ * of a fully qualified name of the class.
+ *
+ * @param nameOrClass a name of the fqn of the implementation
+ * @return the file name mapping implementation
+ * @throws IllegalStateException if the implementation is not found
+ */
+ public FileNameMapping getFileNameMapping( final String nameOrClass )
+ throws IllegalStateException
+ {
+ // Check if it's there yet
+ if ( mappings.containsKey( nameOrClass ) )
+ {
+ return mappings.get( nameOrClass );
+ }
+ else
+ {
+ try
+ {
+ final Class c = (Class) Class.forName( nameOrClass );
+ final FileNameMapping fnm = c.newInstance();
+ mappings.put( nameOrClass, fnm );
+ return fnm;
+ }
+ catch ( ClassNotFoundException e )
+ {
+ throw new IllegalStateException(
+ "File name mapping implementation[" + nameOrClass + "] was not found " + e.getMessage() );
+ }
+ catch ( InstantiationException e )
+ {
+ throw new IllegalStateException( "Could not instanciate file name mapping implementation[" +
+ nameOrClass + "] make sure it has a default public constructor" );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new IllegalStateException( "Could not access file name mapping implementation[" + nameOrClass +
+ "] make sure it has a default public constructor" );
+ }
+ catch ( ClassCastException e )
+ {
+ throw new IllegalStateException( "Specified class[" + nameOrClass + "] does not implement[" +
+ FileNameMapping.class.getName() + "]" );
+ }
+ }
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/FullFileNameMapping.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/FullFileNameMapping.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/FullFileNameMapping.java (revision 0)
@@ -0,0 +1,40 @@
+package org.maven.ide.eclipse.wtp.earmodules.output;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * A full file name mapping, useful if artifacts might have the same
+ * name accross groups.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: FullFileNameMapping.java 485857 2006-12-11 20:34:39Z snicoll $
+ */
+public class FullFileNameMapping implements FileNameMapping
+{
+
+ public String mapFileName( final Artifact a )
+ {
+ //FIXME project artifacts have no "file"
+ final String dashedGroupId = a.getGroupId().replace( '.', '-');
+ return dashedGroupId + "-" + a.getFile().getName();
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/StandardFileNameMapping.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/StandardFileNameMapping.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/output/StandardFileNameMapping.java (revision 0)
@@ -0,0 +1,39 @@
+package org.maven.ide.eclipse.wtp.earmodules.output;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The standard fine name mapping. It returns the name
+ * of the file in the local repository.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: StandardFileNameMapping.java 485857 2006-12-11 20:34:39Z snicoll $
+ */
+public class StandardFileNameMapping implements FileNameMapping
+{
+
+ public String mapFileName( final Artifact a )
+ {
+ //FIXME project artifacts have no "file"
+ return a.getFile().getName();
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/ParModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/ParModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/ParModule.java (revision 0)
@@ -0,0 +1,45 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+
+/**
+ * The {@link EarModule} implementation for a Par module.
+ *
+ * @author Stephane Nicoll
+ * @author $Author: $ (last edit)
+ * @version $Revision: $
+ */
+public class ParModule
+ extends EjbModule
+{
+
+ public ParModule( Artifact a, String bundleFileName )
+ {
+ super( a, bundleFileName );
+ }
+
+ public String getType()
+ {
+ return "par";
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/RarModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/RarModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/RarModule.java (revision 0)
@@ -0,0 +1,44 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for an J2EE connector module.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: RarModule.java 543037 2007-05-31 03:40:51Z snicoll $
+ */
+public class RarModule
+ extends AbstractEarModule
+{
+ protected static final String RAR_MODULE = "connector";
+
+ public RarModule( Artifact a, String bundleFileName )
+ {
+ super( a, bundleFileName );
+ }
+
+ public String getType()
+ {
+ return "rar";
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/SarModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/SarModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/SarModule.java (revision 0)
@@ -0,0 +1,46 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for a JBoss sar module.
+ *
+ * @author Stephane Nicoll
+ * @author $Author: snicoll $ (last edit)
+ * @version $Revision: 485857 $
+ */
+public class SarModule
+ extends AbstractEarModule
+ implements JbossEarModule
+{
+ protected static final String SAR_MODULE = "connector";
+
+ public SarModule( Artifact a, String bundleFileName )
+ {
+ super( a, bundleFileName );
+ }
+
+ public String getType()
+ {
+ return "sar";
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/UnknownArtifactTypeException.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/UnknownArtifactTypeException.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/UnknownArtifactTypeException.java (revision 0)
@@ -0,0 +1,41 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * Thrown if an unknown artifact type is encountered.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: EarModule.java 332974 2005-11-13 12:42:44Z snicoll $
+ */
+public class UnknownArtifactTypeException
+ extends EarPluginException
+{
+
+ public UnknownArtifactTypeException()
+ {
+ super();
+ }
+
+ public UnknownArtifactTypeException( String message )
+ {
+ super( message );
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/WebModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/WebModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/WebModule.java (revision 0)
@@ -0,0 +1,88 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for a Web application module.
+ *
+ * @author Stephane Nicoll
+ * @version $Id: WebModule.java 543037 2007-05-31 03:40:51Z snicoll $
+ */
+public class WebModule
+ extends AbstractEarModule
+{
+ protected static final String WEB_MODULE = "web";
+
+ protected static final String WEB_URI_FIELD = "web-uri";
+
+ protected static final String CONTEXT_ROOT_FIELD = "context-root";
+
+ private String contextRoot;
+
+ public WebModule( Artifact a, String bundleFileName )
+ {
+ super( a, bundleFileName );
+ }
+
+ /**
+ * Returns the context root to use for the web module.
+ *
+ * Note that this might return null till the
+ * artifact has been resolved.
+ *
+ * @return the context root
+ */
+ public String getContextRoot()
+ {
+ // Context root has not been customized - using default
+ if ( contextRoot == null )
+ {
+ contextRoot = getDefaultContextRoot( getArtifact() );
+ }
+ return contextRoot;
+ }
+
+ public String getType()
+ {
+ return "war";
+ }
+
+ /**
+ * Generates a default context root for the given artifact, based
+ * on the artifactId.
+ *
+ * @param a the artifact
+ * @return a context root for the artifact
+ */
+ private static String getDefaultContextRoot( Artifact a )
+ {
+ if ( a == null )
+ {
+ throw new NullPointerException( "Artifact could not be null." );
+ }
+ return "/" + a.getArtifactId();
+ }
+
+ public void setContextRoot(String contextRoot) {
+ this.contextRoot = contextRoot;
+ }
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/WsrModule.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/WsrModule.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/earmodules/WsrModule.java (revision 0)
@@ -0,0 +1,43 @@
+package org.maven.ide.eclipse.wtp.earmodules;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for a JBoss wsr module.
+ *
+ * @author Brad O'Hearne
+ * @author $Author: brado $ (last edit)
+ * @version $Revision: $
+ */
+public class WsrModule
+ extends RarModule
+{
+ public WsrModule( Artifact a, String bundleFileName )
+ {
+ super( a, bundleFileName );
+ }
+
+ public String getType()
+ {
+ return "wsr";
+ }
+}
\ No newline at end of file
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EarPluginConfiguration.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EarPluginConfiguration.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EarPluginConfiguration.java (revision 0)
@@ -0,0 +1,252 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.wtp;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.maven.ide.eclipse.core.MavenLogger;
+import org.maven.ide.eclipse.project.MavenProjectUtils;
+import org.maven.ide.eclipse.wtp.earmodules.ArtifactTypeMappingService;
+import org.maven.ide.eclipse.wtp.earmodules.EarModule;
+import org.maven.ide.eclipse.wtp.earmodules.EarModuleFactory;
+import org.maven.ide.eclipse.wtp.earmodules.EarPluginException;
+import org.maven.ide.eclipse.wtp.earmodules.output.FileNameMapping;
+import org.maven.ide.eclipse.wtp.earmodules.output.FileNameMappingFactory;
+
+/**
+ * EarPluginConfiguration used to read maven-ear-plugin configuration.
+ *
+ * @see http://maven.apache.org/plugins/maven-ear-plugin/
+ * @see http://maven.apache.org/plugins/maven-ear-plugin/modules.html
+ * @author Fred Bricon
+ */
+class EarPluginConfiguration {
+
+ private static final String EAR_DEFAULT_LIB_DIR = "/"; //J2EEConstants.EAR_DEFAULT_LIB_DIR
+
+ //Default EAR version produced by the maven-ear-plugin
+ private static final IProjectFacetVersion DEFAULT_EAR_FACET = IJ2EEFacetConstants.ENTERPRISE_APPLICATION_13;
+
+ final Plugin plugin;
+
+ final MavenProject mavenProject;
+
+ String libDirectory;
+
+ //XXX see if Lazy loading / caching the different factories and services is relevant.
+ ArtifactTypeMappingService typeMappingService;
+
+ @SuppressWarnings("unchecked")
+ public EarPluginConfiguration(MavenProject mavenProject) {
+
+ if (JEEPackaging.EAR != JEEPackaging.getValue(mavenProject.getPackaging()))
+ throw new IllegalArgumentException("Maven project must have ear packaging");
+
+
+ Plugin ear = null;
+ for(Plugin plugin : (List) mavenProject.getBuildPlugins()) {
+ if("org.apache.maven.plugins".equals(plugin.getGroupId()) && "maven-ear-plugin".equals(plugin.getArtifactId())) {
+ ear = plugin;
+ break;
+ }
+ }
+ this.plugin = ear;
+ this.mavenProject = mavenProject;
+ }
+
+ /**
+ * @return ear plugin configuration or null.
+ */
+ private Xpp3Dom getConfiguration() {
+ if(plugin == null) {
+ return null;
+ }
+ return (Xpp3Dom) plugin.getConfiguration();
+ }
+
+ /**
+ * Gets an IProjectFacetVersion version from maven-ear-plugin configuration.
+ * @return the facet version of the project, Maven defaults to (Java EE) 1.3
+ */
+ public IProjectFacetVersion getEarFacetVersion() {
+ Xpp3Dom config = getConfiguration();
+ if(config == null) {
+ return DEFAULT_EAR_FACET;
+ }
+
+ Xpp3Dom domVersion = config.getChild("version");
+ if(domVersion != null) {
+ String sVersion = domVersion.getValue();
+ try {
+ double version = Double.parseDouble(sVersion); //hack to transform version 5 to 5.0
+ //IJ2EEFacetConstants.ENTERPRISE_APPLICATION_FACET.getVersion(String version) is available in WTP 3.x
+ return WTPFacetsUtil.EAR_FACET.getVersion(Double.toString(version));
+ } catch(NumberFormatException nfe) {
+ MavenLogger.log("unable to read ear version : " + sVersion, nfe);
+ return DEFAULT_EAR_FACET;
+ }
+ }
+ return DEFAULT_EAR_FACET;
+ }
+
+
+ /**
+ * Gets the ear content directory of the project from pom.xml configuration.
+ * @return the first resource directory found in pom.xml.
+ */
+ @SuppressWarnings("unchecked")
+ public String getEarContentDirectory(IProject project) {
+ //Returns the first resource directory we find
+ //default should be src/main/resources
+ return MavenProjectUtils.getResourceLocations(project, mavenProject.getResources())[0].toString();
+ }
+
+ public String getDefaultLibDirectory() {
+ Xpp3Dom config = getConfiguration();
+ if(config != null) {
+ Xpp3Dom libDom = config.getChild("defaultJavaBundleDir");
+ if(libDom != null) {
+ String libDir = libDom.getValue().trim();
+ libDirectory = (libDir == null || libDir.length() == 0) ? EAR_DEFAULT_LIB_DIR : libDir;
+ return libDirectory;
+ }
+ }
+
+ return EAR_DEFAULT_LIB_DIR;
+ }
+
+ /**
+ * Reads maven-ear-plugin configuration to build a set of EarModule.
+ * @see org.apache.maven.plugin.ear.AbstractEarMojo
+ * @return an unmodifiable set of EarModule
+ */
+ public Set getEarModules() throws EarPluginException {
+ @SuppressWarnings("unchecked")
+ Set artifacts = mavenProject.getArtifacts();
+ if (artifacts == null || artifacts.isEmpty())
+ {
+ return Collections.emptySet();
+ }
+
+ Set earModules = new HashSet(artifacts.size());
+ String defaultLibDir = getDefaultLibDirectory();
+ EarModuleFactory earModuleFactory = EarModuleFactory.createEarModuleFactory(getArtifactTypeMappingService(), getFileNameMapping(), getMainArtifactId(), artifacts);
+
+ earModules.addAll(getEarModulesFromConfig(earModuleFactory, defaultLibDir)); //Resolve Ear modules from plugin config
+
+ ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
+
+ //next, add remaining modules from maven project dependencies
+ for (Artifact artifact : artifacts) {
+
+ // If the artifact's type is POM, ignore and continue
+ // since it's used for transitive deps only.
+ if ( "pom".equals( artifact.getType() ) )
+ {
+ continue;
+ }
+
+ // Artifact is not yet registered and it has neither test, nor a
+ // provided scope, not is it optional
+ if (!isArtifactRegistered(artifact, earModules) && !artifact.isOptional() &&
+ filter.include(artifact)){
+ EarModule module = earModuleFactory.newEarModule(artifact, defaultLibDir);
+ if (module != null) {
+ earModules.add(module);
+ }
+ }
+ }
+ return Collections.unmodifiableSet(earModules);
+ }
+
+
+ private String getMainArtifactId() {
+ // TODO read xml config
+ return "none";
+ }
+
+ private ArtifactTypeMappingService getArtifactTypeMappingService() throws EarPluginException {
+ if (typeMappingService == null)
+ {
+ typeMappingService = new ArtifactTypeMappingService(getConfiguration());
+ }
+ return typeMappingService;
+ }
+
+
+ private FileNameMapping getFileNameMapping() {
+
+ Xpp3Dom config = getConfiguration();
+ if(config == null) {
+ return FileNameMappingFactory.INSTANCE.getDefaultFileNameMapping();
+ }
+
+ Xpp3Dom fileNameMappingDom = config.getChild("fileNameMapping");
+ if (fileNameMappingDom != null) {
+ String fileNameMappingName = fileNameMappingDom.getValue().trim();
+ return FileNameMappingFactory.INSTANCE.getFileNameMapping( fileNameMappingName );
+ }
+ return FileNameMappingFactory.INSTANCE.getDefaultFileNameMapping();
+ }
+
+
+
+ /**
+ * Return a set of ear modules defined in maven-ear-plugin configuration.
+ * @param earModuleFactory
+ */
+ @SuppressWarnings("unchecked")
+ private Set getEarModulesFromConfig(EarModuleFactory earModuleFactory, String defaultLib) {
+ Set earModules = new HashSet();
+ Xpp3Dom configuration = getConfiguration();
+ if(configuration == null) {
+ return earModules;
+ }
+ Xpp3Dom modulesNode = configuration.getChild("modules");
+
+ if(modulesNode == null) {
+ return earModules;
+ }
+
+ Xpp3Dom[] domModules = modulesNode.getChildren();
+ if(domModules == null || domModules.length == 0) {
+ return earModules;
+ }
+ /*
+ for(Xpp3Dom domModule : domModules) {
+ EarModule earModule = earModuleFactory.newEarModule(domModule, defaultLib, mavenProject.getArtifacts());
+ if(earModule != null && !earModule.isExcluded()) {
+ earModules.add(earModule);
+ }
+ }
+ */
+ return earModules;
+ }
+
+ private static boolean isArtifactRegistered(Artifact a, Set modules) {
+ for(EarModule module : modules) {
+ if(module.getArtifact().equals(a)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EarProjectConfiguratorDelegate.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EarProjectConfiguratorDelegate.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EarProjectConfiguratorDelegate.java (revision 0)
@@ -0,0 +1,385 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.wtp;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jst.j2ee.application.internal.operations.AddComponentToEnterpriseApplicationDataModelProvider;
+import org.eclipse.jst.j2ee.earcreation.IEarFacetInstallDataModelProperties;
+import org.eclipse.jst.j2ee.internal.earcreation.EarFacetInstallDataModelProvider;
+import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties;
+import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
+import org.maven.ide.eclipse.core.IMavenConstants;
+import org.maven.ide.eclipse.core.MavenLogger;
+import org.maven.ide.eclipse.project.IMavenProjectFacade;
+import org.maven.ide.eclipse.wtp.earmodules.EarModule;
+
+/**
+ * Configures Ear projects from maven-ear-plugin.
+ *
+ * @see org.eclipse.jst.j2ee.ui.AddModulestoEARPropertiesPage
+ * @author Fred Bricon
+ */
+@SuppressWarnings("restriction")
+class EarProjectConfiguratorDelegate extends AbstractProjectConfiguratorDelegate {
+
+ private static String M2_REPO_PREFIX = VirtualArchiveComponent.VARARCHIVETYPE + IPath.SEPARATOR
+ + IMavenConstants.M2_REPO + IPath.SEPARATOR;
+
+ private static final IStatus OK_STATUS = IDataModelProvider.OK_STATUS;
+
+ public void configureProject(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException {
+
+ EarPluginConfiguration config = new EarPluginConfiguration(mavenProject);
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
+
+ Set actions = new LinkedHashSet();
+
+ IDataModel earModelCfg = DataModelFactory.createDataModel(new EarFacetInstallDataModelProvider());
+
+ //Configuring content directory
+ String contentDir = config.getEarContentDirectory(project);
+ earModelCfg.setProperty(IEarFacetInstallDataModelProperties.CONTENT_DIR, contentDir);
+
+ //Adding EAR Facet
+ IProjectFacetVersion earFv = config.getEarFacetVersion();
+
+ if(!facetedProject.hasProjectFacet(WTPFacetsUtil.EAR_FACET)) {//WTP doesn't allow facet versions changes for JEE facets.
+ actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, earFv, earModelCfg));
+ }
+
+ if (!actions.isEmpty()) {
+ facetedProject.modify(actions, monitor);
+ }
+ removeTestFolderLinks(project, mavenProject, monitor, "/");
+ }
+
+ public void setModuleDependencies(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException {
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
+ if(!facetedProject.hasProjectFacet(WTPFacetsUtil.EAR_FACET)) {
+ return;
+ }
+
+ EarPluginConfiguration config = new EarPluginConfiguration(mavenProject);
+ //Retrieving all ear module configuration from maven-ear-plugin : User defined modules + artifacts dependencies.
+ Set earModules = config.getEarModules();
+ String libBundleDir = config.getDefaultLibDirectory();
+
+ //FB : I consider the delegate to be stateless - maybe I'm wrong -
+ //hence we wrap all the interesting attributes of our new ear in an inner class, to stay close to AddModulestoEARPropertiesPage.
+ EarComponentWrapper earComponentWrp = new EarComponentWrapper(project, libBundleDir);
+
+ for (EarModule earModule : earModules) {
+ if (earModule.isExcluded()) continue;
+
+ Artifact artifact = earModule.getArtifact();
+ IMavenProjectFacade workspaceDependency = projectManager.getMavenProject(artifact.getGroupId(), artifact
+ .getArtifactId(), artifact.getVersion());
+
+ if(workspaceDependency != null && !workspaceDependency.getProject().equals(project)
+ && workspaceDependency.getFullPath(artifact.getFile()) != null) {
+ //artifact dependency is a workspace project
+ IProject depProject = workspaceDependency.getProject();
+ configureDependencyProject(workspaceDependency, monitor);
+ earComponentWrp.addProject(depProject, earModule);
+ } else {
+ //artifact dependency should be added as a JEE module, referenced with M2_REPO variable
+ earComponentWrp.addReference(earModule);
+ }
+ }
+
+ removeComponents(earComponentWrp, monitor);
+ addComponents(earComponentWrp, monitor);
+ //XXX how do we set security roles using wtp api?
+ //XXX how do we set alt-dds using wtp api?
+ //XXX updating libdir?
+ //XXX generating Deployment Descriptor ? operation exists in WTP 3.0.0
+ }
+
+ private void configureDependencyProject(IMavenProjectFacade mavenProjectFacade, IProgressMonitor monitor) throws CoreException{
+ // TODO Check what to do w/ the following datamodel
+ /*
+ IDataModel migrationdm = DataModelFactory.createDataModel(new JavaProjectMigrationDataModelProvider());
+ migrationdm.setProperty(IJavaProjectMigrationDataModelProperties.PROJECT_NAME, project.getName());
+ try{
+ migrationdm.getDefaultOperation().execute(monitor, null);
+ } catch (ExecutionException e) {
+ throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, "Unable to configure dependent project",e));
+ }
+ */
+
+ //XXX Refactor the following w/
+ IProject project = mavenProjectFacade.getProject();
+ String depPackaging = mavenProjectFacade.getPackaging();
+ //jee dependency has not been configured yet - i.e. has not JEE facet-
+ if (JEEPackaging.isJEEPackaging(depPackaging) && !J2EEProjectUtilities.isJEEProject(project)){
+ IProjectConfiguratorDelegate delegate = ProjectConfiguratorDelegateFactory.getProjectConfiguratorDelegate(mavenProjectFacade.getPackaging());
+ if (delegate != null)
+ {
+ //Lets install the proper facets
+ delegate.configureProject(project, mavenProjectFacade.getMavenProject(monitor), monitor);
+ }
+ } else {
+ //XXX Probably should create a UtilProjectConfiguratorDelegate
+ configureWtpUtil(project, monitor);
+ }
+ }
+
+ private void addComponents(EarComponentWrapper earComponentWrapper, IProgressMonitor monitor) throws CoreException {
+ //XXX adding components is probably the most complex part. look closely at AddModulestoEARPropertiesPage.java.
+ //We need to handle java projects, dependency components, if jeeVersion >=5 : java project in lib dir and dependency components in lib dir
+ //I try a slightly different approach than what's done in AddModulestoEARPropertiesPage. Not sure if it's gonna make it though.
+ //The thing is maven-ear-plugin lets you define as many bundle dir as you want
+ if( earComponentWrapper != null ){
+ IVirtualComponent earComponent = earComponentWrapper.getEarComponent();
+ Map> compMap = earComponentWrapper.getJeeComponentsMap();
+ if (compMap != null && !compMap.isEmpty())
+ {
+ for (String bundleDir : compMap.keySet()) {
+ execAddOp(monitor, earComponent, compMap.get(bundleDir), bundleDir);
+ }
+ }
+ Map> projectsMap = earComponentWrapper.getProjectsMap();
+ if (projectsMap != null && !projectsMap.isEmpty())
+ {
+ for (String bundleDir : projectsMap.keySet()) {
+ execAddOp(monitor, earComponent, projectsMap.get(bundleDir), bundleDir);
+ }
+ }
+
+ }
+ }
+
+ /**
+ * Execute addComponent operation on the ear component.
+ * @param monitor - the monitor.
+ * @param earComponent - the ear component.
+ * @param uriMap - the components set to be added to the ear.
+ * @param deployPath - the deploy path
+ * @throws CoreException
+ */
+
+ private void execAddOp(IProgressMonitor monitor, IVirtualComponent earComponent, Map uriMap, String deployPath) throws CoreException {
+ if (uriMap == null || uriMap.isEmpty()) return;
+
+ List components = new ArrayList(uriMap.keySet());
+ IDataModel dm = DataModelFactory.createDataModel(new AddComponentToEnterpriseApplicationDataModelProvider());
+
+ dm.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earComponent);
+ dm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, components);
+ dm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_DEPLOY_PATH, deployPath);
+ dm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_TO_URI_MAP, uriMap);
+
+ IStatus stat = dm.validateProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST);
+ if (stat != OK_STATUS)
+ throw new CoreException(stat);
+ try {
+ dm.getDefaultOperation().execute(monitor, null);
+ } catch (ExecutionException e) {
+ throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, "Unable to add components to ear",e));
+ }
+ }
+
+ private void removeComponents(EarComponentWrapper earComponent, IProgressMonitor monitor) {
+ MavenLogger.log(new Status(IStatus.INFO, IMavenConstants.PLUGIN_ID, "should remove components now"));
+ }
+
+ protected List getComponentsToRemove(EarComponentWrapper earComponentWrp){
+ List newComponents = earComponentWrp.getAllReferencedComponents();
+ List compToRemove = new ArrayList();
+
+ IVirtualReference[] oldrefs = earComponentWrp.getEarComponent().getReferences();
+ for (int j = 0; j < oldrefs.length; j++) {
+ IVirtualReference ref = oldrefs[j];
+ IVirtualComponent handle = ref.getReferencedComponent();
+ if(!newComponents.contains(handle)){
+ compToRemove.add(handle);
+ }
+ }
+ return compToRemove;
+ }
+
+ /**
+ * EarComponentWrapper stores ear component informations and its dependency components.
+ *
+ * @author Fred Bricon.
+ */
+ //XXX Refactor to top level class if private fields accessibility is an issue.
+ private class EarComponentWrapper {
+
+ //XXX I apologize for the ugly maps. It's a work in progress after all. FB.
+ /**
+ * Sets of components per bundleDir.
+ */
+ private Map> jeeComponentsMap;
+
+ /**
+ * Sets of project per bundleDir.
+ */
+ private Map> projectsMap;
+
+ private boolean isJeeVersion = false;
+
+ private IVirtualComponent earComponent;
+
+ private String defaultLibBundleDir;
+
+ private EarComponentWrapper(IProject project, String libBundleDir) {
+ earComponent = ComponentCore.createComponent(project);
+ jeeComponentsMap = new HashMap>();
+ projectsMap = new HashMap>();
+ this.isJeeVersion = J2EEProjectUtilities.isJEEProject(project);//XXX need to check if this is based on project facet versions
+ this.defaultLibBundleDir = (libBundleDir == null || "".equals(libBundleDir.trim()))?"/":libBundleDir;
+ }
+
+ void addProject(IProject project, EarModule earModule) {
+ IVirtualComponent projectComponent = ComponentCore.createComponent(project);
+ if (!inEARAlready(projectComponent)) {
+ addComponentToMap(projectsMap, projectComponent, earModule.getUri(), earModule.getBundleDir());
+ }
+ }
+
+ private boolean inEARAlready(IVirtualComponent component){
+ IVirtualReference refs[] = earComponent.getReferences();
+ for( int i=0; i< refs.length; i++){
+ IVirtualReference ref = refs[i];
+ if ( ref.getReferencedComponent().equals( component ))
+ return true;
+ }
+ return false;
+ }
+
+
+ void addReference(EarModule earModule) {
+ //Create dependency component
+ String artifactPath = M2_REPO_PREFIX + ArtifactHelper.getLocalRepoRelativePath(earModule.getArtifact()).toPortableString();
+ IVirtualComponent depComponent = ComponentCore.createArchiveComponent(earComponent.getProject(), artifactPath);
+ IVirtualReference newRef = ComponentCore.createReference( earComponent, depComponent);
+
+ //Check duplicates for dependency component
+ IVirtualReference [] existingRefs = earComponent.getReferences();
+ String defaultArchiveName = new Path(newRef.getReferencedComponent().getName()).lastSegment();
+
+ boolean dupeArchiveName = false;
+ //check for duplicates
+ for(int j=0;j> targetCompMap, IVirtualComponent component, String uri, String bundleDir) {
+
+ bundleDir = (bundleDir == null || "".equals(bundleDir.trim()))? defaultLibBundleDir : bundleDir;
+
+ Map componentsUriMap = targetCompMap.get(bundleDir);
+ if ( componentsUriMap == null) {
+ componentsUriMap = new HashMap();
+ }
+ componentsUriMap.put(component, uri);
+ targetCompMap.put(bundleDir, componentsUriMap);
+ }
+
+
+ boolean isJeeVersion() {
+ return isJeeVersion;
+ }
+
+ IVirtualComponent getEarComponent() {
+ return earComponent;
+ }
+
+ String getDefaultLibBundleDir() {
+ return defaultLibBundleDir;
+ }
+
+ Map> getJeeComponentsMap() {
+ return jeeComponentsMap;
+ }
+
+ Map> getProjectsMap() {
+ return projectsMap;
+ }
+
+ List getAllReferencedComponents() {
+ Set set = new HashSet();
+ getMapAsSet(set, jeeComponentsMap);
+ getMapAsSet(set, projectsMap);
+ return new ArrayList(set);
+ }
+
+
+ private void getMapAsSet(Set set, Map> compMap) {
+ if (compMap != null && !compMap.isEmpty()){
+ for (Map uriMaps : compMap.values()){
+ set.addAll(uriMaps.keySet());
+ }
+ }
+ }
+
+
+ }
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EjbPluginConfiguration.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EjbPluginConfiguration.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EjbPluginConfiguration.java (revision 0)
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.wtp;
+
+import java.util.List;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.maven.ide.eclipse.project.MavenProjectUtils;
+
+/**
+ * See http://maven.apache.org/plugins/maven-ejb-plugin/ejb-mojo.html
+ *
+ * @author Fred Bricon
+ */
+
+@SuppressWarnings("restriction")
+class EjbPluginConfiguration {
+
+ /**
+ * Maven defaults ejb version to 2.1
+ */
+ private static final IProjectFacetVersion DEFAULT_EJB_FACET_VERSION = IJ2EEFacetConstants.EJB_21;
+
+ final Plugin plugin;
+
+ final MavenProject ejbProject;
+
+ @SuppressWarnings("unchecked")
+ public EjbPluginConfiguration(MavenProject mavenProject) {
+
+ if (JEEPackaging.EJB != JEEPackaging.getValue(mavenProject.getPackaging()))
+ throw new IllegalArgumentException("Maven project must have ejb packaging");
+
+ this.ejbProject = mavenProject;
+
+ Plugin ejbPlugin = null;
+ for (Plugin plugin : (List) mavenProject.getBuildPlugins()) {
+ if ("org.apache.maven.plugins".equals(plugin.getGroupId()) && "maven-ejb-plugin".equals(plugin.getArtifactId())) {
+ ejbPlugin = plugin;
+ break;
+ }
+ }
+ this.plugin = ejbPlugin;
+ }
+
+ /**
+ * Gets EJB_FACET version of the project from pom.xml.
+ * @return value of <maven-ejb-plugin><configuration><ejbVersion>. Default value is 2.1.
+ */
+ public IProjectFacetVersion getEjbFacetVersion() {
+ if (plugin == null){
+ return DEFAULT_EJB_FACET_VERSION;
+ }
+
+ Xpp3Dom dom = (Xpp3Dom) plugin.getConfiguration();
+ if (dom == null) {
+ return DEFAULT_EJB_FACET_VERSION;
+ }
+
+ Xpp3Dom domVersion = dom.getChild("ejbVersion");
+ if (domVersion != null) {
+ return WTPFacetsUtil.EJB_FACET.getVersion(domVersion.getValue());
+ }
+ return DEFAULT_EJB_FACET_VERSION;
+ }
+
+ /**
+ * @return the first resource location directory declared in pom.xml
+ */
+ @SuppressWarnings("unchecked")
+ public String getEjbContentDirectory(IProject project) {
+ IPath[] resources = MavenProjectUtils.getResourceLocations(project, ejbProject.getResources());
+ return resources[0].toPortableString();
+ }
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EjbProjectConfiguratorDelegate.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EjbProjectConfiguratorDelegate.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/EjbProjectConfiguratorDelegate.java (revision 0)
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.wtp;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.maven.project.MavenProject;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jst.j2ee.ejb.project.operations.IEjbFacetInstallDataModelProperties;
+import org.eclipse.jst.j2ee.internal.ejb.project.operations.EjbFacetInstallDataModelProvider;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
+
+/**
+ * EjbProjectConfiguratorDelegate
+ *
+ * @author Fred Bricon
+ */
+@SuppressWarnings("restriction")
+class EjbProjectConfiguratorDelegate extends AbstractProjectConfiguratorDelegate {
+
+ public void configureProject(IProject project, MavenProject mavenProject, IProgressMonitor monitor)
+ throws CoreException {
+
+ EjbPluginConfiguration config = new EjbPluginConfiguration(mavenProject);
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
+ Set actions = new LinkedHashSet();
+ installJavaFacet(actions, project, facetedProject);
+ IProjectFacetVersion ejbFv = config.getEjbFacetVersion();
+
+ IDataModel ejbModelCfg = DataModelFactory.createDataModel(new EjbFacetInstallDataModelProvider());
+
+ //Configuring content directory : used by WTP to create META-INF/manifest.mf, ejb-jar.xml
+ String contentDir = config.getEjbContentDirectory(project);
+ ejbModelCfg.setProperty(IEjbFacetInstallDataModelProperties.CONFIG_FOLDER, contentDir);
+
+ if(!facetedProject.hasProjectFacet(WTPFacetsUtil.EJB_FACET)) {//WTP doesn't allow facet versions changes for JEE facets.
+ actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, ejbFv, ejbModelCfg));
+ }
+
+ if (!actions.isEmpty()) {
+ facetedProject.modify(actions, monitor);
+ }
+ removeTestFolderLinks(project, mavenProject, monitor, "/"); //XXX Doesn't work !!!
+ }
+
+ public void setModuleDependencies(IProject project, MavenProject mavenProject, IProgressMonitor monitor)
+ throws CoreException {
+ // TODO check if there's anything to do!
+ }
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/IProjectConfiguratorDelegate.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/IProjectConfiguratorDelegate.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/IProjectConfiguratorDelegate.java (revision 0)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.wtp;
+
+import org.apache.maven.project.MavenProject;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * Configure projects based on maven plugin configuration.
+ *
+ * @author Fred Bricon
+ */
+interface IProjectConfiguratorDelegate {
+
+ /**
+ * Set project facet and configure settings according to maven plugin configuration.
+ * @param mavenProject
+ * @param project
+ * @param monitor
+ * @throws CoreException
+ */
+ void configureProject(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException;
+
+ /**
+ * Configure project module dependencies based on maven plugin configuration.
+ * @param mavenProject
+ * @param project
+ * @param monitor
+ * @throws CoreException
+ */
+ void setModuleDependencies(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException;
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/JEEPackaging.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/JEEPackaging.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/JEEPackaging.java (revision 0)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.wtp;
+
+/**
+ * Enumeration of Maven JEE related packaging types.
+ *
+ * @author Fred Bricon
+ */
+//XXX enum should most probably be refactored to another project.
+public enum JEEPackaging {
+ /**
+ * Web project.
+ */
+ WAR("war"),
+ /**
+ * Enterprise Java Bean.
+ */
+ EJB("ejb"),
+ /**
+ * Enterprise Application Resource.
+ */
+ EAR("ear"),
+ /**
+ * Resource Adapter Archive.
+ */
+ RAR("rar"),
+ /**
+ * Unknown packaging.
+ */
+ UNKNOWN(null);
+ //XXX add support for other packaging types.
+
+ private String name;
+
+ private JEEPackaging(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the packaging name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets a JEEPackaging from maven packaging name. Supported values are war, ejb, ear,
+ * rar.
+ *
+ * @param packaging of a maven artifact.
+ * @return the corresponding JEEPackaging or UNKNOWN if the package type is not supported.
+ */
+ static JEEPackaging getValue(String packaging) {
+ if(packaging == null) {
+ throw new IllegalArgumentException("packaging must not be null");
+ }
+ for(JEEPackaging pkg : values()) {
+ if(packaging.equals(pkg.getName())) {
+ return pkg;
+ }
+ }
+ return UNKNOWN;
+ }
+
+ static boolean isJEEPackaging(String packaging) {
+ JEEPackaging pkg = getValue(packaging);
+ return !UNKNOWN.equals(pkg);
+ }
+
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/ProjectConfiguratorDelegateFactory.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/ProjectConfiguratorDelegateFactory.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/ProjectConfiguratorDelegateFactory.java (revision 0)
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.wtp;
+
+
+/**
+ * This factory creates IProjectConfiguratorDelegate based on Maven projects packaging.
+ *
+ * @author Fred Bricon
+ */
+//XXX See if we could refactor this to do JEEPackaging.createProjectConfiguratorDelegate() instead.
+class ProjectConfiguratorDelegateFactory {
+
+ private ProjectConfiguratorDelegateFactory() {
+ //We don't need to instantiate this class
+ }
+
+
+ /**
+ * IProjectConfiguratorDelegate factory method.
+ * @param packaging supported values are war, ejb, ear.
+ * @return a new instance of IProjectConfiguratorDelegate or null if packaging is not supported.
+ */
+ static IProjectConfiguratorDelegate getProjectConfiguratorDelegate(String packaging){
+ JEEPackaging mvnPackaging = JEEPackaging.getValue(packaging);
+
+ switch(mvnPackaging) {
+ case WAR:
+ return new WebProjectConfiguratorDelegate();
+ case EJB:
+ return new EjbProjectConfiguratorDelegate();
+ case EAR:
+ return new EarProjectConfiguratorDelegate();
+ default :
+ return null;
+ }
+
+ }
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WarPluginConfiguration.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WarPluginConfiguration.java (revision 1148)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WarPluginConfiguration.java (working copy)
@@ -8,11 +8,20 @@
package org.maven.ide.eclipse.wtp;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.List;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
+import org.eclipse.jst.j2ee.web.project.facet.WebFacetUtils;
+import org.eclipse.jst.jee.util.internal.JavaEEQuickPeek;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
/**
@@ -20,10 +29,12 @@
*
* @author Igor Fedorenko
*/
+@SuppressWarnings("restriction")
class WarPluginConfiguration {
private static final String WAR_SOURCE_FOLDER = "/src/main/webapp";
private static final String WAR_PACKAGING = "war";
+ private static final String WEB_XML = "WEB-INF/web.xml";
final Plugin plugin;
@@ -61,4 +72,30 @@
return WAR_SOURCE_FOLDER;
}
+
+
+ public IProjectFacetVersion getWebFacetVersion(IProject project) {
+ IFile webXml = project.getFolder(getWarSourceDirectory()).getFile(WEB_XML);
+ if (webXml.isAccessible()) {
+ try {
+ InputStream is = webXml.getContents();
+ try {
+ JavaEEQuickPeek jqp = new JavaEEQuickPeek(is);
+ switch (jqp.getVersion()) {
+ case J2EEVersionConstants.WEB_2_2_ID: return WebFacetUtils.WEB_22;
+ case J2EEVersionConstants.WEB_2_3_ID: return WebFacetUtils.WEB_23;
+ case J2EEVersionConstants.WEB_2_4_ID: return WebFacetUtils.WEB_24;
+ case J2EEVersionConstants.WEB_2_5_ID: return WebFacetUtils.WEB_FACET.getVersion("2.5");
+ }
+ } finally {
+ is.close();
+ }
+ } catch (IOException ex) {
+ // expected
+ } catch(CoreException ex) {
+ // expected
+ }
+ }
+ return WebFacetUtils.WEB_23;
}
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WebProjectConfiguratorDelegate.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WebProjectConfiguratorDelegate.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WebProjectConfiguratorDelegate.java (revision 0)
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.wtp;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.maven.project.MavenProject;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
+import org.eclipse.jst.j2ee.project.facet.IJ2EEModuleFacetInstallDataModelProperties;
+import org.eclipse.jst.j2ee.web.project.facet.WebFacetInstallDataModelProvider;
+import org.eclipse.jst.j2ee.web.project.facet.WebFacetUtils;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
+import org.maven.ide.eclipse.project.IMavenProjectFacade;
+
+/**
+ * WebProjectConfiguratorDelegate
+ *
+ * @author Igor Fedorenko.
+ * @author Fred Bricon.
+ */
+@SuppressWarnings("restriction")
+class WebProjectConfiguratorDelegate extends AbstractProjectConfiguratorDelegate {
+
+ public void configureProject(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException {
+ WarPluginConfiguration config = new WarPluginConfiguration(mavenProject);
+
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
+ Set actions = new LinkedHashSet();
+ installJavaFacet(actions, project, facetedProject);
+
+ String warSourceDirectory = config.getWarSourceDirectory();
+ IProjectFacetVersion webFv = config.getWebFacetVersion(project);
+ IDataModel webModelCfg = DataModelFactory.createDataModel(new WebFacetInstallDataModelProvider());
+ webModelCfg.setProperty(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER, warSourceDirectory);
+ if(!facetedProject.hasProjectFacet(WebFacetUtils.WEB_FACET)) {
+ actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, webFv, webModelCfg));
+ }
+ // WTP 2.0.2/3.0M6 does not allow to change WEB_FACET version
+ //else if (!facetedProject.hasProjectFacet(webFv)) {
+ // actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, webFv, webModelCfg));
+ //}
+
+ facetedProject.modify(actions, monitor);
+
+ // MNGECLIPSE-632 remove test sources/resources from WEB-INF/classes
+ removeTestFolderLinks(project, mavenProject, monitor, "/WEB-INF/classes");
+
+ addContainerAttribute(project, WTPClasspathConfigurator.DEPENDENCY_ATTRIBUTE, monitor);
+ }
+
+
+ public void setModuleDependencies(IProject project, MavenProject mavenProject, IProgressMonitor monitor)
+ throws CoreException {
+ IVirtualComponent component = ComponentCore.createComponent(project);
+
+ Set references = new LinkedHashSet();
+ for(IMavenProjectFacade dependency : getWorkspaceDependencies(project, mavenProject)) {
+ String depPackaging = dependency.getPackaging();
+ //jee dependency has not been configured yet - i.e. has not JEE facet-
+ if (JEEPackaging.isJEEPackaging(depPackaging) && !J2EEProjectUtilities.isJEEProject(project)){
+ IProjectConfiguratorDelegate delegate = ProjectConfiguratorDelegateFactory.getProjectConfiguratorDelegate(depPackaging);
+ if (delegate != null) {
+ delegate.configureProject(dependency.getProject(), dependency.getMavenProject(monitor), monitor);
+ }
+ } else {
+ //standard jar project
+ configureWtpUtil(dependency.getProject(), monitor);
+ }
+ IVirtualComponent depComponent = ComponentCore.createComponent(dependency.getProject());
+ IVirtualReference reference = ComponentCore.createReference(component, depComponent);
+ reference.setRuntimePath(new Path("/WEB-INF/lib"));
+ references.add(reference);
+ }
+
+ component.setReferences(references.toArray(new IVirtualReference[references.size()]));
+ }
+
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WTPFacetsUtil.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WTPFacetsUtil.java (revision 0)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WTPFacetsUtil.java (revision 0)
@@ -0,0 +1,31 @@
+
+package org.maven.ide.eclipse.wtp;
+
+import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+
+
+/**
+ * Facet utility class for WTP projects.
+ *
+ * @author Fred Bricon
+ */
+public class WTPFacetsUtil {
+
+ public static final IProjectFacet UTILITY_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.UTILITY);
+
+ public static final IProjectFacetVersion UTILITY_10 = UTILITY_FACET.getVersion("1.0");
+
+ public static final IProjectFacet EJB_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.EJB);
+
+ public static final IProjectFacet JCA_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.JCA);
+
+ public static final IProjectFacet DYNAMIC_WEB_FACET = ProjectFacetsManager
+ .getProjectFacet(IJ2EEFacetConstants.DYNAMIC_WEB);
+
+ public static final IProjectFacet EAR_FACET = ProjectFacetsManager
+ .getProjectFacet(IJ2EEFacetConstants.ENTERPRISE_APPLICATION);
+
+}
Index: org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WTPProjectConfigurator.java
===================================================================
--- org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WTPProjectConfigurator.java (revision 1148)
+++ org.maven.ide.eclipse.wtp/src/org/maven/ide/eclipse/wtp/WTPProjectConfigurator.java (working copy)
@@ -8,84 +8,37 @@
package org.maven.ide.eclipse.wtp;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.project.MavenProject;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IClasspathAttribute;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jst.common.project.facet.JavaFacetUtils;
-import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
-import org.eclipse.jst.j2ee.project.facet.IJ2EEModuleFacetInstallDataModelProperties;
-import org.eclipse.jst.j2ee.web.project.facet.WebFacetInstallDataModelProvider;
-import org.eclipse.jst.j2ee.web.project.facet.WebFacetUtils;
-import org.eclipse.jst.jee.util.internal.JavaEEQuickPeek;
-import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.ModuleCoreNature;
-import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
-import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
-import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
-import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject;
-import org.eclipse.wst.common.project.facet.core.IProjectFacet;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
-import org.maven.ide.eclipse.MavenPlugin;
-import org.maven.ide.eclipse.jdt.BuildPathManager;
import org.maven.ide.eclipse.project.IMavenProjectFacade;
import org.maven.ide.eclipse.project.MavenProjectChangedEvent;
-import org.maven.ide.eclipse.project.MavenProjectManager;
-import org.maven.ide.eclipse.project.MavenProjectUtils;
import org.maven.ide.eclipse.project.configurator.AbstractProjectConfigurator;
import org.maven.ide.eclipse.project.configurator.ProjectConfigurationRequest;
/**
- * @author Igor Fedorenko
+ * Project configurator for WTP projects. Specific project configuration is delegated
+ * to the IProjectConfiguratorDelegate bound to a maven packaging type.
+ *
+ * @author Igor Fedorenko.
*/
@SuppressWarnings("restriction")
public class WTPProjectConfigurator extends AbstractProjectConfigurator {
- // XXX move to WarPluginConfoguration
- private static final String WEB_XML = "WEB-INF/web.xml";
-
- // WTP 2.0 does not seem to have any public API to access Utility JAR facet
- private static final IProjectFacet UTILITY_FACET = ProjectFacetsManager.getProjectFacet("jst.utility");
- private static final IProjectFacetVersion UTILITY_10 = UTILITY_FACET.getVersion("1.0");
-
- private final MavenProjectManager projectManager;
-
- public WTPProjectConfigurator() {
- this.projectManager = MavenPlugin.getDefault().getMavenProjectManager();
- }
-
@Override
public void configure(MavenEmbedder embedder, ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
MavenProject mavenProject = request.getMavenProject();
- if(WarPluginConfiguration.isWarProject(mavenProject)) {
+ //Lookup the project configurator
+ IProjectConfiguratorDelegate configuratorDelegate = ProjectConfiguratorDelegateFactory.getProjectConfiguratorDelegate(mavenProject.getPackaging());
+ if (configuratorDelegate != null)
+ {
IProject project = request.getProject();
- configureWtpWar(project, mavenProject, monitor);
- setModuleDependencies(project, mavenProject, monitor);
+ configuratorDelegate.configureProject(project, mavenProject, monitor);
+ configuratorDelegate.setModuleDependencies(project, mavenProject, monitor);
}
}
@@ -94,169 +47,19 @@
IMavenProjectFacade facade = event.getMavenProject();
if(facade != null) {
IProject project = facade.getProject();
- if(isWTPWARProject(project)) {
- setModuleDependencies(project, facade.getMavenProject(monitor), monitor);
- }
- }
- }
-
- private List getWorkspaceDependencies(IProject project, MavenProject mavenProject) {
- Set projects = new HashSet();
- List dependencies = new ArrayList();
- @SuppressWarnings("unchecked")
- Set artifacts = mavenProject.getArtifacts();
- for(Artifact artifact : artifacts) {
- IMavenProjectFacade dependency = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
- if(Artifact.SCOPE_COMPILE.equals(artifact.getScope())
- && dependency != null && !dependency.getProject().equals(project)
- && dependency.getFullPath(artifact.getFile()) != null
- && projects.add(dependency.getProject()))
- {
- dependencies.add(dependency);
- }
- }
- return dependencies;
- }
-
- private void configureWtpUtil(IProject project, IProgressMonitor monitor) throws CoreException {
- IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
- Set actions = new LinkedHashSet();
- installJavaFacet(actions, project, facetedProject);
-
- if(!facetedProject.hasProjectFacet(UTILITY_FACET)) {
- actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, UTILITY_10, null));
- } else if (!facetedProject.hasProjectFacet(UTILITY_10)) {
- actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, UTILITY_10, null));
- }
-
- facetedProject.modify(actions, monitor);
- }
-
- private void configureWtpWar(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException {
- WarPluginConfiguration config = new WarPluginConfiguration(mavenProject);
-
- IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
- Set actions = new LinkedHashSet();
- installJavaFacet(actions, project, facetedProject);
-
- String warSourceDirectory = config.getWarSourceDirectory();
- IProjectFacetVersion webFv = getWebFacetVersion(project, warSourceDirectory);
- IDataModel webModelCfg = DataModelFactory.createDataModel(new WebFacetInstallDataModelProvider());
- webModelCfg.setProperty(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER, warSourceDirectory);
- if(!facetedProject.hasProjectFacet(WebFacetUtils.WEB_FACET)) {
- actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, webFv, webModelCfg));
- }
- // WTP 2.0.2/3.0M6 does not allow to change WEB_FACET version
- //else if (!facetedProject.hasProjectFacet(webFv)) {
- // actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, webFv, webModelCfg));
- //}
-
- facetedProject.modify(actions, monitor);
-
- // MNGECLIPSE-632 remove test sources/resources from WEB-INF/classes
- IVirtualComponent component = ComponentCore.createComponent(project);
- IVirtualFolder jsrc = component.getRootFolder().getFolder("/WEB-INF/classes");
- for (IPath location : getTestRoots(project, mavenProject)) {
- jsrc.removeLink(location, 0, monitor);
- }
-
- addContainerAttribute(project, WTPClasspathConfigurator.DEPENDENCY_ATTRIBUTE, monitor);
- }
-
- @SuppressWarnings("unchecked")
- private Set getTestRoots(IProject project, MavenProject mavenProject) {
- Set testRoots = new HashSet();
- testRoots.addAll(Arrays.asList(MavenProjectUtils.getSourceLocations(project, mavenProject.getTestCompileSourceRoots())));
- testRoots.addAll(Arrays.asList(MavenProjectUtils.getResourceLocations(project, mavenProject.getTestResources())));
- return testRoots;
- }
-
- private IProjectFacetVersion getWebFacetVersion(IProject project, String warSourceFolder) {
- IFile webXml = project.getFolder(warSourceFolder).getFile(WEB_XML);
- if (webXml.isAccessible()) {
- try {
- InputStream is = webXml.getContents();
- try {
- JavaEEQuickPeek jqp = new JavaEEQuickPeek(is);
- switch (jqp.getVersion()) {
- case J2EEVersionConstants.WEB_2_2_ID: return WebFacetUtils.WEB_22;
- case J2EEVersionConstants.WEB_2_3_ID: return WebFacetUtils.WEB_23;
- case J2EEVersionConstants.WEB_2_4_ID: return WebFacetUtils.WEB_24;
- case J2EEVersionConstants.WEB_2_5_ID: return WebFacetUtils.WEB_FACET.getVersion("2.5");
- }
- } finally {
- is.close();
- }
- } catch (IOException ex) {
- // expected
- } catch(CoreException ex) {
- // expected
+ if(isWTPProject(project)) {
+ MavenProject mavenProject = facade.getMavenProject(monitor);
+ IProjectConfiguratorDelegate configuratorDelegate = ProjectConfiguratorDelegateFactory.getProjectConfiguratorDelegate(mavenProject.getPackaging());
+ if (configuratorDelegate != null)
+ {
+ configuratorDelegate.setModuleDependencies(project, mavenProject, monitor);
}
- }
- return WebFacetUtils.WEB_23;
- }
-
- private void installJavaFacet(Set actions, IProject project, IFacetedProject facetedProject) {
- IProjectFacetVersion javaFv = JavaFacetUtils.compilerLevelToFacet(JavaFacetUtils.getCompilerLevel(project));
- if(!facetedProject.hasProjectFacet(JavaFacetUtils.JAVA_FACET)) {
- actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, javaFv, null));
- } else if (!facetedProject.hasProjectFacet(javaFv)) {
- actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, javaFv, null));
- }
- }
-
- // XXX consider adding getContainerAttributes to ClasspathConfigurator
- private void addContainerAttribute(IProject project, IClasspathAttribute attribute, IProgressMonitor monitor)
- throws JavaModelException {
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathEntry[] cp = javaProject.getRawClasspath();
- for(int i = 0; i < cp.length; i++ ) {
- if(IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind()
- && BuildPathManager.isMaven2ClasspathContainer(cp[i].getPath())) {
- LinkedHashMap attrs = new LinkedHashMap();
- for(IClasspathAttribute attr : cp[i].getExtraAttributes()) {
- attrs.put(attr.getName(), attr);
- }
- attrs.put(attribute.getName(), attribute);
- IClasspathAttribute[] newAttrs = attrs.values().toArray(new IClasspathAttribute[attrs.size()]);
- cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newAttrs, cp[i].isExported());
- break;
}
}
- javaProject.setRawClasspath(cp, monitor);
}
- private void setModuleDependencies(IProject project, MavenProject mavenProject, IProgressMonitor monitor)
- throws CoreException {
- IVirtualComponent component = ComponentCore.createComponent(project);
-
- Set references = new LinkedHashSet();
- for(IMavenProjectFacade dependency : getWorkspaceDependencies(project, mavenProject)) {
- configureWtpUtil(dependency.getProject(), monitor);
- IVirtualComponent depComponent = ComponentCore.createComponent(dependency.getProject());
- IVirtualReference reference = ComponentCore.createReference(component, depComponent);
- reference.setRuntimePath(new Path("/WEB-INF/lib"));
- references.add(reference);
- }
-
- component.setReferences(references.toArray(new IVirtualReference[references.size()]));
- }
-
- // isWEB = facetedProject.hasProjectFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_WEB_MODULE));
-
-// @SuppressWarnings("restriction")
-// private void removeRefernce(IVirtualComponent component, IVirtualReference reference) {
-// // no public API to remove references?
-// ((VirtualComponent) component).removeReference(reference);
-// }
-
static boolean isWTPProject(IProject project) {
return ModuleCoreNature.getModuleCoreNature(project) != null;
}
- static boolean isWTPWARProject(IProject project) throws CoreException {
- IFacetedProject facetedProject = ProjectFacetsManager.create(project);
- return facetedProject != null && facetedProject.hasProjectFacet(WebFacetUtils.WEB_FACET);
- }
-
-}
+}
\ No newline at end of file
Index: org.maven.ide.eclipse/src/org/maven/ide/eclipse/wizards/MavenArtifactComponent.java
===================================================================
--- org.maven.ide.eclipse/src/org/maven/ide/eclipse/wizards/MavenArtifactComponent.java (revision 1148)
+++ org.maven.ide.eclipse/src/org/maven/ide/eclipse/wizards/MavenArtifactComponent.java (working copy)
@@ -35,8 +35,11 @@
public static final String POM = "pom";
- static final String[] PACKAGING_OPTIONS = {JAR, WAR, EAR, RAR, POM};
+ //MNGECLIPSE-688 add EJB Support
+ public static final String EJB = "ejb";
+ static final String[] PACKAGING_OPTIONS = {JAR, WAR, EJB, EAR, RAR, POM};
+
public static final String DEFAULT_PACKAGING = JAR;
public static final String DEFAULT_VERSION = "0.0.1-SNAPSHOT";
Index: org.maven.ide.eclipse/src/org/maven/ide/eclipse/wizards/MavenProjectWizardArtifactPage.java
===================================================================
--- org.maven.ide.eclipse/src/org/maven/ide/eclipse/wizards/MavenProjectWizardArtifactPage.java (revision 1148)
+++ org.maven.ide.eclipse/src/org/maven/ide/eclipse/wizards/MavenProjectWizardArtifactPage.java (working copy)
@@ -66,6 +66,8 @@
private static final ProjectFolder[] WAR_DIRS = {JAVA, JAVA_TEST, RESOURCES, RESOURCES_TEST, WEBAPP};
+ private static final ProjectFolder[] EAR_DIRS = {RESOURCES, RESOURCES_TEST};//MNGECLIPSE-688 add EAR Support
+
private static final ProjectFolder[] POM_DIRS = {SITE};
/** special directory sets, default is JAR_DIRS */
@@ -73,6 +75,7 @@
static {
directorySets.put(MavenArtifactComponent.WAR, WAR_DIRS);
directorySets.put(MavenArtifactComponent.POM, POM_DIRS);
+ directorySets.put(MavenArtifactComponent.EAR, EAR_DIRS); //MNGECLIPSE-688 add EAR Support
}
/** parent property panel */