flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cd...@apache.org
Subject [23/51] [partial] Refactored the PMD Maven build - Adjusted the directory structure - Fixed a lot of compile problems - Fixed the maven setup - Made PMD build with Flexmojos 7.1.0 and Apache Flex 4.13.0 - Fixed a few UnitTests
Date Tue, 26 Aug 2014 22:43:54 GMT
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/com/adobe/ac/pmd/files/impl/FileUtils.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/com/adobe/ac/pmd/files/impl/FileUtils.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/com/adobe/ac/pmd/files/impl/FileUtils.java
new file mode 100644
index 0000000..12450f8
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/com/adobe/ac/pmd/files/impl/FileUtils.java
@@ -0,0 +1,163 @@
+/*
+ * 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 com.adobe.ac.pmd.files.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.sourceforge.pmd.PMDException;
+
+import com.adobe.ac.ncss.filters.FlexFilter;
+import com.adobe.ac.pmd.files.IFlexFile;
+
+/**
+ * @author xagnetti
+ */
+public final class FileUtils
+{
+   /**
+    * @param source
+    * @param sourceList
+    * @param packageToExclude
+    * @param excludePatterns
+    * @return
+    * @throws PMDException
+    */
+   public static Map< String, IFlexFile > computeFilesList( final File source,
+                                                            final List< File > sourceList,
+                                                            final String packageToExclude,
+                                                            final List< String > excludePatterns ) throws PMDException
+   {
+      final Map< String, IFlexFile > files = new LinkedHashMap< String, IFlexFile >();
+      final FlexFilter flexFilter = new FlexFilter();
+      final Collection< File > foundFiles = getFlexFiles( source,
+                                                          sourceList,
+                                                          flexFilter );
+
+      for ( final File sourceFile : foundFiles )
+      {
+         final AbstractFlexFile file = create( sourceFile,
+                                               source );
+
+         if ( ( "".equals( packageToExclude ) || !file.getFullyQualifiedName().startsWith( packageToExclude ) )
+               && !currentPackageIncludedInExcludePatterns( file.getFullyQualifiedName(),
+                                                            excludePatterns ) )
+         {
+            files.put( file.getFullyQualifiedName(),
+                       file );
+         }
+      }
+
+      return files;
+   }
+
+   /**
+    * @param sourceFile
+    * @param sourceDirectory
+    * @return
+    */
+   public static AbstractFlexFile create( final File sourceFile,
+                                          final File sourceDirectory )
+   {
+      AbstractFlexFile file;
+
+      if ( sourceFile.getName().endsWith( ".as" ) )
+      {
+         file = new As3File( sourceFile, sourceDirectory );
+      }
+      else
+      {
+         file = new MxmlFile( sourceFile, sourceDirectory );
+      }
+
+      return file;
+   }
+
+   /**
+    * @param file
+    * @return
+    * @throws IOException
+    */
+   public static String[] readLines( final File file ) throws IOException
+   {
+      final List< String > lines = com.adobe.ac.ncss.utils.FileUtils.readFile( file );
+
+      return lines.toArray( new String[ lines.size() ] );
+   }
+
+   private static boolean currentPackageIncludedInExcludePatterns( final String fullyQualifiedName,
+                                                                   final List< String > excludePatterns )
+   {
+      if ( excludePatterns != null )
+      {
+         for ( final String excludePattern : excludePatterns )
+         {
+            if ( fullyQualifiedName.startsWith( excludePattern ) )
+            {
+               return true;
+            }
+         }
+      }
+      return false;
+   }
+
+   private static Collection< File > getFlexFiles( final File source,
+                                                   final List< File > sourceList,
+                                                   final FlexFilter flexFilter ) throws PMDException
+   {
+      if ( source == null
+            && sourceList == null )
+      {
+         throw new PMDException( "sourceDirectory is not specified", null );
+      }
+      Collection< File > foundFiles;
+      if ( source == null )
+      {
+         foundFiles = com.adobe.ac.ncss.utils.FileUtils.listFiles( sourceList,
+                                                                   flexFilter,
+                                                                   true );
+      }
+      else
+      {
+         if ( source.isDirectory() )
+         {
+            foundFiles = com.adobe.ac.ncss.utils.FileUtils.listFiles( source,
+                                                                      flexFilter,
+                                                                      true );
+         }
+         else
+         {
+            foundFiles = new ArrayList< File >();
+            foundFiles.add( source );
+         }
+      }
+      if ( foundFiles.isEmpty() )
+      {
+         return new ArrayList< File >();
+      }
+      return foundFiles;
+   }
+
+   private FileUtils()
+   {
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/com/adobe/ac/pmd/files/impl/MxmlFile.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/com/adobe/ac/pmd/files/impl/MxmlFile.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/com/adobe/ac/pmd/files/impl/MxmlFile.java
new file mode 100644
index 0000000..7438c53
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/com/adobe/ac/pmd/files/impl/MxmlFile.java
@@ -0,0 +1,334 @@
+/*
+ * 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 com.adobe.ac.pmd.files.impl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.adobe.ac.pmd.files.IMxmlFile;
+
+/**
+ * @author xagnetti
+ */
+class MxmlFile extends AbstractFlexFile implements IMxmlFile
+{
+   private static final String METADATA_TAG    = "Metadata";
+   private String[]            actualScriptBlock;
+   private int                 endLine;
+   private boolean             mainApplication = false;
+   private String[]            scriptBlock;
+   private int                 startLine;
+
+   /**
+    * @param file
+    * @param rootDirectory
+    */
+   protected MxmlFile( final File file,
+                       final File rootDirectory )
+   {
+      super( file, rootDirectory );
+
+      computeIfIsMainApplication();
+      if ( getLinesNb() > 0 )
+      {
+         extractScriptBlock();
+      }
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see com.adobe.ac.pmd.files.IMxmlFile#getActualScriptBlock()
+    */
+   public final String[] getActualScriptBlock()
+   {
+      return actualScriptBlock; // NOPMD
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see com.adobe.ac.pmd.files.IMxmlFile#getBeginningScriptBlock()
+    */
+   public int getBeginningScriptBlock()
+   {
+      return startLine;
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#getCommentClosingTag()
+    */
+   @Override
+   public final String getCommentClosingTag()
+   {
+      return "-->";
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#getCommentOpeningTag()
+    */
+   @Override
+   public final String getCommentOpeningTag()
+   {
+      return "<!--";
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see com.adobe.ac.pmd.files.IMxmlFile#getEndingScriptBlock()
+    */
+   public int getEndingScriptBlock()
+   {
+      return endLine;
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see com.adobe.ac.pmd.files.IMxmlFile#getScriptBlock()
+    */
+   public final String[] getScriptBlock()
+   {
+      return scriptBlock; // NOPMD by xagnetti on 7/7/09 3:15 PM
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see com.adobe.ac.pmd.files.IFlexFile#getSingleLineComment()
+    */
+   public String getSingleLineComment()
+   {
+      return getCommentOpeningTag();
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#isMainApplication()
+    */
+   @Override
+   public final boolean isMainApplication()
+   {
+      return mainApplication;
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#isMxml()
+    */
+   @Override
+   public final boolean isMxml()
+   {
+      return true;
+   }
+
+   private void computeIfIsMainApplication()
+   {
+      for ( final String line : getLines() )
+      {
+         if ( line.contains( "Application " )
+               && line.charAt( 0 ) == '<' )
+         {
+            mainApplication = true;
+            break;
+         }
+      }
+   }
+
+   private int computeScriptOffSet( final int startingLineIndex )
+   {
+      int currentLineIndex = startingLineIndex + 1;
+      while ( getLines().get( currentLineIndex ).contains( "CDATA[" )
+            || getLines().get( currentLineIndex ).contains( "//" ) || containsCloseComment( currentLineIndex )
+            || getLines().get( currentLineIndex ).trim().equals( "" ) )
+      {
+         currentLineIndex++;
+      }
+      return currentLineIndex
+            - startingLineIndex;
+   }
+
+   private boolean containsCloseComment( final int currentLineIndex )
+   {
+      final boolean closedAsComment = getLines().get( currentLineIndex ).contains( "/*" )
+            && getLines().get( currentLineIndex ).contains( "*/" );
+      final boolean closeMxmlComment = getLines().get( currentLineIndex ).contains( "<!--" )
+            && getLines().get( currentLineIndex ).contains( "-->" );
+      return closedAsComment
+            || closeMxmlComment;
+   }
+
+   private void copyScriptLinesKeepingOriginalLineIndices()
+   {
+      final List< String > scriptLines = extractScriptLines();
+      final List< String > metaDataLines = extractMetaDataLines();
+      final String packageLine = "package "
+            + getPackageName() + "{";
+      final String classLine = "class "
+            + getClassName().split( "\\." )[ 0 ] + "{";
+
+      scriptLines.set( 0,
+                       packageLine );
+
+      if ( metaDataLines.isEmpty()
+            || metaDataLines.get( 0 ).compareTo( "HostComponent" ) == 0 )
+      {
+         if ( scriptLines.size() > 1 )
+         {
+            scriptLines.set( 1,
+                             classLine );
+         }
+      }
+      else
+      {
+         final int firstMetaDataLine = getFirstMetaDataLine( getLines() );
+
+         for ( int i = firstMetaDataLine; i < firstMetaDataLine
+               + metaDataLines.size(); i++ )
+         {
+            scriptLines.set( i,
+                             metaDataLines.get( i
+                                   - firstMetaDataLine ) );
+         }
+         scriptLines.set( firstMetaDataLine
+                                + metaDataLines.size(),
+                          classLine );
+      }
+
+      scriptLines.set( scriptLines.size() - 1,
+                       "}}" );
+      scriptBlock = scriptLines.toArray( new String[ scriptLines.size() ] );
+   }
+
+   private List< String > extractMetaDataLines()
+   {
+      final ArrayList< String > metaDataLines = new ArrayList< String >();
+      int currentLineIndex = 0;
+      int start = 0;
+      int end = 0;
+
+      for ( final String line : getLines() )
+      {
+         if ( line.contains( METADATA_TAG ) )
+         {
+            if ( line.contains( "</" ) )
+            {
+               end = currentLineIndex
+                     - ( getLines().get( currentLineIndex - 1 ).contains( "]]>" ) ? 1
+                                                                                 : 0 );
+               if ( line.contains( "<fx" )
+                     || line.contains( "<mx" ) )
+               {
+                  start = end;
+               }
+               break;
+            }
+            if ( line.contains( "<" ) )
+            {
+               start = currentLineIndex
+                     + ( getLines().get( currentLineIndex + 1 ).contains( "CDATA[" ) ? 2
+                                                                                    : 1 );
+            }
+         }
+         currentLineIndex++;
+      }
+      metaDataLines.addAll( getLines().subList( start,
+                                                end ) );
+      return metaDataLines;
+   }
+
+   private void extractScriptBlock()
+   {
+      int currentLineIndex = 0;
+      startLine = 0;
+      endLine = 0;
+
+      for ( final String line : getLines() )
+      {
+         if ( line.contains( "Script" ) )
+         {
+            if ( line.contains( "</" ) )
+            {
+               endLine = currentLineIndex
+                     - ( getLines().get( currentLineIndex - 1 ).contains( "]]>" ) ? 1
+                                                                                 : 0 );
+               break;
+            }
+            else if ( line.contains( "<" ) )
+            {
+               startLine = currentLineIndex
+                     + computeScriptOffSet( currentLineIndex );
+            }
+         }
+         currentLineIndex++;
+      }
+
+      copyScriptLinesKeepingOriginalLineIndices();
+   }
+
+   private List< String > extractScriptLines()
+   {
+      final List< String > scriptLines = new ArrayList< String >();
+
+      for ( int j = 0; j < startLine; j++ )
+      {
+         scriptLines.add( "" );
+      }
+      if ( startLine < endLine )
+      {
+         actualScriptBlock = getLines().subList( startLine,
+                                                 endLine ).toArray( new String[ endLine
+               - startLine ] );
+         scriptLines.addAll( new ArrayList< String >( getLines().subList( startLine,
+                                                                          endLine ) ) );
+      }
+      for ( int j = endLine; j < getLines().size(); j++ )
+      {
+         scriptLines.add( "" );
+      }
+      return scriptLines;
+   }
+
+   private int getFirstMetaDataLine( final List< String > lines )
+   {
+      for ( int i = 0; i < lines.size(); i++ )
+      {
+         final String line = lines.get( i );
+
+         if ( line.contains( METADATA_TAG )
+               && line.contains( "<" ) )
+         {
+            return i;
+         }
+      }
+      return 0;
+   }
+
+   // private String printMetaData( final List< String > metaDataLines )
+   // {
+   // final StringBuffer buffer = new StringBuffer();
+   // if ( metaDataLines == null
+   // || metaDataLines.isEmpty() )
+   // {
+   // return "";
+   // }
+   // for ( final String line : metaDataLines )
+   // {
+   // buffer.append( line );
+   // }
+   // return buffer + " ";
+   // }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/net/sourceforge/pmd/PMDException.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/net/sourceforge/pmd/PMDException.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/net/sourceforge/pmd/PMDException.java
new file mode 100644
index 0000000..ce150c9
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/main/java/net/sourceforge/pmd/PMDException.java
@@ -0,0 +1,80 @@
+/*
+ * 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 net.sourceforge.pmd;
+
+/**
+ * A convenience exception wrapper. Contains the original exception, if any.
+ * Also, contains a severity number (int). Zero implies no severity. The higher
+ * the number the greater the severity.
+ * 
+ * @author Donald A. Leckie
+ * @version $Revision: 5681 $, $Date: 2007-11-30 14:00:56 -0800 (Fri, 30 Nov
+ *          2007) $
+ * @since August 30, 2002
+ */
+public class PMDException extends Exception
+{
+   private static final long serialVersionUID = 6938647389367956874L;
+
+   private int               severity;
+
+   /**
+    * @param message
+    */
+   public PMDException( final String message )
+   {
+      super( message );
+   }
+
+   /**
+    * @param message
+    * @param reason
+    */
+   public PMDException( final String message,
+                        final Exception reason )
+   {
+      super( message, reason );
+   }
+
+   /**
+    * Returns the cause of this exception or <code>null</code>
+    * 
+    * @return the cause of this exception or <code>null</code>
+    * @deprecated use {@link #getCause()} instead
+    */
+   @Deprecated
+   public Exception getReason()
+   {
+      return ( Exception ) getCause();
+   }
+
+   /**
+    * @return
+    */
+   public int getSeverity()
+   {
+      return severity;
+   }
+
+   /**
+    * @param severityToBeSet
+    */
+   public void setSeverity( final int severityToBeSet )
+   {
+      severity = severityToBeSet;
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/FlexPmdTestBaseTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/FlexPmdTestBaseTest.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/FlexPmdTestBaseTest.java
new file mode 100644
index 0000000..3fede84
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/FlexPmdTestBaseTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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 com.adobe.ac.pmd;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import com.adobe.ac.pmd.files.IFlexFile;
+
+public class FlexPmdTestBaseTest
+{
+   @Test
+   public void testSetTestFiles()
+   {
+      final FlexPmdTestBase testBase = new FlexPmdTestBase();
+      final Map< String, IFlexFile > testFilesToBeSet = new LinkedHashMap< String, IFlexFile >();
+
+      testBase.setTestFiles( testFilesToBeSet );
+      Assert.assertEquals( testFilesToBeSet,
+                           testBase.getTestFiles() );
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/ResourcesManagerTestTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/ResourcesManagerTestTest.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/ResourcesManagerTestTest.java
new file mode 100644
index 0000000..fe4848a
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/ResourcesManagerTestTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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 com.adobe.ac.pmd;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+public class ResourcesManagerTestTest
+{
+   @Test
+   public void testGetInstance()
+   {
+      final ResourcesManagerTest manager = ResourcesManagerTest.getInstance();
+
+      Assert.assertNotNull( manager.getTestFiles() );
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/MxmlFileTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/MxmlFileTest.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/MxmlFileTest.java
new file mode 100644
index 0000000..948115d
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/MxmlFileTest.java
@@ -0,0 +1,150 @@
+/*
+ * 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 com.adobe.ac.pmd.files;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.adobe.ac.pmd.FlexPmdTestBase;
+
+public class MxmlFileTest extends FlexPmdTestBase
+{
+   private IMxmlFile bug141;
+   private IMxmlFile bug233a;
+   private IMxmlFile bug233b;
+   private IMxmlFile deleteRenderer;
+   private IMxmlFile iterationsList;
+   private IMxmlFile nestedComponent;
+
+   @Before
+   public void setUp()
+   {
+      bug141 = ( IMxmlFile ) getTestFiles().get( "bug.FlexPMD141a.mxml" );
+      bug233a = ( IMxmlFile ) getTestFiles().get( "bug.FlexPMD233a.mxml" );
+      bug233b = ( IMxmlFile ) getTestFiles().get( "bug.FlexPMD233b.mxml" );
+      iterationsList = ( IMxmlFile ) getTestFiles().get( "com.adobe.ac.ncss.mxml.IterationsList.mxml" );
+      nestedComponent = ( IMxmlFile ) getTestFiles().get( "com.adobe.ac.ncss.mxml.NestedComponent.mxml" );
+      deleteRenderer = ( IMxmlFile ) getTestFiles().get( "DeleteButtonRenderer.mxml" );
+   }
+
+   @Test
+   public void testCommentTags()
+   {
+      assertEquals( "<!--",
+                    iterationsList.getCommentOpeningTag() );
+      assertEquals( "-->",
+                    iterationsList.getCommentClosingTag() );
+   }
+
+   @Test
+   public void testFlexPMD141()
+   {
+      final String[] lines = bug141.getScriptBlock();
+
+      assertEquals( "package bug{",
+                    lines[ 0 ] );
+      assertEquals( "class FlexPMD141a{",
+                    lines[ 1 ] );
+      assertEquals( Integer.valueOf( 32 ),
+                    Integer.valueOf( lines.length ) );
+      assertEquals( "",
+                    lines[ 22 ] );
+      assertEquals( "",
+                    lines[ 23 ] );
+      assertEquals( "",
+                    lines[ 24 ] );
+      assertEquals( "private var object:List = new List();",
+                    lines[ 25 ].trim() );
+      assertEquals( "}}",
+                    lines[ lines.length - 1 ] );
+   }
+
+   @Test
+   public void testFlexPMD233()
+   {
+      final String[] lines = bug233a.getScriptBlock();
+
+      Assert.assertEquals( "",
+                           lines[ 47 ] );
+
+      Assert.assertEquals( 80,
+                           bug233b.getActualScriptBlock().length );
+   }
+
+   @Test
+   public void testGetActionScriptScriptBlock()
+   {
+      final String[] deleteRendererLines = deleteRenderer.getScriptBlock();
+
+      assertEquals( "package {",
+                    deleteRendererLines[ 0 ] );
+      assertEquals( "       [Event(name=\"ruleRemoved\", type=\"flash.events.Event\")]",
+                    deleteRendererLines[ 29 ] );
+      assertEquals( "class DeleteButtonRenderer{",
+                    deleteRendererLines[ 30 ] );
+      assertEquals( Integer.valueOf( 101 ),
+                    Integer.valueOf( deleteRendererLines.length ) );
+      assertEquals( "            import com.adobe.ac.pmd.model.Rule;",
+                    deleteRendererLines[ 35 ] );
+      assertEquals( "}}",
+                    deleteRendererLines[ deleteRendererLines.length - 1 ] );
+   }
+
+   @Test
+   public void testGetMxmlScriptBlock()
+   {
+      final String[] iterationsListLines = iterationsList.getScriptBlock();
+
+      assertEquals( "package com.adobe.ac.ncss.mxml{",
+                    iterationsListLines[ 0 ] );
+      assertEquals( "class IterationsList{",
+                    iterationsListLines[ 1 ] );
+      assertEquals( "         import com.adobe.ac.anthology.model.object.IterationModelLocator;",
+                    iterationsListLines[ 26 ] );
+      assertEquals( "}}",
+                    iterationsListLines[ iterationsListLines.length - 1 ] );
+      assertEquals( Integer.valueOf( 90 ),
+                    Integer.valueOf( iterationsListLines.length ) );
+   }
+
+   @Test
+   public void testGetMxmlScriptBlock2()
+   {
+      final String[] nestedLines = nestedComponent.getScriptBlock();
+
+      assertEquals( "package com.adobe.ac.ncss.mxml{",
+                    nestedLines[ 0 ] );
+      assertEquals( "class NestedComponent{",
+                    nestedLines[ 1 ] );
+      assertEquals( Integer.valueOf( 43 ),
+                    Integer.valueOf( nestedLines.length ) );
+      assertEquals( "}}",
+                    nestedLines[ nestedLines.length - 1 ] );
+   }
+
+   @Test
+   public void testScriptBlockLines()
+   {
+      assertEquals( Integer.valueOf( 26 ),
+                    Integer.valueOf( iterationsList.getBeginningScriptBlock() ) );
+      assertEquals( Integer.valueOf( 80 ),
+                    Integer.valueOf( iterationsList.getEndingScriptBlock() ) );
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/AbstractFlexFileTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/AbstractFlexFileTest.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/AbstractFlexFileTest.java
new file mode 100644
index 0000000..97715fe
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/AbstractFlexFileTest.java
@@ -0,0 +1,157 @@
+/*
+ * 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 com.adobe.ac.pmd.files.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.adobe.ac.pmd.FlexPmdTestBase;
+import com.adobe.ac.pmd.files.IAs3File;
+import com.adobe.ac.pmd.files.IMxmlFile;
+
+public class AbstractFlexFileTest extends FlexPmdTestBase
+{
+   private IAs3File  as3;
+   private IMxmlFile mainMxml;
+   private IMxmlFile mxml;
+
+   @Before
+   public void init() throws FileNotFoundException,
+                     URISyntaxException
+   {
+      as3 = ( IAs3File ) getTestFiles().get( "AbstractRowData.as" );
+      mainMxml = ( IMxmlFile ) getTestFiles().get( "Main.mxml" );
+      mxml = ( IMxmlFile ) getTestFiles().get( "com.adobe.ac.ncss.mxml.IterationsList.mxml" );
+   }
+
+   @Test
+   public void testContains()
+   {
+      assertTrue( as3.contains( "logger",
+                                buildSetContaining( 0 ) ) );
+      assertFalse( as3.contains( "loggerr",
+                                 buildSetContaining( 0 ) ) );
+      assertFalse( as3.contains( "addEventListener",
+                                 buildSetContaining( 97,
+                                                     102 ) ) );
+   }
+
+   @Test
+   public void testEquals()
+   {
+      Assert.assertTrue( as3.equals( as3 ) );
+      Assert.assertFalse( mxml.equals( as3 ) );
+      Assert.assertFalse( as3.equals( mxml ) );
+   }
+
+   @Test
+   public void testFlexPMD152()
+   {
+      Assert.assertEquals( "com.something",
+                           AbstractFlexFile.computePackageName( "C:/somePath/ProjectName/com/something/Test.mxml",
+                                                                "C:/somePath/ProjectName",
+                                                                "Test.mxml",
+                                                                "/" ) );
+
+      Assert.assertEquals( "com.something",
+                           AbstractFlexFile.computePackageName( "C:/somePath/ProjectName/com/something/Test.mxml",
+                                                                "C:/somePath/ProjectName/",
+                                                                "Test.mxml",
+                                                                "/" ) );
+   }
+
+   @Test
+   public void testGetClassName()
+   {
+      assertEquals( "AbstractRowData.as",
+                    as3.getClassName() );
+      assertEquals( "IterationsList.mxml",
+                    mxml.getClassName() );
+   }
+
+   @Test
+   public void testGetFileName()
+   {
+      Assert.assertEquals( "AbstractRowData.as",
+                           as3.getFilename() );
+   }
+
+   @Test
+   public void testGetFilePath()
+   {
+      assertNotNull( as3.getFilePath() );
+      assertNotNull( mxml.getFilePath() );
+      assertNotNull( mainMxml.getFilePath() );
+   }
+
+   @Test
+   public void testGetPackageName()
+   {
+      assertEquals( "",
+                    as3.getPackageName() );
+      assertEquals( "com.adobe.ac.ncss.mxml",
+                    mxml.getPackageName() );
+   }
+
+   @Test
+   public void testGetPath()
+   {
+      assertEquals( "AbstractRowData.as",
+                    as3.getFullyQualifiedName() );
+      assertEquals( "com.adobe.ac.ncss.mxml.IterationsList.mxml",
+                    mxml.getFullyQualifiedName() );
+   }
+
+   @Test
+   public void testIsMainApplication()
+   {
+      assertFalse( as3.isMainApplication() );
+      assertFalse( mxml.isMainApplication() );
+      assertTrue( mainMxml.isMainApplication() );
+   }
+
+   @Test
+   public void testIsMxml()
+   {
+      assertFalse( as3.isMxml() );
+      assertTrue( mxml.isMxml() );
+   }
+
+   private Set< Integer > buildSetContaining( final int... lines )
+   {
+
+      final HashSet< Integer > hashSet = new HashSet< Integer >();
+
+      for ( final int line : lines )
+      {
+         hashSet.add( line );
+      }
+      return hashSet;
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/As3FileTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/As3FileTest.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/As3FileTest.java
new file mode 100644
index 0000000..c783e55
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/As3FileTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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 com.adobe.ac.pmd.files.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.adobe.ac.pmd.FlexPmdTestBase;
+import com.adobe.ac.pmd.files.IAs3File;
+
+public class As3FileTest extends FlexPmdTestBase
+{
+   private IAs3File data;
+
+   @Before
+   public void setUp()
+   {
+      data = ( IAs3File ) getTestFiles().get( "AbstractRowData.as" );
+   }
+
+   @Test
+   public void testGetCommentClosingTag()
+   {
+      assertEquals( "*/",
+                    data.getCommentClosingTag() );
+   }
+
+   @Test
+   public void testGetCommentOpeningTag()
+   {
+      assertEquals( "/*",
+                    data.getCommentOpeningTag() );
+   }
+
+   @Test
+   public void testGetLineAt()
+   {
+      assertEquals( "      public const logger : ILogger;",
+                    data.getLineAt( 33 ) );
+   }
+
+   @Test
+   public void testGetSingleLineComment()
+   {
+      assertEquals( "//",
+                    data.getSingleLineComment() );
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/FileUtilsTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/FileUtilsTest.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/FileUtilsTest.java
new file mode 100644
index 0000000..4c26497
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/FileUtilsTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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 com.adobe.ac.pmd.files.impl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Assert;
+import net.sourceforge.pmd.PMDException;
+
+import org.junit.Test;
+
+import com.adobe.ac.pmd.FlexPmdTestBase;
+import com.adobe.ac.pmd.files.IFlexFile;
+
+public class FileUtilsTest extends FlexPmdTestBase
+{
+   @Test
+   public void testComputeFilesList() throws PMDException
+   {
+      Map< String, IFlexFile > files;
+      files = FileUtils.computeFilesList( getTestDirectory(),
+                                          null,
+                                          "",
+                                          null );
+
+      Assert.assertEquals( 98,
+                           files.size() );
+
+      final List< String > excludePatterns = new ArrayList< String >();
+      excludePatterns.add( "bug" );
+      files = FileUtils.computeFilesList( getTestDirectory(),
+                                          null,
+                                          "",
+                                          excludePatterns );
+
+      Assert.assertEquals( 82,
+                           files.size() );
+   }
+
+   @Test
+   public void testComputeFilesListWithEmptySourceFolder() throws PMDException
+   {
+      final Map< String, IFlexFile > files = FileUtils.computeFilesList( new File( getTestDirectory().getAbsolutePath()
+                                                                               + "/" + "empty/emptyFolder" ),
+                                                                         null,
+                                                                         "",
+                                                                         null );
+
+      Assert.assertEquals( 1,
+                           files.size() );
+   }
+
+   @Test
+   public void testComputeFilesListWithoutSource()
+   {
+      try
+      {
+         FileUtils.computeFilesList( null,
+                                     null,
+                                     "",
+                                     null );
+         Assert.fail();
+      }
+      catch ( final PMDException e )
+      {
+         Assert.assertEquals( "sourceDirectory is not specified",
+                              e.getMessage() );
+      }
+   }
+
+   @Test
+   public void testComputeFilesListWithSourceFile() throws PMDException
+   {
+      final Map< String, IFlexFile > files = FileUtils.computeFilesList( new File( getTestFiles().get( "AbstractRowData.as" )
+                                                                                                 .getFilePath() ),
+                                                                         null,
+                                                                         "",
+                                                                         null );
+
+      Assert.assertEquals( 1,
+                           files.size() );
+   }
+
+   @Test
+   public void testComputeFilesListWithSourceList() throws PMDException
+   {
+      final List< File > sourceList = new ArrayList< File >();
+
+      sourceList.add( getTestDirectory() );
+      final Map< String, IFlexFile > files = FileUtils.computeFilesList( null,
+                                                                         sourceList,
+                                                                         "",
+                                                                         null );
+
+      Assert.assertEquals( 98,
+                           files.size() );
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/FlexFileFactoryTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/FlexFileFactoryTest.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/FlexFileFactoryTest.java
new file mode 100644
index 0000000..842f3e6
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/FlexFileFactoryTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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 com.adobe.ac.pmd.files.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.adobe.ac.pmd.FlexPmdTestBase;
+import com.adobe.ac.pmd.files.IAs3File;
+import com.adobe.ac.pmd.files.IFlexFile;
+import com.adobe.ac.pmd.files.IMxmlFile;
+
+public class FlexFileFactoryTest extends FlexPmdTestBase
+{
+   @Test
+   public void testCreate()
+   {
+      assertTrue( "",
+                  create( new File( getTestFiles().get( "AbstractRowData.as" ).getFilePath() ),
+                          new File( "" ) ) instanceof IAs3File );
+      assertTrue( "",
+                  create( new File( getTestFiles().get( "Main.mxml" ).getFilePath() ),
+                          new File( "" ) ) instanceof IMxmlFile );
+      assertTrue( "",
+                  create( new File( getTestFiles().get( "com.adobe.ac.ncss.mxml.IterationsList.mxml" )
+                                                  .getFilePath() ),
+                          new File( "" ) ) instanceof IMxmlFile );
+   }
+
+   private IFlexFile create( final File sourceFile,
+                             final File sourceDirectory )
+   {
+      IFlexFile file;
+
+      if ( sourceFile.getName().endsWith( ".as" ) )
+      {
+         file = new As3File( sourceFile, sourceDirectory );
+      }
+      else
+      {
+         file = new MxmlFile( sourceFile, sourceDirectory );
+      }
+
+      return file;
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/MxmlFileTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/MxmlFileTest.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/MxmlFileTest.java
new file mode 100644
index 0000000..e51bc29
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/com/adobe/ac/pmd/files/impl/MxmlFileTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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 com.adobe.ac.pmd.files.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.adobe.ac.pmd.FlexPmdTestBase;
+import com.adobe.ac.pmd.files.IMxmlFile;
+
+public class MxmlFileTest extends FlexPmdTestBase
+{
+   private IMxmlFile data;
+
+   @Before
+   public void setUp()
+   {
+      data = ( IMxmlFile ) getTestFiles().get( "Main.mxml" );
+   }
+
+   @Test
+   public void testGetActualScriptBlock()
+   {
+      assertEquals( Integer.valueOf( 4 ),
+                    Integer.valueOf( data.getActualScriptBlock().length ) );
+   }
+
+   @Test
+   public void testGetSingleLineComment()
+   {
+      assertEquals( "<!--",
+                    data.getSingleLineComment() );
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/net/sourceforge/pmd/PMDExceptionTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/net/sourceforge/pmd/PMDExceptionTest.java b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/net/sourceforge/pmd/PMDExceptionTest.java
new file mode 100644
index 0000000..550d982
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-files/src/test/java/net/sourceforge/pmd/PMDExceptionTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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 net.sourceforge.pmd;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class PMDExceptionTest
+{
+   @SuppressWarnings("deprecation")
+   @Test
+   public void testGetReason()
+   {
+      final Exception reason = new Exception();
+      final PMDException exception = new PMDException( "message", reason );
+
+      assertEquals( reason,
+                    exception.getReason() );
+   }
+
+   @Test
+   public void testPMDExceptionString()
+   {
+      assertEquals( "message",
+                    new PMDException( "message" ).getMessage() );
+   }
+
+   @Test
+   public void testPMDExceptionStringException()
+   {
+      final PMDException exception = new PMDException( "message", new Exception() );
+
+      assertEquals( "message",
+                    exception.getMessage() );
+   }
+
+   @Test
+   public void testSetSeverity()
+   {
+      final PMDException exception = new PMDException( "message" );
+
+      exception.setSeverity( 1 );
+      assertEquals( Integer.valueOf( 1 ),
+                    Integer.valueOf( exception.getSeverity() ) );
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/pom.xml b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/pom.xml
new file mode 100644
index 0000000..049ef0c
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/pom.xml
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+  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.
+
+-->
+<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>
+
+    <parent>
+        <groupId>org.apache.flex.pmd</groupId>
+        <artifactId>flex-pmd-java</artifactId>
+        <version>1.3-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>flex-pmd-maven-plugin</artifactId>
+    <packaging>maven-plugin</packaging>
+
+    <name>Adobe Flex PMD Maven plugin</name>
+
+    <build>
+        <testResources>
+            <testResource>
+                <directory>${project.build.directory}/test/generated-resources</directory>
+            </testResource>
+            <testResource>
+                <directory>src/test/resources</directory>
+            </testResource>
+        </testResources>
+
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>unpack-test-resources</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>unpack-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <includeGroupIds>${project.groupId}</includeGroupIds>
+                            <includes>**/*.as,**/*.mxml</includes>
+                            <outputDirectory>${project.build.directory}/test/generated-resources</outputDirectory>
+                            <excludeTransitive>true</excludeTransitive>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>${project.parent.groupId}</groupId>
+            <artifactId>flex-pmd-test-resources</artifactId>
+            <version>${project.parent.version}</version>
+            <type>zip</type>
+            <classifier>resources</classifier>
+            <scope>provided</scope>
+            <optional>false</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <version>${maven-plugin-api.version}</version>
+            <type>jar</type>
+            <optional>false</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven.reporting</groupId>
+            <artifactId>maven-reporting-impl</artifactId>
+            <version>${maven-reporting-impl.version}</version>
+            <type>jar</type>
+            <optional>false</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-pmd-plugin</artifactId>
+            <version>${maven-pmd-plugin.version}</version>
+            <type>maven-plugin</type>
+            <optional>false</optional>
+        </dependency>
+        <dependency>
+            <groupId>${project.parent.groupId}</groupId>
+            <artifactId>flex-pmd-core</artifactId>
+            <version>${project.parent.version}</version>
+            <type>jar</type>
+            <optional>false</optional>
+        </dependency>
+        <dependency>
+            <groupId>${project.parent.groupId}</groupId>
+            <artifactId>flex-pmd-ruleset</artifactId>
+            <version>${project.parent.version}</version>
+            <type>jar</type>
+            <optional>false</optional>
+        </dependency>
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/AbstractFlexPmdMojo.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/AbstractFlexPmdMojo.java b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/AbstractFlexPmdMojo.java
new file mode 100644
index 0000000..df314e1
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/AbstractFlexPmdMojo.java
@@ -0,0 +1,362 @@
+/*
+ * 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 com.adobe.ac.pmd.maven;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.MavenReportException;
+import org.codehaus.doxia.site.renderer.SiteRenderer;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import com.adobe.ac.pmd.FlexPmdParameters;
+import com.adobe.ac.pmd.FlexPmdViolations;
+import com.adobe.ac.pmd.LoggerUtils;
+import com.adobe.ac.pmd.engines.AbstractFlexPmdEngine;
+import com.adobe.ac.pmd.engines.FlexPmdXmlEngine;
+import com.adobe.ac.pmd.engines.PmdEngineUtils;
+
+abstract class AbstractFlexPmdMojo extends AbstractMavenReport
+{
+   protected static final Logger LOGGER      = Logger.getLogger( AbstractFlexPmdMojo.class.getName() );
+
+   private static final String   OUTPUT_NAME = "flexpmd";
+
+   protected static ResourceBundle getBundle( final Locale locale )
+   {
+      return ResourceBundle.getBundle( "flexPmd",
+                                       locale,
+                                       FlexPmdReportMojo.class.getClassLoader() ); // NOPMD
+   }
+
+   /**
+    * Location of the file.
+    * 
+    * @parameter expression="${flexpmd.excludePackage}"
+    */
+   private String       excludePackage = "";
+
+   /**
+    * Build fails if an violation error occurs.
+    * 
+    * @parameter expression="${flexpmd.failOnError}"
+    */
+   private boolean      failOnError;
+
+   /**
+    * Build fails if an violation error occurs.
+    * 
+    * @parameter expression="${flexpmd.failOnRuleViolation}"
+    */
+   private boolean      failOnRuleViolation;
+
+   /**
+    * Location of the file.
+    * 
+    * @parameter expression="${project.build.directory}"
+    * @required
+    */
+   private File         outputDirectory;
+
+   /**
+    * @parameter expression="${project}"
+    * @required
+    * @readonly
+    */
+   private MavenProject project;
+
+   /**
+    * Location of the file.
+    * 
+    * @parameter expression="${flexpmd.ruleset}"
+    */
+   private File         ruleSet;
+
+   /**
+    * @parameter 
+    *            expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
+    * @required
+    * @readonly
+    */
+   private SiteRenderer siteRenderer;
+
+   /**
+    * Specifies the location of the source files to be used.
+    * 
+    * @parameter expression="${project.build.sourceDirectory}"
+    * @required
+    */
+   private File         sourceDirectory;
+
+   /**
+    * URL of the file
+    * 
+    * @parameter expression="${flexpmd.url}"
+    */
+   private URL          url;
+
+   public AbstractFlexPmdMojo()
+   {
+      super();
+      excludePackage = "";
+   }
+
+   public AbstractFlexPmdMojo( final MavenProject projectToBeSet,
+                               final FlexPmdParameters parameters )
+   {
+      this();
+
+      project = projectToBeSet;
+      outputDirectory = parameters.getOutputDirectory();
+      ruleSet = parameters.getRuleSet();
+      sourceDirectory = parameters.getSource();
+      failOnError = parameters.isFailOnError();
+      failOnRuleViolation = parameters.isFailOnRuleViolation();
+      excludePackage = parameters.getExcludePackage();
+   }
+
+   public final String getDescription( final Locale locale )
+   {
+      return getBundle( locale ).getString( "report.flexPmd.description" );
+   }
+
+   public final String getName( final Locale locale )
+   {
+      return getBundle( locale ).getString( "report.flexPmd.name" );
+   }
+
+   public final String getOutputName()
+   {
+      return OUTPUT_NAME;
+   }
+
+   @Override
+   protected final void executeReport( final Locale locale ) throws MavenReportException
+   {
+      new LoggerUtils().loadConfiguration();
+      getLog().info( "FlexPmdMojo starts" );
+      getLog().info( "   failOnError     "
+            + failOnError );
+      getLog().info( "   ruleSet         "
+            + ruleSet );
+      getLog().info( "   sourceDirectory "
+            + sourceDirectory );
+      getLog().info( "   ruleSetURL      "
+            + url );
+      try
+      {
+         final AbstractFlexPmdEngine engine = new FlexPmdXmlEngine( new FlexPmdParameters( excludePackage,
+                                                                                           failOnError,
+                                                                                           failOnRuleViolation,
+                                                                                           outputDirectory,
+                                                                                           getRuleSet(),
+                                                                                           sourceDirectory ) );
+         final FlexPmdViolations violations = new FlexPmdViolations();
+         engine.executeReport( violations );
+
+         onXmlReportExecuted( violations,
+                              locale );
+      }
+      catch ( final Exception e )
+      {
+         throw new MavenReportException( "A system exception has been thrown", e );
+      }
+   }
+
+   protected final String getExcludePackage()
+   {
+      return excludePackage;
+   }
+
+   @Override
+   protected final String getOutputDirectory()
+   {
+      return outputDirectory.getAbsolutePath();
+   }
+
+   protected final File getOutputDirectoryFile()
+   {
+      return outputDirectory;
+   }
+
+   @Override
+   protected final MavenProject getProject()
+   {
+      return project;
+   }
+
+   protected final File getRuleSet()
+   {
+      if ( ruleSet == null )
+      {
+         try
+         {
+            getRulesetFromURL();
+         }
+         catch ( final IOException ioe )
+         {
+            throw new RuntimeException( "Could not get ruleset from URL", ioe );
+         }
+         catch ( final Exception e )
+         {
+            // if this goes wrong, we're experiencing an unrecoverable
+            // error, so we'll fall back on the default rules
+         }
+      }
+      return ruleSet;
+   }
+
+   @Override
+   protected final SiteRenderer getSiteRenderer()
+   {
+      return siteRenderer;
+   }
+
+   protected final File getSourceDirectory()
+   {
+      return sourceDirectory;
+   }
+
+   protected void onXmlReportExecuted( final FlexPmdViolations violations,
+                                       final Locale locale ) throws MavenReportException
+   {
+      if ( failOnError )
+      {
+         final String message = PmdEngineUtils.findFirstViolationError( violations );
+
+         if ( message.length() > 0 )
+         {
+            throw new MavenReportException( message );
+         }
+      }
+      if ( failOnRuleViolation
+            && !violations.getViolations().isEmpty() )
+      {
+         throw new MavenReportException( "At least one violation has been found" );
+      }
+   }
+
+   protected final void setSiteRenderer( final SiteRenderer siteRendererToBeSet ) // NO_UCD
+   {
+      this.siteRenderer = siteRendererToBeSet;
+   }
+
+   /**
+    * @throws ParserConfigurationException
+    * @throws SAXException
+    * @throws SAXException
+    * @throws TransformerException
+    * @throws TransformerFactoryConfigurationError
+    * @throws IOException
+    */
+   private void getRulesetFromURL() throws ParserConfigurationException,
+                                   SAXException,
+                                   TransformerFactoryConfigurationError,
+                                   TransformerException,
+                                   IOException
+   {
+      getLog().info( "getting RuleSet from URL" );
+      if ( url == null )
+      {
+         getLog().info( "Ruleset URL is not set" );
+         return;
+      }
+      ruleSet = File.createTempFile( "pmdRuleset",
+                                     "" );
+
+      final DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+
+      try
+      {
+         final Document pmdRules = db.parse( url.toExternalForm() );
+         writeToFile( pmdRules,
+                      ruleSet );
+      }
+      catch ( final SAXException sax )
+      {
+         saveUTF8SafeXML();
+      }
+   }
+
+   private void saveUTF8SafeXML() throws IOException,
+                                 FileNotFoundException
+   {
+      final InputStream inputstream = url.openStream();
+      final OutputStream outputstream = new FileOutputStream( ruleSet );
+      int thisByteAsInt;
+      while ( ( thisByteAsInt = inputstream.read() ) != -1 )
+      {
+         outputstream.write( stripNonValidXMLCharacters( ( byte ) thisByteAsInt ) );
+
+      }
+      inputstream.close();
+      outputstream.flush();
+      outputstream.close();
+   }
+
+   private byte stripNonValidXMLCharacters( final byte in )
+   {
+      byte current; // Used to reference the current character.
+
+      current = in;
+      if ( current == 0x9
+            || current == 0xA || current == 0xD || current >= 0x20 && current <= 0xD7FF || current >= 0xE000
+            && current <= 0xFFFD || current >= 0x10000 && current <= 0x10FFFF )
+      {
+         return current;
+      }
+      return '\n';
+   }
+
+   private void writeToFile( final Document pmdRules,
+                             final File ruleSet ) throws TransformerFactoryConfigurationError,
+                                                 IOException,
+                                                 TransformerException
+   {
+      final Transformer transformer = TransformerFactory.newInstance().newTransformer();
+      transformer.setOutputProperty( OutputKeys.INDENT,
+                                     "yes" );
+      final StreamResult result = new StreamResult( new FileWriter( ruleSet ) );
+      final DOMSource source = new DOMSource( pmdRules );
+      transformer.transform( source,
+                             result );
+
+   }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdHtmlEngine.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdHtmlEngine.java b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdHtmlEngine.java
new file mode 100644
index 0000000..33715fa
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdHtmlEngine.java
@@ -0,0 +1,125 @@
+/*
+ * 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 com.adobe.ac.pmd.maven;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import net.sourceforge.pmd.PMDException;
+import net.sourceforge.pmd.Report;
+import net.sourceforge.pmd.RuleContext;
+import net.sourceforge.pmd.renderers.HTMLRenderer;
+
+import org.apache.maven.plugin.pmd.PmdFileInfo;
+import org.apache.maven.plugin.pmd.PmdReportListener;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.doxia.sink.Sink;
+
+import com.adobe.ac.pmd.FlexPmdParameters;
+import com.adobe.ac.pmd.FlexPmdViolations;
+import com.adobe.ac.pmd.IFlexViolation;
+import com.adobe.ac.pmd.engines.AbstractFlexPmdEngine;
+import com.adobe.ac.pmd.engines.FlexPMDFormat;
+import com.adobe.ac.pmd.files.IFlexFile;
+
+class FlexPmdHtmlEngine extends AbstractFlexPmdEngine
+{
+   private final boolean        aggregate;
+   private final ResourceBundle bundle;
+   private final MavenProject   project;
+   private final Sink           sink;
+
+   protected FlexPmdHtmlEngine( final Sink sinkToBeSet,
+                                final ResourceBundle bundleToBeSet,
+                                final boolean aggregateToBeSet,
+                                final MavenProject projectToBeSet,
+                                final FlexPmdParameters parameters )
+   {
+      super( parameters );
+
+      sink = sinkToBeSet;
+      bundle = bundleToBeSet;
+      aggregate = aggregateToBeSet;
+      project = projectToBeSet;
+   }
+
+   @Override
+   protected final void writeReport( final FlexPmdViolations pmd ) throws PMDException
+   {
+      writeReport( getOutputDirectory(),
+                   computeReport( pmd ) );
+   }
+
+   private Report computeReport( final FlexPmdViolations pmd )
+   {
+      final Report report = new Report();
+      final RuleContext ruleContext = new RuleContext();
+      final PmdReportListener reportSink = new PmdReportListener( sink, bundle, aggregate );
+
+      report.addListener( reportSink );
+      ruleContext.setReport( report );
+      reportSink.beginDocument();
+      report.start();
+
+      for ( final IFlexFile file : pmd.getViolations().keySet() )
+      {
+         final File javaFile = new File( file.getFilePath() ); // NOPMD
+         final List< IFlexViolation > violations = pmd.getViolations().get( file );
+
+         reportSink.beginFile( javaFile,
+                               new PmdFileInfo( project, javaFile.getParentFile(), "" ) ); // NOPMD
+         ruleContext.setSourceCodeFilename( file.getPackageName()
+               + "." + file.getClassName() );
+
+         for ( final IFlexViolation violation : violations )
+         {
+            report.addRuleViolation( violation );
+            reportSink.ruleViolationAdded( violation );
+         }
+         reportSink.endFile( javaFile );
+      }
+
+      reportSink.endDocument();
+      report.end();
+
+      return report;
+   }
+
+   private void writeReport( final File outputDirectory,
+                             final Report report ) throws PMDException
+   {
+      final HTMLRenderer renderer = new HTMLRenderer( "", "" );
+
+      try
+      {
+         final FileWriter fileWriter = new FileWriter( new File( outputDirectory.getAbsolutePath()
+               + "/" + FlexPMDFormat.HTML.toString() ) );
+
+         renderer.render( fileWriter,
+                          report );
+         renderer.getWriter().flush();
+         fileWriter.close();
+      }
+      catch ( final IOException e )
+      {
+         throw new PMDException( "unable to write the HTML report", e );
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdMojo.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdMojo.java b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdMojo.java
new file mode 100644
index 0000000..f428eba
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdMojo.java
@@ -0,0 +1,40 @@
+/*
+ * 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 com.adobe.ac.pmd.maven;
+
+import org.apache.maven.project.MavenProject;
+
+import com.adobe.ac.pmd.FlexPmdParameters;
+
+/**
+ * @goal check
+ * @phase verify
+ * @execute goal="report"
+ */
+public class FlexPmdMojo extends AbstractFlexPmdMojo // NO_UCD
+{
+   public FlexPmdMojo()
+   {
+      super();
+   }
+
+   public FlexPmdMojo( final MavenProject projectToBeSet,
+                       final FlexPmdParameters parameters )
+   {
+      super( projectToBeSet, parameters );
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdReportMojo.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdReportMojo.java b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdReportMojo.java
new file mode 100644
index 0000000..dabed45
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/main/java/com/adobe/ac/pmd/maven/FlexPmdReportMojo.java
@@ -0,0 +1,82 @@
+/*
+ * 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 com.adobe.ac.pmd.maven;
+
+import java.util.Locale;
+
+import net.sourceforge.pmd.PMDException;
+
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.reporting.MavenReportException;
+
+import com.adobe.ac.pmd.FlexPmdParameters;
+import com.adobe.ac.pmd.FlexPmdViolations;
+
+/**
+ * @author xagnetti
+ * @goal report
+ * @phase site
+ */
+public class FlexPmdReportMojo extends AbstractFlexPmdMojo
+{
+   /**
+    * Specifies the location of the source files to be used.
+    * 
+    * @parameter default-value="false"
+    * @required
+    * @readonly
+    */
+   private boolean aggregate;
+
+   public FlexPmdReportMojo()
+   {
+      super();
+   }
+
+   public FlexPmdReportMojo( final MavenProject projectToBeSet,
+                             final FlexPmdParameters parameters )
+   {
+      super( projectToBeSet, parameters );
+   }
+
+   @Override
+   protected void onXmlReportExecuted( final FlexPmdViolations violations,
+                                       final Locale locale ) throws MavenReportException
+   {
+      super.onXmlReportExecuted( violations,
+                                 locale );
+
+      final FlexPmdParameters parameters = new FlexPmdParameters( getExcludePackage(),
+                                                                  getOutputDirectoryFile(),
+                                                                  getRuleSet(),
+                                                                  getSourceDirectory() );
+      final FlexPmdHtmlEngine flexPmdHtmlEngine = new FlexPmdHtmlEngine( getSink(),
+                                                                         getBundle( locale ),
+                                                                         aggregate,
+                                                                         getProject(),
+                                                                         parameters );
+
+      try
+      {
+         flexPmdHtmlEngine.executeReport( violations );
+      }
+      catch ( final PMDException e )
+      {
+         throw new MavenReportException( "An exception has been thrown while executing the HTML report", e );
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/test/java/com/adobe/ac/pmd/maven/FlexPmdMojoTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/test/java/com/adobe/ac/pmd/maven/FlexPmdMojoTest.java b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/test/java/com/adobe/ac/pmd/maven/FlexPmdMojoTest.java
new file mode 100644
index 0000000..39ff497
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/test/java/com/adobe/ac/pmd/maven/FlexPmdMojoTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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 com.adobe.ac.pmd.maven;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Locale;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.doxia.site.renderer.DefaultSiteRenderer;
+import org.junit.Test;
+
+import com.adobe.ac.pmd.FlexPmdParameters;
+import com.adobe.ac.pmd.FlexPmdTestBase;
+
+public class FlexPmdMojoTest extends FlexPmdTestBase
+{
+   @Test
+   public void testExecuteReport()
+   {
+      executeReport( false,
+                     null );
+   }
+
+   @Test
+   public void testExecuteReportFailOnError()
+   {
+      executeReport( true,
+                     null );
+   }
+
+   @Test
+   public void testExecuteReportWithCustomRuleset()
+   {
+      final URL resource = this.getClass().getResource( "/rulesets/broken_pmd.xml" );
+      executeReport( true,
+                     new File( resource.getFile() ) );
+   }
+
+   private void executeReport( final boolean failOnError,
+                               final File ruleset )
+   {
+      final File outputDirectoryToBeSet = new File( "target/pmd" );
+
+      outputDirectoryToBeSet.mkdirs();
+
+      final FlexPmdMojo mojo = new FlexPmdMojo( new MavenProjectStub(),
+                                                new FlexPmdParameters( "",
+                                                                       failOnError,
+                                                                       false,
+                                                                       outputDirectoryToBeSet,
+                                                                       ruleset,
+                                                                       getTestDirectory() ) );
+
+      mojo.setSiteRenderer( new DefaultSiteRenderer() );
+      assertNotNull( "",
+                     mojo.getName( Locale.ENGLISH ) );
+
+      try
+      {
+         mojo.execute();
+         if ( failOnError )
+         {
+            fail( "One expection should have been thrown" );
+         }
+      }
+      catch ( final MojoExecutionException e )
+      {
+         if ( !failOnError )
+         {
+            fail( "No expections should have been thrown" );
+         }
+      }
+      finally
+      {
+         new File( "target/pmd.xml" ).delete();
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/test/java/com/adobe/ac/pmd/maven/FlexPmdReportMojoTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/test/java/com/adobe/ac/pmd/maven/FlexPmdReportMojoTest.java b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/test/java/com/adobe/ac/pmd/maven/FlexPmdReportMojoTest.java
new file mode 100644
index 0000000..54767cf
--- /dev/null
+++ b/FlexPMD/flex-pmd-java/flex-pmd-maven-plugin/src/test/java/com/adobe/ac/pmd/maven/FlexPmdReportMojoTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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 com.adobe.ac.pmd.maven;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.doxia.site.renderer.DefaultSiteRenderer;
+import org.junit.Test;
+
+import com.adobe.ac.pmd.FlexPmdParameters;
+import com.adobe.ac.pmd.FlexPmdTestBase;
+
+public class FlexPmdReportMojoTest extends FlexPmdTestBase
+{
+   @Test
+   public void testExecuteReport() throws MojoExecutionException
+   {
+      new File( "target/site" ).mkdirs();
+      final FlexPmdReportMojo mojo = new FlexPmdReportMojo( new MavenProjectStub(),
+                                                            new FlexPmdParameters( "",
+                                                                                   false,
+                                                                                   false,
+                                                                                   new File( "target" ),
+                                                                                   null,
+                                                                                   getTestDirectory() ) );
+
+      mojo.setSiteRenderer( new DefaultSiteRenderer() );
+      assertNotNull( "",
+                     mojo.getName( Locale.ENGLISH ) );
+
+      mojo.execute();
+   }
+
+   @Test
+   public void testExecuteReportOnNoViolationsSourcePath() throws MojoExecutionException
+   {
+      new File( "target/site" ).mkdirs();
+      final FlexPmdReportMojo mojo = new FlexPmdReportMojo( new MavenProjectStub(),
+                                                            new FlexPmdParameters( "",
+                                                                                   false,
+                                                                                   false,
+                                                                                   new File( "target" ),
+                                                                                   null,
+                                                                                   new File( getTestDirectory().getAbsoluteFile()
+                                                                                         + "/fu" ) ) );
+
+      mojo.setSiteRenderer( new DefaultSiteRenderer() );
+      assertNotNull( "",
+                     mojo.getName( Locale.ENGLISH ) );
+
+      mojo.execute();
+   }
+
+   @Test
+   public void testGetBundle()
+   {
+      final Locale[] availableLocales = Locale.getAvailableLocales();
+      final ResourceBundle bundle = AbstractFlexPmdMojo.getBundle( availableLocales[ 0 ] );
+      final ResourceBundle englishBundle = AbstractFlexPmdMojo.getBundle( Locale.ENGLISH );
+
+      assertNotNull( "",
+                     bundle );
+      assertNotNull( "",
+                     englishBundle );
+   }
+}


Mime
View raw message