You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ah...@apache.org on 2007/05/15 11:13:01 UTC

svn commit: r538099 - in /maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide: IdeUtils.java JeeDescriptor.java JeeUtils.java

Author: aheritier
Date: Tue May 15 02:13:01 2007
New Revision: 538099

URL: http://svn.apache.org/viewvc?view=rev&rev=538099
Log:
MECLIPSE-268 : Create a JEEUtils class to store all the logical about JEE versions and ...

Added:
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java   (with props)
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java   (with props)
Modified:
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java?view=diff&rev=538099&r1=538098&r2=538099
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java Tue May 15 02:13:01 2007
@@ -35,10 +35,8 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
@@ -47,6 +45,18 @@
  */
 public class IdeUtils
 {
+    public static final String JAVA_1_1 = "1.1";
+
+    public static final String JAVA_1_2 = "1.2";
+
+    public static final String JAVA_1_3 = "1.3";
+
+    public static final String JAVA_1_4 = "1.4";
+
+    public static final String JAVA_5_0 = "5.0";
+
+    public static final String JAVA_6_0 = "6.0";
+
     /**
      * compiler plugin id.
      */
@@ -62,8 +72,7 @@
      */
     private static final String PROPERTY_TARGET = "target"; //$NON-NLS-1$
 
-    public static String getCanonicalPath( File file )
-        throws MojoExecutionException
+    public static String getCanonicalPath( File file ) throws MojoExecutionException
     {
         try
         {
@@ -72,13 +81,15 @@
         catch ( IOException e )
         {
             throw new MojoExecutionException( Messages.getString( "cantcanonicalize", file //$NON-NLS-1$
-                .getAbsolutePath() ), e );
+            .getAbsolutePath() ), e );
         }
     }
 
     /**
      * Returns a compiler plugin settings, considering also settings altered in plugin executions .
-     * @param project maven project
+     * 
+     * @param project
+     *            maven project
      * @return option value (may be null)
      */
     public static String getCompilerPluginSetting( MavenProject project, String optionName )
@@ -92,35 +103,42 @@
         }
         return value;
     }
-    
+
     /**
      * Returns the source version configured for the compiler plugin. Returns the minimum version required to compile
      * both standard and test sources, if settings are different.
-     * @param project maven project
+     * 
+     * @param project
+     *            maven project
      * @return java source version
      */
     public static String getCompilerSourceVersion( MavenProject project )
     {
         return IdeUtils.getCompilerPluginSetting( project, PROPERTY_SOURCE );
     }
-    
+
     /**
      * Returns the target version configured for the compiler plugin. Returns the minimum version required to compile
      * both standard and test sources, if settings are different.
-     * @param project maven project
+     * 
+     * @param project
+     *            maven project
      * @return java target version
      */
     public static String getCompilerTargetVersion( MavenProject project )
     {
         return IdeUtils.getCompilerPluginSetting( project, PROPERTY_TARGET );
     }
-    
+
     /**
      * Extracts the version of the first matching dependency in the given list.
      * 
-     * @param artifactIds artifact names to compare against for extracting version
-     * @param dependencies Collection of dependencies for our project
-     * @param len expected length of the version sub-string
+     * @param artifactIds
+     *            artifact names to compare against for extracting version
+     * @param dependencies
+     *            Collection of dependencies for our project
+     * @param len
+     *            expected length of the version sub-string
      * @return
      */
     public static String getDependencyVersion( String[] artifactIds, List dependencies, int len )
@@ -188,8 +206,8 @@
             type = "java-source"; //$NON-NLS-1$
         }
 
-        Artifact resolvedArtifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
-                                                                                  classifier );
+        Artifact resolvedArtifact =
+            artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
 
         try
         {
@@ -210,138 +228,67 @@
         return resolvedArtifact;
     }
 
