public static void addFile(JavaArchive archive, String originalPath) { archive.addAsResource(new UrlAsset(Thread.currentThread().getContextClassLoader().getResource("internal/" + originalPath)), originalPath); }
@Override public InputStream openStream() { final URL source = this.getSource(); String fileName = getFileName(source); File file = new File(TEMP_LOCATION, fileName); try { if (!file.exists() || !file.isFile() || isExpired(file)) { InputStream is = super.openStream(); Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } return new BufferedInputStream(new FileInputStream(file), 8192); } catch (IOException e) { throw new RuntimeException(e); } }
public static void addFile(JavaArchive archive, String originalFile, String targetFile) { archive.addAsResource(new UrlAsset(Thread.currentThread().getContextClassLoader().getResource(originalFile)), targetFile); }
@Override public InputStream openStream() { final URL source = this.getSource(); String fileName = getFileName(source); File file = new File(TEMP_LOCATION, fileName); try { if (!file.exists() || !file.isFile() || isExpired(file)) { InputStream is = super.openStream(); Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } return new BufferedInputStream(new FileInputStream(file), 8192); } catch (IOException e) { throw new RuntimeException(e); } }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.container.ManifestContainer#setManifest(java.net.URL) */ @Override public T setManifest(URL resource) throws IllegalArgumentException { Validate.notNull(resource, "Resource should be specified"); return setManifest(new UrlAsset(resource)); }
@Override public T setResourceAdapterXML(URL resource) throws IllegalArgumentException { Validate.notNull(resource, "Resource must be specified"); return setResourceAdapterXML(new UrlAsset(resource)); }
@Override public T setApplicationXML(URL resource) throws IllegalArgumentException { Validate.notNull(resource, "Resource must be specified"); return setApplicationXML(new UrlAsset(resource)); }
@Override public T setApplicationXML(URL resource) throws IllegalArgumentException { Validate.notNull(resource, "Resource must be specified"); return setApplicationXML(new UrlAsset(resource)); }
@Override public T setWebXML(URL resource) throws IllegalArgumentException { Validate.notNull(resource, "Resource should be specified"); return setWebXML(new UrlAsset(resource)); }
@Override public T setWebXML(URL resource) throws IllegalArgumentException { Validate.notNull(resource, "Resource should be specified"); return setWebXML(new UrlAsset(resource)); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.container.ManifestContainer#setManifest(java.net.URL) */ @Override public T setManifest(URL resource) throws IllegalArgumentException { Validate.notNull(resource, "Resource should be specified"); return setManifest(new UrlAsset(resource)); }
/** * @see org.jboss.shrinkwrap.portal.api.container.PortletContainer#setPortletXML(java.net.URL) */ @Override public T setPortletXML(URL resource) throws IllegalArgumentException { Validate.notNull(resource, "Resource should be specified"); return setPortletXML(new UrlAsset(resource)); }
@Override public T addAsResource(URL resource, ArchivePath target) throws IllegalArgumentException { Validate.notNull(resource, "Resource should be specified"); Validate.notNull(target, "Target should be specified"); File file = new File(resource.getFile()); if (file.exists()) { return addAsResource(file, target); } return addAsResource(new UrlAsset(resource), target); }
@Override public T setResourceAdapterXML(URL resource) throws IllegalArgumentException { Validate.notNull(resource, "Resource must be specified"); return setResourceAdapterXML(new UrlAsset(resource)); }
@Override public T addAsManifestResource(URL resource, ArchivePath target) throws IllegalArgumentException { Validate.notNull(resource, "Resource should be specified"); Validate.notNull(target, "Target should be specified"); File file = new File(resource.getFile()); if (file.exists()) { return addAsManifestResource(file, target); } return addAsManifestResource(new UrlAsset(resource), target); }
@Override public T addAsManifestResource(URL resource, ArchivePath target) throws IllegalArgumentException { Validate.notNull(resource, "Resource should be specified"); Validate.notNull(target, "Target should be specified"); File file = new File(resource.getFile()); if (file.exists()) { return addAsManifestResource(file, target); } return addAsManifestResource(new UrlAsset(resource), target); }
@Override public T addAsResource(URL resource, ArchivePath target) throws IllegalArgumentException { Validate.notNull(resource, "Resource should be specified"); Validate.notNull(target, "Target should be specified"); File file = new File(resource.getFile()); if (file.exists()) { return addAsResource(file, target); } return addAsResource(new UrlAsset(resource), target); }
@Override public T addAsLibrary(URL resource, ArchivePath target) throws IllegalArgumentException { Validate.notNull(resource, "Resource must be specified"); Validate.notNull(target, "Target must be specified"); File resourceFile = new File(resource.getFile()); if (!resourceFile.exists()) { return addAsLibrary(new UrlAsset(resource), target); } if (resourceFile.isFile()) { return addAsLibrary(new UrlAsset(resource), target); } if (resourceFile.listFiles().length == 0) { return addAsLibrary(new UrlAsset(resource), target); } for (File file : resourceFile.listFiles()) { addAsLibrary(file, new BasicPath(target, file.getName())); } return covarientReturn(); }