Author: fgiust
Date: Sun Sep 17 07:13:54 2006
New Revision: 447069

URL: http://svn.apache.org/viewvc?view=rev&rev=447069
Log:
MECLIPSE-159 Generate additional "generic" eclipse configuration files

Added:
    
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseConfigFile.java
   (with props)
    
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/
    
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/
    
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.checkstyle
    
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.classpath
    
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.project
    
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/pom.xml
   (with props)
Modified:
    
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
    
maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
    
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
    
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java

Added: 
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseConfigFile.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseConfigFile.java?view=auto&rev=447069
==============================================================================
--- 
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseConfigFile.java
 (added)
+++ 
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseConfigFile.java
 Sun Sep 17 07:13:54 2006
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.maven.plugin.eclipse;
+
+/**
+ * Represents a generic configuration file, with a name and a content.
+ * @author Fabrizio Giustina
+ * @version $Id$
+ */
+public class EclipseConfigFile
+{
+    /**
+     * The name of the file.
+     */
+    private String name;
+
+    /**
+     * The file content.
+     */
+    private String content;
+
+    /**
+     * Getter for <code>content</code>.
+     * @return Returns the content.
+     */
+    public String getContent()
+    {
+        return this.content;
+    }
+
+    /**
+     * Setter for <code>content</code>.
+     * @param content The content to set.
+     */
+    public void setContent( String content )
+    {
+        this.content = content;
+    }
+
+    /**
+     * Getter for <code>name</code>.
+     * @return Returns the name.
+     */
+    public String getName()
+    {
+        return this.name;
+    }
+
+    /**
+     * Setter for <code>name</code>.
+     * @param name The name to set.
+     */
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+}

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

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

Propchange: 
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseConfigFile.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java?view=diff&rev=447069&r1=447068&r2=447069
==============================================================================
--- 
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
 (original)
+++ 
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
 Sun Sep 17 07:13:54 2006
@@ -17,6 +17,7 @@
  */
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -40,6 +41,7 @@
 import org.apache.maven.plugin.ide.IdeDependency;
 import org.apache.maven.plugin.ide.IdeUtils;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 
 /**
@@ -236,6 +238,30 @@
     private File manifest;
 
     /**
+     * Allow to configure additional generic configuration files for eclipse 
that will be written out to disk when
+     * running eclipse:eclipse. FOr each file you can specify the name and the 
text content.
+     * 
+     * <pre>
+     * &lt;additionalConfig&gt;
+     *    &lt;file&gt;
+     *      &lt;name&gt;.checkstyle&lt;/name&gt;
+     *      &lt;content&gt;
+     *        &lt;![CDATA[&lt;fileset-config file-format-version="1.2.0" 
simple-config="true"&gt;
+     *          &lt;fileset name="all" enabled="true" check-config-name="acme 
corporate style" local="false"&gt;
+     *              &lt;file-match-pattern match-pattern="." 
include-pattern="true"/&gt;
+     *          &lt;/fileset&gt;
+     *          &lt;filter name="NonSrcDirs" enabled="true"/&gt;
+     *        &lt;/fileset-config&gt;]]&gt;
+     *      &lt;/content&gt;
+     *    &lt;/file&gt;
+     * &lt;/additionalConfig&gt;
+     * </pre>
+     * 
+     * @parameter
+     */
+    private EclipseConfigFile[] additionalConfig;
+
+    /**
      * Parsed wtp version.
      */
     private float wtpVersionFloat;
@@ -582,6 +608,31 @@
         {
             this.getLog().info( "The Maven Eclipse plugin runs in 'pde'-mode." 
);
             new EclipseOSGiManifestWriter().init( getLog(), config ).write();
+        }
+
+        if ( additionalConfig != null )
+        {
+            for ( int j = 0; j < additionalConfig.length; j++ )
+            {
+                EclipseConfigFile file = additionalConfig[j];
+                File projectRelativeFile = new File( this.eclipseProjectDir, 
file.getName() );
+                if ( projectRelativeFile.isDirectory() )
+                {
+                    // just ignore?
+                    getLog().warn( Messages.getString( 
"EclipsePlugin.foundadir", //$NON-NLS-1$
+                                                       
projectRelativeFile.getAbsolutePath() ) );
+                }
+
+                try
+                {
+                    FileUtils.fileWrite( 
projectRelativeFile.getAbsolutePath(), file.getContent() );
+                }
+                catch ( IOException e )
+                {
+                    throw new MojoExecutionException( Messages.getString( 
"EclipsePlugin.cantwritetofile", //$NON-NLS-1$
+                                                                          
projectRelativeFile.getAbsolutePath() ) );
+                }
+            }
         }
 
         getLog().info( Messages.getString( "EclipsePlugin.wrote", new Object[] 
{ //$NON-NLS-1$

Modified: 
maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties?view=diff&rev=447069&r1=447068&r2=447069
==============================================================================
--- 
maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
 (original)
+++ 
maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
 Sun Sep 17 07:13:54 2006
@@ -19,6 +19,7 @@
 EclipsePlugin.missingjrecontainer=You did specify a list of classpath 
containers without the base org.eclipse.jdt.launching.JRE_CONTAINER.\n       If 
you specify custom classpath containers you should also add 
org.eclipse.jdt.launching.JRE_CONTAINER to the list
 EclipsePlugin.deprecatedpar=Plugin parameter "{0}" is deprecated, please use 
"{1}"
 EclipsePlugin.cantcopyartifact=Can''t copy artifact "{0}".
+EclipsePlugin.foundadir={0} is a directory, ignoring.
 
 EclipseSettingsWriter.wrotesettings=Wrote settings to {0}
 EclipseSettingsWriter.cannotcreatesettings=Cannot create settings file

Modified: 
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java?view=diff&rev=447069&r1=447068&r2=447069
==============================================================================
--- 
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
 (original)
+++ 
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
 Sun Sep 17 07:13:54 2006
@@ -17,6 +17,7 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
@@ -130,8 +131,12 @@
             "org.apache.maven.plugins:maven-eclipse-plugin:eclipse" } ), 
eventMonitor, new ConsoleDownloadMonitor(),
                             properties, basedir );
 
-        assertFileEquals( localRepositoryDir.getCanonicalPath(), new File( 
basedir, "project" ),
-                          new File( projectOutputDir, ".project" ) );
+        File projectExpectedFile = new File( basedir, "project" );
+        if ( projectExpectedFile.exists() )
+        {
+            assertFileEquals( localRepositoryDir.getCanonicalPath(), 
projectExpectedFile, new File( projectOutputDir,
+                                                                               
                     ".project" ) );
+        }
 
         File classpathExpectedFile = new File( basedir, "classpath" );
         if ( classpathExpectedFile.exists() )
@@ -168,6 +173,40 @@
                               new File( projectOutputDir, 
".settings/org.eclipse.wst.common.component" ) );
         }
 
+        compareDirectoryContent( basedir, projectOutputDir, "" );
+        compareDirectoryContent( basedir, projectOutputDir, ".settings/" );
+
+    }
+
+    /**
+     * @param basedir
+     * @param projectOutputDir
+     * @throws IOException
+     */
+    private void compareDirectoryContent( File basedir, File projectOutputDir, 
String additionalDir )
+        throws IOException
+    {
+        File expectedConfigDir = new File( basedir, "expected/" + 
additionalDir );
+
+        if ( expectedConfigDir.isDirectory() )
+        {
+            File[] files = expectedConfigDir.listFiles( new FileFilter()
+            {
+                public boolean accept( File file )
+                {
+                    return !file.isDirectory();
+                }
+            } );
+
+            for ( int j = 0; j < files.length; j++ )
+            {
+                File file = files[j];
+
+                assertFileEquals( localRepositoryDir.getCanonicalPath(), file,
+                                  new File( projectOutputDir, additionalDir + 
file.getName() ) );
+
+            }
+        }
     }
 
     protected void assertFileEquals( String mavenRepo, File expectedFile, File 
actualFile )

Modified: 
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java?view=diff&rev=447069&r1=447068&r2=447069
==============================================================================
--- 
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java
 (original)
+++ 
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java
 Sun Sep 17 07:13:54 2006
@@ -213,4 +213,14 @@
         testProject( "project-22" );
     }
 
+    /**
+     * Additional config files using "additionalConfig" property.
+     * @throws Exception any exception thrown during test
+     */
+    public void testProject23()
+        throws Exception
+    {
+        testProject( "project-23" );
+    }
+
 }

Added: 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.checkstyle
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.checkstyle?view=auto&rev=447069
==============================================================================
--- 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.checkstyle
 (added)
+++ 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.checkstyle
 Sun Sep 17 07:13:54 2006
@@ -0,0 +1,6 @@
+<fileset-config file-format-version="1.2.0" simple-config="true">
+  <fileset name="all" enabled="true" check-config-name="acme corporate style" 
local="false">
+    <file-match-pattern match-pattern="." include-pattern="true"/>
+  </fileset>
+  <filter name="NonSrcDirs" enabled="true"/>
+</fileset-config>
\ No newline at end of file

Added: 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.classpath
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.classpath?view=auto&rev=447069
==============================================================================
--- 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.classpath
 (added)
+++ 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.classpath
 Sun Sep 17 07:13:54 2006
@@ -0,0 +1,5 @@
+<classpath>
+  <classpathentry kind="output" path="target/classes"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+  <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+</classpath>
\ No newline at end of file

Added: 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.project
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.project?view=auto&rev=447069
==============================================================================
--- 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.project
 (added)
+++ 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/expected/.project
 Sun Sep 17 07:13:54 2006
@@ -0,0 +1,23 @@
+<projectDescription>
+  <name>maven-eclipse-plugin-test-project-23</name>
+  <comment/>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+      <arguments/>
+    </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.pde.ManifestBuilder</name>
+      <arguments/>
+    </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.pde.SchemaBuilder</name>
+      <arguments/>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+    <nature>org.eclipse.pde.PluginNature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Added: 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/pom.xml?view=auto&rev=447069
==============================================================================
--- 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/pom.xml
 Sun Sep 17 07:13:54 2006
@@ -0,0 +1,32 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>eclipse</groupId>
+  <artifactId>maven-eclipse-plugin-test-project-23</artifactId>
+  <packaging>eclipse-plugin</packaging>
+  <version>23</version>
+  <name>maven-eclipse-plugin-test-project-23</name>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-eclipse-plugin</artifactId>
+        <configuration>
+          <additionalConfig>
+            <file>
+              <name>.checkstyle</name>
+              <content>
+                <![CDATA[<fileset-config file-format-version="1.2.0" 
simple-config="true">
+  <fileset name="all" enabled="true" check-config-name="acme corporate style" 
local="false">
+    <file-match-pattern match-pattern="." include-pattern="true"/>
+  </fileset>
+  <filter name="NonSrcDirs" enabled="true"/>
+</fileset-config>]]>
+              </content>
+            </file>
+          </additionalConfig>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-23/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to