[seam-commits] Seam SVN: r13585 - in sandbox/encore: core/src/main/java/org/jboss/encore/grammar/java and 12 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Aug 9 18:07:23 EDT 2010


Author: lincolnthree
Date: 2010-08-09 18:07:22 -0400 (Mon, 09 Aug 2010)
New Revision: 13585

Added:
   sandbox/encore/core/src/test/java/org/jboss/encore/test/grammar/java/JavaClassCreationTest.java
   sandbox/encore/model/src/main/java/org/jboss/encore/model/ProjectModelException.java
   sandbox/encore/model/src/test/java/org/
   sandbox/encore/model/src/test/java/org/jboss/
   sandbox/encore/model/src/test/java/org/jboss/encore/
   sandbox/encore/model/src/test/java/org/jboss/encore/model/
   sandbox/encore/model/src/test/java/org/jboss/encore/model/test/
   sandbox/encore/model/src/test/java/org/jboss/encore/model/test/MavenJavaProjectTest.java
Removed:
   sandbox/encore/core/src/test/java/org/jboss/encore/grammar/
   sandbox/encore/src/main/java/org/
   sandbox/encore/src/test/java/org/
Modified:
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/Mutable.java
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/AnnotationTarget.java
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Field.java
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/FieldImpl.java
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ImportImpl.java
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java
   sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java
   sandbox/encore/model/src/main/java/org/jboss/encore/model/AbstractProject.java
   sandbox/encore/model/src/main/java/org/jboss/encore/model/MavenJavaProject.java
   sandbox/encore/model/src/main/java/org/jboss/encore/model/Project.java
Log:
Project Model in progress.
Updates to Java Parser API

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/Mutable.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/Mutable.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/Mutable.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -22,16 +22,19 @@
 package org.jboss.encore.grammar;
 
 /**
- * Represents an object that queues changes before making final modifications to a resource.
+ * Represents an object that queues changes before making final modifications to
+ * a resource.
  * 
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
  * 
  */
-public interface Mutable
+public interface Mutable<T>
 {
    /**
-    * Apply all changes made to this or other objects to which this may belong. (Apply all pending changes in the object
-    * graph.)
+    * Apply all changes made to this or other objects to which this may belong.
+    * (Apply all pending changes in the object graph.)
+    * 
+    * @return the instance of the updated root object.
     */
-   void applyChanges();
+   T applyChanges();
 }

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/AnnotationTarget.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/AnnotationTarget.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/AnnotationTarget.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -31,7 +31,7 @@
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
  * 
  */
