Author: abelevich
Date: 2009-02-05 09:23:57 -0500 (Thu, 05 Feb 2009)
New Revision: 12578
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java
Log:
format code, rename script/stylePackName to script/styleFileName parameter
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java 2009-02-05
14:19:20 UTC (rev 12577)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java 2009-02-05
14:23:57 UTC (rev 12578)
@@ -64,19 +64,20 @@
return true;
}
}
+
return false;
}
protected void walk(FileObject file) throws IOException{
FileObject [] children = file.getChildren();
for(FileObject child : children) {
+
if(child.getType() != FileType.FILE) {
walk(child);
- } else {
- if(isAcceptable(child)) {
- result.add(child);
- }
+ } else if(isAcceptable(child)) {
+ result.add(child);
}
+
}
}
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java 2009-02-05
14:19:20 UTC (rev 12577)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java 2009-02-05
14:23:57 UTC (rev 12578)
@@ -32,4 +32,5 @@
public void assembly(URL resource);
public void writeToFile(File file);
+
}
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java 2009-02-05
14:19:20 UTC (rev 12577)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java 2009-02-05
14:23:57 UTC (rev 12578)
@@ -67,12 +67,14 @@
private void iterate(Collection<String> resources) {
for (String resourceName: resources) {
+
URL resource = getResourceURL(resourceName);
if(resource != null) {
if (assembler != null) {
assembler.assembly(resource);
}
- }
+ }
+
}
}
@@ -86,6 +88,7 @@
Class clazz = classLoader.loadClass(resourceName);
Object obj = clazz.newInstance();
Method method = clazz.getMethod("getPath", new Class [0]);
+
String path = (String) method.invoke(obj, new Object[0]);
resource = classLoader.getResource(path);
}
@@ -98,14 +101,17 @@
public void writeToFile() {
if(assemblyFile != null) {
+
if(assemblyFile.exists()) {
assemblyFile.delete();
- }
+ }
+
try {
assemblyFile.createNewFile();
} catch (IOException e) {
log.error("Error create assembly File: " +
assemblyFile.getAbsolutePath(),e);
}
+
assembler.writeToFile(assemblyFile);
}
}
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java 2009-02-05
14:19:20 UTC (rev 12577)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java 2009-02-05
14:23:57 UTC (rev 12578)
@@ -36,32 +36,39 @@
*/
public class ScriptAssembler implements ResourceAssembler {
- Log log = new SystemStreamLog();
+ protected Log log = new SystemStreamLog();
private StringBuilder builder = new StringBuilder();
+
public void assembly(URL resource) {
log.info("process resource : " + resource.getFile());
+
try {
builder.append(IOUtil.toString(resource.openStream()));
builder.append("\n");
} catch (IOException e) {
log.error("Error read resource: " + resource.getFile());
}
+
}
public void writeToFile(File file) {
if(builder.length() > 0) {
+
try {
FileWriter fileWriter = new FileWriter(file);
+
try {
IOUtil.copy(builder.toString(), fileWriter);
} finally {
fileWriter.close();
}
+
} catch (IOException e) {
log.error("Error write file: " + file.getAbsolutePath(),e);
}
+
}
}
}
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java 2009-02-05
14:19:20 UTC (rev 12577)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java 2009-02-05
14:23:57 UTC (rev 12578)
@@ -44,9 +44,8 @@
public class StyleAssembler implements ResourceAssembler {
+ protected Log log = new SystemStreamLog();
- private Log log = new SystemStreamLog();
-
private VelocityComponent velocityComponent;
private StringBuilder builder = new StringBuilder();
@@ -56,20 +55,26 @@
String file = resource.getFile();
log.info("process resource: " + file);
+
try {
InputStream resourceInputStream = resource.openStream();
+
try {
+
if(file.endsWith(".xcss")) {
XMLBody xmlBody = new XMLBody();
+
try {
xmlBody.loadXML(resourceInputStream,true);
builder.append(xmlBody.getContent());
} catch (ParsingException e) {
log.error("Error process xcss: " + e.getMessage(), e);
- }
+ }
+
} else {
builder.append(IOUtil.toString(resourceInputStream));
}
+
} finally {
resourceInputStream.close();
}
@@ -89,11 +94,13 @@
public void writeToFile(File file) {
try {
+
if(builder.length() > 0 && velocityComponent != null) {
VelocityContext context = new VelocityContext();
context.put("content", builder);
VelocityEngine engine = velocityComponent.getEngine();
FileWriter fileWriter = new FileWriter(file);
+
try {
Template velocityTemplate = engine.getTemplate("templates12/xcss.vm");
velocityTemplate.merge(context, fileWriter);
@@ -101,7 +108,9 @@
} finally {
fileWriter.close();
}
+
}
+
} catch (Exception e) {
log.error("Error write file: " + file.getAbsolutePath(),e);
}
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java 2009-02-05
14:19:20 UTC (rev 12577)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java 2009-02-05
14:23:57 UTC (rev 12578)
@@ -85,7 +85,6 @@
for(Component component : components ){
String componentName = component.getComponentName();
-
if(localName.equals(componentName)) {
if(doMatch(componentIncludes, componentName,false)) {
@@ -117,9 +116,11 @@
for(String style : component.getStyles()) {
if(doMatch(styleIncludes, style, true)) {
+
if(!doMatch(styleExcludes, style, true)) {
this.styles.add(style);
}
+
}
}
@@ -155,9 +156,11 @@
for(String script : component.getScripts()) {
if(doMatch(scriptIncludes, script, true)) {
+
if(!doMatch(scriptExcludes, script, true)) {
this.scripts.add(script);
}
+
}
}
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-02-05
14:19:20 UTC (rev 12577)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-02-05
14:23:57 UTC (rev 12578)
@@ -39,11 +39,13 @@
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.VFS;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
@@ -84,16 +86,27 @@
*
* @component
*/
- private org.apache.maven.artifact.factory.ArtifactFactory factory;
+ private ArtifactFactory factory;
/**
* Used to look up Artifacts in the remote repository.
*
* @component
*/
- private org.apache.maven.artifact.resolver.ArtifactResolver resolver;
+ private ArtifactResolver resolver;
/**
+ *
+ * @component
+ */
+ private ArtifactMetadataSource metadataSource;
+
+ /**
+ * @component
+ */
+ protected VelocityComponent velocity;
+
+ /**
* The local repository.
*
* @parameter expression="${localRepository}"
@@ -102,25 +115,19 @@
/**
* webSourceDirectory
+ *
* @parameter expression="${basedir}/src/main/webapp"
*/
private File webSourceDirectory;
/**
- *
- * @component
- */
- private ArtifactMetadataSource metadataSource;
-
- /**
* outputScriptDirectory
* @parameter expression = "${basedir}/src/main/webapp/WEB-INF/classes"
*/
private File outputScriptDirectory ;
/**
- *
- * scriptPackName
+ * scriptFileName
* @parameter expression="custom-dependencies"
*/
private String scriptFileName;
@@ -132,7 +139,7 @@
private File outputStyleDirectory;
/**
- * stylePackName
+ * styleFileName
* @parameter expression="custom-dependencies"
*/
private String styleFileName;
@@ -227,17 +234,12 @@
*/
private String [] xhtmlExcludes;
- /**
- * @component
- */
- protected VelocityComponent velocity;
-
-
-
-
+
public void execute() throws MojoExecutionException, MojoFailureException {
+
try {
Set <Artifact> artifacts = resolveDependenciesArtifacts();
+
Digester defaultDigester = createDigester();
Map <String, Components> components = new HashMap<String, Components>();
@@ -251,9 +253,11 @@
FileObject [] configs = PluginUtils.resolveConfigsFromJar(jar, xmlConfigPatterns);
components.putAll(PluginUtils.processConfigs(configs, defaultDigester));
}
+
if(!webSourceDirectory.exists()) {
webSourceDirectory.mkdirs();
}
+
ComponentsHandler handler = findComponents(webSourceDirectory, components,
xhtmlIncludes, xhtmlExcludes);
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
@@ -267,21 +271,24 @@
File scriptFile = new File(outputScriptDirectory, scriptFileName + ".js");
if(!scripts.isEmpty()) {
+
if(!outputScriptDirectory.exists()) {
outputScriptDirectory.mkdirs();
}
+
ScriptAssembler scriptAssembler = new ScriptAssembler();
mergeResources(scriptFile, scriptAssembler, beforeScriptIncludes,
afterScriptIncludes, scripts);
- } else {
- if(scriptFile.exists()) {
- scriptFile.delete();
- }
+
+ } else if(scriptFile.exists()) {
+ scriptFile.delete();
}
Set <String> styles = handler.getStyles();
+
File styleFile = new File(outputStyleDirectory, styleFileName + ".xcss");
if(!styles.isEmpty()) {
+
if(!outputStyleDirectory.exists()) {
outputStyleDirectory.mkdirs();
}
@@ -289,15 +296,18 @@
StyleAssembler styleAssembler = new StyleAssembler();
styleAssembler.setVelocityComponent(velocity);
mergeResources(styleFile, styleAssembler, beforeStyleIncludes, afterStyleIncludes,
styles);
+
} else if(styleFile.exists()) {
styleFile.delete();
}
}
+
Thread.currentThread().setContextClassLoader(oldClassLoader);
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(),e);
}
+
}
public void mergeResources(File assembly, ResourceAssembler assembler, List
<String> beforeIncludes, List <String> afterIncludes, Collection<String>
resources) {
@@ -312,10 +322,14 @@
}
protected Set <Artifact> resolveDependenciesArtifacts() throws Exception {
+
ArtifactResolutionResult result = null;
+
List <Dependency> dependencies = project.getDependencies();
+
Set <Artifact> artifacts = MavenMetadataSource.createArtifacts(factory,
dependencies, null, null, project);
artifacts.add(project.getArtifact());
+
result = resolver.resolveTransitively(artifacts, project.getArtifact(),
Collections.EMPTY_LIST, localRepository, metadataSource);
return result.getArtifacts();
}
@@ -337,6 +351,7 @@
scanner.setExcludes(excludes);
scanner.addDefaultExcludes();
scanner.scan();
+
String [] collectedFiles = scanner.getIncludedFiles();
ComponentsHandler handler = new ComponentsHandler();
@@ -355,6 +370,7 @@
SAXParser saxParser = saxParserFactory.newSAXParser();
for(String processFile : collectedFiles) {
+
File file = new File(webSourceDir,processFile);
if(file.exists()) {
getLog().info("process file: " + file.getName());
@@ -370,7 +386,9 @@
protected FileObject resolveArtifact(Artifact artifact) {
FileObject jarFileObjects = null;
+
if(artifact != null) {
+
try {
resolver.resolve(artifact, Collections.EMPTY_LIST, localRepository);
getLog().info("artifact " + artifact.getFile().getAbsolutePath() + "
is resolved");
@@ -381,6 +399,7 @@
}
File file = artifact.getFile();
+
try {
FileSystemManager manager = VFS.getManager();
jarFileObjects = manager.resolveFile("jar://" + file.getAbsolutePath());
@@ -388,6 +407,7 @@
getLog().error("Error during processing file: " + file.getAbsolutePath()+
"\n" + e.getMessage(), e);
}
}
+
return jarFileObjects;
}
@@ -417,7 +437,6 @@
} catch (MalformedURLException e) {
getLog().error("Artifact url " + jar.getFile() + " is invalid");
}
-
}
// add project classes, scripts, styles etc ...
@@ -438,7 +457,9 @@
}
private void addResources(ClassRealm realm, List resources) {
+
if(realm != null && resources != null) {
+
for(Object path: resources) {
URL url = null;
String formatted = null;
@@ -459,6 +480,9 @@
realm.addConstituent(url);
}
}
+
}
+
}
+
}
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java 2009-02-05
14:19:20 UTC (rev 12577)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java 2009-02-05
14:23:57 UTC (rev 12578)
@@ -41,25 +41,31 @@
public static FileObject [] resolveConfigsFromJar(FileObject jarFileObject, String []
patterns) throws IOException{
FileObject [] result = new FileObject[0];
+
JarResourceScanner jarScanner = new JarResourceScanner();
jarScanner.setBaseFile(jarFileObject);
jarScanner.setPatterns(patterns);
jarScanner.doScan();
+
result = (FileObject [])jarScanner.getResult().toArray(new
FileObject[jarScanner.getResult().size()]);
return result;
}
public static Map <String,Components> processConfigs(FileObject [] configs,
Digester digester) throws SAXException, IOException {
Map <String, Components>collector = new HashMap <String, Components>();
+
for (FileObject config: configs) {
InputStream configInputStream = config.getContent().getInputStream();
+
try {
Components components = (Components)digester.parse(configInputStream);
collector.put(components.getNamespace(), components);
} finally {
configInputStream.close();
}
+
}
+
return collector;
}
@@ -72,6 +78,7 @@
digester.addCallMethod("components/component/scripts/script",
"addScript",0);
digester.addCallMethod("components/component/styles/style",
"addStyle",0);
digester.addSetNext("components/component", "addComponent");
+
return digester;
}
}