-    public static String resolveEjbVersion(MavenProject project)
+    public static String resolveEjbVersion( MavenProject project )
     {
-        String[] artifactIds = new String[] { "ejb", "geronimo-spec-ejb" }; //$NON-NLS-1$
-    
-        String version = IdeUtils.getDependencyVersion( artifactIds, project.getDependencies(), 3 );
-    
-        // For new Geronimo APIs, the version of the artifact isn't the one of the spec
-        if ( version == null )
-        {
-            if ( IdeUtils.getDependencyVersion( new String[] { "geronimo-ejb_2.1_spec" },
-                                                project.getDependencies(), 3 ) != null )
-                return "2.1";
-        }
-        if ( version == null )
-        {
-            if ( IdeUtils.getDependencyVersion( new String[] { "geronimo-ejb_3.0_spec" },
-                                                project.getDependencies(), 3 ) != null )
-                return "3.0";
-        }
-    
+        String version = findEjbVersionInDependencies( project );
+
         if ( version == null )
         {
             // No ejb dependency detected. Try to resolve the ejb
             // version from J2EE/JEE.
-            String versionJEE = resolveJ2eeVersionWithoutDefault(project);
-    
-            if ( versionJEE != null )
-            {
-                // A J2EE version was found, now determine the ejb
-                // version to be used from it.
-                Map conversionTable = new HashMap();
-                conversionTable.put( "1.3", "2.0" );
-                conversionTable.put( "1.4", "2.1" );
-                conversionTable.put( "5", "3.0" );
-                if ( conversionTable.containsKey( versionJEE ) )
-                {
-                    version = (String) conversionTable.get( versionJEE );
-                }
-            }
+            JeeDescriptor descriptor =
+                JeeUtils.getJeeDescriptorFromJeeVersion( findJ2eeVersionInDependencies( project ) );
+            if ( descriptor != null )
+                version = descriptor.getEjbVersion();
         }
-        return version == null ? "2.1" : version; //$NON-NLS-1$
+        return version == null ? JeeDescriptor.EJB_2_1 : version; //$NON-NLS-1$
     }
 
-    public static String resolveJ2eeVersion(MavenProject project)
+    public static String resolveJ2eeVersion( MavenProject project )
     {
-        String version = resolveJ2eeVersionWithoutDefault(project);
-    
-        return version == null ? "1.3" : version; //$NON-NLS-1$
-    }
+        String version = findJ2eeVersionInDependencies( project );
 