-public interface AnnotationTarget<T> extends Internal, Mutable
+public interface AnnotationTarget<T> extends Internal, Mutable<T>
 {
    public abstract Annotation addAnnotation();
 

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Field.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Field.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Field.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -29,7 +29,7 @@
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
  * 
  */
-public interface Field extends Mutable, Internal, VisibilityScoped<Field>, AnnotationTarget<Field>
+public interface Field extends Mutable<Field>, Internal, VisibilityScoped<Field>, AnnotationTarget<Field>
 {
    String getName();
 

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -31,7 +31,7 @@
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
  * 
  */
-public interface JavaClass extends Internal, Mutable, Abstractable<JavaClass>, VisibilityScoped<JavaClass>, AnnotationTarget<JavaClass>
+public interface JavaClass extends Internal, Mutable<JavaClass>, Abstractable<JavaClass>, VisibilityScoped<JavaClass>, AnnotationTarget<JavaClass>
 {
    /*
     * Annotation modifiers

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -22,6 +22,9 @@
 
 package org.jboss.encore.grammar.java;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.InputStream;
 
 import org.jboss.encore.grammar.java.impl.JavaClassImpl;
@@ -42,8 +45,26 @@
       return new JavaClassImpl(data);
    }
 
-   public static JavaClassImpl parse(InputStream data)
+   public static JavaClass parse(InputStream data)
    {
       return new JavaClassImpl(data);
    }
+
+   public static JavaClass createClass()
+   {
+      return new JavaClassImpl();
+   }
+
+   public static JavaClass parse(File file)
+   {
+      try
+      {
+         FileInputStream stream = new FileInputStream(file);
+         return parse(stream);
+      }
+      catch (FileNotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
 }

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -29,7 +29,7 @@
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
  * 
  */
-public interface Method extends Internal, Mutable, Abstractable<Method>, VisibilityScoped<Method>, AnnotationTarget<Method>
+public interface Method extends Internal, Mutable<Method>, Abstractable<Method>, VisibilityScoped<Method>, AnnotationTarget<Method>
 {
    public String getBody();
 

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -329,12 +329,13 @@
    }
 
    @Override
-   public void applyChanges()
+   public Annotation applyChanges()
    {
       if (parent instanceof Mutable)
       {
          ((Mutable) parent).applyChanges();
       }
+      return this;
    }
 
    @Override

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/FieldImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/FieldImpl.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/FieldImpl.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -84,9 +84,10 @@
    }
 
    @Override
-   public void applyChanges()
+   public Field applyChanges()
    {
       parent.applyChanges();
+      return this;
    }
 
    @Override

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ImportImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ImportImpl.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ImportImpl.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -86,9 +86,10 @@
    }
 
    @Override
-   public void applyChanges()
+   public Import applyChanges()
    {
       parent.applyChanges();
+      return this;
    }
 
    @Override

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -96,6 +96,11 @@
       init(source);
    }
 
+   public JavaClassImpl()
+   {
+      this("public class JavaClass { }");
+   }
+
    private void init(final char[] source)
    {
       document = new Document(new String(source));
@@ -366,6 +371,10 @@
    @Override
    public JavaClass setPackage(String name)
    {
+      if (unit.getPackage() == null)
+      {
+         unit.setPackage(unit.getAST().newPackageDeclaration());
+      }
       unit.getPackage().setName(unit.getAST().newName(name));
       return this;
    }
@@ -482,7 +491,7 @@
    }
 
    @Override
-   public void applyChanges()
+   public JavaClass applyChanges()
    {
       try
       {
@@ -497,6 +506,8 @@
       {
          throw new RuntimeException(e);
       }
+
+      return this;
    }
 
    @Override
@@ -504,7 +515,7 @@
    {
       final int prime = 31;
       int result = 1;
-      result = prime * result + ((unit == null) ? 0 : unit.hashCode());
+      result = prime * result + ((toString() == null) ? 0 : unit.toString().hashCode());
       return result;
    }
 
@@ -523,16 +534,8 @@
       {
          return false;
       }
-      JavaClassImpl other = (JavaClassImpl) obj;
-      if (unit == null)
+      if (!this.toString().equals(obj.toString()))
       {
-         if (other.unit != null)
-         {
-            return false;
-         }
-      }
-      else if (!unit.equals(other.unit))
-      {
          return false;
       }
       return true;

Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -328,9 +328,10 @@
    }
 
    @Override
-   public void applyChanges()
+   public Method applyChanges()
    {
       parent.applyChanges();
+      return this;
    }
 
    @Override

Added: sandbox/encore/core/src/test/java/org/jboss/encore/test/grammar/java/JavaClassCreationTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/test/grammar/java/JavaClassCreationTest.java	                        (rev 0)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/test/grammar/java/JavaClassCreationTest.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.test.grammar.java;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.jboss.encore.grammar.java.JavaClass;
+import org.jboss.encore.grammar.java.JavaParser;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ */
+public class JavaClassCreationTest
+{
+
+   private static JavaClass jc;
+
+   @BeforeClass
+   public static void testCreateClass() throws Exception
+   {
+      jc = JavaParser.createClass();
+   }
+
+   @Test
+   public void testClassCreatesStub() throws Exception
+   {
+      assertEquals("JavaClass", jc.getName());
+      assertTrue(jc.isPublic());
+   }
+
+}

