Java Code Examples for org.jboss.shrinkwrap.api.spec.JavaArchive#addAsServiceProvider()
The following examples show how to use
org.jboss.shrinkwrap.api.spec.JavaArchive#addAsServiceProvider() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StartSuspendedTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Before public void startContainer() throws Exception { // Start the server container.startSuspended(); managementClient = container.getClient(); //ServerDeploymentHelper helper = new ServerDeploymentHelper(managementClient.getControllerClient()); JavaArchive war = ShrinkWrap.create(JavaArchive.class, WEB_SUSPEND_JAR); war.addPackage(SuspendResumeHandler.class.getPackage()); war.addAsServiceProvider(ServiceActivator.class, TestSuspendServiceActivator.class); war.addAsResource(new StringAsset("Dependencies: org.jboss.dmr, org.jboss.as.controller, io.undertow.core, org.jboss.as.server,org.wildfly.extension.request-controller, org.jboss.as.network\n"), "META-INF/MANIFEST.MF"); war.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset( new RuntimePermission("createXnioWorker"), new SocketPermission(TestSuiteEnvironment.getServerAddress() + ":8080", "listen,resolve"), new SocketPermission("*", "accept,resolve") ), "permissions.xml"); //helper.deploy(WEB_SUSPEND_JAR, war.as(ZipExporter.class).exportAsInputStream()); serverController.deploy(war, WEB_SUSPEND_JAR); }
Example 2
Source File: ServiceActivatorDeploymentUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public static void createServiceActivatorDeployment(File destination, String objectName, Class mbeanClass) throws IOException { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class); archive.addClass(ServiceActivatorDeployment.class); archive.addClass(mbeanClass); archive.addAsServiceProvider(ServiceActivator.class, ServiceActivatorDeployment.class); StringBuilder sb = new StringBuilder(); sb.append(ServiceActivatorDeployment.MBEAN_CLASS_NAME); sb.append('='); sb.append(mbeanClass.getName()); sb.append("\n"); sb.append(ServiceActivatorDeployment.MBEAN_OBJECT_NAME); sb.append('='); sb.append(objectName); sb.append("\n"); archive.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset( getMBeanPermission(mbeanClass, objectName, "registerMBean"), getMBeanPermission(mbeanClass, objectName, "unregisterMBean"), new MBeanTrustPermission("register")), "permissions.xml"); archive.addAsManifestResource(new StringAsset("Dependencies: org.jboss.msc,org.jboss.as.jmx,org.jboss.as.server,org.jboss.as.controller\n"), "MANIFEST.MF"); archive.addAsResource(new StringAsset(sb.toString()), ServiceActivatorDeployment.PROPERTIES_RESOURCE); archive.as(ZipExporter.class).exportTo(destination); }
Example 3
Source File: DeploymentScenario.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private File createDeployment(Class<? extends ServiceActivator> clazz, String qualifier) throws Exception{ File tmpRoot = new File(System.getProperty("java.io.tmpdir")); File tmpDir = new File(tmpRoot, this.getClass().getSimpleName() + System.currentTimeMillis()); Files.createDirectory(tmpDir.toPath()); tmpDirs.add(tmpDir); String deploymentName = getDeploymentName(qualifier); File deployment = new File(tmpDir, deploymentName); final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, deploymentName); archive.addClasses(clazz, ServiceActivatorBaseDeployment.class); archive.addAsServiceProvider(ServiceActivator.class, clazz); archive.addAsManifestResource(new StringAsset("Dependencies: org.jboss.msc\n"), "MANIFEST.MF"); archive.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset( new PropertyPermission("test.deployment.broken.fail", "read"), new PropertyPermission("test.deployment.prop.one", "write"), new PropertyPermission("test.deployment.prop.two", "write"), new PropertyPermission("test.deployment.prop.three", "write"), new PropertyPermission("test.deployment.prop.four", "write") ), "permissions.xml"); archive.as(ZipExporter.class).exportTo(deployment); return deployment; }
Example 4
Source File: ServiceActivatorDeploymentUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public static void createServiceActivatorListenerArchiveForModule(File destination, String targetName, Class listenerClass) throws IOException { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class); archive.addClass(JMXNotificationsService.class); archive.addClass(listenerClass); archive.addClass(JMXControlledStateNotificationListenerExtension.class); archive.addClass(EmptySubsystemParser.class); archive.addAsServiceProvider(Extension.class, JMXControlledStateNotificationListenerExtension.class); StringBuilder sb = new StringBuilder(); sb.append(ServiceActivatorDeployment.LISTENER_CLASS_NAME); sb.append('='); sb.append(listenerClass.getName()); sb.append("\n"); sb.append(ServiceActivatorDeployment.LISTENER_OBJECT_NAME); sb.append('='); sb.append(targetName); sb.append("\n"); sb.append("keep.after.stop=true\n"); archive.addAsResource(new StringAsset(sb.toString()), JMXNotificationsService.PROPERTIES_RESOURCE); archive.as(ZipExporter.class).exportTo(destination); }
Example 5
Source File: ServiceActivatorDeploymentUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public static JavaArchive createServiceActivatorDeploymentArchive(String name, Map<String, String> properties) throws IOException { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, name); archive.addClass(ServiceActivatorDeployment.class); archive.addAsServiceProvider(ServiceActivator.class, ServiceActivatorDeployment.class); archive.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset( new PropertyPermission("test.deployment.trivial.prop", "write"), new PropertyPermission("service", "write"), new PropertyPermission("rbac", "write") ), "permissions.xml"); if (properties != null && properties.size() > 0) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> prop : properties.entrySet()) { sb.append(prop.getKey()); sb.append('='); sb.append(prop.getValue()); sb.append("\n"); } archive.addAsManifestResource(new StringAsset("Dependencies: org.jboss.msc\n"), "MANIFEST.MF"); archive.addAsResource(new StringAsset(sb.toString()), ServiceActivatorDeployment.PROPERTIES_RESOURCE); } return archive; }
Example 6
Source File: SuspendResumeTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@BeforeClass public static void deploy() throws Exception { //ServerDeploymentHelper helper = new ServerDeploymentHelper(managementClient.getControllerClient()); JavaArchive war = ShrinkWrap.create(JavaArchive.class, WEB_SUSPEND_JAR); war.addPackage(SuspendResumeHandler.class.getPackage()); war.addAsServiceProvider(ServiceActivator.class, TestSuspendServiceActivator.class); war.addAsResource(new StringAsset("Dependencies: org.jboss.dmr, org.jboss.as.controller, io.undertow.core, org.jboss.as.server,org.wildfly.extension.request-controller, org.jboss.as.network\n"), "META-INF/MANIFEST.MF"); war.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset( new RuntimePermission("createXnioWorker"), new SocketPermission(TestSuiteEnvironment.getServerAddress() + ":8080", "listen,resolve"), new SocketPermission("*", "accept,resolve") ), "permissions.xml"); //helper.deploy(WEB_SUSPEND_JAR, war.as(ZipExporter.class).exportAsInputStream()); serverController.deploy(war, WEB_SUSPEND_JAR); }
Example 7
Source File: CamelAuxiliaryArchiveAppender.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Override public Archive<?> createAuxiliaryArchive() { JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "wildfly-camel-testenricher.jar"); archive.addAsServiceProvider(RemoteLoadableExtension.class, CamelRemoteLoadableExtension.class); archive.addPackage(CamelLoadableExtension.class.getPackage()); return archive; }
Example 8
Source File: DeploymentRollbackFailureTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@BeforeClass public static void setupDomain() throws Exception { testSupport = DomainTestSuite.createSupport(DeploymentRollbackFailureTestCase.class.getSimpleName()); masterClient = testSupport.getDomainMasterLifecycleUtil().getDomainClient(); File tmpRoot = new File(System.getProperty("java.io.tmpdir")); tmpDir = new File(tmpRoot, DeploymentRollbackFailureTestCase.class.getSimpleName() + System.currentTimeMillis()); Files.createDirectory(tmpDir.toPath()); deployment = new File(tmpDir, BROKEN_DEPLOYMENT); final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, BROKEN_DEPLOYMENT); archive.addClass(ServiceActivatorDeployment.class); archive.addAsServiceProvider(ServiceActivator.class, ServiceActivatorDeployment.class); archive.addAsManifestResource(new StringAsset("Dependencies: org.jboss.msc\n"), "MANIFEST.MF"); archive.as(ZipExporter.class).exportTo(deployment); }
Example 9
Source File: DomainGracefulShutdownTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static JavaArchive createDeployment() throws Exception { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, WEB_SUSPEND_JAR); jar.addPackage(SuspendResumeHandler.class.getPackage()); jar.addAsServiceProvider(ServiceActivator.class, TestSuspendServiceActivator.class); jar.addAsResource(new StringAsset("Dependencies: org.jboss.dmr, org.jboss.as.controller, io.undertow.core, org.jboss.as.server,org.wildfly.extension.request-controller, org.jboss.as.network\n"), "META-INF/MANIFEST.MF"); jar.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset( new ReflectPermission("suppressAccessChecks"), new RuntimePermission("createXnioWorker"), new SocketPermission(TestSuiteEnvironment.getServerAddress() + ":8080", "listen,resolve"), new SocketPermission("*", "accept,resolve") ), "permissions.xml"); return jar; }
Example 10
Source File: ExtensionSetup.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static StreamExporter createResourceRoot(Class<? extends Extension> extension, Package... additionalPackages) throws IOException { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class); archive.addPackage(extension.getPackage()); if (additionalPackages != null) { for (Package pkg : additionalPackages) { archive.addPackage(pkg); } } archive.addAsServiceProvider(Extension.class, extension); return archive.as(ZipExporter.class); }
Example 11
Source File: SuspendOnSoftKillTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void startContainer(int suspendTimeout) throws Exception { suspendTimeout = suspendTimeout < 1 ? suspendTimeout : TimeoutUtil.adjust(suspendTimeout); jbossArgs = System.getProperty("jboss.args"); String newArgs = jbossArgs == null ? "" : jbossArgs; newArgs += " -D[Standalone] -Dorg.wildfly.sigterm.suspend.timeout=" + suspendTimeout; System.setProperty("jboss.args", newArgs); if (File.pathSeparatorChar == ':'){ processUtil = new UnixProcessUtil(); } else { processUtil = new WindowsProcessUtil(); } // Start the server serverController.start(); // If there's already the deployment there from a previous test, remove it try { serverController.undeploy(WEB_SUSPEND_JAR); } catch (Exception ignored) { // assume it wasn't deployed. if it was we'll fail below } JavaArchive war = ShrinkWrap.create(JavaArchive.class, WEB_SUSPEND_JAR); war.addPackage(SuspendResumeHandler.class.getPackage()); war.addAsServiceProvider(ServiceActivator.class, TestSuspendServiceActivator.class); war.addAsResource(new StringAsset("Dependencies: org.jboss.dmr, org.jboss.as.controller, io.undertow.core, org.jboss.as.server,org.wildfly.extension.request-controller, org.jboss.as.network\n"), "META-INF/MANIFEST.MF"); war.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset( new RuntimePermission("createXnioWorker"), new SocketPermission(TestSuiteEnvironment.getServerAddress() + ":8080", "listen,resolve"), new SocketPermission("*", "accept,resolve") ), "permissions.xml"); serverController.deploy(war, WEB_SUSPEND_JAR); }
Example 12
Source File: ExtensionSetup.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static StreamExporter createResourceRoot(Class<? extends Extension> extension, Package... additionalPackages) throws IOException { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class); archive.addPackage(extension.getPackage()); if (additionalPackages != null) { for (Package pkg : additionalPackages) { archive.addPackage(pkg); } } archive.addAsServiceProvider(Extension.class, extension); return archive.as(ZipExporter.class); }
Example 13
Source File: ExtensionUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static StreamExporter createResourceRoot(Class<? extends Extension> extension, Package... additionalPackages) throws IOException { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class); storePackage(extension.getPackage(), extension.getClassLoader(), archive); if (additionalPackages != null) { for (Package pkg : additionalPackages) { storePackage(pkg, extension.getClassLoader(), archive); } } archive.addAsServiceProvider(Extension.class, extension); return archive.as(ZipExporter.class); }
Example 14
Source File: ServiceActivatorDeploymentUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static void createServiceActivatorListenerDeployment(File destination, String targetName, Class listenerClass, Collection<Permission> additionalPermissions) throws IOException { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class); archive.addClass(ServiceActivatorDeployment.class); archive.addClass(listenerClass); archive.addAsServiceProvider(ServiceActivator.class, ServiceActivatorDeployment.class); StringBuilder sb = new StringBuilder(); sb.append(ServiceActivatorDeployment.LISTENER_CLASS_NAME); sb.append('='); sb.append(listenerClass.getName()); sb.append("\n"); sb.append(ServiceActivatorDeployment.LISTENER_OBJECT_NAME); sb.append('='); sb.append(targetName); sb.append("\n"); archive.addAsManifestResource(new StringAsset("Dependencies: org.jboss.msc,org.jboss.as.jmx,org.jboss.logging,org.jboss.as.server,org.jboss.as.controller\n"), "MANIFEST.MF"); archive.addAsResource(new StringAsset(sb.toString()), ServiceActivatorDeployment.PROPERTIES_RESOURCE); Path targetPath = destination.getParentFile().getParentFile().toPath(); List<Permission> permissions = new ArrayList<>(Arrays.asList( new FilePermission(destination.getAbsolutePath() .replace("archives", "wildfly-core") .replace(destination.getName(), ""), "read"), new FilePermission("target", "read, write"), new FilePermission("target/notifications", "read, write"), new FilePermission("target/notifications/-", "read, write"), new FilePermission(targetPath.toAbsolutePath().toString(), "read"), new FilePermission(targetPath.resolve("notifications").toAbsolutePath().toString(), "read, write"), new FilePermission(targetPath.resolve("notifications").toAbsolutePath().toString() + File.separatorChar + '-', "read, write"), getMBeanPermission(RunningStateJmx.class, targetName, "addNotificationListener"), getMBeanPermission(RunningStateJmx.class, targetName, "removeNotificationListener"), new PropertyPermission("user.dir", "read") )); if(additionalPermissions != null && !additionalPermissions.isEmpty()) { permissions.addAll(additionalPermissions); } archive.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(permissions.toArray(new Permission[permissions.size()])), "permissions.xml"); archive.as(ZipExporter.class).exportTo(destination); }
Example 15
Source File: DeploymentProcessor.java From thorntail with Apache License 2.0 | 5 votes |
@Override public void process(Archive<?> archive, TestClass testClass) { JavaArchive extensionsJar = ShrinkWrap.create(JavaArchive.class,"mp-ot-mocktracer-resolver.jar") .addAsServiceProvider(TracerResolver.class, MockTracerResolver.class); extensionsJar.addAsServiceProvider(Providers.class, ExceptionMapper.class); extensionsJar.addClass(MockTracerResolver.class); extensionsJar.addClass(ExceptionMapper.class); extensionsJar.addPackages(true, "io.opentracing.tracerresolver", "io.opentracing.mock"); WebArchive war = WebArchive.class.cast(archive); war.addAsLibraries(extensionsJar); war.setWebXML("web.xml"); }
Example 16
Source File: DomainSuspendResumeTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static JavaArchive createDeployment() throws Exception { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, WEB_SUSPEND_JAR); jar.addPackage(SuspendResumeHandler.class.getPackage()); jar.addAsServiceProvider(ServiceActivator.class, TestSuspendServiceActivator.class); jar.addAsResource(new StringAsset("Dependencies: org.jboss.dmr, org.jboss.as.controller, io.undertow.core, org.jboss.as.server,org.wildfly.extension.request-controller, org.jboss.as.network\n"), "META-INF/MANIFEST.MF"); jar.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset( new ReflectPermission("suppressAccessChecks"), new RuntimePermission("createXnioWorker"), new SocketPermission(TestSuiteEnvironment.getServerAddress() + ":8080", "listen,resolve"), new SocketPermission("*", "accept,resolve") ), "permissions.xml"); return jar; }
Example 17
Source File: CustomConverterTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Deployment public static JavaArchive deployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "converter-tests"); archive.addClasses(Customer.class, CustomConverter.class); archive.addAsServiceProvider("org/apache/camel/TypeConverter", CustomConverter.class.getPackage().getName()); return archive; }
Example 18
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombine() throws Exception { File jar1 = new File("target/testCombine1.jar"); File jar2 = new File("target/testCombine2.jar"); File jar3 = new File("target/testCombine3.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); jarArchive2.addAsServiceProvider("com.test.demo.DemoSP2", "com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"); jarArchive2.as(ZipExporter.class).exportTo(jar2, true); JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class); jarArchive3.addClass(SPICombineTest.class); jarArchive3.as(ZipExporter.class).exportTo(jar3, true); Set<Artifact> artifacts = new LinkedHashSet<>(); Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0", "compile", "jar", "", null); a1.setFile(jar1); Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0", "compile", "jar", "", null); a2.setFile(jar2); Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0", "compile", "jar", "", null); a3.setFile(jar3); artifacts.add(a1); artifacts.add(a2); artifacts.add(a3); MavenProject project = new MavenProject(); project.setVersion("1.0"); project.setArtifactId("foo"); AbstractVertxMojo mojo = new AbstractVertxMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.setLog(new SystemStreamLog()); Build build = new Build(); build.setOutputDirectory("target/junk"); project.setBuild(build); ServiceFileCombinationConfig config = new ServiceFileCombinationConfig() .setProject(project) .setArtifacts(artifacts) .setArchive(ServiceUtils.getDefaultFatJar()) .setMojo(mojo); combiner.doCombine(config); File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI"); assertThat(merged).isFile(); List<String> lines = FileUtils.readLines(merged, "UTF-8"); assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly); }
Example 19
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombine() throws Exception { File jar1 = new File("target/testCombine1.jar"); File jar2 = new File("target/testCombine2.jar"); File jar3 = new File("target/testCombine3.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); jarArchive2.addAsServiceProvider("com.test.demo.DemoSP2", "com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"); jarArchive2.as(ZipExporter.class).exportTo(jar2, true); JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class); jarArchive3.addClass(SPICombineTest.class); jarArchive3.as(ZipExporter.class).exportTo(jar3, true); Set<Artifact> artifacts = new LinkedHashSet<>(); Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0", "compile", "jar", "", null); a1.setFile(jar1); Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0", "compile", "jar", "", null); a2.setFile(jar2); Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0", "compile", "jar", "", null); a3.setFile(jar3); artifacts.add(a1); artifacts.add(a2); artifacts.add(a3); MavenProject project = new MavenProject(); project.setVersion("1.0"); project.setArtifactId("foo"); AbstractVertxMojo mojo = new AbstractVertxMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.setLog(new SystemStreamLog()); Build build = new Build(); build.setOutputDirectory("target/junk"); project.setBuild(build); ServiceFileCombinationConfig config = new ServiceFileCombinationConfig() .setProject(project) .setArtifacts(artifacts) .setArchive(ServiceUtils.getDefaultFatJar()) .setMojo(mojo); combiner.doCombine(config); File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI"); assertThat(merged).isFile(); List<String> lines = FileUtils.readLines(merged, "UTF-8"); assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly); }
Example 20
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombineDiffSPI() throws Exception { File jar1 = new File("target/testCombineDiffSPI.jar"); File jar2 = new File("target/testCombineDiffSPI2.jar"); File jar3 = new File("target/testCombineDiffSPI3.jar"); File jar4 = new File("target/testCombineDiffSPI4.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); jarArchive2.as(ZipExporter.class).exportTo(jar2, true); JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class); jarArchive3.addClass(SPICombineTest.class); jarArchive3.as(ZipExporter.class).exportTo(jar3, true); JavaArchive jarArchive4 = ShrinkWrap.create(JavaArchive.class); jarArchive4.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl4"); jarArchive4.as(ZipExporter.class).exportTo(jar4, true); Set<Artifact> artifacts = new LinkedHashSet<>(); Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0", "compile", "jar", "", null); a1.setFile(jar1); Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0", "compile", "jar", "", null); a2.setFile(jar2); Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0", "compile", "jar", "", null); a3.setFile(jar3); Artifact a4 = new DefaultArtifact("org.acme", "a4", "1.0", "compile", "jar", "", null); a4.setFile(jar4); artifacts.add(a1); artifacts.add(a2); artifacts.add(a3); artifacts.add(a4); MavenProject project = new MavenProject(); project.setVersion("1.0"); project.setArtifactId("foo"); AbstractVertxMojo mojo = new AbstractVertxMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.setLog(new SystemStreamLog()); Build build = new Build(); build.setOutputDirectory("target/junk"); project.setBuild(build); ServiceFileCombinationConfig config = new ServiceFileCombinationConfig() .setProject(project) .setArtifacts(artifacts) .setArchive(ServiceUtils.getDefaultFatJar()) .setMojo(mojo); combiner.doCombine(config); File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI"); assertThat(merged).isFile(); List<String> lines = FileUtils.readLines(merged, "UTF-8"); assertThat(lines).hasSize(3).containsExactly( "com.test.demo.DemoSPI.impl.DemoSPIImpl", "com.test.demo.DemoSPI.impl.DemoSPIImpl2", "com.test.demo.DemoSPI.impl.DemoSPIImpl4"); Stream.of(jar1, jar2, jar3, jar4, new File("target/junk")).forEach(FileUtils::deleteQuietly); }