use of org.jboss.shrinkwrap.impl.base.path.BasicPath in project camel by apache.
the class ArquillianPackager method addSpringbootPackage.
private static JavaArchive addSpringbootPackage(JavaArchive ark, String... packageNames) throws Exception {
Iterable<ClassLoader> classLoaders = Collections.singleton(Thread.currentThread().getContextClassLoader());
for (String packageName : packageNames) {
for (final ClassLoader classLoader : classLoaders) {
final URLPackageScanner.Callback callback = new URLPackageScanner.Callback() {
@Override
public void classFound(String className) {
ArchivePath classNamePath = AssetUtil.getFullPathForClassResource(className);
Asset asset = new ClassLoaderAsset(classNamePath.get().substring(1), classLoader);
ArchivePath location = new BasicPath(CLASSES_FOLDER + "/", classNamePath);
ark.add(asset, location);
}
};
final URLPackageScanner scanner = URLPackageScanner.newInstance(true, classLoader, callback, packageName);
scanner.scanPackage();
}
}
return ark;
}
use of org.jboss.shrinkwrap.impl.base.path.BasicPath in project wildfly-swarm by wildfly-swarm.
the class DefaultDeploymentScenarioGenerator method generate.
@Override
public List<DeploymentDescription> generate(TestClass testClass) {
DefaultDeployment anno = testClass.getAnnotation(DefaultDeployment.class);
if (anno == null) {
return super.generate(testClass);
}
String classPrefix = (anno.type() == DefaultDeployment.Type.JAR ? "" : "WEB-INF/classes");
Archive<?> archive;
if (DefaultDeployment.Type.WAR.equals(anno.type())) {
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, testClass.getJavaClass().getSimpleName() + ".war");
// Add the marker to also include the project dependencies
MarkerContainer.addMarker(webArchive, DependenciesContainer.ALL_DEPENDENCIES_MARKER);
archive = webArchive;
} else {
archive = ShrinkWrap.create(JavaArchive.class, testClass.getJavaClass().getSimpleName() + ".jar");
}
ClassLoader cl = testClass.getJavaClass().getClassLoader();
Set<CodeSource> codeSources = new HashSet<>();
URLPackageScanner.Callback callback = (className, asset) -> {
ArchivePath classNamePath = AssetUtil.getFullPathForClassResource(className);
ArchivePath location = new BasicPath(classPrefix, classNamePath);
archive.add(asset, location);
try {
Class<?> cls = cl.loadClass(className);
codeSources.add(cls.getProtectionDomain().getCodeSource());
} catch (ClassNotFoundException | NoClassDefFoundError e) {
// e.printStackTrace();
}
};
URLPackageScanner scanner = URLPackageScanner.newInstance(true, cl, callback, testClass.getJavaClass().getPackage().getName());
scanner.scanPackage();
Set<String> prefixes = codeSources.stream().map(e -> e.getLocation().toExternalForm()).collect(Collectors.toSet());
try {
List<URL> resources = Collections.list(cl.getResources(""));
resources.stream().filter(e -> {
for (String prefix : prefixes) {
if (e.toExternalForm().startsWith(prefix)) {
return true;
}
}
return false;
}).filter(e -> e.getProtocol().equals("file")).map(e -> getPlatformPath(e.getPath())).map(e -> Paths.get(e)).filter(e -> Files.isDirectory(e)).forEach(e -> {
try {
Files.walkFileTree(e, new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (!file.toString().endsWith(".class")) {
String location = javaSlashize(handleExceptionalCases(archive, e.relativize(file)));
archive.add(new FileAsset(file.toFile()), location);
}
return super.visitFile(file, attrs);
}
});
} catch (IOException e1) {
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
/*
Map<ArchivePath, Node> content = archive.getContent();
for (ArchivePath each : content.keySet()) {
System.err.println(" --> " + each);
}
*/
DeploymentModules deploymentModules = testClass.getAnnotation(DeploymentModules.class);
if (deploymentModules != null) {
for (DeploymentModule each : deploymentModules.value()) {
archive.as(JARArchive.class).addModule(each.name(), each.slot());
}
}
DeploymentModule deploymentModule = testClass.getAnnotation(DeploymentModule.class);
if (deploymentModule != null) {
archive.as(JARArchive.class).addModule(deploymentModule.name(), deploymentModule.slot());
}
DeploymentDescription description = new DeploymentDescription(testClass.getName(), archive);
Class<?> mainClass = anno.main();
if (mainClass != Void.class) {
archive.add(new StringAsset(mainClass.getName()), "META-INF/arquillian-main-class");
}
description.shouldBeTestable(anno.testable());
return Collections.singletonList(description);
}
use of org.jboss.shrinkwrap.impl.base.path.BasicPath in project wildfly by wildfly.
the class ServletResourceOverlaysTestCase method single.
@Deployment
public static WebArchive single() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "single.war");
war.addAsWebResource(new StringAsset("a"), "a.txt");
war.addAsWebResource(new StringAsset("b"), "b.txt");
war.addClass(PathAccessCheckServlet.class);
war.addAsManifestResource(createPermissionsXmlAsset(new FilePermission("/-", "read"), new PropertyPermission("java.io.tmpdir", "read"), new VirtualFilePermission(Paths.get(System.getProperty("java.io.tmpdir"), "noaccess.txt").toFile().getAbsolutePath(), "read")), "permissions.xml");
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test.jar");
jar.addAsManifestResource(new StringAsset("b - overlay"), new BasicPath("resources", "b.txt"));
jar.addAsManifestResource(new StringAsset("c - overlay"), new BasicPath("resources", "c.txt"));
war.addAsLibrary(jar);
return war;
}
use of org.jboss.shrinkwrap.impl.base.path.BasicPath in project tomee by apache.
the class MicroProfileRestClientTCKArchiveProcessor method process.
@Override
public void process(final Archive<?> archive, final TestClass testClass) {
if (archive instanceof WebArchive) {
WebArchive webArchive = (WebArchive) archive;
final Map<ArchivePath, Node> content = webArchive.getContent();
final Node node = content.get(new BasicPath("META-INF/certificates-dir.txt"));
if (node != null) {
webArchive.addAsResource(node.getAsset(), "META-INF/certificates-dir.txt");
}
}
}
use of org.jboss.shrinkwrap.impl.base.path.BasicPath in project eap-additional-testsuite by jboss-set.
the class ArchiveTestCase method before.
@BeforeClass
public static void before() throws Exception {
String tempDir = TestSuiteEnvironment.getTmpDir();
WebArchive[] wars = new WebArchive[3];
// deployment1
wars[0] = ShrinkWrap.create(WebArchive.class, "deployment0.war");
wars[0].addClass(SimpleServlet.class);
wars[0].addAsWebResource(new StringAsset("Version0"), "page.html");
// deployment2
wars[1] = ShrinkWrap.create(WebArchive.class, "deployment1.war");
wars[1].addClass(SimpleServlet.class);
wars[1].addAsWebResource(new StringAsset("Version1"), "page.html");
// deployment3 is included but not deployed
wars[2] = ShrinkWrap.create(WebArchive.class, "deployment2.war");
wars[2].addClass(SimpleServlet.class);
wars[2].addAsWebResource(new StringAsset("Version2"), "page.html");
// build cli archive
EnterpriseArchive cliArchive = ShrinkWrap.create(EnterpriseArchive.class, "archive.cli");
String deploy = "deploy deployment0.war\ndeploy deployment1.war";
String undeploy = "undeploy deployment0.war\nundeploy deployment1.war";
cliArchive.add(new StringAsset(deploy), new BasicPath("/", "install.scr"));
// add the default script which shouldn't be picked up
cliArchive.add(new StringAsset("deploy deployment0.war\ndeploy deployment1.war\ndeploy deployment2.war"), new BasicPath("/", "deploy.scr"));
cliArchive.add(new StringAsset(undeploy), new BasicPath("/", "uninstall.scr"));
cliArchive.add(new StringAsset("undeploy deployment0.war\nundeploy deployment1.war\nundeploy deployment2.war"), new BasicPath("/", "undeploy.scr"));
for (WebArchive war : wars) {
cliArchive.add(war, new BasicPath("/"), ZipExporter.class);
}
cliArchiveFile = new File(tempDir + File.separator + "archive.cli");
new ZipExporterImpl(cliArchive).exportTo(cliArchiveFile, true);
}
Aggregations