diff --git a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/ArchiveMavenAssembler.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/ArchiveMavenAssembler.java new file mode 100644 index 000000000..188999287 --- /dev/null +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/ArchiveMavenAssembler.java @@ -0,0 +1,91 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.api.maven.archive.assembler; + +import java.io.File; + +import org.jboss.shrinkwrap.api.Assignable; +import org.jboss.shrinkwrap.resolver.api.ConfigurableResolverSystem; +import org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException; + +/** + * ArchiveMavenAssembler is an abstraction of Maven Package phase for ShrinkWrap. It allows to package an archive based on pom.xml file. + * + * @author Matous Jobanek + * @author Karel Piwko + * + */ +public interface ArchiveMavenAssembler extends PomlessArchiveMavenAssembler, Assignable { + + /** + * Optional operation. Configures this {@link ArchiveMavenAssembler} from the specified settings.xml file + * + * @param file A settings.xml {@link File} this {@link ArchiveMavenAssembler} should be configured from. + * @return This configured {@link ArchiveMavenAssembler} + * @throws IllegalArgumentException If the file is not specified, is a directory, or does not exist + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + * @throws UnsupportedOperationException If this {@link ConfigurableResolverSystem} does not support configuration by + * {@link File} + */ + ConfiguredArchiveMavenAssembler configuredFrom(File file) throws IllegalArgumentException, UnsupportedOperationException, + InvalidConfigurationFileException; + + /** + * Optional operation. Configures this {@link ArchiveMavenAssembler} from the specified settings.xml file at the specified + * path + * + * @param pathToFile A path to a settings.xml file this {@link ArchiveMavenAssembler} should be configured from. + * @return This configured {@link ArchiveMavenAssembler} + * @throws IllegalArgumentException If the file is not specified, is a directory, or does not exist + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + * @throws UnsupportedOperationException If this {@link ConfigurableResolverSystem} does not support configuration by + * {@link File} + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + */ + ConfiguredArchiveMavenAssembler configuredFrom(String pathToFile) throws IllegalArgumentException, + UnsupportedOperationException, InvalidConfigurationFileException; + + /** + * Optional operation. Configures this {@link ArchiveMavenAssembler} from the result of + * {@link ClassLoader#getResource(String)} call using the current {@link Thread#getContextClassLoader()} + * + * @param path A {@link ClassLoader} path to a settings.xml file this {@link ArchiveMavenAssembler} should be configured from. + * @return This configured {@link ArchiveMavenAssembler} + * @throws IllegalArgumentException If the either argument is not specified or if the path can not be found + * @throws UnsupportedOperationException If this {@link ConfigurableResolverSystem} does not support configuration by + * {@link ClassLoader} resource + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + */ + ConfiguredArchiveMavenAssembler configuredFromClassloaderResource(String path) throws IllegalArgumentException, + UnsupportedOperationException, InvalidConfigurationFileException; + + /** + * Optional operation. Configures this {@link ConfigurableResolverSystem} from the result of + * {@link ClassLoader#getResource(String)} using the specified {@link ClassLoader} + * + * @param path A {@link ClassLoader} path to a settings.xml file this {@link ArchiveMavenAssembler} should be configured from. + * @param cl A {@link ClassLoader} + * @return This configured {@link ArchiveMavenAssembler} + * @throws IllegalArgumentException If the either argument is not specified or if the path can not be found + * @throws UnsupportedOperationException If this {@link ConfigurableResolverSystem} does not support configuration by + * {@link ClassLoader} resource + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + */ + ConfiguredArchiveMavenAssembler configuredFromClassloaderResource(String path, ClassLoader cl) throws IllegalArgumentException, + UnsupportedOperationException, InvalidConfigurationFileException; + +} diff --git a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/ArchiveMavenAssemblerException.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/ArchiveMavenAssemblerException.java new file mode 100644 index 000000000..70ca17f86 --- /dev/null +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/ArchiveMavenAssemblerException.java @@ -0,0 +1,41 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.api.maven.archive.assembler; + +/** + * Exception which in raised if assembling a Maven project is not successful. + * + * @author Matous Jobanek + * @author Karel Piwko + * + */ +public class ArchiveMavenAssemblerException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public ArchiveMavenAssemblerException(String msg) { + super(msg); + } + + public ArchiveMavenAssemblerException(String msg, Throwable cause) { + super(msg, cause); + } + +} diff --git a/maven/impl-maven-integration-tests/war-sample/src/main/java/test/WarClass.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/ConfiguredArchiveMavenAssembler.java similarity index 62% rename from maven/impl-maven-integration-tests/war-sample/src/main/java/test/WarClass.java rename to maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/ConfiguredArchiveMavenAssembler.java index 6d413c7e7..584a1f480 100644 --- a/maven/impl-maven-integration-tests/war-sample/src/main/java/test/WarClass.java +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/ConfiguredArchiveMavenAssembler.java @@ -1,6 +1,6 @@ /* * JBoss, Home of Professional Open Source - * Copyright 2011, Red Hat Middleware LLC, and individual contributors + * Copyright 2013, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * @@ -14,19 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package test; +package org.jboss.shrinkwrap.resolver.api.maven.archive.assembler; /** - * Dummy class + * Instance of {@link ArchiveMavenAssembler} that has configuration from a settings.xml file loaded * - * @author Matous Jobanek + * @author Karel Piwko * */ -public class WarClass { +public interface ConfiguredArchiveMavenAssembler extends PomlessArchiveMavenAssembler { - public static final String GREETINGS = "Hello from MavenImporter imported class"; - - public String greet() { - return GREETINGS; - } } diff --git a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/PomEquippedArchiveMavenAssembler.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/PomEquippedArchiveMavenAssembler.java new file mode 100644 index 000000000..a8014574d --- /dev/null +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/PomEquippedArchiveMavenAssembler.java @@ -0,0 +1,161 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.api.maven.archive.assembler; + +import org.jboss.shrinkwrap.api.Assignable; +import org.jboss.shrinkwrap.resolver.api.maven.ScopeType; +import org.jboss.shrinkwrap.resolver.api.maven.filter.MavenResolutionFilter; + +/** + * Instance of {@link ArchiveMavenAssembler} that has configuration from a POM file loaded + * + * @author Matous Jobanek + * @author Karel Piwko + */ +public interface PomEquippedArchiveMavenAssembler extends Assignable { + + /** + * Based on metadata previously loaded from a Project Object Model file, adds content made during package phase to + * the archive. The content is compiled using dependencies with following scopes: + * {@link ScopeType#COMPILE}, {@link ScopeType#IMPORT}, {@link ScopeType#PROVIDED}, {@link ScopeType#RUNTIME}, + * {@link ScopeType#SYSTEM} - there isn't used the scope {@link ScopeType#TEST} as it simulates Maven package build. + *

+ * If you want to use all scopes, then use this method: {@code withBuildOutput(ScopeType.values())} + *

+ * + * @return This modified {@link ArchiveMavenAssembler} instance with added content based on metadata previously loaded + * from a Project Object Model file. + */ + PomEquippedArchiveMavenAssembler withBuildOutput(); + + /** + * Based on metadata previously loaded from a Project Object Model file, adds content (classes and resources) made + * during package phase to the archive. + * The content is compiled using dependencies with the set of scopes given by the parameter + *

+ * If you want to use all scopes, then use: {@code withBuildOutput(ScopeType.values())} + *

+ * + * @return This modified {@link ArchiveMavenAssembler} instance with added content based on metadata previously loaded + * from a Project Object Model file. + */ + PomEquippedArchiveMavenAssembler withBuildOutput(ScopeType... scopes); + + /** + * Based on metadata previously loaded from a Project Object Model file, adds test content (test classes and test resources) + * made during package phase to the archive. + * The content is compiled using dependencies with all scopes: + * {@link ScopeType#COMPILE}, {@link ScopeType#IMPORT}, {@link ScopeType#PROVIDED}, {@link ScopeType#RUNTIME}, + * {@link ScopeType#SYSTEM}, {@link ScopeType#TEST} + *

+ * If you want to limit the set of used scopes, then use this method: {@link #withTestBuildOutput(ScopeType...)} + *

+ * + * @return This modified {@link ArchiveMavenAssembler} instance with added test content based on metadata previously loaded + * from a Project Object Model file. + */ + PomEquippedArchiveMavenAssembler withTestBuildOutput(); + + /** + * Based on metadata previously loaded from a Project Object Model file, adds test content (test classes and test resources) + * made during package phase to the archive. + * The content is compiled using dependencies with the set of scopes given by the parameter + *

+ * If you want to use all scopes, then use: {@code withTestBuildOutput()} + *

+ * + * @return This modified {@link ArchiveMavenAssembler} instance with added test content based on metadata previously loaded + * from a Project Object Model file. + */ + PomEquippedArchiveMavenAssembler withTestBuildOutput(ScopeType... scopes); + + /** + * Ads dependencies defined in previously loaded Project Object Model file. + * The set of dependencies can be limited by {@link MavenResolutionFilter} and set of {@link ScopeType}s. + *

+ * If you want to use all possible scopes, then use this method: {@link #withDependencies(MavenResolutionFilter)} + *

+ *

+ * If you don't want to specify {@link MavenResolutionFilter} and limit it only by set of {@link ScopeType}s, + * then use this method: {@link #withDependencies(ScopeType...)} + *

+ *

+ * If you don't want to limit anything and use all defined dependencies, then use this method: {@link #withDependencies()} + *

+ * + * @return This modified {@link ArchiveMavenAssembler} instance with added dependencies limited by {@link MavenResolutionFilter} and set of {@link ScopeType}s + * @param filter A {@link MavenResolutionFilter} the added dependencies should be limited by + * @param scopes A set of {@link ScopeType}s the added dependencies should be limited by + */ + PomEquippedArchiveMavenAssembler withDependencies(MavenResolutionFilter filter, ScopeType... scopes); + + /** + * Ads dependencies defined in previously loaded Project Object Model file. All scopes will be used. + * The set of dependencies can be limited by {@link MavenResolutionFilter}. + *

+ * If you want to limit the set of dependencies also by scopes, then use this method: {@link #withDependencies(MavenResolutionFilter, ScopeType...)} + *

+ *

+ * If you don't want to specify {@link MavenResolutionFilter} and limit it only by set of scopes, + * then use this method: {@link #withDependencies(ScopeType...)} + *

+ *

+ * If you don't want to limit anything and use all defined dependencies, then use this method: {@link #withDependencies()} + *

+ * + * @return This modified {@link ArchiveMavenAssembler} instance with added dependencies limited by {@link MavenResolutionFilter} + * @param filter A {@link MavenResolutionFilter} the added dependencies should be limited by + */ + PomEquippedArchiveMavenAssembler withDependencies(MavenResolutionFilter filter); + + /** + * Ads dependencies defined in previously loaded Project Object Model file. + * The set of dependencies can be limited by set of {@link ScopeType}s. + *

+ * If you want to limit the set of dependencies also by scopes, then use this method: {@link #withDependencies(MavenResolutionFilter, ScopeType...)} + *

+ *

+ * If you don't want to specify {@link MavenResolutionFilter} and limit it only by set of scopes, + * then use this method: {@link #withDependencies(ScopeType...)} + *

+ *

+ * If you don't want to limit anything and use all defined dependencies, then use this method: {@link #withDependencies()} + *

+ * + * @return This modified {@link ArchiveMavenAssembler} instance with added dependencies limited by a set of {@link ScopeType}s + * @param scopes A set of {@link ScopeType}s the added dependencies should be limited by + */ + PomEquippedArchiveMavenAssembler withDependencies(ScopeType... scopes); + + /** + * Ads all dependencies defined in previously loaded Project Object Model file. + * The set of dependencies can be limited by {@link MavenResolutionFilter} and set of {@link ScopeType}s. + *

+ * If you want to limit the set of added dependencies, use any of these methods:
+ * {@link #withDependencies(ScopeType...)}
+ * {@link #withDependencies(MavenResolutionFilter, ScopeType...)}
+ * {@link #withDependencies(MavenResolutionFilter)} + *

+ * + * @return This modified {@link ArchiveMavenAssembler} instance with added dependencies + + */ + PomEquippedArchiveMavenAssembler withDependencies(); + + TYPE as(Class var1, String name); + +} diff --git a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/PomlessArchiveMavenAssembler.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/PomlessArchiveMavenAssembler.java new file mode 100644 index 000000000..6bdcc90ff --- /dev/null +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/PomlessArchiveMavenAssembler.java @@ -0,0 +1,124 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.api.maven.archive.assembler; + +import java.io.File; + +import org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException; + +/** + * Instance of {@link ArchiveMavenAssembler} that allows to load configuration from a POM file + * + * @author Matous Jobanek + * @author Karel Piwko + */ +public interface PomlessArchiveMavenAssembler extends UncustomizedArchiveMavenAssembler { + + /** + * Configures the Maven Assembler from Project Object Model contained in the specified POM {@link File}. + * + * @param pomFile A POM {@link File} the maven Assembler should be configured from. + * @return The configured Maven Assembler from the given Project Object Model. + * @throws IllegalArgumentException If no file was specified, if the file does not exist or points to a directory + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + */ + PomEquippedArchiveMavenAssembler usingPom(File pomFile) + throws IllegalArgumentException, InvalidConfigurationFileException; + + /** + * Configures the Maven Assembler from Project Object Model contained in the specified POM {@link File}. + * + * @param pomFile A POM {@link File} the maven Assembler should be configured from. + * @param profiles Active/inactive profiles + * @return The configured Maven Assembler from the given Project Object Model. + * @throws IllegalArgumentException If no file was specified, if the file does not exist or points to a directory + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + */ + PomEquippedArchiveMavenAssembler usingPom(File pomFile, String... profiles) throws IllegalArgumentException, + InvalidConfigurationFileException; + + /** + * Configures the Maven Assembler from Project Object Model contained in the POM file located at the specified path. The path + * will be represented as a new {@link File} by means of {@link File#File(String)} + * + * @param pathToPomFile A path to a POM file the maven Assembler should be configured from. + * @return The configured Maven Assembler from the given Project Object Model. + * @throws IllegalArgumentException If no path was specified, or if the path points to a file which does not exist or is a + * directory + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + */ + PomEquippedArchiveMavenAssembler usingPom(String pathToPomFile) throws IllegalArgumentException, + InvalidConfigurationFileException; + + /** + * Configures the Maven Assembler from Project Object Model contained in the POM file located at the specified path. The path + * will be represented as a new {@link File} by means of {@link File#File(String)} + * + * @param pathToPomFile A path to a POM file the maven Assembler should be configured from. + * @param profiles Active/inactive profiles + * @return The configured Maven Assembler from the given Project Object Model. + * @throws IllegalArgumentException If no path was specified, or if the path points to a file which does not exist or is a + * directory + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + */ + PomEquippedArchiveMavenAssembler usingPom(String pathToPomFile, String... profiles) throws IllegalArgumentException, + InvalidConfigurationFileException; + + /** + * Configures the Maven Assembler from Project Object Model contained in the POM file located at the specified + * {@link ClassLoader} resource path, loaded by the current {@link Thread#getContextClassLoader()}. + * + * @param pathToPomResource A {@link ClassLoader} resource path to a POM filee the maven Assembler should be configured from. + * @return The configured Maven Assembler from the given Project Object Model. + * @throws IllegalArgumentException If no path was specified, or if the resource could not be found at the specified path + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + */ + PomEquippedArchiveMavenAssembler usingPomFromClassLoaderResource(String pathToPomResource) + throws IllegalArgumentException, + InvalidConfigurationFileException; + + /** + * Configures the Maven Assembler from Project Object Model contained in the POM file located at the specified + * {@link ClassLoader} resource path, loaded by the specified {@link ClassLoader}. + * + * @param pathToPomResource A {@link ClassLoader} resource path to a POM filee the maven Assembler should be configured from. + * @param cl A {@link ClassLoader} + * @return The configured Maven Assembler from the given Project Object Model. + * @throws IllegalArgumentException If no path was specified, no ClassLoader was specified, or if the resource could not be + * found at the specified path + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + */ + PomEquippedArchiveMavenAssembler usingPomFromClassLoaderResource(String pathToPomResource, ClassLoader cl) + throws IllegalArgumentException, InvalidConfigurationFileException; + + /** + * Configures the Maven Assembler from Project Object Model contained in the POM file located at the specified + * {@link ClassLoader} resource path, loaded by the specified {@link ClassLoader}. + * + * @param pathToPomResource A {@link ClassLoader} resource path to a POM filee the maven Assembler should be configured from. + * @param cl A {@link ClassLoader} + * @param profiles Active/inactive profiles + * @return The configured Maven Assembler from the given Project Object Model. + * @throws IllegalArgumentException If no path was specified, no ClassLoader was specified, any specified profiles are + * invalid or null, or if the resource could not be found at the specified path + * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format + */ + PomEquippedArchiveMavenAssembler usingPomFromClassLoaderResource(String pathToPomResource, ClassLoader cl, + String... profiles) + throws IllegalArgumentException, InvalidConfigurationFileException; + +} diff --git a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/UncustomizedArchiveMavenAssembler.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/UncustomizedArchiveMavenAssembler.java new file mode 100644 index 000000000..6fdf2eaa9 --- /dev/null +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/assembler/UncustomizedArchiveMavenAssembler.java @@ -0,0 +1,45 @@ +package org.jboss.shrinkwrap.resolver.api.maven.archive.assembler; + +/** + * @author Matous Jobanek + */ +public interface UncustomizedArchiveMavenAssembler { + + /** + * Optional operation. Sets whether a default build directory (usually target/classes) should be used as a source and target of compiled classes and other resources .
+ * If the values is set to false then there is created a new directory (resolver-randomUUID()) inside of this default directory. + * This ensures that each run of ArchiveMavenAssembler uses clear directory, so cannot be influenced by previous runs/builds. + * But this also can decrease a performance as for each run it needs to compile the classes again. + * By default, the value is set to false, so the default build directory is not used. + * + * @param useDefaultBuildDirectory whether the default build directory should be used + * @return Modified {@link PomlessArchiveMavenAssembler} instance + */ + PomlessArchiveMavenAssembler usingDefaultBuildDirectory(boolean useDefaultBuildDirectory); + + /** + * Optional operation. Force using a default build directory as a source and target of compiled classes and other resources (usually target/classes).
+ * Alias to {@link ConfiguredArchiveMavenAssembler#usingDefaultBuildDirectory(boolean)}, passing true as a parameter. + * + * @return Modified {@link PomlessArchiveMavenAssembler} instance + */ + PomlessArchiveMavenAssembler usingDefaultBuildDirectory(); + + /** + * Optional operation. Sets whether resolution should be done in "offline" (ie. not connected to Internet) mode. + * By default, resolution is done in online mode + * + * @param offline Whether resolution should be done in "offline". By default, resolution is done in online mode. + * + * @return Modified {@link PomlessArchiveMavenAssembler} instance + */ + PomlessArchiveMavenAssembler usingOfflineMode(boolean useOfflineMode); + + /** + * Optional operation. Sets that resolution should be done in "offline" (ie. not connected to Internet) mode. Alias to + * {@link ConfiguredArchiveMavenAssembler#offline(boolean)}, passing true as a parameter. + * + * @return Modified {@link PomlessArchiveMavenAssembler} instance + */ + PomlessArchiveMavenAssembler usingOfflineMode(); +} diff --git a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/ConfiguredMavenImporter.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/ConfiguredMavenImporter.java index 96b862276..bdfe1e5b1 100644 --- a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/ConfiguredMavenImporter.java +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/ConfiguredMavenImporter.java @@ -16,12 +16,19 @@ */ package org.jboss.shrinkwrap.resolver.api.maven.archive.importer; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ConfiguredArchiveMavenAssembler; + /** * Instance of {@link MavenImporter} that has configuration from a settings.xml file loaded + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API and {@link ConfiguredArchiveMavenAssembler} instead + *

* * @author Karel Piwko * */ +@Deprecated public interface ConfiguredMavenImporter extends PomlessMavenImporter { } diff --git a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/MavenImporter.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/MavenImporter.java index 56a5b32b3..51e2b0a49 100644 --- a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/MavenImporter.java +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/MavenImporter.java @@ -21,17 +21,25 @@ import org.jboss.shrinkwrap.api.Assignable; import org.jboss.shrinkwrap.resolver.api.ConfigurableResolverSystem; import org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; /** * MavenImporter is an abstraction of Maven Package phase for ShrinkWrap. It allows to package an archive based on pom.xml file. + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @author Karel Piwko * */ +@Deprecated public interface MavenImporter extends PomlessMavenImporter, Assignable { /** * Optional operation. Configures this {@link MavenImporter} from the specified settings.xml file + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param file A settings.xml {@link File} this {@link MavenImporter} should be configured from. * @return This configured {@link MavenImporter} @@ -40,12 +48,16 @@ public interface MavenImporter extends PomlessMavenImporter, Assignable { * @throws UnsupportedOperationException If this {@link ConfigurableResolverSystem} does not support configuration by * {@link File} */ + @Deprecated ConfiguredMavenImporter configureFromFile(File file) throws IllegalArgumentException, UnsupportedOperationException, InvalidConfigurationFileException; /** * Optional operation. Configures this {@link MavenImporter} from the specified settings.xml file at the specified * path + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param pathToFile A path to a settings.xml file this {@link MavenImporter} should be configured from. * @return This configured {@link MavenImporter} @@ -55,12 +67,16 @@ ConfiguredMavenImporter configureFromFile(File file) throws IllegalArgumentExcep * {@link File} * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format */ + @Deprecated ConfiguredMavenImporter configureFromFile(String pathToFile) throws IllegalArgumentException, UnsupportedOperationException, InvalidConfigurationFileException; /** * Optional operation. Configures this {@link MavenImporter} from the result of * {@link ClassLoader#getResource(String)} call using the current {@link Thread#getContextClassLoader()} + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param path A {@link ClassLoader} path to a settings.xml file this {@link MavenImporter} should be configured from. * @return This configured {@link MavenImporter} @@ -69,12 +85,16 @@ ConfiguredMavenImporter configureFromFile(String pathToFile) throws IllegalArgum * {@link ClassLoader} resource * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format */ + @Deprecated ConfiguredMavenImporter configureFromClassloaderResource(String path) throws IllegalArgumentException, UnsupportedOperationException, InvalidConfigurationFileException; /** * Optional operation. Configures this {@link ConfigurableResolverSystem} from the result of * {@link ClassLoader#getResource(String)} using the specified {@link ClassLoader} + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param path A {@link ClassLoader} path to a settings.xml file this {@link MavenImporter} should be configured from. * @param cl A {@link ClassLoader} @@ -84,6 +104,7 @@ ConfiguredMavenImporter configureFromClassloaderResource(String path) throws Ill * {@link ClassLoader} resource * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format */ + @Deprecated ConfiguredMavenImporter configureFromClassloaderResource(String path, ClassLoader cl) throws IllegalArgumentException, UnsupportedOperationException, InvalidConfigurationFileException; diff --git a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/MavenImporterException.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/MavenImporterException.java index 89ccc0f39..93b8f238e 100644 --- a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/MavenImporterException.java +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/MavenImporterException.java @@ -16,13 +16,20 @@ */ package org.jboss.shrinkwrap.resolver.api.maven.archive.importer; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssemblerException; + /** * Exception which in raised if importing a Maven project is not successful. + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API and {@link ArchiveMavenAssemblerException} instead + *

* * @author Karel Piwko * */ -public class MavenImporterException extends RuntimeException { +@Deprecated +public class MavenImporterException extends ArchiveMavenAssemblerException { /** * diff --git a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/PomEquippedMavenImporter.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/PomEquippedMavenImporter.java index 54c8e790f..e7f7fad04 100644 --- a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/PomEquippedMavenImporter.java +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/PomEquippedMavenImporter.java @@ -18,34 +18,48 @@ import org.jboss.shrinkwrap.api.Assignable; import org.jboss.shrinkwrap.resolver.api.maven.ScopeType; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; import org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.PomlessArchiveMavenAssembler; /** * Instance of {@link MavenImporter} that has configuration from a POM file loaded + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API and {@link PomlessArchiveMavenAssembler} instead + *

* * @author Karel Piwko * */ +@Deprecated public interface PomEquippedMavenImporter extends Assignable { /** * Build an archive based on metadata previously loaded from a Project Object Model file. Packages following scopes: * {@link ScopeType#COMPILE}, {@link ScopeType#IMPORT}, {@link ScopeType#RUNTIME}, {@link ScopeType#SYSTEM} + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @return This modified {@link MavenImporter} instance with a built archive based on metadata previously loaded * from a Project Object Model file. */ + @Deprecated PomEquippedMavenImporter importBuildOutput(); /** * Build an archive based on metadata previously loaded from a Project Object Model file. Uses passed strategy to define * dependencies to be packaged into the archive. + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param strategy The strategy defining objects to be packaged * @return This modified {@link MavenImporter} instance with a built archive based on metadata previously loaded * from a Project Object Model file. * @throws IllegalArgumentException If no strategy is specified */ + @Deprecated PomEquippedMavenImporter importBuildOutput(MavenResolutionStrategy strategy) throws IllegalArgumentException; } diff --git a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/PomlessMavenImporter.java b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/PomlessMavenImporter.java index 2d6d5882d..12d8aa815 100644 --- a/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/PomlessMavenImporter.java +++ b/maven/api-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/archive/importer/PomlessMavenImporter.java @@ -19,27 +19,40 @@ import java.io.File; import org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.PomlessArchiveMavenAssembler; /** * Instance of {@link MavenImporter} that allows to load configuration from a POM file + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API and {@link PomlessArchiveMavenAssembler} instead + *

* * @author Karel Piwko * */ +@Deprecated public interface PomlessMavenImporter { /** * Configures the Maven Importer from Project Object Model contained in the specified POM {@link File}. + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param pomFile A POM {@link File} the maven Importer should be configured from. * @return The configured Maven Importer from the given Project Object Model. * @throws IllegalArgumentException If no file was specified, if the file does not exist or points to a directory * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format */ + @Deprecated PomEquippedMavenImporter loadPomFromFile(File pomFile) throws IllegalArgumentException, InvalidConfigurationFileException; /** * Configures the Maven Importer from Project Object Model contained in the specified POM {@link File}. + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param pomFile A POM {@link File} the maven Importer should be configured from. * @param profiles Active/inactive profiles @@ -47,12 +60,16 @@ public interface PomlessMavenImporter { * @throws IllegalArgumentException If no file was specified, if the file does not exist or points to a directory * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format */ + @Deprecated PomEquippedMavenImporter loadPomFromFile(File pomFile, String... profiles) throws IllegalArgumentException, InvalidConfigurationFileException; /** * Configures the Maven Importer from Project Object Model contained in the POM file located at the specified path. The path * will be represented as a new {@link File} by means of {@link File#File(String)} + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param pathToPomFile A path to a POM file the maven Importer should be configured from. * @return The configured Maven Importer from the given Project Object Model. @@ -60,12 +77,16 @@ PomEquippedMavenImporter loadPomFromFile(File pomFile, String... profiles) throw * directory * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format */ + @Deprecated PomEquippedMavenImporter loadPomFromFile(String pathToPomFile) throws IllegalArgumentException, InvalidConfigurationFileException; /** * Configures the Maven Importer from Project Object Model contained in the POM file located at the specified path. The path * will be represented as a new {@link File} by means of {@link File#File(String)} + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param pathToPomFile A path to a POM file the maven Importer should be configured from. * @param profiles Active/inactive profiles @@ -74,24 +95,32 @@ PomEquippedMavenImporter loadPomFromFile(String pathToPomFile) throws IllegalArg * directory * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format */ + @Deprecated PomEquippedMavenImporter loadPomFromFile(String pathToPomFile, String... profiles) throws IllegalArgumentException, InvalidConfigurationFileException; /** * Configures the Maven Importer from Project Object Model contained in the POM file located at the specified * {@link ClassLoader} resource path, loaded by the current {@link Thread#getContextClassLoader()}. + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param pathToPomResource A {@link ClassLoader} resource path to a POM filee the maven Importer should be configured from. * @return The configured Maven Importer from the given Project Object Model. * @throws IllegalArgumentException If no path was specified, or if the resource could not be found at the specified path * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format */ + @Deprecated PomEquippedMavenImporter loadPomFromClassLoaderResource(String pathToPomResource) throws IllegalArgumentException, InvalidConfigurationFileException; /** * Configures the Maven Importer from Project Object Model contained in the POM file located at the specified * {@link ClassLoader} resource path, loaded by the specified {@link ClassLoader}. + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param pathToPomResource A {@link ClassLoader} resource path to a POM filee the maven Importer should be configured from. * @param cl A {@link ClassLoader} @@ -100,12 +129,16 @@ PomEquippedMavenImporter loadPomFromClassLoaderResource(String pathToPomResource * found at the specified path * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format */ + @Deprecated PomEquippedMavenImporter loadPomFromClassLoaderResource(String pathToPomResource, ClassLoader cl) throws IllegalArgumentException, InvalidConfigurationFileException; /** * Configures the Maven Importer from Project Object Model contained in the POM file located at the specified * {@link ClassLoader} resource path, loaded by the specified {@link ClassLoader}. + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param pathToPomResource A {@link ClassLoader} resource path to a POM filee the maven Importer should be configured from. * @param cl A {@link ClassLoader} @@ -115,24 +148,33 @@ PomEquippedMavenImporter loadPomFromClassLoaderResource(String pathToPomResource * invalid or null, or if the resource could not be found at the specified path * @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format */ + @Deprecated PomEquippedMavenImporter loadPomFromClassLoaderResource(String pathToPomResource, ClassLoader cl, String... profiles) throws IllegalArgumentException, InvalidConfigurationFileException; /** * Optional operation. Sets whether resolution should be done in "offline" (ie. not connected to Internet) mode. * By default, resolution is done in online mode + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @param offline Whether resolution should be done in "offline". By default, resolution is done in online mode. * * @return Modified {@link PomlessMavenImporter} instance */ + @Deprecated PomlessMavenImporter offline(boolean offline); /** * Optional operation. Sets that resolution should be done in "offline" (ie. not connected to Internet) mode. Alias to * {@link ConfiguredMavenImporter#offline(boolean)}, passing true as a parameter. + *

+ * This API is deprecated, please use {@link ArchiveMavenAssembler} API instead + *

* * @return Modified {@link PomlessMavenImporter} instance */ + @Deprecated PomlessMavenImporter offline(); } diff --git a/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/filter/AcceptDependenciesFilter.java b/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/filter/AcceptDependenciesFilter.java new file mode 100644 index 000000000..0d5bf10a3 --- /dev/null +++ b/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/filter/AcceptDependenciesFilter.java @@ -0,0 +1,71 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.api.maven.filter; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.jboss.shrinkwrap.resolver.api.CoordinateParseException; +import org.jboss.shrinkwrap.resolver.api.maven.ScopeType; +import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate; +import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinates; +import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependencies; +import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency; + +/** + * A {@link MavenResolutionFilter} which will accept only the specified dependencies + * + * @author Karel Piwko + * @author Andrew Lee Rubinger + */ +public class AcceptDependenciesFilter implements MavenResolutionFilter { + + private final Set acceptDependencies; + + + public AcceptDependenciesFilter(final String... coordinates) + throws IllegalArgumentException, + CoordinateParseException { + if (coordinates == null || coordinates.length == 0) { + throw new IllegalArgumentException("There must be at least one coordinate specified."); + } + + final Set acceptDependencies = new HashSet(coordinates.length); + for (final String coords : coordinates) { + final MavenCoordinate coordinate = MavenCoordinates.createCoordinate(coords); + final MavenDependency dependency = MavenDependencies.createDependency(coordinate, ScopeType.COMPILE, false); + acceptDependencies.add(dependency); + } + this.acceptDependencies = Collections.unmodifiableSet(acceptDependencies); + + } + + /** + * {@inheritDoc} + * + * @see MavenResolutionFilter#accepts(MavenDependency, + * List, List) + */ + @Override + public boolean accepts(final MavenDependency dependency, final List dependenciesForResolution, + final List dependencyAncestors) { + return acceptDependencies.contains(dependency); + } + +} diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ArchiveMavenAssemblerImpl.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ArchiveMavenAssemblerImpl.java new file mode 100644 index 000000000..2faaad0f3 --- /dev/null +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ArchiveMavenAssemblerImpl.java @@ -0,0 +1,186 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler; + +import java.io.File; + +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.Assignable; +import org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException; +import org.jboss.shrinkwrap.resolver.api.Resolvers; +import org.jboss.shrinkwrap.resolver.api.maven.MavenResolverSystem; +import org.jboss.shrinkwrap.resolver.api.maven.MavenWorkingSession; +import org.jboss.shrinkwrap.resolver.api.maven.PackagingType; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ConfiguredArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.PomEquippedArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.PomlessArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.impl.maven.MavenWorkingSessionImpl; +import org.jboss.shrinkwrap.resolver.impl.maven.task.ConfigureSettingsFromFileTask; +import org.jboss.shrinkwrap.resolver.impl.maven.task.InferPackagingTypeTask; +import org.jboss.shrinkwrap.resolver.impl.maven.task.LoadPomDependenciesTask; +import org.jboss.shrinkwrap.resolver.impl.maven.task.LoadPomTask; +import org.jboss.shrinkwrap.resolver.impl.maven.util.FileUtil; +import org.jboss.shrinkwrap.resolver.impl.maven.util.Validate; +import org.jboss.shrinkwrap.resolver.spi.maven.archive.packaging.PackagingProcessor; +import org.jboss.shrinkwrap.resolver.spi.maven.archive.packaging.PackagingProcessors; + +/** + * @author Matous Jobanek + */ +public class ArchiveMavenAssemblerImpl implements ArchiveMavenAssembler, ConfiguredArchiveMavenAssembler { + + private MavenWorkingSession session; + private Archive archive; + private boolean useDefaultBuildDirectory = false; + + public ArchiveMavenAssemblerImpl(Archive archive) { + // this is needed to boostrap session + Resolvers.use(MavenResolverSystem.class); + this.session = new MavenWorkingSessionImpl(); + this.archive = archive; + } + + @Override + public TYPE as(Class type) { + throw new UnsupportedOperationException( + "There were no data added yet. Please load a pom file first using any of the usingPom*() methods."); + } + + @Override + public ConfiguredArchiveMavenAssembler configuredFromClassloaderResource(String path) throws IllegalArgumentException, + UnsupportedOperationException, InvalidConfigurationFileException { + + return this.configuredFromClassloaderResource(path, SecurityActions.getThreadContextClassLoader()); + } + + @Override + public ConfiguredArchiveMavenAssembler configuredFrom(File file) throws IllegalArgumentException, UnsupportedOperationException, + InvalidConfigurationFileException { + + Validate.notNull(file, "settings file must be specified"); + Validate.readable(file, "settings file is not readable: " + file.getAbsolutePath()); + new ConfigureSettingsFromFileTask(file).execute(session); + return this; + } + + @Override + public ConfiguredArchiveMavenAssembler configuredFrom(String pathToFile) throws IllegalArgumentException, + UnsupportedOperationException, InvalidConfigurationFileException { + + Validate.isNullOrEmpty(pathToFile); + new ConfigureSettingsFromFileTask(pathToFile).execute(session); + return this; + } + + @Override + public ConfiguredArchiveMavenAssembler configuredFromClassloaderResource(String path, ClassLoader cl) + throws IllegalArgumentException, UnsupportedOperationException, InvalidConfigurationFileException { + + Validate.isNullOrEmpty(path); + Validate.notNull(cl, "ClassLoader is required"); + final File file = FileUtil.INSTANCE.fileFromClassLoaderResource(path, cl); + return this.configuredFrom(file); + } + + @Override + public PomEquippedArchiveMavenAssembler usingPom(File pomFile) throws IllegalArgumentException, + InvalidConfigurationFileException { + + this.session = LoadPomTask.loadPomFromFile(pomFile).execute(session); + return usingPom(); + } + + @Override + public PomEquippedArchiveMavenAssembler usingPom(File pomFile, String... profiles) throws IllegalArgumentException, + InvalidConfigurationFileException { + + this.session = LoadPomTask.loadPomFromFile(pomFile, profiles).execute(session); + return usingPom(); + } + + @Override + public PomEquippedArchiveMavenAssembler usingPom(String pathToPomFile) throws IllegalArgumentException, + InvalidConfigurationFileException { + + return usingPom(new File(pathToPomFile)); + + } + + @Override + public PomEquippedArchiveMavenAssembler usingPom(String pathToPomFile, String... profiles) throws IllegalArgumentException, + InvalidConfigurationFileException { + + return usingPom(new File(pathToPomFile), profiles); + } + + @Override + public PomEquippedArchiveMavenAssembler usingPomFromClassLoaderResource(String pathToPomResource) throws IllegalArgumentException, + InvalidConfigurationFileException { + + this.session = LoadPomTask.loadPomFromClassLoaderResource(pathToPomResource).execute(session); + return usingPom(); + } + + @Override + public PomEquippedArchiveMavenAssembler usingPomFromClassLoaderResource(String pathToPomResource, ClassLoader cl) + throws IllegalArgumentException, InvalidConfigurationFileException { + + this.session = LoadPomTask.loadPomFromClassLoaderResource(pathToPomResource, cl).execute(session); + return usingPom(); + } + + @Override + public PomEquippedArchiveMavenAssembler usingPomFromClassLoaderResource(String pathToPomResource, ClassLoader cl, String... profiles) + throws IllegalArgumentException, InvalidConfigurationFileException { + + this.session = LoadPomTask.loadPomFromClassLoaderResource(pathToPomResource, cl, profiles).execute(session); + return usingPom(); + } + + private PomEquippedArchiveMavenAssembler usingPom() throws IllegalArgumentException, + InvalidConfigurationFileException { + + this.session = LoadPomDependenciesTask.INSTANCE.execute(session); + PackagingType packagingType = InferPackagingTypeTask.INSTANCE.execute(session); + PackagingProcessor> processor = PackagingProcessors.find(packagingType); + processor.configure(archive, session, useDefaultBuildDirectory); + return new PomEquippedArchiveMavenAssemblerImpl(processor); + } + + @Override public PomlessArchiveMavenAssembler usingDefaultBuildDirectory(boolean useDefaultBuildDirectory) { + this.useDefaultBuildDirectory = useDefaultBuildDirectory; + return this; + } + + @Override public PomlessArchiveMavenAssembler usingDefaultBuildDirectory() { + this.useDefaultBuildDirectory = true; + return this; + } + + @Override + public PomlessArchiveMavenAssembler usingOfflineMode(boolean useOfflineMode) { + session.setOffline(useOfflineMode); + return this; + } + + @Override + public PomlessArchiveMavenAssembler usingOfflineMode() { + return this.usingOfflineMode(true); + } + +} diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/PomEquippedArchiveMavenAssemblerImpl.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/PomEquippedArchiveMavenAssemblerImpl.java new file mode 100644 index 000000000..4fcba2742 --- /dev/null +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/PomEquippedArchiveMavenAssemblerImpl.java @@ -0,0 +1,87 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler; + +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.Assignable; +import org.jboss.shrinkwrap.resolver.api.maven.ScopeType; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.PomEquippedArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.api.maven.filter.AcceptAllFilter; +import org.jboss.shrinkwrap.resolver.api.maven.filter.MavenResolutionFilter; +import org.jboss.shrinkwrap.resolver.spi.maven.archive.packaging.PackagingProcessor; + +/** + * @author Matous Jobanek + */ +public class PomEquippedArchiveMavenAssemblerImpl implements PomEquippedArchiveMavenAssembler { + + private final PackagingProcessor> processor; + + + public PomEquippedArchiveMavenAssemblerImpl(PackagingProcessor> processor) { + this.processor = processor; + } + + @Override + public PomEquippedArchiveMavenAssembler withBuildOutput() { + return withBuildOutput(ScopeType.values()); + } + + @Override public PomEquippedArchiveMavenAssembler withBuildOutput(ScopeType... scopes) { + processor.addBuildOutput(scopes); + return this; + } + + @Override public PomEquippedArchiveMavenAssembler withTestBuildOutput() { + return withTestBuildOutput(ScopeType.values()); + } + + @Override public PomEquippedArchiveMavenAssembler withTestBuildOutput(ScopeType... scopes) { + processor.addTestOutput(scopes); + return this; + } + + @Override + public PomEquippedArchiveMavenAssembler withDependencies(MavenResolutionFilter filter, ScopeType... scopes) + throws IllegalArgumentException { + processor.addDependencies(filter, scopes.length == 0 ? ScopeType.values() : scopes); + return this; + } + + @Override public PomEquippedArchiveMavenAssembler withDependencies(MavenResolutionFilter filter) { + return withDependencies(filter, ScopeType.values()); + } + + @Override public PomEquippedArchiveMavenAssembler withDependencies() throws IllegalArgumentException { + return withDependencies(ScopeType.values()); + } + + @Override + public PomEquippedArchiveMavenAssembler withDependencies(ScopeType... scopes) throws IllegalArgumentException { + return withDependencies(AcceptAllFilter.INSTANCE, scopes); + } + + @Override + public TYPE as(Class type) { + return processor.getResultingArchive().as(type); + } + + @Override public TYPE as(Class type, String name) { + return processor.getResultingArchive(name).as(type); + } + +} diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/SecurityActions.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/SecurityActions.java new file mode 100644 index 000000000..0e1648047 --- /dev/null +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/SecurityActions.java @@ -0,0 +1,164 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler; + +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.Properties; + +import org.jboss.shrinkwrap.resolver.impl.maven.GetTcclAction; + +/** + * SecurityActions + * + * A set of privileged actions that are not to leak out of this package + * + * + * @author ALR + * @author Karel Piwko + */ +final class SecurityActions { + + // -------------------------------------------------------------------------------|| + // Constructor -------------------------------------------------------------------|| + // -------------------------------------------------------------------------------|| + + /** + * No instantiation + */ + private SecurityActions() { + throw new UnsupportedOperationException("No instantiation"); + } + + // -------------------------------------------------------------------------------|| + // Utility Methods ---------------------------------------------------------------|| + // -------------------------------------------------------------------------------|| + + /** + * Obtains the Thread Context ClassLoader + */ + static ClassLoader getThreadContextClassLoader() { + return AccessController.doPrivileged(GetTcclAction.INSTANCE); + } + + static String getProperty(final String key) { + try { + String value = AccessController.doPrivileged(new PrivilegedExceptionAction() { + @Override + public String run() { + return System.getProperty(key); + } + }); + return value; + } + // Unwrap + catch (final PrivilegedActionException pae) { + final Throwable t = pae.getCause(); + // Rethrow + if (t instanceof SecurityException) { + throw (SecurityException) t; + } + if (t instanceof NullPointerException) { + throw (NullPointerException) t; + } else if (t instanceof IllegalArgumentException) { + throw (IllegalArgumentException) t; + } else { + // No other checked Exception thrown by System.getProperty + try { + throw (RuntimeException) t; + } + // Just in case we've really messed up + catch (final ClassCastException cce) { + throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t); + } + } + } + } + + static Properties getProperties() { + try { + return AccessController.doPrivileged(new PrivilegedExceptionAction() { + @Override + public Properties run() { + return System.getProperties(); + } + }); + } + // Unwrap + catch (final PrivilegedActionException pae) { + final Throwable t = pae.getCause(); + // Rethrow + if (t instanceof SecurityException) { + throw (SecurityException) t; + } + if (t instanceof NullPointerException) { + throw (NullPointerException) t; + } else if (t instanceof IllegalArgumentException) { + throw (IllegalArgumentException) t; + } else { + // No other checked Exception thrown by System.getProperty + try { + throw (RuntimeException) t; + } + // Just in case we've really messed up + catch (final ClassCastException cce) { + throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t); + } + } + } + } + + static URL getResource(final String resource) { + // AccessController.doPrivileged(SecurityActions.GetTcclAction.INSTANCE).getResource(resourceName); + + try { + URL value = AccessController.doPrivileged(new PrivilegedExceptionAction() { + @Override + public URL run() throws Exception { + return getThreadContextClassLoader().getResource(resource); + } + + }); + + return value; + } + // Unwrap + catch (final PrivilegedActionException pae) { + final Throwable t = pae.getCause(); + // Rethrow + if (t instanceof SecurityException) { + throw (SecurityException) t; + } + if (t instanceof NullPointerException) { + throw (NullPointerException) t; + } else if (t instanceof IllegalArgumentException) { + throw (IllegalArgumentException) t; + } else { + // No other checked Exception thrown by System.getProperty + try { + throw (RuntimeException) t; + } + // Just in case we've really messed up + catch (final ClassCastException cce) { + throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t); + } + } + } + } +} diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/MavenImporterImpl.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/MavenImporterImpl.java index ca0b15461..7e8f5f805 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/MavenImporterImpl.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/MavenImporterImpl.java @@ -100,7 +100,7 @@ public PomEquippedMavenImporter loadPomFromFile(File pomFile) throws IllegalArgu this.session = LoadPomDependenciesTask.INSTANCE.execute(session); PackagingType packagingType = InferPackagingTypeTask.INSTANCE.execute(session); PackagingProcessor> processor = PackagingProcessors.find(packagingType); - processor.configure(archive, session); + processor.configure(archive, session, true); return new PomEquippedMavenImporterImpl(processor); } @@ -111,7 +111,7 @@ public PomEquippedMavenImporter loadPomFromFile(File pomFile, String... profiles this.session = LoadPomDependenciesTask.INSTANCE.execute(session); PackagingType packagingType = InferPackagingTypeTask.INSTANCE.execute(session); PackagingProcessor> processor = PackagingProcessors.find(packagingType); - processor.configure(archive, session); + processor.configure(archive, session, true); return new PomEquippedMavenImporterImpl(processor); } @@ -123,7 +123,7 @@ public PomEquippedMavenImporter loadPomFromFile(String pathToPomFile) throws Ill this.session = LoadPomDependenciesTask.INSTANCE.execute(session); PackagingType packagingType = InferPackagingTypeTask.INSTANCE.execute(session); PackagingProcessor> processor = PackagingProcessors.find(packagingType); - processor.configure(archive, session); + processor.configure(archive, session, true); return new PomEquippedMavenImporterImpl(processor); } @@ -135,7 +135,7 @@ public PomEquippedMavenImporter loadPomFromFile(String pathToPomFile, String... this.session = LoadPomDependenciesTask.INSTANCE.execute(session); PackagingType packagingType = InferPackagingTypeTask.INSTANCE.execute(session); PackagingProcessor> processor = PackagingProcessors.find(packagingType); - processor.configure(archive, session); + processor.configure(archive, session, true); return new PomEquippedMavenImporterImpl(processor); } @@ -146,7 +146,7 @@ public PomEquippedMavenImporter loadPomFromClassLoaderResource(String pathToPomR this.session = LoadPomDependenciesTask.INSTANCE.execute(session); PackagingType packagingType = InferPackagingTypeTask.INSTANCE.execute(session); PackagingProcessor> processor = PackagingProcessors.find(packagingType); - processor.configure(archive, session); + processor.configure(archive, session, true); return new PomEquippedMavenImporterImpl(processor); } @@ -157,7 +157,7 @@ public PomEquippedMavenImporter loadPomFromClassLoaderResource(String pathToPomR this.session = LoadPomDependenciesTask.INSTANCE.execute(session); PackagingType packagingType = InferPackagingTypeTask.INSTANCE.execute(session); PackagingProcessor> processor = PackagingProcessors.find(packagingType); - processor.configure(archive, session); + processor.configure(archive, session, true); return new PomEquippedMavenImporterImpl(processor); } @@ -168,13 +168,13 @@ public PomEquippedMavenImporter loadPomFromClassLoaderResource(String pathToPomR this.session = LoadPomDependenciesTask.INSTANCE.execute(session); PackagingType packagingType = InferPackagingTypeTask.INSTANCE.execute(session); PackagingProcessor> processor = PackagingProcessors.find(packagingType); - processor.configure(archive, session); + processor.configure(archive, session, true); return new PomEquippedMavenImporterImpl(processor); } @Override public PomlessMavenImporter offline(boolean offline) { - session.setOffline(true); + session.setOffline(offline); return this; } diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/AbstractCompilingProcessor.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/AbstractCompilingProcessor.java index 56f09142d..23aea7a88 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/AbstractCompilingProcessor.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/AbstractCompilingProcessor.java @@ -17,7 +17,11 @@ package org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging; import java.io.File; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -31,7 +35,8 @@ import org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact; import org.jboss.shrinkwrap.resolver.api.maven.MavenWorkingSession; import org.jboss.shrinkwrap.resolver.api.maven.ScopeType; -import org.jboss.shrinkwrap.resolver.api.maven.archive.importer.MavenImporterException; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssemblerException; +import org.jboss.shrinkwrap.resolver.api.maven.pom.ParsedPomFile; import org.jboss.shrinkwrap.resolver.api.maven.strategy.AcceptScopesStrategy; import org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy; import org.jboss.shrinkwrap.resolver.impl.maven.archive.plugins.CompilerPluginConfiguration; @@ -42,6 +47,7 @@ /** * Packaging processor which is able to compile Java sources * + * @author Matous Jobanek * @author Karel Piwko * * @param Type of the archive produced @@ -54,9 +60,14 @@ public abstract class AbstractCompilingProcessor> resolvedScopesCache = new HashMap>(); + private boolean useDefaultBuildDirectory; - protected PackagingProcessor configure(MavenWorkingSession session) { + protected PackagingProcessor configure(MavenWorkingSession session, boolean useDefaultBuildDirectory) { this.session = session; + this.pomFile = session.getParsedPomFile(); + this.useDefaultBuildDirectory = useDefaultBuildDirectory; return this; } @@ -77,9 +88,8 @@ protected AbstractCompilingProcessor compile(File inputDirectory, F // in order to compile sources, we need to resolve dependencies first // so we have a classpath available new AddScopedDependenciesTask(ScopeType.values()).execute(session); - final MavenResolutionStrategy scopeStrategy = new AcceptScopesStrategy(scopes); - final Collection artifactResults = session.resolveDependencies(scopeStrategy); + Collection artifactResults = resolveArtifacts(scopes); for (MavenResolvedArtifact artifact : artifactResults) { String classpathEntry = artifact.asFile().getAbsolutePath(); configuration.addClasspathEntry(classpathEntry); @@ -96,7 +106,7 @@ protected AbstractCompilingProcessor compile(File inputDirectory, F // try to fork compilation process if it wasn't set to fork already if (!configuration.isFork()) { log.log(Level.WARNING, - "MavenImporter was not able to identify javac compiler, probably JAVA_HOME points to JRE instead of JDK. MavenImporter will try to fork and use javac from $PATH"); + "ArchiveMavenAssembler was not able to identify javac compiler, probably JAVA_HOME points to JRE instead of JDK. ArchiveMavenAssembler will try to fork and use javac from $PATH"); configuration.setFork(true); CompilerResult result2 = compiler.performCompile(configuration); if (!result2.isSuccess()) { @@ -113,12 +123,26 @@ protected AbstractCompilingProcessor compile(File inputDirectory, F } catch (CompilerException e) { log.log(Level.SEVERE, "Compilation failed with {0}", e.getMessage()); - throw new MavenImporterException("Unable to compile source at " + inputDirectory.getPath() + " due to: ", e); + throw new ArchiveMavenAssemblerException("Unable to compile source at " + inputDirectory.getPath() + " due to: ", e); } return this; } + protected Collection resolveArtifacts(ScopeType... scopes){ + Collection artifactResults = new ArrayList(); + for (ScopeType scope : scopes) { + if (!resolvedScopesCache.containsKey(scope)){ + new AddScopedDependenciesTask(scope).execute(session); + final MavenResolutionStrategy scopeStrategy = new AcceptScopesStrategy(scope); + Collection resolvedArtifacts = session.resolveDependencies(scopeStrategy); + resolvedScopesCache.put(scope, resolvedArtifacts); + } + artifactResults.addAll(resolvedScopesCache.get(scope)); + } + return artifactResults; + } + private CompilerConfiguration getCompilerConfiguration() { CompilerPluginConfiguration pluginConfiguration = new CompilerPluginConfiguration(session.getParsedPomFile()); return pluginConfiguration.asCompilerConfiguration(); @@ -129,7 +153,7 @@ protected static boolean hasGeneratedName(Archive archive) { return archiveName != null && UUID4_PATTERN.matcher(archiveName.toLowerCase()).matches(); } - private static MavenImporterException constructCompilationException(CompilerResult result, File sourceDirectory) { + private static ArchiveMavenAssemblerException constructCompilationException(CompilerResult result, File sourceDirectory) { StringBuilder sb = new StringBuilder("Unable to compile sources at "); sb.append(sourceDirectory.getPath()); sb.append(" due to following reason(s): "); @@ -142,7 +166,15 @@ private static MavenImporterException constructCompilationException(CompilerResu log.log(Level.SEVERE, sb.toString()); - return new MavenImporterException(sb.toString()); + return new ArchiveMavenAssemblerException(sb.toString()); + } + + protected File getBuildDir(){ + StringBuffer pathToBuildDir = new StringBuffer(pomFile.getBuildOutputDirectory().getAbsolutePath()); + if (useDefaultBuildDirectory){ + pathToBuildDir.append("/resolver-" + UUID.randomUUID()); + } + return new File(pathToBuildDir.toString()); } } diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ArchiveFilteringUtils.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ArchiveFilteringUtils.java index acc10c3a0..3a96e2d75 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ArchiveFilteringUtils.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ArchiveFilteringUtils.java @@ -30,17 +30,18 @@ /** * Utils related to filtering of archive content * + * @author Matous Jobanek * @author Karel Piwko * */ public class ArchiveFilteringUtils { - public static > T filterArchiveContent(T archive, Class archiveType, final String[] includes, + public static > T filterArchiveContent(T archive, Class archiveType, String archiveName, final String[] includes, final String[] excludes) { - return filterArchiveContent(archive, archiveType, Arrays.asList(includes), Arrays.asList(excludes)); + return filterArchiveContent(archive, archiveType, archiveName, Arrays.asList(includes), Arrays.asList(excludes)); } - public static > T filterArchiveContent(T archive, Class archiveType, final List includes, + public static > T filterArchiveContent(T archive, Class archiveType, String archiveName, final List includes, final List excludes) { // get all files that should be included in archive @@ -73,7 +74,7 @@ public boolean include(ArchivePath path) { }); // create new archive and merge content together - T newArchive = ShrinkWrap.create(archiveType, archive.getName()); + T newArchive = ShrinkWrap.create(archiveType, archiveName); for (Map.Entry entry : includePart.entrySet()) { if (entry.getValue() != null && entry.getValue().getAsset() != null) { diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/JarPackagingProcessor.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/JarPackagingProcessor.java index c3d86ac08..e26c89157 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/JarPackagingProcessor.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/JarPackagingProcessor.java @@ -16,30 +16,38 @@ */ package org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging; +import java.io.File; +import java.util.Collection; +import java.util.List; import java.util.jar.Manifest; import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.Assignable; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.importer.ExplodedImporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.resolver.api.ResolutionException; +import org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact; import org.jboss.shrinkwrap.resolver.api.maven.MavenWorkingSession; import org.jboss.shrinkwrap.resolver.api.maven.PackagingType; import org.jboss.shrinkwrap.resolver.api.maven.ScopeType; +import org.jboss.shrinkwrap.resolver.api.maven.filter.MavenResolutionFilter; import org.jboss.shrinkwrap.resolver.api.maven.pom.ParsedPomFile; import org.jboss.shrinkwrap.resolver.api.maven.pom.Resource; import org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy; import org.jboss.shrinkwrap.resolver.impl.maven.archive.plugins.JarPluginConfiguration; +import org.jboss.shrinkwrap.resolver.impl.maven.convert.MavenConverter; import org.jboss.shrinkwrap.resolver.impl.maven.util.Validate; import org.jboss.shrinkwrap.resolver.spi.maven.archive.packaging.PackagingProcessor; /** * Packaging processor for Maven projects of JAR packaging type * + * @author Matous Jobanek * @author Karel Piwko - * */ -public class JarPackagingProcessor extends AbstractCompilingProcessor implements PackagingProcessor { +public class JarPackagingProcessor extends AbstractCompilingProcessor + implements PackagingProcessor { public static final String MAVEN_WAR_PLUGIN_KEY = "org.apache.maven.plugins:maven-jar-plugin"; @@ -51,17 +59,72 @@ public boolean handles(PackagingType packagingType) { } @Override - public JarPackagingProcessor configure(Archive archive, MavenWorkingSession session) { - super.configure(session); + public JarPackagingProcessor configure(Archive archive, MavenWorkingSession session, + boolean useDefaultBuildDirectory) { + super.configure(session, useDefaultBuildDirectory); // archive is ignored, just name is propagated String archiveName = hasGeneratedName(archive) ? session.getParsedPomFile().getFinalName() : archive.getName(); // archive is ignored so far - this.archive = ShrinkWrap.create(JavaArchive.class, archiveName); + this.archive = ShrinkWrap.create(JavaArchive.class, archiveName).merge(archive); + + return this; + } + + @Override public PackagingProcessor addBuildOutput(ScopeType[] scopes) + throws IllegalArgumentException, ResolutionException { + + // add source filed if any + addCompiledClassesFromDirectory(pomFile.getSourceDirectory(), scopes); + // add resources + addResources(pomFile.getResources()); + + return this; + } + + @Override public PackagingProcessor addTestOutput(ScopeType[] scopes) + throws IllegalArgumentException, ResolutionException { + + addCompiledClassesFromDirectory(pomFile.getTestSourceDirectory(), scopes); + addResources(pomFile.getTestResources()); + return this; } + @Override + public JarPackagingProcessor addDependencies(MavenResolutionFilter filter, ScopeType... scopes) + throws ResolutionException, + IllegalArgumentException, UnsupportedOperationException { + + Collection resolvedArtifacts = resolveArtifacts(scopes); + for (MavenResolvedArtifact artifact : resolvedArtifacts) { + if (filter.accepts(MavenConverter.fromResolvedArtifact(artifact), null, null)) { + archive = archive.merge(artifact.as(JavaArchive.class)); + } + } + return this; + } + + private void addResources(List resources) { + for (Resource resource : resources) { + archive.addAsResource(resource.getSource(), resource.getTargetPath()); + } + } + + private void addCompiledClassesFromDirectory(File sourceDirectory, ScopeType... scopes) { + if (Validate.isReadable(sourceDirectory)) { + + File buildDir = getBuildDir(); + compile(sourceDirectory, buildDir, scopes); + + JavaArchive classes = ShrinkWrap.create(ExplodedImporter.class, "sources.jar") + .importDirectory(buildDir).as(JavaArchive.class); + + archive = archive.merge(classes); + } + } + @Override public JarPackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) throws ResolutionException, IllegalArgumentException, UnsupportedOperationException { @@ -70,8 +133,9 @@ public JarPackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) // add source filed if any if (Validate.isReadable(pomFile.getSourceDirectory())) { - compile(pomFile.getSourceDirectory(), pomFile.getBuildOutputDirectory(), ScopeType.COMPILE, ScopeType.IMPORT, - ScopeType.PROVIDED, ScopeType.RUNTIME, ScopeType.SYSTEM); + compile(pomFile.getSourceDirectory(), pomFile.getBuildOutputDirectory(), ScopeType.COMPILE, + ScopeType.IMPORT, + ScopeType.PROVIDED, ScopeType.RUNTIME, ScopeType.SYSTEM); JavaArchive classes = ShrinkWrap.create(ExplodedImporter.class, "sources.jar") .importDirectory(pomFile.getBuildOutputDirectory()).as(JavaArchive.class); @@ -79,27 +143,30 @@ public JarPackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) archive = archive.merge(classes); } - JarPluginConfiguration jarConfiguration = new JarPluginConfiguration(pomFile); - // add resources for (Resource resource : pomFile.getResources()) { archive.addAsResource(resource.getSource(), resource.getTargetPath()); } + return this; + } + + + @Override public JavaArchive getResultingArchive(String name) { + JarPluginConfiguration jarConfiguration = new JarPluginConfiguration(pomFile); // set manifest Manifest manifest = jarConfiguration.getArchiveConfiguration().asManifest(); archive.setManifest(new ManifestAsset(manifest)); // construct new archive via applying includes/excludes - archive = ArchiveFilteringUtils.filterArchiveContent(archive, JavaArchive.class, jarConfiguration.getIncludes(), - jarConfiguration.getExcludes()); - - return this; + archive = + ArchiveFilteringUtils.filterArchiveContent(archive, JavaArchive.class, name, jarConfiguration.getIncludes(), + jarConfiguration.getExcludes()); + return archive; } @Override public JavaArchive getResultingArchive() { - return archive; + return getResultingArchive(archive.getName()); } - } diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/WarPackagingProcessor.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/WarPackagingProcessor.java index 5bc0a1092..4bb8d3832 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/WarPackagingProcessor.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/WarPackagingProcessor.java @@ -25,19 +25,23 @@ import org.codehaus.plexus.util.DirectoryScanner; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ArchivePath; +import org.jboss.shrinkwrap.api.Assignable; import org.jboss.shrinkwrap.api.Filter; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.importer.ExplodedImporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.ResolutionException; import org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact; import org.jboss.shrinkwrap.resolver.api.maven.MavenWorkingSession; import org.jboss.shrinkwrap.resolver.api.maven.PackagingType; import org.jboss.shrinkwrap.resolver.api.maven.ScopeType; +import org.jboss.shrinkwrap.resolver.api.maven.filter.MavenResolutionFilter; import org.jboss.shrinkwrap.resolver.api.maven.pom.ParsedPomFile; import org.jboss.shrinkwrap.resolver.api.maven.pom.Resource; import org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy; import org.jboss.shrinkwrap.resolver.impl.maven.archive.plugins.WarPluginConfiguration; +import org.jboss.shrinkwrap.resolver.impl.maven.convert.MavenConverter; import org.jboss.shrinkwrap.resolver.impl.maven.task.AddAllDeclaredDependenciesTask; import org.jboss.shrinkwrap.resolver.impl.maven.util.Validate; import org.jboss.shrinkwrap.resolver.spi.maven.archive.packaging.PackagingProcessor; @@ -45,10 +49,11 @@ /** * Packaging processor for Maven projects of WAR packaging type * + * @author Matous Jobanek * @author Karel Piwko - * */ -public class WarPackagingProcessor extends AbstractCompilingProcessor implements PackagingProcessor { +public class WarPackagingProcessor extends AbstractCompilingProcessor + implements PackagingProcessor { // private static final Logger log = Logger.getLogger(WarPackagingProcessor.class.getName()); public static final String MAVEN_WAR_PLUGIN_KEY = "org.apache.maven.plugins:maven-war-plugin"; @@ -61,19 +66,112 @@ public boolean handles(PackagingType packagingType) { } @Override - public WarPackagingProcessor configure(Archive archive, MavenWorkingSession session) { - super.configure(session); + public WarPackagingProcessor configure(Archive archive, MavenWorkingSession session, + boolean useDefaultBuildDirectory) { + super.configure(session, useDefaultBuildDirectory); // archive is ignored, just name is propagated String archiveName = hasGeneratedName(archive) ? session.getParsedPomFile().getFinalName() : archive.getName(); - this.archive = ShrinkWrap.create(WebArchive.class, archiveName); + this.archive = ShrinkWrap.create(WebArchive.class, archiveName).merge(archive); return this; } @Override public WebArchive getResultingArchive() { - return archive; + return getResultingArchive(archive.getName()); + } + + @Override + public WarPackagingProcessor addBuildOutput(ScopeType... scopes) throws IllegalArgumentException, + UnsupportedOperationException { + + // add source filed if any + addCompiledClassesFromDirectory(pomFile.getSourceDirectory(), scopes); + // add resources + addResources(pomFile.getResources()); + + return this; + } + + @Override public PackagingProcessor addTestOutput(ScopeType[] scopes) + throws IllegalArgumentException, ResolutionException { + + addCompiledClassesFromDirectory(pomFile.getTestSourceDirectory(), scopes); + addResources(pomFile.getTestResources()); + + return this; + } + + @Override + public PackagingProcessor addDependencies(MavenResolutionFilter filter, ScopeType... scopes) + throws IllegalArgumentException, + UnsupportedOperationException { + + Collection resolvedArtifacts = resolveArtifacts(scopes); + for (MavenResolvedArtifact artifact : resolvedArtifacts) { + if (filter.accepts(MavenConverter.fromResolvedArtifact(artifact), null, null)) { + archive.addAsLibrary(artifact.asFile()); + } + } + return this; + } + + private void addResources(List resources) { + for (Resource resource : resources) { + archive.addAsResource(resource.getSource(), resource.getTargetPath()); + } + } + + private void addCompiledClassesFromDirectory(File sourceDirectory, ScopeType... scopes) { + if (Validate.isReadable(sourceDirectory)) { + + File buildDir = getBuildDir(); + compile(sourceDirectory, buildDir, scopes); + + JavaArchive classes = ShrinkWrap.create(ExplodedImporter.class, "sources.jar") + .importDirectory(buildDir).as(JavaArchive.class); + + archive = archive.merge(classes, "WEB-INF/classes"); + } + } + + private boolean containsTestScope(ScopeType... scopeTypes) { + if (scopeTypes != null) { + for (ScopeType st : scopeTypes) { + if (st.equals(ScopeType.TEST)) { + return true; + } + } + } + return false; + } + + /** + * Returns the file to copy. If the includes are null or empty, the default includes are used. + * + * @param baseDir the base directory to start from + * @param includes the includes + * @param excludes the excludes + * @return the files to copy + */ + protected String[] getFilesToIncludes(File baseDir, String[] includes, String[] excludes) { + final DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir(baseDir); + + if (excludes != null) { + scanner.setExcludes(excludes); + } + + scanner.addDefaultExcludes(); + scanner.scan(); + + final String[] includedFiles = scanner.getIncludedFiles(); + for (int i = 0; i < includedFiles.length; i++) { + includedFiles[i] = "/" + includedFiles[i].replace(File.separator, "/"); + } + return includedFiles; + } @Override @@ -84,8 +182,9 @@ public WarPackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) // add source files if any if (Validate.isReadable(pomFile.getSourceDirectory())) { - compile(pomFile.getSourceDirectory(), pomFile.getBuildOutputDirectory(), ScopeType.COMPILE, ScopeType.IMPORT, - ScopeType.PROVIDED, ScopeType.RUNTIME, ScopeType.SYSTEM); + compile(pomFile.getSourceDirectory(), pomFile.getBuildOutputDirectory(), ScopeType.COMPILE, + ScopeType.IMPORT, + ScopeType.PROVIDED, ScopeType.RUNTIME, ScopeType.SYSTEM); JavaArchive classes = ShrinkWrap.create(ExplodedImporter.class, "sources.jar") .importDirectory(pomFile.getBuildOutputDirectory()).as(JavaArchive.class); @@ -98,6 +197,17 @@ public WarPackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) archive.addAsResource(resource.getSource(), resource.getTargetPath()); } + // add dependencies + this.session = AddAllDeclaredDependenciesTask.INSTANCE.execute(session); + final Collection artifacts = session.resolveDependencies(strategy); + for (MavenResolvedArtifact artifact : artifacts) { + archive.addAsLibrary(artifact.asFile()); + } + + return this; + } + + @Override public WebArchive getResultingArchive(String name) { WarPluginConfiguration warConfiguration = new WarPluginConfiguration(pomFile); if (Validate.isReadable(warConfiguration.getWarSourceDirectory())) { WebArchive webapp = ShrinkWrap.create(ExplodedImporter.class, "webapp.war") @@ -107,27 +217,22 @@ public WarPackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) archive = archive.merge(webapp); } - // add dependencies - this.session = AddAllDeclaredDependenciesTask.INSTANCE.execute(session); - final Collection artifacts = session.resolveDependencies(strategy); - for (MavenResolvedArtifact artifact : artifacts) { - archive.addAsLibrary(artifact.asFile()); - } - // set manifest Manifest manifest = warConfiguration.getArchiveConfiguration().asManifest(); archive.setManifest(new ManifestAsset(manifest)); // filter via includes/excludes - archive = ArchiveFilteringUtils.filterArchiveContent(archive, WebArchive.class, warConfiguration.getIncludes(), - warConfiguration.getExcludes()); + archive = ArchiveFilteringUtils + .filterArchiveContent(archive, WebArchive.class, name, warConfiguration.getIncludes(), + warConfiguration.getExcludes()); - return this; + return archive; } protected Filter createFilter(WarPluginConfiguration configuration) { final List filesToIncludes = Arrays.asList(getFilesToIncludes(configuration.getWarSourceDirectory(), - configuration.getIncludes(), configuration.getExcludes())); + configuration.getIncludes(), + configuration.getExcludes())); return new Filter() { @Override public boolean include(ArchivePath archivePath) { @@ -145,31 +250,4 @@ public boolean include(ArchivePath archivePath) { }; } - /** - * Returns the file to copy. If the includes are null or empty, the default includes are used. - * - * @param baseDir the base directory to start from - * @param includes the includes - * @param excludes the excludes - * @return the files to copy - */ - protected String[] getFilesToIncludes(File baseDir, String[] includes, String[] excludes) { - final DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir(baseDir); - - if (excludes != null) { - scanner.setExcludes(excludes); - } - - scanner.addDefaultExcludes(); - scanner.scan(); - - final String[] includedFiles = scanner.getIncludedFiles(); - for (int i = 0; i < includedFiles.length; i++) { - includedFiles[i] = "/" + includedFiles[i].replace(File.separator, "/"); - } - return includedFiles; - - } - } diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/MavenArchiveConfiguration.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/MavenArchiveConfiguration.java index c14119b5f..3a7aa574b 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/MavenArchiveConfiguration.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/MavenArchiveConfiguration.java @@ -27,7 +27,7 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; -import org.jboss.shrinkwrap.resolver.api.maven.archive.importer.MavenImporterException; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssemblerException; import org.jboss.shrinkwrap.resolver.api.maven.pom.ParsedPomFile; import org.jboss.shrinkwrap.resolver.impl.maven.archive.plugins.ConfigurationUtils.Key; @@ -141,7 +141,7 @@ public ParsedPomFile getPomFile() { return pomFile; } - public Manifest asManifest() throws MavenImporterException { + public Manifest asManifest() throws ArchiveMavenAssemblerException { return new ManifestBuilder().addCustomEntries().addDefaultImplementationEntries().addDefaultSpecificationEntries() .addManifestEntries().addManifestSections().addMainClass() // loadFile() needs to be the last step as we might need to overwrite values generated by ShrinkWrap @@ -198,7 +198,7 @@ private class ManifestBuilder { manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); } - ManifestBuilder loadFile() throws MavenImporterException { + ManifestBuilder loadFile() throws ArchiveMavenAssemblerException { if (Validate.isReadable(getManifestFile())) { InputStream is = null; try { @@ -206,7 +206,7 @@ ManifestBuilder loadFile() throws MavenImporterException { Manifest userSupplied = new Manifest(is); this.manifest = ManifestMerger.merge(userSupplied, manifest); } catch (IOException e) { - throw new MavenImporterException("Unable to build MANIFEST.MF from file " + throw new ArchiveMavenAssemblerException("Unable to build MANIFEST.MF from file " + getManifestFile().getAbsolutePath(), e); } finally { try { diff --git a/maven/impl-maven-archive/src/main/resources/META-INF/services/org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler b/maven/impl-maven-archive/src/main/resources/META-INF/services/org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler new file mode 100644 index 000000000..506051ae7 --- /dev/null +++ b/maven/impl-maven-archive/src/main/resources/META-INF/services/org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler @@ -0,0 +1,2 @@ +implementingClassName=org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler.ArchiveMavenAssemblerImpl +extension=.war \ No newline at end of file diff --git a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ArchiveContentMatchers.java b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ArchiveContentMatchers.java new file mode 100644 index 000000000..c634c10b5 --- /dev/null +++ b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ArchiveContentMatchers.java @@ -0,0 +1,211 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2013, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.jar.Attributes; +import java.util.jar.Manifest; + +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ArchivePath; +import org.jboss.shrinkwrap.api.ArchivePaths; +import org.jboss.shrinkwrap.api.Node; +import org.jboss.shrinkwrap.api.asset.Asset; + +/** + * Represents Hamcrest matchers for validating content of an Archive + * + * @author Karel Piwko + * @author Matous Jobanek + * + */ +public final class ArchiveContentMatchers { + + public static ArchiveContentMatcher contains(String path) { + return new ArchiveContentMatcher(path); + } + + public static ArchiveSizeMatcher size(int filesTotal) { + return new ArchiveSizeMatcher(filesTotal); + } + + public static ManifestAssetMatcher hasManifestEntry(String section, String entry, String value) { + return new ManifestAssetMatcher(section, entry, value); + } + + public static ManifestAssetMatcher hasManifestEntry(String entry) { + return new ManifestAssetMatcher(null, entry, null); + } + + public static ManifestAssetMatcher hasManifestEntry(String entry, String value) { + return new ManifestAssetMatcher(null, entry, value); + } + + /** + * Checks that archive {@link Asset}, that represents Manifest contains a manifest entry with specified value or at least + * entry itself + * + * @author Karel Piwko + * + */ + public static class ManifestAssetMatcher extends BaseMatcher implements Matcher { + + private final String section; + private final String name; + private final String value; + + private ManifestAssetMatcher(String section, String entry, String value) { + this.section = section; + this.name = entry; + this.value = value; + } + + @Override + public void describeTo(Description description) { + description.appendText("Archive manifest contains entry named: ").appendText(name); + if (value != null) { + description.appendText(" with value: ").appendText(value); + } + if (section != null) { + description.appendText("(in section ").appendText(section).appendText(")"); + } + } + + @Override + public boolean matches(Object item) { + if (item == null) { + return false; + } else if (item instanceof Asset) { + Manifest mf = getManifest((Asset) item); + + String manifestValue = null; + if (section == null) { + manifestValue = mf.getMainAttributes().getValue(name); + } else { + Attributes attrs = mf.getAttributes(section); + if (attrs != null) { + manifestValue = attrs.getValue(name); + } + } + return value == null ? manifestValue != null : value.equals(manifestValue); + } + return false; + } + + private Manifest getManifest(Asset asset) { + InputStream is = null; + try { + is = asset.openStream(); + return new Manifest(is); + } catch (IOException e) { + + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException e) { + } + } + return new Manifest(); + } + + } + + /** + * Checks that an archive contains specific number of assets (directories are excluded) + * + * @author Karel Piwko + * + */ + public static class ArchiveSizeMatcher extends BaseMatcher> implements + Matcher> { + + private final int assetsTotal; + + private ArchiveSizeMatcher(int assetsTotal) { + this.assetsTotal = assetsTotal; + } + + @Override + public void describeTo(Description description) { + description.appendText("Archive contains ").appendText(String.valueOf(assetsTotal)).appendText(" assets."); + } + + @Override + public boolean matches(Object item) { + if (item == null) { + return false; + } else if (item instanceof Map) { + @SuppressWarnings("unchecked") + Map content = (Map) item; + int assets = 0; + for (Map.Entry entry : content.entrySet()) { + if (entry.getValue().getAsset() != null) { + assets++; + } + } + return assets == assetsTotal; + } + return false; + } + } + + /** + * Checks that archive contains a node under given path + * + * @author Karel Piwko + * + */ + public static class ArchiveContentMatcher extends BaseMatcher> implements + Matcher> { + + private final String path; + + private ArchiveContentMatcher(String path) { + this.path = path; + } + + @Override + public void describeTo(Description description) { + description.appendText("Archive contains path ").appendText(path); + } + + @Override + public boolean matches(Object item) { + if (item == null) { + return false; + } else if (item instanceof Map) { + @SuppressWarnings("unchecked") + Map content = (Map) item; + return content.containsKey(ArchivePaths.create(path)); + } + + else if (item instanceof Archive) { + Archive archive = (Archive) item; + return archive.contains(path); + } + return false; + } + + } +} diff --git a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ConfiguredArchiveMavenAssemblerTestCase.java b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ConfiguredArchiveMavenAssemblerTestCase.java new file mode 100644 index 000000000..e40664fe1 --- /dev/null +++ b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ConfiguredArchiveMavenAssemblerTestCase.java @@ -0,0 +1,124 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler; + +import java.io.File; +import java.io.IOException; + +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.NoResolvedResultException; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.impl.maven.archive.util.TestFileUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler.ArchiveContentMatchers.contains; +import static org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler.ArchiveContentMatchers.size; +import static org.junit.Assert.assertThat; + +/** + * JAR import test case with settings.xml configuration + * + * @author Karel Piwko + * @author Matous Jobanek + * + */ +public class ConfiguredArchiveMavenAssemblerTestCase { + + private static final String LOCAL_REPOSITORY = "target/local-only-repository"; + private static final String SETTINGS_FILE = "src/test/resources/settings.xml"; + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @BeforeClass + public static void clearLocalRepositoryReference() { + System.clearProperty("maven.repo.local"); // May conflict with release settings + } + + /** + * Cleanup, remove the repositories from previous tests + */ + @Before + @After + // For debugging you might want to temporarily remove the @After lifecycle call just to sanity-check for yourself + // the repo + public void cleanLocalRepository() throws Exception { + TestFileUtil.removeDirectory(new File(LOCAL_REPOSITORY)); + } + + @Before + public void cleanTarget() throws IOException { + TestFileUtil.removeDirectory(new File("src/it/jar-sample/target")); + } + + @Test + public void importJar() { + // When + final Archive archive = ShrinkWrap.create(ArchiveMavenAssembler.class).configuredFrom(SETTINGS_FILE) + .usingPom("src/it/jar-sample/pom.xml").withBuildOutput().as(WebArchive.class); + + // Then + assertThat(archive.getContent(), contains("main.properties")); + assertThat(archive.getContent(), not(contains("file.toExclude"))); + assertThat(archive.getContent(), size(4)); + + File commonsCodec = new File(LOCAL_REPOSITORY + "/commons-codec/commons-codec/1.7/commons-codec-1.7.jar"); + assertThat(commonsCodec.exists(), is(true)); + } + + // SHRINKRES-176 + @Test + public void importJarWithName() { + + // given + final String name = "myownname.jar"; + + // When + final Archive archive = ShrinkWrap.create(ArchiveMavenAssembler.class, "test").configuredFrom(SETTINGS_FILE) + .usingPom("src/it/jar-sample/pom.xml").withBuildOutput().as(WebArchive.class, name); + + // Then + assertThat(archive.getName(), is(name)); + assertThat(archive.getContent(), contains("main.properties")); + assertThat(archive.getContent(), not(contains("file.toExclude"))); + assertThat(archive.getContent(), size(4)); + + File commonsCodec = new File(LOCAL_REPOSITORY + "/commons-codec/commons-codec/1.7/commons-codec-1.7.jar"); + assertThat(commonsCodec.exists(), is(true)); + } + + + @Test + public void importJarOffline() { + + // if running offline, this would not work + exception.expect(NoResolvedResultException.class); + ShrinkWrap.create(ArchiveMavenAssembler.class).configuredFrom(SETTINGS_FILE).usingOfflineMode() + .usingPom("src/it/jar-sample/pom.xml").withBuildOutput().as(WebArchive.class); + + } + +} diff --git a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/JarArchiveMavenAssemblerTestCase.java b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/JarArchiveMavenAssemblerTestCase.java new file mode 100644 index 000000000..b197427e1 --- /dev/null +++ b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/JarArchiveMavenAssemblerTestCase.java @@ -0,0 +1,123 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler; + +import java.io.File; +import java.io.IOException; + +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.impl.maven.archive.util.TestFileUtil; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.not; +import static org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler.ArchiveContentMatchers.contains; +import static org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler.ArchiveContentMatchers.size; +import static org.junit.Assert.assertThat; + +/** + * JAR import test case + * + * @author Karel Piwko + * @author Matous Jobanek + * + */ +public class JarArchiveMavenAssemblerTestCase { + + + @Test + public void importJarWithCleanup() throws IOException { + TestFileUtil.removeDirectory(new File("src/it/jar-sample/target")); + TestFileUtil.removeDirectory(new File("src/it/jar-without-resources/target")); + + // When + final Archive archive = doImport("src/it/jar-sample/pom.xml"); + + // Then + System.out.println(archive.toString(true)); + assertThat(archive.getContent(), contains("/test/JarClass.class")); + assertThat(archive.getContent(), contains("main.properties")); + assertThat(archive.getContent(), not(contains("file.toExclude"))); + assertThat(archive.getContent(), size(4)); + } + + @Test + public void importJarWithTestClasses() { + + // When + JavaArchive archive = ShrinkWrap.create(ArchiveMavenAssembler.class).usingPom("src/it/jar-sample/pom.xml").withBuildOutput() + .withTestBuildOutput().as(JavaArchive.class); + + // Then + System.out.println(archive.toString(true)); + assertThat(archive.getContent(), contains("/test/JarClass.class")); + assertThat(archive.getContent(), contains("test/JarTestCase.class")); + assertThat(archive.getContent(), contains("main.properties")); + assertThat(archive.getContent(), not(contains("file.toExclude"))); + assertThat(archive.getContent(), size(6)); + } + + @Test + public void importJarWithIncludes() { + // When + final Archive archive = doImport("src/it/jar-sample/pom-b.xml"); + + // Then + assertThat(archive.getContent(), not(contains("main.properties"))); + assertThat(archive.getContent(), contains("file.toExclude")); + assertThat(archive.getContent(), size(1)); + } + + @Test + public void importJarWithResourceIncludes() { + // When + final Archive archive = doImport("src/it/jar-sample/pom-c.xml"); + + System.out.println(archive.toString(true)); + // Then + assertThat(archive.getContent(), contains("main.properties")); + assertThat(archive.getContent(), contains("test/JarClass.class")); + assertThat(archive.getContent(), size(4)); + } + + + //SHRINKRES-141 + @Test + public void importJarWithoutResources() { + + // When + final Archive archive = doImport("src/it/jar-without-resources/pom.xml"); + + assertThat(archive.getContent(), size(3)); + } + + private Archive doImport(String pomFile) { + // When + WebArchive archive = ShrinkWrap.create(ArchiveMavenAssembler.class).usingPom(pomFile).withBuildOutput() + .as(WebArchive.class); + + // Then + assertThat(archive.getContent(), not(contains(".svn"))); + assertThat(archive.getContent(), not(contains("WEB-INF/.svn"))); + + return archive; + } + +} diff --git a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ManifestTestCase.java b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ManifestTestCase.java new file mode 100644 index 000000000..8353d0bb7 --- /dev/null +++ b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/ManifestTestCase.java @@ -0,0 +1,154 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2013, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler; + +import java.io.File; +import java.io.IOException; +import java.util.jar.Attributes; + +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.impl.maven.archive.util.TestFileUtil; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.not; +import static org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.ArchiveContentMatchers.contains; +import static org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.ArchiveContentMatchers.hasManifestEntry; +import static org.junit.Assert.assertThat; + + +/** + * + * @author Karel Piwko + * @author Matous Jobanek + * + */ +public class ManifestTestCase { + + @Before + public void cleanTarget() throws IOException { + TestFileUtil.removeDirectory(new File("src/it/war-sample/target")); + TestFileUtil.removeDirectory(new File("src/it/jar-sample/target")); + TestFileUtil.removeDirectory(new File("src/it/jar-with-mf-sample/target")); + } + + @Test + public void manifestCreatedInJar() { + // When + final Archive archive = ShrinkWrap.create(ArchiveMavenAssembler.class).usingPom("src/it/jar-sample/pom.xml") + .withBuildOutput().as(JavaArchive.class); + + // Then + assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver")); + } + + @Test + public void manifestCreatedInWar() { + // When + final Archive archive = ShrinkWrap.create(ArchiveMavenAssembler.class).usingPom("src/it/war-sample/pom.xml") + .withBuildOutput().as(WebArchive.class); + + // Then + assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver")); + } + + @Test + public void suppliedManifestHasPrecedence() { + // When + final Archive archive = ShrinkWrap.create(ArchiveMavenAssembler.class).usingPom("src/it/jar-with-mf-sample/pom.xml") + .withBuildOutput().as(JavaArchive.class); + + // Then + assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "User")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), + hasManifestEntry(Attributes.Name.MANIFEST_VERSION.toString(), "1.0")); + } + + @Test + public void manifestWithDefaultImplementationEntries() { + // When + final Archive archive = ShrinkWrap.create(ArchiveMavenAssembler.class) + .usingPom("src/it/jar-with-mf-sample/pom-b.xml").withBuildOutput().as(JavaArchive.class); + + // Then + assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Implementation-Title")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), not(hasManifestEntry("Implementation-Vendor"))); + } + + @Test + public void manifestWithDefaultSpecificationEntries() { + // When + final Archive archive = ShrinkWrap.create(ArchiveMavenAssembler.class) + .usingPom("src/it/jar-with-mf-sample/pom-c.xml").withBuildOutput().as(JavaArchive.class); + + // Then + assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Specification-Title")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Specification-Vendor", "Arquillian")); + } + + @Test + public void manifestWithManifestSection() { + // When + final Archive archive = ShrinkWrap.create(ArchiveMavenAssembler.class) + .usingPom("src/it/jar-with-mf-sample/pom-d.xml").withBuildOutput().as(JavaArchive.class); + + // Then + assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Specification-Title")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Specification-Vendor", "Arquillian")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("MyFirstSection", "Foo", "bar")); + } + + @Test + public void manifestWithManifestSections() { + // When + final Archive archive = ShrinkWrap.create(ArchiveMavenAssembler.class) + .usingPom("src/it/jar-with-mf-sample/pom-e.xml").withBuildOutput().as(JavaArchive.class); + + // Then + assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Specification-Title")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Specification-Vendor", "Arquillian")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("MyFirstSection", "Foo", "bar")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("MySecondSection", "Foo2", "bar2")); + } + + @Test + public void manifestWithCustomManifestEntries() { + // When + final Archive archive = ShrinkWrap.create(ArchiveMavenAssembler.class).usingPom("src/it/war-sample/pom.xml") + .withBuildOutput().as(JavaArchive.class); + + // Then + assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver")); + assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Dependencies")); + } +} diff --git a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/WarArchiveMavenAssemblerTestCase.java b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/WarArchiveMavenAssemblerTestCase.java new file mode 100644 index 000000000..609b367a9 --- /dev/null +++ b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/assembler/WarArchiveMavenAssemblerTestCase.java @@ -0,0 +1,130 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler; + +import java.io.File; +import java.io.IOException; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.ScopeType; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; +import org.jboss.shrinkwrap.resolver.api.maven.filter.AcceptDependenciesFilter; +import org.jboss.shrinkwrap.resolver.impl.maven.archive.util.TestFileUtil; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler.ArchiveContentMatchers.contains; +import static org.jboss.shrinkwrap.resolver.impl.maven.archive.assembler.ArchiveContentMatchers.size; +import static org.junit.Assert.assertThat; + +/** + * WAR import test case + * + * @author Karel Piwko + * @author Matous Jobanek + * + */ +public class WarArchiveMavenAssemblerTestCase { + + @Before + public void cleanTarget() throws IOException { + TestFileUtil.removeDirectory(new File("src/it/war-sample/target")); + } + + @Test + public void importWar() { + // When + final WebArchive archive = doImport("src/it/war-sample/pom.xml"); + + archive.as(ZipExporter.class).exportTo(new File("target/foo.war"), true); + + // Then + assertThat(archive.getContent(), contains("WEB-INF/web.xml")); + assertThat(archive.getContent(), contains("WEB-INF/classes/test/nested/NestedWarClass.class")); + assertThat(archive.getContent(), contains("WEB-INF/classes/test/WarClass.class")); + assertThat(archive.getContent(), contains("WEB-INF/classes/main.properties")); + assertThat(archive.getContent(), contains("WEB-INF/classes/nesteddir/nested.properties")); + assertThat(archive.getContent(), not(contains("file.toExclude"))); + assertThat(archive.getContent(), not(contains("file.packagingToExclude"))); + assertThat(archive.getContent(), not(contains("file.warSourceToExclude"))); + assertThat(archive.getContent(), size(7)); + } + + // SHRINKRES-176 + @Test + public void importWarWithName() { + + // Given + final String name = "myownname.war"; + + // When + final WebArchive archive = ShrinkWrap.create(ArchiveMavenAssembler.class) + .usingPom("src/it/war-sample/pom.xml") + .withBuildOutput() + .withDependencies(ScopeType.COMPILE) + .as(WebArchive.class, name); + + + + // Then + assertThat(archive.getName(), is(name)); + assertThat(archive.getContent(), contains("WEB-INF/web.xml")); + assertThat(archive.getContent(), contains("WEB-INF/classes/test/nested/NestedWarClass.class")); + assertThat(archive.getContent(), contains("WEB-INF/classes/test/WarClass.class")); + assertThat(archive.getContent(), contains("WEB-INF/classes/main.properties")); + assertThat(archive.getContent(), contains("WEB-INF/classes/nesteddir/nested.properties")); + assertThat(archive.getContent(), not(contains("file.toExclude"))); + assertThat(archive.getContent(), not(contains("file.packagingToExclude"))); + assertThat(archive.getContent(), not(contains("file.warSourceToExclude"))); + System.out.println(archive.getContent().size()); + + System.out.println(archive.toString(true)); + assertThat(archive.getContent(), size(7)); + } + + @Test + public void importWarWithIncludes() { + // When + final WebArchive archive = doImport("src/it/war-sample/pom-b.xml"); + + // Then + assertThat(archive.getContent(), contains("WEB-INF/web.xml")); + assertThat(archive.getContent(), contains("file.toExclude")); + assertThat(archive.getContent(), contains("file.packagingToExclude")); + assertThat(archive.getContent(), contains("file.warSourceToExclude")); + assertThat(archive.getContent(), size(5)); + } + + private WebArchive doImport(String pomFile) { + + // When + WebArchive archive = ShrinkWrap.create(ArchiveMavenAssembler.class).usingPom(pomFile).withBuildOutput() + .withDependencies(new AcceptDependenciesFilter("commons-codec:commons-codec:?")).as(WebArchive.class); + + // Then + assertThat(archive.getContent(), not(contains(".svn"))); + assertThat(archive.getContent(), not(contains("WEB-INF/.svn"))); + + assertThat(archive.getContent(), contains("WEB-INF/lib/commons-codec-1.7.jar")); + + return archive; + } +} diff --git a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/ConfiguredMavenImporterTestCase.java b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/ConfiguredMavenImporterTestCase.java index 998888c42..11fc32520 100644 --- a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/ConfiguredMavenImporterTestCase.java +++ b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/ConfiguredMavenImporterTestCase.java @@ -16,12 +16,6 @@ */ package org.jboss.shrinkwrap.resolver.impl.maven.archive.importer; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.ArchiveContentMatchers.contains; -import static org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.ArchiveContentMatchers.size; -import static org.junit.Assert.assertThat; - import java.io.File; import java.io.IOException; @@ -38,6 +32,12 @@ import org.junit.Test; import org.junit.rules.ExpectedException; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.ArchiveContentMatchers.contains; +import static org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.ArchiveContentMatchers.size; +import static org.junit.Assert.assertThat; + /** * JAR import test case with settings.xml configuration * diff --git a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/JarMavenImporterTestCase.java b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/JarMavenImporterTestCase.java index b804d5c85..f5cb43058 100644 --- a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/JarMavenImporterTestCase.java +++ b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/JarMavenImporterTestCase.java @@ -74,7 +74,6 @@ public void importJarWithResourceIncludes() { // When final Archive archive = doImport("src/it/jar-sample/pom-c.xml"); - System.out.println(archive.toString(true)); // Then assertThat(archive.getContent(), contains("main.properties")); assertThat(archive.getContent(), contains("test/JarClass.class")); diff --git a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/usecases/UseCasesTestCase.java b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/usecases/UseCasesTestCase.java index 1ca6ff8b7..f09306e7c 100644 --- a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/usecases/UseCasesTestCase.java +++ b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/usecases/UseCasesTestCase.java @@ -29,7 +29,7 @@ import org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact; import org.jboss.shrinkwrap.resolver.api.maven.MavenResolverSystem; import org.jboss.shrinkwrap.resolver.api.maven.ScopeType; -import org.jboss.shrinkwrap.resolver.api.maven.archive.importer.MavenImporter; +import org.jboss.shrinkwrap.resolver.api.maven.archive.assembler.ArchiveMavenAssembler; import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate; import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependencies; import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency; @@ -250,12 +250,12 @@ public void mimickMavenDependencies() { // // // or using ShrinkWrap Maven plugin and current Maven execution // - // DependencyResolvers.use(MavenDependencyResolver.class).configureFrom(MavenConfigurationTypes.ENVIRONMENT) + // DependencyResolvers.use(MavenDependencyResolver.class).configuredFrom(MavenConfigurationTypes.ENVIRONMENT) // .importAnyDependencies(new ScopeFilter("compile", "runtime", "")).resolveAsFiles(); // - // // or using MavenImporter, which does a bit different thing + // // or using ArchiveMavenAssembler, which does a bit different thing // - // ShrinkWrap.create(MavenImporter.class).loadSettings("settings.xml").loadEffectivePom("pom.xml") + // ShrinkWrap.create(ArchiveMavenAssembler.class).loadSettings("settings.xml").loadEffectivePom("pom.xml") // .importAnyDependencies(new ScopeFilter("compile", "runtime", "")); } @@ -349,7 +349,7 @@ public void mimickMaven() { // // or // // note current implementation is expecting mvn package to be run first (SHRINKRES-18) // - // ShrinkWrap.create(MavenImporter.class).loadEffectivePom("pom.xml").importBuildOutput(); + // ShrinkWrap.create(ArchiveMavenAssembler.class).loadEffectivePom("pom.xml").withDependencies(); // // // note usage of ENVIRONMENT configuration is not possible } @@ -395,7 +395,7 @@ public void offline() { Maven.configureResolver().workOffline().resolve("groupId:artifactId:version").withoutTransitivity() .asSingle(File.class); - ShrinkWrap.create(MavenImporter.class).offline().loadPomFromClassLoaderResource("/path/to/pom").importBuildOutput(); + ShrinkWrap.create(ArchiveMavenAssembler.class).usingOfflineMode().usingPomFromClassLoaderResource("/path/to/pom").withBuildOutput(); } /** diff --git a/maven/impl-maven-integration-tests/ear-sample-test/pom.xml b/maven/impl-maven-integration-tests/ear-sample-test/pom.xml deleted file mode 100644 index 3e3d58d2d..000000000 --- a/maven/impl-maven-integration-tests/ear-sample-test/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - 4.0.0 - - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven-tests - 2.0.0-alpha-2-SNAPSHOT - ../pom.xml - - - - org.jboss.shrinkwrap.resolver.test - shrinkwrap-resolver-impl-maven-test-ear-sample-test - jar - ShrinkWrap Resolver Maven Implementation Tests: Ear Sample Test - - - - - org.jboss.shrinkwrap - shrinkwrap-api - compile - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-api - ${project.version} - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-api-maven - ${project.version} - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven - ${project.version} - test - - - org.jboss.shrinkwrap - shrinkwrap-impl-base - test - - - - - junit - junit - test - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - default-test - integration-test - - test - - - - - - - - diff --git a/maven/impl-maven-integration-tests/ear-sample-test/src/main/application/test.xml b/maven/impl-maven-integration-tests/ear-sample-test/src/main/application/test.xml deleted file mode 100644 index 3f89e49bc..000000000 --- a/maven/impl-maven-integration-tests/ear-sample-test/src/main/application/test.xml +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/maven/impl-maven-integration-tests/ear-sample-test/src/test/java/test/EarTestCase.java b/maven/impl-maven-integration-tests/ear-sample-test/src/test/java/test/EarTestCase.java deleted file mode 100644 index 313ca208f..000000000 --- a/maven/impl-maven-integration-tests/ear-sample-test/src/test/java/test/EarTestCase.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2011, Red Hat Middleware LLC, and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package test; - -import java.util.Set; - -import junit.framework.Assert; - -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ArchivePath; -import org.jboss.shrinkwrap.api.Filter; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; -import org.jboss.shrinkwrap.resolver.api.maven.MavenImporter; -import org.jboss.shrinkwrap.resolver.api.maven.filter.DependenciesFilter; -import org.junit.Test; - -public class EarTestCase { - - @Test - public void testEar() { - EnterpriseArchive archive = ShrinkWrap.create(MavenImporter.class, "test.ear") - .loadEffectivePom("../ear-sample/pom.xml").importBuildOutput().as(EnterpriseArchive.class); - - Assert.assertNotNull("Archive is not null", archive); - Assert.assertTrue("Archive contains test.xml", archive.contains("test.xml")); - Assert.assertTrue("Archive contains application.xml", archive.contains("META-INF/application.xml")); - - Assert.assertEquals("Archive contains one library", 1, getLibraries(archive).size()); - } - - @Test(expected = UnsupportedOperationException.class) - public void testEarWithTestClasses() { - ShrinkWrap.create(MavenImporter.class, "testWithTestClasses.ear").loadEffectivePom("../ear-sample/pom.xml") - .importBuildOutput().importTestBuildOutput().as(EnterpriseArchive.class); - - Assert.fail("EAR test build import is not supported"); - } - - @Test - public void testEnterpriseArchiveAsMavenImporter() { - EnterpriseArchive archive = ShrinkWrap - .create(EnterpriseArchive.class, "testEnterpriseArchiveAsMavenImporter.ear").as(MavenImporter.class) - .loadEffectivePom("../ear-sample/pom.xml").importBuildOutput().as(EnterpriseArchive.class); - - Assert.assertNotNull("Archive is not null", archive); - Assert.assertTrue("Archive contains test.xml", archive.contains("test.xml")); - Assert.assertTrue("Archive contains application.xml", archive.contains("META-INF/application.xml")); - - Assert.assertEquals("Archive contains one library", 1, getLibraries(archive).size()); - } - - @Test - public void testEarWithTestArtifacts() { - EnterpriseArchive archive = ShrinkWrap.create(MavenImporter.class, "testWithTestArtifacts.ear") - .loadEffectivePom("../ear-sample/pom.xml").importBuildOutput() - .importTestDependencies(new DependenciesFilter("junit:junit")).as(EnterpriseArchive.class); - System.out.println(archive.toString(true)); - - Assert.assertNotNull("Archive is not null", archive); - Assert.assertTrue("Archive contains test.xml", archive.contains("test.xml")); - Assert.assertTrue("Archive contains application.xml", archive.contains("META-INF/application.xml")); - - Assert.assertTrue("Archive contains more than one library", 1 < getLibraries(archive).size()); - } - - private Set getLibraries(Archive archive) { - return archive.getContent(new Filter() { - - public boolean include(ArchivePath arg0) { - String path = arg0.get(); - return path.endsWith(".jar"); - } - }).keySet(); - } - -} diff --git a/maven/impl-maven-integration-tests/ear-sample/pom.xml b/maven/impl-maven-integration-tests/ear-sample/pom.xml deleted file mode 100644 index b6c828af0..000000000 --- a/maven/impl-maven-integration-tests/ear-sample/pom.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - 4.0.0 - - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven-tests - 2.0.0-alpha-2-SNAPSHOT - ../pom.xml - - - - org.jboss.shrinkwrap.resolver.test - shrinkwrap-resolver-impl-maven-test-ear-sample - ear - ShrinkWrap Resolver Maven Implementation Tests: Ear Sample - - - - - org.jboss.shrinkwrap - shrinkwrap-api - compile - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-api - ${project.version} - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-api-maven - ${project.version} - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven - ${project.version} - test - - - org.jboss.shrinkwrap - shrinkwrap-impl-base - test - - - - - junit - junit - test - - - - - - - maven-surefire-plugin - - - default-test - test - - test - - - - - - maven-ear-plugin - - - - org.jboss.shrinkwrap - shrinkwrap-api - true - - - - - - - - diff --git a/maven/impl-maven-integration-tests/ear-sample/src/main/application/test.xml b/maven/impl-maven-integration-tests/ear-sample/src/main/application/test.xml deleted file mode 100644 index 3f89e49bc..000000000 --- a/maven/impl-maven-integration-tests/ear-sample/src/main/application/test.xml +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/maven/impl-maven-integration-tests/jar-sample/pom.xml b/maven/impl-maven-integration-tests/jar-sample/pom.xml deleted file mode 100644 index a5a4e019f..000000000 --- a/maven/impl-maven-integration-tests/jar-sample/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - 4.0.0 - - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven-tests - 2.0.0-alpha-2-SNAPSHOT - ../pom.xml - - - - org.jboss.shrinkwrap.resolver.test - shrinkwrap-resolver-impl-maven-test-jar-sample - jar - ShrinkWrap Resolver Maven Implementation Tests: Jar Sample - - - - - org.jboss.shrinkwrap - shrinkwrap-api - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-api - ${project.version} - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-api-maven - ${project.version} - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven - ${project.version} - test - - - org.jboss.shrinkwrap - shrinkwrap-impl-base - test - - - - - junit - junit - test - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - default-test - integration-test - - test - - - - - - - - diff --git a/maven/impl-maven-integration-tests/jar-sample/src/main/java/test/JarClass.java b/maven/impl-maven-integration-tests/jar-sample/src/main/java/test/JarClass.java deleted file mode 100644 index 87d89e4dd..000000000 --- a/maven/impl-maven-integration-tests/jar-sample/src/main/java/test/JarClass.java +++ /dev/null @@ -1,10 +0,0 @@ -package test; - -public class JarClass { - - public static final String GREETINGS = "Hello from MavenImporter imported class"; - - public String greet() { - return GREETINGS; - } -} diff --git a/maven/impl-maven-integration-tests/jar-sample/src/main/resources/main.properties b/maven/impl-maven-integration-tests/jar-sample/src/main/resources/main.properties deleted file mode 100644 index 260dcfdef..000000000 --- a/maven/impl-maven-integration-tests/jar-sample/src/main/resources/main.properties +++ /dev/null @@ -1 +0,0 @@ -property=value diff --git a/maven/impl-maven-integration-tests/jar-sample/src/test/java/test/JarTestCase.java b/maven/impl-maven-integration-tests/jar-sample/src/test/java/test/JarTestCase.java deleted file mode 100644 index a680267e8..000000000 --- a/maven/impl-maven-integration-tests/jar-sample/src/test/java/test/JarTestCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat Middleware LLC, and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package test; - -import junit.framework.Assert; - -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.jboss.shrinkwrap.resolver.api.maven.MavenImporter; -import org.junit.Test; - -/** - * Test cases for MavenImporter with Jar - * - * @author - - - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-parent - 2.0.0-alpha-2-SNAPSHOT - ../../pom.xml - - - - 4.0.0 - - - shrinkwrap-resolver-impl-maven-tests - ShrinkWrap Resolver Maven Implementation Tests - ShrinkWrap Extension for Resolving Dependencies from a Maven Back-End Integration Tests - pom - - - - - - org.apache.maven.plugins - maven-deploy-plugin - true - - true - - - - - - - jar-sample - war-sample - ear-sample - ear-sample-test - - - - diff --git a/maven/impl-maven-integration-tests/war-sample/pom.xml b/maven/impl-maven-integration-tests/war-sample/pom.xml deleted file mode 100644 index a83dc479d..000000000 --- a/maven/impl-maven-integration-tests/war-sample/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - - 4.0.0 - - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven-tests - 2.0.0-alpha-2-SNAPSHOT - ../pom.xml - - - - org.jboss.shrinkwrap.resolver.test - shrinkwrap-resolver-impl-maven-test-war-sample - war - ShrinkWrap Resolver Maven Implementation Tests: War Sample - - - - - org.jboss.shrinkwrap - shrinkwrap-api - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-api - ${project.version} - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-api-maven - ${project.version} - test - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven - ${project.version} - test - - - org.jboss.shrinkwrap - shrinkwrap-impl-base - test - - - - - junit - junit - test - - - - - org.slf4j - slf4j-api - 1.6.1 - provided - - - - - - - - org.apache.maven.plugins - maven-war-plugin - 2.1.1 - - - - org.slf4j - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - default-test - integration-test - - test - - - - - - - - diff --git a/maven/impl-maven-integration-tests/war-sample/src/main/resources/main.properties b/maven/impl-maven-integration-tests/war-sample/src/main/resources/main.properties deleted file mode 100644 index 260dcfdef..000000000 --- a/maven/impl-maven-integration-tests/war-sample/src/main/resources/main.properties +++ /dev/null @@ -1 +0,0 @@ -property=value diff --git a/maven/impl-maven-integration-tests/war-sample/src/main/webapp/WEB-INF/web.xml b/maven/impl-maven-integration-tests/war-sample/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index ebf92331a..000000000 --- a/maven/impl-maven-integration-tests/war-sample/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/maven/impl-maven-integration-tests/war-sample/src/test/java/test/WarTestCase.java b/maven/impl-maven-integration-tests/war-sample/src/test/java/test/WarTestCase.java deleted file mode 100644 index 6686dc94b..000000000 --- a/maven/impl-maven-integration-tests/war-sample/src/test/java/test/WarTestCase.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2011, Red Hat Middleware LLC, and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package test; - -import java.util.Set; - -import junit.framework.Assert; - -import org.jboss.shrinkwrap.api.ArchivePath; -import org.jboss.shrinkwrap.api.Filter; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.jboss.shrinkwrap.resolver.api.maven.MavenImporter; -import org.jboss.shrinkwrap.resolver.api.maven.filter.DependenciesFilter; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Test cases for MavenImporter with war packaging - * - * @author libs = archive.getContent(new Filter() { - - public boolean include(ArchivePath arg0) { - return arg0.get().startsWith("/WEB-INF/lib"); - } - }).keySet(); - for (final ArchivePath lib : libs) { - if (lib.get().startsWith("/WEB-INF/lib/junit")) { - foundJunit = true; - } - } - - Assert.assertTrue("Should have been able to import test dependency upon junit", foundJunit); - } - - @Test - public void testWarWithFilteredTestArtifacts() { - WebArchive archive = ShrinkWrap.create(MavenImporter.class, "testWithFilteredTestArtifacts.war") - .loadEffectivePom("pom.xml").importBuildOutput().importTestBuildOutput() - .importAnyDependencies(new DependenciesFilter("junit:junit")).as(WebArchive.class); - - Assert.assertNotNull("Archive is not null", archive); - Assert.assertTrue("Archive contains war class", archive.contains("WEB-INF/classes/test/WarClass.class")); - Assert.assertTrue("Archive contains main.properties", archive.contains("WEB-INF/classes/main.properties")); - Assert - .assertTrue("Archive contains war test class", archive.contains("WEB-INF/classes/test/WarTestCase.class")); - Assert.assertTrue("Archive contains test.properties", archive.contains("WEB-INF/classes/test.properties")); - - Set libs = archive.getContent(new Filter() { - - public boolean include(ArchivePath arg0) { - String path = arg0.get(); - return path.startsWith("/WEB-INF/lib") && path.endsWith(".jar"); - } - }).keySet(); - - Assert.assertEquals("There should be one filtered lib", 1, libs.size()); - } - -} diff --git a/maven/impl-maven-integration-tests/war-sample/src/test/resources/test.properties b/maven/impl-maven-integration-tests/war-sample/src/test/resources/test.properties deleted file mode 100644 index 4fde3f851..000000000 --- a/maven/impl-maven-integration-tests/war-sample/src/test/resources/test.properties +++ /dev/null @@ -1 +0,0 @@ -test.property=value diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/convert/MavenConverter.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/convert/MavenConverter.java index 3c371ec63..fe9953d46 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/convert/MavenConverter.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/convert/MavenConverter.java @@ -46,6 +46,7 @@ import org.eclipse.aether.repository.RepositoryPolicy; import org.eclipse.aether.util.repository.AuthenticationBuilder; import org.jboss.shrinkwrap.resolver.api.CoordinateParseException; +import org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact; import org.jboss.shrinkwrap.resolver.api.maven.PackagingType; import org.jboss.shrinkwrap.resolver.api.maven.ScopeType; import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate; @@ -218,6 +219,10 @@ public static Set fromDependencies(Collection> { * * @param originalArchive Original archive holder * @param session Current Maven working session + * @param useDefaultBuildDirectory * @return Modified instance for chaining */ - PackagingProcessor configure(Archive originalArchive, MavenWorkingSession session); + PackagingProcessor configure(Archive originalArchive, MavenWorkingSession session, + boolean useDefaultBuildDirectory); /** * Compiles, packages and resolve dependencies for the project. Uses {@code strategy} to define what dependencies will be * packaged into project. * * @param strategy The strategy defining objects to be packaged + * @param scopes * @return * @throws IllegalArgumentException If strategy is {@code null} * @throws ResolutionException If a dependency of the project could not be resolved */ - PackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) throws IllegalArgumentException, + PackagingProcessor addBuildOutput(ScopeType[] scopes) throws IllegalArgumentException, ResolutionException; + /** + * Compiles, packages and resolve dependencies for the project. Uses {@code strategy} to define what dependencies will be + * packaged into project. + * + * @param strategy The strategy defining objects to be packaged + * @param scopes + * @return + * @throws IllegalArgumentException If strategy is {@code null} + * @throws ResolutionException If a dependency of the project could not be resolved + */ + PackagingProcessor addTestOutput(ScopeType[] scopes) throws IllegalArgumentException, + ResolutionException; + + /** + * Compiles, packages and resolve dependencies for the project. Uses {@code strategy} to define what dependencies will be + * packaged into project. + * + * @param strategy The strategy defining objects to be packaged + * @param filter + * @return + * @throws IllegalArgumentException If strategy is {@code null} + * @throws ResolutionException If a dependency of the project could not be resolved + */ + PackagingProcessor addDependencies(MavenResolutionFilter filter, ScopeType... scopes) throws IllegalArgumentException, + ResolutionException; + /** * Returns archive as a ShrinkWrap archive * * @return */ - ARCHIVETYPE getResultingArchive(); + ARCHIVETYPE getResultingArchive(); + + ARCHIVETYPE getResultingArchive(String name); + + + /** + * Compiles, packages and resolve dependencies for the project. Uses {@code strategy} to define what dependencies will be + * packaged into project. + * + * @param strategy The strategy defining objects to be packaged + * @return + * @throws IllegalArgumentException If strategy is {@code null} + * @throws ResolutionException If a dependency of the project could not be resolved + */ + @Deprecated + PackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) throws IllegalArgumentException, + ResolutionException; } diff --git a/pom.xml b/pom.xml index 1772da4ce..2a7e08286 100644 --- a/pom.xml +++ b/pom.xml @@ -91,9 +91,6 @@ gradle/api-gradle-embedded-archive gradle/depchain-gradle gradle/impl-gradle-embedded-archive - - -