congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
ShrinkWrapClassLoader.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
org.jboss.shrinkwrap.api.classloader.ShrinkWrapClassLoader
constructor

Best Java code snippets using org.jboss.shrinkwrap.api.classloader.ShrinkWrapClassLoader.<init> (Showing top 13 results out of 315)

origin: org.jboss.arquillian.container/arquillian-weld-ee-embedded-1.1

private ShrinkWrapClassLoader getClassLoader(Archive<?> archive) {
  return (archive.getName().endsWith(SUFFIX_WEB_ARCHIVE)) ? new WebArchiveClassLoader(archive.getClass().getClassLoader(), archive)
      : new ShrinkWrapClassLoader(archive.getClass().getClassLoader(), archive);
}
origin: org.jboss.arquillian.extension/arquillian-warp-impl

public static <I, T extends I> I invoke(Class<T> clazz, JavaArchive... classPathArchives) {
  JavaArchive[] copy = new JavaArchive[classPathArchives.length + 1];
  System.arraycopy(classPathArchives, 0, copy, 0, classPathArchives.length);
  copy[copy.length - 1] = ShrinkWrap.create(JavaArchive.class).addClass(SerializationUtils.class);
  ClassLoader separatedClassLoader = new ShrinkWrapClassLoader(ClassLoaderUtils.getBootstrapClassLoader(), copy);
  return invoke(clazz, separatedClassLoader);
}
origin: org.jboss.arquillian.container/arquillian-weld-se-embedded-1.1

Validate.notNull(archive, "Archive must be specified");
this.classLoader = new ShrinkWrapClassLoader(archive.getClass().getClassLoader(), archive);
origin: shrinkwrap/shrinkwrap

/**
 * Creates the {@link ShrinkWrapClassLoaderTestCase#shrinkWrapClassLoader} used to load classes from an
 * {@link Archive}. The {@link ClassLoader} will be isolated from the application classpath by specifying a null
 * parent explicitly.
 */
@Before
public void createClassLoader() {
  shrinkWrapClassLoader = new ShrinkWrapClassLoader((ClassLoader)null , archive);
}
origin: org.jboss.arquillian.daemon/arquillian-daemon-server

final ShrinkWrapClassLoader isolatedArchiveCL = new ShrinkWrapClassLoader((ClassLoader) null, archive);
origin: org.jboss.arquillian.extension/arquillian-warp-impl

private MigrationResult migrate() throws InspectionTransformationException {
  byte[] oldClassFile = transformed.toBytecode();
  String oldClassName = transformed.getTransformedClass().getName();
  String newClassName = transformed.getOriginalClass().getName();
  Inspection serverInspection = transformed.getTransformedInspection();
  NamedAsset transformedAsset = transformed.toShrinkWrapAsset();
  try {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class).add(transformedAsset);
    ShrinkWrapClassLoader shrinkWrapClassLoader =
      new ShrinkWrapClassLoader(ClassLoaderUtils.getBootstrapClassLoader(),
        archive);
    SeparatedClassLoader separatedClassLoader =
      new SeparatedClassLoader(shrinkWrapClassLoader, contextClassLoader);
    return SeparateInvocator.<Migration, MigrationImpl>invoke(MigrationImpl.class, separatedClassLoader).process(
      oldClassName, newClassName, oldClassFile, serverInspection);
  } catch (Throwable e) {
    throw new IllegalStateException("Cannot migrate transformed inspection back to original name", e);
  }
}
origin: shrinkwrap/shrinkwrap

/**
 * Ensures that we can open up an asset that doesn't exist via a {@link URL} from the {@link ShrinkWrapClassLoader}
 * (ie. should throw {@link FileNotFoundException}
 *
 * SHRINKWRAP-308
 */
@Test(expected = FileNotFoundException.class)
public void shouldNotBeAbleToOpenStreamOnNonexistantAsset() throws IOException {
  // Make a new Archive with some content in a directory
  final String nestedResourceName = "nested/test";
  final Asset testAsset = new StringAsset("testContent");
  final GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add(testAsset, nestedResourceName);
  // Make a CL to load the content
  final ClassLoader swCl = new ShrinkWrapClassLoader(archive);
  // Get the URL to something that doesn't exist
  final URL nestedResourceUrl = swCl.getResource(nestedResourceName);
  final URL nestedResourceThatDoesntExistUrl = new URL(nestedResourceUrl, "../fake");
  // openStream on the URL that doesn't exist should throw FNFE
  nestedResourceThatDoesntExistUrl.openStream();
}
origin: shrinkwrap/shrinkwrap

/**
 * Ensures that we can open up directory content as obtained via a {@link URL} from the
 * {@link ShrinkWrapClassLoader} (ie. should return null, not throw an exception)
 *
 * SHRINKWRAP-306
 */
