Author: nbelaevski
Date: 2009-05-10 10:31:42 -0400 (Sun, 10 May 2009)
New Revision: 14098
Modified:
trunk/cdk/maven-resource-dependency-plugin/
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
Log:
https://jira.jboss.org/jira/browse/RF-7076
Property changes on: trunk/cdk/maven-resource-dependency-plugin
___________________________________________________________________
Name: svn:ignore
- target
+ target
bin
.classpath
.project
.settings
Modified:
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java
===================================================================
---
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java 2009-05-08
19:12:42 UTC (rev 14097)
+++
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java 2009-05-10
14:31:42 UTC (rev 14098)
@@ -101,4 +101,8 @@
return componentName.compareToIgnoreCase(o.getComponentName());
}
+ @Override
+ public String toString() {
+ return "Component: " + componentName;
+ }
}
Modified:
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java
===================================================================
---
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java 2009-05-08
19:12:42 UTC (rev 14097)
+++
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java 2009-05-10
14:31:42 UTC (rev 14098)
@@ -79,4 +79,9 @@
return false;
return true;
}
+
+ @Override
+ public String toString() {
+ return "Components set: " + namespace;
+ }
}
Modified:
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java
===================================================================
---
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java 2009-05-08
19:12:42 UTC (rev 14097)
+++
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java 2009-05-10
14:31:42 UTC (rev 14098)
@@ -24,6 +24,7 @@
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;
@@ -37,21 +38,28 @@
protected Log log;
-
private StringBuilder builder = new StringBuilder();
-
public ScriptAssembler(Log log) {
this.log = log;
}
public void assembly(URL resource) {
-
+ InputStream inputStream = null;
try {
- builder.append(IOUtil.toString(resource.openStream()));
+ 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);
+ }
+ }
}
}
Modified:
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java
===================================================================
---
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java 2009-05-08
19:12:42 UTC (rev 14097)
+++
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java 2009-05-10
14:31:42 UTC (rev 14098)
@@ -25,6 +25,8 @@
import java.io.Reader;
import java.io.StringReader;
import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -43,110 +45,117 @@
*
*/
public class ComponentsHandler extends DefaultHandler{
-
+
private String [] INCLUDE_ALL_PATTERN = {"**"};
-
+
protected Log log;
+
+ private Map <String, Components> components;
+
+ private Map <String, Set<String>> processedComponents = new
HashMap<String, Set<String>>();
- private Map <String,Components> components;
-
private Set <String> scripts = new LinkedHashSet<String>();
-
+
private Set <String> styles = new LinkedHashSet<String>();
-
+
private String [] scriptIncludes;
-
+
private String [] scriptExcludes;
-
+
private String [] styleIncludes;
-
+
private String [] styleExcludes;
-
+
private String [] namespaceIncludes;
-
+
private String [] namespaceExcludes;
-
+
private String [] componentIncludes;
-
+
private String [] componentExcludes;
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 && components.containsKey(uri)) {
-
- if(namespaceIncludes == null) {
- namespaceIncludes = INCLUDE_ALL_PATTERN;
+ if (components != null) {
+
+ Components library = components.get(uri);
+ if (library != null) {
- if(log.isDebugEnabled()) {
- log.debug("use default include patterns for namespaces");
- }
- }
-
- if(doMatch(namespaceIncludes, uri, true)){
-
- if(!doMatch(namespaceExcludes, uri, true)) {
-
- Components library = components.get(uri);
- List <Component> components = library.getComponents();
-
- if (componentIncludes == null) {
-
- componentIncludes = INCLUDE_ALL_PATTERN;
-
- if(log.isDebugEnabled()) {
- log.debug("use default include patterns for components");
+ Set<String> processedComponentsSet = getProcessedComponentsSet(uri);
+ if (processedComponentsSet.add(localName)) {
+ if (namespaceIncludes == null) {
+ namespaceIncludes = INCLUDE_ALL_PATTERN;
+
+ if (log.isDebugEnabled()) {
+ log.debug("use default include patterns for namespaces");
}
-
}
-
- for(Component component : components ){
-
- String componentName = component.getComponentName();
- if(localName.equals(componentName)) {
-
- if(doMatch(componentIncludes, componentName,false)) {
-
- if(!doMatch(componentExcludes, componentName,false)) {
-
- log.info("process component: " + componentName);
-
- collectScripts(component);
- collectStyles(component);
+
+ if (doMatch(namespaceIncludes, uri, true)){
+ if (!doMatch(namespaceExcludes, uri, true)) {
+ List <Component> components = library.getComponents();
+
+ if (componentIncludes == null) {
+ componentIncludes = INCLUDE_ALL_PATTERN;
+
+ if(log.isDebugEnabled()) {
+ log.debug("use default include patterns for components");
}
-
- }
-
+ }
+
+ if (doMatch(componentIncludes, localName, false)) {
+ if (!doMatch(componentExcludes, localName, false)) {
+ for (Component component : components) {
+
+ String componentName = component.getComponentName();
+ if(localName.equals(componentName)) {
+ log.info("process component: " + componentName);
+
+ 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");
}
-
- } 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");
}
}
}
-
+
private void collectStyles(Component component) {
-
+
if(styleIncludes == null) {
styleIncludes = INCLUDE_ALL_PATTERN;
}
-
+
if(log.isDebugEnabled()) {
log.debug("start collect styles from component: " +
component.getComponentName() );
}
-
+
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");
@@ -156,62 +165,61 @@
log.info(styleExclude);
}
}
-
+
} else {
log.info("style files are not in included list");
for(String styleInclude: styleIncludes) {
log.info(styleInclude);
}
}
-
+
}
}
-
+
private boolean doMatch(String [] patterns, String str, boolean matchPath) {
boolean allow = false;
-
+
if(patterns != null) {
-
+
for(String excludePattern: patterns) {
-
+
if(matchPath) {
allow = SelectorUtils.matchPath(excludePattern, str);
} else {
allow = SelectorUtils.match(excludePattern, str);
}
-
+
if(allow) break;
}
-
+
}
-
+
return allow;
}
-
+
private void collectScripts(Component component) {
-
- if(scriptIncludes == null) {
+
+ if (scriptIncludes == null) {
scriptIncludes = INCLUDE_ALL_PATTERN;
}
-
- if(log.isDebugEnabled()) {
+
+ if (log.isDebugEnabled()) {
log.debug("start collect scripts from component: " +
component.getComponentName() );
}
-
- for(String script : component.getScripts()) {
-
- if(doMatch(scriptIncludes, script, true)) {
-
- if(!doMatch(scriptExcludes, script, 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 {
+ } else {
log.info("script files are in excluded list");
for(String styleExclude: scriptExcludes) {
log.info(styleExclude);
}
}
-
+
} else {
log.info("script files are not in included list");
for(String styleInclude: scriptIncludes) {
@@ -220,15 +228,15 @@
}
}
}
-
+
public Set <String> getStyles() {
return this.styles;
}
-
+
public Set <String> getScripts() {
return this.scripts;
}
-
+
public Map <String, Components> getComponents() {
return components;
}
@@ -236,7 +244,7 @@
public void setComponents(Map <String, Components> components) {
this.components = components;
}
-
+
public String[] getNamespaceExcludes() {
return namespaceExcludes;
}
@@ -300,51 +308,51 @@
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);
- }
+ 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 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;
+ }
+ }
+
+ return dtdContent;
}
-
+
@Override
public InputSource resolveEntity(String publicId, String systemId)
- throws IOException, SAXException {
-
+ throws IOException, SAXException {
+
if (defaultDtdContent == null) {
defaultDtdContent = readDtdContent(DEFAULT_DTD_PATH);
}
-
+
return new InputSource(new StringReader(defaultDtdContent));
}
}
Modified:
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
===================================================================
---
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-05-08
19:12:42 UTC (rev 14097)
+++
trunk/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-05-10
14:31:42 UTC (rev 14098)
@@ -51,6 +51,7 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+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;
@@ -336,7 +337,7 @@
protected Set <Artifact> resolveDependenciesArtifacts() throws Exception {
ArtifactResolutionResult result = null;
-
+
List <Dependency> dependencies = project.getDependencies();
Set <Artifact> artifacts = MavenMetadataSource.createArtifacts(factory,
dependencies, null, null, project);
@@ -384,24 +385,30 @@
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
- SAXParser saxParser = saxParserFactory.newSAXParser();
- for(String processFile : collectedFiles) {
-
+ Log log = getLog();
+ for (String processFile : collectedFiles) {
+ SAXParser saxParser = saxParserFactory.newSAXParser();
File file = new File(webSourceDir,processFile);
- if(file.exists()) {
+ if (file.exists()) {
- getLog().info("start process file: " + file.getPath());
+ if (log.isDebugEnabled()) {
+ log.debug("start process file: " + file.getPath());
+ }
+
try {
saxParser.parse(file, handler);
} catch (Exception e) {
- getLog().error("Error process file: " + file.getPath() + "\n"
+ e.getMessage(), 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;
+
+ return handler;
}
protected FileObject resolveArtifact(Artifact artifact) {