Author: maksimkaszynski
Date: 2008-05-15 09:10:04 -0400 (Thu, 15 May 2008)
New Revision: 8592
Added:
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/java/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/java/images/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/java/images/BaseImage.java
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/resources/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/resources/css/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/resources/images/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/resources/images/README.txt
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/test/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/test/java/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/test/java/images/
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/test/java/images/BaseImageTest.java
Modified:
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/CreateSkinMojo.java
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/GenerateMojo.java
trunk/cdk/maven-cdk-plugin/src/main/mdo/resource-config.mdo
Log:
Modified:
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/CreateSkinMojo.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/CreateSkinMojo.java 2008-05-15
13:09:51 UTC (rev 8591)
+++
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/CreateSkinMojo.java 2008-05-15
13:10:04 UTC (rev 8592)
@@ -2,7 +2,9 @@
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;
@@ -23,6 +25,8 @@
import org.apache.maven.project.MavenProject;
import org.apache.velocity.VelocityContext;
+import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;
+
/**
* This mojo is intended to create new skin add-on.
* If mojo is executed within project, new resources are added to the project, and
existing resource config is modified to include new files.
@@ -39,7 +43,7 @@
*
*
* @goal add-skin
- * @requiresProject false
+ * @requiresProject true
*
*
@@ -88,16 +92,10 @@
private String groupId;
/**
- * Name of newly added skin. If not set explicitly but project exists, project arifactId
will be used.
- * @parameter expression="${name}"
default-value="${project.artifactId}"
+ * @parameter expression="${baseName}"
+ * @required
*/
- private String skinName;
-
- /**
- * Name of the base package of newly added skin. If not set explicitly but project
exists, project groupId will be used.
- * @parameter expression="${package}"
default-value="${project.groupId}"
- */
- private String packageName;
+ private String baseName;
/**
* Version of newly generated project. Default is 1.0-SNAPSHOT
@@ -152,6 +150,7 @@
private File resourceDir;
+ @Deprecated
private void createProjectIfNeeded() throws MojoExecutionException,
MojoFailureException{
//mavenProjectBuilder.build(project, localRepository, globalProfileManager)
@@ -184,7 +183,7 @@
}
project.setFile(pomFile);
}
-
+
public void execute() throws MojoExecutionException, MojoFailureException {
if (pom != null) {
@@ -196,19 +195,22 @@
getLog().info("Generating Skin");
- String name = skinName;
+
+ String fullSkinName = baseName.replace('/', '.');
+ String shortName = fullSkinName;
+ int lastIndexOfDot = fullSkinName.lastIndexOf('.');
+ if (lastIndexOfDot > 0) {
+ shortName = shortName.substring(lastIndexOfDot + 1);
+ }
+ getLog().debug("Skin name is supposed to be " + shortName);
- String packageName = this.packageName + "." + name;
- getLog().debug("Skin name is supposed to be " + name);
+ getLog().debug("Package detected " + fullSkinName);
- getLog().debug("Package detected " + packageName);
-
-
SkinInfo skinInfoTemplate = new SkinInfo();
- skinInfoTemplate.setShortName(name);
- skinInfoTemplate.setPackageName(packageName);
+ skinInfoTemplate.setShortName(shortName);
+ skinInfoTemplate.setPackageName(fullSkinName);
skinInfoTemplate.setBaseClassResources(getArchetypeSkinTemplatesFromJar("skin/baseclasses"));
skinInfoTemplate.setExtClassResources(getArchetypeSkinTemplatesFromJar("skin/extclasses"));
skinInfoTemplate.setBaseSkin(baseSkin);
@@ -223,6 +225,32 @@
}
+ 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 void filterJarResource(Resource template, Resource skinResource, File baseDir,
VelocityContext context) throws Exception{
File newFile = new File(baseDir, skinResource.getPath());
@@ -246,7 +274,7 @@
if (indexOfSlash > 0) {
jarTemplateName = jarTemplateName.substring(indexOfSlash + 1);
}
- String resourceName = skinInfo.getPackageName().replace('.', '/') +
"/" + jarTemplateName;
+ String resourceName = skinInfo.getPackageName().replace('.', '/') +
"/css/" + jarTemplateName;
newResource.setName(resourceName);
newResource.setPath(resourceName);
newResources.add(newResource);
@@ -338,16 +366,62 @@
File resourceConfigDir = new File(project.getBasedir(), SRC_MAIN_CONFIG_RESOURCES);
checkAndCreateDirectory(resourceConfigDir);
- File resourceConfigFile = new File(resourceConfigDir, RESOURCES_CONFIG_XML);
+ 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;
+ }
+ 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 List<Resource> getArchetypeResources(String prefix) throws
MojoExecutionException {
+ return getArchetypeSkinTemplatesFromJar("skin/archetype/" + prefix);
+ }
+
private void generateMasterXCSSFile(Resource template, Resource target,
List<Resource> includedResources) throws Exception {
VelocityContext context = new VelocityContext();
context.put("mojo", this);
Modified:
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/GenerateMojo.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/GenerateMojo.java 2008-05-15
13:09:51 UTC (rev 8591)
+++
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/GenerateMojo.java 2008-05-15
13:10:04 UTC (rev 8592)
@@ -267,11 +267,14 @@
}
}
}
-
if (!filesParsed) {
+ getLog().warn("No component configuration files found -- probably a skin
project");
+ }
+ /*
+ if (!filesParsed) {
throw new ParsingException("No config files found");
}
-
+ */
builderConfig.checkComponentProperties();
return builderConfig;
}
Modified: trunk/cdk/maven-cdk-plugin/src/main/mdo/resource-config.mdo
===================================================================
--- trunk/cdk/maven-cdk-plugin/src/main/mdo/resource-config.mdo 2008-05-15 13:09:51 UTC
(rev 8591)
+++ trunk/cdk/maven-cdk-plugin/src/main/mdo/resource-config.mdo 2008-05-15 13:10:04 UTC
(rev 8592)
@@ -30,6 +30,15 @@
//]]></code></codeSegment>
</codeSegments>
</class>
+ <class xml.tagName="renderer">
+ <name>Renderer</name>
+ <fields>
+ <field xml.attribute="true" xml.tagName="class">
+ <name>className</name>
+ <type>String</type>
+ </field>
+ </fields>
+ </class>
<class xml.tagName="resource">
<name>Resource</name>
<fields>
@@ -45,6 +54,13 @@
<name>path</name>
<type>String</type>
</field>
+ <field>
+ <name>renderer</name>
+ <association>
+ <type>Renderer</type>
+ <multiplicity>1</multiplicity>
+ </association>
+ </field>
</fields>
<codeSegments>
<codeSegment>
Added:
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/java/images/BaseImage.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/java/images/BaseImage.java
(rev 0)
+++
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/java/images/BaseImage.java 2008-05-15
13:10:04 UTC (rev 8592)
@@ -0,0 +1,28 @@
+package ${skinInfo.packageName}.images;
+
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.util.Date;
+
+import org.ajax4jsf.resource.InternetResourceBuilder;
+import org.ajax4jsf.resource.Java2Dresource;
+import org.ajax4jsf.resource.PngRenderer;
+import org.ajax4jsf.resource.ResourceContext;
+
+public class BaseImage extends Java2Dresource{
+ public BaseImage() {
+ setRenderer(new PngRenderer());
+ setLastModified(new Date(InternetResourceBuilder.getInstance().getStartTime()));
+ }
+
+ @Override
+ protected void paint(ResourceContext context, Graphics2D graphics2D) {
+ graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
+ graphics2D.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
+ graphics2D.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+ graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+ graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
+ //Paint here:)
+
+ }
+}
Added:
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/resources/images/README.txt
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/resources/images/README.txt
(rev 0)
+++
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/main/resources/images/README.txt 2008-05-15
13:10:04 UTC (rev 8592)
@@ -0,0 +1 @@
+Place image files here
\ No newline at end of file
Added:
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/test/java/images/BaseImageTest.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/test/java/images/BaseImageTest.java
(rev 0)
+++
trunk/cdk/maven-cdk-plugin/src/main/resources/skin/archetype/src/test/java/images/BaseImageTest.java 2008-05-15
13:10:04 UTC (rev 8592)
@@ -0,0 +1,19 @@
+package ${skinInfo.packageName}.images;
+
+import junit.framework.TestCase;
+
+public class BaseImageTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testPaint() throws Exception {
+ //TODO: Write test here
+ }
+
+}