public void addLibrary(LibraryContainer deployment, String coordinate) { deployment.addAsLibraries(getDependency(coordinate)); }
private static void enrichWithDefaultCucumber(final LibraryContainer<?> libraryContainer) { libraryContainer.addAsLibraries( jarLocation(Mapper.class), jarLocation(ResourceLoaderClassFinder.class), jarLocation(ConverterRegistry.class), jarLocation(JavaBackend.class)); for (final String potential : asList( "cucumber.api.junit.Cucumber", "cucumber.api.testng.TestNGCucumberRunner", "cucumber.runtime.java8.LambdaGlueBase")) { try { libraryContainer.addAsLibraries(jarLocation(Thread.currentThread().getContextClassLoader().loadClass(potential))); } catch (final Throwable e) { // no-op } } }
private static void tryToAdd(final Collection<ArchivePath> paths, final LibraryContainer<?> container, final String exclusion, final String... classes) { final Collection<File> files = new ArrayList<File>(); try { // if scala dsl is here, add it for (final String clazz : classes) { final File file = jarLocation(load(clazz)); boolean found = false; for (final ArchivePath ap : paths) { final String path = ap.get(); if (path.contains(exclusion) && path.endsWith(".jar")) { found = true; break; } } if (!found) { files.add(file); } } } catch (final Exception e) { return; // if any jar is missing don't add it } container.addAsLibraries(files.toArray(new File[files.size()])); }
@Override public Archive<?> generateDeployment(final TestDeployment testDeployment, final Collection<ProtocolArchiveProcessor> processors) { // Merge auxiliary archives with the declared for ARQ and testrunner support final Archive archive = testDeployment.getApplicationArchive(); if (log.isLoggable(Level.FINEST)) { log.finest("Archive before additional packaging: " + archive.toString(true)); } if (Validate.isArchiveOfType(WebArchive.class, archive)) { ((LibraryContainer<?>) archive).addAsLibraries(testDeployment.getAuxiliaryArchives()); } else { mergeAuxAsClasses(archive, testDeployment); } if (log.isLoggable(Level.FINEST)) { log.finest("Archive after additional packaging: " + archive.toString(true)); } return archive; }
@Override public Archive<?> generateDeployment(final TestDeployment testDeployment, final Collection<ProtocolArchiveProcessor> processors) { // Merge auxiliary archives with the declared for ARQ and testrunner support final Archive<?> archive = testDeployment.getApplicationArchive(); if (log.isLoggable(Level.FINEST)) { log.finest("Archive before additional packaging: " + archive.toString(true)); } if (Validate.isArchiveOfType(WebArchive.class, archive)) { ((LibraryContainer<?>) archive).addAsLibraries(testDeployment.getAuxiliaryArchives()); } else { mergeAuxAsClasses(archive, testDeployment); } if (log.isLoggable(Level.FINEST)) { log.finest("Archive after additional packaging: " + archive.toString(true)); } return archive; }
.importDependencies(scopes).resolve().withTransitivity().asFile(); if (deps.length > 0) { LibraryContainer.class.cast(webArchive).addAsLibraries(deps);
.importDependencies(scopes).resolve().withTransitivity().asFile(); if (deps.length > 0) { LibraryContainer.class.cast(webArchive).addAsLibraries(deps);
/** * Process libraries. * * @param archive */ protected void processLibraries(LibraryContainer<?> archive) { if (libraries != null) { for (LibraryDescriptor descriptor : libraries) { if (descriptor.getFileDescriptor() != null) { archive.addAsLibrary(descriptor.getFileDescriptor()); } else { archive.addAsLibrary(descriptor.buildJarArchive()); } } } if (shrinkWrapLibraries != null) { archive.addAsLibraries(shrinkWrapLibraries); } }
@Test @ArchiveType(LibraryContainer.class) public void testAddLibrariesArchiveCollection() throws Exception { Archive<?> archive = createNewArchive(); Archive<?> archive2 = createNewArchive(); final Collection<Archive<?>> archives = new ArrayList<Archive<?>>(); archives.add(archive); archives.add(archive2); getLibraryContainer().addAsLibraries(archives); ArchivePath testPath = new BasicPath(getLibraryPath(), archive.getName()); ArchivePath testPath2 = new BasicPath(getLibraryPath(), archive.getName()); Assert.assertTrue("Archive should contain " + testPath, getArchive().contains(testPath)); Assert.assertTrue("Archive should contain " + testPath2, getArchive().contains(testPath2)); }
@Test @ArchiveType(LibraryContainer.class) public void testAddLibrariesResource() throws Exception { getLibraryContainer().addAsLibraries(NAME_TEST_PROPERTIES, NAME_TEST_PROPERTIES_2); ArchivePath testPath = new BasicPath(getLibraryPath(), NAME_TEST_PROPERTIES); ArchivePath testPath2 = new BasicPath(getLibraryPath(), NAME_TEST_PROPERTIES_2); Assert.assertTrue("Archive should contain " + testPath, getArchive().contains(testPath)); Assert.assertTrue("Archive should contain " + testPath2, getArchive().contains(testPath2)); }
@Test(expected = IllegalArgumentException.class) @ArchiveType(LibraryContainer.class) public void testAddLibrariesArchiveArraysWithNullArguments() throws Exception { Archive<?> archive1 = createNewArchive(); Archive<?> archive2 = createNewArchive(); Archive<?> archive3 = createNewArchive(); Archive<?> archive4 = createNewArchive(); Archive<?>[] archives = { archive1, archive2, archive3, archive4 }; getLibraryContainer().addAsLibraries(archives, null, null); }
@Test @ArchiveType(LibraryContainer.class) public void testAddLibrariesFile() throws Exception { getLibraryContainer().addAsLibraries(getFileForClassResource(NAME_TEST_PROPERTIES), getFileForClassResource(NAME_TEST_PROPERTIES_2)); ArchivePath testPath = new BasicPath(getLibraryPath(), "Test.properties"); ArchivePath testPath2 = new BasicPath(getLibraryPath(), "Test2.properties"); Assert.assertTrue("Archive should contain " + testPath, getArchive().contains(testPath)); Assert.assertTrue("Archive should contain " + testPath2, getArchive().contains(testPath2)); }
@Test(expected = IllegalArgumentException.class) @ArchiveType(LibraryContainer.class) public void testAddLibrariesArchiveArraysWithNullValues() throws Exception { Archive<?> archive1 = createNewArchive(); Archive<?> archive2 = createNewArchive(); Archive<?> archive3 = createNewArchive(); Archive<?> archive4 = createNewArchive(); Archive<?>[] archives = { archive1, archive2, archive3, null, archive4, null }; getLibraryContainer().addAsLibraries(archives); }
@Test @ArchiveType(LibraryContainer.class) public void testAddLibrariesArchive() throws Exception { Archive<?> archive = createNewArchive(); Archive<?> archive2 = createNewArchive(); getLibraryContainer().addAsLibraries(archive, archive2); ArchivePath testPath = new BasicPath(getLibraryPath(), archive.getName()); ArchivePath testPath2 = new BasicPath(getLibraryPath(), archive.getName()); Assert.assertTrue("Archive should contain " + testPath, getArchive().contains(testPath)); Assert.assertTrue("Archive should contain " + testPath2, getArchive().contains(testPath2)); }
@Test @ArchiveType(LibraryContainer.class) public void testAddLibrariesArchiveArrays() throws Exception { Archive<?> archive1 = createNewArchive(); Archive<?> archive2 = createNewArchive(); Archive<?> archive3 = createNewArchive(); Archive<?> archive4 = createNewArchive(); Archive<?>[] archiveArray1 = { archive1, archive2 }; Archive<?>[] archiveArray2 = { archive3, archive4 }; getLibraryContainer().addAsLibraries(archiveArray1, archiveArray2); ArchivePath testPath1 = new BasicPath(getLibraryPath(), archive1.getName()); ArchivePath testPath2 = new BasicPath(getLibraryPath(), archive2.getName()); ArchivePath testPath3 = new BasicPath(getLibraryPath(), archive3.getName()); ArchivePath testPath4 = new BasicPath(getLibraryPath(), archive4.getName()); Assert.assertTrue("Archive should contain " + testPath1, getArchive().contains(testPath1)); Assert.assertTrue( "Archive should contain " + testPath2, getArchive().contains(testPath2)); Assert.assertTrue("Archive should contain " + testPath3, getArchive().contains(testPath3)); Assert.assertTrue("Archive should contain " + testPath4, getArchive().contains(testPath4)); }