Author: abelevich
Date: 2009-02-03 10:36:56 -0500 (Tue, 03 Feb 2009)
New Revision: 12549
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.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/handler/ComponentsHandler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
Log:
https://jira.jboss.org/jira/browse/RF-6003
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java 2009-02-03
14:58:27 UTC (rev 12548)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java 2009-02-03
15:36:56 UTC (rev 12549)
@@ -27,7 +27,7 @@
* @author Anton Belevich
*
*/
-public class Component {
+public class Component implements Comparable<Component>{
private String componentName;
@@ -97,4 +97,8 @@
return true;
}
+ public int compareTo(Component o) {
+ return componentName.compareToIgnoreCase(o.getComponentName());
+ }
+
}
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-03
14:58:27 UTC (rev 12548)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java 2009-02-03
15:36:56 UTC (rev 12549)
@@ -99,11 +99,11 @@
if(assemblyFile != null) {
if(assemblyFile.exists()) {
assemblyFile.delete();
- try {
- assemblyFile.createNewFile();
- } catch (IOException e) {
- log.error("Error create assembly File: " +
assemblyFile.getAbsolutePath(),e);
- }
+ }
+ 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/handler/ComponentsHandler.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java 2009-02-03
14:58:27 UTC (rev 12548)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java 2009-02-03
15:36:56 UTC (rev 12549)
@@ -20,11 +20,17 @@
*/
package org.richfaces.cdk.rd.handler;
+import java.text.Collator;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.codehaus.plexus.util.SelectorUtils;
import org.richfaces.cdk.rd.Component;
import org.richfaces.cdk.rd.Components;
import org.xml.sax.SAXException;
@@ -42,17 +48,28 @@
private Set <String> styles = new LinkedHashSet<String>();
-
+ private String [] scriptExcludes;
+
+ private String [] styleExcludes;
+
+ private String [] namespaceExcludes;
+
+ private String [] componentExcludes;
+
@Override
public void endElement(String uri, String localName, String name) throws SAXException {
if(components != null && components.containsKey(uri)) {
- Components library = components.get(uri);
- List <Component> components = library.getComponents();
- for(Component component : components ){
- if(localName.equals(component.getComponentName())) {
- collectScripts(component);
- collectStyles(component);
+ if(!isExcluded(namespaceExcludes, uri, true)) {
+ Components library = components.get(uri);
+ List <Component> components = library.getComponents();
+ for(Component component : components ){
+ String componentName = component.getComponentName();
+ System.out.println("process: " + componentName);
+ if(localName.equals(componentName) && !isExcluded(componentExcludes,
componentName,false)) {
+ collectScripts(component);
+ collectStyles(component);
+ }
}
}
}
@@ -60,13 +77,32 @@
private void collectStyles(Component component) {
for(String style : component.getStyles()) {
- this.styles.add(style);
+ if(!isExcluded(styleExcludes, style, true)) {
+ this.styles.add(style);
+ }
}
}
+ private boolean isExcluded(String [] excludePatterns, String str, boolean matchPath) {
+ boolean exclude = false;
+ if(excludePatterns != null) {
+ for(String excludePattern: excludePatterns) {
+ if(matchPath) {
+ exclude = SelectorUtils.matchPath(excludePattern, str);
+ } else {
+ exclude = SelectorUtils.matchPath(excludePattern, str);
+ }
+ if(exclude) break;
+ }
+ }
+ return exclude;
+ }
+
private void collectScripts(Component component) {
for(String script : component.getScripts()) {
- this.scripts.add(script);
+ if(!isExcluded(scriptExcludes, script, true)) {
+ this.scripts.add(script);
+ }
}
}
@@ -85,4 +121,36 @@
public void setComponents(Map <String, Components> components) {
this.components = components;
}
+
+ public String[] getNamespaceExcludes() {
+ return namespaceExcludes;
+ }
+
+ public void setNamespaceExcludes(String[] namespaceExcludes) {
+ this.namespaceExcludes = namespaceExcludes;
+ }
+
+ public String[] getComponentExcludes() {
+ return componentExcludes;
+ }
+
+ public void setComponentExcludes(String[] componentExcludes) {
+ this.componentExcludes = componentExcludes;
+ }
+
+ public String [] getScriptExcludes() {
+ return scriptExcludes;
+ }
+
+ public void setScriptExcludes(String [] scriptExcludes) {
+ this.scriptExcludes = scriptExcludes;
+ }
+
+ public String [] getStyleExcludes() {
+ return styleExcludes;
+ }
+
+ public void setStyleExcludes(String [] styleExcludes) {
+ this.styleExcludes = styleExcludes;
+ }
}
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-03
14:58:27 UTC (rev 12548)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-02-03
15:36:56 UTC (rev 12549)
@@ -141,27 +141,51 @@
* beforeIncludes
* @parameter
*/
- private List beforeScriptIncludes;
+ private List <String> beforeScriptIncludes;
/**
* afterIncludes
* @parameter
*/
- private List afterScriptIncludes;
+ private List <String> afterScriptIncludes;
/**
* beforeIncludes
* @parameter
*/
- private List beforeStyleIncludes;
+ private List <String> beforeStyleIncludes;
/**
* afterIncludes
* @parameter
*/
- private List afterStyleIncludes;
+ private List <String> afterStyleIncludes;
/**
+ * scriptExcludes
+ * @parameter
+ */
+ private String [] scriptExcludes;
+
+ /**
+ * styleExcludes
+ * @parameter
+ */
+ private String [] styleExcludes;
+
+ /**
+ * namespaceExcludes
+ * @parameter
+ */
+ private String [] namespaceExcludes;
+
+ /**
+ * componentExcludes
+ * @parameter
+ */
+ private String [] componentExcludes;
+
+ /**
* @component
*/
protected VelocityComponent velocity;
@@ -182,6 +206,7 @@
webSourceDirectory.mkdirs();
}
ComponentsHandler handler = findComponents(webSourceDirectory, components,
PluginUtils.DEFAULT_PROCESS_INCLUDES, new String[0]);
+
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
ClassLoader contextClassLoader = createClassLoader();
Thread.currentThread().setContextClassLoader(contextClassLoader);
@@ -189,25 +214,32 @@
if(contextClassLoader != null) {
Set <String> scripts = handler.getScripts();
+
+ File scriptFile = new File(outputScriptDirectory, scriptPackName + ".js");
+ if(scriptFile.exists()) {
+ scriptFile.delete();
+ }
+
if(!scripts.isEmpty()) {
if(!outputScriptDirectory.exists()) {
outputScriptDirectory.mkdirs();
}
- File assemblyFile = new File(outputScriptDirectory, scriptPackName +
".js");
ScriptAssembler scriptAssembler = new ScriptAssembler();
- mergeResources(assemblyFile, scriptAssembler, beforeScriptIncludes,
afterScriptIncludes, scripts);
+ mergeResources(scriptFile, scriptAssembler, beforeScriptIncludes,
afterScriptIncludes, scripts);
}
Set <String> styles = handler.getStyles();
+ File styleFile = new File(outputStyleDirectory, stylePackName + ".xcss");
+ if(styleFile.exists()) styleFile.delete();
if(!styles.isEmpty()) {
if(!outputStyleDirectory.exists()) {
outputStyleDirectory.mkdirs();
}
- File assemblyFile = new File(outputStyleDirectory, stylePackName +
".xcss");
+
StyleAssembler styleAssembler = new StyleAssembler();
styleAssembler.setVelocityComponent(velocity);
- mergeResources(assemblyFile, styleAssembler, beforeStyleIncludes,
afterStyleIncludes, styles);
- }
+ mergeResources(styleFile, styleAssembler, beforeStyleIncludes, afterStyleIncludes,
styles);
+ }
}
Thread.currentThread().setContextClassLoader(oldClassLoader);
@@ -249,6 +281,10 @@
ComponentsHandler handler = new ComponentsHandler();
handler.setComponents(components);
+ handler.setScriptExcludes(scriptExcludes);
+ handler.setStyleExcludes(styleExcludes);
+ handler.setComponentExcludes(componentExcludes);
+ handler.setNamespaceExcludes(namespaceExcludes);
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
@@ -334,16 +370,14 @@
return classLoader;
}
- private ClassRealm addResources(ClassRealm realm, List<Resource> resources) {
+ 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();
}
@@ -359,6 +393,5 @@
}
}
}
- return realm;
}
}