@Test
public void shouldBeAbleToOpenStreamOnDirectoryUrl() throws IOException {
  // Make a new Archive with some content in a directory
  final String nestedResourceName = "nested/test";
  final Asset testAsset = new StringAsset("testContent");
  final GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add(testAsset, nestedResourceName);
  // Make a CL to load the content
  final ClassLoader swCl = new ShrinkWrapClassLoader(archive);
  // Get the URL to the parent directory
  final URL nestedResourceUrl = swCl.getResource(nestedResourceName);
  final URL nestedResourceUpALevelUrl = new URL(nestedResourceUrl, "../");
  // openStream on the URL to the parent directory; should return null, not throw an exception
  final InputStream in = nestedResourceUpALevelUrl.openStream();
  Assert.assertNull("URLs pointing to a directory should openStream as null", in);
}
origin: shrinkwrap/shrinkwrap

/**
 * Ensures we can load a Class instance from the {@link ShrinkWrapClassLoader} in a web archive
 */
@Test
public void shouldBeAbleToLoadClassFromWebArchive() throws ClassNotFoundException {
  /**
   * Web Archive to be read via a {@link ShrinkWrapClassLoaderTestCase#shrinkWrapClassLoader}.
   * Places classes under WEB-INF/classes, so with this different root needs the CL to respect that
   * and know what to do
   */
  final WebArchive webArchive = ShrinkWrap.create(WebArchive.class).addClass(
      applicationClassLoaderClass);
  final ClassLoader webArchiveClassLoader = new ShrinkWrapClassLoader((ClassLoader) null,
      "WEB-INF/classes", webArchive);
  // Load the test class from the CL
  final Class<?> loadedTestClass = Class.forName(applicationClassLoaderClass.getName(), false,
      webArchiveClassLoader);
  final ClassLoader loadedTestClassClassLoader = loadedTestClass.getClassLoader();
  log.info("Got " + loadedTestClass + " from " + loadedTestClassClassLoader);
  // Assertions
  Assert.assertNotNull("Test class could not be found via the ClassLoader", loadedTestClass);
  Assert.assertSame("Test class should have been loaded via the web archive ClassLoader", webArchiveClassLoader,
      loadedTestClassClassLoader);
  Assert.assertNotSame("Class Loaded from the CL should not be the same as the one on the appCL",
      loadedTestClass, applicationClassLoaderClass);
}
origin: arquillian/arquillian-core

@Test
public void shouldBeAbleToLoadVetoedClasses() throws Exception {
  Archive<JavaArchive> jarWithVetoedServiceImpl = createJarWithVetoedServices();
  ClassLoader emptyParent = null;
  ShrinkWrapClassLoader swClassloader = new ShrinkWrapClassLoader(emptyParent, jarWithVetoedServiceImpl);
  ClassLoader emptyClassLoader = new ClassLoader(null) {
  };
  ClassLoader originalClassLoader = SecurityActions.getThreadContextClassLoader();
  Map<Class<?>, Set<Class<?>>> vetoed = null;
  Class<?> service;
  try {
    Thread.currentThread().setContextClassLoader(emptyClassLoader);
    service = swClassloader.loadClass("org.jboss.arquillian.core.impl.loadable.util.FakeService");
    swClassloader.loadClass("org.jboss.arquillian.core.impl.loadable.util.ShouldBeIncluded");
    swClassloader.loadClass("org.jboss.arquillian.core.impl.loadable.util.ShouldBeExcluded");
    vetoed = new JavaSPIExtensionLoader().loadVetoed(swClassloader);
  } finally {
    Thread.currentThread().setContextClassLoader(originalClassLoader);
  }
  Assert.assertEquals("Unexpected number of vetoed services", 1, vetoed.size());
  Assert.assertEquals("Unexpected number of vetoed services impl", 2, vetoed.get(service).size());
}
origin: org.jboss.arquillian.core/arquillian-core-impl-base

