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 extends Archive>> 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 extends Archive>> processor;
+
+
+ public PomEquippedArchiveMavenAssemblerImpl(PackagingProcessor extends Archive>> 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 extends Archive>> 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 extends Archive>> 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 extends Archive>> 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 extends Archive>> 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 extends Archive>> 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 extends Archive>> 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 extends Archive>> 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