本文整理了Java中org.jboss.shrinkwrap.api.Filters
类的一些代码示例,展示了Filters
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Filters
类的具体详情如下:
包路径:org.jboss.shrinkwrap.api.Filters
类名称:Filters
[英]Factory class for the creation of new Filter instances. Filter instances using this shorthand class will be created using the ClassLoader associated with the default Domain's Configuration.
[中]用于创建新筛选器实例的Factory类。使用此速记类的筛选器实例将使用与默认域配置关联的类加载器创建。
代码示例来源:origin: org.jboss.arquillian.extension/arquillian-jacoco
public Map<ArchivePath, Node> getSignatureFiles(Archive<?> archive) {
return archive.getContent(//
// This is adapted from Jacoco SignatureRemover
Filters.include("/META-INF/[^/]*\\.SF|" //
+ "/META-INF/[^/]*\\.DSA|" //
+ "/META-INF/[^/]*\\.RSA|" //
+ "/META-INF/SIG-[^/]*"));
}
代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-impl-base
/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.Archive#shallowCopy()
*/
@Override
public Archive<T> shallowCopy() {
return this.shallowCopy(Filters.includeAll());
}
代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-api
/**
* {@link Filter} that excludes listed {@link Class}.
*
* @param classes
* To be excluded
* @return
*/
public static Filter<ArchivePath> exclude(Class<?>... classes) {
return createRegExpFilter(IMPL_CLASS_NAME_EXCLUDE_REGEXP_PATHS, classes);
}
代码示例来源:origin: org.jboss.arquillian.container/arquillian-glassfish-embedded-3.1
/**
* @param archive
* @return
*/
private String[] resolveWebArchiveNames(Archive<?> archive) {
if (archive instanceof WebArchive) {
return new String[] {createDeploymentName(archive.getName())};
} else if (archive instanceof EnterpriseArchive) {
Map<ArchivePath, Node> webArchives = archive.getContent(Filters.include(".*\\.war"));
List<String> deploymentNames = new ArrayList<String>();
for (ArchivePath path : webArchives.keySet()) {
deploymentNames.add(createDeploymentName(path.get()));
}
return deploymentNames.toArray(new String[0]);
}
return new String[0];
}
代码示例来源:origin: shrinkwrap/shrinkwrap
/**
* Ensure that the filter is used when merging.
*
* @throws Exception
*/
@Test
public void testMergeWithFilter() throws Exception {
Archive<?> archive = getArchive();
Archive<T> sourceArchive = createNewArchive();
ArchivePath location = new BasicPath("/", "test.properties");
ArchivePath locationTwo = new BasicPath("/", "test2.properties");
Asset asset = new ClassLoaderAsset(NAME_TEST_PROPERTIES);
Asset assetTwo = new ClassLoaderAsset(NAME_TEST_PROPERTIES_2);
sourceArchive.add(asset, location).add(assetTwo, locationTwo);
archive.merge(sourceArchive, Filters.include(".*test2.*"));
Assert.assertEquals("Should only have merged 1", 1, numAssets(archive));
Assert.assertTrue("Asset should have been added to path: " + locationTwo.get(),
this.compareAssets(archive.get(locationTwo).getAsset(), asset));
}
代码示例来源:origin: arquillian/arquillian-core
private boolean containsBeansXML(Archive<?> archive) {
Map<ArchivePath, Node> content = archive.getContent(Filters.include(".*/beans\\.xml"));
if (!content.isEmpty()) {
return true;
}
Map<ArchivePath, Node> nested = archive.getContent(Filters.include("/.*\\.(jar|war)"));
if (!nested.isEmpty()) {
for (ArchivePath path : nested.keySet()) {
try {
if (containsBeansXML(archive.getAsType(GenericArchive.class, path))) {
return true;
}
} catch (IllegalArgumentException e) {
// no-op, Nested archive is not a ShrinkWrap archive.
}
}
}
return false;
}
}
代码示例来源:origin: shrinkwrap/shrinkwrap
@Test
public void shouldBeAbleToImportADirectoryWithIncludeFilter() throws Exception {
String fileName = SecurityActions.getThreadContextClassLoader().getResource(EXISTING_DIRECTORY_RESOURCE).toURI().getPath();
Archive<?> archive = ShrinkWrap
.create(ExplodedImporter.class, "test.jar")
.importDirectory(fileName, Filters.include(".*META-INF.*"))
.as(JavaArchive.class);
Logger.getLogger(ExplodedImporterTestCase.class.getName()).info(archive.toString(true));
Assert.assertEquals("Archive should contains only 2 paths", 2, archive.getContent().size());
Assert.assertTrue("Nested files should be imported", archive.contains(new BasicPath("/META-INF/MANIFEST.FM")));
}
代码示例来源:origin: shrinkwrap/shrinkwrap
/**
* Ensure get content returns the correct map of content based on the given filter
*
* @throws Exception
*/
@Test
public void testToGetContentFiltered() throws Exception {
Archive<T> archive = getArchive();
ArchivePath location = new BasicPath("/", "test.properties");
ArchivePath locationTwo = new BasicPath("/", "test2.properties");
Asset asset = new ClassLoaderAsset(NAME_TEST_PROPERTIES);
Asset assetTwo = new ClassLoaderAsset(NAME_TEST_PROPERTIES_2);
archive.add(asset, location).add(assetTwo, locationTwo);
Map<ArchivePath, Node> content = archive.getContent(Filters.include(".*test2.*"));
final Node node1 = content.get(location);
final Node node2 = content.get(locationTwo);
Assert.assertEquals("Only 1 Asset should have been included", 1, content.size());
Assert.assertNull("Should not be included in content", node1);
Assert.assertNotNull("Should be included in content", node2);
}
代码示例来源:origin: shrinkwrap/shrinkwrap
/**
* Ensures that we may import a file and create an archive with matching structure with filter
*/
@Test
public void shouldBeAbleToImportFileWithFilter() throws Exception {
// Get the delegate
final ContentAssertionDelegateBase delegate = this.getDelegate();
assert delegate != null : "Delegate must be specified by implementations";
final File testFile = delegate.getExistingResource();
// Import
final Class<? extends StreamImporter<?>> importerClass = this.getImporterClass();
assert importerClass != null : "Importer class must be specified by implementations";
Archive<?> archive = ShrinkWrap.create(importerClass, "test.jar")
.importFrom(testFile, Filters.include(".*MANIFEST\\.MF")).as(JavaArchive.class);
// Ensure we don't have a null archive
Assert.assertNotNull("Should not return a null archive", archive);
// Validate the contents of the imported only contain filtered content
Assert.assertEquals(2, archive.getContent().size());
Assert.assertTrue(archive.contains(ArchivePaths.create("META-INF/MANIFEST.MF")));
}
代码示例来源:origin: shrinkwrap/shrinkwrap
@Test
public void testImportArchiveAsTypeFromFilterUsingDefaultFormat() throws Exception {
String resourcePath = "/test/cl-test.jar";
GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add(
new FileAsset(TestIOUtil.createFileFromResourceName("cl-test.jar")), resourcePath);
Collection<JavaArchive> jars = archive.getAsType(JavaArchive.class, Filters.include(".*jar"));
Assert.assertEquals("Unexpected result found", 1, jars.size());
JavaArchive jar = jars.iterator().next().add(new StringAsset("test file content"), "test.txt");
Assert.assertEquals("JAR imported with wrong name", resourcePath, jar.getName());
Assert.assertNotNull("Class in JAR not imported", jar.get("test/classloader/DummyClass.class"));
Assert.assertNotNull("Inner Class in JAR not imported",
jar.get("test/classloader/DummyClass$DummyInnerClass.class"));
Assert.assertNotNull("Should contain a new asset", ((ArchiveAsset) archive.get(resourcePath).getAsset())
.getArchive().get("test.txt"));
}
代码示例来源:origin: shrinkwrap/shrinkwrap
@Test
public void shouldBeAbleToImportADirectoryWithExcludeFilter() throws Exception {
String fileName = SecurityActions.getThreadContextClassLoader().getResource(EXISTING_DIRECTORY_RESOURCE).toURI().getPath();
Archive<?> archive = ShrinkWrap
.create(ExplodedImporter.class, "test.jar")
.importDirectory(fileName, Filters.exclude(".*META-INF.*"))
.as(JavaArchive.class);
Logger.getLogger(ExplodedImporterTestCase.class.getName()).info(archive.toString(true));
Assert.assertTrue("Root files should be imported", archive.contains(new BasicPath("/Test.properties")));
Assert.assertTrue("Nested files should be imported", archive.contains(new BasicPath("/org/jboss/Test.properties")));
Assert.assertTrue("Empty directories should be imported", archive.contains(new BasicPath("/empty_dir")));
Assert.assertTrue("Nested empty directories should be imported", archive.contains(new BasicPath("/parent/empty_dir")));
}
代码示例来源:origin: org.arquillian.ape/arquillian-ape-sql-container-dbunit
@Override
public Archive<?> createAuxiliaryArchive() {
final JavaArchive dbUnitExtensionArchive =
ShrinkWrap.create(JavaArchive.class, "arquillian-ape-sql-container-dbunit.jar")
.addPackages(true,
// exclude client package
Filters.exclude(DBUnitExtension.class.getPackage()),
"org.arquillian.ape.rdbms.dbunit")
.addPackages(true,
// Avoid slf4j implementation in case different impl is chosen in @Deployment
Filters.exclude(".*/org/slf4j/impl/.*"),
requiredLibraries())
.addAsServiceProvider(RemoteLoadableExtension.class, RemoteDBUnitExtension.class)
.addAsServiceProvider(TableFilterProvider.class, DefaultDatabaseSequenceFilterProvider.class,
OracleDatabaseSequenceFilterProvider.class);
return dbUnitExtensionArchive;
}
代码示例来源:origin: GoogleCloudPlatform/appengine-tck
public void process(Archive<?> archive, TestClass testClass) {
if (archive instanceof EnterpriseArchive) {
final EnterpriseArchive ear = (EnterpriseArchive) archive;
Map<ArchivePath, Node> wars = ear.getContent(Filters.include(".*\\.war"));
for (Map.Entry<ArchivePath, Node> war : wars.entrySet()) {
handleWebArchive(ear.getAsType(WebArchive.class, war.getKey()));
}
} else if (archive instanceof WebArchive) {
handleWebArchive((WebArchive) archive);
} else {
throw new IllegalArgumentException("Can only handle .ear or .war deployments: " + archive);
}
}
代码示例来源:origin: org.jboss.arquillian.extension/arquillian-jacoco
public Filter<ArchivePath> composeFilter() {
final List<Filter<ArchivePath>> includeFilter = new ArrayList<Filter<ArchivePath>>();
final List<Filter<ArchivePath>> excludeFilter = new ArrayList<Filter<ArchivePath>>();
for (String include : getIncludeRegexps()) {
includeFilter.add(Filters.include(include));
}
for (String exclude : getExcludeRegexps()) {
excludeFilter.add(Filters.exclude(exclude));
}
if (includeFilter.isEmpty() && excludeFilter.isEmpty()) {
includeFilter.add(ALL_CLASSES);
}
final Filter<ArchivePath> notExcluded = AndFilter.and(excludeFilter);
final Filter<ArchivePath> included = OrFilter.or(includeFilter);
return AndFilter.and(notExcluded, included);
}
代码示例来源:origin: org.jboss.arquillian.testng/arquillian-testng-container
@Override
protected Archive<?> buildArchive() {
JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "arquillian-testng.jar")
.addPackages(
true,
// exclude com.sun.javadoc.Doclet loading, not in OpenJDK
Filters.exclude("/org/testng/junit/.*|/org/testng/eclipse/.*"),
"org.testng",
"bsh",
"org.jboss.arquillian.testng")
.addAsServiceProvider(
TestRunner.class,
TestNGTestRunner.class);
/* Attempt to add Guice if on classpath. TestNG 5.12 > use Guice */
// exclude AOP Alliance reference, not provided as part of TestNG jar
optionalPackages(
archive,
Filters.exclude(".*/InterceptorStackCallback\\$InterceptedMethodInvocation.*"),
"com.google.inject");
/* Attempt to add com.beust, internal TestNG package 5.14 > */
optionalPackages(
archive,
Filters.includeAll(),
"com.beust");
return archive;
}
代码示例来源:origin: shrinkwrap/shrinkwrap
@Test
@ArchiveType(ClassContainer.class)
public void shouldExcludeOnlySelectedClasses() throws Exception {
getClassContainer().addPackages(true, Filters.exclude(DynamicContainerTestBase.class, ArchiveType.class),
DynamicContainerTestBase.class.getPackage().getName());
ArchivePath notExpectedPath = new BasicPath(getClassPath(),
AssetUtil.getFullPathForClassResource(DynamicContainerTestBase.class));
ArchivePath notExpectedPath2 = new BasicPath(getClassPath(),
AssetUtil.getFullPathForClassResource(ArchiveType.class));
Assert.assertFalse("Archive should not contain " + notExpectedPath.get(), getArchive()
.contains(notExpectedPath));
Assert.assertFalse("Archive should not contain " + notExpectedPath2.get(),
getArchive().contains(notExpectedPath2));
}
代码示例来源:origin: shrinkwrap/shrinkwrap
/**
* Ensure that the filter is used when merging.
*
* @throws Exception
*/
@Test
public void testMergeToStringPathWithFilter() throws Exception {
Archive<?> archive = getArchive();
Archive<T> sourceArchive = createNewArchive();
ArchivePath location = new BasicPath("/", "test.properties");
ArchivePath locationTwo = new BasicPath("/", "test2.properties");
Asset asset = new ClassLoaderAsset(NAME_TEST_PROPERTIES);
Asset assetTwo = new ClassLoaderAsset(NAME_TEST_PROPERTIES_2);
sourceArchive.add(asset, location).add(assetTwo, locationTwo);
String baseLocation = "somewhere";
archive.merge(sourceArchive, baseLocation, Filters.include(".*test2.*"));
Assert.assertEquals("Should only have merged 1", 1, numAssets(archive));
ArchivePath expectedPath = new BasicPath(baseLocation, locationTwo);
Assert.assertTrue("Asset should have been added to path: " + expectedPath.get(),
this.compareAssets(archive.get(expectedPath).getAsset(), asset));
}
代码示例来源:origin: arquillian/arquillian-extension-persistence
/**
* Inspects archive in order to find nested testable archive, assuming
*
* @return testable archive or passed one if nothing found
*/
private Archive<?> findTestableArchive(final Archive<?> archive) {
final Map<ArchivePath, Node> nestedArchives = archive.getContent(Filters.include(WAR_AND_JAR));
if (!nestedArchives.isEmpty()) {
for (ArchivePath path : nestedArchives.keySet()) {
try {
GenericArchive genericArchive = archive.getAsType(GenericArchive.class, path);
if (genericArchive != null && Testable.isArchiveToTest(genericArchive)) {
return genericArchive;
}
} catch (IllegalArgumentException e) {
// no-op, Nested archive is not a ShrinkWrap archive.
}
}
}
return archive;
}
代码示例来源:origin: shrinkwrap/shrinkwrap
@Test
public void testImportArchiveAsTypeFromFilter() throws Exception {
String resourcePath = "/test/cl-test.jar";
GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add(
new FileAsset(TestIOUtil.createFileFromResourceName("cl-test.jar")), resourcePath);
Collection<JavaArchive> jars = archive
.getAsType(JavaArchive.class, Filters.include(".*jar"), ArchiveFormat.ZIP);
Assert.assertEquals("Unexpected result found", 1, jars.size());
JavaArchive jar = jars.iterator().next().add(new StringAsset("test file content"), "test.txt");
Assert.assertEquals("JAR imported with wrong name", resourcePath, jar.getName());
Assert.assertNotNull("Class in JAR not imported", jar.get("test/classloader/DummyClass.class"));
Assert.assertNotNull("Inner Class in JAR not imported",
jar.get("test/classloader/DummyClass$DummyInnerClass.class"));
Assert.assertNotNull("Should contain a new asset", ((ArchiveAsset) archive.get(resourcePath).getAsset())
.getArchive().get("test.txt"));
}
代码示例来源:origin: org.jboss.arquillian.extension/arquillian-persistence-impl
@Override
public Archive<?> createAuxiliaryArchive()
{
final JavaArchive persistenceExtensionArchive = ShrinkWrap.create(JavaArchive.class, "arquillian-persistence.jar")
.addPackages(true,
// exclude client package
Filters.exclude(PersistenceExtension.class.getPackage()),
"org.jboss.arquillian.persistence")
.addPackages(true, requiredLibraries())
.addAsServiceProvider(RemoteLoadableExtension.class, RemotePersistenceExtension.class);
return persistenceExtensionArchive;
}
内容来源于网络,如有侵权,请联系作者删除!