Author: abelevich
Date: 2009-01-22 09:26:55 -0500 (Thu, 22 Jan 2009)
New Revision: 12368
Added:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
Removed:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateScriptMojo.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateStyleMojo.java
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/pom.xml
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java
Log:
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/pom.xml
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/pom.xml 2009-01-22 14:13:07 UTC
(rev 12367)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/pom.xml 2009-01-22 14:26:55 UTC
(rev 12368)
@@ -1,108 +1,122 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <artifactId>cdk</artifactId>
- <groupId>org.richfaces.sandbox</groupId>
- <version>3.3.1-SNAPSHOT</version>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>cdk</artifactId>
+ <groupId>org.richfaces.sandbox</groupId>
+ <version>3.3.1-SNAPSHOT</version>
+ </parent>
- <groupId>org.richfaces.cdk.sandbox</groupId>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.richfaces.cdk.sandbox</groupId>
+
<artifactId>maven-resource-dependency-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>3.3.1-SNAPSHOT</version>
<name>maven-resource-dependency-plugin</name>
-
+
<dependencies>
-
+
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- <version>2.0.4</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-plugin-testing-harness</artifactId>
- <version>1.0-beta-1</version>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <version>1.0-beta-1</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
- </dependency>
- <dependency>
- <groupId>commons-vfs</groupId>
- <artifactId>commons-vfs</artifactId>
- <version>1.0</version>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>commons-vfs</groupId>
+ <artifactId>commons-vfs</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ <version>1.4.1</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.1</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>jdom</groupId>
+ <artifactId>jdom</artifactId>
+ <version>1.0</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>2.0.2</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>com.jcraft</groupId>
+ <artifactId>jsch</artifactId>
+ <version>0.1.23</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ <version>1.0.b2</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>oro</groupId>
+ <artifactId>oro</artifactId>
+ <version>2.0.8</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-digester</groupId>
+ <artifactId>commons-digester</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.8.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>generator</artifactId>
+ <version>3.3.1-SNAPSHOT</version>
+ </dependency>
<dependency>
- <groupId>commons-net</groupId>
- <artifactId>commons-net</artifactId>
- <version>1.4.1</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1.1</version>
- </dependency>
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>3.1</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>jdom</groupId>
- <artifactId>jdom</artifactId>
- <version>1.0</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>2.0.2</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>com.jcraft</groupId>
- <artifactId>jsch</artifactId>
- <version>0.1.23</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>xml-apis</groupId>
- <artifactId>xml-apis</artifactId>
- <version>1.0.b2</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>oro</groupId>
- <artifactId>oro</artifactId>
- <version>2.0.8</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>commons-digester</groupId>
- <artifactId>commons-digester</artifactId>
- <version>2.0</version>
- </dependency>
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>1.8.0</version>
- </dependency>
-
-
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-velocity</artifactId>
+ <version>1.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-cdk-plugin</artifactId>
+ <version>3.3.1-SNAPSHOT</version>
+ </dependency>
+
</dependencies>
</project>
Added:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java
(rev 0)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java 2009-01-22
14:26:55 UTC (rev 12368)
@@ -0,0 +1,15 @@
+package org.richfaces.cdk.rd.generator;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public interface ResourceAssembler {
+
+ public void assembly(URL resource);
+
+ public void writeToFile(File file);
+}
Added:
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
(rev 0)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java 2009-01-22
14:26:55 UTC (rev 12368)
@@ -0,0 +1,139 @@
+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;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.logging.SystemStreamLog;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class ResourcesGenerator {
+
+ private File assemblyFile;
+
+ private Log log = new SystemStreamLog();
+
+ private Collection<String> resources;
+
+ private List <String> includesBefore;
+
+ private List <String> includesAfter;
+
+ private ResourceAssembler assembler;
+
+
+ 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);
+ 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.getAbsolutePath(),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;
+ }
+}
Added:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java
(rev 0)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ScriptAssembler.java 2009-01-22
14:26:55 UTC (rev 12368)
@@ -0,0 +1,69 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.rd.generator;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.logging.SystemStreamLog;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class ScriptAssembler implements ResourceAssembler {
+
+ Log log = new SystemStreamLog();
+
+ private StringBuilder builder;
+
+ public void assembly(URL resource) {
+ log.info("process resource : " + resource.getFile());
+ if (builder == null) {
+ builder = new StringBuilder();
+ }
+ try {
+ builder.append(IOUtil.toString(resource.openStream()));
+ } catch (IOException e) {
+ log.error("Error read resource: " + resource.getFile());
+ }
+ }
+
+ public void writeToFile(File file) {
+ if(builder.length() > 0) {
+ try {
+ FileWriter fileWriter = new FileWriter(file);
+ try {
+ IOUtil.copy(builder.toString(), fileWriter);
+ } finally {
+ fileWriter.close();
+ }
+ } catch (IOException e) {
+ log.error("Error write file: " + file.getAbsolutePath(),e);
+ }
+ }
+ }
+}
Added:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
(rev 0)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java 2009-01-22
14:26:55 UTC (rev 12368)
@@ -0,0 +1,88 @@
+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.ajax4jsf.builder.config.ParsingException;
+import org.ajax4jsf.builder.xml.XMLBody;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.logging.SystemStreamLog;
+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;
+
+
+/**
+ * @author Anton Belevich
+ *
+ */
+
+public class StyleAssembler implements ResourceAssembler {
+
+
+ private Log log = new SystemStreamLog();
+
+ private VelocityComponent velocityComponent;
+
+ private StringBuilder builder = new StringBuilder();
+
+ public void assembly(URL resource) {
+
+ String file = resource.getFile();
+ log.info("process resource: " + file);
+
+ try {
+ InputStream resourceInputStream = resource.openStream();
+ if(file.endsWith(".xcss")) {
+ XMLBody xmlBody = new XMLBody();
+ try {
+ xmlBody.loadXML(resourceInputStream,true);
+ builder.append(xmlBody.getContent());
+ } catch (ParsingException e) {
+ log.error("Error processing xcss: " + e.getMessage(), e);
+ } finally {
+ resourceInputStream.close();
+ }
+ } else {
+ builder.append(IOUtil.toString(resourceInputStream));
+ }
+
+ } catch (IOException e) {
+ log.error("Error load xcss file " + resource.getFile() + " : " +
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) {
+ VelocityContext context = new VelocityContext();
+ context.put("content", builder);
+ VelocityEngine engine = velocityComponent.getEngine();
+ FileWriter fileWriter = new FileWriter(file);
+ try {
+ Template velocityTemplate = engine.getTemplate("templates12/xcss.vm");
+ velocityTemplate.merge(context, fileWriter);
+ fileWriter.flush();
+ } finally {
+ fileWriter.close();
+ }
+ }
+ } catch (Exception e) {
+ log.error("Error write file: " + file.getAbsolutePath(),e);
+ }
+ }
+
+}
Deleted:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateScriptMojo.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateScriptMojo.java 2009-01-22
14:13:07 UTC (rev 12367)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateScriptMojo.java 2009-01-22
14:26:55 UTC (rev 12368)
@@ -1,348 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.rd.mojo;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.apache.commons.digester.Digester;
-import org.apache.commons.vfs.FileObject;
-import org.apache.commons.vfs.FileSystemException;
-import org.apache.commons.vfs.FileSystemManager;
-import org.apache.commons.vfs.VFS;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectBuilder;
-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.richfaces.cdk.rd.Components;
-import org.richfaces.cdk.rd.handler.ComponentsHandler;
-import org.richfaces.cdk.rd.utils.PluginUtils;
-
-/**
- * @author Anton Belevich
- *
- * @goal assemblyScripts
- * @phase process-resources
- *
- */
-public class CreateScriptMojo extends AbstractMojo {
-
- /** Top maven project.
- *
- * @parameter expression="${project}"
- * @readonly
- */
- protected MavenProject project;
-
- /**
- *
- * @component
- */
- protected MavenProjectBuilder builder;
-
- /**
- * Used to look up Artifacts in the remote repository.
- *
- * @component
- */
- private org.apache.maven.artifact.factory.ArtifactFactory factory;
-
- /**
- * Used to look up Artifacts in the remote repository.
- *
- * @component
- */
- private org.apache.maven.artifact.resolver.ArtifactResolver resolver;
-
- /**
- * The local repository.
- *
- * @parameter expression="${localRepository}"
- */
- private ArtifactRepository localRepository;
-
- /**
- * outputScriptDirectory
- * @parameter expression = "${basedir}/src/main/webapp"
- */
- private File outputScriptDirectory ;
-
- /**
- * scriptPackName
- * @parameter expression="custom-dependencies";
- */
- private String scriptPackName;
-
- /**
- * webSourceDirectory
- * @parameter expression="${basedir}/src/main/webapp" ;
- */
- private File webSourceDirectory;
-
-
- /**
- * namespaces
- * @parameter
- *
- */
- private List namespaces;
-
- /**
- * beforeIncludes
- * @parameter
- */
- private List beforeIncludes;
-
- /**
- * afterIncludes
- * @parameter
- */
- private List afterIncludes;
-
- /**
- *
- * @component
- */
- private ArtifactMetadataSource metadataSource;
-
-
-
- public void execute() throws MojoExecutionException {
- try {
-
- Set <Artifact> artifacts = resolveDependenciesArtifacts();
- Digester defaultDigester = getDigester();
-
- Map <String, Components> components = new HashMap<String, Components>();
- for (Artifact artifact : artifacts) {
- FileObject jar = resolveArtifact(artifact);
- FileObject [] configs = PluginUtils.resolveConfigsFromJar(jar,
PluginUtils.DEFAULT_CONFIG_PATTERNS);
- components.putAll(PluginUtils.processConfigs(configs, defaultDigester));
- }
-
- ComponentsHandler handler = findComponents(webSourceDirectory, components,
PluginUtils.DEFAULT_PROCESS_INCLUDES, new String[0]);
- Set <String> result = handler.getScripts();
- mergeScripts(result,outputScriptDirectory, beforeIncludes, afterIncludes);
-
- } catch (Exception e) {
- throw new MojoExecutionException(e.getMessage(),e);
- }
-
- }
-
- public Digester getDigester() {
- return PluginUtils.createDefaultDigester();
- }
-
- public ComponentsHandler findComponents (File webSourceDir, Map <String,
Components> components, String [] includes, String [] excludes) {
-
- DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir(webSourceDir);
- scanner.setIncludes(includes);
- scanner.setExcludes(excludes);
- scanner.addDefaultExcludes();
- scanner.scan();
- String [] collectedFiles = scanner.getIncludedFiles();
-
- ComponentsHandler handler = new ComponentsHandler();
- handler.setComponents(components);
-
- try {
-
- SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
- saxParserFactory.setNamespaceAware(true);
- SAXParser saxParser = saxParserFactory.newSAXParser();
-
- for(String processFile : collectedFiles) {
- File file = new File(webSourceDir,processFile);
- if(file.exists()) {
- getLog().info("process file: " + file.getName());
- try {
- saxParser.parse(file, handler);
- } catch (Exception e) {
- getLog().error("Error process file: " + file.getAbsolutePath() +
"\n" + e.getMessage(), e);
- }
- }
- }
-
- } catch (Exception e) {
- getLog().error(e);
- }
-
- return handler;
- }
-
- protected Set <Artifact> resolveDependenciesArtifacts() {
- ArtifactResolutionResult result = null;
- try {
- 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);
- } catch (Exception e) {
- getLog().error(e);
- }
- return result.getArtifacts();
- }
-
-
- protected FileObject resolveArtifact(Artifact artifact) {
- FileObject jarFileObjects = null;
- if(artifact != null) {
- try {
- resolver.resolve(artifact, Collections.EMPTY_LIST, localRepository);
- getLog().info("artifact " + artifact.getFile().getAbsolutePath() + "
is resolved");
- } catch (ArtifactResolutionException e) {
- getLog().error("Error with resolve artifact " +
artifact.getFile().getAbsolutePath() + "\n" + e.getMessage(), e);
- } catch (ArtifactNotFoundException e) {
- getLog().error("Not found artifact " + artifact.getFile().getAbsolutePath()
+ "\n" + e.getMessage(), e);
- }
-
- File file = artifact.getFile();
- try {
- FileSystemManager manager = VFS.getManager();
- jarFileObjects = manager.resolveFile("jar://" + file.getAbsolutePath());
- } catch (FileSystemException e) {
- getLog().error("Error during processing file: " + file.getAbsolutePath()+
"\n" + e.getMessage(), e);
- }
- }
- return jarFileObjects;
- }
-
-
- protected void mergeScripts(Set <String> scripts, File outputScriptDirectory, List
<String> beforeIncludes, List <String> afterIncludes) {
-
- File assemblyScriptFile = new File(outputScriptDirectory, scriptPackName +
".js");
-
- try {
- if(assemblyScriptFile.exists()) {
- assemblyScriptFile.delete();
- }
- getLog().info("Create assembly file: " +
assemblyScriptFile.getAbsolutePath());
- assemblyScriptFile.createNewFile();
-
- } catch (IOException e) {
- getLog().error("Error create file: " + assemblyScriptFile.getAbsolutePath()
+ "\n" + e.getMessage(), e);
- }
-
- try {
-
- Set <Artifact> artifacts = resolveDependenciesArtifacts();
-
- //save current ContextClassloader
- ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
-
- //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 ) {
- childRealm.addConstituent(jar.getFile().toURL());
- }
-
- // add project classes, scripts etc ...
- List compileClasspathElements = project.getCompileClasspathElements();
- for (Object path: compileClasspathElements) {
- childRealm.addConstituent(new File((String)path).toURI().toURL());
- }
-
- //make the child realm the ContextClassLoader
- Thread.currentThread().setContextClassLoader(childRealm.getClassLoader());
-
- if(beforeIncludes != null) {
- merge(assemblyScriptFile, beforeIncludes);
- }
-
- merge(assemblyScriptFile, scripts);
-
- if(afterIncludes != null) {
- merge(assemblyScriptFile, afterIncludes);
- }
-
- //restore old ContextClassLoader
- Thread.currentThread().setContextClassLoader(oldClassLoader);
-
- } catch (Exception e) {
- getLog().error(e);
- }
-
- }
-
- public void merge(File assembly, Collection <String> resources) {
- for(String script: resources) {
- URL resource = getResourceURL(script);
- if(resource != null) {
- getLog().info("merge file: " + resource.getFile() + " in to " +
assembly.getAbsolutePath());
- try {
- PluginUtils.mergeFiles(assembly, resource);
- } catch (Exception e) {
- getLog().error("Error during merge: " + resource.getFile() +
"\n" + e.getMessage(), e);
- }
- }
- }
- }
-
- protected URL getResourceURL(String resourceName) {
- URL resource =
Thread.currentThread().getContextClassLoader().getResource(resourceName);
- try {
- if(resource == null) {
- //resolve framework script path
- Class clazz =
Thread.currentThread().getContextClassLoader().loadClass(resourceName);
- Object obj = clazz.newInstance();
- Method method = clazz.getMethod("getPath", new Class [0]);
- String path = (String) method.invoke(obj, new Object[0]);
- resource = Thread.currentThread().getContextClassLoader().getResource(path);
- }
- } catch (Exception e) {
- getLog().error("Error process: " + resourceName + "\n" +
e.getMessage(), e);
- }
-
- return resource;
- }
-}
Deleted:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateStyleMojo.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateStyleMojo.java 2009-01-22
14:13:07 UTC (rev 12367)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateStyleMojo.java 2009-01-22
14:26:55 UTC (rev 12368)
@@ -1,64 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.rd.mojo;
-
-import java.io.File;
-
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-
-/**
- * @author Anton Belevich
- * @goal assemblyStyles
- * @phase process-resources
- */
-public class CreateStyleMojo extends AbstractMojo {
-
- /**
- * outputStyleDirectory
- * @parameter
- */
- private File outputStyleDirectory;
-
- /**
- * stylePackName
- * @parameter;
- */
- private String stylePackName;
-
- /**
- * webSourceDirectory
- * @parameter expression="${basedir}/src/main/webapp" ;
- */
- private File webSourceDirectory;
-
- /**
- * loadOrder
- * @parameter;
- */
- private String loadOrder;
-
- public void execute() throws MojoExecutionException{
- System.out.println("CreateStyleMojo.execute()");
- }
-
-}
Added:
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
(rev 0)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-01-22
14:26:55 UTC (rev 12368)
@@ -0,0 +1,331 @@
+package org.richfaces.cdk.rd.mojo;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.ajax4jsf.builder.mojo.Library;
+import org.ajax4jsf.builder.xml.XMLBodyMerge;
+import org.apache.commons.digester.Digester;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.VFS;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+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;
+import org.richfaces.cdk.rd.generator.ScriptAssembler;
+import org.richfaces.cdk.rd.generator.StyleAssembler;
+import org.richfaces.cdk.rd.handler.ComponentsHandler;
+import org.richfaces.cdk.rd.utils.PluginUtils;
+
+/**
+ * @author Anton Belevich
+ * @goal assemblyResources
+ * @phase process-resources
+
+ */
+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 org.apache.maven.artifact.factory.ArtifactFactory factory;
+
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @component
+ */
+ private org.apache.maven.artifact.resolver.ArtifactResolver resolver;
+
+
+ /**
+ * The local repository.
+ *
+ * @parameter expression="${localRepository}"
+ */
+ private ArtifactRepository localRepository;
+
+
+ /**
+ * webSourceDirectory
+ * @parameter expression="${basedir}/src/main/webapp"
+ */
+ private File webSourceDirectory;
+
+ /**
+ *
+ * @component
+ */
+ private ArtifactMetadataSource metadataSource;
+
+
+ /**
+ * outputScriptDirectory
+ * @parameter expression = "${basedir}/src/main/webapp"
+ */
+ private File outputScriptDirectory ;
+
+ /**
+ *
+ * scriptPackName
+ * @parameter expression="custom-dependencies"
+ */
+ private String scriptPackName;
+
+ /**
+ * outputStyleDirectory
+ * @parameter expression = "${basedir}/src/main/webapp"
+ */
+ private File outputStyleDirectory;
+
+ /**
+ * stylePackName
+ * @parameter expression="custom-dependencies"
+ */
+ private String stylePackName;
+
+
+ /**
+ * beforeIncludes
+ * @parameter
+ */
+ private List beforeScriptIncludes;
+
+ /**
+ * afterIncludes
+ * @parameter
+ */
+ private List afterScriptIncludes;
+
+ /**
+ * beforeIncludes
+ * @parameter
+ */
+ private List beforeStylesIncludes;
+
+ /**
+ * afterIncludes
+ * @parameter
+ */
+ private List afterStylesIncludes;
+
+ /**
+ *
+ * @parameter
+ */
+ protected Library library;
+
+ /**
+ * @component
+ */
+ protected VelocityComponent velocity;
+
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ try {
+ Set <Artifact> artifacts = resolveDependenciesArtifacts();
+ Digester defaultDigester = getDigester();
+
+ Map <String, Components> components = new HashMap<String, Components>();
+ for (Artifact artifact : artifacts) {
+ FileObject jar = resolveArtifact(artifact);
+ FileObject [] configs = PluginUtils.resolveConfigsFromJar(jar,
PluginUtils.DEFAULT_CONFIG_PATTERNS);
+ components.putAll(PluginUtils.processConfigs(configs, defaultDigester));
+ }
+ ComponentsHandler handler = findComponents(webSourceDirectory, components,
PluginUtils.DEFAULT_PROCESS_INCLUDES, new String[0]);
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader contextClassLoader = createClassLoader();
+ Thread.currentThread().setContextClassLoader(contextClassLoader);
+
+ if(contextClassLoader != null) {
+
+ Set <String> scripts = handler.getScripts();
+ if(!scripts.isEmpty()) {
+ File assemblyFile = new File(outputScriptDirectory, scriptPackName +
".js");
+ ScriptAssembler scriptAssembler = new ScriptAssembler();
+ mergeResources(assemblyFile, scriptAssembler, beforeScriptIncludes,
afterScriptIncludes, scripts);
+ }
+
+ Set <String> styles = handler.getStyles();
+ if(!styles.isEmpty()) {
+ XMLBodyMerge xmlBodyMerge = new XMLBodyMerge(null);
+ File assemblyFile = new File(outputStyleDirectory, stylePackName +
".xcss");
+ StyleAssembler styleAssembler = new StyleAssembler();
+ styleAssembler.setVelocityComponent(velocity);
+ mergeResources(assemblyFile, styleAssembler, beforeStylesIncludes,
afterStylesIncludes, styles);
+ }
+ }
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
+
+ } catch (Exception e) {
+ throw new MojoExecutionException(e.getMessage(),e);
+ }
+ }
+
+ public void mergeResources(File assembly, ResourceAssembler assembler, List
<String> beforeIncludes, List <String> afterIncludes, Collection<String>
resources) {
+ ResourcesGenerator styleGenerator = new ResourcesGenerator();
+ styleGenerator.setAssembler(assembler);
+ styleGenerator.setIncludesAfter(afterIncludes);
+ styleGenerator.setIncludesBefore(beforeIncludes);
+ styleGenerator.setResources(resources);
+ styleGenerator.setAssemblyFile(assembly);
+ styleGenerator.doAssembly();
+ styleGenerator.writeToFile();
+ }
+
+ protected Set <Artifact> resolveDependenciesArtifacts() {
+ ArtifactResolutionResult result = null;
+ try {
+ 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);
+ } catch (Exception e) {
+ getLog().error(e);
+ }
+ return result.getArtifacts();
+ }
+
+
+ public ComponentsHandler findComponents (File webSourceDir, Map <String,
Components> components, String [] includes, String [] excludes) {
+
+ DirectoryScanner scanner = new DirectoryScanner();
+ scanner.setBasedir(webSourceDir);
+ scanner.setIncludes(includes);
+ scanner.setExcludes(excludes);
+ scanner.addDefaultExcludes();
+ scanner.scan();
+ String [] collectedFiles = scanner.getIncludedFiles();
+
+ ComponentsHandler handler = new ComponentsHandler();
+ handler.setComponents(components);
+
+ try {
+
+ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+ saxParserFactory.setNamespaceAware(true);
+ SAXParser saxParser = saxParserFactory.newSAXParser();
+
+ for(String processFile : collectedFiles) {
+ File file = new File(webSourceDir,processFile);
+ if(file.exists()) {
+ getLog().info("process file: " + file.getName());
+ try {
+ saxParser.parse(file, handler);
+ } catch (Exception e) {
+ getLog().error("Error process file: " + file.getAbsolutePath() +
"\n" + e.getMessage(), e);
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ getLog().error(e);
+ }
+
+ return handler;
+ }
+
+ protected FileObject resolveArtifact(Artifact artifact) {
+ FileObject jarFileObjects = null;
+ if(artifact != null) {
+ try {
+ resolver.resolve(artifact, Collections.EMPTY_LIST, localRepository);
+ getLog().info("artifact " + artifact.getFile().getAbsolutePath() + "
is resolved");
+ } catch (ArtifactResolutionException e) {
+ getLog().error("Error with resolve artifact " +
artifact.getFile().getAbsolutePath() + "\n" + e.getMessage(), e);
+ } catch (ArtifactNotFoundException e) {
+ getLog().error("Not found artifact " + artifact.getFile().getAbsolutePath()
+ "\n" + e.getMessage(), e);
+ }
+
+ File file = artifact.getFile();
+ try {
+ FileSystemManager manager = VFS.getManager();
+ jarFileObjects = manager.resolveFile("jar://" + file.getAbsolutePath());
+ } catch (FileSystemException e) {
+ getLog().error("Error during processing file: " + file.getAbsolutePath()+
"\n" + e.getMessage(), e);
+ }
+ }
+ return jarFileObjects;
+ }
+
+ public Digester getDigester() {
+ // default digester for *.component-dependencies.xml
+ return PluginUtils.createDefaultDigester();
+ }
+
+ protected ClassLoader createClassLoader() {
+
+ ClassLoader classLoader = null;
+ try {
+
+ 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 ) {
+ childRealm.addConstituent(jar.getFile().toURL());
+ }
+
+ // add project classes, scripts etc ...
+ List compileClasspathElements = project.getCompileClasspathElements();
+ for (Object path: compileClasspathElements) {
+ try {
+ childRealm.addConstituent(new File((String)path).toURI().toURL());
+ } catch (Exception e) {
+ getLog().error(e);
+ }
+ }
+
+ //make the child realm the ContextClassLoader
+ classLoader = childRealm.getClassLoader();
+
+ } catch (Exception e) {
+ getLog().error(e);
+ }
+ return classLoader;
+ }
+}
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java
===================================================================
---
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java 2009-01-22
14:13:07 UTC (rev 12367)
+++
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java 2009-01-22
14:26:55 UTC (rev 12368)
@@ -1,15 +1,11 @@
package org.richfaces.cdk.rd.utils;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.InputStream;
-import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.digester.Digester;
import org.apache.commons.vfs.FileObject;
-import org.codehaus.plexus.util.IOUtil;
import org.richfaces.cdk.rd.Component;
import org.richfaces.cdk.rd.Components;
import org.richfaces.cdk.rd.JarResourceScanner;
@@ -21,24 +17,6 @@
public static String [] DEFAULT_PROCESS_INCLUDES = new String []
{"**/*.xhtml"};
-
- public static void mergeFiles(File dest, URL resource) throws Exception{
- FileOutputStream out = new FileOutputStream(dest, true);
- try {
- InputStream in = resource.openStream();
- try {
- IOUtil.copy(in, out);
- out.write('\n');
- } finally {
- IOUtil.close(in);
- in = null;
- }
- } finally {
- IOUtil.close(out);
- out = null;
- }
- }
-
public static FileObject [] resolveConfigsFromJar(FileObject jarFileObject, String []
patterns) throws Exception {
FileObject [] result = new FileObject[0];
JarResourceScanner jarScanner = new JarResourceScanner();
@@ -76,7 +54,7 @@
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/styles",
"addStyle",0);
+ digester.addCallMethod("components/component/styles/style",
"addStyle",0);
digester.addSetNext("components/component", "addComponent");
return digester;
}