Author: nbelaevski
Date: 2010-08-05 17:30:13 -0400 (Thu, 05 Aug 2010)
New Revision: 18491
Added:
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/2_0/
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/2_0/jquery/
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/2_0/jquery/1_3_2.js
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/2_0/jquery/1_4_2.js
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/2_1/
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/2_1/jquery/
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/2_1/jquery/1_4_2.js
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceKey.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/AbstractResourceHandler.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceHandler.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/ResourcesScanner.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/MarkerResourcesScanner.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/ReflectionsExt.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/scanner/
Removed:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceInfo.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourcesScanner.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceHandlerImpl.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/MarkerResourcesScanner.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/StaticResourcesScannerImpl.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/URLResource.java
Modified:
root/sandbox/cdk/maven-resources-plugin/pom.xml
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/pom.xml
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ApplicationImpl.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/FacesImpl.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/MorePredicates.java
Log:
Dynamic resources prerenderer: latest changes check-in
Modified: root/sandbox/cdk/maven-resources-plugin/pom.xml
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/pom.xml 2010-08-05 20:59:23 UTC (rev 18490)
+++ root/sandbox/cdk/maven-resources-plugin/pom.xml 2010-08-05 21:30:13 UTC (rev 18491)
@@ -104,6 +104,19 @@
<artifactId>slf4j-simple</artifactId>
<version>1.5.8</version>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ <version>3.0.0.CR5</version>
+ </dependency>
+
+ <!-- TODO use maven logging -->
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ <version>2.2.0.CR1</version>
+ </dependency>
</dependencies>
<build>
Modified: root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/pom.xml
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/pom.xml 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/pom.xml 2010-08-05
21:30:13 UTC (rev 18491)
@@ -5,6 +5,7 @@
<artifactId>richfaces-application</artifactId>
<name>Test component annotations</name>
<version>0.0.1-SNAPSHOT</version>
+ <packaging>war</packaging>
<build>
<plugins>
<plugin>
@@ -35,7 +36,7 @@
<include>text/css</include>
<include>image/.+</include>
</includedContentTypes>
- <fileNameMappings>
+ <!-- fileNameMappings>
<property>
<name>^org\.richfaces\.renderkit\.html\.(images\.)?</name>
<value>org.richfaces/images/</value>
@@ -44,7 +45,7 @@
<name>^css/</name>
<value>org.richfaces/css/</value>
</property>
- </fileNameMappings>
+ </fileNameMappings -->
</configuration>
</execution>
</executions>
Added:
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/2_0/jquery/1_3_2.js
===================================================================
Added:
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/2_0/jquery/1_4_2.js
===================================================================
Added:
root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/src/main/webapp/resources/versioned.lib/2_1/jquery/1_4_2.js
===================================================================
Modified:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -31,6 +31,7 @@
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.List;
+import java.util.Locale;
import java.util.Properties;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
@@ -39,18 +40,24 @@
import java.util.concurrent.Future;
import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
+import org.jboss.vfs.VirtualFile;
import org.richfaces.cdk.concurrent.CountingExecutorCompletionService;
import org.richfaces.cdk.faces.FacesImpl;
import org.richfaces.cdk.naming.FileNameMapperImpl;
+import org.richfaces.cdk.resource.ResourceUtil;
import org.richfaces.cdk.resource.ResourceWriterImpl;
-import org.richfaces.cdk.resource.ResourcesScannerImpl;
-import org.richfaces.cdk.resource.StaticResourcesScannerImpl;
+import org.richfaces.cdk.resource.handler.impl.DynamicResourceHandler;
+import org.richfaces.cdk.resource.handler.impl.StaticResourceHandler;
+import org.richfaces.cdk.resource.scan.ResourcesScanner;
+import org.richfaces.cdk.resource.scan.impl.DynamicResourcesScanner;
+import org.richfaces.cdk.resource.scan.impl.StaticResourcesScanner;
import org.richfaces.cdk.task.ResourceTaskFactoryImpl;
import org.richfaces.cdk.util.ClasspathUtil;
import org.richfaces.cdk.util.MoreConstraints;
@@ -61,6 +68,8 @@
import com.google.common.base.Predicates;
import com.google.common.collect.Constraints;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
/**
* @goal process
* @requiresDependencyResolution compile
@@ -72,7 +81,8 @@
private static final Function<String, Predicate<CharSequence>>
REGEX_CONTAINS_BUILDER_FUNCTION = new Function<String,
Predicate<CharSequence>>() {
public Predicate<CharSequence> apply(String from) {
- return Predicates.containsPattern(from);
+ Predicate<CharSequence> containsPredicate =
Predicates.containsPattern(from);
+ return Predicates.and(Predicates.notNull(), containsPredicate);
};
};
@@ -130,15 +140,23 @@
* @parameter
*/
// TODO review usage of properties?
- private Properties fileNameMappings;
+ private Properties fileNameMappings = new Properties();
/**
* @parameter
*/
private ProcessMode processMode = ProcessMode.embedded;
+ /**
+ * @parameter expression="${basedir}/src/main/webapp"
+ */
private String webRoot;
+ //TODO handle resource locales
+ private Locale resourceLocales;
+
+ private Collection<ResourceKey> foundResources = Sets.newHashSet();
+
// TODO executor parameters
private static ExecutorService createExecutorService() {
return Executors.newSingleThreadExecutor();
@@ -150,20 +168,30 @@
return Predicates.compose(contentTypePredicate, CONTENT_TYPE_FUNCTION);
}
- private ResourcesScanner createResourcesScanner() {
- Collection<URL> urls = ClasspathUtil.getFacesClasspathUrls();
- switch (processMode) {
- case external:
- //TODO webroot
- return new StaticResourcesScannerImpl(urls, null);
- case embedded:
- return new ResourcesScannerImpl(urls);
-
- default:
- throw new IllegalArgumentException();
+ private URL resolveWebRoot() throws MalformedURLException {
+ File result = new File(webRoot);
+ if (!result.exists()) {
+ result = new File(project.getBasedir(), webRoot);
}
+ if (!result.exists()) {
+ return null;
+ }
+
+ return result.toURI().toURL();
}
+ private void scanDynamicResources(Collection<URL> cpUrls) throws Exception {
+ ResourcesScanner scanner = new DynamicResourcesScanner(cpUrls);
+ scanner.scan();
+ foundResources.addAll(scanner.getResources());
+ }
+
+ private void scanStaticResources(Collection<VirtualFile> resourceRoots) throws
Exception {
+ ResourcesScanner scanner = new StaticResourcesScanner(resourceRoots);
+ scanner.scan();
+ foundResources.addAll(scanner.getResources());
+ }
+
protected ClassLoader createProjectClassLoader(MavenProject project, boolean useCCL)
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
@@ -187,11 +215,20 @@
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
+
ClassLoader cCL = Thread.currentThread().getContextClassLoader();
Faces faces = null;
ExecutorService executorService = null;
try {
+ URL webRootUrl = resolveWebRoot();
+
+ Collection<URL> cpUrls = ClasspathUtil.getFacesClasspathUrls();
+ Collection<VirtualFile> resourceRoots =
ResourceUtil.getResourceRoots(cpUrls, webRootUrl);
+
+ scanDynamicResources(cpUrls);
+ scanStaticResources(resourceRoots);
+
ClassLoader projectCL = createProjectClassLoader(project, true);
Thread.currentThread().setContextClassLoader(projectCL);
@@ -200,26 +237,23 @@
outputDirFile = new File(project.getBuild().getDirectory(), outputDir);
}
+ ResourceHandler resourceHandler = new DynamicResourceHandler(new
StaticResourceHandler(resourceRoots));
+
+ // TODO set webroot
+ faces = new FacesImpl(null, new
FileNameMapperImpl(Maps.fromProperties(fileNameMappings)), resourceHandler);
+ faces.start();
+
ResourceWriterImpl resourceWriter = new ResourceWriterImpl(outputDirFile);
- ResourceTaskFactoryImpl taskFactory = new ResourceTaskFactoryImpl();
+ ResourceTaskFactoryImpl taskFactory = new ResourceTaskFactoryImpl(faces);
taskFactory.setResourceWriter(resourceWriter);
- // TODO set webroot
- faces = new FacesImpl(null, new FileNameMapperImpl(fileNameMappings),
taskFactory);
- faces.start();
-
- ResourcesScanner resourcesScanner = createResourcesScanner();
- resourcesScanner.scan();
-
executorService = createExecutorService();
CompletionService<Object> completionService = new
CountingExecutorCompletionService<Object>(executorService);
taskFactory.setCompletionService(completionService);
taskFactory.setSkins(skins);
taskFactory.setLog(getLog());
taskFactory.setFilter(createResourcesFilter());
- for (ResourceInfo resourceInfo : resourcesScanner.getResources()) {
- taskFactory.submit(resourceInfo);
- }
+ taskFactory.submit(foundResources);
Future<Object> future = null;
while (true) {
Deleted:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceInfo.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceInfo.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceInfo.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -1,103 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk;
-
-import com.google.common.base.Objects;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class ResourceInfo {
-
- public static final String CLASSPATH_RESOURCES_LOCATION =
"META-INF/resources/";
-
- public static final String WEB_RESOURCES_LOCATION = "resources/";
-
- private final String resourceName;
-
- private final String libraryName;
-
- public ResourceInfo(String resourceName) {
- this(resourceName, null);
- }
-
- public ResourceInfo(String resourceName, String libraryName) {
- super();
- this.resourceName = resourceName;
- this.libraryName = libraryName;
- }
-
- public String getResourceName() {
- return resourceName;
- }
-
- public String getLibraryName() {
- return libraryName;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((libraryName == null) ? 0 : libraryName.hashCode());
- result = prime * result + ((resourceName == null) ? 0 :
resourceName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- ResourceInfo other = (ResourceInfo) obj;
- if (libraryName == null) {
- if (other.libraryName != null) {
- return false;
- }
- } else if (!libraryName.equals(other.libraryName)) {
- return false;
- }
- if (resourceName == null) {
- if (other.resourceName != null) {
- return false;
- }
- } else if (!resourceName.equals(other.resourceName)) {
- return false;
- }
- return true;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return Objects.toStringHelper(this).add("resourceName",
resourceName).add("libraryName", libraryName).toString();
- }
-}
Added:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceKey.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceKey.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceKey.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk;
+
+import com.google.common.base.Objects;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceKey {
+
+ private String resourceName;
+
+ private String libraryName;
+
+ public ResourceKey(String resourceName) {
+ this(resourceName, null);
+ }
+
+ public ResourceKey(String resourceName, String libraryName) {
+ super();
+ this.resourceName = resourceName;
+ this.libraryName = libraryName;
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public String getLibraryName() {
+ return libraryName;
+ }
+
+ public void setResourceName(String resourceName) {
+ this.resourceName = resourceName;
+ }
+
+ public void setLibraryName(String libraryName) {
+ this.libraryName = libraryName;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((libraryName == null) ? 0 : libraryName.hashCode());
+ result = prime * result + ((resourceName == null) ? 0 :
resourceName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ResourceKey other = (ResourceKey) obj;
+ if (libraryName == null) {
+ if (other.libraryName != null) {
+ return false;
+ }
+ } else if (!libraryName.equals(other.libraryName)) {
+ return false;
+ }
+ if (resourceName == null) {
+ if (other.resourceName != null) {
+ return false;
+ }
+ } else if (!resourceName.equals(other.resourceName)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return Objects.toStringHelper(this).add("resourceName",
resourceName).add("libraryName", libraryName).toString();
+ }
+}
Modified:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -25,6 +25,7 @@
import javax.faces.application.Resource;
+
import com.google.common.base.Predicate;
/**
@@ -37,12 +38,10 @@
public void setCompletionService(CompletionService<Object> completionService);
- public void setFaces(Faces faces);
-
public void setResourceWriter(ResourceWriter resourceWriter);
public void setFilter(Predicate<Resource> filter);
- public void submit(ResourceInfo info);
+ public void submit(Iterable<ResourceKey> keys);
}
Deleted:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourcesScanner.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourcesScanner.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourcesScanner.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk;
-
-import java.util.Collection;
-
-/**
- * @author Nick Belaevski
- *
- */
-public interface ResourcesScanner {
-
- //TODO inclusions/exclusions
-
- public void scan();
-
- public Collection<ResourceInfo> getResources();
-
-}
Modified:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ApplicationImpl.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ApplicationImpl.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ApplicationImpl.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -46,6 +46,8 @@
import javax.faces.event.ActionListener;
import javax.faces.validator.Validator;
+import org.richfaces.application.ServiceTracker;
+
import com.sun.el.ExpressionFactoryImpl;
/**
@@ -56,16 +58,10 @@
private ExpressionFactory expressionFactory = createExpressionFactory();
- private ResourceHandler resourceHandler = createResourceHandler();
-
private ExpressionFactory createExpressionFactory() {
return ExpressionFactoryImpl.newInstance();
}
- private ResourceHandler createResourceHandler() {
- return new ResourceHandlerImpl();
- }
-
/*
* (non-Javadoc)
*
@@ -475,7 +471,7 @@
*/
@Override
public ResourceHandler getResourceHandler() {
- return resourceHandler;
+ return ServiceTracker.getService(ResourceHandler.class);
}
@Override
Modified:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/FacesImpl.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/FacesImpl.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/FacesImpl.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -23,16 +23,18 @@
import java.util.Collections;
+import javax.faces.application.ResourceHandler;
import javax.faces.context.FacesContext;
import org.ajax4jsf.context.InitParametersStorage;
+import org.richfaces.application.DependencyInjectionServiceImpl;
+import org.richfaces.application.DependencyInjector;
import org.richfaces.application.Module;
import org.richfaces.application.ServiceTracker;
import org.richfaces.application.ServicesFactory;
import org.richfaces.application.ServicesFactoryImpl;
import org.richfaces.cdk.Faces;
import org.richfaces.cdk.FileNameMapper;
-import org.richfaces.cdk.ResourceTaskFactory;
import org.richfaces.cdk.skin.SkinFactoryImpl;
import org.richfaces.skin.SkinFactory;
@@ -46,27 +48,25 @@
private FileNameMapper fileNameMapper;
- private ResourceTaskFactory resourceTaskFactory;
+ private ResourceHandler resourceHandler;
- public FacesImpl(String webroot, FileNameMapper fileNameMapper, ResourceTaskFactory
resourceTaskFactory) {
+ public FacesImpl(String webroot, FileNameMapper fileNameMapper, ResourceHandler
resourceHandler) {
super();
this.webroot = webroot;
this.fileNameMapper = fileNameMapper;
- this.resourceTaskFactory = resourceTaskFactory;
- resourceTaskFactory.setFaces(this);
+ this.resourceHandler = resourceHandler;
}
public void start() {
- final SkinFactoryImpl skinFactory = new SkinFactoryImpl();
-
final ServicesFactoryImpl serviceFactory = new ServicesFactoryImpl();
Module module = new Module() {
public void configure(ServicesFactory factory) {
- serviceFactory.setInstance(SkinFactory.class, skinFactory);
+ serviceFactory.setInstance(SkinFactory.class, new SkinFactoryImpl());
serviceFactory.setInstance(InitParametersStorage.class, new
InitParametersStorage());
serviceFactory.setInstance(FileNameMapper.class, fileNameMapper);
- serviceFactory.setInstance(ResourceTaskFactory.class,
resourceTaskFactory);
+ serviceFactory.setInstance(DependencyInjector.class, new
DependencyInjectionServiceImpl());
+ serviceFactory.setInstance(ResourceHandler.class, resourceHandler);
}
};
serviceFactory.init(Collections.singleton(module));
Modified:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -34,9 +34,6 @@
import javax.faces.application.ResourceHandler;
import javax.faces.context.FacesContext;
-import org.richfaces.application.ServiceTracker;
-import org.richfaces.cdk.FileNameMapper;
-
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
@@ -111,16 +108,14 @@
context.setPropertyResolved(true);
if (resource != null) {
- FileNameMapper fileNameMapper =
ServiceTracker.getService(FileNameMapper.class);
- String name = fileNameMapper.createName(resource);
-
+ String requestPath = resource.getRequestPath();
FacesContext facesContext = (FacesContext)
context.getContext(FacesContext.class);
Resource contextResource =
CurrentResourceContext.getInstance(facesContext).getResource();
if (contextResource != null) {
- name = relativize(name, fileNameMapper.createName(contextResource));
+ requestPath = relativize(resource.getRequestPath(),
contextResource.getRequestPath());
}
- return name;
+ return requestPath;
}
}
return null;
Deleted:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceHandlerImpl.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceHandlerImpl.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceHandlerImpl.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -1,152 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.faces;
-
-import java.io.IOException;
-import java.lang.reflect.Modifier;
-import java.net.URL;
-
-import javax.faces.application.Resource;
-import javax.faces.application.ResourceHandler;
-import javax.faces.context.FacesContext;
-
-import org.reflections.util.Utils;
-import org.richfaces.application.ServiceTracker;
-import org.richfaces.cdk.ResourceInfo;
-import org.richfaces.cdk.ResourceTaskFactory;
-import org.richfaces.cdk.resource.URLResource;
-import org.richfaces.resource.CompiledCSSResource;
-import org.richfaces.resource.Java2DUserResource;
-import org.richfaces.resource.Java2DUserResourceWrapperImpl;
-import org.richfaces.resource.UserResource;
-import org.richfaces.resource.UserResourceWrapperImpl;
-
-import com.google.common.base.Strings;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class ResourceHandlerImpl extends ResourceHandler {
-
- @Override
- public Resource createResource(String resourceName) {
- return createResource(resourceName, null);
- }
-
- @Override
- public Resource createResource(String resourceName, String libraryName) {
- return createResource(resourceName, libraryName, null);
- }
-
- @Override
- public Resource createResource(String resourceName, String libraryName, String
contentType) {
- Resource result = null;
- if (Strings.isNullOrEmpty(libraryName)) {
- try {
- Class<?> resourceClass = Class.forName(resourceName, false,
Utils.getContextClassLoader());
- if (resourceClass.isInterface() || (resourceClass.getModifiers() &
Modifier.ABSTRACT) != 0) {
- return null;
- }
-
- Object resourceObject = resourceClass.newInstance();
- if (resourceObject instanceof Java2DUserResource) {
- result = new Java2DUserResourceWrapperImpl((Java2DUserResource)
resourceObject);
- } else if (resourceObject instanceof UserResource) {
- result = new UserResourceWrapperImpl((UserResource) resourceObject);
- } else {
- result = (Resource) resourceObject;
- }
- } catch (ClassNotFoundException e) {
- //TODO ignore, but add to debug logs
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- if (result == null) {
- String resourcePath;
-
- if (libraryName != null && libraryName.length() != 0) {
- resourcePath = libraryName + '/' + resourceName;
- } else {
- resourcePath = resourceName;
- }
-
- URL url =
Utils.getContextClassLoader().getResource(ResourceInfo.CLASSPATH_RESOURCES_LOCATION +
resourcePath);
- if (url != null) {
- result = new URLResource(url);
-
- if (resourceName.endsWith(".ecss")) {
- //TODO process CSS dependencies
- result = new CompiledCSSResource(result);
- }
- }
- }
-
- if (result != null) {
- //TODO detect content type
- result.setContentType(contentType);
- result.setResourceName(resourceName);
- result.setLibraryName(libraryName);
-
- //TODO simply discover & process all available resources
- ResourceTaskFactory resourceTaskFactory =
ServiceTracker.getService(ResourceTaskFactory.class);
- resourceTaskFactory.submit(new ResourceInfo(resourceName, libraryName));
- }
-
- return result;
- }
-
- /* (non-Javadoc)
- * @see javax.faces.application.ResourceHandler#libraryExists(java.lang.String)
- */
- @Override
- public boolean libraryExists(String libraryName) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void handleResourceRequest(FacesContext context) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isResourceRequest(FacesContext context) {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see
javax.faces.application.ResourceHandler#getRendererTypeForResourceName(java.lang.String)
- */
- @Override
- public String getRendererTypeForResourceName(String resourceName) {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
Modified:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -22,17 +22,15 @@
package org.richfaces.cdk.naming;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
-import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.faces.application.Resource;
import org.richfaces.cdk.FileNameMapper;
-import org.richfaces.resource.VersionedResource;
-import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
/**
@@ -42,9 +40,9 @@
public class FileNameMapperImpl implements FileNameMapper {
private static final class Mapping {
-
+
private Pattern pattern;
-
+
private String replacement;
public Mapping(Pattern pattern, String replacement) {
@@ -52,77 +50,54 @@
this.pattern = pattern;
this.replacement = replacement;
}
-
+
public Pattern getPattern() {
return pattern;
}
-
+
public String getReplacement() {
return replacement;
}
}
-
+
private List<Mapping> fileNameMappings;
-
- public FileNameMapperImpl(Properties fileNameMappings) {
+
+ public FileNameMapperImpl(Map<String, String> fileNameMappings) {
super();
this.fileNameMappings = compileMappings(fileNameMappings);
}
- private static List<Mapping> compileMappings(Properties properties) {
+ private static List<Mapping> compileMappings(Map<String, String>
mappings) {
List<Mapping> result = Lists.newArrayList();
- for (Entry<Object, Object> entry: properties.entrySet()) {
+ for (Entry<String, String> entry: mappings.entrySet()) {
Pattern pattern = Pattern.compile((String) entry.getKey());
- String replacement = (String) entry.getValue();
-
+ String replacement = entry.getValue();
+
result.add(new Mapping(pattern, replacement));
}
-
+
return result;
}
-
- private String stripContentClassifier(String mimeType) {
- if (mimeType == null) {
- return null;
- }
-
- int idx = mimeType.lastIndexOf('/');
- if (idx < 0) {
- return mimeType;
- } else {
- return mimeType.substring(idx + 1);
- }
- }
-
+
private String remapName(String name) {
if (name == null) {
return name;
}
-
+
for (Mapping mapping : fileNameMappings) {
Matcher matcher = mapping.getPattern().matcher(name);
if (matcher.find()) {
return matcher.replaceAll(mapping.getReplacement());
}
}
-
+
return name;
}
-
+
@Override
public String createName(Resource resource) {
- String resourceVersion = null;
- if (resource instanceof VersionedResource) {
- resourceVersion = ((VersionedResource) resource).getVersion();
- }
-
- String resourcePath =
Joiner.on('/').skipNulls().join(resource.getLibraryName(), resourceVersion,
resource.getResourceName());
- String fileExt = stripContentClassifier(resource.getContentType());
-
- resourcePath = Joiner.on('.').skipNulls().join(resourcePath, fileExt);
-
- return remapName(resourcePath);
+ return remapName(resource.getRequestPath());
}
}
Deleted:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/MarkerResourcesScanner.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/MarkerResourcesScanner.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/MarkerResourcesScanner.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -1,61 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.resource;
-
-import org.reflections.scanners.AbstractScanner;
-import org.reflections.vfs.Vfs.File;
-
-import com.google.common.collect.Multimap;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class MarkerResourcesScanner extends AbstractScanner {
-
- static final String STORE_KEY = "org.richfaces.cdk.dynamicResourceNames";
-
- private static final String RESOURCE_PROPERTIES_EXT =
".resource.properties";
-
- private static final String META_INF = "META-INF/";
-
- @Override
- public void scan(Object cls) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void scan(File file) {
- String relativePath = file.getRelativePath();
- if (relativePath.startsWith(META_INF) &&
relativePath.endsWith(RESOURCE_PROPERTIES_EXT)) {
- Multimap<String, String> store = getStore();
-
- String className = relativePath.substring(META_INF.length(),
relativePath.length() - RESOURCE_PROPERTIES_EXT.length());
- store.put(STORE_KEY, className);
- }
- }
-
- @Override
- public boolean acceptsInput(String file) {
- return true;
- }
-}
Deleted:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -1,62 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.resource;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-import org.reflections.Configuration;
-import org.reflections.Reflections;
-import org.reflections.scanners.Scanner;
-import org.reflections.util.Utils;
-
-import com.google.common.collect.Multimap;
-
-/**
- * @author Nick Belaevski
- *
- */
-class ReflectionsExt extends Reflections {
-
- public ReflectionsExt() {
- super();
- }
-
- public ReflectionsExt(Configuration configuration) {
- super(configuration);
- }
-
- public ReflectionsExt(String prefix, Scanner... scanners) {
- super(prefix, scanners);
- }
-
- public Collection<Class<?>> getMarkedClasses() {
- Map<String, Multimap<String, String>> storeMap =
getStore().getStoreMap();
- Multimap<String, String> scannerMMap =
storeMap.get(MarkerResourcesScanner.class.getName());
- if (scannerMMap == null) {
- return Collections.emptySet();
- }
- return Utils.forNames(scannerMMap.get(MarkerResourcesScanner.STORE_KEY));
- }
-
-}
Added:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.util.automount.Automounter;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Ordering;
+import com.google.common.primitives.Ints;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class ResourceUtil {
+
+ private static final String CLASSPATH_RESOURCES_LOCATION =
"META-INF/resources";
+
+ private static final String WEB_RESOURCES_LOCATION = "resources";
+
+ private static final Pattern LIBRARY_VERSION_PATTERN =
Pattern.compile("^(\\d+)(_\\d+)+");
+
+ private static final Pattern RESOURCE_VERSION_PATTERN =
Pattern.compile("^((?:\\d+)(?:_\\d+)+)[\\.]?(\\w+)?");
+
+ public static final class VersionKey {
+
+ static final Ordering<VersionKey> ORDERING = Ordering.from(new
Comparator<VersionKey>() {
+
+ @Override
+ public int compare(VersionKey o1, VersionKey o2) {
+ return Ints.lexicographicalComparator().compare(o1.versionVector,
o2.versionVector);
+ }
+ }).nullsFirst();
+
+ private static final Joiner DOT_JOINER = Joiner.on('.').skipNulls();
+
+ private String version;
+
+ private int[] versionVector;
+
+ private String extension;
+
+ public VersionKey(String version, String extension) throws NumberFormatException
{
+ this.version = version;
+ this.versionVector = parseVersionString(version);
+ this.extension = extension;
+ }
+
+ private static int[] parseVersionString(String s) {
+ String[] split = s.split("_");
+ int[] result = new int[split.length];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = Integer.parseInt(split[i]);
+ }
+ return result;
+ }
+
+ public String toString() {
+ return DOT_JOINER.join(version, extension);
+ }
+ }
+
+ private ResourceUtil() {}
+
+ public static VirtualFile getLatestVersion(VirtualFile file, boolean library) {
+ VersionKey latestVersionKey = null;
+
+ List<VirtualFile> children = file.getChildren();
+ for (VirtualFile child : children) {
+ if (library && child.isDirectory()) {
+ Matcher matcher = LIBRARY_VERSION_PATTERN.matcher(child.getName());
+ if (matcher.matches()) {
+ latestVersionKey = VersionKey.ORDERING.max(latestVersionKey, new
VersionKey(child.getName(), null));
+ }
+ } else if (!library && child.isFile()) {
+ Matcher matcher = RESOURCE_VERSION_PATTERN.matcher(child.getName());
+ if (matcher.matches()) {
+ latestVersionKey = VersionKey.ORDERING.max(latestVersionKey, new
VersionKey(matcher.group(1), matcher.group(2)));
+ }
+ }
+ }
+
+ VirtualFile result;
+
+ if (latestVersionKey != null) {
+ result = file.getChild(latestVersionKey.toString());
+ } else {
+ result = file;
+ }
+
+ if (result.exists() && (library ^ result.isFile())) {
+ return result;
+ }
+
+ return null;
+ }
+
+ private static VirtualFile getExistingChild(URL rootUrl, String path) throws
URISyntaxException, IOException {
+ VirtualFile root = VFS.getChild(rootUrl);
+ Automounter.mount(root);
+ VirtualFile child = root.getChild(path);
+ if (child.exists()) {
+ return child;
+ }
+
+ return null;
+ }
+
+ public static Collection<VirtualFile> getResourceRoots(Iterable<URL>
cpUrls, URL webrootUrl) throws URISyntaxException, IOException {
+ Collection<VirtualFile> result = Lists.newArrayList();
+
+ for (URL url : cpUrls) {
+ result.add(getExistingChild(url, CLASSPATH_RESOURCES_LOCATION));
+ }
+
+ if (webrootUrl != null) {
+ result.add(getExistingChild(webrootUrl, WEB_RESOURCES_LOCATION));
+ }
+
+ Iterables.removeIf(result, Predicates.isNull());
+
+ return result;
+ }
+
+}
Modified:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -63,7 +63,11 @@
}
private File getRoot(String rootName) {
- return new File(baseDir, rootName);
+ if (!Strings.isNullOrEmpty(rootName)) {
+ return new File(baseDir, rootName);
+ } else {
+ return baseDir;
+ }
}
private String addSkinPrefix(String s) {
@@ -110,6 +114,7 @@
@Override
public void writeProcessedResourceMappings() throws IOException {
+ //TODO separate mappings file location
FileOutputStream fos = null;
try {
File mappingsFile = new File(baseDir,
"org.richfaces/resource-mappings.properties");
Deleted:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -1,96 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.resource;
-
-import static com.google.common.collect.Collections2.transform;
-
-import java.net.URL;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Set;
-
-import org.reflections.scanners.SubTypesScanner;
-import org.reflections.scanners.TypeAnnotationsScanner;
-import org.reflections.util.ConfigurationBuilder;
-import org.richfaces.cdk.ResourceInfo;
-import org.richfaces.cdk.ResourcesScanner;
-import org.richfaces.resource.DynamicResource;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-/**
- * @author Nick Belaevski
- *
- */
-public class ResourcesScannerImpl implements ResourcesScanner {
-
- private static final Function<Class<?>, ResourceInfo>
CLASS_RESOURCE_FUNCTION = new Function<Class<?>, ResourceInfo>() {
-
- @Override
- public ResourceInfo apply(Class<?> from) {
- return new ResourceInfo(from.getName());
- }
- };
-
- private Collection<ResourceInfo> resources = Sets.newHashSet();
-
- private Collection<URL> urls;
-
- public ResourcesScannerImpl(Collection<URL> urls) {
- super();
- this.urls = urls;
- }
-
- protected Collection<URL> getUrls() {
- return urls;
- }
-
- public void scan() {
- resources.clear();
-
- ConfigurationBuilder configurationBuilder = new
ConfigurationBuilder().setUrls(urls);
- configurationBuilder.setScanners(new SubTypesScanner(), new
TypeAnnotationsScanner(),
- new MarkerResourcesScanner());
-
- ReflectionsExt refl = new ReflectionsExt(configurationBuilder);
- Set<Class<?>> classResources =
refl.getTypesAnnotatedWith(DynamicResource.class);
-
- // TODO - reflections library doesn't handle @Inherited correctly
- for (Class<?> resourceClass : classResources) {
- resources.addAll(transform(Collections.singleton(resourceClass),
CLASS_RESOURCE_FUNCTION));
- resources.addAll(transform(refl.getSubTypesOf(resourceClass),
CLASS_RESOURCE_FUNCTION));
- }
-
- resources.addAll(transform(refl.getMarkedClasses(), CLASS_RESOURCE_FUNCTION));
- }
-
- protected void addResources(Iterable<ResourceInfo> infos) {
- Iterables.addAll(resources, infos);
- }
-
- @Override
- public Collection<ResourceInfo> getResources() {
- return resources;
- }
-
-}
Deleted:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/StaticResourcesScannerImpl.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/StaticResourcesScannerImpl.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/StaticResourcesScannerImpl.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -1,126 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.resource;
-
-import static com.google.common.collect.Iterables.transform;
-import static java.util.Collections.singleton;
-
-import java.net.URL;
-import java.util.Collection;
-
-import org.reflections.vfs.Vfs;
-import org.reflections.vfs.Vfs.File;
-import org.richfaces.cdk.ResourceInfo;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class StaticResourcesScannerImpl extends ResourcesScannerImpl {
-
- private static class RelativePathStartsWithPredicate implements Predicate<File>
{
-
- private String prefix;
-
- public RelativePathStartsWithPredicate(String prefix) {
- super();
- this.prefix = prefix;
- }
-
- @Override
- public boolean apply(File input) {
- return input.getRelativePath().startsWith(prefix);
- }
- }
-
- private static class RelativePathResourceFunction implements Function<File,
ResourceInfo> {
-
- private String prefix;
-
- public RelativePathResourceFunction(String prefix) {
- super();
- this.prefix = prefix;
- }
-
- private String getResourceRelativePath(File file) {
- return file.getRelativePath().substring(prefix.length());
- }
-
- private String getLibraryName(String relativePath) {
- int idx = relativePath.lastIndexOf('/');
- if (idx < 0) {
- return null;
- } else {
- return relativePath.substring(0, idx);
- }
- }
-
- private String getResourceName(String relativePath) {
- int idx = relativePath.lastIndexOf('/');
- if (idx < 0) {
- return relativePath;
- } else {
- return relativePath.substring(idx + 1);
- }
- }
-
- @Override
- public ResourceInfo apply(File from) {
- String relPath = getResourceRelativePath(from);
- String libraryName = getLibraryName(relPath);
- String resourceName = getResourceName(relPath);
- return new ResourceInfo(resourceName, libraryName);
- }
- }
-
- private static final Predicate<File> CLASSPATH_RESOURCE_PREDICATE = new
RelativePathStartsWithPredicate(ResourceInfo.CLASSPATH_RESOURCES_LOCATION);
- private static final Predicate<File> WEB_RESOURCE_PREDICATE = new
RelativePathStartsWithPredicate(ResourceInfo.WEB_RESOURCES_LOCATION);
-
- private static final Function<File, ResourceInfo> CLASSPATH_RESOURCE_FUNCTION =
new RelativePathResourceFunction(ResourceInfo.CLASSPATH_RESOURCES_LOCATION);
- private static final Function<File, ResourceInfo> WEB_RESOURCE_FUNCTION = new
RelativePathResourceFunction(ResourceInfo.WEB_RESOURCES_LOCATION);
-
- private URL webRootUrl;
-
- public StaticResourcesScannerImpl(Collection<URL> cpUrls, URL webRootUrl) {
- super(cpUrls);
-
- this.webRootUrl = webRootUrl;
- }
-
- private void addResources(Collection<URL> urls, Predicate<Vfs.File>
filter, Function<Vfs.File, ResourceInfo> transformer) {
- Iterable<File> classpathResources = Vfs.findFiles(urls, filter);
- addResources(transform(classpathResources, transformer));
- }
-
- @Override
- public void scan() {
- super.scan();
-
- addResources(getUrls(), CLASSPATH_RESOURCE_PREDICATE,
CLASSPATH_RESOURCE_FUNCTION);
- if (webRootUrl != null) {
- addResources(singleton(webRootUrl), WEB_RESOURCE_PREDICATE,
WEB_RESOURCE_FUNCTION);
- }
- }
-}
\ No newline at end of file
Deleted:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/URLResource.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/URLResource.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/URLResource.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.resource;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Map;
-
-import javax.activation.FileTypeMap;
-import javax.activation.MimetypesFileTypeMap;
-import javax.faces.application.Resource;
-import javax.faces.context.FacesContext;
-
-import com.google.common.collect.Maps;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class URLResource extends Resource {
-
- private URL resourceUrl;
-
- public URLResource(URL resourceUrl) {
- super();
- this.resourceUrl = resourceUrl;
- }
-
- @Override
- public InputStream getInputStream() throws IOException {
- return resourceUrl.openStream();
- }
-
- @Override
- public Map<String, String> getResponseHeaders() {
- return Maps.newHashMap();
- }
-
- @Override
- public String getRequestPath() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public URL getURL() {
- return resourceUrl;
- }
-
- @Override
- public boolean userAgentNeedsUpdate(FacesContext context) {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see javax.faces.application.Resource#getContentType()
- */
- @Override
- public String getContentType() {
- FileTypeMap typeMap = MimetypesFileTypeMap.getDefaultFileTypeMap();
-
- return typeMap.getContentType(resourceUrl.getFile());
- }
-}
Added:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/AbstractResourceHandler.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/AbstractResourceHandler.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/AbstractResourceHandler.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource.handler.impl;
+
+import java.io.IOException;
+
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class AbstractResourceHandler extends ResourceHandler {
+
+ @Override
+ public Resource createResource(String resourceName) {
+ return createResource(resourceName, null);
+ }
+
+ @Override
+ public Resource createResource(String resourceName, String libraryName) {
+ return createResource(resourceName, libraryName, null);
+ }
+
+ @Override
+ public abstract Resource createResource(String resourceName, String libraryName,
String contentType);
+
+ @Override
+ public boolean libraryExists(String libraryName) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void handleResourceRequest(FacesContext context) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isResourceRequest(FacesContext context) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getRendererTypeForResourceName(String resourceName) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Added:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceHandler.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceHandler.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceHandler.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource.handler.impl;
+
+import java.io.IOException;
+
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.resource.ResourceFactory;
+import org.richfaces.resource.ResourceFactoryImpl;
+import org.richfaces.resource.StateHolderResource;
+
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DynamicResourceHandler extends AbstractResourceHandler {
+
+ private ResourceFactory resourceFactory;
+
+ private ResourceHandler staticResourceHandler;
+
+ public DynamicResourceHandler(ResourceHandler staticResourceHandler) {
+ this.staticResourceHandler = staticResourceHandler;
+ this.resourceFactory = new ResourceFactoryImpl(staticResourceHandler);
+ }
+
+ @Override
+ public Resource createResource(String resourceName, String libraryName, String
contentType) {
+ Resource result = resourceFactory.createResource(resourceName, libraryName,
null);
+
+ if (result != null) {
+ if (result instanceof StateHolderResource) {
+ StateHolderResource stateHolderResource = (StateHolderResource) result;
+ ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
+ try {
+ stateHolderResource.writeState(FacesContext.getCurrentInstance(),
dataOutput);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ byte[] bs = dataOutput.toByteArray();
+ //TODO use collected data
+ } else if (result instanceof StateHolder) {
+ StateHolder stateHolder = (StateHolder) result;
+ if (!stateHolder.isTransient()) {
+ Object savedData =
stateHolder.saveState(FacesContext.getCurrentInstance());
+ //TODO use collected data
+ }
+ }
+
+ result = new DynamicResourceWrapper(result);
+ } else {
+ result = staticResourceHandler.createResource(resourceName, libraryName);
+ }
+
+ return result;
+ }
+}
Added:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,171 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource.handler.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Map;
+
+import javax.faces.application.Resource;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.resource.VersionedResource;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Strings;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DynamicResourceWrapper extends Resource {
+
+ /**
+ *
+ */
+ private static final String ECSS_EXTENSION = ".ecss";
+
+ private static final Joiner SLASH_JOINER = Joiner.on('/').skipNulls();
+
+ private static final Joiner DOT_JOINER = Joiner.on('.').skipNulls();
+
+ private static final Joiner DASH_JOINER = Joiner.on('-').skipNulls();
+
+ private Resource resource;
+
+ public DynamicResourceWrapper(Resource resource) {
+ super();
+ this.resource = resource;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return resource.getInputStream();
+ }
+
+ public String getContentType() {
+ return resource.getContentType();
+ }
+
+ public void setContentType(String contentType) {
+ resource.setContentType(contentType);
+ }
+
+ public String getLibraryName() {
+ return resource.getLibraryName();
+ }
+
+ public void setLibraryName(String libraryName) {
+ resource.setLibraryName(libraryName);
+ }
+
+ public String getResourceName() {
+ return resource.getResourceName();
+ }
+
+ public void setResourceName(String resourceName) {
+ resource.setResourceName(resourceName);
+ }
+
+ @Override
+ public Map<String, String> getResponseHeaders() {
+ throw new UnsupportedOperationException();
+ }
+
+ private String getMangledLibraryName() {
+ String resourceName = getResourceName();
+ if (Strings.isNullOrEmpty(getLibraryName()) &&
!resourceName.endsWith(ECSS_EXTENSION)) {
+ int idx = resourceName.lastIndexOf('.');
+ if (idx < 0) {
+ return null;
+ } else {
+ return resourceName.substring(0, idx);
+ }
+ }
+
+ return getLibraryName();
+ }
+
+ private String getMangledResourceName() {
+ String resourceName = getResourceName();
+ if (resourceName.endsWith(ECSS_EXTENSION)) {
+ return resourceName.substring(0, resourceName.length() -
ECSS_EXTENSION.length());
+ }
+
+ if (Strings.isNullOrEmpty(getLibraryName())) {
+ int idx = resourceName.lastIndexOf('.');
+ if (idx < 0) {
+ return resourceName;
+ } else {
+ return resourceName.substring(idx + 1);
+ }
+ } else {
+ return resourceName;
+ }
+ }
+
+ private String getVersion() {
+ String version = null;
+ if (resource instanceof VersionedResource) {
+ version = ((VersionedResource) resource).getVersion();
+ }
+ return version;
+ }
+
+ @Override
+ public String getRequestPath() {
+ String mangledLibraryName = getMangledLibraryName();
+ String mangledResourceName = getMangledResourceName();
+ String resourceExtension = getResourceExtension();
+
+ String resourceName = DOT_JOINER.join(DASH_JOINER.join(mangledResourceName,
getVersion()), resourceExtension);
+
+ return SLASH_JOINER.join(mangledLibraryName, resourceName);
+ }
+
+ @Override
+ public URL getURL() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean userAgentNeedsUpdate(FacesContext context) {
+ throw new UnsupportedOperationException();
+ }
+
+ protected String getResourceExtension() {
+ String contentType = getContentType();
+ if (contentType == null) {
+ return null;
+ }
+
+ if (contentType.startsWith("text/") ||
contentType.startsWith("image/")) {
+ String[] split = contentType.split("/");
+ if (split.length == 2) {
+ return split[1];
+ }
+ }
+
+ return null;
+ }
+}
Added:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource.handler.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.activation.MimetypesFileTypeMap;
+import javax.faces.application.Resource;
+
+import org.jboss.vfs.VirtualFile;
+import org.richfaces.cdk.resource.ResourceUtil;
+
+import com.google.common.base.Strings;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class StaticResourceHandler extends AbstractResourceHandler {
+
+ private Collection<VirtualFile> roots;
+
+ public StaticResourceHandler(Collection<VirtualFile> roots) {
+ super();
+ this.roots = roots;
+ }
+
+ private VirtualFile findLibrary(String libraryName) {
+ for (VirtualFile file : roots) {
+ VirtualFile child = file.getChild(libraryName);
+ if (!child.exists()) {
+ continue;
+ }
+
+ VirtualFile libraryDir = ResourceUtil.getLatestVersion(child, true);
+ if (libraryDir != null) {
+ return libraryDir;
+ }
+ }
+
+ return null;
+ }
+
+ private VirtualFile findResource(Collection<VirtualFile> libraryDirs, String
resourceName) {
+ for (VirtualFile libraryDir : libraryDirs) {
+ VirtualFile child = libraryDir.getChild(resourceName);
+ if (child.exists()) {
+ VirtualFile resource = ResourceUtil.getLatestVersion(child, false);
+ if (resource != null) {
+ return resource;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Resource createResource(String resourceName, String libraryName, String
contentType) {
+ Collection<VirtualFile> libraryDirs = Collections.emptyList();
+ if (!Strings.isNullOrEmpty(libraryName)) {
+ VirtualFile libraryDir = findLibrary(libraryName);
+ if (libraryDir != null) {
+ libraryDirs = Collections.singletonList(libraryDir);
+ }
+ } else {
+ libraryDirs = roots;
+ }
+
+ VirtualFile resource = findResource(libraryDirs, resourceName);
+ if (resource != null) {
+ Resource result = new VFSResource(resource, getRelativePath(resource));
+
+ result.setResourceName(resourceName);
+ result.setLibraryName(libraryName);
+
+ if (Strings.isNullOrEmpty(contentType)) {
+
result.setContentType(MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(resourceName));
+ } else {
+ result.setContentType(contentType);
+ }
+
+
+ return result;
+ }
+
+ return null;
+ }
+
+ private String getRelativePath(VirtualFile resource) {
+ String relativePath = null;
+ for (VirtualFile parent : resource.getParentFileList()) {
+ if (roots.contains(parent)) {
+ relativePath = resource.getPathNameRelativeTo(parent);
+ break;
+ }
+ }
+ return relativePath;
+ }
+}
Added:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource.handler.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Map;
+
+import javax.faces.application.Resource;
+import javax.faces.context.FacesContext;
+
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class VFSResource extends Resource {
+
+ private VirtualFile file;
+
+ private String relativePath;
+
+ public VFSResource(VirtualFile file, String relativePath) {
+ super();
+
+ assert file.isFile();
+ assert relativePath != null;
+
+ this.file = file;
+ this.relativePath = relativePath;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return file.openStream();
+ }
+
+ @Override
+ public Map<String, String> getResponseHeaders() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getRequestPath() {
+ return relativePath;
+ }
+
+ @Override
+ public URL getURL() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean userAgentNeedsUpdate(FacesContext context) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Copied:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/ResourcesScanner.java
(from rev 18474,
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourcesScanner.java)
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/ResourcesScanner.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/ResourcesScanner.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource.scan;
+
+import java.util.Collection;
+
+import org.richfaces.cdk.ResourceKey;
+
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ResourcesScanner {
+
+ //TODO inclusions/exclusions
+
+ public void scan() throws Exception;
+
+ public Collection<ResourceKey> getResources();
+
+}
Copied:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java
(from rev 18395,
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java)
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource.scan.impl;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.Set;
+
+import org.reflections.scanners.SubTypesScanner;
+import org.reflections.scanners.TypeAnnotationsScanner;
+import org.reflections.util.ConfigurationBuilder;
+import org.richfaces.cdk.ResourceKey;
+import org.richfaces.cdk.resource.scan.ResourcesScanner;
+import org.richfaces.cdk.resource.scan.impl.reflections.MarkerResourcesScanner;
+import org.richfaces.cdk.resource.scan.impl.reflections.ReflectionsExt;
+import org.richfaces.resource.DynamicResource;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Sets;
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DynamicResourcesScanner implements ResourcesScanner {
+
+ private static final Function<Class<?>, ResourceKey>
RESOURCE_LOCATOR_FUNCTION = new Function<Class<?>, ResourceKey>() {
+
+ @Override
+ public ResourceKey apply(Class<?> from) {
+ ResourceKey key = new ResourceKey(from.getName());
+
+ return key;
+ }
+ };
+
+ private Collection<ResourceKey> resources = Sets.newHashSet();
+
+ private Collection<URL> urls;
+
+ public DynamicResourcesScanner(Collection<URL> urls) {
+ super();
+ this.urls = urls;
+ }
+
+ public void scan() {
+ ConfigurationBuilder configurationBuilder = new
ConfigurationBuilder().setUrls(urls);
+ configurationBuilder.setScanners(new SubTypesScanner(), new
TypeAnnotationsScanner(),
+ new MarkerResourcesScanner());
+
+ ReflectionsExt refl = new ReflectionsExt(configurationBuilder);
+ Set<Class<?>> allClasses = Sets.newHashSet();
+
+ // TODO - reflections library doesn't handle @Inherited correctly
+ for (Class<?> annotatedClass :
refl.getTypesAnnotatedWith(DynamicResource.class)) {
+ allClasses.add(annotatedClass);
+ allClasses.addAll(refl.getSubTypesOf(annotatedClass));
+ }
+ allClasses.addAll(refl.getMarkedClasses());
+
+ resources.addAll(Collections2.transform(allClasses, RESOURCE_LOCATOR_FUNCTION));
+ }
+
+ public Collection<ResourceKey> getResources() {
+ return resources;
+ }
+
+}
Copied:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java
(from rev 18395,
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/StaticResourcesScannerImpl.java)
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource.scan.impl;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.jboss.vfs.VirtualFile;
+import org.richfaces.cdk.ResourceKey;
+import org.richfaces.cdk.resource.ResourceUtil;
+import org.richfaces.cdk.resource.scan.ResourcesScanner;
+
+import com.google.common.collect.Sets;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class StaticResourcesScanner implements ResourcesScanner {
+
+ private Collection<ResourceKey> resources = Sets.newHashSet();
+
+ private Collection<VirtualFile> resourceRoots;
+
+ public StaticResourcesScanner(Collection<VirtualFile> resourceRoots) {
+ this.resourceRoots = resourceRoots;
+ }
+
+ private void scanResourcesRoot(VirtualFile file) {
+ if (file == null) {
+ return;
+ }
+
+ List<VirtualFile> children = file.getChildren();
+ for (VirtualFile child : children) {
+ if (child.isFile()) {
+ resources.add(new ResourceKey(child.getName()));
+ } else {
+ String libraryName = child.getName();
+ VirtualFile libraryDir = ResourceUtil.getLatestVersion(child, true);
+ if (libraryDir != null) {
+ scanLibrary(libraryName, libraryDir);
+ }
+ }
+ }
+ }
+
+ private void scanLibrary(String libraryName, VirtualFile dir) {
+ List<VirtualFile> children = dir.getChildren();
+ for (VirtualFile child : children) {
+ if (child.isFile()) {
+ resources.add(new ResourceKey(child.getName(), libraryName));
+ } else {
+ VirtualFile resource = ResourceUtil.getLatestVersion(child, false);
+ if (resource != null) {
+ resources.add(new ResourceKey(child.getName(), libraryName));
+ }
+ }
+ }
+ }
+
+ @Override
+ public void scan() throws Exception {
+ for (VirtualFile resourceRoot : resourceRoots) {
+ scanResourcesRoot(resourceRoot);
+ }
+ }
+
+ public Collection<ResourceKey> getResources() {
+ return resources;
+ }
+
+}
\ No newline at end of file
Copied:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/MarkerResourcesScanner.java
(from rev 18474,
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/MarkerResourcesScanner.java)
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/MarkerResourcesScanner.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/MarkerResourcesScanner.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource.scan.impl.reflections;
+
+import org.reflections.scanners.AbstractScanner;
+import org.reflections.vfs.Vfs.File;
+
+import com.google.common.collect.Multimap;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MarkerResourcesScanner extends AbstractScanner {
+
+ static final String STORE_KEY = "org.richfaces.cdk.dynamicResourceNames";
+
+ private static final String RESOURCE_PROPERTIES_EXT =
".resource.properties";
+
+ private static final String META_INF = "META-INF/";
+
+ @Override
+ public void scan(Object cls) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void scan(File file) {
+ String relativePath = file.getRelativePath();
+ if (relativePath.startsWith(META_INF) &&
relativePath.endsWith(RESOURCE_PROPERTIES_EXT)) {
+ Multimap<String, String> store = getStore();
+
+ String className = relativePath.substring(META_INF.length(),
relativePath.length() - RESOURCE_PROPERTIES_EXT.length());
+ store.put(STORE_KEY, className);
+ }
+ }
+
+ @Override
+ public boolean acceptsInput(String file) {
+ return true;
+ }
+}
Copied:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/ReflectionsExt.java
(from rev 18474,
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java)
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/ReflectionsExt.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/ReflectionsExt.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.resource.scan.impl.reflections;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+import org.reflections.Configuration;
+import org.reflections.Reflections;
+import org.reflections.scanners.Scanner;
+import org.reflections.util.Utils;
+
+import com.google.common.collect.Multimap;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ReflectionsExt extends Reflections {
+
+ public ReflectionsExt() {
+ super();
+ }
+
+ public ReflectionsExt(Configuration configuration) {
+ super(configuration);
+ }
+
+ public ReflectionsExt(String prefix, Scanner... scanners) {
+ super(prefix, scanners);
+ }
+
+ public Collection<Class<?>> getMarkedClasses() {
+ Map<String, Multimap<String, String>> storeMap =
getStore().getStoreMap();
+ Multimap<String, String> scannerMMap =
storeMap.get(MarkerResourcesScanner.class.getName());
+ if (scannerMMap == null) {
+ return Collections.emptySet();
+ }
+ return Utils.forNames(scannerMMap.get(MarkerResourcesScanner.STORE_KEY));
+ }
+
+}
Modified:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -26,22 +26,19 @@
import java.util.concurrent.CompletionService;
import javax.faces.application.Resource;
-import javax.faces.component.StateHolder;
+import javax.faces.application.ResourceHandler;
import javax.faces.context.FacesContext;
import org.apache.maven.plugin.logging.Log;
import org.richfaces.cdk.Faces;
-import org.richfaces.cdk.ResourceInfo;
+import org.richfaces.cdk.ResourceKey;
import org.richfaces.cdk.ResourceTaskFactory;
import org.richfaces.cdk.ResourceWriter;
import org.richfaces.cdk.faces.CurrentResourceContext;
-import org.richfaces.cdk.util.ConcurrentHashSet;
-import org.richfaces.resource.StateHolderResource;
+import org.richfaces.cdk.resource.handler.impl.DynamicResourceWrapper;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.common.io.ByteStreams;
/**
* @author Nick Belaevski
@@ -51,19 +48,19 @@
private class ResourcesRendererCallable implements Callable<Object> {
- private ResourceInfo resourceInfo;
+ private ResourceKey resourceInfo;
private boolean skinDependent;
private boolean skipped = false;
- ResourcesRendererCallable(ResourceInfo resourceInfo) {
+ ResourcesRendererCallable(ResourceKey resourceInfo) {
this.resourceInfo = resourceInfo;
}
- private Resource createResource(FacesContext facesContext, ResourceInfo
resourceInfo) {
- return
facesContext.getApplication().getResourceHandler().createResource(resourceInfo.getResourceName(),
- resourceInfo.getLibraryName());
+ private Resource createResource(FacesContext facesContext, ResourceKey
resourceInfo) {
+ ResourceHandler resourceHandler =
facesContext.getApplication().getResourceHandler();
+ return resourceHandler.createResource(resourceInfo.getResourceName(),
resourceInfo.getLibraryName());
}
private void renderResource(String skin) {
@@ -76,21 +73,6 @@
Resource resource = createResource(facesContext, resourceInfo);
CurrentResourceContext.getInstance(facesContext).setResource(resource);
-
- if (resource instanceof StateHolderResource) {
- StateHolderResource stateHolderResource = (StateHolderResource)
resource;
- ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
- stateHolderResource.writeState(facesContext, dataOutput);
- byte[] bs = dataOutput.toByteArray();
- //TODO use collected data
- } else if (resource instanceof StateHolder) {
- StateHolder stateHolder = (StateHolder) resource;
- if (!stateHolder.isTransient()) {
- Object savedData = stateHolder.saveState(facesContext);
- //TODO use collected data
- }
- }
-
//TODO check content type
resourceWriter.writeResource(skin, resource);
} catch (Exception e) {
@@ -108,6 +90,7 @@
private void checkResource() {
try {
FacesContext facesContext = faces.startRequest();
+ faces.setSkin("DEFAULT");
Resource resource = createResource(facesContext, resourceInfo);
if (resource == null) {
@@ -128,10 +111,10 @@
return;
}
- if (contentType.contains("css") ||
contentType.contains("image")) {
- skinDependent = true;
- }
+ //TODO hack
+ skinDependent = (resource instanceof DynamicResourceWrapper);
} finally {
+ faces.setSkin(null);
faces.stopRequest();
}
}
@@ -158,22 +141,21 @@
private ResourceWriter resourceWriter;
- private ConcurrentHashSet<ResourceInfo> submittedResources = new
ConcurrentHashSet<ResourceInfo>();
-
private CompletionService<Object> completionService;
private String[] skins = new String[0];
private Predicate<Resource> filter = Predicates.alwaysTrue();
+ public ResourceTaskFactoryImpl(Faces faces) {
+ super();
+ this.faces = faces;
+ }
+
public void setLog(Log log) {
this.log = log;
}
- public void setFaces(Faces faces) {
- this.faces = faces;
- }
-
public void setResourceWriter(ResourceWriter resourceWriter) {
this.resourceWriter = resourceWriter;
}
@@ -190,10 +172,9 @@
this.filter = filter;
}
- @Override
- public void submit(ResourceInfo info) {
- if (submittedResources.addIfAbsent(info)) {
- completionService.submit(new ResourcesRendererCallable(info));
+ public void submit(Iterable<ResourceKey> locators) {
+ for (ResourceKey locator : locators) {
+ completionService.submit(new ResourcesRendererCallable(locator));
}
}
}
Modified:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/MorePredicates.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/MorePredicates.java 2010-08-05
20:59:23 UTC (rev 18490)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/MorePredicates.java 2010-08-05
21:30:13 UTC (rev 18491)
@@ -21,6 +21,8 @@
*/
package org.richfaces.cdk.util;
+import java.util.regex.Pattern;
+
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
@@ -68,5 +70,14 @@
return input.startsWith(prefix);
}
};
+ }
+
+ public static Predicate<CharSequence> matches(final Pattern pattern) {
+ return new Predicate<CharSequence>() {
+ @Override
+ public boolean apply(CharSequence input) {
+ return pattern.matcher(input).matches();
+ }
+ };
}
}
\ No newline at end of file