Author: nbelaevski
Date: 2010-12-06 15:34:27 -0500 (Mon, 06 Dec 2010)
New Revision: 20423
Added:
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/FileNameMapping.java
Modified:
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java
Log:
maven-resources-plugin:
- file name mappings are now applied in the same order as they are defined in pom.xml
Added:
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/FileNameMapping.java
===================================================================
--- trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/FileNameMapping.java
(rev 0)
+++
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/FileNameMapping.java 2010-12-06
20:34:27 UTC (rev 20423)
@@ -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;
+
+import java.util.regex.Pattern;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FileNameMapping {
+
+ private String name;
+
+ private String value;
+
+ private Pattern namePattern = null;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public Pattern getNamePattern() {
+ if (namePattern == null) {
+ namePattern = Pattern.compile(name);
+ }
+
+ return namePattern;
+ }
+}
Modified:
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java
===================================================================
---
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java 2010-12-06
19:22:19 UTC (rev 20422)
+++
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java 2010-12-06
20:34:27 UTC (rev 20423)
@@ -36,7 +36,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
-import java.util.Properties;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@@ -79,7 +78,6 @@
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
@@ -151,7 +149,7 @@
* @parameter
*/
// TODO review usage of properties?
- private Properties fileNameMappings = new Properties();
+ private FileNameMapping[] fileNameMappings = new FileNameMapping[0];
/**
* @parameter
@@ -286,7 +284,7 @@
ResourceHandler resourceHandler = new
DynamicResourceHandler(staticResourceHandler, resourceFactory);
// TODO set webroot
- faces = new FacesImpl(null, new
FileNameMapperImpl(Maps.fromProperties(fileNameMappings)), resourceHandler);
+ faces = new FacesImpl(null, new FileNameMapperImpl(fileNameMappings),
resourceHandler);
faces.start();
ResourceWriterImpl resourceWriter = new ResourceWriterImpl(resourceOutputDir,
resourceMappingDir, resourceProcessors);
Modified:
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java
===================================================================
---
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java 2010-12-06
19:22:19 UTC (rev 20422)
+++
trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java 2010-12-06
20:34:27 UTC (rev 20423)
@@ -21,73 +21,34 @@
*/
package org.richfaces.cdk.naming;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.richfaces.cdk.FileNameMapper;
+import org.richfaces.cdk.FileNameMapping;
-import com.google.common.collect.Lists;
-
/**
* @author Nick Belaevski
*
*/
public class FileNameMapperImpl implements FileNameMapper {
- private static final class Mapping {
+ private FileNameMapping[] fileNameMappings;
- private Pattern pattern;
-
- private String replacement;
-
- public Mapping(Pattern pattern, String replacement) {
- super();
- this.pattern = pattern;
- this.replacement = replacement;
- }
-
- public Pattern getPattern() {
- return pattern;
- }
-
- public String getReplacement() {
- return replacement;
- }
- }
-
- private List<Mapping> fileNameMappings;
-
- public FileNameMapperImpl(Map<String, String> fileNameMappings) {
+ public FileNameMapperImpl(FileNameMapping[] fileNameMappings) {
super();
- this.fileNameMappings = compileMappings(fileNameMappings);
+ this.fileNameMappings = fileNameMappings;
}
- private static List<Mapping> compileMappings(Map<String, String>
mappings) {
- List<Mapping> result = Lists.newArrayList();
-
- for (Entry<String, String> entry: mappings.entrySet()) {
- Pattern pattern = Pattern.compile((String) entry.getKey());
- String replacement = entry.getValue();
-
- result.add(new Mapping(pattern, replacement));
- }
-
- return result;
- }
-
@Override
public String createName(String resourcePath) {
if (resourcePath == null) {
return resourcePath;
}
- for (Mapping mapping : fileNameMappings) {
- Matcher matcher = mapping.getPattern().matcher(resourcePath);
+ for (FileNameMapping mapping : fileNameMappings) {
+ Matcher matcher = mapping.getNamePattern().matcher(resourcePath);
if (matcher.find()) {
- return matcher.replaceAll(mapping.getReplacement());
+ return matcher.replaceAll(mapping.getValue());
}
}