Modified: sandbox/encore/model/src/main/java/org/jboss/encore/model/AbstractProject.java
===================================================================
--- sandbox/encore/model/src/main/java/org/jboss/encore/model/AbstractProject.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/model/src/main/java/org/jboss/encore/model/AbstractProject.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -30,7 +30,6 @@
 import javax.inject.Inject;
 
 import org.jboss.encore.grammar.java.JavaClass;
-import org.jboss.encore.grammar.java.JavaParser;
 import org.jboss.encore.model.events.JavaFileCreated;
 
 /**
@@ -42,28 +41,65 @@
    @Inject
    Event<JavaFileCreated> event;
 
-   public File createJavaFile(final String path, final char[] data)
+   private File createJavaFile(File sourceFolder, final String classPackage, final String className, final char[] data)
    {
-      return createJavaFile(path, JavaParser.parse(data));
-   }
-
-   public File createJavaFile(final String path, JavaClass clazz)
-   {
       BufferedWriter writer = null;
       try
       {
-         File file = new File(path);
+         String pkg = getDefaultSourceFolder() + File.separator + classPackage.replaceAll("\\.", File.separator);
+
+         File file = new File(pkg + File.separator + className + ".java");
+
+         if (!file.mkdirs())
+         {
+            throw new IOException("Failed to create required directory structure for file: " + file);
+         }
+
+         file.delete();
+
+         if (!file.createNewFile())
+         {
+            throw new IOException("Failed to create file because it already exists: " + file);
+         }
+
          writer = new BufferedWriter(new FileWriter(file));
-         writer.write(clazz.toString());
+         writer.write(data);
          writer.close();
 
-         event.fire(new JavaFileCreated(file));
+         // event.fire(new JavaFileCreated(file));
          return file;
       }
       catch (IOException e)
       {
-         throw new RuntimeException(e);
+         throw new ProjectModelException(e);
       }
    }
 
+   private File createJavaFile(final String classPackage, final String className, String data)
+   {
+      return createJavaFile(getDefaultSourceFolder(), classPackage, className, data.toCharArray());
+   }
+
+   @Override
+   public File createJavaFile(JavaClass clazz)
+   {
+      return createJavaFile(clazz.getPackage(), clazz.getName(), clazz.toString());
+   }
+
+   @Override
+   public boolean delete(File file)
+   {
+      if (file.isDirectory())
+      {
+         for (File c : file.listFiles())
+         {
+            if (!delete(c))
+            {
+               throw new ProjectModelException("Could not delete file or folder: " + file);
+            }
+         }
+      }
+      return file.delete();
+   }
+
 }

Modified: sandbox/encore/model/src/main/java/org/jboss/encore/model/MavenJavaProject.java
===================================================================
--- sandbox/encore/model/src/main/java/org/jboss/encore/model/MavenJavaProject.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/model/src/main/java/org/jboss/encore/model/MavenJavaProject.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -21,6 +21,9 @@
  */
 package org.jboss.encore.model;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
@@ -28,5 +31,36 @@
  */
 public class MavenJavaProject extends AbstractProject
 {
+   private File projectRoot = null;
 
+   public MavenJavaProject(File directory)
+   {
+      if (!directory.isDirectory())
+      {
+         throw new ProjectModelException("Cannot load project from directory that does not exist.");
+      }
+      projectRoot = directory;
+   }
+
+   @Override
+   public List<File> getSourceFolders()
+   {
+      List<File> result = new ArrayList<File>();
+      result.add(getDefaultSourceFolder());
+      result.add(new File(getProjectRoot().getAbsolutePath() + "/src/test/java"));
+      return result;
+   }
+
+   @Override
+   public File getDefaultSourceFolder()
+   {
+      return new File(getProjectRoot().getAbsolutePath() + "/src/main/java");
+   }
+
+   @Override
+   public File getProjectRoot()
+   {
+      return projectRoot;
+   }
+
 }

