org.jboss.shrinkwrap.api.asset.FileAsset Java Examples
The following examples show how to use
org.jboss.shrinkwrap.api.asset.FileAsset.
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: DefaultDeploymentFactory.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
protected boolean setupUsingAppPath(Archive<?> archive) throws IOException { final String appPath = System.getProperty(BootstrapProperties.APP_PATH); if (appPath != null) { final Path path = Paths.get(appPath); if (Files.isDirectory(path)) { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path simple = path.relativize(file); archive.add(new FileAsset(file.toFile()), convertSeparators(simple)); return super.visitFile(file, attrs); } }); } else { archive.as(ZipImporter.class) .importFrom(path.toFile()); } return true; } return false; }
Example #2
Source File: ServletContextTemplateLocatorTest.java From trimou with Apache License 2.0 | 6 votes |
@Deployment public static WebArchive createTestArchive() { return createTestArchiveBase() // WEB-INF/templates .addAsWebInfResource(new StringAsset("<html/>"), "templates/foo.html") .addAsWebInfResource(new StringAsset("<html/>"), "templates/qux.html") .addAsWebInfResource(new StringAsset("<xml/>"), "templates/alpha.xml") .addAsWebInfResource(new StringAsset("<html/>"), "templates/cool/charlie.html") // templates .addAsWebResource(new StringAsset("<html/>"), "templates/bart.html") .addAsWebResource(new StringAsset("<html/>"), "templates/html.html") .addAsWebResource( new FileAsset(new File( "src/test/resources/locator/file/encoding.html")), "templates/encoding.html") .addAsLibraries(resolve("org.trimou:trimou-extension-servlet")); }
Example #3
Source File: MoviesSeleniumTest.java From tomee with Apache License 2.0 | 6 votes |
private static void addResources(String source, String target, WebArchive archive) { File sourceFile = new File(source); if (! sourceFile.exists()) return; if (sourceFile.isFile()) { archive.add(new FileAsset(sourceFile), target); } if (sourceFile.isDirectory()) { final File[] files = sourceFile.listFiles(); if (files != null) { for (File file : files) { if (file.getName().startsWith(".")) continue; addResources(source + File.separator + file.getName(), target + File.separator + file.getName(), archive); } } } }
Example #4
Source File: HttpGenericOperationUnitTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private File createTempDeploymentZip() throws IOException { // Reuse the test deployment and add the random content file final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test-http-deployment.jar") .add(new FileAsset(randomContent), "file"); File temp = null; try { temp = File.createTempFile("test", "http-deployment"); archive.as(ZipExporter.class).exportTo(temp, true); } catch (IOException e) { if (temp != null) { temp.delete(); } throw e; } return temp; }
Example #5
Source File: DefaultJarDeploymentFactory.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
@Override public boolean setupUsingMaven(Archive<?> archive) throws Exception { Path pwd = Paths.get(System.getProperty("user.dir")); final Path classes = pwd.resolve("target").resolve("classes"); boolean success = false; if (Files.exists(classes)) { success = true; Files.walkFileTree(classes, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path simple = classes.relativize(file); archive.add(new FileAsset(file.toFile()), convertSeparators(simple)); return super.visitFile(file, attrs); } }); } //archive.addAllDependencies(); return success; }
Example #6
Source File: DefaultJarDeploymentFactory.java From thorntail with Apache License 2.0 | 6 votes |
@Override public boolean setupUsingMaven(Archive<?> archive) throws Exception { FileSystemLayout fsLayout = FileSystemLayout.create(); final Path classes = fsLayout.resolveBuildClassesDir(); boolean success = false; if (Files.exists(classes)) { success = true; Files.walkFileTree(classes, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path simple = classes.relativize(file); archive.add(new FileAsset(file.toFile()), convertSeparators(simple)); return super.visitFile(file, attrs); } }); } return success; }
Example #7
Source File: DefaultDeploymentFactory.java From thorntail with Apache License 2.0 | 6 votes |
protected boolean setupUsingAppPath(Archive<?> archive) throws IOException { final String appPath = System.getProperty(APP_PATH); if (appPath != null) { final Path path = Paths.get(appPath); if (Files.isDirectory(path)) { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path simple = path.relativize(file); archive.add(new FileAsset(file.toFile()), convertSeparators(simple)); return super.visitFile(file, attrs); } }); } else { archive.as(ZipImporter.class) .importFrom(path.toFile()); } return true; } return false; }
Example #8
Source File: DefaultWarDeploymentFactory.java From thorntail with Apache License 2.0 | 6 votes |
private void addFilesToArchive(final Path files, final DependenciesContainer<?> archive) throws Exception { Files.walkFileTree(files, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path simple = files.relativize(file); archive.add(new FileAsset(file.toFile()), "WEB-INF/classes/" + convertSeparators(simple)); // If the user's maven output is a jar then they may place // static content under src/main/resources, in which case // we need to hoist anything under WEB-INF out of there // and put it into the root of this archive instead of // under WEB-INF/classes/WEB-INF/foo if (simple.toString().contains("WEB-INF")) { archive.add(new FileAsset(file.toFile()), convertSeparators(simple)); } return super.visitFile(file, attrs); } }); }
Example #9
Source File: FileJolokiaAccessPreparer.java From thorntail with Apache License 2.0 | 5 votes |
@Override protected Asset getJolokiaAccessXmlAsset() { if (this.file.exists()) { return new FileAsset(this.file); } return null; }
Example #10
Source File: OpenEJBArchiveProcessor.java From tomee with Apache License 2.0 | 5 votes |
private static void addPersistenceXml(final Archive<?> archive, final String prefix, final AppModule appModule) { Node persistenceXml = archive.get(prefix.concat(PERSISTENCE_XML)); if (persistenceXml == null && WEB_INF.equals(prefix)) { persistenceXml = archive.get(WEB_INF_CLASSES.concat(META_INF).concat(PERSISTENCE_XML)); } if (persistenceXml != null) { final Asset asset = persistenceXml.getAsset(); if (UrlAsset.class.isInstance(asset)) { appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(URL.class, "url", asset))); } else if (FileAsset.class.isInstance(asset)) { try { appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(File.class, "file", asset).toURI().toURL())); } catch (final MalformedURLException e) { appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null))); } } else if (ClassLoaderAsset.class.isInstance(asset)) { final URL url = get(ClassLoader.class, "classLoader", asset).getResource(get(String.class, "resourceName", asset)); if (url != null) { appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(url)); } else { appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null))); } } else { appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null))); } } }
Example #11
Source File: SWClassLoader.java From tomee with Apache License 2.0 | 5 votes |
@Override protected URLConnection openConnection(final URL u) throws IOException { final String arName = key(u); final Archive<?> archive = archives.get(arName); final String path = path(archive.getName(), WebArchive.class.isInstance(archive) ? "/WEB-INF/classes/" : "", u); Node node = archive.get(path); if (node == null) { node = archive.get(path(archive.getName(), "", u)); // web resources if (node == null) { throw new IOException(u.toExternalForm() + " not found"); } } final Asset asset = node.getAsset(); if (UrlAsset.class.isInstance(asset)) { return URL.class.cast(Reflections.get(asset, "url")).openConnection(); } else if (FileAsset.class.isInstance(asset)) { return File.class.cast(Reflections.get(asset, "file")).toURI().toURL().openConnection(); } else if (ClassLoaderAsset.class.isInstance(asset)) { return ClassLoader.class.cast(Reflections.get(asset, "classLoader")).getResource(String.class.cast(Reflections.get(asset, "resourceName"))).openConnection(); } return new URLConnection(u) { @Override public void connect() throws IOException { // no-op } @Override public InputStream getInputStream() throws IOException { final InputStream input = asset.openStream(); final Collection<Closeable> c = closeables.get(arName); c.add(input); return input; } }; }
Example #12
Source File: AuthBeanTest.java From tomee with Apache License 2.0 | 5 votes |
@Deployment(testable = false) public static WebArchive createDeployment() { return ShrinkWrap.create(WebArchive.class, "low-typed-realm.war") .addClasses(SecuredServlet.class, AuthBean.class) .addAsManifestResource(new FileAsset(new File("src/main/webapp/META-INF/context.xml")), "context.xml") .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); }
Example #13
Source File: JerseyApplicationTest.java From tomee with Apache License 2.0 | 5 votes |
@Deployment(testable = false) public static WebArchive createDeployment() { return ShrinkWrap.create(WebArchive.class, "jersey-application.war") .addPackage(JerseyApplication.class.getPackage()) .addPackage(Person.class.getPackage()) .addPackage(PersonDAO.class.getPackage()) .addAsManifestResource(new FileAsset(new File("src/main/webapp/WEB-INF/web.xml")), "web.xml") .addAsManifestResource(new ClassLoaderAsset("META-INF/persistence.xml"), "persistence.xml") .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); }
Example #14
Source File: RabbitMQConfigurationTest.java From hammock with Apache License 2.0 | 5 votes |
@Deployment public static JavaArchive create() { return ShrinkWrap.create(JavaArchive.class) .addClasses(RabbitMQConfiguration.class, ConnectionFactoryProducer.class) .addPackage("io.astefanutti.metrics.cdi") .addAsServiceProviderAndClasses(Extension.class) .addAsManifestResource(new FileAsset(new File("src/main/resources/META-INF/beans.xml")), "beans.xml"); }
Example #15
Source File: ListenerTest.java From hammock with Apache License 2.0 | 5 votes |
public static JavaArchive createArchive(Class<?>... classes) { String property = System.getProperty(Bootstrapper.class.getName()); return ShrinkWrap.create(JavaArchive.class) .addClasses(DefaultServlet.class, HammockRuntime.class, MessageProvider.class, DefaultListener.class, WebServerConfiguration.class, StartWebServer.class) .addClasses(classes) .addAsServiceProvider(Bootstrapper.class.getName(), property) .addAsManifestResource(new FileAsset(new File("src/main/resources/META-INF/beans.xml")), "beans.xml"); }
Example #16
Source File: ServletTest.java From hammock with Apache License 2.0 | 5 votes |
public static JavaArchive createArchive(Class<?>... classes) { String property = System.getProperty(Bootstrapper.class.getName()); return ShrinkWrap.create(JavaArchive.class) .addClasses(DefaultServlet.class, MessageProvider.class, HammockRuntime.class, WebServerConfiguration.class, StartWebServer.class) .addClasses(classes) .addAsServiceProvider(Bootstrapper.class.getName(), property) .addAsManifestResource(new FileAsset(new File("src/main/resources/META-INF/beans.xml")), "beans.xml"); }
Example #17
Source File: TopCDsEndpointTest.java From microprofile-samples with Apache License 2.0 | 5 votes |
@Deployment public static Archive<?> archive() { if (System.getProperty("arquillian.launch", "").equals("arquillian-hammock")) { return ShrinkWrap.create(JavaArchive.class) .addClasses(RestApplication.class, TopCDsEndpoint.class, QLogger.class, ResourceProducer.class); } else { return ShrinkWrap.create(WebArchive.class).addClass(RestApplication.class).addClass(TopCDsEndpoint.class) .addClass(ResourceProducer.class).addAsWebInfResource(new FileAsset(new File("src/main/webapp/WEB-INF/beans.xml")), "beans.xml"); } }
Example #18
Source File: BuildTool.java From thorntail with Apache License 2.0 | 5 votes |
private void addArtifactToArchiveMavenRepository(Archive archive, ArtifactSpec artifact) throws Exception { if (!artifact.isResolved()) { throw new IllegalArgumentException("Artifact should be resolved!"); } StringBuilder artifactPath = new StringBuilder("m2repo/"); artifactPath.append(artifact.repoPath(true)); archive.add(new FileAsset(artifact.file), artifactPath.toString()); }
Example #19
Source File: ArquillianPackager.java From camel-spring-boot with Apache License 2.0 | 5 votes |
private static JavaArchive addDependencies(JavaArchive ark, Collection<File> deps) { Set<File> dependencySet = new HashSet<>(deps); for (File d : dependencySet) { debug("Adding spring-boot dependency: " + d.getName()); ark = ark.add(new FileAsset(d), LIB_FOLDER + "/" + d.getName()); } return ark; }
Example #20
Source File: DefaultWarDeploymentFactory.java From thorntail with Apache License 2.0 | 5 votes |
public boolean setupUsingMaven(final Archive<?> givenArchive) throws Exception { final DependenciesContainer<?> archive = (DependenciesContainer<?>) givenArchive; FileSystemLayout fsLayout = FileSystemLayout.create(); final Path classes = fsLayout.resolveBuildClassesDir(); boolean success = false; if (Files.exists(classes)) { success = true; addFilesToArchive(classes, archive); } // If it a gradle project, the reources are seperated from the class files. final Path resources = fsLayout.resolveBuildResourcesDir(); if (!Files.isSameFile(resources, classes) && Files.exists(resources)) { success = true; addFilesToArchive(resources, archive); } final Path webapp = fsLayout.resolveSrcWebAppDir(); if (Files.exists(webapp)) { success = true; Files.walkFileTree(webapp, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path simple = webapp.relativize(file); archive.add(new FileAsset(file.toFile()), convertSeparators(simple)); return super.visitFile(file, attrs); } }); } archive.addAllDependencies(); return success; }
Example #21
Source File: FilterTest.java From hammock with Apache License 2.0 | 4 votes |
public static JavaArchive createArchive(Class<?>...classes) { return ShrinkWrap.create(JavaArchive.class) .addClasses(DefaultFilter.class, HammockRuntime.class, WebServerConfiguration.class, StartWebServer.class) .addClasses(classes) .addAsManifestResource(new FileAsset(new File("src/main/resources/META-INF/beans.xml")), "beans.xml"); }
Example #22
Source File: WebArchiveBuilder.java From ozark with Apache License 2.0 | 4 votes |
public WebArchiveBuilder addView(File file, String name) { return this.addView(new FileAsset(file), name); }
Example #23
Source File: RARArchiveImpl.java From thorntail with Apache License 2.0 | 4 votes |
@Override public RARArchive resourceAdapter(final File ironjacamarFile) { getArchive().add(new FileAsset(ironjacamarFile), "META-INF/ironjacamar.xml"); return this; }
Example #24
Source File: WebArchiveBuilder.java From krazo with Apache License 2.0 | 4 votes |
public WebArchiveBuilder addView(File file, String name) { return this.addView(new FileAsset(file), name); }
Example #25
Source File: DependencyManager.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 3 votes |
public void addArtifactToArchiveMavenRepository(Archive archive, ArtifactSpec artifact) throws Exception { if (artifact.gathered) { return; } artifact = resolveArtifact(artifact); StringBuilder artifactPath = new StringBuilder("m2repo/"); artifactPath.append(artifact.repoPath(true)); archive.add(new FileAsset(artifact.file), artifactPath.toString()); artifact.gathered = true; }