-    public static String resolveJ2eeVersionWithoutDefault(MavenProject project)
-    {
-        String[] artifactIds = new String[] { "javaee-api", "j2ee", "geronimo-spec-j2ee" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-    
-        String version = IdeUtils.getDependencyVersion( artifactIds, project.getDependencies(), 3 );
-    
-        // For new Geronimo APIs, the version of the artifact isn't the one of the spec
-        if ( version == null )
-        {
-            if ( IdeUtils.getDependencyVersion( new String[] { "geronimo-j2ee_1.4_spec" },
-                                                project.getDependencies(), 3 ) != null )
-                return "1.4";
-        }
-    
-        return version;
+        return version == null ? JeeDescriptor.J2EE_1_4 : version; //$NON-NLS-1$
     }
-    
-    public static String resolveJavaVersion(MavenProject project)
+
+    public static String resolveJavaVersion( MavenProject project )
     {
         String version = IdeUtils.getCompilerTargetVersion( project );
         if ( version == null )
         {
             version = IdeUtils.getCompilerSourceVersion( project );
         }
-    
+
         if ( "1.5".equals( version ) ) //$NON-NLS-1$ //$NON-NLS-2$
         {
-            version = "5.0";// see MECLIPSE-47 eclipse only accept 5.0 as a valid version //$NON-NLS-1$
+            version = IdeUtils.JAVA_5_0;// see MECLIPSE-47 eclipse only accept 5.0 as a valid version //$NON-NLS-1$
         }
         else if ( "1.6".equals( version ) ) //$NON-NLS-1$ //$NON-NLS-2$
         {
-            version = "6.0";
+            version = IdeUtils.JAVA_6_0;
         }
         else if ( version != null && version.length() == 1 )
         {
             version = version + ".0";// 5->5.0 6->6.0 7->7.0 //$NON-NLS-1$
         }
-    
-        return version == null ? "1.4" : version; //$NON-NLS-1$
+
+        return version == null ? IdeUtils.JAVA_1_4 : version; //$NON-NLS-1$
     }
 
-    public static String resolveServletVersion(MavenProject project)
+    public static String resolveServletVersion( MavenProject project )
     {
-        String[] artifactIds = new String[] { "servlet-api", "servletapi", "geronimo-spec-servlet" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-    
-        String version = IdeUtils.getDependencyVersion( artifactIds, project.getDependencies(), 3 );
-    
-        // For new Geronimo APIs, the version of the artifact isn't the one of the spec
-        if ( version == null )
-        {
-            if ( IdeUtils.getDependencyVersion( new String[] { "geronimo-servlet_2.4_spec" },
-                                                project.getDependencies(), 3 ) != null )
-                return "2.4";
-        }
-        if ( version == null )
-        {
-            if ( IdeUtils.getDependencyVersion( new String[] { "geronimo-servlet_2.5_spec" },
-                                                project.getDependencies(), 3 ) != null )
-                return "2.5";
-        }
-    
+        String version = findServletVersionInDependencies( project );
+
         if ( version == null )
         {
             // No servlet dependency detected. Try to resolve the servlet
             // version from J2EE/JEE.
-            String versionJEE = resolveJ2eeVersionWithoutDefault(project);
-    
-            if ( versionJEE != null )
-            {
-                // A J2EE version was found, now determine the servlet
-                // version to be used from it.
-                Map conversionTable = new HashMap();
-                conversionTable.put( "1.3", "2.3" );
-                conversionTable.put( "1.4", "2.4" );
-                conversionTable.put( "5", "2.5" );
-                if ( conversionTable.containsKey( versionJEE ) )
-                {
-                    version = (String) conversionTable.get( versionJEE );
-                }
-            }
+            JeeDescriptor descriptor =
+                JeeUtils.getJeeDescriptorFromJeeVersion( findJ2eeVersionInDependencies( project ) );
+            if ( descriptor != null )
+                version = descriptor.getServletVersion();
         }
-        return version == null ? "2.4" : version; //$NON-NLS-1$
+        return version == null ? JeeDescriptor.SERVLET_2_4 : version; //$NON-NLS-1$
     }
 
     public static String toRelativeAndFixSeparator( File basedir, File fileToAdd, boolean replaceSlashesWithDashes )
@@ -381,7 +328,9 @@
 
     /**
      * Returns a compiler plugin settings from a list of plugins .
-     * @param project maven project
+     * 
+     * @param project
+     *            maven project
      * @return option value (may be null)
      */
     private static String findCompilerPluginSettingInPlugins( List plugins, String optionName )
@@ -420,9 +369,69 @@
         return value;
     }
 
+    private static String findEjbVersionInDependencies( MavenProject project )
+    {
+        String[] artifactIds = new String[] { "ejb", "geronimo-spec-ejb" }; //$NON-NLS-1$
+
+        String version = IdeUtils.getDependencyVersion( artifactIds, project.getDependencies(), 3 );
+
+        // For new Geronimo APIs, the version of the artifact isn't the one of the spec
+        if ( version == null )
+        {
+            if ( IdeUtils.getDependencyVersion( new String[] { "geronimo-ejb_2.1_spec" }, project.getDependencies(), 3 ) != null )
+                return JeeDescriptor.EJB_2_1;
+        }
+        if ( version == null )
+        {
+            if ( IdeUtils.getDependencyVersion( new String[] { "geronimo-ejb_3.0_spec" }, project.getDependencies(), 3 ) != null )
+                return JeeDescriptor.EJB_3_0;
+        }
+
+        return version;
+    }
+
+    private static String findJ2eeVersionInDependencies( MavenProject project )
+    {
+        String[] artifactIds = new String[] { "javaee-api", "j2ee", "geronimo-spec-j2ee" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+        String version = IdeUtils.getDependencyVersion( artifactIds, project.getDependencies(), 3 );
+
+        // For new Geronimo APIs, the version of the artifact isn't the one of the spec
+        if ( version == null )
+        {
+            if ( IdeUtils.getDependencyVersion( new String[] { "geronimo-j2ee_1.4_spec" }, project.getDependencies(), 3 ) != null )
+                return JeeDescriptor.J2EE_1_4;
+        }
+
+        return version;
+    }
+
+    private static String findServletVersionInDependencies( MavenProject project )
+    {
+        String[] artifactIds = new String[] { "servlet-api", "servletapi", "geronimo-spec-servlet" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+        String version = IdeUtils.getDependencyVersion( artifactIds, project.getDependencies(), 3 );
+
+        // For new Geronimo APIs, the version of the artifact isn't the one of the spec
+        if ( version == null )
+        {
+            if ( IdeUtils.getDependencyVersion( new String[] { "geronimo-servlet_2.4_spec" },
+                                                project.getDependencies(), 3 ) != null )
+                return JeeDescriptor.SERVLET_2_4;
+        }
+        if ( version == null )
+        {
+            if ( IdeUtils.getDependencyVersion( new String[] { "geronimo-servlet_2.5_spec" },
+                                                project.getDependencies(), 3 ) != null )
+                return JeeDescriptor.SERVLET_2_5;
+        }
+
+        return version;
+    }
+
     private static String getProjectName( String artifactId, String version, boolean addVersionToProjectName )
     {
-        if( addVersionToProjectName )
+        if ( addVersionToProjectName )
         {
             return artifactId + '-' + version;
         }

Added: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java?view=auto&rev=538099
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java (added)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java Tue May 15 02:13:01 2007
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.ide;
+
+public class JeeDescriptor
+{
+    private String jeeVersion;
+
+    private String ejbVersion;
+
+    private String servletVersion;
+
+    private String jspVersion;
+
+    public static final String J2EE_1_2 = "1.2";
+
+    public static final String J2EE_1_3 = "1.3";
+
+    public static final String J2EE_1_4 = "1.4";
+
+    public static final String J2EE_5_0 = "5.0";
+
+    public static final String EJB_1_1 = "1.1";
+
+    public static final String EJB_2_0 = "2.0";
+
+    public static final String EJB_2_1 = "2.1";
+
+    public static final String EJB_3_0 = "3.0";
+
+    public static final String SERVLET_2_2 = "2.2";
+
+    public static final String SERVLET_2_3 = "2.3";
+
+    public static final String SERVLET_2_4 = "2.4";
+
+    public static final String SERVLET_2_5 = "2.5";
+
+    public static final String JSP_1_1 = "1.1";
+
+    public static final String JSP_1_2 = "1.2";
+
+    public static final String JSP_2_0 = "2.0";
+
+    public static final String JSP_2_1 = "2.1";
+
+    /**
+     * @param jeeVersion
+     * @param ejbVersion
+     * @param servletVersion
+     * @param jspVersion
+     */
+    public JeeDescriptor( String jeeVersion, String ejbVersion, String servletVersion, String jspVersion )
+    {
+        super();
+        this.jeeVersion = jeeVersion;
+        this.ejbVersion = ejbVersion;
+        this.servletVersion = servletVersion;
+        this.jspVersion = jspVersion;
+    }
+
+    /**
+     * @return the ejbVersion
+     */
+    public String getEjbVersion()
+    {
+        return ejbVersion;
+    }
+
+    /**
+     * @return the jeeVersion
+     */
+    public String getJeeVersion()
+    {
+        return jeeVersion;
+    }
+
+    /**
+     * @return the jspVersion
+     */
+    public String getJspVersion()
+    {
+        return jspVersion;
+    }
+
+    /**
+     * @return the servletVersion
+     */
+    public String getServletVersion()
+    {
+        return servletVersion;
+    }
+}

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java?view=auto&rev=538099
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java (added)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java Tue May 15 02:13:01 2007
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.ide;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class JeeUtils
+{
+    private static final Map jeeMap = new HashMap();
+
+    private static final Map ejbMap = new HashMap();
+
+    private static final Map servletMap = new HashMap();
+
+    private static final Map jspMap = new HashMap();
+
+    static
+    {
+        addJEE( JeeDescriptor.J2EE_5_0, JeeDescriptor.EJB_3_0, JeeDescriptor.SERVLET_2_5, JeeDescriptor.JSP_2_1 );
+        addJEE( JeeDescriptor.J2EE_1_4, JeeDescriptor.EJB_2_1, JeeDescriptor.SERVLET_2_4, JeeDescriptor.JSP_2_0 );
+        addJEE( JeeDescriptor.J2EE_1_3, JeeDescriptor.EJB_2_0, JeeDescriptor.SERVLET_2_3, JeeDescriptor.JSP_1_2 );
+        addJEE( JeeDescriptor.J2EE_1_2, JeeDescriptor.EJB_1_1, JeeDescriptor.SERVLET_2_2, JeeDescriptor.JSP_1_1 );
+
+    }
+
+    private static void addJEE( String jeeVersion, String ejbVersion, String servletVersion, String jspVersion )
+    {
+        JeeDescriptor descriptor = new JeeDescriptor( jeeVersion, ejbVersion, servletVersion, jspVersion );
+        jeeMap.put( jeeVersion, descriptor );
+        ejbMap.put( ejbVersion, descriptor );
+        servletMap.put( servletVersion, descriptor );
+        jspMap.put( jspVersion, descriptor );
+    }
+
+    public final static JeeDescriptor getJeeDescriptorFromJeeVersion( String jeeVersion )
+    {
+        if ( jeeMap.containsKey( jeeVersion ) )
+            return (JeeDescriptor) jeeMap.get( jeeVersion );
+        else
+            return null;
+    }
+
+    public final static JeeDescriptor getJeeDescriptorFromEjbVersion( String ejbVersion )
+    {
+        if ( ejbMap.containsKey( ejbVersion ) )
+            return (JeeDescriptor) ejbMap.get( ejbVersion );
+        else
+            return null;
+    }
+
+    public final static JeeDescriptor getJeeDescriptorFromServletVersion( String servletVersion )
+    {
+        if ( servletMap.containsKey( servletVersion ) )
+            return (JeeDescriptor) servletMap.get( servletVersion );
+        else
+            return null;
+    }
+
+    public final static JeeDescriptor getJeeDescriptorFromJspVersion( String jspVersion )
+    {
+        if ( jspMap.containsKey( jspVersion ) )
+            return (JeeDescriptor) jspMap.get( jspVersion );
+        else
+            return null;
+    }
+
+}

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"