@Test
public void shouldBeAbleToAddSelectedProviderFromClassLoader() throws Exception {
  Archive<JavaArchive> jarWithDefaultServiceImpl = createJarWithDefaultServiceImpl();
  Archive<JavaArchive> jarThatReplaceServiceImpl = createJarThatReplaceServiceImpl();
  ClassLoader emptyParent = null;
  ShrinkWrapClassLoader swClassloader =
    new ShrinkWrapClassLoader(emptyParent, jarThatReplaceServiceImpl, jarWithDefaultServiceImpl);
  ClassLoader emptyClassLoader = new ClassLoader(null) {
  };
  ClassLoader originalClassLoader = SecurityActions.getThreadContextClassLoader();
  Collection<?> providers = null;
  Class<?> expectedImplClass = null;
  try {
    Thread.currentThread().setContextClassLoader(emptyClassLoader);
    Class<?> serviceClass = swClassloader.loadClass("org.jboss.arquillian.core.impl.loadable.util.FakeService");
    expectedImplClass = swClassloader.loadClass("org.jboss.arquillian.core.impl.loadable.util.ShouldBeIncluded");
    providers = new JavaSPIExtensionLoader().all(swClassloader, serviceClass);
  } finally {
    Thread.currentThread().setContextClassLoader(originalClassLoader);
  }
  Assert.assertEquals("Unexpected number of providers loaded", 1, providers.size());
  Assert.assertEquals("Wrong provider loaded", expectedImplClass, providers.iterator().next().getClass());
}
origin: org.jboss.arquillian.core/arquillian-core-impl-base

@Test
public void shouldBeAbleToLoadVetoedClasses() throws Exception {
  Archive<JavaArchive> jarWithVetoedServiceImpl = createJarWithVetoedServices();
  ClassLoader emptyParent = null;
  ShrinkWrapClassLoader swClassloader = new ShrinkWrapClassLoader(emptyParent, jarWithVetoedServiceImpl);
  ClassLoader emptyClassLoader = new ClassLoader(null) {
  };
  ClassLoader originalClassLoader = SecurityActions.getThreadContextClassLoader();
  Map<Class<?>, Set<Class<?>>> vetoed = null;
  Class<?> service;
  try {
    Thread.currentThread().setContextClassLoader(emptyClassLoader);
    service = swClassloader.loadClass("org.jboss.arquillian.core.impl.loadable.util.FakeService");
    swClassloader.loadClass("org.jboss.arquillian.core.impl.loadable.util.ShouldBeIncluded");
    swClassloader.loadClass("org.jboss.arquillian.core.impl.loadable.util.ShouldBeExcluded");
    vetoed = new JavaSPIExtensionLoader().loadVetoed(swClassloader);
  } finally {
    Thread.currentThread().setContextClassLoader(originalClassLoader);
  }
  Assert.assertEquals("Unexpected number of vetoed services", 1, vetoed.size());
  Assert.assertEquals("Unexpected number of vetoed services impl", 2, vetoed.get(service).size());
}
origin: arquillian/arquillian-core

@Test
public void shouldBeAbleToAddSelectedProviderFromClassLoader() throws Exception {
  Archive<JavaArchive> jarWithDefaultServiceImpl = createJarWithDefaultServiceImpl();
  Archive<JavaArchive> jarThatReplaceServiceImpl = createJarThatReplaceServiceImpl();
  ClassLoader emptyParent = null;
  ShrinkWrapClassLoader swClassloader =
    new ShrinkWrapClassLoader(emptyParent, jarThatReplaceServiceImpl, jarWithDefaultServiceImpl);
  ClassLoader emptyClassLoader = new ClassLoader(null) {
  };
  ClassLoader originalClassLoader = SecurityActions.getThreadContextClassLoader();
  Collection<?> providers = null;
  Class<?> expectedImplClass = null;
  try {
    Thread.currentThread().setContextClassLoader(emptyClassLoader);
    Class<?> serviceClass = swClassloader.loadClass("org.jboss.arquillian.core.impl.loadable.util.FakeService");
    expectedImplClass = swClassloader.loadClass("org.jboss.arquillian.core.impl.loadable.util.ShouldBeIncluded");
    providers = new JavaSPIExtensionLoader().all(swClassloader, serviceClass);
  } finally {
    Thread.currentThread().setContextClassLoader(originalClassLoader);
  }
  Assert.assertEquals("Unexpected number of providers loaded", 1, providers.size());
  Assert.assertEquals("Wrong provider loaded", expectedImplClass, providers.iterator().next().getClass());
}
org.jboss.shrinkwrap.api.classloaderShrinkWrapClassLoader<init>

Javadoc

Constructs a new ShrinkWrapClassLoader for the given Archives. The Archives will be searched in the order specified for classes and resources after first searching in the specified parent class loader.

Popular methods of ShrinkWrapClassLoader

  • close
  • loadClass
  • addArchive
  • addArchives
  • addURL
  • findResource
  • findResources
  • getResource
  • getResources

Popular in Java

  • Creating JSON documents from java classes using gson
  • putExtra (Intent)
  • setRequestProperty (URLConnection)
  • onRequestPermissionsResult (Fragment)
  • String (java.lang)
  • Permission (java.security)
    Legacy security code; do not use.
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • BoxLayout (javax.swing)
  • JLabel (javax.swing)
  • IsNull (org.hamcrest.core)
    Is the value null?
  • PhpStorm for WordPress
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now