Java Code Examples for org.jboss.shrinkwrap.api.spec.JavaArchive#addClass()
The following examples show how to use
org.jboss.shrinkwrap.api.spec.JavaArchive#addClass() .
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: ModuleTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@BeforeClass public static void beforeClass() throws Exception { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "Dummy.jar"); jar.addClass(ModuleTestCase.class); jarFile = new File(TestSuiteEnvironment.getTmpDir() + File.separator + "Dummy.jar"); jarFile2 = new File(TestSuiteEnvironment.getTmpDir() + File.separator + "Dummy2.jar"); new ZipExporterImpl(jar).exportTo(jarFile, true); new ZipExporterImpl(jar).exportTo(jarFile2, true); // Create an empty directory customModulesDirectory = new File(TestSuiteEnvironment.getTmpDir(), System.currentTimeMillis() + "-mymodules"); customModulesDirectory.mkdir(); AbstractCliTestBase.initCLI(); }
Example 2
Source File: QuarkusUnitTest.java From quarkus with Apache License 2.0 | 6 votes |
private void exportArchive(Path deploymentDir, Class<?> testClass) { try { JavaArchive archive = getArchiveProducerOrDefault(); Class<?> c = testClass; while (c != Object.class) { archive.addClass(c); c = c.getSuperclass(); } if (customApplicationProperties != null) { archive.add(new PropertiesAsset(customApplicationProperties), "application.properties"); } archive.as(ExplodedExporter.class).exportExplodedInto(deploymentDir.toFile()); //debugging code ExportUtil.exportToQuarkusDeploymentPath(archive); } catch (Exception e) { throw new RuntimeException("Unable to create the archive", e); } }
Example 3
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 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: ModuleOpsCompletionTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@BeforeClass public static void before() throws Exception { cleanUp(); cli = new CLIWrapper(true, null, System.in); final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "Dummy.jar"); jar.addClass(ModuleTestCase.class); jarFile = new File(TestSuiteEnvironment.getTmpDir() + File.separator + "Dummy.jar"); new ZipExporterImpl(jar).exportTo(jarFile, true); }
Example 7
Source File: BuildTest.java From pnc with Apache License 2.0 | 5 votes |
@Deployment public static EnterpriseArchive deploy() { final EnterpriseArchive ear = Deployments.testEarForInContainerTest(BuildTest.class); Deployments.addBuildExecutorMock(ear); JavaArchive coordinatorJar = ear.getAsType(JavaArchive.class, Deployments.COORDINATOR_JAR); coordinatorJar.addAsManifestResource("beans-use-mock-remote-clients.xml", "beans.xml"); coordinatorJar.addClass(RemoteBuildsCleanerMock.class); return ear; }
Example 8
Source File: SpringPropertyPlaceholderTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Deployment public static JavaArchive createDeployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "camel-spring-tests"); archive.addAsResource("spring/property-placeholder-context.xml", "spring-camel-context.xml"); archive.addClass(PropertyValueBean.class); return archive; }
Example 9
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 10
Source File: MainIT.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 4 votes |
@Test public void testNoUserMain() throws Throwable { JavaArchive archive = createBootstrapArchive(); JavaArchive app = ShrinkWrap.create(JavaArchive.class); app.addClass(MyMain.class); archive.add(new ArchiveAsset(app, ZipExporter.class), "_bootstrap/myapp.jar"); ClassLoader cl = createClassLoader(archive); Class<?> mainClass = cl.loadClass(Main.class.getName()); Constructor<?> ctor = mainClass.getConstructor(String[].class); Object main = ctor.newInstance((Object) new String[]{}); Method getMainClassName = mainClass.getMethod("getMainClassName"); String mainClassName = (String) getMainClassName.invoke(main); assertThat(mainClassName).isEqualTo(Main.DEFAULT_MAIN_CLASS_NAME); }
Example 11
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombineWithSpringDescriptors() throws Exception { File jar1 = new File("target/testCombine1Spring.jar"); File jar2 = new File("target/testCombine2Spring.jar"); File jar3 = new File("target/testCombine3Spring.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl"), "/META-INF/spring.foo"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl2"), "/META-INF/spring.foo"); jarArchive2.add(new StringAsset("com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"), "/META-INF/spring.bar"); 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/spring.foo"); 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 12
Source File: MainIT.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 4 votes |
@Test public void testRunWithoutError() throws Throwable { JavaArchive archive = createBootstrapArchive(MyMain.class.getName(), "_bootstrap/myapp.jar"); JavaArchive app = ShrinkWrap.create(JavaArchive.class); app.addClass(MyMain.class); archive.add(new ArchiveAsset(app, ZipExporter.class), "_bootstrap/myapp.jar"); ClassLoader cl = createClassLoader(archive); Class<?> mainClass = cl.loadClass(Main.class.getName()); Constructor<?> ctor = mainClass.getConstructor(String[].class); Object main = ctor.newInstance((Object) new String[]{}); Method run = mainClass.getMethod("run"); run.invoke(main); }
Example 13
Source File: LogIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Deployment public static JavaArchive createDeployment() { JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "log-tests"); return archive.addClass(LogUtils.class); }
Example 14
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 15
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombineWithSpringDescriptors() throws Exception { File jar1 = new File("target/testCombine1Spring.jar"); File jar2 = new File("target/testCombine2Spring.jar"); File jar3 = new File("target/testCombine3Spring.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl"), "/META-INF/spring.foo"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl2"), "/META-INF/spring.foo"); jarArchive2.add(new StringAsset("com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"), "/META-INF/spring.bar"); 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/spring.foo"); 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 16
Source File: LoggingFrameworkIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Deployment public static JavaArchive createDeployment() { JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "logger-tests"); return archive.addClass(LogUtils.class); }
Example 17
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); }
Example 18
Source File: ShrinkWrapArchiveUtil.java From deltaspike with Apache License 2.0 | 4 votes |
private static JavaArchive addFileArchive(File archiveBasePath, String[] includeIfPackageExists, String[] excludeIfPackageExists, String archiveName) throws IOException { if (!archiveBasePath.exists()) { return null; } if (archiveName == null) { archiveName = UUID.randomUUID().toString(); } JavaArchive ret = null; JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar"); if (includeIfPackageExists == null) { // no include rule, thus add it immediately ret = javaArchive; } int basePathLength = archiveBasePath.getAbsolutePath().length() + 1; for (File archiveEntry : collectArchiveEntries(archiveBasePath) ) { String entryName = archiveEntry.getAbsolutePath().substring(basePathLength); // exclude rule if (excludeIfPackageExists(entryName, excludeIfPackageExists)) { continue; } // include rule if (ret == null && includeIfPackageExists(entryName, includeIfPackageExists)) { ret = javaArchive; } if (entryName.endsWith(".class")) { String className = pathToClassName(entryName.substring(0, entryName.length() - (".class".length()))); try { javaArchive.addClass(className); } catch (Throwable t) { LOG.info("Ignoring class " + className + " due to " + t.getMessage()); } } else { javaArchive.addAsResource(archiveEntry, entryName.replace('\\', '/')); } } return ret; }
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: EarTest.java From tomee with Apache License 2.0 | 3 votes |
@Deployment(testable = false) public static EnterpriseArchive createDeployment() { final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "beans.jar"); ejbJar.addClass(Bean.class); final WebArchive webapp = ShrinkWrap.create(WebArchive.class, "green.war").addClass(Hello.class); final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "red.ear").addAsModule(ejbJar).addAsModule(webapp); ear.addAsLibraries(JarLocation.jarLocation(Test.class)); return ear; }