Author: Alex.Kolonitsky
Date: 2009-11-01 11:31:55 -0500 (Sun, 01 Nov 2009)
New Revision: 15794
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java
Log:
Code style policy
https://jira.jboss.org/jira/browse/RFPL-195
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java
===================================================================
---
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java 2009-11-01
16:30:05 UTC (rev 15793)
+++
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java 2009-11-01
16:31:55 UTC (rev 15794)
@@ -18,6 +18,9 @@
* 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.rd;
import java.util.ArrayList;
@@ -27,82 +30,96 @@
* @author Anton Belevich
*
*/
-public class Component implements Comparable<Component>{
-
- private String componentName;
-
- private List <String> scripts = new ArrayList<String>();
-
- private List <String> styles = new ArrayList<String>();
-
-
- public String getComponentName() {
- return componentName;
- }
+public class Component implements Comparable<Component> {
+ private List<String> scripts = new ArrayList<String>();
+ private List<String> styles = new ArrayList<String>();
+ private String componentName;
- public void setComponentName(String componentName) {
- this.componentName = componentName;
- }
-
- public void addScript(String script){
- scripts.add(script);
- }
-
- public void addStyle(String style){
- styles.add(style);
- }
-
- public List <String> getStyles() {
- return this.styles;
- }
-
- public List <String> getScripts() {
- return this.scripts;
- }
+ public String getComponentName() {
+ return componentName;
+ }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((componentName == null) ? 0 : componentName.hashCode());
- result = prime * result + ((scripts == null) ? 0 : scripts.hashCode());
- result = prime * result + ((styles == null) ? 0 : styles.hashCode());
- return result;
- }
+ public void setComponentName(String componentName) {
+ this.componentName = componentName;
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- final Component other = (Component) obj;
- if (componentName == null) {
- if (other.componentName != null)
- return false;
- } else if (!componentName.equals(other.componentName))
- return false;
- if (scripts == null) {
- if (other.scripts != null)
- return false;
- } else if (!scripts.equals(other.scripts))
- return false;
- if (styles == null) {
- if (other.styles != null)
- return false;
- } else if (!styles.equals(other.styles))
- return false;
- return true;
- }
+ public void addScript(String script) {
+ scripts.add(script);
+ }
- public int compareTo(Component o) {
- return componentName.compareToIgnoreCase(o.getComponentName());
- }
+ public void addStyle(String style) {
+ styles.add(style);
+ }
- @Override
- public String toString() {
- return "Component: " + componentName;
- }
+ public List<String> getStyles() {
+ return this.styles;
+ }
+
+ public List<String> getScripts() {
+ return this.scripts;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+
+ result = prime * result + ((componentName == null) ? 0 :
componentName.hashCode());
+ result = prime * result + ((scripts == null) ? 0 : scripts.hashCode());
+ result = prime * result + ((styles == null) ? 0 : styles.hashCode());
+
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ final Component other = (Component) obj;
+
+ if (componentName == null) {
+ if (other.componentName != null) {
+ return false;
+ }
+ } else if (!componentName.equals(other.componentName)) {
+ return false;
+ }
+
+ if (scripts == null) {
+ if (other.scripts != null) {
+ return false;
+ }
+ } else if (!scripts.equals(other.scripts)) {
+ return false;
+ }
+
+ if (styles == null) {
+ if (other.styles != null) {
+ return false;
+ }
+ } else if (!styles.equals(other.styles)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int compareTo(Component o) {
+ return componentName.compareToIgnoreCase(o.getComponentName());
+ }
+
+ @Override
+ public String toString() {
+ return "Component: " + componentName;
+ }
}
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java
===================================================================
---
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java 2009-11-01
16:30:05 UTC (rev 15793)
+++
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java 2009-11-01
16:31:55 UTC (rev 15794)
@@ -18,6 +18,9 @@
* 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.rd;
import java.util.ArrayList;
@@ -28,60 +31,73 @@
*
*/
public class Components {
-
- private String namespace;
-
- private List <Component> components = new ArrayList<Component> ();
+ private List<Component> components = new ArrayList<Component>();
+ private String namespace;
- public String getNamespace() {
- return namespace;
- }
+ public String getNamespace() {
+ return namespace;
+ }
- public void setNamespace(String namespace) {
- this.namespace = namespace;
- }
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
- public void addComponent(Component component) {
- components.add(component);
- }
-
- public List <Component> getComponents() {
- return this.components;
- }
+ public void addComponent(Component component) {
+ components.add(component);
+ }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((components == null) ? 0 : components.hashCode());
- result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
- return result;
- }
+ public List<Component> getComponents() {
+ return this.components;
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- final Components other = (Components) obj;
- if (components == null) {
- if (other.components != null)
- return false;
- } else if (!components.equals(other.components))
- return false;
- if (namespace == null) {
- if (other.namespace != null)
- return false;
- } else if (!namespace.equals(other.namespace))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "Components set: " + namespace;
- }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+
+ result = prime * result + ((components == null) ? 0 : components.hashCode());
+ result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
+
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ final Components other = (Components) obj;
+
+ if (components == null) {
+ if (other.components != null) {
+ return false;
+ }
+ } else if (!components.equals(other.components)) {
+ return false;
+ }
+
+ if (namespace == null) {
+ if (other.namespace != null) {
+ return false;
+ }
+ } else if (!namespace.equals(other.namespace)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "Components set: " + namespace;
+ }
}
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java
===================================================================
---
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java 2009-11-01
16:30:05 UTC (rev 15793)
+++
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java 2009-11-01
16:31:55 UTC (rev 15794)
@@ -18,80 +18,79 @@
* 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.rd;
import java.io.IOException;
+
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileType;
+
import org.codehaus.plexus.util.SelectorUtils;
-
+
/**
* @author Anton Belevich
*
*/
public class JarResourceScanner {
-
- private FileObject baseFile;
-
- private Set <FileObject> result = new HashSet <FileObject>();
-
- private String [] patterns = new String[] {"**"};
-
-
- public String[] getPatterns() {
- return patterns;
- }
+ private String[] patterns = new String[] {"**"};
+ private Set<FileObject> result = new HashSet<FileObject>();
+ private FileObject baseFile;
- public void setPatterns(String[] patterns) {
- this.patterns = patterns;
- }
+ public String[] getPatterns() {
+ return patterns;
+ }
- public FileObject getBaseFile() {
- return baseFile;
- }
+ public void setPatterns(String[] patterns) {
+ this.patterns = patterns;
+ }
- public void setBaseFile(FileObject baseFile) {
- this.baseFile = baseFile;
- }
-
- protected boolean isAcceptable(FileObject fileObject) {
-
- for (int i = 0; i < patterns.length; i++) {
- if(SelectorUtils.matchPath(patterns[i], fileObject.getName().getURI())) {
- return true;
- }
- }
-
- return false;
- }
+ public FileObject getBaseFile() {
+ return baseFile;
+ }
- 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);
- }
-
- }
- }
-
- public void doScan() throws IOException{
- if(baseFile != null && baseFile.exists()) {
- walk(baseFile);
- }
- }
+ public void setBaseFile(FileObject baseFile) {
+ this.baseFile = baseFile;
+ }
- public Set <FileObject> getResult() {
- return result;
- }
+ protected boolean isAcceptable(FileObject fileObject) {
+ for (int i = 0; i < patterns.length; i++) {
+ if (SelectorUtils.matchPath(patterns[i], fileObject.getName().getURI())) {
+ return true;
+ }
+ }
- public void setResult(Set <FileObject> result) {
- this.result = result;
- }
+ 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);
+ }
+ }
+ }
+
+ public void doScan() throws IOException {
+ if (baseFile != null && baseFile.exists()) {
+ walk(baseFile);
+ }
+ }
+
+ public Set<FileObject> getResult() {
+ return result;
+ }
+
+ public void setResult(Set<FileObject> result) {
+ this.result = result;
+ }
}
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java
===================================================================
---
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java 2009-11-01
16:30:05 UTC (rev 15793)
+++
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java 2009-11-01
16:31:55 UTC (rev 15794)
@@ -18,9 +18,13 @@
* 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.rd.generator;
import java.io.File;
+
import java.net.URL;
/**
@@ -28,9 +32,7 @@
*
*/
public interface ResourceAssembler {
-
- public void assembly(URL resource);
-
- public void writeToFile(File file);
-
+ public void assembly(URL resource);
+
+ public void writeToFile(File file);
}
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java
===================================================================
---
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java 2009-11-01
16:30:05 UTC (rev 15793)
+++
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java 2009-11-01
16:31:55 UTC (rev 15794)
@@ -18,12 +18,18 @@
* 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.rd.generator;
import java.io.File;
import java.io.IOException;
+
import java.lang.reflect.Method;
+
import java.net.URL;
+
import java.util.Collection;
import java.util.List;
@@ -34,129 +40,122 @@
*
*/
public class ResourcesGenerator {
-
- private File assemblyFile;
-
- private Log log;
-
- private Collection<String> resources;
-
- private List <String> includesBefore;
-
- private List <String> includesAfter;
-
- private ResourceAssembler assembler;
-
- public ResourcesGenerator(Log log) {
- this.log = log;
- }
+ private ResourceAssembler assembler;
+ private File assemblyFile;
+ private List<String> includesAfter;
+ private List<String> includesBefore;
+ private Log log;
+ private Collection<String> resources;
- public void doAssembly() {
- if(resources != null) {
- if(includesBefore != null && !includesBefore.isEmpty()) {
- iterate(includesBefore);
- }
-
- if(resources != null && !resources.isEmpty()) {
- iterate(resources);
- }
-
- if(includesAfter != null && !includesAfter.isEmpty()) {
- iterate(includesAfter);
- }
- }
- }
-
- private void iterate(Collection<String> resources) {
- for (String resourceName: resources) {
-
- URL resource = getResourceURL(resourceName);
- log.info("concatenate resource: " + resource);
- if(resource != null) {
- if (assembler != null) {
- assembler.assembly(resource);
- }
- }
-
- }
- }
-
- private URL getResourceURL(String resourceName) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- URL resource = classLoader.getResource(resourceName);
-
- try {
- if(resource == null) {
- //resolve framework script path
- 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);
- }
- } catch (Exception e) {
- log.error("Error process: " + resourceName + "\n" +
e.getMessage(), e);
- }
-
- return resource;
- }
-
- public void writeToFile() {
- if(assemblyFile != null) {
-
- if(assemblyFile.exists()) {
- assemblyFile.delete();
- }
-
- try {
- assemblyFile.createNewFile();
-
- } catch (IOException e) {
- log.error("Error create assembly File: " + assemblyFile.getPath(),e);
- }
-
- assembler.writeToFile(assemblyFile);
- }
- }
+ public ResourcesGenerator(Log log) {
+ this.log = log;
+ }
- public File getAssemblyFile() {
- return assemblyFile;
- }
+ public void doAssembly() {
+ if (resources != null) {
+ if (includesBefore != null && !includesBefore.isEmpty()) {
+ iterate(includesBefore);
+ }
- public void setAssemblyFile(File assemblyFile) {
- this.assemblyFile = assemblyFile;
- }
+ if (resources != null && !resources.isEmpty()) {
+ iterate(resources);
+ }
- public Collection<String> getResources() {
- return resources;
- }
+ if (includesAfter != null && !includesAfter.isEmpty()) {
+ iterate(includesAfter);
+ }
+ }
+ }
- public void setResources(Collection<String> resources) {
- this.resources = resources;
- }
+ private void iterate(Collection<String> resources) {
+ for (String resourceName : resources) {
+ URL resource = getResourceURL(resourceName);
- public List<String> getIncludesBefore() {
- return includesBefore;
- }
+ log.info("concatenate resource: " + resource);
- public void setIncludesBefore(List<String> includesBefore) {
- this.includesBefore = includesBefore;
- }
+ if (resource != null) {
+ if (assembler != null) {
+ assembler.assembly(resource);
+ }
+ }
+ }
+ }
- public List<String> getIncludesAfter() {
- return includesAfter;
- }
+ private URL getResourceURL(String resourceName) {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ URL resource = classLoader.getResource(resourceName);
- public void setIncludesAfter(List<String> includesAfter) {
- this.includesAfter = includesAfter;
- }
+ try {
+ if (resource == null) {
- public ResourceAssembler getAssembler() {
- return assembler;
- }
+ // resolve framework script path
+ 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]);
- public void setAssembler(ResourceAssembler assembler) {
- this.assembler = assembler;
- }
+ resource = classLoader.getResource(path);
+ }
+ } catch (Exception e) {
+ log.error("Error process: " + resourceName + "\n" +
e.getMessage(), e);
+ }
+
+ return resource;
+ }
+
+ public void writeToFile() {
+ if (assemblyFile != null) {
+ if (assemblyFile.exists()) {
+ assemblyFile.delete();
+ }
+
+ try {
+ assemblyFile.createNewFile();
+ } catch (IOException e) {
+ log.error("Error create assembly File: " +
assemblyFile.getPath(), e);
+ }
+
+ assembler.writeToFile(assemblyFile);
+ }
+ }
+
+ public File getAssemblyFile() {
+ return assemblyFile;
+ }
+
+ public void setAssemblyFile(File assemblyFile) {
+ this.assemblyFile = assemblyFile;
+ }
+
+ public Collection<String> getResources() {
+ return resources;
+ }
+
+ public void setResources(Collection<String> resources) {
+ this.resources = resources;
+ }
+
+ public List<String> getIncludesBefore() {
+ return includesBefore;
+ }
+
+ public void setIncludesBefore(List<String> includesBefore) {
+ this.includesBefore = includesBefore;
+ }
+
+ public List<String> getIncludesAfter() {
+ return includesAfter;
+ }
+
+ public void setIncludesAfter(List<String> includesAfter) {
+ this.includesAfter = includesAfter;
+ }
+
+ public ResourceAssembler getAssembler() {
+ return assembler;
+ }
+
+ public void setAssembler(ResourceAssembler assembler) {
+ this.assembler = assembler;
+ }
}
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java
===================================================================
---
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java 2009-11-01
16:30:05 UTC (rev 15793)
+++
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java 2009-11-01
16:31:55 UTC (rev 15794)
@@ -19,68 +19,67 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
+
package org.richfaces.cdk.rd.generator;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+
import java.net.URL;
import org.apache.maven.plugin.logging.Log;
+
import org.codehaus.plexus.util.IOUtil;
/**
* @author Anton Belevich
- *
+ *
*/
public class ScriptAssembler implements ResourceAssembler {
+ private StringBuilder builder = new StringBuilder();
+ protected Log log;
- protected Log log;
-
- private StringBuilder builder = new StringBuilder();
-
- public ScriptAssembler(Log log) {
- this.log = log;
- }
-
- public void assembly(URL resource) {
- InputStream inputStream = null;
- try {
- inputStream = resource.openStream();
- builder.append(IOUtil.toString(inputStream));
- builder.append("\n");
- } catch (IOException e) {
- log.error("Error read resource: " + resource.getFile());
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- log.error(e.getLocalizedMessage(), e);
- }
- }
- }
-
- }
+ public ScriptAssembler(Log log) {
+ this.log = log;
+ }
- public void writeToFile(File file) {
- if(builder.length() > 0) {
-
- try {
- FileWriter fileWriter = new FileWriter(file);
-
- try {
- log.info("write result to the: " + file.getPath());
- IOUtil.copy(builder.toString(), fileWriter);
- } finally {
- fileWriter.close();
- }
-
- } catch (IOException e) {
- log.error("Error write file: " + file.getAbsolutePath(),e);
- }
-
- }
- }
+ public void assembly(URL resource) {
+ InputStream inputStream = null;
+
+ try {
+ inputStream = resource.openStream();
+ builder.append(IOUtil.toString(inputStream));
+ builder.append("\n");
+ } catch (IOException e) {
+ log.error("Error read resource: " + resource.getFile());
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ log.error(e.getLocalizedMessage(), e);
+ }
+ }
+ }
+ }
+
+ public void writeToFile(File file) {
+ if (builder.length() > 0) {
+ try {
+ FileWriter fileWriter = new FileWriter(file);
+
+ try {
+ log.info("write result to the: " + file.getPath());
+ IOUtil.copy(builder.toString(), fileWriter);
+ } finally {
+ fileWriter.close();
+ }
+ } catch (IOException e) {
+ log.error("Error write file: " + file.getAbsolutePath(), e);
+ }
+ }
+ }
}
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
===================================================================
---
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java 2009-11-01
16:30:05 UTC (rev 15793)
+++
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java 2009-11-01
16:31:55 UTC (rev 15794)
@@ -18,12 +18,16 @@
* 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.rd.generator;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+
import java.net.URL;
import org.apache.maven.plugin.logging.Log;
@@ -31,96 +35,88 @@
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
+
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.velocity.VelocityComponent;
+
import org.richfaces.builder.config.ParsingException;
import org.richfaces.builder.xml.XMLBody;
-
/**
* @author Anton Belevich
*
*/
-
public class StyleAssembler implements ResourceAssembler {
-
- protected Log log = new SystemStreamLog();
-
- private VelocityComponent velocityComponent;
-
- private StringBuilder builder = new StringBuilder();
-
- public StyleAssembler(Log log) {
- this.log = log;
- }
-
- public void assembly(URL resource) {
-
- String file = resource.getFile();
-
- if(log.isDebugEnabled()) {
- log.debug("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();
- }
-
- } catch (IOException e) {
- log.error("Error process css file " + file + " : " +
e.getMessage(), e);
- }
- }
-
- public VelocityComponent getVelocityComponent() {
- return velocityComponent;
- }
+ protected Log log = new SystemStreamLog();
+ private StringBuilder builder = new StringBuilder();
+ private VelocityComponent velocityComponent;
- public void setVelocityComponent(VelocityComponent velocityComponent) {
- this.velocityComponent = velocityComponent;
- }
+ public StyleAssembler(Log log) {
+ this.log = log;
+ }
- 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);
- log.info("write result to the: " + file.getPath());
- try {
- Template velocityTemplate = engine.getTemplate("templates12/xcss.vm");
- velocityTemplate.merge(context, fileWriter);
- fileWriter.flush();
- } finally {
- fileWriter.close();
- }
-
- }
-
- } catch (Exception e) {
- log.error("Error write file: " + file.getAbsolutePath(),e);
- }
- }
-
+ public void assembly(URL resource) {
+ String file = resource.getFile();
+
+ if (log.isDebugEnabled()) {
+ log.debug("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();
+ }
+ } catch (IOException e) {
+ log.error("Error process css file " + file + " : " +
e.getMessage(), e);
+ }
+ }
+
+ public VelocityComponent getVelocityComponent() {
+ return velocityComponent;
+ }
+
+ public void setVelocityComponent(VelocityComponent velocityComponent) {
+ this.velocityComponent = velocityComponent;
+ }
+
+ 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);
+
+ log.info("write result to the: " + file.getPath());
+
+ try {
+ Template velocityTemplate =
engine.getTemplate("templates12/xcss.vm");
+
+ velocityTemplate.merge(context, fileWriter);
+ fileWriter.flush();
+ } finally {
+ fileWriter.close();
+ }
+ }
+ } catch (Exception e) {
+ log.error("Error write file: " + file.getAbsolutePath(), e);
+ }
+ }
}
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java
===================================================================
---
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java 2009-11-01
16:30:05 UTC (rev 15793)
+++
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java 2009-11-01
16:31:55 UTC (rev 15794)
@@ -18,13 +18,18 @@
* 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.rd.handler;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
+
import java.net.URL;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
@@ -33,9 +38,12 @@
import java.util.Set;
import org.apache.maven.plugin.logging.Log;
+
import org.codehaus.plexus.util.SelectorUtils;
+
import org.richfaces.cdk.rd.Component;
import org.richfaces.cdk.rd.Components;
+
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@@ -44,315 +52,295 @@
* @author Anton Belevich
*
*/
-public class ComponentsHandler extends DefaultHandler{
+public class ComponentsHandler extends DefaultHandler {
+ private static final String DEFAULT_DTD_PATH =
"org/richfaces/default.dtd";
+ private String[] INCLUDE_ALL_PATTERN = {"**"};
+ private Map<String, Set<String>> processedComponents = new
HashMap<String, Set<String>>();
+ private Set<String> scripts = new LinkedHashSet<String>();
+ private Set<String> styles = new LinkedHashSet<String>();
+ private String[] componentExcludes;
+ private String[] componentIncludes;
+ private Map<String, Components> components;
+ private String defaultDtdContent;
+ protected Log log;
+ private String[] namespaceExcludes;
+ private String[] namespaceIncludes;
+ private String[] scriptExcludes;
+ private String[] scriptIncludes;
+ private String[] styleExcludes;
+ private String[] styleIncludes;
- private String [] INCLUDE_ALL_PATTERN = {"**"};
+ public ComponentsHandler(Log log) {
+ this.log = log;
+ }
- protected Log log;
+ private Set<String> getProcessedComponentsSet(String uri) {
+ Set<String> result = processedComponents.get(uri);
- private Map <String, Components> components;
+ if (result == null) {
+ result = new HashSet<String>();
+ processedComponents.put(uri, result);
+ }
- private Map <String, Set<String>> processedComponents = new
HashMap<String, Set<String>>();
-
- private Set <String> scripts = new LinkedHashSet<String>();
+ return result;
+ }
- private Set <String> styles = new LinkedHashSet<String>();
+ @Override
+ public void endElement(String uri, String localName, String name) throws SAXException
{
+ if (components != null) {
+ Components library = components.get(uri);
- private String [] scriptIncludes;
+ if (library != null) {
+ Set<String> processedComponentsSet =
getProcessedComponentsSet(uri);
- private String [] scriptExcludes;
+ if (processedComponentsSet.add(localName)) {
+ if (namespaceIncludes == null) {
+ namespaceIncludes = INCLUDE_ALL_PATTERN;
- private String [] styleIncludes;
+ if (log.isDebugEnabled()) {
+ log.debug("use default include patterns for
namespaces");
+ }
+ }
- private String [] styleExcludes;
+ if (doMatch(namespaceIncludes, uri, true)) {
+ if (!doMatch(namespaceExcludes, uri, true)) {
+ List<Component> components = library.getComponents();
- private String [] namespaceIncludes;
+ if (componentIncludes == null) {
+ componentIncludes = INCLUDE_ALL_PATTERN;
- private String [] namespaceExcludes;
+ if (log.isDebugEnabled()) {
+ log.debug("use default include patterns for
components");
+ }
+ }
- private String [] componentIncludes;
+ if (doMatch(componentIncludes, localName, false)) {
+ if (!doMatch(componentExcludes, localName, false)) {
+ for (Component component : components) {
+ String componentName =
component.getComponentName();
- private String [] componentExcludes;
+ if (localName.equals(componentName)) {
+ log.info("process component: " +
componentName);
+ collectScripts(component);
+ collectStyles(component);
- public ComponentsHandler(Log log) {
- this.log = log;
- }
-
- private Set<String> getProcessedComponentsSet(String uri) {
- Set<String> result = processedComponents.get(uri);
- if (result == null) {
- result = new HashSet<String>();
- processedComponents.put(uri, result);
- }
-
- return result;
- }
-
- @Override
- public void endElement(String uri, String localName, String name) throws SAXException {
- if (components != null) {
+ break;
+ }
+ }
+ }
+ }
+ } else if (log.isDebugEnabled()) {
+ log.debug("components from namespace " + uri +
" are in excluded list");
+ }
+ } else if (log.isDebugEnabled()) {
+ log.debug("components from namespace " + uri + "
aren't in include list");
+ }
+ }
+ }
+ }
+ }
- Components library = components.get(uri);
- if (library != null) {
-
- Set<String> processedComponentsSet = getProcessedComponentsSet(uri);
- if (processedComponentsSet.add(localName)) {
- if (namespaceIncludes == null) {
- namespaceIncludes = INCLUDE_ALL_PATTERN;
+ private void collectStyles(Component component) {
+ if (styleIncludes == null) {
+ styleIncludes = INCLUDE_ALL_PATTERN;
+ }
- if (log.isDebugEnabled()) {
- log.debug("use default include patterns for namespaces");
- }
- }
+ if (log.isDebugEnabled()) {
+ log.debug("start collect styles from component: " +
component.getComponentName());
+ }
- if (doMatch(namespaceIncludes, uri, true)){
- if (!doMatch(namespaceExcludes, uri, true)) {
- List <Component> components = library.getComponents();
+ for (String style : component.getStyles()) {
+ if (doMatch(styleIncludes, style, true)) {
+ if (!doMatch(styleExcludes, style, true)) {
+ this.styles.add(style);
+ log.info("style " + style + " is collected");
+ } else {
+ log.info("style files are in excluded list");
- if (componentIncludes == null) {
- componentIncludes = INCLUDE_ALL_PATTERN;
+ for (String styleExclude : styleExcludes) {
+ log.info(styleExclude);
+ }
+ }
+ } else {
+ log.info("style files are not in included list");
- if(log.isDebugEnabled()) {
- log.debug("use default include patterns for components");
- }
- }
+ for (String styleInclude : styleIncludes) {
+ log.info(styleInclude);
+ }
+ }
+ }
+ }
- if (doMatch(componentIncludes, localName, false)) {
- if (!doMatch(componentExcludes, localName, false)) {
- for (Component component : components) {
+ private boolean doMatch(String[] patterns, String str, boolean matchPath) {
+ boolean allow = false;
- String componentName = component.getComponentName();
- if(localName.equals(componentName)) {
- log.info("process component: " + componentName);
+ if (patterns != null) {
+ for (String excludePattern : patterns) {
+ if (matchPath) {
+ allow = SelectorUtils.matchPath(excludePattern, str);
+ } else {
+ allow = SelectorUtils.match(excludePattern, str);
+ }
- collectScripts(component);
- collectStyles(component);
- break;
- }
- }
- }
- }
- } else if(log.isDebugEnabled()) {
- log.debug("components from namespace " + uri + " are in excluded
list");
- }
- } else if(log.isDebugEnabled()) {
- log.debug("components from namespace " + uri + " aren't in
include list");
- }
- }
- }
- }
- }
+ if (allow) {
+ break;
+ }
+ }
+ }
- private void collectStyles(Component component) {
+ return allow;
+ }
- if(styleIncludes == null) {
- styleIncludes = INCLUDE_ALL_PATTERN;
- }
+ private void collectScripts(Component component) {
+ if (scriptIncludes == null) {
+ scriptIncludes = INCLUDE_ALL_PATTERN;
+ }
- if(log.isDebugEnabled()) {
- log.debug("start collect styles from component: " +
component.getComponentName() );
- }
+ if (log.isDebugEnabled()) {
+ log.debug("start collect scripts from component: " +
component.getComponentName());
+ }
- for(String style : component.getStyles()) {
- if(doMatch(styleIncludes, style, true)) {
+ for (String script : component.getScripts()) {
+ if (doMatch(scriptIncludes, script, true)) {
+ if (!doMatch(scriptExcludes, script, true)) {
+ this.scripts.add(script);
+ log.info("script " + script + " is collected");
+ } else {
+ log.info("script files are in excluded list");
- if(!doMatch(styleExcludes, style, true)) {
- this.styles.add(style);
- log.info("style " + style + " is collected");
- } else {
- log.info("style files are in excluded list");
- for(String styleExclude: styleExcludes) {
- log.info(styleExclude);
- }
- }
+ for (String styleExclude : scriptExcludes) {
+ log.info(styleExclude);
+ }
+ }
+ } else {
+ log.info("script files are not in included list");
- } else {
- log.info("style files are not in included list");
- for(String styleInclude: styleIncludes) {
- log.info(styleInclude);
- }
- }
+ for (String styleInclude : scriptIncludes) {
+ log.info(styleInclude);
+ }
+ }
+ }
+ }
- }
- }
+ public Set<String> getStyles() {
+ return this.styles;
+ }
- private boolean doMatch(String [] patterns, String str, boolean matchPath) {
- boolean allow = false;
+ public Set<String> getScripts() {
+ return this.scripts;
+ }
- if(patterns != null) {
+ public Map<String, Components> getComponents() {
+ return components;
+ }
- for(String excludePattern: patterns) {
+ public void setComponents(Map<String, Components> components) {
+ this.components = components;
+ }
- if(matchPath) {
- allow = SelectorUtils.matchPath(excludePattern, str);
- } else {
- allow = SelectorUtils.match(excludePattern, str);
- }
+ public String[] getNamespaceExcludes() {
+ return namespaceExcludes;
+ }
- if(allow) break;
- }
+ public void setNamespaceExcludes(String[] namespaceExcludes) {
+ this.namespaceExcludes = namespaceExcludes;
+ }
- }
+ public String[] getComponentExcludes() {
+ return componentExcludes;
+ }
- return allow;
- }
+ public void setComponentExcludes(String[] componentExcludes) {
+ this.componentExcludes = componentExcludes;
+ }
- private void collectScripts(Component component) {
+ public String[] getScriptExcludes() {
+ return scriptExcludes;
+ }
- if (scriptIncludes == null) {
- scriptIncludes = INCLUDE_ALL_PATTERN;
- }
+ public void setScriptExcludes(String[] scriptExcludes) {
+ this.scriptExcludes = scriptExcludes;
+ }
- if (log.isDebugEnabled()) {
- log.debug("start collect scripts from component: " +
component.getComponentName() );
- }
+ public String[] getStyleExcludes() {
+ return styleExcludes;
+ }
- for (String script : component.getScripts()) {
+ public void setStyleExcludes(String[] styleExcludes) {
+ this.styleExcludes = styleExcludes;
+ }
- if (doMatch(scriptIncludes, script, true)) {
- if (!doMatch(scriptExcludes, script, true)) {
- this.scripts.add(script);
- log.info("script " + script + " is collected");
- } else {
- log.info("script files are in excluded list");
- for(String styleExclude: scriptExcludes) {
- log.info(styleExclude);
- }
- }
+ public String[] getScriptIncludes() {
+ return scriptIncludes;
+ }
- } else {
- log.info("script files are not in included list");
- for(String styleInclude: scriptIncludes) {
- log.info(styleInclude);
- }
- }
- }
- }
+ public void setScriptIncludes(String[] scriptIncludes) {
+ this.scriptIncludes = scriptIncludes;
+ }
- public Set <String> getStyles() {
- return this.styles;
- }
+ public String[] getStyleIncludes() {
+ return styleIncludes;
+ }
- public Set <String> getScripts() {
- return this.scripts;
- }
+ public void setStyleIncludes(String[] styleIncludes) {
+ this.styleIncludes = styleIncludes;
+ }
- public Map <String, Components> getComponents() {
- return components;
- }
+ public String[] getNamespaceIncludes() {
+ return namespaceIncludes;
+ }
- public void setComponents(Map <String, Components> components) {
- this.components = components;
- }
+ public void setNamespaceIncludes(String[] namespaceIncludes) {
+ this.namespaceIncludes = namespaceIncludes;
+ }
- public String[] getNamespaceExcludes() {
- return namespaceExcludes;
- }
+ public String[] getComponentIncludes() {
+ return componentIncludes;
+ }
- public void setNamespaceExcludes(String[] namespaceExcludes) {
- this.namespaceExcludes = namespaceExcludes;
- }
+ public void setComponentIncludes(String[] componentIncludes) {
+ this.componentIncludes = componentIncludes;
+ }
- public String[] getComponentExcludes() {
- return componentExcludes;
- }
+ private String readDtdContent(String path) throws IOException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource(path);
- public void setComponentExcludes(String[] componentExcludes) {
- this.componentExcludes = componentExcludes;
- }
+ if (url == null) {
+ url = getClass().getClassLoader().getResource(path);
+ }
- public String [] getScriptExcludes() {
- return scriptExcludes;
- }
+ Reader reader = new InputStreamReader(url.openStream());
+ String dtdContent;
- public void setScriptExcludes(String [] scriptExcludes) {
- this.scriptExcludes = scriptExcludes;
- }
+ try {
+ StringBuilder builder = new StringBuilder(32);
+ char[] cs = new char[512];
+ int read;
- public String [] getStyleExcludes() {
- return styleExcludes;
- }
+ while ((read = reader.read(cs)) != -1) {
+ builder.append(cs, 0, read);
+ }
- public void setStyleExcludes(String [] styleExcludes) {
- this.styleExcludes = styleExcludes;
- }
+ dtdContent = builder.toString();
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ log.error(e.getLocalizedMessage(), e);
+ }
+ }
+ }
- public String[] getScriptIncludes() {
- return scriptIncludes;
- }
+ return dtdContent;
+ }
- public void setScriptIncludes(String[] scriptIncludes) {
- this.scriptIncludes = scriptIncludes;
- }
+ @Override
+ public InputSource resolveEntity(String publicId, String systemId) throws
IOException, SAXException {
+ if (defaultDtdContent == null) {
+ defaultDtdContent = readDtdContent(DEFAULT_DTD_PATH);
+ }
- public String[] getStyleIncludes() {
- return styleIncludes;
- }
-
- public void setStyleIncludes(String[] styleIncludes) {
- this.styleIncludes = styleIncludes;
- }
-
- public String[] getNamespaceIncludes() {
- return namespaceIncludes;
- }
-
- public void setNamespaceIncludes(String[] namespaceIncludes) {
- this.namespaceIncludes = namespaceIncludes;
- }
-
- public String[] getComponentIncludes() {
- return componentIncludes;
- }
-
- public void setComponentIncludes(String[] componentIncludes) {
- this.componentIncludes = componentIncludes;
- }
-
- private static final String DEFAULT_DTD_PATH = "org/richfaces/default.dtd";
-
- private String defaultDtdContent;
-
- private String readDtdContent(String path) throws IOException {
- URL url = Thread.currentThread().getContextClassLoader().getResource(path);
- if (url == null) {
- url = getClass().getClassLoader().getResource(path);
- }
-
- Reader reader = new InputStreamReader(url.openStream());
- String dtdContent;
-
- try {
- StringBuilder builder = new StringBuilder(32);
- char[] cs = new char[512];
- int read;
-
- while ((read = reader.read(cs)) != -1) {
- builder.append(cs, 0, read);
- }
-
- dtdContent = builder.toString();
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- log.error(e.getLocalizedMessage(), e);
- }
- }
- }
-
- return dtdContent;
- }
-
- @Override
- public InputSource resolveEntity(String publicId, String systemId)
- throws IOException, SAXException {
-
- if (defaultDtdContent == null) {
- defaultDtdContent = readDtdContent(DEFAULT_DTD_PATH);
- }
-
- return new InputSource(new StringReader(defaultDtdContent));
- }
+ return new InputSource(new StringReader(defaultDtdContent));
+ }
}
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
===================================================================
---
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-11-01
16:30:05 UTC (rev 15793)
+++
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-11-01
16:31:55 UTC (rev 15794)
@@ -18,11 +18,16 @@
* 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.rd.mojo;
import java.io.File;
+
import java.net.MalformedURLException;
import java.net.URL;
+
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -54,10 +59,12 @@
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.MavenMetadataSource;
+
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.velocity.VelocityComponent;
+
import org.richfaces.cdk.rd.Components;
import org.richfaces.cdk.rd.generator.ResourceAssembler;
import org.richfaces.cdk.rd.generator.ResourcesGenerator;
@@ -70,451 +77,457 @@
* @author Anton Belevich
* @goal assembly-resources
* @phase generate-resources
- *
+ *
*/
-public class ResourceDependencyMojo extends AbstractMojo {
+public class ResourceDependencyMojo extends AbstractMojo {
- /**
- * Top maven project.
- *
- * @parameter expression="${project}"
- * @readonly
- */
- MavenProject project;
-
- /**
- * Used to look up Artifacts in the remote repository.
- *
- * @component
- */
- private ArtifactFactory factory;
-
- /**
- * Used to look up Artifacts in the remote repository.
- *
- * @component
- */
- private ArtifactResolver resolver;
-
- /**
- *
- * @component
- */
- private ArtifactMetadataSource metadataSource;
-
- /**
- * @component
- */
- protected VelocityComponent velocity;
-
- /**
- * The local repository.
- *
- * @parameter expression="${localRepository}"
- */
- private ArtifactRepository localRepository;
-
- /**
- * webSourceDirectory
- *
- * @parameter expression="${basedir}/src/main/webapp"
- */
- private File webSourceDirectory;
-
- /**
- * scriptFilePath
- * @parameter expression="custom-dependencies"
- */
- private String scriptFilePath;
-
-
- /**
- * outputResourceDirectory
- * @parameter expression="${project.build.directory}/generated-resources
- *
- */
- private File outputResourceDirectory;
- /**
- * styleFilePath
- * @parameter expression="custom-dependencies"
- */
- private String styleFilePath;
-
- /**
- * beforeScriptIncludes
- * @parameter
- */
- private List <String> beforeScriptIncludes;
-
- /**
- * afterScriptIncludes
- * @parameter
- */
- private List <String> afterScriptIncludes;
-
- /**
- * beforeStyleIncludes
- * @parameter
- */
- private List <String> beforeStyleIncludes;
-
- /**
- * afterStyleIncludes
- * @parameter
- */
- private List <String> afterStyleIncludes;
-
- /**
- * scriptIncludes
- * @parameter
- */
- private String [] scriptIncludes;
-
- /**
- * scriptExcludes
- * @parameter
- */
- private String [] scriptExcludes;
-
- /**
- * styleIncludes
- * @parameter
- */
- private String [] styleIncludes;
-
- /**
- * styleExcludes
- * @parameter
- */
- private String [] styleExcludes;
-
- /**
- * namespaceIncludes
- * @parameter
- */
- private String [] namespaceIncludes;
-
- /**
- * namespaceExcludes
- * @parameter
- */
- private String [] namespaceExcludes;
-
- /**
- * componentIncludes
- * @parameter
- */
- private String [] componentIncludes;
-
- /**
- * componentExcludes
- * @parameter
- */
- private String [] componentExcludes;
-
- /**
- * xmlConfigPatterns
- * @parameter
- */
- private String [] xmlConfigPatterns;
-
- /**
- * xhtmlIncludes
- * @parameter
- */
- private String [] xhtmlIncludes;
-
- /**
- * xhtmlExcludes
- * @parameter
- */
- private String [] xhtmlExcludes;
-
-
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- try {
- Set <Artifact> artifacts = resolveDependenciesArtifacts();
-
- Digester defaultDigester = createDigester();
-
- Map <String, Components> components = new HashMap<String, Components>();
-
- if(xmlConfigPatterns == null) {
- xmlConfigPatterns = PluginUtils.DEFAULT_CONFIG_PATTERNS;
- }
-
- for (Artifact artifact : artifacts) {
- FileObject jar = resolveArtifact(artifact);
- getLog().info("Process jar: " + jar.getName().getFriendlyURI());
- FileObject [] configs = PluginUtils.resolveConfigsFromJar(jar, xmlConfigPatterns);
-
- if(configs.length == 0) {
- getLog().info("no dependecy files found");
- } else {
- getLog().info("next dependency files found");
- for (FileObject config: configs) {
- getLog().info(config.getName().getBaseName());
- }
- }
-
- components.putAll(PluginUtils.processConfigs(configs, defaultDigester));
- }
-
- if(!webSourceDirectory.exists()) {
- webSourceDirectory.mkdirs();
- }
-
- ComponentsHandler handler = findComponents(webSourceDirectory, components,
xhtmlIncludes, xhtmlExcludes);
-
- ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
- ClassLoader contextClassLoader = createClassLoader();
- Thread.currentThread().setContextClassLoader(contextClassLoader);
-
- if(contextClassLoader != null) {
-
- Set <String> scripts = handler.getScripts();
-
- scriptFilePath = scriptFilePath.endsWith(".js") ? scriptFilePath :
scriptFilePath + ".js";
- File scriptFile = new File(outputResourceDirectory, scriptFilePath);
- if(!scriptFile.exists()) {
- File parent = scriptFile.getParentFile();
- if(parent != null && !parent.exists()) {
- parent.mkdirs();
- }
- }
-
- ScriptAssembler scriptAssembler = new ScriptAssembler(getLog());
-
- if(!scripts.isEmpty()) {
- getLog().info("Start merge scripts to the: " + scriptFile.getPath());
- mergeResources(scriptFile,scriptAssembler, beforeScriptIncludes,
afterScriptIncludes, scripts);
- }
-
- Set <String> styles = handler.getStyles();
-
- styleFilePath = styleFilePath.endsWith(".xcss") ? styleFilePath :
styleFilePath + ".xcss";
-
- File styleFile = new File(outputResourceDirectory, styleFilePath);
- File parent = styleFile.getParentFile();
- if(parent != null && !parent.exists()) {
- parent.mkdirs();
- }
+ /**
+ * afterScriptIncludes
+ * @parameter
+ */
+ private List<String> afterScriptIncludes;
- StyleAssembler styleAssembler = new StyleAssembler(getLog());
- styleAssembler.setVelocityComponent(velocity);
-
- if(!styles.isEmpty()) {
- getLog().info("Start merge styles to the: " + styleFile.getPath());
- mergeResources(styleFile,styleAssembler, beforeStyleIncludes, afterStyleIncludes,
styles);
- }
-
- Resource resource = new Resource();
- resource.setDirectory(outputResourceDirectory.getPath());
- project.addResource(resource);
- }
-
- Thread.currentThread().setContextClassLoader(oldClassLoader);
+ /**
+ * afterStyleIncludes
+ * @parameter
+ */
+ private List<String> afterStyleIncludes;
- } catch (Exception e) {
- getLog().error("Error generate resource", e);
- throw new MojoExecutionException(e.getMessage(),e);
- }
-
- }
-
- public void mergeResources(File assembly, ResourceAssembler assembler, List
<String> beforeIncludes, List <String> afterIncludes, Collection<String>
resources) {
- ResourcesGenerator styleGenerator = new ResourcesGenerator(getLog());
- styleGenerator.setAssembler(assembler);
- styleGenerator.setIncludesAfter(afterIncludes);
- styleGenerator.setIncludesBefore(beforeIncludes);
- styleGenerator.setResources(resources);
- styleGenerator.setAssemblyFile(assembly);
- styleGenerator.doAssembly();
- styleGenerator.writeToFile();
- }
-
- protected Set <Artifact> resolveDependenciesArtifacts() throws Exception {
-
- ArtifactResolutionResult result = null;
+ /**
+ * beforeScriptIncludes
+ * @parameter
+ */
+ private List<String> beforeScriptIncludes;
- 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();
- }
-
-
- public ComponentsHandler findComponents (File webSourceDir, Map <String,
Components> components, String [] includes, String [] excludes) throws Exception {
-
- if(includes == null) {
- includes = PluginUtils.DEFAULT_PROCESS_INCLUDES;
- }
-
- if(excludes == null) {
- excludes = new String[0];
- }
-
- DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir(webSourceDir);
- scanner.setIncludes(includes);
- scanner.setExcludes(excludes);
- scanner.addDefaultExcludes();
- getLog().info("search *.xhtml files");
- scanner.scan();
-
- String [] collectedFiles = scanner.getIncludedFiles();
-
- for(String collectedFile: collectedFiles) {
- getLog().info(collectedFile + " found");
- }
+ /**
+ * beforeStyleIncludes
+ * @parameter
+ */
+ private List<String> beforeStyleIncludes;
- ComponentsHandler handler = new ComponentsHandler(getLog());
- handler.setComponents(components);
- handler.setScriptIncludes(scriptIncludes);
- handler.setScriptExcludes(scriptExcludes);
- handler.setStyleIncludes(styleIncludes);
- handler.setStyleExcludes(styleExcludes);
- handler.setComponentIncludes(componentIncludes);
- handler.setComponentExcludes(componentExcludes);
- handler.setNamespaceIncludes(namespaceIncludes);
- handler.setNamespaceExcludes(namespaceExcludes);
+ /**
+ * componentExcludes
+ * @parameter
+ */
+ private String[] componentExcludes;
- SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
- saxParserFactory.setNamespaceAware(true);
-
- Log log = getLog();
- for (String processFile : collectedFiles) {
- SAXParser saxParser = saxParserFactory.newSAXParser();
- File file = new File(webSourceDir,processFile);
- if (file.exists()) {
-
- if (log.isDebugEnabled()) {
- log.debug("start process file: " + file.getPath());
- }
-
- try {
- saxParser.parse(file, handler);
- } catch (Exception e) {
- if (log.isDebugEnabled()) {
- log.error("Error process file: " + file.getPath() + "\n" +
e.getMessage(), e);
- } else {
- log.error("Error process file: " + file.getPath() + "\n" +
e.getMessage());
- }
- }
- }
- }
-
- return handler;
- }
-
- protected FileObject resolveArtifact(Artifact artifact) {
- FileObject jarFileObjects = null;
-
- if(artifact != null) {
-
- try {
- resolver.resolve(artifact, Collections.EMPTY_LIST, localRepository);
- if(getLog().isDebugEnabled()) {
- getLog().debug("artifact " + artifact.getFile().toURI() + " is
resolved");
- }
- } catch (ArtifactResolutionException e) {
- getLog().error("Error with resolve artifact " +
artifact.getFile().getPath() + "\n" + e.getMessage(), e);
- } catch (ArtifactNotFoundException e) {
- getLog().error("Not found artifact " + artifact.getFile().toURI() +
"\n" + e.getMessage(), e);
- }
-
- File file = artifact.getFile();
-
- try {
- FileSystemManager manager = VFS.getManager();
- jarFileObjects = manager.resolveFile("jar:" + file.toURI());
- } catch (FileSystemException e) {
- getLog().error("Error during processing file: " + file.toURI()+
"\n" + e.getMessage(), e);
- }
-
- }
-
- return jarFileObjects;
- }
-
- public Digester createDigester() {
- // default digester for *.component-dependencies.xml
- return PluginUtils.createDefaultDigester();
- }
-
- protected ClassLoader createClassLoader() throws Exception {
-
- ClassLoader classLoader = null;
-
- Set <Artifact> artifacts = resolveDependenciesArtifacts();
-
- //create a new classloading space
- ClassWorld world = new ClassWorld();
-
- //use the existing ContextClassLoader in a realm of the classloading space
- ClassRealm realm = world.newRealm("org.richfaces.cdk",
Thread.currentThread().getContextClassLoader());
-
- //create another realm for the app jars
- ClassRealm childRealm = realm.createChildRealm("jar");
-
- for(Artifact jar : artifacts ) {
- try {
- childRealm.addConstituent(jar.getFile().toURL());
- } catch (MalformedURLException e) {
- getLog().error("Artifact url " + jar.getFile() + " is invalid");
- }
- }
-
- // add project classes, scripts, styles etc ...
- List<Resource> compileClasspathElements = project.getCompileClasspathElements();
- addResources(childRealm, compileClasspathElements);
-
- List<Resource> scripts = project.getScriptSourceRoots();
- addResources(childRealm, scripts);
-
- List<Resource> resources = project.getResources();
- addResources(childRealm, resources);
-
- childRealm.addConstituent(webSourceDirectory.toURI().toURL());
-
- //make the child realm the ContextClassLoader
- classLoader = childRealm.getClassLoader();
- return classLoader;
- }
-
- private void addResources(ClassRealm realm, List resources) {
-
- if(realm != null && resources != null) {
-
- for(Object path: resources) {
- URL url = null;
- String formatted = null;
-
- if (path instanceof String) {
- formatted = (String)path;
- } else if(path instanceof Resource) {
- formatted = ((Resource)path).getDirectory();
- }
-
- if (formatted != null) {
- File file = new File(formatted);
-
- try {
- url = file.toURI().toURL();
- } catch (MalformedURLException e) {
- getLog().error("Resource url " + file.getPath() + " is
invalid");
- }
-
- realm.addConstituent(url);
- }
- }
-
- }
-
- }
-
-}
+ /**
+ * componentIncludes
+ * @parameter
+ */
+ private String[] componentIncludes;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @component
+ */
+ private ArtifactFactory factory;
+
+ /**
+ * The local repository.
+ *
+ * @parameter expression="${localRepository}"
+ */
+ private ArtifactRepository localRepository;
+
+ /**
+ *
+ * @component
+ */
+ private ArtifactMetadataSource metadataSource;
+
+ /**
+ * namespaceExcludes
+ * @parameter
+ */
+ private String[] namespaceExcludes;
+
+ /**
+ * namespaceIncludes
+ * @parameter
+ */
+ private String[] namespaceIncludes;
+
+ /**
+ * outputResourceDirectory
+ * @parameter expression="${project.build.directory}/generated-resources
+ *
+ */
+ private File outputResourceDirectory;
+
+ /**
+ * Top maven project.
+ *
+ * @parameter expression="${project}"
+ * @readonly
+ */
+ MavenProject project;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @component
+ */
+ private ArtifactResolver resolver;
+
+ /**
+ * scriptExcludes
+ * @parameter
+ */
+ private String[] scriptExcludes;
+
+ /**
+ * scriptFilePath
+ * @parameter expression="custom-dependencies"
+ */
+ private String scriptFilePath;
+
+ /**
+ * scriptIncludes
+ * @parameter
+ */
+ private String[] scriptIncludes;
+
+ /**
+ * styleExcludes
+ * @parameter
+ */
+ private String[] styleExcludes;
+
+ /**
+ * styleFilePath
+ * @parameter expression="custom-dependencies"
+ */
+ private String styleFilePath;
+
+ /**
+ * styleIncludes
+ * @parameter
+ */
+ private String[] styleIncludes;
+
+ /**
+ * @component
+ */
+ protected VelocityComponent velocity;
+
+ /**
+ * webSourceDirectory
+ *
+ * @parameter expression="${basedir}/src/main/webapp"
+ */
+ private File webSourceDirectory;
+
+ /**
+ * xhtmlExcludes
+ * @parameter
+ */
+ private String[] xhtmlExcludes;
+
+ /**
+ * xhtmlIncludes
+ * @parameter
+ */
+ private String[] xhtmlIncludes;
+
+ /**
+ * xmlConfigPatterns
+ * @parameter
+ */
+ private String[] xmlConfigPatterns;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ try {
+ Set<Artifact> artifacts = resolveDependenciesArtifacts();
+ Digester defaultDigester = createDigester();
+ Map<String, Components> components = new HashMap<String,
Components>();
+
+ if (xmlConfigPatterns == null) {
+ xmlConfigPatterns = PluginUtils.DEFAULT_CONFIG_PATTERNS;
+ }
+
+ for (Artifact artifact : artifacts) {
+ FileObject jar = resolveArtifact(artifact);
+
+ getLog().info("Process jar: " +
jar.getName().getFriendlyURI());
+
+ FileObject[] configs = PluginUtils.resolveConfigsFromJar(jar,
xmlConfigPatterns);
+
+ if (configs.length == 0) {
+ getLog().info("no dependecy files found");
+ } else {
+ getLog().info("next dependency files found");
+
+ for (FileObject config : configs) {
+ getLog().info(config.getName().getBaseName());
+ }
+ }
+
+ components.putAll(PluginUtils.processConfigs(configs, defaultDigester));
+ }
+
+ if (!webSourceDirectory.exists()) {
+ webSourceDirectory.mkdirs();
+ }
+
+ ComponentsHandler handler = findComponents(webSourceDirectory, components,
xhtmlIncludes, xhtmlExcludes);
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader contextClassLoader = createClassLoader();
+
+ Thread.currentThread().setContextClassLoader(contextClassLoader);
+
+ if (contextClassLoader != null) {
+ Set<String> scripts = handler.getScripts();
+
+ scriptFilePath = scriptFilePath.endsWith(".js") ?
scriptFilePath : scriptFilePath + ".js";
+
+ File scriptFile = new File(outputResourceDirectory, scriptFilePath);
+
+ if (!scriptFile.exists()) {
+ File parent = scriptFile.getParentFile();
+
+ if (parent != null && !parent.exists()) {
+ parent.mkdirs();
+ }
+ }
+
+ ScriptAssembler scriptAssembler = new ScriptAssembler(getLog());
+
+ if (!scripts.isEmpty()) {
+ getLog().info("Start merge scripts to the: " +
scriptFile.getPath());
+ mergeResources(scriptFile, scriptAssembler, beforeScriptIncludes,
afterScriptIncludes, scripts);
+ }
+
+ Set<String> styles = handler.getStyles();
+
+ styleFilePath = styleFilePath.endsWith(".xcss") ? styleFilePath
: styleFilePath + ".xcss";
+
+ File styleFile = new File(outputResourceDirectory, styleFilePath);
+ File parent = styleFile.getParentFile();
+
+ if (parent != null && !parent.exists()) {
+ parent.mkdirs();
+ }
+
+ StyleAssembler styleAssembler = new StyleAssembler(getLog());
+
+ styleAssembler.setVelocityComponent(velocity);
+
+ if (!styles.isEmpty()) {
+ getLog().info("Start merge styles to the: " +
styleFile.getPath());
+ mergeResources(styleFile, styleAssembler, beforeStyleIncludes,
afterStyleIncludes, styles);
+ }
+
+ Resource resource = new Resource();
+
+ resource.setDirectory(outputResourceDirectory.getPath());
+ project.addResource(resource);
+ }
+
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
+ } catch (Exception e) {
+ getLog().error("Error generate resource", e);
+
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+
+ public void mergeResources(File assembly, ResourceAssembler assembler,
List<String> beforeIncludes,
+ List<String> afterIncludes, Collection<String>
resources) {
+ ResourcesGenerator styleGenerator = new ResourcesGenerator(getLog());
+
+ styleGenerator.setAssembler(assembler);
+ styleGenerator.setIncludesAfter(afterIncludes);
+ styleGenerator.setIncludesBefore(beforeIncludes);
+ styleGenerator.setResources(resources);
+ styleGenerator.setAssemblyFile(assembly);
+ styleGenerator.doAssembly();
+ styleGenerator.writeToFile();
+ }
+
+ 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();
+ }
+
+ public ComponentsHandler findComponents(File webSourceDir, Map<String,
Components> components, String[] includes,
+ String[] excludes)
+ throws Exception {
+ if (includes == null) {
+ includes = PluginUtils.DEFAULT_PROCESS_INCLUDES;
+ }
+
+ if (excludes == null) {
+ excludes = new String[0];
+ }
+
+ DirectoryScanner scanner = new DirectoryScanner();
+
+ scanner.setBasedir(webSourceDir);
+ scanner.setIncludes(includes);
+ scanner.setExcludes(excludes);
+ scanner.addDefaultExcludes();
+ getLog().info("search *.xhtml files");
+ scanner.scan();
+
+ String[] collectedFiles = scanner.getIncludedFiles();
+
+ for (String collectedFile : collectedFiles) {
+ getLog().info(collectedFile + " found");
+ }
+
+ ComponentsHandler handler = new ComponentsHandler(getLog());
+
+ handler.setComponents(components);
+ handler.setScriptIncludes(scriptIncludes);
+ handler.setScriptExcludes(scriptExcludes);
+ handler.setStyleIncludes(styleIncludes);
+ handler.setStyleExcludes(styleExcludes);
+ handler.setComponentIncludes(componentIncludes);
+ handler.setComponentExcludes(componentExcludes);
+ handler.setNamespaceIncludes(namespaceIncludes);
+ handler.setNamespaceExcludes(namespaceExcludes);
+
+ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+
+ saxParserFactory.setNamespaceAware(true);
+
+ Log log = getLog();
+
+ for (String processFile : collectedFiles) {
+ SAXParser saxParser = saxParserFactory.newSAXParser();
+ File file = new File(webSourceDir, processFile);
+
+ if (file.exists()) {
+ if (log.isDebugEnabled()) {
+ log.debug("start process file: " + file.getPath());
+ }
+
+ try {
+ saxParser.parse(file, handler);
+ } catch (Exception e) {
+ if (log.isDebugEnabled()) {
+ log.error("Error process file: " + file.getPath() +
"\n" + e.getMessage(), e);
+ } else {
+ log.error("Error process file: " + file.getPath() +
"\n" + e.getMessage());
+ }
+ }
+ }
+ }
+
+ return handler;
+ }
+
+ protected FileObject resolveArtifact(Artifact artifact) {
+ FileObject jarFileObjects = null;
+
+ if (artifact != null) {
+ try {
+ resolver.resolve(artifact, Collections.EMPTY_LIST, localRepository);
+
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("artifact " + artifact.getFile().toURI() +
" is resolved");
+ }
+ } catch (ArtifactResolutionException e) {
+ getLog().error("Error with resolve artifact " +
artifact.getFile().getPath() + "\n" + e.getMessage(),
+ e);
+ } catch (ArtifactNotFoundException e) {
+ getLog().error("Not found artifact " +
artifact.getFile().toURI() + "\n" + e.getMessage(), e);
+ }
+
+ File file = artifact.getFile();
+
+ try {
+ FileSystemManager manager = VFS.getManager();
+
+ jarFileObjects = manager.resolveFile("jar:" + file.toURI());
+ } catch (FileSystemException e) {
+ getLog().error("Error during processing file: " + file.toURI()
+ "\n" + e.getMessage(), e);
+ }
+ }
+
+ return jarFileObjects;
+ }
+
+ public Digester createDigester() {
+
+ // default digester for *.component-dependencies.xml
+ return PluginUtils.createDefaultDigester();
+ }
+
+ protected ClassLoader createClassLoader() throws Exception {
+ ClassLoader classLoader = null;
+ Set<Artifact> artifacts = resolveDependenciesArtifacts();
+
+ // create a new classloading space
+ ClassWorld world = new ClassWorld();
+
+ // use the existing ContextClassLoader in a realm of the classloading space
+ ClassRealm realm = world.newRealm("org.richfaces.cdk",
Thread.currentThread().getContextClassLoader());
+
+ // create another realm for the app jars
+ ClassRealm childRealm = realm.createChildRealm("jar");
+
+ for (Artifact jar : artifacts) {
+ try {
+ childRealm.addConstituent(jar.getFile().toURL());
+ } catch (MalformedURLException e) {
+ getLog().error("Artifact url " + jar.getFile() + " is
invalid");
+ }
+ }
+
+ // add project classes, scripts, styles etc ...
+ List<Resource> compileClasspathElements =
project.getCompileClasspathElements();
+
+ addResources(childRealm, compileClasspathElements);
+
+ List<Resource> scripts = project.getScriptSourceRoots();
+
+ addResources(childRealm, scripts);
+
+ List<Resource> resources = project.getResources();
+
+ addResources(childRealm, resources);
+ childRealm.addConstituent(webSourceDirectory.toURI().toURL());
+
+ // make the child realm the ContextClassLoader
+ classLoader = childRealm.getClassLoader();
+
+ return classLoader;
+ }
+
+ private void addResources(ClassRealm realm, List resources) {
+ if (realm != null && resources != null) {
+ for (Object path : resources) {
+ URL url = null;
+ String formatted = null;
+
+ if (path instanceof String) {
+ formatted = (String) path;
+ } else if (path instanceof Resource) {
+ formatted = ((Resource) path).getDirectory();
+ }
+
+ if (formatted != null) {
+ File file = new File(formatted);
+
+ try {
+ url = file.toURI().toURL();
+ } catch (MalformedURLException e) {
+ getLog().error("Resource url " + file.getPath() +
" is invalid");
+ }
+
+ realm.addConstituent(url);
+ }
+ }
+ }
+ }
+}
Modified:
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java
===================================================================
---
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java 2009-11-01
16:30:05 UTC (rev 15793)
+++
root/cdk/trunk/plugins/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java 2009-11-01
16:31:55 UTC (rev 15794)
@@ -18,68 +18,72 @@
* 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.rd.utils;
import java.io.IOException;
import java.io.InputStream;
+
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.digester.Digester;
import org.apache.commons.vfs.FileObject;
+
import org.richfaces.cdk.rd.Component;
import org.richfaces.cdk.rd.Components;
import org.richfaces.cdk.rd.JarResourceScanner;
+
import org.xml.sax.SAXException;
public class PluginUtils {
+ public static String[] DEFAULT_CONFIG_PATTERNS = new String[]
{"**/*.component-dependencies.xml"};
+ public static String[] DEFAULT_PROCESS_INCLUDES = new String[]
{"**/*.xhtml"};
- public static String [] DEFAULT_CONFIG_PATTERNS = new String []
{"**/*.component-dependencies.xml"};
-
- public static String [] DEFAULT_PROCESS_INCLUDES = new String []
{"**/*.xhtml"};
+ public static FileObject[] resolveConfigsFromJar(FileObject jarFileObject, String[]
patterns) throws IOException {
+ FileObject[] result = new FileObject[0];
+ JarResourceScanner jarScanner = new JarResourceScanner();
-
- 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;
- }
-
- public static Digester createDefaultDigester() {
- Digester digester = new Digester();
- digester.addObjectCreate("components", Components.class);
- digester.addCallMethod("components/namespace", "setNamespace", 0);
- digester.addObjectCreate("components/component", Component.class);
- digester.addCallMethod("components/component/name",
"setComponentName",0);
- digester.addCallMethod("components/component/scripts/script",
"addScript",0);
- digester.addCallMethod("components/component/styles/style",
"addStyle",0);
- digester.addSetNext("components/component", "addComponent");
-
- return digester;
- }
+ 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;
+ }
+
+ public static Digester createDefaultDigester() {
+ Digester digester = new Digester();
+
+ digester.addObjectCreate("components", Components.class);
+ digester.addCallMethod("components/namespace",
"setNamespace", 0);
+ digester.addObjectCreate("components/component", Component.class);
+ digester.addCallMethod("components/component/name",
"setComponentName", 0);
+ digester.addCallMethod("components/component/scripts/script",
"addScript", 0);
+ digester.addCallMethod("components/component/styles/style",
"addStyle", 0);
+ digester.addSetNext("components/component", "addComponent");
+
+ return digester;
+ }
}
-