Modified: sandbox/encore/model/src/main/java/org/jboss/encore/model/Project.java
===================================================================
--- sandbox/encore/model/src/main/java/org/jboss/encore/model/Project.java	2010-08-09 19:16:37 UTC (rev 13584)
+++ sandbox/encore/model/src/main/java/org/jboss/encore/model/Project.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -21,11 +21,24 @@
  */
 package org.jboss.encore.model;
 
+import java.io.File;
+import java.util.List;
 
+import org.jboss.encore.grammar.java.JavaClass;
+
 /**
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
  * 
  */
 public interface Project
 {
+   public File getProjectRoot();
+
+   public List<File> getSourceFolders();
+
+   public File getDefaultSourceFolder();
+
+   public File createJavaFile(JavaClass clazz);
+
+   public boolean delete(File file);
 }

Added: sandbox/encore/model/src/main/java/org/jboss/encore/model/ProjectModelException.java
===================================================================
--- sandbox/encore/model/src/main/java/org/jboss/encore/model/ProjectModelException.java	                        (rev 0)
+++ sandbox/encore/model/src/main/java/org/jboss/encore/model/ProjectModelException.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.model;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class ProjectModelException extends RuntimeException
+{
+   private static final long serialVersionUID = 9036061452674068890L;
+
+   public ProjectModelException()
+   {
+   }
+
+   public ProjectModelException(String message)
+   {
+      super(message);
+   }
+
+   public ProjectModelException(Throwable e)
+   {
+      super(e);
+   }
+
+   public ProjectModelException(String message, Throwable e)
+   {
+      super(message, e);
+   }
+
+}

Added: sandbox/encore/model/src/test/java/org/jboss/encore/model/test/MavenJavaProjectTest.java
===================================================================
--- sandbox/encore/model/src/test/java/org/jboss/encore/model/test/MavenJavaProjectTest.java	                        (rev 0)
+++ sandbox/encore/model/src/test/java/org/jboss/encore/model/test/MavenJavaProjectTest.java	2010-08-09 22:07:22 UTC (rev 13585)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.model.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.jboss.encore.grammar.java.JavaClass;
+import org.jboss.encore.grammar.java.JavaParser;
+import org.jboss.encore.model.MavenJavaProject;
+import org.jboss.encore.model.Project;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class MavenJavaProjectTest
+{
+   private static final String PKG = MavenJavaProjectTest.class.getSimpleName().toLowerCase();
+   private static File tempFolder;
+   private static Project project;
+
+   @BeforeClass
+   public static void before() throws IOException
+   {
+      tempFolder = File.createTempFile(PKG, null);
+      tempFolder.delete();
+      tempFolder.mkdirs();
+      project = new MavenJavaProject(tempFolder);
+   }
+
+   @AfterClass
+   public static void after()
+   {
+      if (tempFolder.exists())
+      {
+         assertTrue(project.delete(tempFolder));
+      }
+   }
+
+   @Test
+   public void testGetDefaultSourceDir() throws Exception
+   {
+      assertEquals(new File(project.getProjectRoot() + "/src/main/java/"), project.getDefaultSourceFolder());
+   }
+
+   @Test
+   public void testCreateJavaFile() throws Exception
+   {
+      String name = "JustCreated";
+      JavaClass clazz = JavaParser.createClass().setName(name).setPackage(PKG);
+      clazz.applyChanges();
+      File file = project.createJavaFile(clazz);
+      assertEquals(name + ".java", file.getName());
+
+      JavaClass result = JavaParser.parse(file);
+      assertEquals(name, result.getName());
+      assertEquals(PKG, result.getPackage());
+      assertTrue(project.delete(file));
+      assertEquals(clazz, result);
+   }
+}



More information about the seam-commits mailing list