You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2006/10/01 22:07:35 UTC
svn commit: r451797 - in /myfaces/tobago/trunk: tobago-sandbox/pom.xml
tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java
Author: bommel
Date: Sun Oct 1 13:07:34 2006
New Revision: 451797
URL: http://svn.apache.org/viewvc?view=rev&rev=451797
Log:
[TOBAGO-140] generate faces-config from annotations
Modified:
myfaces/tobago/trunk/tobago-sandbox/pom.xml
myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java
Modified: myfaces/tobago/trunk/tobago-sandbox/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-sandbox/pom.xml?view=diff&rev=451797&r1=451796&r2=451797
==============================================================================
--- myfaces/tobago/trunk/tobago-sandbox/pom.xml (original)
+++ myfaces/tobago/trunk/tobago-sandbox/pom.xml Sun Oct 1 13:07:34 2006
@@ -78,7 +78,7 @@
<phase>process-classes</phase>
<configuration>
<targetFiles>
- <targetFile>target/classes/META-INF/faces-config.xml</targetFile>
+ <targetFile>target/generated-faces-config/faces-config.xml</targetFile>
</targetFiles>
<excludes>
<exclude>org/apache/myfaces/tobago/util/CommonsLoggingLogger.java</exclude>
@@ -90,14 +90,32 @@
<aptSourceRoot>${project.build.directory}/tobago-core-sources</aptSourceRoot>
</aptSourceRoots>
<resourceTargetPath>META-INF</resourceTargetPath>
- <generated>target/generated-tld</generated>
+ <generated>target/generated-faces-config</generated>
<factory>org.apache.myfaces.tobago.apt.FacesConfigAnnotationProcessorFactory</factory>
<!--<force>true</force>-->
<fork>true</fork>
<nocompile>true</nocompile>
<encoding>UTF-8</encoding>
- <A>sourceFacesConfig=src/main/faces-config/faces-config.xml,targetFacesConfig=target/classes/META-INF/faces-config.xml</A>
+ <A>sourceFacesConfig=src/main/faces-config/faces-config.xml,targetFacesConfig=faces-config.xml</A>
<!--verbose>true</verbose-->
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-faces-config</id>
+ <goals><goal>resources</goal></goals>
+ <phase>process-classes</phase>
+ <configuration>
+ <resources>
+ <resource>
+ <targetPath>META-INF</targetPath>
+ <directory>target/generated-faces-config</directory>
+ </resource>
+ </resources>
</configuration>
</execution>
</executions>
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java?view=diff&rev=451797&r1=451796&r2=451797
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java Sun Oct 1 13:07:34 2006
@@ -17,6 +17,7 @@
*/
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.apt.Filer;
import com.sun.mirror.declaration.ClassDeclaration;
import com.sun.mirror.declaration.InterfaceDeclaration;
import com.sun.mirror.declaration.MethodDeclaration;
@@ -26,6 +27,7 @@
import org.apache.myfaces.tobago.apt.annotation.Facet;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.commons.io.IOUtils;
import org.codehaus.plexus.util.FileUtils;
import org.jdom.Comment;
import org.jdom.DocType;
@@ -42,6 +44,8 @@
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
+import java.io.File;
+import java.io.Writer;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
@@ -90,9 +94,10 @@
targetFacesConfigFile = entry.getKey().substring(TARGET_FACES_CONFIG_KEY.length() + 3);
}
}
-
+ // TODO remove the foreach
for (PackageDeclaration packageDeclaration :getCollectedPackageDeclations()) {
Document document;
+ Writer writer = null;
try {
String content = FileUtils.fileRead( sourceFacesConfigFile );
SAXBuilder builder = new SAXBuilder();
@@ -108,6 +113,7 @@
XMLOutputter out = new XMLOutputter( format );
out.output( document.getRootElement(), w );
+ System.err.println(w.toString());
Element rootElement = document.getRootElement();
Namespace namespace = rootElement.getNamespace();
List<Element> components = rootElement.getChildren(COMPONENT, namespace);
@@ -149,17 +155,22 @@
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN",
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd"));
- StringWriter writer = new StringWriter();
+ writer =
+ getEnv().getFiler().createTextFile(Filer.Location.SOURCE_TREE, "", new File(targetFacesConfigFile), null);
+
+
format = Format.getPrettyFormat();
format.setLineSeparator(SEPERATOR);
out = new XMLOutputter( format );
out.output( document , writer );
- FileUtils.fileWrite(targetFacesConfigFile, writer.toString());
+
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
+ } finally {
+ IOUtils.closeQuietly(writer);
}
}
}
@@ -317,7 +328,7 @@
protected void addElement(ClassDeclaration decl, List<Element> components, Namespace namespace) throws IOException {
UIComponentTag componentTag = decl.getAnnotation(UIComponentTag.class);
- if (componentTag != null) {
+ if (componentTag != null && !componentTag.isComponentAlreadyDefined()) {
try {
Class<?> uiComponentClass = Class.forName(componentTag.uiComponent());
Element element = createElement(decl, componentTag, uiComponentClass, namespace);
@@ -335,7 +346,7 @@
protected void addElement(InterfaceDeclaration decl, List<Element> components, Namespace namespace) throws IOException {
UIComponentTag componentTag = decl.getAnnotation(UIComponentTag.class);
- if (componentTag != null) {
+ if (componentTag != null && !componentTag.isComponentAlreadyDefined()) {
try {
Class<?> uiComponentClass = Class.forName(componentTag.uiComponent());
Element element = createElement(decl, componentTag, uiComponentClass, namespace);