Author: nbelaevski
Date: 2010-08-01 14:42:55 -0400 (Sun, 01 Aug 2010)
New Revision: 18318
Added:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/MoreConstraints.java
Removed:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/config/
Modified:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java
Log:
Latest changes in maven-resources-plugin
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-01
17:30:53 UTC (rev 18317)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java 2010-08-01
18:42:55 UTC (rev 18318)
@@ -21,12 +21,15 @@
*/
package org.richfaces.cdk;
+import static com.google.common.base.Predicates.notNull;
+import static com.google.common.collect.Collections2.filter;
+import static com.google.common.collect.Collections2.transform;
+
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.CompletionService;
@@ -50,12 +53,14 @@
import org.richfaces.cdk.resource.StaticResourcesScannerImpl;
import org.richfaces.cdk.task.ResourceTaskFactoryImpl;
import org.richfaces.cdk.util.ClasspathUtil;
+import org.richfaces.cdk.util.MoreConstraints;
import org.richfaces.cdk.util.MorePredicates;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
-
+import com.google.common.collect.Constraints;
+import com.google.common.collect.Lists;
/**
* @goal process
* @requiresDependencyResolution compile
@@ -63,6 +68,8 @@
*/
public class ProcessMojo extends AbstractMojo {
+ private static final URL[] EMPTY_URL_ARRAY = new URL[0];
+
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);
@@ -75,6 +82,21 @@
};
};
+ private final Function<String, URL> filePathToURL = new Function<String,
URL>() {
+ public URL apply(String from) {
+ try {
+ File file = new File(from);
+ if (file.exists()) {
+ return file.toURI().toURL();
+ }
+ } catch (MalformedURLException e) {
+ getLog().error("Bad URL in classpath", e);
+ }
+
+ return null;
+ };
+ };
+
/**
* @parameter
* @required
@@ -146,26 +168,16 @@
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
- List<?> compileClasspathElements =
project.getCompileClasspathElements();
- String outputDirectory = project.getBuild().getOutputDirectory();
- URL[] urls = new URL[compileClasspathElements.size() + 1];
- int i = 0;
+ List<String> classpath =
Constraints.constrainedList(Lists.<String>newArrayList(),
MoreConstraints.cast(String.class));
+ classpath.addAll((List<String>)
project.getCompileClasspathElements());
+ classpath.add(project.getBuild().getOutputDirectory());
- urls[i++] = new File(outputDirectory).toURI().toURL();
-
- for (Iterator<?> iter = compileClasspathElements.iterator();
iter.hasNext();) {
- String element = (String) iter.next();
-
- urls[i++] = new File(element).toURI().toURL();
- }
-
+ URL[] urlClasspath = filter(transform(classpath, filePathToURL),
notNull()).toArray(EMPTY_URL_ARRAY);
if (useCCL) {
- classLoader = new URLClassLoader(urls, classLoader);
+ classLoader = new URLClassLoader(urlClasspath, classLoader);
} else {
- classLoader = new URLClassLoader(urls);
+ classLoader = new URLClassLoader(urlClasspath);
}
- } catch (MalformedURLException e) {
- getLog().error("Bad URL in classpath", e);
} catch (DependencyResolutionRequiredException e) {
getLog().error("Dependencies not resolved ", e);
}
Added:
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/MoreConstraints.java
===================================================================
---
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/MoreConstraints.java
(rev 0)
+++
root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/MoreConstraints.java 2010-08-01
18:42:55 UTC (rev 18318)
@@ -0,0 +1,41 @@
+/*
+ * 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.util;
+
+import com.google.common.collect.Constraint;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class MoreConstraints {
+
+ private MoreConstraints() {}
+
+ public static <E> Constraint<E> cast(final Class<E> clazz) {
+ return new Constraint<E>() {
+ public E checkElement(E element) {
+ return clazz.cast(element);
+ };
+ };
+ }
+}