Author: alexsmirnov
Date: 2009-10-05 17:26:45 -0400 (Mon, 05 Oct 2009)
New Revision: 15697
Removed:
root/cdk/trunk/plugins/generator/src/main/resources/org/
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AbstractCreateMojo.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AssemblyAttachedLibraryMojo.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AssemblyLibraryMojo.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateComponentMojo.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateSkinMojo.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateThemeMojo.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/resources/META-INF/plexus/
Modified:
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AbstractCDKMojo.java
Log:
fix missed velocity dependencies
Modified:
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AbstractCDKMojo.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AbstractCDKMojo.java 2009-10-05
16:54:09 UTC (rev 15696)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AbstractCDKMojo.java 2009-10-05
21:26:45 UTC (rev 15697)
@@ -161,10 +161,6 @@
*/
protected File outputDirectory;
/**
- * @component
- */
- protected VelocityComponent velocity;
- /**
* Check library configuration, and fill all empty values to default.
*
* @return
@@ -288,19 +284,6 @@
return "1.2";
}
- protected void writeParsedTemplate(String templateName, VelocityContext context, File
configFile) throws IOException, ResourceNotFoundException, ParseErrorException,
MethodInvocationException, Exception {
- File dir = configFile.getParentFile();
- if(!dir.exists()){
- dir.mkdirs();
- }
- VelocityEngine engine = velocity.getEngine();
- FileWriter fileWriter = new FileWriter(configFile);
- Template velocityTemplate = engine.getTemplate(templateName);
- velocityTemplate.merge(context, fileWriter);
- fileWriter.flush();
- fileWriter.close();
- }
-
protected ClassLoader createProjectClassLoader(MavenProject project, boolean useCCL) {
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
Deleted:
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AbstractCreateMojo.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AbstractCreateMojo.java 2009-10-05
16:54:09 UTC (rev 15696)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AbstractCreateMojo.java 2009-10-05
21:26:45 UTC (rev 15697)
@@ -1,141 +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.builder.mojo;
-
-import java.io.File;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.velocity.VelocityContext;
-import org.richfaces.cdk.model.Resource;
-
-/**
- * @author Nick Belaevski
- *
- */
-public abstract class AbstractCreateMojo extends AbstractCDKMojo {
-
- protected static final String SRC_MAIN_RESOURCES = "src/main/resources";
-
- protected static final Set<String> JAVA_RESERVED_WORDS;
-
- static{
- JAVA_RESERVED_WORDS = new HashSet<String>();
- JAVA_RESERVED_WORDS.add("abstract");
- JAVA_RESERVED_WORDS.add("assert");
- JAVA_RESERVED_WORDS.add("boolean");
- JAVA_RESERVED_WORDS.add("break");
- JAVA_RESERVED_WORDS.add("byte");
- JAVA_RESERVED_WORDS.add("case");
- JAVA_RESERVED_WORDS.add("catch");
- JAVA_RESERVED_WORDS.add("char");
- JAVA_RESERVED_WORDS.add("class");
- JAVA_RESERVED_WORDS.add("const");
- JAVA_RESERVED_WORDS.add("continue");
- JAVA_RESERVED_WORDS.add("default");
- JAVA_RESERVED_WORDS.add("do");
- JAVA_RESERVED_WORDS.add("double");
- JAVA_RESERVED_WORDS.add("else");
- JAVA_RESERVED_WORDS.add("extends");
- JAVA_RESERVED_WORDS.add("false");
- JAVA_RESERVED_WORDS.add("final");
- JAVA_RESERVED_WORDS.add("finally");
- JAVA_RESERVED_WORDS.add("float");
- JAVA_RESERVED_WORDS.add("for");
- JAVA_RESERVED_WORDS.add("goto");
- JAVA_RESERVED_WORDS.add("if");
- JAVA_RESERVED_WORDS.add("implements");
- JAVA_RESERVED_WORDS.add("import");
- JAVA_RESERVED_WORDS.add("instanceof");
- JAVA_RESERVED_WORDS.add("int");
- JAVA_RESERVED_WORDS.add("interface");
- JAVA_RESERVED_WORDS.add("long");
- JAVA_RESERVED_WORDS.add("native");
- JAVA_RESERVED_WORDS.add("new");
- JAVA_RESERVED_WORDS.add("null");
- JAVA_RESERVED_WORDS.add("package");
- JAVA_RESERVED_WORDS.add("private");
- JAVA_RESERVED_WORDS.add("protected");
- JAVA_RESERVED_WORDS.add("public");
- JAVA_RESERVED_WORDS.add("return");
- JAVA_RESERVED_WORDS.add("short");
- JAVA_RESERVED_WORDS.add("static");
- JAVA_RESERVED_WORDS.add("strictfp");
- JAVA_RESERVED_WORDS.add("super");
- JAVA_RESERVED_WORDS.add("switch");
- JAVA_RESERVED_WORDS.add("synchronized");
- JAVA_RESERVED_WORDS.add("this");
- JAVA_RESERVED_WORDS.add("throw");
- JAVA_RESERVED_WORDS.add("throws");
- JAVA_RESERVED_WORDS.add("transient");
- JAVA_RESERVED_WORDS.add("true");
- JAVA_RESERVED_WORDS.add("try");
- JAVA_RESERVED_WORDS.add("void");
- JAVA_RESERVED_WORDS.add("volatile");
- JAVA_RESERVED_WORDS.add("while");
- }
-
- protected void checkAndCreateDirectory(File directory)
- throws MojoExecutionException {
- getLog().debug("Checking directory " + directory + " for
existence");
- if (!directory.exists()) {
- directory.mkdirs();
- getLog().debug("Directory " + directory + " created");
- }
- if (!directory.isDirectory()) {
- throw new MojoExecutionException("Directory " + directory.getAbsolutePath()
+ " is not a Directory");
- }
- }
-
- protected void filterJarResource(Resource template, Resource skinResource, File
baseDir,
- VelocityContext context) throws Exception {
- File newFile = new File(baseDir, skinResource.getPath());
- if (newFile.exists()) {
- getLog().debug("File " + newFile + " already exists. Skipping.");
- } else {
- try {
- writeParsedTemplate(template.getPath(), context, newFile);
- } catch (Exception e) {
- throw new MojoExecutionException("Unable to write file " + newFile, e);
- }
- }
- }
-
- protected boolean isValidJavaName(String name) {
- return !JAVA_RESERVED_WORDS.contains(name);
- }
-
- protected boolean isValidPackageName(String packageName) {
- if (packageName != null) {
- String[] packageNameSegments = packageName.split("\\.");
- for (String packageNameSegment : packageNameSegments) {
- if (!isValidJavaName(packageNameSegment)) {
- return false;
- }
- }
- }
-
- return true;
- }
-
-}
Deleted:
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AssemblyAttachedLibraryMojo.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AssemblyAttachedLibraryMojo.java 2009-10-05
16:54:09 UTC (rev 15696)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AssemblyAttachedLibraryMojo.java 2009-10-05
21:26:45 UTC (rev 15697)
@@ -1,737 +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.builder.mojo;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
-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.model.Dependency;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Parent;
-import org.apache.maven.model.Resource;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectBuilder;
-import org.apache.maven.project.MavenProjectHelper;
-import org.apache.maven.project.ProjectBuildingException;
-import org.apache.velocity.VelocityContext;
-import org.codehaus.plexus.archiver.UnArchiver;
-import org.codehaus.plexus.archiver.manager.ArchiverManager;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.richfaces.cdk.xmlutils.NamesListComparator;
-import org.richfaces.cdk.xmlutils.ParsingException;
-import org.richfaces.cdk.xmlutils.XMLBody;
-import org.richfaces.cdk.xmlutils.XMLBodyMerge;
-import org.richfaces.cdk.xmlutils.XPathComparator;
-import org.w3c.dom.Node;
-
-/**
- * This plugin assembly full components library from modules, included in parent
- * project. Steps to create library : 1. Got parent project, and check modules
- * included in them. 2. For every module , build project and got it properties.
- * 3. Resolve module artifact, check for "jar" type and include/exclude
- * criteria. for accepted modules, unpack it to classes directory, and put
- * config files in separate directories. 4. Append unpacked directory to
- * resources, included in result jar. 5. Merge all META-INF/faces-config.xml ,
- * *.tld, *.taglib.xml , resources-config.xml into ones. 6. append dependencies
- * of included projects to this.
- *
- * @author shura
- * @goal attached
- * @phase package
- * @aggregator
- */
-public class AssemblyAttachedLibraryMojo extends AbstractCDKMojo {
-
- private static final String TEMPLATES_PREFIX = "/templates/";
-
- private static final String TEMPLATES12_PREFIX = "/templates12/";
-
- private static final String FACES_CONFIG_TEMPLATE = "faces-config.vm";
-
- private static final String RESOURCES_CONFIG_TEMPLATE =
"resources-config.vm";
-
- private static final String TLD_TEMPLATE = "tld.vm";
-
- private static final String TAGLIB_TEMPLATE = "taglib.vm";
-
- private static final String[] TLD_TAG_NAMES = new String[] {
- "description", "display-name", "icon",
"tlib-version",
- "short-name", "uri", "validator", "listener",
"tag",
- "tag-file", "function", "taglib-extension"
- };
-
- private static final String[] TAGLIB_TAG_NAMES = new String[] {
- "library-class", "namespace", "tag",
"function"
- };
-
- /**
- * 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;
-
- /**
- * To look up Archiver/UnArchiver implementations
- *
- * @component
- */
- private ArchiverManager archiverManager;
-
- /**
- * Project builder
- *
- * @component
- */
- private MavenProjectBuilder mavenProjectBuilder;
-
- /**
- * Maven ProjectHelper
- *
- * @component
- */
- private MavenProjectHelper projectHelper;
-
- /**
- * The reactor projects.
- *
- * @parameter expression="${reactorProjects}"
- * @required
- * @readonly
- */
- private List reactorProjects;
-
- /**
- * The reactor projects.
- *
- * @parameter expression="${project.parent}"
- * @readonly
- */
- private MavenProject parentProject;
-
- /**
- * The directory for compiled classes.
- *
- * @parameter expression="${project.build.directory}"
- * @required
- * @readonly
- */
- private File buildDirectory;
-
- /**
- * The directory for compiled classes.
- *
- * @parameter expression="${project.build.directory}/pom.xml"
- * @required
- * @readonly
- */
- private File generatedPom;
-
- /**
- * The directory for compiled classes.
- *
- * @parameter expression="${project.build.directory}/src"
- * @required
- * @readonly
- */
- private File modulesSrc;
-
- /**
- * @parameter
- */
- private String templates;
-
- /**
- * @parameter
- */
- private String includeTld = "META-INF/*.tld";
-
- /**
- * @parameter
- */
- private String includeTaglib = "META-INF/*.taglib.xml";
-
-
- /**
- * @parameter
- */
- private Taglib[] taglibs;
-
- /**
- *
- */
- public AssemblyAttachedLibraryMojo() {
- // used for plexus init.
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.maven.plugin.Mojo#execute()
- */
- public void execute() throws MojoExecutionException, MojoFailureException {
- if(null != reactorProjects){
- getLog().info("Reactor projects");
- for (Iterator iterator = reactorProjects.iterator(); iterator.hasNext();) {
- MavenProject reactor = (MavenProject) iterator.next();
- getLog().info("Project
"+reactor.getGroupId()+":"+reactor.getArtifactId());
- }
- }
- // assemblyProjects();
-
- }
-
- /**
- * @throws MojoFailureException
- * @throws MojoExecutionException
- */
- protected void assemblyProjects() throws MojoFailureException,
- MojoExecutionException {
- // Parent project not set for a custom lifecycles. Try to load artifact.
- if (null == parentProject || null == parentProject.getFile()) {
- Parent parentModel = project.getModel().getParent();
- if (null != parentModel) {
- String relativePath = parentModel.getRelativePath();
- File parentPom = new File(project.getFile().getAbsoluteFile().getParentFile(),
relativePath);
- if (parentPom.isDirectory()) {
- parentPom = new File(parentPom, "pom.xml");
- }
- if (parentPom.exists()) {
- try {
- parentProject = mavenProjectBuilder.build(parentPom,
- localRepository, null);
- } catch (ProjectBuildingException e) {
- throw new MojoFailureException("Error get parent project for a components
library");
- }
- } else {
- throw new MojoFailureException("Parent project pom file not found for a
components library");
- }
- }else {
- throw new MojoFailureException("Components library project must have parent pom
with components modules");
- }
-
- }
- if (null != parentProject) {
- this.checkLibraryConfig();
- if (null == templates) {
- templates = Library.JSF12.equals(library.getJsfVersion()) ? TEMPLATES12_PREFIX
- : TEMPLATES_PREFIX;
- }
- Model generatedProject;
- try {
- MavenXpp3Reader reader = new MavenXpp3Reader();
- generatedProject = reader
- .read(new FileReader(project.getFile()));
- } catch (Exception e1) {
- throw new MojoExecutionException("Unable to read local POM", e1);
- }
- List modules = parentProject.getModules();
- List models = new ArrayList(modules.size());
- Map<String, Dependency> projectsDependencies = new HashMap<String,
Dependency>();
- for (Iterator iter = modules.iterator(); iter.hasNext();) {
- String moduleName = (String) iter.next();
- getLog().info("Parent project have module " + moduleName);
- Model model;
- File f = new File(parentProject.getBasedir(), moduleName
- + "/pom.xml");
- if (f.exists()) {
- try {
- model = mavenProjectBuilder.build(f, localRepository,
- null).getModel();
- } catch (ProjectBuildingException e) {
- throw new MojoExecutionException(
- "Unable to read local module-POM", e);
- }
- } else {
- getLog().warn("No filesystem module-POM available");
-
- model = new Model();
- model.setName(moduleName);
- model.setUrl(moduleName);
- }
- if (project.getGroupId().equals(model.getGroupId())
- && "jar".equals(model.getPackaging())
- && (!project.getArtifactId().equals(
- model.getArtifactId()))) {
- // TODO - check include/exclude
- getLog().debug(
- "Project " + model.getName()
- + " included to library set");
- List dependencies = model.getDependencies();
- for (Iterator iterator = dependencies.iterator(); iterator
- .hasNext();) {
- Dependency dependency = (Dependency) iterator.next();
- getLog().debug(
- dependency.getClass().getName() + " : "
- + dependency + " with key: "
- + dependency.getManagementKey());
- if (!"test".equals(dependency.getScope())) {
- projectsDependencies.put(dependency
- .getManagementKey(), dependency);
-
- }
- }
- models.add(model);
- }
- }
- // Remove modules projects from dependencise
- Set<String> unwanted = new HashSet<String>(projectsDependencies
- .size());
- for (Iterator iter = models.iterator(); iter.hasNext();) {
- Model model = (Model) iter.next();
- for (Iterator iterator = projectsDependencies.values()
- .iterator(); iterator.hasNext();) {
- Dependency dependency = (Dependency) iterator.next();
- if (model.getGroupId().equals(dependency.getGroupId())
- && model.getArtifactId().equals(
- dependency.getArtifactId())) {
- getLog().debug(
- "Remove dependency of library module "
- + dependency.getManagementKey());
- unwanted.add(dependency.getManagementKey());
- }
- }
- // Got module and unpack it to target directory.
- Artifact artifact = factory.createBuildArtifact(model
- .getGroupId(), model.getArtifactId(), model
- .getVersion(), model.getPackaging());
- File moduleDir = new File(buildDirectory, model.getArtifactId());
- unpackArtifact(artifact, moduleDir, true);
- artifact = factory.createArtifactWithClassifier(model
- .getGroupId(), model.getArtifactId(), model
- .getVersion(), "jar", "sources");
- unpackArtifact(artifact, modulesSrc, false);
- }
- // Add projects dependencies to this project
- projectsDependencies.keySet().removeAll(unwanted);
- generatedProject.getDependencies().addAll(
- projectsDependencies.values());
- writePom(generatedProject);
- mergeFacesConfig(models);
- File resourcesConfig = new File(outputDirectory,
- "META-INF/resources-config.xml");
- mergeXML(models, "META-INF/resources-config.xml",
- RESOURCES_CONFIG_TEMPLATE, "/resource-config/resource",
"name/text()",
- new VelocityContext(), resourcesConfig, null);
- File tld = new File(outputDirectory, "META-INF/"
- + library.getTaglib().getShortName() + ".tld");
- mergeXML(models, includeTld, TLD_TEMPLATE,
- "/taglib/tag | /taglib/listener",
- null, new VelocityContext(), tld, new NamesListComparator(
- new XPathComparator("name/text()", "listener-class/text()"),
TLD_TAG_NAMES));
- File taglib = new File(outputDirectory, "META-INF/"
- + library.getTaglib().getShortName() + ".taglib.xml");
- mergeXML(models, includeTaglib, TAGLIB_TEMPLATE,
- "/facelet-taglib/tag | /facelet-taglib/function",
- null, new VelocityContext(), taglib, new NamesListComparator(
- new XPathComparator("tag-name/text()",
"function-name/text()"), TAGLIB_TAG_NAMES));
- }else {
- throw new MojoFailureException("Components library project must have parent pom
with components modules");
- }
- }
-
- /**
- * @param models
- * @throws MojoExecutionException
- */
- private void mergeFacesConfig(List models) throws MojoExecutionException {
- StringBuffer config = new StringBuffer();
- for (int i = 0; i < library.getRenderkits().length; i++) {
- Renderkit kit = library.getRenderkits()[i];
- kit.setContent(new StringBuffer());
- }
- for (Iterator iter = models.iterator(); iter.hasNext();) {
- Model model = (Model) iter.next();
- File moduleFacesConfig = new File(buildDirectory, model
- .getArtifactId()
- + "/META-INF/faces-config.xml");
- if (moduleFacesConfig.exists()) {
- getLog().info(
- "Process faces-config.xml for module "
- + model.getArtifactId());
- XMLBody configBody = new XMLBody();
- try {
- configBody.loadXML(new FileInputStream(moduleFacesConfig));
- config
- .append(configBody
- .getContent("/faces-config/*[name()!=\'render-kit\']"));
- for (int i = 0; i < library.getRenderkits().length; i++) {
- Renderkit kit = library.getRenderkits()[i];
- kit
- .getContent()
- .append(
- configBody
- .getContent("/faces-config/render-kit[child::render-kit-id='"
- + kit.getName()
- + "']/renderer"));
- }
- } catch (FileNotFoundException e) {
- throw new MojoExecutionException(
- "Could't read faces-config file", e);
- } catch (org.richfaces.cdk.xmlutils.ParsingException e) {
- throw new MojoExecutionException(
- "Error parsing faces-config file", e);
- }
- }
- }
- VelocityContext context = new VelocityContext();
- context.put("content", config.toString());
- context.put("library", library);
- context.put("renderkits", Arrays.asList(library.getRenderkits()));
- try {
- writeParsedTemplate(templates + FACES_CONFIG_TEMPLATE, context,
- new File(outputDirectory, "META-INF/faces-config.xml"));
- } catch (Exception e) {
- throw new MojoExecutionException(
- "Error to process faces-config template", e);
- }
- }
-
- /**
- * Merge XML files from extracted models to one in build directory.
- *
- * @param models
- * models collected in library.
- * @param filename
- * relative path to config file in models/output.
- * @param templateName -
- * name of velocity template for result file.
- * @param commonXpath -
- * XPath expression fof common part of result file.
- * @param keyXPath - XPath expression for key part of common parts
- * @param keySet - {@link Set} to check for duplicate keys. Must not be null
- * @param context -
- * Velocity context for template processing.
- * @throws MojoExecutionException
- */
- private void mergeXML(List<Model> models, String filename, String templateName,
- String commonXpath, String keyXPath, VelocityContext context, File target,
Comparator<Node> comparator)
- throws MojoExecutionException {
- StringBuilder content = new StringBuilder();
- XMLBodyMerge bodyMerge = new XMLBodyMerge(commonXpath, keyXPath);
- List<XMLBody> xmls = new ArrayList<XMLBody>(models.size());
- String[] split = filename.split(",");
- for (Iterator<Model> iter = models.iterator(); iter.hasNext();) {
- Model model = iter.next();
- File moduleDir = new File(buildDirectory, model.getArtifactId());
- DirectoryScanner ds = new DirectoryScanner();
- ds.setFollowSymlinks(true);
- ds.setBasedir(moduleDir);
- ds.setIncludes(split);
- ds.addDefaultExcludes();
- ds.scan();
- String[] files = ds.getIncludedFiles();
- for (int i = 0; i < files.length; i++) {
- File moduleFacesConfig = new File(moduleDir, files[i]);
- getLog().info(
- "Process " + files[i] + " for module "
- + model.getArtifactId());
- XMLBody configBody = new XMLBody();
- try {
- configBody.loadXML(new FileInputStream(moduleFacesConfig));
- xmls.add(configBody);
- bodyMerge.add(configBody);
- } catch (FileNotFoundException e) {
- throw new MojoExecutionException("Could't read file "
- + moduleFacesConfig.getPath(), e);
- } catch (ParsingException e) {
- throw new MojoExecutionException(
- "Error parsing config file "
- + moduleFacesConfig.getPath(), e);
- }
-
-
- }
- }
- if (comparator != null) {
- bodyMerge.sort(comparator);
- }
-
- try {
- content.append(bodyMerge.getContent());
- } catch (Exception e) {
- // TODO: handle exception
- }
-
- if (xmls.size() > 0) {
- context.put("content", content);
- context.put("library", library);
- context.put("models", models);
- context.put("xmls", xmls);
- try {
- writeParsedTemplate(templates + templateName, context, target);
- } catch (Exception e) {
- throw new MojoExecutionException("Error to process template "
- + templateName + " for files " + filename, e);
- }
-
- }
- }
-
- private void unpackArtifact(Artifact artifact, File moduleDir,
- boolean isResource) throws MojoExecutionException {
- try {
- resolver.resolve(artifact, Collections.EMPTY_LIST, localRepository);
- unpack(artifact.getFile(), moduleDir);
- if (isResource) {
- Resource resource = new Resource();
- resource.setDirectory(moduleDir.getPath());
- resource.addExclude("META-INF/faces-config.xml");
- resource.addExclude("META-INF/resources-config.xml");
- resource.addExclude("META-INF/*.taglib.xml");
- resource.addExclude("META-INF/*.tld");
- project.addResource(resource);
-
- }
- } catch (ArtifactResolutionException e) {
- getLog().error("Error with resolve artifact " + artifact, e);
- } catch (ArtifactNotFoundException e) {
- getLog().error("Not found artifact " + artifact, e);
- }
- }
-
- private List<MavenProject> populateReactorProjects() {
- List<MavenProject> projects = new ArrayList<MavenProject>();
- if (reactorProjects != null && reactorProjects.size() > 1) {
- Iterator reactorItr = reactorProjects.iterator();
-
- while (reactorItr.hasNext()) {
- MavenProject reactorProject = (MavenProject) reactorItr.next();
-
- if (reactorProject != null
- && reactorProject.getParent() != null
- && project.getArtifactId().equals(
- reactorProject.getParent().getArtifactId())) {
- String name = reactorProject.getGroupId() + ":"
- + reactorProject.getArtifactId();
- getLog().info("Have reactor project with name " + name);
- projects.add(reactorProject);
- }
- }
- }
- return projects;
- }
-
- /**
- * Unpacks the archive file.
- *
- * @param file
- * File to be unpacked.
- * @param location
- * Location where to put the unpacked files.
- */
- private void unpack(File file, File location) throws MojoExecutionException {
-
- getLog().debug(
- "Unpack file " + file.getAbsolutePath() + " to: "
- + location.getAbsolutePath());
- try {
- location.mkdirs();
-
- UnArchiver unArchiver;
-
- unArchiver = archiverManager.getUnArchiver(file);
-
- unArchiver.setSourceFile(file);
-
- unArchiver.setDestDirectory(location);
-
- unArchiver.setOverwrite(true);
-
- unArchiver.extract();
-
- } catch (Exception e) {
- throw new MojoExecutionException("Error unpacking file: " + file
- + " to: " + location + "\r\n" + e.toString(), e);
- }
- }
-
- private void writePom(Model pom) throws MojoExecutionException {
- MavenXpp3Writer pomWriter = new MavenXpp3Writer();
- try {
- FileWriter out = new FileWriter(generatedPom);
- pomWriter.write(out, pom);
- } catch (IOException e) {
- throw new MojoExecutionException("Error for write generated pom", e);
- }
-
- }
-
- /**
- * @return the archiverManager
- */
- public ArchiverManager getArchiverManager() {
- return this.archiverManager;
- }
-
- /**
- * @param archiverManager
- * the archiverManager to set
- */
- public void setArchiverManager(ArchiverManager archiverManager) {
- this.archiverManager = archiverManager;
- }
-
- /**
- * @return the buildDirectory
- */
- public File getBuildDirectory() {
- return this.buildDirectory;
- }
-
- /**
- * @param buildDirectory
- * the buildDirectory to set
- */
- public void setBuildDirectory(File buildDirectory) {
- this.buildDirectory = buildDirectory;
- }
-
- /**
- * @return the factory
- */
- public org.apache.maven.artifact.factory.ArtifactFactory getFactory() {
- return this.factory;
- }
-
- /**
- * @param factory
- * the factory to set
- */
- public void setFactory(
- org.apache.maven.artifact.factory.ArtifactFactory factory) {
- this.factory = factory;
- }
-
- /**
- * @return the localRepository
- */
- public ArtifactRepository getLocalRepository() {
- return this.localRepository;
- }
-
- /**
- * @param localRepository
- * the localRepository to set
- */
- public void setLocalRepository(ArtifactRepository localRepository) {
- this.localRepository = localRepository;
- }
-
- /**
- * @return the mavenProjectBuilder
- */
- public MavenProjectBuilder getMavenProjectBuilder() {
- return this.mavenProjectBuilder;
- }
-
- /**
- * @param mavenProjectBuilder
- * the mavenProjectBuilder to set
- */
- public void setMavenProjectBuilder(MavenProjectBuilder mavenProjectBuilder) {
- this.mavenProjectBuilder = mavenProjectBuilder;
- }
-
- /**
- * @return the parentProject
- */
- public MavenProject getParentProject() {
- return this.parentProject;
- }
-
- /**
- * @param parentProject
- * the parentProject to set
- */
- public void setParentProject(MavenProject parentProject) {
- this.parentProject = parentProject;
- }
-
- /**
- * @return the reactorProjects
- */
- public List getReactorProjects() {
- return this.reactorProjects;
- }
-
- /**
- * @param reactorProjects
- * the reactorProjects to set
- */
- public void setReactorProjects(List reactorProjects) {
- this.reactorProjects = reactorProjects;
- }
-
- /**
- * @return the resolver
- */
- public org.apache.maven.artifact.resolver.ArtifactResolver getResolver() {
- return this.resolver;
- }
-
- /**
- * @param resolver
- * the resolver to set
- */
- public void setResolver(
- org.apache.maven.artifact.resolver.ArtifactResolver resolver) {
- this.resolver = resolver;
- }
-
-}
Deleted:
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AssemblyLibraryMojo.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AssemblyLibraryMojo.java 2009-10-05
16:54:09 UTC (rev 15696)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/AssemblyLibraryMojo.java 2009-10-05
21:26:45 UTC (rev 15697)
@@ -1,942 +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.builder.mojo;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
-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.model.Dependency;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Parent;
-import org.apache.maven.model.Resource;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectBuilder;
-import org.apache.maven.project.ProjectBuildingException;
-import org.apache.velocity.VelocityContext;
-import org.codehaus.plexus.archiver.UnArchiver;
-import org.codehaus.plexus.archiver.manager.ArchiverManager;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.richfaces.cdk.xmlutils.NamesListComparator;
-import org.richfaces.cdk.xmlutils.ParsingException;
-import org.richfaces.cdk.xmlutils.XMLBody;
-import org.richfaces.cdk.xmlutils.XMLBodyMerge;
-import org.richfaces.cdk.xmlutils.XPathComparator;
-import org.w3c.dom.Node;
-
-/**
- * This plugin assembly full components library from modules, included in parent
- * project. Steps to create library : 1. Got parent project, and check modules
- * included in them. 2. For every module , build project and got it properties.
- * 3. Resolve module artifact, check for "jar" type and include/exclude
- * criteria. for accepted modules, unpack it to classes directory, and put
- * config files in separate directories. 4. Append unpacked directory to
- * resources, included in result jar. 5. Merge all META-INF/faces-config.xml ,
- * *.tld, *.taglib.xml, *.component-dependencies.xml , resources-config.xml into ones.
- * 6. append dependencies of included projects to this.
- *
- * @author shura
- * @goal assembly
- * @requiresDependencyResolution compile
- * @phase generate-resources
- */
-public class AssemblyLibraryMojo extends AbstractCDKMojo {
-
- private static final String TEMPLATES_PREFIX = "/templates/";
-
- private static final String TEMPLATES12_PREFIX = "/templates12/";
-
- private static final String FACES_CONFIG_TEMPLATE = "faces-config.vm";
-
- private static final String RESOURCES_CONFIG_TEMPLATE =
"resources-config.vm";
-
- private static final String COMPONENT_DEPENDENCIES_TEMPLATE =
"component-dependencies.vm";
-
- private static final String XCSS_TEMPLATE = "xcss.vm";
-
- private static final String TLD_TEMPLATE = "tld.vm";
-
- private static final String TAGLIB_TEMPLATE = "taglib.vm";
-
- private static final String[] TLD_TAG_NAMES = new String[] {
- "description", "display-name", "icon",
"tlib-version",
- "short-name", "uri", "validator", "listener",
"tag",
- "tag-file", "function", "taglib-extension"
- };
-
- private static final String[] TAGLIB_TAG_NAMES = new String[] {
- "library-class", "namespace", "tag",
"function"
- };
-
- private static final String[] DEPENDENCIES_TAG_NAMES = new String[] {
- "component"
- };
-
- private static final Comparator<Node> TLD_COMPARATOR = new NamesListComparator(
- new XPathComparator("listener-class/text()", "name/text()"),
TLD_TAG_NAMES);
-
- private static final Comparator<Node> FACELET_COMPARATOR = new
NamesListComparator(
- new XPathComparator("function-name/text()", "tag-name/text()"),
TAGLIB_TAG_NAMES);
-
- private static final Comparator<Node> DEPENDENCIES_COMPARATOR = new
NamesListComparator(
- new XPathComparator("name/text()"), DEPENDENCIES_TAG_NAMES);
-
- /**
- * 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;
-
- /**
- * To look up Archiver/UnArchiver implementations
- *
- * @component
- */
- private ArchiverManager archiverManager;
-
- /**
- * Project builder
- *
- * @component
- */
- private MavenProjectBuilder mavenProjectBuilder;
-
- /**
- * The reactor projects.
- *
- * @parameter expression="${reactorProjects}"
- * @required
- * @readonly
- */
- private List reactorProjects;
-
- /**
- * The reactor projects.
- *
- * @parameter expression="${project.parent}"
- * @readonly
- */
- private MavenProject parentProject;
-
- /**
- * The list of resources we want to transfer.
- *
- * @parameter default-value="src/main/config"
- */
- private File config;
-
- /**
- * The directory for compiled classes.
- *
- * @parameter expression="${project.build.directory}"
- * @required
- * @readonly
- */
- private File buildDirectory;
-
- /**
- * @parameter default-value="${project.build.directory}/modules"
- */
- private File modulesDirectory;
-
- /**
- * The directory for compiled classes.
- *
- * @parameter expression="${project.build.directory}/pom.xml"
- * @required
- * @readonly
- */
- private File generatedPom;
-
- /**
- * The directory for compiled classes.
- *
- * @parameter expression="${project.build.directory}/src"
- * @required
- * @readonly
- */
- private File modulesSrc;
-
- /**
- * @parameter
- */
- private String templates;
-
- /**
- * @parameter
- */
- private String includeTld = "META-INF/*.tld";
-
- /**
- * @parameter
- */
- private String includeTaglib = "META-INF/*.taglib.xml";
-
- /**
- * @parameter
- */
- private String includeDependencies = "META-INF/*.component-dependencies.xml";
-
- /**
- * @parameter
- */
- private String includeXcss = "**/*.xcss";
-
- /**
- * @parameter
- */
- private String excludeXcss = null;
-
- /**
- * @parameter
- */
- private String commonStyle;
-
- /**
- * @parameter
- */
- private String templateXpath;
-
- /**
- *
- */
- public AssemblyLibraryMojo() {
- // used for plexus init.
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.maven.plugin.Mojo#execute()
- */
- public void execute() throws MojoExecutionException, MojoFailureException {
- setupParentProject();
- checkLibraryConfig();
- if (null == templates) {
- templates = Library.JSF12.equals(library.getJsfVersion()) ? TEMPLATES12_PREFIX
- : TEMPLATES_PREFIX;
- }
- List<Model> models = extractModules();
- mergeFacesConfig(models);
- File resourcesConfig = new File(outputDirectory,
- "META-INF/resources-config.xml");
- mergeXML(models, "META-INF/resources-config.xml", null,
- RESOURCES_CONFIG_TEMPLATE, "/resource-config/resource",
- "name/text()", new VelocityContext(), resourcesConfig, false, null);
-
- if (null != commonStyle) {
- File commonXcss = new File(outputDirectory, commonStyle);
- mergeXML(models, includeXcss, excludeXcss, XCSS_TEMPLATE,
- templateXpath, null, new VelocityContext(), commonXcss, true, null);
- }
-
- if (null != library.getTaglibs() && library.getTaglibs().length > 0) {
- for (int i = 0; i < library.getTaglibs().length; i++) {
- Taglib taglib = library.getTaglibs()[i];
- List<Model> taglibModels;
- if (taglib.getIncludeModules() == null
- && taglib.getExcludeModules() == null) {
- taglibModels = models;
- } else {
- String[] includeModules = null;
- String[] excludeModules = null;
- if (null != taglib.getIncludeModules()) {
- includeModules = taglib.getIncludeModules().split(",");
- Arrays.sort(includeModules);
- }
- if (null != taglib.getExcludeModules()) {
- excludeModules = taglib.getExcludeModules().split(",");
- Arrays.sort(excludeModules);
- }
- taglibModels = new ArrayList<Model>();
- for (Iterator iterator = models.iterator(); iterator
- .hasNext();) {
- Model model = (Model) iterator.next();
- String id = model.getArtifactId();
- if ((includeModules == null || Arrays.binarySearch(
- includeModules, id) >= 0)
- && (excludeModules == null || Arrays
- .binarySearch(excludeModules, id) < 0)) {
- taglibModels.add(model);
- }
- }
- }
- generateTaglibAndDependencies(taglibModels, taglib);
- }
- } else {
- generateTaglibAndDependencies(models, library.getTaglib());
- }
- }
-
- /**
- * @param models
- * @throws MojoExecutionException
- */
- private void generateTaglibAndDependencies(List<Model> models, Taglib taglib)
- throws MojoExecutionException {
- getLog().debug(
- "Assembly taglib for uri " + taglib.getUri()
- + " with short name " + taglib.getShortName());
- VelocityContext taglibContext = new VelocityContext();
- taglibContext.put("taglib", taglib);
- // Build includes/excludes Xpath condition
- String nameTag = "name";
- createTagCondition(taglib, nameTag);
- File tld = new File(outputDirectory, "META-INF/" + taglib.getTaglib()
- + ".tld");
- getLog().debug("Write JSP taglib " + tld.getPath());
- String commonXPath = "/taglib/tag"
- + createTagCondition(taglib, "name") + " | /taglib/listener |
/taglib/function";
-
- mergeXML(models, includeTld, null, TLD_TEMPLATE, commonXPath,
- "listener-class/text() | name/text()", new VelocityContext(taglibContext),
tld, false, TLD_COMPARATOR);
-
-
- File faceletsTaglib = new File(outputDirectory, "META-INF/"
- + taglib.getTaglib() + ".taglib.xml");
- commonXPath = "/facelet-taglib/tag"
- + createTagCondition(taglib, "tag-name")
- + " | /facelet-taglib/function";
-
- mergeXML(models, includeTaglib, null, TAGLIB_TEMPLATE, commonXPath,
"tag-name/text() | function-name/text()", new VelocityContext(
- taglibContext), faceletsTaglib, false, FACELET_COMPARATOR);
- getLog().debug("Write Facelets taglib " + faceletsTaglib.getPath());
-
- File dependenciesFile = new File(outputDirectory, "META-INF/"
- + taglib.getTaglib() + ".component-dependencies.xml");
- commonXPath = "/components/component" + createTagCondition(taglib,
"name");
-
- mergeXML(models, includeDependencies, null, COMPONENT_DEPENDENCIES_TEMPLATE,
commonXPath, "name/text()", new VelocityContext(
- taglibContext), dependenciesFile, false, DEPENDENCIES_COMPARATOR);
- getLog().debug("Write dependencies file " + dependenciesFile.getPath());
- }
-
- /**
- * @param taglib
- * @param nameTag
- */
- private String createTagCondition(Taglib taglib, String nameTag) {
- StringBuffer condition = new StringBuffer();
- if (taglib.getIncludeTags() != null || taglib.getExcludeTags() != null) {
- condition.append('[');
- if (taglib.getIncludeTags() != null) {
- condition.append('(');
- String[] includes = taglib.getIncludeTags().split(",");
- for (int i = 0; i < includes.length; i++) {
- String includeTag = includes[i];
- if (i != 0) {
- condition.append(" or ");
- }
- condition.append("normalize-space(").append(nameTag)
- .append(")='").append(includeTag).append("'");
- }
- condition.append(')');
- }
- if (taglib.getIncludeTags() != null
- && taglib.getExcludeTags() != null) {
- condition.append(" and ");
- }
- if (taglib.getExcludeTags() != null) {
- condition.append('(');
- String[] excludes = taglib.getExcludeTags().split(",");
- for (int i = 0; i < excludes.length; i++) {
- String includeTag = excludes[i];
- if (i != 0) {
- condition.append(" and ");
- }
- condition.append("normalize-space(").append(nameTag)
- .append(")!='").append(includeTag).append("'");
- }
- condition.append(')');
- }
- condition.append(']');
- }
- return condition.toString();
- }
-
- /**
- * @return
- * @throws MojoExecutionException
- */
- private List<Model> extractModules() throws MojoExecutionException {
- List<String> modules = parentProject.getModules();
- List<Model> models = new ArrayList<Model>(modules.size());
- Map<String, Dependency> projectsDependencies = new HashMap<String,
Dependency>();
- for (Iterator<String> iter = modules.iterator(); iter.hasNext();) {
- String moduleName = iter.next();
- getLog().info("Parent project have module " + moduleName);
- Model model;
- File f = new File(parentProject.getBasedir(), moduleName
- + "/pom.xml");
- if (f.exists()) {
- try {
- model = mavenProjectBuilder.build(f, localRepository, null)
- .getModel();
- } catch (ProjectBuildingException e) {
- throw new MojoExecutionException(
- "Unable to read local module-POM", e);
- }
- } else {
- getLog().warn("No filesystem module-POM available");
-
- model = new Model();
- model.setName(moduleName);
- model.setUrl(moduleName);
- }
- if (project.getGroupId().equals(model.getGroupId())
- && "jar".equals(model.getPackaging())
- && (!project.getArtifactId().equals(model.getArtifactId()))) {
- // TODO - check include/exclude
- getLog().debug(
- "Project " + model.getName()
- + " included to library set");
- List<Dependency> dependencies = model.getDependencies();
- for (Iterator<Dependency> iterator = dependencies.iterator(); iterator
- .hasNext();) {
- Dependency dependency = iterator.next();
- getLog().debug(
- dependency.getClass().getName() + " : "
- + dependency + " with key: "
- + dependency.getManagementKey());
- if (!"test".equals(dependency.getScope())) {
- projectsDependencies.put(dependency.getManagementKey(),
- dependency);
-
- }
- }
- models.add(model);
- }
- }
- // Remove modules projects from dependencise
- Set<String> unwanted = new HashSet<String>(projectsDependencies.size());
- for (Iterator<Model> iter = models.iterator(); iter.hasNext();) {
- Model model = (Model) iter.next();
- for (Iterator<Dependency> iterator = projectsDependencies.values().iterator();
iterator
- .hasNext();) {
- Dependency dependency = (Dependency) iterator.next();
- if (model.getGroupId().equals(dependency.getGroupId())
- && model.getArtifactId().equals(
- dependency.getArtifactId())) {
- getLog().debug(
- "Remove dependency of library module "
- + dependency.getManagementKey());
- unwanted.add(dependency.getManagementKey());
- }
- }
- // Got module and unpack it to target directory.
- Artifact artifact = factory.createBuildArtifact(model.getGroupId(),
- model.getArtifactId(), model.getVersion(), model
- .getPackaging());
- File moduleDir = new File(modulesDirectory, model.getArtifactId());
- unpackArtifact(artifact, moduleDir, true);
- artifact = factory
- .createArtifactWithClassifier(model.getGroupId(), model
- .getArtifactId(), model.getVersion(), "jar",
- "sources");
- unpackArtifact(artifact, modulesSrc, false);
- }
- // Add projects dependencies to this project
- projectsDependencies.keySet().removeAll(unwanted);
- setupGeneratedProject(projectsDependencies);
- return models;
- }
-
- /**
- * @param projectsDependencies
- * @throws MojoExecutionException
- */
- private void setupGeneratedProject(
- Map<String, Dependency> projectsDependencies)
- throws MojoExecutionException {
- Model generatedProject;
- try {
- MavenXpp3Reader reader = new MavenXpp3Reader();
- generatedProject = reader.read(new FileReader(project.getFile()));
- } catch (Exception e1) {
- throw new MojoExecutionException("Unable to read local POM", e1);
- }
- generatedProject.getDependencies()
- .addAll(projectsDependencies.values());
- writePom(generatedProject);
- project.setDependencies(new
ArrayList<Dependency>(projectsDependencies.values()));
- // project.setFile(generatedPom);
- }
-
- /**
- * Check parent project, build if nesessary.
- *
- * @throws MojoFailureException
- */
- protected void setupParentProject() throws MojoFailureException {
- // Parent project not set for a custom lifecycles. Try to load artifact.
- if (null == parentProject || null == parentProject.getFile()) {
- Parent parentModel = project.getModel().getParent();
- if (null != parentModel) {
- String relativePath = parentModel.getRelativePath();
- File parentPom = new File(project.getFile().getAbsoluteFile()
- .getParentFile(), relativePath);
- if (parentPom.isDirectory()) {
- parentPom = new File(parentPom, "pom.xml");
- }
- if (parentPom.exists()) {
- try {
- parentProject = mavenProjectBuilder.build(parentPom,
- localRepository, null);
- if (null == parentProject) {
- throw new MojoFailureException(
- "Components library project must have parent pom with components
modules");
- }
- } catch (ProjectBuildingException e) {
- throw new MojoFailureException(
- "Error get parent project for a components library");
- }
- } else {
- throw new MojoFailureException(
- "Parent project pom file not found for a components library");
- }
- } else {
- throw new MojoFailureException(
- "Components library project must have parent pom with components
modules");
- }
-
- }
- }
-
- /**
- * @param models
- * @throws MojoExecutionException
- */
- private void mergeFacesConfig(List<Model> models) throws MojoExecutionException {
- StringBuffer facesConfig = new StringBuffer();
- for (int i = 0; i < library.getRenderkits().length; i++) {
- Renderkit kit = library.getRenderkits()[i];
- kit.setContent(new StringBuffer());
- }
- // Process all faces-config.xml from modules
- for (Iterator<Model> iter = models.iterator(); iter.hasNext();) {
- Model model = iter.next();
- File moduleFacesConfig = new File(modulesDirectory, model
- .getArtifactId()
- + "/META-INF/faces-config.xml");
- processFacesConfigFile(facesConfig, moduleFacesConfig);
- }
- // Process faces-config from project resources
- if (null !=config) {
- processFacesConfigFile(facesConfig, new File(config,
"META-INF/faces-config.xml"));
- }
- VelocityContext context = new VelocityContext();
- context.put("content", facesConfig.toString());
- context.put("library", library);
- context.put("renderkits", Arrays.asList(library.getRenderkits()));
- try {
- writeParsedTemplate(templates + FACES_CONFIG_TEMPLATE, context,
- new File(outputDirectory, "META-INF/faces-config.xml"));
- } catch (Exception e) {
- throw new MojoExecutionException(
- "Error to process faces-config template", e);
- }
- }
-
- /**
- * @param config
- * @param moduleFacesConfig
- * @throws MojoExecutionException
- */
- private void processFacesConfigFile(StringBuffer config,
- File moduleFacesConfig) throws MojoExecutionException {
- if (moduleFacesConfig.exists()) {
- getLog().info(
- "Process "+moduleFacesConfig.getName());
- XMLBody configBody = new XMLBody();
- try {
- configBody.loadXML(new FileInputStream(moduleFacesConfig));
- config
- .append(configBody
- .getContent("/faces-config/*[name()!=\'render-kit\']"));
- for (int i = 0; i < library.getRenderkits().length; i++) {
- Renderkit kit = library.getRenderkits()[i];
- kit
- .getContent()
- .append(
- configBody
- .getContent("/faces-config/render-kit[child::render-kit-id='"
- + kit.getName()
- + "']/renderer"));
- }
- } catch (FileNotFoundException e) {
- throw new MojoExecutionException(
- "Could't read faces-config file", e);
- } catch (ParsingException e) {
- throw new MojoExecutionException(
- "Error parsing faces-config file", e);
- }
- }
- }
-
- /**
- * Merge XML files from extracted models to one in build directory.
- *
- * @param models
- * models collected in library.
- * @param includes
- * relative path to config file in models/output.
- * @param templateName -
- * name of velocity template for result file.
- * @param commonXpath -
- * XPath expression fof common part of result file.
- * @param keyXPath -
- * XPath expression for key part of common parts
- * @param context -
- * Velocity context for template processing.
- * @param namespaceAware TODO
- * @param keySet -
- * {@link Set} to check for duplicate keys. Must not be null
- * @throws MojoExecutionException
- */
- private void mergeXML(List<Model> models, String includes, String excludes, String
templateName,
- String commonXpath, String keyXPath, VelocityContext context,
- File target, boolean namespaceAware, Comparator<Node> comparator) throws
MojoExecutionException {
- StringBuffer content = new StringBuffer();
- String[] split = includes.split(",");
- String[] excludesSplit = excludes != null ? excludes.split(",") : null;
- XMLBodyMerge xBodyMerge = new XMLBodyMerge(commonXpath, keyXPath);
- for (Iterator<Model> iter = models.iterator(); iter.hasNext();) {
- Model model = iter.next();
- File moduleDir = new File(modulesDirectory, model.getArtifactId());
- mergeXMLdir(moduleDir, namespaceAware, split, excludesSplit, xBodyMerge);
- }
- if(null!=config){
- mergeXMLdir(config, namespaceAware, split, excludesSplit, xBodyMerge);
- }
-
- if (comparator != null) {
- xBodyMerge.sort(comparator);
- }
- try {
- content.append(xBodyMerge.getContent());
- } catch (Exception e1) {
- throw new MojoExecutionException("XML Merge Exception Occured", e1);
- }
- if (content.length() > 0) {
- context.put("content", content.toString());
- context.put("library", library);
- context.put("models", models);
- try {
- writeParsedTemplate(templates + templateName, context, target);
- } catch (Exception e) {
- throw new MojoExecutionException("Error to process template "
- + templateName + " for files " + includes, e);
- }
-
- }
- }
-
- /**
- * @param moduleDir
- * @param commonXpath
- * @param keyXPath
- * @param namespaceAware
- * @param keySet
- * @param content
- * @param xmls
- * @param split
- * @throws IllegalStateException
- * @throws MojoExecutionException
- */
- private void mergeXMLdir(File moduleDir, boolean namespaceAware, String[] split,
String[] excludesSplit, XMLBodyMerge xBodyMerge)
- throws IllegalStateException, MojoExecutionException {
- DirectoryScanner ds = new DirectoryScanner();
- ds.setFollowSymlinks(true);
- ds.setBasedir(moduleDir);
- ds.setIncludes(split);
- ds.setExcludes(excludesSplit);
- ds.addDefaultExcludes();
- ds.scan();
- String[] files = ds.getIncludedFiles();
- for (int i = 0; i < files.length; i++) {
- File moduleFacesConfig = new File(moduleDir, files[i]);
- getLog().info(
- "Process " + files[i] );
- XMLBody configBody = new XMLBody();
- try {
- configBody.loadXML(new FileInputStream(moduleFacesConfig),namespaceAware);
- xBodyMerge.add(configBody);
- } catch (FileNotFoundException e) {
- throw new MojoExecutionException("Could't read file "
- + moduleFacesConfig.getPath(), e);
- } catch (ParsingException e) {
- throw new MojoExecutionException(
- "Error parsing config file "
- + moduleFacesConfig.getPath(), e);
- }
- }
- }
-
- private void unpackArtifact(Artifact artifact, File moduleDir,
- boolean isResource) throws MojoExecutionException {
- try {
- resolver.resolve(artifact, Collections.EMPTY_LIST, localRepository);
- unpack(artifact.getFile(), moduleDir);
- if (isResource) {
- Resource resource = new Resource();
- resource.setDirectory(moduleDir.getPath());
- resource.addExclude("META-INF/faces-config.xml");
- resource.addExclude("META-INF/resources-config.xml");
- resource.addExclude("META-INF/*.taglib.xml");
- resource.addExclude("META-INF/*.component-dependencies.xml");
- resource.addExclude("META-INF/*.tld");
- project.addResource(resource);
-
- }
- } catch (ArtifactResolutionException e) {
- getLog().error("Error with resolve artifact " + artifact, e);
- } catch (ArtifactNotFoundException e) {
- getLog().error("Not found artifact " + artifact, e);
- }
- }
-
- private List<MavenProject> populateReactorProjects() {
- List<MavenProject> projects = new ArrayList<MavenProject>();
- if (reactorProjects != null && reactorProjects.size() > 1) {
- Iterator reactorItr = reactorProjects.iterator();
-
- while (reactorItr.hasNext()) {
- MavenProject reactorProject = (MavenProject) reactorItr.next();
-
- if (reactorProject != null
- && reactorProject.getParent() != null
- && project.getArtifactId().equals(
- reactorProject.getParent().getArtifactId())) {
- String name = reactorProject.getGroupId() + ":"
- + reactorProject.getArtifactId();
- getLog().info("Have reactor project with name " + name);
- projects.add(reactorProject);
- }
- }
- }
- return projects;
- }
-
- /**
- * Unpacks the archive file.
- *
- * @param file
- * File to be unpacked.
- * @param location
- * Location where to put the unpacked files.
- */
- private void unpack(File file, File location) throws MojoExecutionException {
-
- getLog().debug(
- "Unpack file " + file.getAbsolutePath() + " to: "
- + location.getAbsolutePath());
- try {
- location.mkdirs();
-
- UnArchiver unArchiver;
-
- unArchiver = archiverManager.getUnArchiver(file);
-
- unArchiver.setSourceFile(file);
-
- unArchiver.setDestDirectory(location);
-
- unArchiver.setOverwrite(true);
-
- unArchiver.extract();
-
- } catch (Exception e) {
- throw new MojoExecutionException("Error unpacking file: " + file
- + " to: " + location + "\r\n" + e.toString(), e);
- }
- }
-
- private void writePom(Model pom) throws MojoExecutionException {
- MavenXpp3Writer pomWriter = new MavenXpp3Writer();
- try {
- FileWriter out = new FileWriter(generatedPom);
- pomWriter.write(out, pom);
- } catch (IOException e) {
- throw new MojoExecutionException("Error for write generated pom", e);
- }
-
- }
-
- /**
- * @return the archiverManager
- */
- public ArchiverManager getArchiverManager() {
- return this.archiverManager;
- }
-
- /**
- * @param archiverManager
- * the archiverManager to set
- */
- public void setArchiverManager(ArchiverManager archiverManager) {
- this.archiverManager = archiverManager;
- }
-
- /**
- * @return the buildDirectory
- */
- public File getBuildDirectory() {
- return this.buildDirectory;
- }
-
- /**
- * @param buildDirectory
- * the buildDirectory to set
- */
- public void setBuildDirectory(File buildDirectory) {
- this.buildDirectory = buildDirectory;
- }
-
- /**
- * @return the factory
- */
- public org.apache.maven.artifact.factory.ArtifactFactory getFactory() {
- return this.factory;
- }
-
- /**
- * @param factory
- * the factory to set
- */
- public void setFactory(
- org.apache.maven.artifact.factory.ArtifactFactory factory) {
- this.factory = factory;
- }
-
- /**
- * @return the localRepository
- */
- public ArtifactRepository getLocalRepository() {
- return this.localRepository;
- }
-
- /**
- * @param localRepository
- * the localRepository to set
- */
- public void setLocalRepository(ArtifactRepository localRepository) {
- this.localRepository = localRepository;
- }
-
- /**
- * @return the mavenProjectBuilder
- */
- public MavenProjectBuilder getMavenProjectBuilder() {
- return this.mavenProjectBuilder;
- }
-
- /**
- * @param mavenProjectBuilder
- * the mavenProjectBuilder to set
- */
- public void setMavenProjectBuilder(MavenProjectBuilder mavenProjectBuilder) {
- this.mavenProjectBuilder = mavenProjectBuilder;
- }
-
- /**
- * @return the parentProject
- */
- public MavenProject getParentProject() {
- return this.parentProject;
- }
-
- /**
- * @param parentProject
- * the parentProject to set
- */
- public void setParentProject(MavenProject parentProject) {
- this.parentProject = parentProject;
- }
-
- /**
- * @return the reactorProjects
- */
- public List getReactorProjects() {
- return this.reactorProjects;
- }
-
- /**
- * @param reactorProjects
- * the reactorProjects to set
- */
- public void setReactorProjects(List reactorProjects) {
- this.reactorProjects = reactorProjects;
- }
-
- /**
- * @return the resolver
- */
- public org.apache.maven.artifact.resolver.ArtifactResolver getResolver() {
- return this.resolver;
- }
-
- /**
- * @param resolver
- * the resolver to set
- */
- public void setResolver(
- org.apache.maven.artifact.resolver.ArtifactResolver resolver) {
- this.resolver = resolver;
- }
-
-}
Deleted:
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateComponentMojo.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateComponentMojo.java 2009-10-05
16:54:09 UTC (rev 15696)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateComponentMojo.java 2009-10-05
21:26:45 UTC (rev 15697)
@@ -1,148 +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.builder.mojo;
-
-import java.io.File;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.maven.model.Plugin;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.velocity.VelocityContext;
-
-/**
- * @author shura
- * @goal create
- *
- */
-public class CreateComponentMojo extends AbstractCDKMojo {
-
- private static final String TEMPLATES_PREFIX = "/component/";
-
- private static final String CONFIG_TEMPLATE = TEMPLATES_PREFIX+"config.xml";
-
- private static final String CLASS_TEMPLATE = TEMPLATES_PREFIX+"UIClass.java";
-
- private static final String RENDERER_TEMPLATE =
TEMPLATES_PREFIX+"template.jspx";
-
- /**
- * @parameter expression="${name}"
- * @required
- */
- private String name ;
-
- /**
- * @parameter expression="${markup}"
- */
- private String markup ;
-
- /**
- * @parameter expression="${baseClass}"
default-value="javax.faces.component.UIComponentBase"
- */
- private String baseClass ;
-
- /**
- * Directory where the output Java Files will be located.
- *
- * @parameter expression="${project.build.plugins}"
- * @required
- * @readonly
- */
- private List plugins ;
-
- /* (non-Javadoc)
- * @see org.apache.maven.plugin.Mojo#execute()
- */
- public void execute() throws MojoExecutionException, MojoFailureException {
- if(project.getFile()!= null){
- boolean found= false;
- Plugin plugin = null;
- // Search for this plugin in project pom
- for (Iterator iter = plugins.iterator(); iter.hasNext();) {
- plugin = (Plugin) iter.next();
- if("maven-cdk-plugin".equals(plugin.getArtifactId())) {
-
- String groupId;
- if ("3.1.0".compareTo(plugin.getVersion()) > 0) {
- groupId = "org.richfaces.cdk";
- } else {
- groupId = "org.richfaces.cdk";
- }
-
- if (groupId.equals(plugin.getGroupId())) {
- found = true;
- break;
- }
- }
- }
- if(found){
- try {
- createComponent(plugin);
- } catch (Exception e) {
- throw new MojoExecutionException("Error on create component",e);
- }
- } else {
- throw new MojoFailureException("This project is not configured for JSF
components generation");
- }
- } else {
- throw new MojoFailureException("Goal 'create' must be run in existing
project directory");
- }
-
- }
-
- /**
- * @param plugin
- * @throws Exception
- */
- private void createComponent(Plugin plugin) throws Exception {
- checkLibraryConfig();
- String className = Character.toUpperCase(name.charAt(0))+name.substring(1);
- VelocityContext context = new VelocityContext();
- context.put("name", name);
- context.put("className", className);
- String basePackage = baseClass.substring(0, baseClass.lastIndexOf('.'));
- String baseClassName = baseClass.substring(baseClass.lastIndexOf('.')+1);
- context.put("baseClass", baseClass);
- context.put("basePackage", basePackage);
- context.put("baseClassName", baseClassName);
- String prefix = library.getPrefix();
- context.put("package", prefix);
- context.put("prefix", prefix);
- String path = prefix.replace('.', '/');
- context.put("path", path);
- if(null == markup){
- markup = library.getRenderkits()[0].getMarkup();
- }
- context.put("markup", markup);
- String markupName = Character.toUpperCase(markup.charAt(0))+markup.substring(1);
- context.put("markupName", markupName);
- // Create component configuration file.
- File configFile = new File(componentConfigDirectory,name+".xml");
- writeParsedTemplate(CONFIG_TEMPLATE, context, configFile);
- File classFile = new
File(project.getBuild().getSourceDirectory()+"/"+path+"/component/UI"+className+".java");
- writeParsedTemplate(CLASS_TEMPLATE, context, classFile);
- File templFile = new
File(templatesDirectory,path+"/"+markup+className+".jspx");
- writeParsedTemplate(RENDERER_TEMPLATE, context, templFile);
- }
-
-}
Deleted:
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateSkinMojo.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateSkinMojo.java 2009-10-05
16:54:09 UTC (rev 15696)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateSkinMojo.java 2009-10-05
21:26:45 UTC (rev 15697)
@@ -1,437 +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.builder.mojo;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.velocity.VelocityContext;
-import org.richfaces.cdk.model.Resource;
-import org.richfaces.cdk.model.ResourceConfig;
-import org.richfaces.cdk.model.io.xpp3.ResourceConfigXpp3Reader;
-import org.richfaces.cdk.model.io.xpp3.ResourceConfigXpp3Writer;
-
-/**
- * This mojo is intended to create new skin add-on within existing project.
- * New resources are added to the project, and existing resource config is modified to
include new files.
- * <p><b>Usage</b> <tt>mvn cdk:add-skin
-Dname=<skinName> -Dpackage=<skinPackage>.
</tt></p>
- * This adds new skin named <skinName> to project resources/META-INF/skins
folder.<br/>
- * Skin resources - XCSS files are placed in
<skinPackage>.<skinName> package within project resources
directory.<br/>
- * If <em>package</em> is not specified, it is set same as
groupId.<br/>
- *
- * Following parameters can be used
- * <li><strong>name</strong> - name of the skin.
<strong>Required.</strong></li>
- * <li><strong>package</strong> - base package of the skin. If not
specified, <em>groupId</em> is used</li>
- * <li><strong>createExt</strong> - if set to true, extended skin files
are added</li>
- * <li><strong>baseSkin</strong> - name of base skin</li>
- *
- * @goal add-skin
- * @requiresProject true
- *
- *
-
- * @author Maksim Kaszynski
- *
- */
-public class CreateSkinMojo extends AbstractCreateMojo {
-
- private static final String PROPERTIES = ".skin.properties";
-
- private static final String XCSS = ".xcss";
-
- private static final String EXT_XCSS = "-ext.xcss";
-
- private static final String SRC_MAIN_CONFIG_RESOURCES =
"src/main/config/resources";
-
- private static final String META_INF_SKINS = "META-INF/skins/";
-
- /**
- * Name of base package of skin.
- * If it is not set, GroupId is used.
- * @parameter expression="${package}"
default-value="${project.groupId}"
- */
- private String packageName;
-
-
- /**
- * Name of skin. Required parameter.
- * @parameter expression="${name}"
- * @required
- */
- private String skinName;
-
-
- /**
- * Name of base skin.
- * @parameter expression="${baseSkin}"
- */
- private String baseSkin;
-
- /**
- * If set to true, a set of extended classes is generated
- * @parameter expression="${createExt}"
- */
- private boolean createExt;
-
-
- /**
- * @parameter expression="${plugin.artifactId}"
- * @readonly
- */
- private String pluginArtifactId;
-
- /**
- * @parameter expression="${plugin.groupId}"
- * @readonly
- */
- private String pluginGroupId;
-
- /**
- * @parameter expression="${plugin.version}"
- * @readonly
- */
- private String pluginVersion;
-
- /** @component */
- private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory;
-
- /** @component */
- private org.apache.maven.artifact.resolver.ArtifactResolver resolver;
-
- /**
- * @parameter expression="${localRepository}"
- * @readonly
- * */
- private org.apache.maven.artifact.repository.ArtifactRepository localRepository;
-
- /**
- *
- */
- private File pluginJarFile = null;
-
- /**
- *
- */
- private File resourceDir;
-
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- getLog().info("Executing " + project);
- getLog().info("Generating Skin " + skinName);
- String fullSkinName = packageName.replace('/', '.') + "." +
skinName;
- String shortName = skinName;
- getLog().debug("Skin name is supposed to be " + shortName);
- getLog().debug("Root package " + packageName);
- getLog().debug("Skin package is " + fullSkinName);
-
- //RF-4023
- if (!isValidJavaName(skinName)){
- throw new MojoExecutionException("Invalid skin name '" + skinName +
"'. Please type another name.");
- }
-
- if (!isValidPackageName(packageName)) {
- throw new MojoExecutionException("Invalid skin package '" + packageName
+ "'. Please type another package.");
- }
-
- SkinInfo skinInfoTemplate = new SkinInfo();
- skinInfoTemplate.setShortName(shortName);
- skinInfoTemplate.setPackageName(fullSkinName.toLowerCase());
- skinInfoTemplate.setBaseClassResources(getArchetypeSkinTemplatesFromJar("skin/baseclasses"));
- skinInfoTemplate.setExtClassResources(getArchetypeSkinTemplatesFromJar("skin/extclasses"));
- skinInfoTemplate.setBaseSkin(baseSkin);
- skinInfoTemplate.setPropertyFile(new Resource("skin/skin.properties"));
- skinInfoTemplate.setMasterXcss(new Resource("skin/skin.xcss"));
- skinInfoTemplate.setExtendedXcss(new Resource("skin/skin.xcss"));
- skinInfoTemplate.setUseExt(createExt);
- generateSkin(skinInfoTemplate);
-
-
- getLog().info("Generating Skin successful");
-
- }
-
- private void copyJarResource(Resource template, Resource skinResource, File baseDir)
throws Exception{
- File newFile = new File(baseDir, skinResource.getPath());
- if (newFile.exists()) {
- getLog().debug("File " + newFile + " already exists. Skipping.");
- } else {
- try {
- File dir = newFile.getParentFile();
- if (!dir.exists()) {
- dir.mkdirs();
- }
-
- InputStream inputStream =
getClass().getClassLoader().getResourceAsStream(template.getPath());
- FileOutputStream fileOutputStream = new FileOutputStream(newFile);
- byte [] buffer = new byte[1024];
- int read = -1;
- while((read = inputStream.read(buffer)) != -1) {
- fileOutputStream.write(buffer, 0, read);
- }
- inputStream.close();
- fileOutputStream.close();
-
- } catch (Exception e) {
- throw new MojoExecutionException("Unable to write file " + newFile, e);
- }
- }
- }
-
- private List<Resource> filterComponentSkinTemplates(List<Resource>
jarTemplates, SkinInfo skinInfo, File resourceDir) throws MojoExecutionException {
- List<Resource> newResources = new
ArrayList<Resource>(jarTemplates.size());
- for (Resource jarTemplate : jarTemplates) {
- Resource newResource = new Resource();
- String jarTemplateName = jarTemplate.getName();
- int indexOfSlash = jarTemplateName.lastIndexOf('/');
- if (indexOfSlash > 0) {
- jarTemplateName = jarTemplateName.substring(indexOfSlash + 1);
- }
- String resourceName = skinInfo.getPackageName().replace('.', '/') +
"/css/" + jarTemplateName;
- newResource.setName(resourceName);
- newResource.setPath(resourceName);
- newResources.add(newResource);
- try {
- filterJarResource(jarTemplate, newResource, resourceDir, new VelocityContext());
- } catch (Exception e) {
- throw new MojoExecutionException("An exception occured while filtering resource
" + jarTemplate + " into " + newResource, e);
- }
- }
- return newResources;
- }
-
-
- private SkinInfo cloneSkinInfo(SkinInfo skinInfo) throws MojoExecutionException {
- try {
- return (SkinInfo) skinInfo.clone();
- } catch(CloneNotSupportedException exception) {
- throw new MojoExecutionException("Dunno why.", exception);
- }
- }
-
- private void generateSkin(SkinInfo skinInfoTemplate) throws MojoExecutionException,
MojoFailureException{
- resourceDir = new File(project.getBasedir(), SRC_MAIN_RESOURCES);
- getLog().debug("Resources directory is supposed to be" + resourceDir);
- checkAndCreateDirectory(resourceDir);
-
- String fullName = skinInfoTemplate.getPackageName();
- String packageFolder = fullName.replace('.', '/');
- getLog().debug("Relative path to package is " + packageFolder);
-
- VelocityContext velocityMasterContext = new VelocityContext();
- velocityMasterContext.put("mojo", this);
- velocityMasterContext.put("packagePath", packageFolder);
- velocityMasterContext.put("name", skinInfoTemplate.getShortName());
-
- if (baseSkin != null) {
- velocityMasterContext.put("baseSkin", baseSkin);
- }
-
- SkinInfo effectiveSkinInfo = cloneSkinInfo(skinInfoTemplate);
- List<Resource> allResources = new ArrayList<Resource>();
- velocityMasterContext.put("skinInfo", effectiveSkinInfo);
-
- //Copy basic classes, and list them
-
- List<Resource> baseClassResources =
filterComponentSkinTemplates(skinInfoTemplate.getBaseClassResources(), skinInfoTemplate,
resourceDir);
-
- effectiveSkinInfo.setBaseClassResources(baseClassResources);
- allResources.addAll(baseClassResources);
- velocityMasterContext.put("baseClassResources", baseClassResources);
-
- //Generate Master XCSS file
- Resource masterXcss = new Resource(META_INF_SKINS + effectiveSkinInfo.getShortName() +
XCSS);
- effectiveSkinInfo.setMasterXcss(masterXcss);
- allResources.add(masterXcss);
- try {
- generateMasterXCSSFile(skinInfoTemplate.getMasterXcss(),
effectiveSkinInfo.getMasterXcss(), effectiveSkinInfo.getBaseClassResources());
- } catch(Exception e) {
- throw new MojoExecutionException("Unable to generate master.xcss file " +
masterXcss, e);
- }
-
- if (createExt) {
- //Copy Ext classes, if needed
- List<Resource> extClassResources =
filterComponentSkinTemplates(skinInfoTemplate.getExtClassResources(), skinInfoTemplate,
resourceDir);
- effectiveSkinInfo.setExtClassResources(extClassResources);
- allResources.addAll(extClassResources);
- velocityMasterContext.put("extClassResources", extClassResources);
-
- //Generate Master EXT XCSS file
- Resource masterExtXcss = new Resource(META_INF_SKINS +
effectiveSkinInfo.getShortName() + EXT_XCSS);
- effectiveSkinInfo.setExtendedXcss(masterExtXcss);
- allResources.add(masterExtXcss);
- try {
- generateMasterXCSSFile(skinInfoTemplate.getExtendedXcss(),
effectiveSkinInfo.getExtendedXcss(), effectiveSkinInfo.getExtClassResources());
-
- } catch(Exception e) {
- throw new MojoExecutionException("Unable to generate master.xcss file " +
masterExtXcss, e);
- }
- }
-
- Resource properties = new Resource(META_INF_SKINS + effectiveSkinInfo.getShortName() +
PROPERTIES);
- effectiveSkinInfo.setPropertyFile(properties);
- try {
- filterJarResource(skinInfoTemplate.getPropertyFile(), properties, resourceDir,
velocityMasterContext);
- } catch (Exception e) {
- throw new MojoExecutionException("An exception occured while filtering resource
" + skinInfoTemplate.getPropertyFile() + " into " + properties, e);
- }
-
-
- File resourceConfigDir = new File(project.getBasedir(), SRC_MAIN_CONFIG_RESOURCES);
- checkAndCreateDirectory(resourceConfigDir);
- File resourceConfigFile = new File(resourceConfigDir, effectiveSkinInfo.getShortName()
+ "-resources.xml");;
- try {
- addToResourceConfig(allResources, resourceConfigFile);
- } catch (Exception e) {
- throw new MojoExecutionException("Unable to register newly added resources in
resource-config.xml", e);
- }
-
-
- packageArchetypeResourcesToBaseDir("src/main/java", effectiveSkinInfo,
true);
- packageArchetypeResourcesToBaseDir("src/main/resources", effectiveSkinInfo,
false);
- packageArchetypeResourcesToBaseDir("src/test/java", effectiveSkinInfo,
true);
-
-
-
- }
-
- private List<Resource> packageArchetypeResourcesToBaseDir(String prefix, final
SkinInfo skinInfo, boolean filter) throws MojoExecutionException{
- String archetypePrefix = "skin/archetype/" + prefix;
- List<Resource> archetypeResources =
getArchetypeSkinTemplatesFromJar(archetypePrefix);
- List<Resource> filteredResources = new
ArrayList<Resource>(archetypeResources.size());
- String newPrefix = prefix;
- String packageFolder = skinInfo.getPackageName().replace('.', '/');
- if (packageFolder != null) {
- newPrefix = prefix + "/" + packageFolder;
- }
-
-
- @SuppressWarnings("serial") VelocityContext velocityContext = new
VelocityContext() {
- {
- put("skinInfo", skinInfo);
- }
- };
- for (Resource resource : archetypeResources) {
- String archetypePath = resource.getPath();
- String pathSuffix = archetypePath.substring(archetypePrefix.length());
- String newPath = newPrefix + pathSuffix;
-
- Resource newResource = new Resource(newPath);
-
- try {
- if (filter) {
- filterJarResource(resource, newResource, project.getBasedir(), velocityContext);
- } else {
- copyJarResource(resource, newResource, project.getBasedir());
- }
- } catch (Exception e) {
- throw new MojoExecutionException("Unable to process archetype file " +
resource.getPath(), e);
- }
-
- filteredResources.add(newResource);
- }
- return filteredResources;
- }
-
- private void generateMasterXCSSFile(Resource template, Resource target,
List<Resource> includedResources) throws Exception {
- VelocityContext context = new VelocityContext();
- context.put("mojo", this);
- context.put("includedResources", includedResources);
- filterJarResource(template, target, resourceDir, context);
- }
-
- private Resource fromJarEntry(JarEntry entry) {
- Resource resource = new Resource();
- resource.setName(entry.getName());
- resource.setPath(entry.getName());
- return resource;
- }
-
- private List<Resource> getArchetypeSkinTemplatesFromJar(String prefix) throws
MojoExecutionException{
- try {
- if (pluginJarFile == null) {
- pluginJarFile = getPluginArtifactJar();
- }
- List <Resource> fileNames = new ArrayList<Resource>();
- JarFile jar = new JarFile(pluginJarFile);
- Enumeration<JarEntry> entries = jar.entries();
- while(entries.hasMoreElements()) {
- JarEntry jarEntry = entries.nextElement();
- String jarEntryName = jarEntry.getName();
- if(jarEntryName.startsWith(prefix) && !jarEntry.isDirectory()) {
- fileNames.add(fromJarEntry(jarEntry));
- }
- }
- return fileNames;
- } catch (Exception e) {
- throw new MojoExecutionException("Unable to list templates within Plugin Jar
file");
- }
- }
-
- private File getPluginArtifactJar() throws ArtifactResolutionException,
ArtifactNotFoundException {
- Artifact pluginArtifact =
- artifactFactory.createPluginArtifact(pluginGroupId, pluginArtifactId,
VersionRange.createFromVersion(pluginVersion));
-
- resolver.resolve(pluginArtifact, Collections.emptyList(), localRepository);
-
- return pluginArtifact.getFile();
- }
-
- private void addToResourceConfig(List<Resource> resources, File
resourceConfigFile) throws Exception{
- ResourceConfig resourceConfig = null;
-
- if (resourceConfigFile.exists()) {
- resourceConfig = new ResourceConfigXpp3Reader().read(new
FileInputStream(resourceConfigFile));
- }
-
- if (resourceConfig == null) {
- resourceConfig = new ResourceConfig();
- resourceConfig.setResources(resources);
- } else {
- for (Resource resource : resources) {
- if (!resourceConfig.containsResource(resource)) {
- resourceConfig.addResource(resource);
- }
- }
- }
-
-
-
- new ResourceConfigXpp3Writer().write(new FileWriter(resourceConfigFile),
resourceConfig);
-
- }
-
-}
Deleted:
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateThemeMojo.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateThemeMojo.java 2009-10-05
16:54:09 UTC (rev 15696)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/CreateThemeMojo.java 2009-10-05
21:26:45 UTC (rev 15697)
@@ -1,158 +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.builder.mojo;
-
-import java.io.File;
-import java.util.Locale;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.velocity.VelocityContext;
-import org.richfaces.cdk.model.Resource;
-
-/**
- * This mojo is intended to create new theme within existing project.
- * <p><b>Usage</b> <tt>mvn cdk:add-theme
-Dname=<themeName> [ -Dpackage=<themePackage>
]</tt></p>
- * This adds new theme named <themeName> to project
resources/META-INF/themes folder.<br/>
- * If <em>package</em> is not specified, it is set same as
groupId.<br/>
- *
- * Following parameters can be used
- * <li><strong>name</strong> - name of the theme.
<strong>Required.</strong></li>
- * <li><strong>package</strong> - base package of the theme. If not
specified, <em>groupId</em> is used</li>
- *
- * @goal add-theme
- * @requiresProject true
- *
- * @author Nick Belaevski
- */
-public class CreateThemeMojo extends AbstractCreateMojo {
-
- private static final String XCSS = ".xcss";
-
- private static final String META_INF_THEMES = "META-INF/themes/";
-
- private static final String XCSS_THEMES_PACKAGE = "/renderkit/html/css";
-
- private static final String THEME_PROPERTIES = ".theme.properties";
-
- private static final String RENDERKIT_THEMES = "renderkit.html";
-
- /**
- * Name of base package of theme.
- * If it is not set, GroupId is used.
- * @parameter expression="${package}"
default-value="${project.groupId}"
- */
- private String packageName;
-
-
- /**
- * Name of theme. Required parameter.
- * @parameter expression="${name}"
- * @required
- */
- private String themeName;
-
- private String generateRendererName(String themeName) {
- StringBuilder rendererTypeBuilder = new StringBuilder();
- rendererTypeBuilder.append(Character.toUpperCase(themeName.charAt(0)));
- rendererTypeBuilder.append(themeName.subSequence(1, themeName.length()));
- rendererTypeBuilder.append("Renderer");
- return rendererTypeBuilder.toString();
- }
-
- private void generateTheme(String packageName, String themeName) throws
MojoExecutionException, MojoFailureException {
- Resource themeProperties = new Resource("theme/themes/theme.properties");
- Resource themeXCSS = new Resource("theme/css/theme.xcss");
- Resource themeConfig = new Resource("theme/component/theme.xml");
- Resource themeTemplate = new Resource("theme/template/theme.jspx");
-
- File resourceDir = new File(project.getBasedir(), SRC_MAIN_RESOURCES);
-
- String packagePath = packageName.replace('.', '/');
- String xcssPackagePath = packagePath + XCSS_THEMES_PACKAGE;
- String rendererName = generateRendererName(themeName);
- String rendererType = packageName + '.' + rendererName;
- String rendererClassName = packageName + '.' + RENDERKIT_THEMES + '.' +
rendererName;
-
- getLog().debug("Relative path to package is " + packagePath);
-
- VelocityContext velocityMasterContext = new VelocityContext();
- velocityMasterContext.put("packagePath", packagePath);
- velocityMasterContext.put("xcssPackagePath", xcssPackagePath);
- velocityMasterContext.put("name", themeName);
- velocityMasterContext.put("rendererType", rendererType);
- velocityMasterContext.put("rendererClassName", rendererClassName);
-
- Resource properties = new Resource(META_INF_THEMES + themeName + THEME_PROPERTIES);
- try {
- filterJarResource(themeProperties, properties, resourceDir, velocityMasterContext);
- } catch (Exception e) {
- throw new MojoExecutionException("An exception occured while filtering resource
" + themeProperties + " into " + properties, e);
- }
-
- Resource xcss = new Resource(xcssPackagePath + '/' + themeName + XCSS);
- try {
- filterJarResource(themeXCSS, xcss, resourceDir, velocityMasterContext);
- } catch (Exception e) {
- throw new MojoExecutionException("An exception occured while filtering resource
" + themeXCSS + " into " + xcss, e);
- }
-
- File configDir = new File(project.getBasedir(),
"src/main/config/component");
- Resource config = new Resource(themeName + ".xml");
- try {
- filterJarResource(themeConfig, config, configDir, velocityMasterContext);
- } catch (Exception e) {
- throw new MojoExecutionException("An exception occured while filtering resource
" + themeConfig + " into " + config, e);
- }
-
- File templateDir = new File(project.getBasedir(), "src/main/templates");
- Resource template = new Resource(packagePath + '/' + themeName +
".jspx");
- try {
- filterJarResource(themeTemplate, template, templateDir, velocityMasterContext);
- } catch (Exception e) {
- throw new MojoExecutionException("An exception occured while filtering resource
" + themeTemplate + " into " + template, e);
- }
- }
-
- public void execute() throws MojoExecutionException, MojoFailureException {
- getLog().info("Executing " + project);
- getLog().info("Generating Theme " + themeName);
-
- String themePackageName = packageName.replace('/',
'.').toLowerCase(Locale.US);
- String shortName = themeName;
- getLog().debug("Root package " + packageName);
- getLog().debug("Theme package is " + themePackageName);
-
- if (!isValidJavaName(themeName)){
- throw new MojoExecutionException("Invalid theme name '" + themeName +
"'. Please type another name.");
- }
-
- if (!isValidPackageName(packageName)) {
- throw new MojoExecutionException("Invalid theme package '" + packageName
+ "'. Please type another package.");
- }
-
- generateTheme(themePackageName, shortName);
-
- getLog().info("Generating Theme successful");
- }
-
-}