diff --git a/magnolia-resource-loader/src/main/java/info/magnolia/resourceloader/classpath/ClasspathOrigin.java b/magnolia-resource-loader/src/main/java/info/magnolia/resourceloader/classpath/ClasspathOrigin.java index 18a76ba..620af47 100644 --- a/magnolia-resource-loader/src/main/java/info/magnolia/resourceloader/classpath/ClasspathOrigin.java +++ b/magnolia-resource-loader/src/main/java/info/magnolia/resourceloader/classpath/ClasspathOrigin.java @@ -203,6 +203,7 @@ public class ClasspathOrigin extends AbstractOrigin { protected Predicate resourcesFilter() { final FilterBuilder filterBuilder = new FilterBuilder(); + filterBuilder.add(new ExcludeMetaInfExceptMagnolia()); filterBuilder.exclude(extensionsPattern(excludedResourcesExtensions())); @@ -234,7 +235,6 @@ public class ClasspathOrigin extends AbstractOrigin { protected String[] excludedPackages() { return new String[] { - "META-INF", "com.oracle.java", "com.oracle.tools", "com.sun", diff --git a/magnolia-resource-loader/src/main/java/info/magnolia/resourceloader/classpath/ExcludeMetaInfExceptMagnolia.java b/magnolia-resource-loader/src/main/java/info/magnolia/resourceloader/classpath/ExcludeMetaInfExceptMagnolia.java new file mode 100644 index 0000000..82d34cb --- /dev/null +++ b/magnolia-resource-loader/src/main/java/info/magnolia/resourceloader/classpath/ExcludeMetaInfExceptMagnolia.java @@ -0,0 +1,49 @@ +/** + * This file Copyright (c) 2015 Magnolia International + * Ltd. (http://www.magnolia-cms.com). All rights reserved. + * + * + * This file is dual-licensed under both the Magnolia + * Network Agreement and the GNU General Public License. + * You may elect to use one or the other of these licenses. + * + * This file is distributed in the hope that it will be + * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. + * Redistribution, except as permitted by whichever of the GPL + * or MNA you select, is prohibited. + * + * 1. For the GPL license (GPL), you can redistribute and/or + * modify this file under the terms of the GNU General + * Public License, Version 3, as published by the Free Software + * Foundation. You should have received a copy of the GNU + * General Public License, Version 3 along with this program; + * if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * 2. For the Magnolia Network Agreement (MNA), this file + * and the accompanying materials are made available under the + * terms of the MNA which accompanies this distribution, and + * is available at http://www.magnolia-cms.com/mna.html + * + * Any modifications to this file must keep this entire header + * intact. + * + */ +package info.magnolia.resourceloader.classpath; + +import com.google.common.base.Predicate; + +/** + * A predicate used by {@link ClasspathOrigin} to include META-INF/magnolia/ resources but exclude other META-INF resources. + * Should be easier to read than a regex. + */ +class ExcludeMetaInfExceptMagnolia implements Predicate { + @Override + public boolean apply(String input) { + // Exclude META-INF except META-INF/magnolia in case we manage to retrofit the module loading mechanism + // Reflections passes resources path in pac.kage.file format, not /dire/ctory/file (which is fun when files have dots in their names) + return !input.startsWith("META-INF") || input.startsWith("META-INF.magnolia."); + } +} diff --git a/magnolia-resource-loader/src/test/java/info/magnolia/resourceloader/classpath/ExcludeMetaInfExceptMagnoliaTest.java b/magnolia-resource-loader/src/test/java/info/magnolia/resourceloader/classpath/ExcludeMetaInfExceptMagnoliaTest.java new file mode 100644 index 0000000..d91ea47 --- /dev/null +++ b/magnolia-resource-loader/src/test/java/info/magnolia/resourceloader/classpath/ExcludeMetaInfExceptMagnoliaTest.java @@ -0,0 +1,56 @@ +/** + * This file Copyright (c) 2015 Magnolia International + * Ltd. (http://www.magnolia-cms.com). All rights reserved. + * + * + * This file is dual-licensed under both the Magnolia + * Network Agreement and the GNU General Public License. + * You may elect to use one or the other of these licenses. + * + * This file is distributed in the hope that it will be + * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. + * Redistribution, except as permitted by whichever of the GPL + * or MNA you select, is prohibited. + * + * 1. For the GPL license (GPL), you can redistribute and/or + * modify this file under the terms of the GNU General + * Public License, Version 3, as published by the Free Software + * Foundation. You should have received a copy of the GNU + * General Public License, Version 3 along with this program; + * if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * 2. For the Magnolia Network Agreement (MNA), this file + * and the accompanying materials are made available under the + * terms of the MNA which accompanies this distribution, and + * is available at http://www.magnolia-cms.com/mna.html + * + * Any modifications to this file must keep this entire header + * intact. + * + */ +package info.magnolia.resourceloader.classpath; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ExcludeMetaInfExceptMagnoliaTest { + @Test + public void includesMagnoliaModuleDescriptor() { + assertTrue(new ExcludeMetaInfExceptMagnolia().apply("META-INF.magnolia.foo.xml")); + } + + @Test + public void excludesJarManifest() { + assertFalse(new ExcludeMetaInfExceptMagnolia().apply("META-INF.MANIFEST.MF")); + } + + @Test + public void excludesServicesManifests() { + assertFalse(new ExcludeMetaInfExceptMagnolia().apply("META-INF.services.javax.annotation.processing.Processor")); + } + +} \ No newline at end of file