Author: alexsmirnov
Date: 2010-02-01 20:17:30 -0500 (Mon, 01 Feb 2010)
New Revision: 16390
Added:
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/TaskFactoryTest.java
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/FileManager.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Logger.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/OutputFileManager.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/SourceFileManager.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptBuilder.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptModule.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CompilationTaskFactory.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/TaskFactoryImpl.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXB.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestRunner.java
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/RunnerTest.java
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/AnnotationProcessorTest.java
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java
Log:
Test Java compilation tasks.
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/FileManager.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/FileManager.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/FileManager.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -26,6 +26,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.Writer;
/**
* <p class="changed_added_4_0"></p>
@@ -38,7 +39,7 @@
public Iterable<File> getFiles();
- public File createFile(String path, long lastModified) throws IOException;
+ public Writer createOutput(String path, long lastModified) throws IOException;
public abstract Iterable<File> getFolders();
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -33,7 +33,11 @@
import org.richfaces.cdk.xmlconfig.XmlModule;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.Writer;
import java.nio.charset.Charset;
+import java.util.Collections;
import java.util.Locale;
import java.util.Map;
@@ -43,6 +47,7 @@
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
@@ -66,7 +71,21 @@
private Map<StandardOutputFolders, FileManager> outputFolders =
Maps.newHashMap();
private Map<StandardSources,FileManager> sources = Maps.newHashMap();
+
+ private LibraryBuilder libraryBuilder;
+
+ public Generator() {
+ EmptyFileManager emptyFileManager = new EmptyFileManager();
+ for (StandardSources source : StandardSources.values()) {
+ sources.put(source, emptyFileManager);
+ }
+
+ for (StandardOutputFolders output : StandardOutputFolders.values()) {
+ outputFolders.put(output, emptyFileManager);
+ }
+ }
+
public void setLoader(CdkClassLoader loader) {
this.loader = loader;
@@ -88,13 +107,37 @@
checkNotNull(loader, "classLoader");
injector = Guice.createInjector(new CdkConfigurationModule(),new AptModule(),new
ModelModule(),
new ClassGeneratorModule(),new FreeMakerModule(),new TemplateModule(),new
XmlModule());
+ // Create builder instance.
+ this.libraryBuilder = injector.getInstance(LibraryBuilder.class);
}
public void execute() {
- checkNotNull(injector, "initialized");
- injector.getInstance(LibraryBuilder.class).build();
+ checkNotNull(libraryBuilder, "initialized");
+ libraryBuilder.build();
}
+ public static final class EmptyFileManager implements FileManager {
+ @Override
+ public Iterable<File> getFolders() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Iterable<File> getFiles() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public File getFile(String path) throws FileNotFoundException {
+ throw new FileNotFoundException();
+ }
+
+ @Override
+ public Writer createOutput(String path, long lastModified) throws IOException {
+ throw new IOException("read-only");
+ }
+ }
+
public class CdkConfigurationModule extends AbstractModule {
@Override
@@ -109,7 +152,10 @@
for (Map.Entry<StandardSources, FileManager> entry :
sources.entrySet()) {
bind(FileManager.class).annotatedWith(new
SourceImpl(entry.getKey())).toInstance(entry.getValue());
}
+ bind(NamingConventions.class).to(RichFacesConventions.class);
+ bind(ModelValidator.class).to(ValidatorImpl.class);
}
+
}
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -39,69 +39,26 @@
* @author asmirnov(a)exadel.com
*
*/
-public final class LibraryBuilder {
+public interface LibraryBuilder {
- @Inject
- private Logger log;
-
- private final ModelValidator validator;
- private final Iterable<ModelBuilder> builders;
- private final Iterable<CdkWriter> generators;
- private final ComponentLibrary library;
/**
* <p class="changed_added_4_0">
- * </p>
- *
- * @param context
- */
- @Inject
- public LibraryBuilder(ModelValidator validator,Iterable<ModelBuilder>
builders,Iterable<CdkWriter> generators, ComponentLibrary library) {
- this.validator = validator;
- this.builders = builders;
- this.generators = generators;
- this.library = library;
- }
-
-
-
-
- /**
- * <p class="changed_added_4_0">
* Build library model from all available sources.
* </p>
*
* @param templates
* @throws CdkException
*/
- public void build() throws CdkException {
+ public void build() throws CdkException ;
- for (ModelBuilder builder : builders) {
- builder.build();
- }
-
- getValidator().verify();
-
- generate();
- }
-
/**
* Generate all types of files from library model.
* @param library
* @throws CdkException
*/
- public void generate() throws CdkException {
- if (0 == log.getErrorCount()) {
- for (CdkWriter generator : generators) {
- generator.render();
- }
- }
- }
+ public void generate() throws CdkException ;
-
- protected ModelValidator getValidator() throws CdkException {
- return validator;
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Logger.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Logger.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Logger.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -21,6 +21,8 @@
package org.richfaces.cdk;
+import com.google.inject.ImplementedBy;
+
/**
* That interface hides current logging system from generator classes.
* Concrete tools ( Maven, Ant, JUnit ) should provide appropriate logger instance that
delegates
@@ -28,6 +30,7 @@
*
* @author shura
*/
+(a)ImplementedBy(JavaLogger.class)
public interface Logger {
public boolean isDebugEnabled();
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/OutputFileManager.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/OutputFileManager.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/OutputFileManager.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -25,7 +25,9 @@
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.FileWriter;
import java.io.IOException;
+import java.io.Writer;
import java.util.Collections;
import org.richfaces.cdk.model.ComponentLibrary;
@@ -53,7 +55,7 @@
* @see org.richfaces.cdk.FileManager#createFile(java.lang.String)
*/
@Override
- public File createFile(String path, long lastModified) throws IOException {
+ public Writer createOutput(String path, long lastModified) throws IOException {
if (null == path) {
throw new NullPointerException();
}
@@ -86,7 +88,7 @@
outputFile.getParentFile().mkdirs();
outputFile.createNewFile();
- return outputFile;
+ return new FileWriter(outputFile);
}
/*
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/SourceFileManager.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/SourceFileManager.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/SourceFileManager.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -26,6 +26,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.Writer;
/**
* <p class="changed_added_4_0">
@@ -50,7 +51,7 @@
* @see org.richfaces.cdk.FileManager#createFile(java.lang.String)
*/
@Override
- public File createFile(String path, long lastModified) throws IOException {
+ public Writer createOutput(String path, long lastModified) throws IOException {
throw new UnsupportedOperationException("Cannot create file in source
folder");
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptBuilder.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptBuilder.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptBuilder.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -25,19 +25,17 @@
package org.richfaces.cdk.apt;
-import java.io.File;
-import java.util.Arrays;
+import java.util.Set;
-import javax.annotation.processing.Processor;
-import com.google.inject.Inject;
import javax.tools.JavaCompiler.CompilationTask;
import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.LibraryBuilder;
import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.ModelBuilder;
-import org.richfaces.cdk.Source;
-import org.richfaces.cdk.StandardSources;
+import com.google.inject.Inject;
+
/**
* <p class="changed_added_4_0">
* That class compiles files from sources and process annotations
@@ -46,41 +44,33 @@
* @author asmirnov(a)exadel.com
*
*/
-public class AptBuilder implements ModelBuilder {
+public class AptBuilder implements LibraryBuilder {
@Inject
private static Logger LOG ;
- @Inject
- private Processor cdkProcessor;
- @Inject
- @Source(StandardSources.JAVA_SOURCES)
- private Iterable<File> sources;
@Inject
private CompilationTaskFactory taskFactory;
- public void build() throws CdkException {
+ @Inject
+ private Set<CdkWriter> generators;
- process(sources, cdkProcessor);
+ public void build() throws CdkException {
+ CompilationTask task = taskFactory.get();
+ if (!task.call()) {
+ throw new AptException("Compilation error");
+ }
}
- /**
- * <p class="changed_added_4_0">That method process source files and
call appropriate annotation processors</p>
- * @param sources
- * @param processors
- * @throws AptException
- */
- protected void process(Iterable<File> sources, Processor... processors) throws
AptException {
- if (sources != null && sources.iterator().hasNext()) {
- CompilationTask task = taskFactory.getTask(sources);
- task.setProcessors(Arrays.asList(processors));
-
- if (!task.call()) {
- throw new AptException("Compilation error");
+ @Override
+ public void generate() throws CdkException {
+ if (0 == LOG.getErrorCount()) {
+ // processing over, generate files.
+ for (CdkWriter generator : generators) {
+ generator.render();
}
- } else {
- LOG.info("No compilation units found, skipping Java sources
processing");
- }
+
+ }
}
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptModule.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptModule.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptModule.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -25,6 +25,8 @@
import javax.annotation.processing.Processor;
+import org.richfaces.cdk.LibraryBuilder;
+
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
@@ -49,6 +51,7 @@
setBinder.addBinding().to(ValidatorProcessor.class);
bind(Processor.class).to(CdkProcessor.class);
bind(CompilationTaskFactory.class).to(TaskFactoryImpl.class);
+ bind(LibraryBuilder.class).to(AptBuilder.class);
}
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -34,6 +34,7 @@
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.LibraryBuilder;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.ModelBuilder;
import org.richfaces.cdk.ModelValidator;
@@ -56,13 +57,10 @@
private Logger log;
@Inject
- private Iterable<CdkAnnotationProcessor> processors;
+ private Set<CdkAnnotationProcessor> processors;
@Inject
- private Iterable<ModelBuilder> builders;
-
- @Inject
- private Iterable<CdkWriter> generators;
+ private Set<ModelBuilder> builders;
@Inject
private SourceUtils sourceUtils;
@@ -70,6 +68,9 @@
@Inject
private ModelValidator validator;
+ @Inject
+ private LibraryBuilder builder;
+
@Override
@@ -87,9 +88,7 @@
validator.verify();
} else if (0 == log.getErrorCount()) {
// processing over, generate files.
- for (CdkWriter generator : generators) {
- generator.render();
- }
+ builder.generate();
}
sourceUtils.release();
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CompilationTaskFactory.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CompilationTaskFactory.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CompilationTaskFactory.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -23,7 +23,6 @@
package org.richfaces.cdk.apt;
-import java.io.File;
import javax.tools.JavaCompiler.CompilationTask;
@@ -34,6 +33,6 @@
*/
public interface CompilationTaskFactory {
- CompilationTask getTask(Iterable<File> sources) throws AptException;
+ CompilationTask get() throws AptException;
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/TaskFactoryImpl.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/TaskFactoryImpl.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/TaskFactoryImpl.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -26,10 +26,13 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Locale;
import com.google.inject.Inject;
+
+import javax.annotation.processing.Processor;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;
import javax.tools.JavaCompiler;
@@ -107,6 +110,9 @@
@Source(StandardSources.JAVA_SOURCES)
private FileManager sourceFolders;
+ @Inject
+ private Processor cdkProcessor;
+
private JavaCompiler javaCompiler;
private StandardJavaFileManager fileManager;
@@ -119,27 +125,26 @@
* @see org.richfaces.cdk.apt.CompilationTaskFactory#getTask(java.lang.Iterable)
*/
@Override
- public CompilationTask getTask(Iterable<File> sources) throws AptException {
+ public CompilationTask get() throws AptException {
diagnosticListener = new DiagnosticListenerImplementation();
- Iterable<? extends JavaFileObject> sourceObjects =
getFileManager().getJavaFileObjectsFromFiles(sources);
+ Iterable<? extends JavaFileObject> sourceObjects =
getFileManager().getJavaFileObjectsFromFiles(sourceFolders.getFiles());
CompilationTask task =
getJavaCompiler().getTask(null, getFileManager(), diagnosticListener,
options, null, sourceObjects);
task.setLocale(locale);
+ task.setProcessors(Collections.singleton(cdkProcessor));
return task;
}
private StandardJavaFileManager getFileManager() {
if (fileManager == null) {
- fileManager = javaCompiler.getStandardFileManager(diagnosticListener, locale,
charset);
+ fileManager = getJavaCompiler().getStandardFileManager(diagnosticListener,
locale, charset);
try {
fileManager.setLocation(StandardLocation.CLASS_PATH,
classPathLoader.getFiles());
- if (null != outputFolder) {
-
fileManager.setLocation(StandardLocation.SOURCE_OUTPUT,outputFolder.getFolders());
+ Iterable<File> outputFolders = outputFolder.getFolders();
+ if (null != outputFolders) {
+ fileManager.setLocation(StandardLocation.SOURCE_OUTPUT,
outputFolders);
}
-
- if (null != sourceFolders ) {
- fileManager.setLocation(StandardLocation.SOURCE_PATH,
sourceFolders.getFolders());
- }
+ fileManager.setLocation(StandardLocation.SOURCE_PATH,
sourceFolders.getFolders());
} catch (IOException e) {
throw new CdkException("Cannot configure JavaFileManager for
compilator",e);
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -122,8 +122,7 @@
}
try {
- File sourceOutput = output.createFile(getOutputFile(c), lastModified);
- return new FileWriter(sourceOutput);
+ return output.createOutput(getOutputFile(c), lastModified);
} catch (IOException e) {
throw new CdkException(e);
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -26,6 +26,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
+import java.io.Writer;
import com.google.inject.Inject;
@@ -99,15 +100,11 @@
JavaClass javaClass = visitor.getGeneratedClass();
String fullName = javaClass.getName();
try {
- File outFile = output.createFile(fullName.replace('.',
'/') + ".java", library.lastModified());
+ Writer outFile =
output.createOutput(fullName.replace('.', '/') + ".java",
library.lastModified());
if (null != outFile) {
- PrintWriter outputWriter = null;
-
- outputWriter = new PrintWriter(outFile);
-
- this.renderer.writeSnippet("class", javaClass,
outputWriter);
- outputWriter.close();
+ this.renderer.writeSnippet("class", javaClass,
outFile);
+ outFile.close();
}
} catch (IOException e) {
throw new CdkException(e);
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -27,6 +27,7 @@
import org.richfaces.cdk.ModelBuilder;
import com.google.inject.AbstractModule;
+import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
/**
@@ -44,6 +45,8 @@
Multibinder<ModelBuilder> modelBinder = Multibinder.newSetBinder(binder(),
ModelBuilder.class);
modelBinder.addBinding().to(RendererTemplateParser.class);
Multibinder.newSetBinder(binder(),CdkWriter.class).addBinding().to(RendererClassGenerator.class);
+ bind(new
TypeLiteral<TemplateVisitorFactory<RendererClassVisitor>>(){}).to(VisitorFactoryImpl.class);
+ bind(FreeMarkerRenderer.class).to(JavaClassConfiguration.class);
}
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -26,6 +26,7 @@
package org.richfaces.cdk.xmlconfig;
import java.io.File;
+import java.io.Writer;
import com.google.inject.Inject;
@@ -76,7 +77,7 @@
// TODO - check modification time.
try {
- File facesConfigXml = outputFileManager.createFile(FACES_CONFIG_XML,
library.lastModified());
+ Writer facesConfigXml = outputFileManager.createOutput(FACES_CONFIG_XML,
library.lastModified());
if (null != facesConfigXml) {
jaxbBinding.marshal(facesConfigXml, FACES_SCHEMA_LOCATION,
libraryAdapter.marshal(library));
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -28,6 +28,7 @@
import com.google.inject.Inject;
import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.FileManager;
import org.richfaces.cdk.ModelBuilder;
import org.richfaces.cdk.Source;
import org.richfaces.cdk.StandardSources;
@@ -51,7 +52,7 @@
@Inject
private ComponentLibrary library;
@Inject @Source(StandardSources.FACES_CONFIGS)
- private Iterable<File> configFiles;
+ private FileManager configFiles;
/*
@@ -62,8 +63,7 @@
@Override
public void build() throws CdkException {
- if (null != configFiles) {
- for (File file : configFiles) {
+ for (File file : configFiles.getFiles()) {
FacesConfigBean unmarshal = unmarshalFacesConfig(file);
if (null != unmarshal) {
ComponentLibrary facesConfig = ADAPTER.unmarshal(unmarshal);
@@ -78,8 +78,6 @@
// library.setExtensions(unmarshal.getExtensions());
}
}
-
- }
}
protected FacesConfigBean unmarshalFacesConfig(File file) throws CdkException {
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXB.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXB.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXB.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -3,6 +3,7 @@
import org.richfaces.cdk.CdkException;
import java.io.File;
+import java.io.Writer;
import javax.xml.transform.Result;
@@ -12,7 +13,7 @@
public abstract <T> T unmarshal(String url, String schemaLocation,
Class<T> bindClass) throws CdkException;
- public abstract <T> void marshal(File output, String schemaLocation, T model)
throws CdkException;
+ public abstract <T> void marshal(Writer output, String schemaLocation, T model)
throws CdkException;
public abstract <T> void marshal(Result output, String schemaLocation, T model)
throws CdkException;
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -34,6 +34,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
+import java.io.Writer;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
@@ -89,6 +90,7 @@
/* (non-Javadoc)
* @see org.richfaces.cdk.xmlconfig.JAXB#unmarshal(java.io.File, java.lang.String,
java.lang.Class)
*/
+ @Override
public <T> T unmarshal(File file, String schemaLocation, Class<T>
bindClass) throws CdkException {
try {
InputSource input = new InputSource(new FileInputStream(file));
@@ -106,6 +108,7 @@
/* (non-Javadoc)
* @see org.richfaces.cdk.xmlconfig.JAXB#unmarshal(java.lang.String,
java.lang.String, java.lang.Class)
*/
+ @Override
public <T> T unmarshal(String url, String schemaLocation, Class<T>
bindClass) throws CdkException {
try {
InputSource inputSource;
@@ -186,14 +189,14 @@
/* (non-Javadoc)
* @see org.richfaces.cdk.xmlconfig.JAXB#marshal(java.io.File, java.lang.String, T)
*/
- public <T> void marshal(File output, String schemaLocation, T model) throws
CdkException {
+ @Override
+ public <T> void marshal(Writer output, String schemaLocation, T model) throws
CdkException {
try {
- FileOutputStream outputStream = new FileOutputStream(output);
- StreamResult result = new StreamResult(outputStream);
+ StreamResult result = new StreamResult(output);
marshal(result, schemaLocation, model);
- outputStream.flush();
- outputStream.close();
+ output.flush();
+ output.close();
} catch (FileNotFoundException e) {
throw new CdkException("File not found", e);
} catch (IOException e) {
@@ -204,6 +207,7 @@
/* (non-Javadoc)
* @see org.richfaces.cdk.xmlconfig.JAXB#marshal(javax.xml.transform.Result,
java.lang.String, T)
*/
+ @Override
public <T> void marshal(Result output, String schemaLocation, T model) throws
CdkException {
try {
JAXBContext jc = JAXBContext.newInstance(model.getClass());
Modified:
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -32,8 +32,10 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.charset.Charset;
import java.util.Collections;
+import java.util.Locale;
import java.util.logging.LogManager;
import org.junit.After;
@@ -41,20 +43,25 @@
import org.richfaces.cdk.annotations.Component;
import com.google.common.collect.ImmutableList;
+import com.google.inject.Binder;
+import com.google.inject.Module;
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
*
*/
-public abstract class CdkTestBase {
+public abstract class CdkTestBase implements Module {
protected Iterable<File> testSourceDirectory;
+ protected File tempDir;
@Before
public void setUpSourceDirectory() throws Exception {
testSourceDirectory =
Collections.singleton(getJavaFile("test.source.properties").getParentFile());
+ this.tempDir = File.createTempFile("cdk", "test");
+
InputStream stream =
this.getClass().getResourceAsStream("logging.properties");
if (null != stream) {
@@ -78,6 +85,12 @@
public void tearDownSourceDirectory() {
testSourceDirectory = null;
}
+
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(Locale.class).toInstance(Locale.getDefault());
+ binder.bind(Charset.class).toInstance(Charset.defaultCharset());
+ }
protected File getJavaFile(String name) throws URISyntaxException {
ClassLoader classLoader = this.getClass().getClassLoader();
Modified:
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestRunner.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestRunner.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestRunner.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -32,7 +32,9 @@
import java.util.Set;
import org.easymock.EasyMock;
+import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import com.google.common.collect.Sets;
@@ -79,6 +81,11 @@
}
@Override
+ protected void runChild(FrameworkMethod method, RunNotifier notifier) {
+ super.runChild(method, notifier);
+ }
+
+ @Override
protected Object createTest() throws Exception {
Class<?> c = getTestClass().getJavaClass();
Set<Field> testFields = getFields(c);
Modified:
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -28,14 +28,8 @@
* @author asmirnov
*
*/
-(a)RunWith(Parameterized.class)
-public class LibraryBuilderTest {
- private String param;
+public class LibraryBuilderTest extends CdkTestBase {
- public LibraryBuilderTest(String param) {
- this.param = param;
- }
-
/**
* @throws java.lang.Exception
*/
@@ -50,15 +44,15 @@
/**
* Test method for {@link org.richfaces.cdk.LibraryBuilder#createInstance()}.
+ * @throws Exception
*/
@Test
- public void createInstance() {
-
-// assertEquals("Parameter match","Two", param);
+ public void testInit() throws Exception {
+ Generator generator = new Generator();
+ // setup CDK configuration.
+ generator.setLoader(createClassLoader());
+ // Test dependencies tree.
+ generator.init();
}
- @Parameters
- public static Collection<String[]> values() {
- return Arrays.asList(new String[] {"One"}, new String[]
{"Two"}, new String[] {"Tree"});
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/RunnerTest.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/RunnerTest.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/RunnerTest.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -25,4 +25,13 @@
replay(log,sources);
verify(log,sources);
}
+
+ @Test
+ public void easyMockInjections2() throws Exception {
+ assertNotNull(log);
+ assertNotNull(sources);
+ replay(log,sources);
+ verify(log,sources);
+ }
+
}
Modified:
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/AnnotationProcessorTest.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/AnnotationProcessorTest.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/AnnotationProcessorTest.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -21,63 +21,33 @@
package org.richfaces.cdk.apt;
-import org.richfaces.cdk.CdkTestBase;
-import org.richfaces.cdk.CdkContext;
-import org.richfaces.cdk.CdkContextBase;
-import org.richfaces.cdk.StandardSources;
-import org.richfaces.cdk.RichFacesConventions;
-import org.richfaces.cdk.NamingConventions;
-import org.richfaces.cdk.ModelValidator;
-import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.CdkProcessingException;
+import javax.el.ELContext;
+import javax.faces.component.UIComponent;
+
import org.richfaces.cdk.CdkClassLoader;
+import org.richfaces.cdk.CdkTestBase;
import org.richfaces.cdk.annotations.Family;
-import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
+
import com.google.common.collect.ImmutableList;
+import com.google.inject.Binder;
-import javax.el.ELContext;
-import javax.faces.component.UIComponent;
-
/**
* @author akolonitsky
* @since Jan 14, 2010
*/
public abstract class AnnotationProcessorTest extends CdkTestBase {
-
- protected ComponentLibrary prepareMockCompilationContext(String javaFilePath) throws
Exception {
- CdkContext cdkContext = createMockContext();
- CdkProcessor processor = new CdkProcessor();
- AptBuilder compiler = new AptBuilder();
-
- compiler.init(cdkContext);
- processor.init(cdkContext);
- compiler.process(ImmutableList.of(getJavaFile(javaFilePath)), processor);
-
- return cdkContext.getLibrary();
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+ try {
+ binder.bind(CdkClassLoader.class).toInstance(createClassLoader());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
- protected CdkContext createMockContext() throws Exception {
- CdkContextBase baseContext = new CdkContextBase(createClassLoader());
- baseContext.setSourceFolders(StandardSources.JAVA_SOURCES, testSourceDirectory);
- RichFacesConventions richFacesConventions = new RichFacesConventions();
- baseContext.setWorker(NamingConventions.class, richFacesConventions);
- baseContext.setWorker(ModelValidator.class, new ModelValidator() {
-
- @Override
- public void init(CdkContext context) {
-
- }
-
- @Override
- public void verify(ComponentLibrary library) throws CdkException {
- }
- });
- baseContext.sendError(new CdkProcessingException());
-
- return baseContext;
- }
-
@Override
protected CdkClassLoader createClassLoader() throws Exception {
return new
CdkClassLoader(ImmutableList.of(getLibraryFile("test.source.properties"),
Modified:
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java 2010-02-01
23:54:20 UTC (rev 16389)
+++
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -27,48 +27,15 @@
import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestRunner;
-import static javax.lang.model.util.ElementFilter.*;
+import com.google.common.collect.ImmutableSet;
-import java.io.File;
+import static org.junit.Assert.*;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.util.Collections;
-import java.util.Set;
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.annotation.processing.Processor;
-import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.annotation.processing.SupportedSourceVersion;
-
-import javax.lang.model.SourceVersion;
-import javax.lang.model.element.TypeElement;
-
-import javax.tools.JavaFileObject;
-import javax.tools.SimpleJavaFileObject;
-
-import org.easymock.Capture;
-import org.easymock.CaptureType;
-
-import org.junit.Test;
-
-import org.richfaces.cdk.CdkContext;
-import org.richfaces.cdk.CdkTestBase;
-import org.richfaces.cdk.OutputType;
-import org.richfaces.cdk.StandardOutputs;
-import org.richfaces.cdk.StandardSources;
-import org.richfaces.cdk.annotations.Attribute;
-import org.richfaces.cdk.annotations.Component;
-import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-
/**
* <p class="changed_added_4_0">
* </p>
@@ -76,225 +43,12 @@
* @author asmirnov(a)exadel.com
*
*/
-public class CdkProcessorTest extends CdkTestBase {
+(a)RunWith(CdkTestRunner.class)
+public class CdkProcessorTest extends AnnotationProcessorTest {
private static final String ANNOTATION2 = TestAnnotation2.class.getName();
private static final String CLASS_JAVA =
"org/richfaces/cdk/apt/TestClass.java";
private static final String COMPONENT_CLASS_JAVA =
"org/richfaces/cdk/test/component/AbstractTestComponent.java";
private static final String INTERFACE_JAVA =
"org/richfaces/cdk/apt/TestInterface.java";
private static final String SUB_CLASS_JAVA =
"org/richfaces/cdk/apt/TestSubClass.java";
private static final ImmutableSet<String> PROCESS_ANNOTATIONS =
ImmutableSet.of(TestAnnotation.class.getName());
- private ClassLoader testLoader;
-
- /**
- * Test method for
- * {@link org.richfaces.cdk.apt.CdkProcessor#process(java.util.Set,
javax.annotation.processing.RoundEnvironment)}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testProcess() throws Exception {
-
- // Prepare Mock compilation context.
- CdkContext cdkContext = createMock(CdkContext.class);
-
-
expect(cdkContext.getSourceFolders(StandardSources.JAVA_SOURCES)).andStubReturn(testSourceDirectory);
- expect(cdkContext.getOutputFolder((OutputType)
anyObject())).andStubReturn(null);
- expect(cdkContext.getLoader()).andStubReturn(createClassLoader());
- replay(cdkContext);
-
- Processor processor = createMock(Processor.class);
-
- processor.init((ProcessingEnvironment) anyObject());
-
expect(processor.getSupportedOptions()).andReturn(ImmutableSet.<String>of());
-
- // processor.process(null,null);
- Capture<Set<? extends TypeElement>> capturedTypes = new
Capture<Set<? extends TypeElement>>();
-
- expect(processor.process(capture(capturedTypes),
- capture(new
Capture<RoundEnvironment>()))).andReturn(true).times(2);
-
expect(processor.getSupportedAnnotationTypes()).andReturn(ImmutableSet.of("*"));
-
expect(processor.getSupportedSourceVersion()).andReturn(SourceVersion.RELEASE_6);
- replay(processor);
-
- AptBuilder compiler = new AptBuilder();
-
- compiler.init(cdkContext);
- compiler.process(ImmutableList.of(getJavaFile(CLASS_JAVA)), processor);
- verify(cdkContext, processor);
- }
-
- /**
- * Test method for
- * {@link org.richfaces.cdk.apt.CdkProcessor#process(java.util.Set,
javax.annotation.processing.RoundEnvironment)}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testProcessSubClass() throws Exception {
-
- // Prepare Mock compilation context.
- CdkContext cdkContext = createMock(CdkContext.class);
-
-
expect(cdkContext.getSourceFolders(StandardSources.JAVA_SOURCES)).andStubReturn(testSourceDirectory);
- expect(cdkContext.getOutputFolder((OutputType)
anyObject())).andStubReturn(null);
- expect(cdkContext.getLoader()).andStubReturn(createClassLoader());
- replay(cdkContext);
-
- Processor processor = createMock(Processor.class);
-
- processor.init((ProcessingEnvironment) anyObject());
-
expect(processor.getSupportedOptions()).andReturn(ImmutableSet.<String>of());
-
- // processor.process(null,null);
- Capture<Set<? extends TypeElement>> capturedTypes = new
Capture<Set<? extends TypeElement>>(CaptureType.FIRST);
-
- expect(processor.process(capture(capturedTypes),
- capture(new
Capture<RoundEnvironment>()))).andReturn(true).times(2);
-
expect(processor.getSupportedAnnotationTypes()).andReturn(ImmutableSet.of(TestAnnotation2.class.getName()));
-
expect(processor.getSupportedSourceVersion()).andReturn(SourceVersion.RELEASE_6);
- replay(processor);
-
- AptBuilder compiler = new AptBuilder();
-
- compiler.init(cdkContext);
- compiler.process(ImmutableList.of(getJavaFile(SUB_CLASS_JAVA),
getJavaFile(CLASS_JAVA)), processor);
- verify(cdkContext, processor);
-
- Set<? extends TypeElement> elements = capturedTypes.getValue();
-
- assertFalse(elements.isEmpty());
- assertEquals("TestAnnotation2",
elements.iterator().next().getSimpleName().toString());
- }
-
- /**
- * Test method for
- * {@link
org.richfaces.cdk.apt.CdkProcessor#getClassesAnnotatedWith(RoundEnvironment, Class)}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testGetClassesAnnotatedWith() throws Exception {
-
- // Prepare Mock compilation context.
- CdkContext cdkContext = createMock(CdkContext.class);
-
-
expect(cdkContext.getSourceFolders(StandardSources.JAVA_SOURCES)).andStubReturn(testSourceDirectory);
- expect(cdkContext.getOutputFolder((OutputType)
anyObject())).andStubReturn(null);
- expect(cdkContext.getLoader()).andStubReturn(createClassLoader());
- replay(cdkContext);
-
- TestProcessor processor = new TestProcessor() {
- @Override
- public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
- if (!roundEnv.processingOver()) {
- this.numOfComponents =
roundEnv.getElementsAnnotatedWith(Component.class).size();
- }
-
- return true;
- }
- };
-
- processor.init(cdkContext);
- // ComponentLibrary library = new
- // ComponentLibrary("org.richfaces.cdk.test");
- // processor.library = library;
- AptBuilder compiler = new AptBuilder();
-
- compiler.init(cdkContext);
- compiler.process(ImmutableList.of(getJavaFile(COMPONENT_CLASS_JAVA)),
processor);
- verify(cdkContext);
- assertTrue(processor.isInitialized());
- assertEquals(1, processor.numOfComponents);
- }
-
- /**
- * Test method for
- * {@link
org.richfaces.cdk.apt.CdkProcessor#getClassesAnnotatedWith(RoundEnvironment, Class)}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testGetPropertiesAnnotatedWith() throws Exception {
-
- // Prepare Mock compilation context.
- CdkContext cdkContext = createMock(CdkContext.class);
-
-
expect(cdkContext.getSourceFolders(StandardSources.JAVA_SOURCES)).andStubReturn(testSourceDirectory);
- expect(cdkContext.getOutputFolder((OutputType)
anyObject())).andStubReturn(null);
- expect(cdkContext.getLoader()).andStubReturn(createClassLoader());
- replay(cdkContext);
-
- TestProcessor processor = new TestProcessor() {
- @Override
- public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
- if (!roundEnv.processingOver()) {
- SourceUtils utils = new SourceUtils(processingEnv,roundEnv);
- utils.init(getContext());
- TypeElement typeElement =
utils.getClassesAnnotatedWith(Component.class).iterator().next();
- Set<BeanProperty> beanProperties =
utils.getBeanPropertiesAnnotatedWith(Attribute.class, typeElement);
-
- assertEquals(3, beanProperties.size());
-
- BeanProperty property = Iterables.get(beanProperties, 2);
-
- assertEquals("foo", property.getName());
- assertEquals("int", property.getType().toString());
- assertNull(property.getDocComment());
- property = Iterables.get(beanProperties, 1);
- assertEquals("testValue", property.getName());
- assertEquals("java.util.List<java.lang.String>",
property.getType().toString());
- assertEquals(" Test Attribute\n",
property.getDocComment());
- property = Iterables.get(beanProperties, 0);
- assertEquals("barValue", property.getName());
- assertEquals("java.util.List<M>",
property.getType().toString());
- assertEquals(" Bar Attribute\n",
property.getDocComment());
-
-// assertEquals("<M>" ,property.getTypeParameters());
- numOfComponents++;
- }
-
- return true;
- }
- };
- processor.init(cdkContext);
-
- // ComponentLibrary library = new
- // ComponentLibrary("org.richfaces.cdk.test");
- // processor.library = library;
- AptBuilder compiler = new AptBuilder();
-
- compiler.init(cdkContext);
- compiler.process(ImmutableList.of(getJavaFile(COMPONENT_CLASS_JAVA)),
processor);
- verify(cdkContext);
- assertTrue(processor.isInitialized());
- assertEquals(1, processor.numOfComponents);
- }
-
- private abstract static class TestProcessor extends CdkProcessor {
- protected int numOfComponents;
-
- public TestProcessor() {
- }
-
- @Override
- public synchronized void init(ProcessingEnvironment processingEnv) {
- super.init(processingEnv);
- }
-
- @Override
- public synchronized boolean isInitialized() {
- return super.isInitialized();
- }
-
- @Override
- public Set<String> getSupportedAnnotationTypes() {
-
- // Process all annotations
- return ImmutableSet.of("*");
- }
- }
}
Added:
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/TaskFactoryTest.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/TaskFactoryTest.java
(rev 0)
+++
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/TaskFactoryTest.java 2010-02-02
01:17:30 UTC (rev 16390)
@@ -0,0 +1,127 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.apt;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+import java.util.Set;
+
+
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.Processor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+import javax.tools.JavaCompiler.CompilationTask;
+
+import org.easymock.Capture;
+import org.easymock.CaptureType;
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.OutputFolder;
+import org.richfaces.cdk.Source;
+import org.richfaces.cdk.StandardOutputFolders;
+import org.richfaces.cdk.StandardSources;
+import org.richfaces.cdk.Stub;
+
+import com.google.common.collect.ImmutableList;
+import com.google.inject.Inject;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+(a)RunWith(CdkTestRunner.class)
+public class TaskFactoryTest extends AnnotationProcessorTest {
+
+ private static final String CLASS_JAVA =
"org/richfaces/cdk/apt/TestClass.java";
+ private static final String SUB_CLASS_JAVA =
"org/richfaces/cdk/apt/TestSubClass.java";
+ private static final String INTERFACE_JAVA =
"org/richfaces/cdk/apt/TestInterface.java";
+
+
+ @Inject
+ private TaskFactoryImpl factory;
+
+ @Mock
+ private Logger log;
+
+ @Mock
+ Processor processor;
+
+ @Stub
+ @OutputFolder(StandardOutputFolders.JAVA_CLASSES)
+ private FileManager output;
+
+ @Stub
+ @Source(StandardSources.JAVA_SOURCES)
+ private FileManager sources;
+ /**
+ * Test method for {@link org.richfaces.cdk.apt.TaskFactoryImpl#get()}.
+ * @throws Exception
+ * @throws AptException
+ */
+ @Test
+ public void testGetTask() throws AptException, Exception {
+
expect(sources.getFiles()).andStubReturn(Collections.singleton(getJavaFile(CLASS_JAVA)));
+ expect(sources.getFolders()).andStubReturn(this.testSourceDirectory);
+ expect(output.getFolders()).andReturn(null);
+ replay(log,processor,sources,output);
+ CompilationTask task = factory.get();
+ assertNotNull(task);
+ verify(log,processor,sources,output);
+ }
+
+ @Test
+ public void testTask() throws AptException, Exception {
+
expect(sources.getFiles()).andStubReturn(ImmutableList.of(getJavaFile(CLASS_JAVA),getJavaFile(SUB_CLASS_JAVA),getJavaFile(INTERFACE_JAVA)));
+ expect(sources.getFolders()).andStubReturn(this.testSourceDirectory);
+ expect(output.getFolders()).andReturn(null);
+ processor.init((ProcessingEnvironment) anyObject());expectLastCall();
+
expect(processor.getSupportedSourceVersion()).andReturn(SourceVersion.RELEASE_6);
+
expect(processor.getSupportedAnnotationTypes()).andReturn(Collections.singleton("*"));
+
expect(processor.getSupportedOptions()).andReturn(Collections.<String>emptySet());
+ // processor.process(null,null);
+ Capture<Set<? extends TypeElement>> capturedTypes = new
Capture<Set<? extends TypeElement>>(CaptureType.FIRST);
+
+ expect(processor.process(capture(capturedTypes),
+ EasyMock.<RoundEnvironment>anyObject())).andReturn(true).times(2);
+ replay(log,processor,sources,output);
+ CompilationTask task = factory.get();
+ assertTrue(task.call());
+ Set<? extends TypeElement> elements = capturedTypes.getValue();
+
+ assertFalse(elements.isEmpty());
+ assertEquals("TestInterfaceAnnotation",
elements.iterator().next().getSimpleName().toString());
+ verify(log,processor,sources,output);
+ }
+
+}
Property changes on:
root/cdk/branches/guice/plugins/generator/src/test/java/org/richfaces/cdk/apt/TaskFactoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain