You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2016/04/22 19:24:56 UTC

[09/35] git commit: [flex-falcon] [refs/heads/feature/maven-migration-test] - factor out processFile so it can be used from Ant

factor out processFile so it can be used from Ant


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/f43f56f4
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/f43f56f4
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/f43f56f4

Branch: refs/heads/feature/maven-migration-test
Commit: f43f56f4e1959180646dcfd9f4acdad7d481c8a0
Parents: 2858873
Author: Alex Harui <ah...@apache.org>
Authored: Tue Apr 19 07:49:01 2016 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Fri Apr 22 09:02:56 2016 -0700

----------------------------------------------------------------------
 .../compiler/tools/annotate/AnnotateClass.java  | 113 +++++++++++++++++++
 .../tools/annotate/AnnotateClassesMojo.java     |  81 ++-----------
 2 files changed, 120 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f43f56f4/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClass.java
----------------------------------------------------------------------
diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClass.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClass.java
new file mode 100644
index 0000000..c3907c9
--- /dev/null
+++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClass.java
@@ -0,0 +1,113 @@
+/*
+ * 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.flex.compiler.tools.annotate;
+
+import java.io.*;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+public class AnnotateClass
+{
+    public static class AnnotateClassDeleteException extends Exception
+    {
+        public AnnotateClassDeleteException(String s)
+        {
+            super(s);
+        }
+    }
+    
+    public static class AnnotateClassRenameException extends Exception
+    {
+        public AnnotateClassRenameException(String s)
+        {
+            super(s);
+        }
+    }
+    
+    public static void processFile(File file, String annotation) throws AnnotateClassDeleteException, AnnotateClassRenameException {
+        if(!file.exists()) {
+            System.out.println("Missing file: " + file.getPath());
+            return;
+        }
+        try
+        {
+            // Prepare to read the file.
+            FileInputStream fileInputStream = new FileInputStream(file);
+            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
+            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
+
+            File tmpOutputFile = new File(file.getParentFile(), file.getName() + ".tmp");
+            FileOutputStream fileOutputStream = new FileOutputStream(tmpOutputFile);
+            PrintStream outputStream = new PrintStream(fileOutputStream);
+            try
+            {
+                // Read it line-by-line.
+                String line;
+                boolean alreadyAnnotated = false;
+                while ((line = bufferedReader.readLine()) != null)
+                {
+                    // If the class is already annotated, prevent us from doing it again.
+                    if (line.contains(annotation)) {
+                        alreadyAnnotated = true;
+                        System.out.println("Annotation " + annotation + " already added to class: " + file.getPath());
+                    }
+                    // If the line starts with "public class", output the annotation on the previous line.
+                    if (!alreadyAnnotated &&
+                            (line.startsWith("public class") || line.startsWith("public interface"))) {
+                        System.out.println("Adding " + annotation + " to class: " + file.getPath());
+                        outputStream.println(annotation);
+                    }
+                    outputStream.println(line);
+                }
+            }
+            finally
+            {
+                try {
+                    bufferedReader.close();
+                } catch(Exception e) {
+                    // Ignore.
+                }
+                try {
+                    outputStream.close();
+                } catch(Exception e) {
+                    // Ignore.
+                }
+                try {
+                    fileOutputStream.close();
+                } catch(Exception e) {
+                    // Ignore.
+                }
+            }
+
+            // Remove the original file.
+            if(!file.delete()) {
+                throw new AnnotateClassDeleteException("Error deleting original file at: " + file.getPath());
+            }
+
+            // Rename the temp file to the name of the original file.
+            if(!tmpOutputFile.renameTo(file)) {
+                throw new AnnotateClassRenameException("Error renaming the temp file from: " + tmpOutputFile.getPath() +
+                        " to: " + file.getPath());
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f43f56f4/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClassesMojo.java
----------------------------------------------------------------------
diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClassesMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClassesMojo.java
index 0f60762..eda26c7 100644
--- a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClassesMojo.java
+++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClassesMojo.java
@@ -60,83 +60,16 @@ public class AnnotateClassesMojo
         try {
             Set<File> candidates = scan.getIncludedSources(directory, null);
             for(File candidate : candidates) {
-                processFile(candidate);
-            }
-        } catch (InclusionScanException e) {
-            throw new MojoExecutionException("Error scanning files to be processed.", e);
-        }
-    }
-
-    private void processFile(File file) {
-        if(!file.exists()) {
-            System.out.println("Missing file: " + file.getPath());
-            return;
-        }
-        try
-        {
-            // Prepare to read the file.
-            FileInputStream fileInputStream = new FileInputStream(file);
-            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
-            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
-
-            File tmpOutputFile = new File(file.getParentFile(), file.getName() + ".tmp");
-            FileOutputStream fileOutputStream = new FileOutputStream(tmpOutputFile);
-            PrintStream outputStream = new PrintStream(fileOutputStream);
-            try
-            {
-                // Read it line-by-line.
-                String line;
-                boolean alreadyAnnotated = false;
-                while ((line = bufferedReader.readLine()) != null)
-                {
-                    // If the class is already annotated, prevent us from doing it again.
-                    if (line.contains(annotation)) {
-                        alreadyAnnotated = true;
-                        System.out.println("Annotation " + annotation + " already added to class: " + file.getPath());
-                    }
-                    // If the line starts with "public class", output the annotation on the previous line.
-                    if (!alreadyAnnotated &&
-                            (line.startsWith("public class") || line.startsWith("public interface"))) {
-                        System.out.println("Adding " + annotation + " to class: " + file.getPath());
-                        outputStream.println(annotation);
-                    }
-                    outputStream.println(line);
-                }
-            }
-            finally
-            {
-                try {
-                    bufferedReader.close();
-                } catch(Exception e) {
-                    // Ignore.
-                }
-                try {
-                    outputStream.close();
-                } catch(Exception e) {
-                    // Ignore.
-                }
                 try {
-                    fileOutputStream.close();
-                } catch(Exception e) {
-                    // Ignore.
+                    AnnotateClass.processFile(candidate, annotation);
+                } catch(AnnotateClass.AnnotateClassDeleteException e) {
+                    throw new MojoExecutionException(e.getMessage());
+                } catch(AnnotateClass.AnnotateClassRenameException e) {
+                    throw new MojoExecutionException(e.getMessage());
                 }
             }
-
-            // Remove the original file.
-            if(!file.delete()) {
-                throw new MojoExecutionException("Error deleting original file at: " + file.getPath());
-            }
-
-            // Rename the temp file to the name of the original file.
-            if(!tmpOutputFile.renameTo(file)) {
-                throw new MojoExecutionException("Error renaming the temp file from: " + tmpOutputFile.getPath() +
-                        " to: " + file.getPath());
-            }
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
+        } catch (InclusionScanException e) {
+            throw new MojoExecutionException("Error scanning files to be processed.", e);
         }
     }
-
 }