/** * Creates a bnd resource that contains the generated dm descriptor. * @param collector * @return * @throws IOException */ private Resource createComponentResource(AnnotationCollector collector) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "UTF-8")); collector.writeTo(pw); pw.close(); byte[] data = out.toByteArray(); out.close(); return new EmbeddedResource(data, 0); }
public static void build(Jar jar, InputStream in, long lastModified) throws IOException { ZipInputStream jin = new ZipInputStream(in); ZipEntry entry = jin.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { byte data[] = collect(jin); jar.putResource(entry.getName(), new EmbeddedResource(data, lastModified), true); } entry = jin.getNextEntry(); } IO.drain(in); jin.close(); }
public static void build(Jar jar, InputStream in, long lastModified) throws IOException { ZipInputStream jin = new ZipInputStream(in); ZipEntry entry = jin.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { byte data[] = collect(jin); jar.putResource(entry.getName(), new EmbeddedResource(data, lastModified), true); } entry = jin.getNextEntry(); } IO.drain(in); jin.close(); }
public static void build(Jar jar, InputStream in, long lastModified) throws IOException { ZipInputStream jin = new ZipInputStream(in); ZipEntry entry = jin.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { byte data[] = collect(jin); jar.putResource(entry.getName(), new EmbeddedResource(data, lastModified), true); } entry = jin.getNextEntry(); } IO.drain(in); jin.close(); }
private Jar buildFromInputStream(InputStream in, long lastModified) throws IOException { try (ZipInputStream jin = new ZipInputStream(in)) { for (ZipEntry entry; (entry = jin.getNextEntry()) != null;) { if (entry.isDirectory()) { continue; } int size = (int) entry.getSize(); try (ByteBufferOutputStream bbos = new ByteBufferOutputStream((size == -1) ? BUFFER_SIZE : size + 1)) { bbos.write(jin); putResource(entry.getName(), new EmbeddedResource(bbos.toByteBuffer(), lastModified), true); } } } return this; }
/** * @param jar * @throws IOException */ private void doMavenMetadata( MavenProject currentProject, Jar jar ) throws IOException { String path = "META-INF/maven/" + currentProject.getGroupId() + "/" + currentProject.getArtifactId(); File pomFile = currentProject.getFile(); if ( pomFile == null || !pomFile.exists() ) { pomFile = new File( currentProject.getBasedir(), "pom.xml" ); } if ( pomFile.exists() ) { jar.putResource( path + "/pom.xml", new FileResource( pomFile ) ); } Properties p = new Properties(); p.put( "version", currentProject.getVersion() ); p.put( "groupId", currentProject.getGroupId() ); p.put( "artifactId", currentProject.getArtifactId() ); ByteArrayOutputStream out = new ByteArrayOutputStream(); p.store( out, "Generated by org.apache.felix.bundleplugin" ); jar.putResource( path + "/pom.properties", new EmbeddedResource( out.toByteArray(), System.currentTimeMillis() ) ); }
public Resource make(Builder builder, String destination, Map<String,String> argumentsOnMake) throws Exception { String type = argumentsOnMake.get("type"); if (!type.equals("copy")) return null; String from = argumentsOnMake.get("from"); if (from == null) { String content = argumentsOnMake.get("content"); if (content == null) throw new IllegalArgumentException("No 'from' or 'content' field in copy " + argumentsOnMake); return new EmbeddedResource(content.getBytes("UTF-8"), 0); } File f = builder.getFile(from); if (f.isFile()) return new FileResource(f); try { URL url = new URL(from); return new URLResource(url); } catch (MalformedURLException mfue) { // We ignore this } throw new IllegalArgumentException("Copy source does not exist " + from + " for destination " + destination); }
public Resource make(Builder builder, String destination, Map<String,String> argumentsOnMake) throws Exception { String type = argumentsOnMake.get("type"); if (!type.equals("copy")) return null; String from = argumentsOnMake.get("from"); if (from == null) { String content = argumentsOnMake.get("content"); if (content == null) throw new IllegalArgumentException("No 'from' or 'content' field in copy " + argumentsOnMake); return new EmbeddedResource(content.getBytes("UTF-8"), 0); } File f = builder.getFile(from); if (f.isFile()) return new FileResource(f); try { URL url = new URL(from); return new URLResource(url); } catch (MalformedURLException mfue) { // We ignore this } throw new IllegalArgumentException("Copy source does not exist " + from + " for destination " + destination); }
private Jar buildFromInputStream(InputStream in, long lastModified) throws IOException { try (ZipInputStream jin = new ZipInputStream(in)) { for (ZipEntry entry; (entry = jin.getNextEntry()) != null;) { if (entry.isDirectory()) { continue; } int size = (int) entry.getSize(); try (ByteBufferOutputStream bbos = new ByteBufferOutputStream((size == -1) ? BUFFER_SIZE : size + 1)) { bbos.write(jin); putResource(entry.getName(), new EmbeddedResource(bbos.toByteBuffer(), lastModified), true); } } } return this; }
public Resource make(Builder builder, String destination, Map<String,String> argumentsOnMake) throws Exception { String type = argumentsOnMake.get("type"); if (!type.equals("copy")) return null; String from = argumentsOnMake.get("from"); if (from == null) { String content = argumentsOnMake.get("content"); if (content == null) throw new IllegalArgumentException("No 'from' or 'content' field in copy " + argumentsOnMake); return new EmbeddedResource(content.getBytes("UTF-8"), 0); } File f = builder.getFile(from); if (f.isFile()) return new FileResource(f); try { URL url = new URL(from); return new URLResource(url); } catch (MalformedURLException mfue) { // We ignore this } throw new IllegalArgumentException("Copy source does not exist " + from + " for destination " + destination); }
@Override public Resource make(Builder builder, String destination, Map<String, String> argumentsOnMake) throws Exception { String type = argumentsOnMake.get("type"); if (!type.equals("copy")) return null; String from = argumentsOnMake.get("from"); if (from == null) { String content = argumentsOnMake.get("content"); if (content == null) throw new IllegalArgumentException("No 'from' or 'content' field in copy " + argumentsOnMake); return new EmbeddedResource(content, 0L); } File f = builder.getFile(from); if (f.isFile()) return new FileResource(f); try { URL url = new URL(from); return Resource.fromURL(url, builder.getPlugin(HttpClient.class)); } catch (MalformedURLException mfue) { // We ignore this } throw new IllegalArgumentException("Copy source does not exist " + from + " for destination " + destination); }
@Override public Resource make(Builder builder, String destination, Map<String, String> argumentsOnMake) throws Exception { String type = argumentsOnMake.get("type"); if (!type.equals("copy")) return null; String from = argumentsOnMake.get("from"); if (from == null) { String content = argumentsOnMake.get("content"); if (content == null) throw new IllegalArgumentException("No 'from' or 'content' field in copy " + argumentsOnMake); return new EmbeddedResource(content, 0L); } File f = builder.getFile(from); if (f.isFile()) return new FileResource(f); try { URL url = new URL(from); return Resource.fromURL(url, builder.getPlugin(HttpClient.class)); } catch (MalformedURLException mfue) { // We ignore this } throw new IllegalArgumentException("Copy source does not exist " + from + " for destination " + destination); }
} else if (extra.containsKey(LITERAL_ATTRIBUTE)) { String literal = extra.get(LITERAL_ATTRIBUTE); Resource r = new EmbeddedResource(literal.getBytes("UTF-8"), 0); String x = extra.get("extra"); if (x != null)
} else if (extra.containsKey(LITERAL_ATTRIBUTE)) { String literal = extra.get(LITERAL_ATTRIBUTE); Resource r = new EmbeddedResource(literal, 0L); String x = extra.get("extra"); if (x != null)
private void copy(Jar jar, String path, File from, Instructions preprocess, Map<String, String> extra) throws Exception { if (doNotCopy(from)) return; logger.debug("copy d={} s={} path={}", jar, from, path); if (from.isDirectory()) { File files[] = from.listFiles(); for (int i = 0; i < files.length; i++) { copy(jar, appendPath(path, files[i].getName()), files[i], preprocess, extra); } } else { if (from.exists()) { Resource resource = new FileResource(from); if (preprocess != null && preprocess.matches(path)) { resource = new PreprocessResource(this, resource); } String x = extra.get("extra"); if (x != null) resource.setExtra(x); if (path.endsWith("/")) path = path + from.getName(); copy(jar, path, resource, extra); } else if (from.getName() .equals(Constants.EMPTY_HEADER)) { jar.putResource(path, new EmbeddedResource(new byte[0], 0L)); } else { error("Input file does not exist: %s", from).header(INCLUDERESOURCE + "|" + INCLUDE_RESOURCE); } } }
private void copy(Jar jar, String path, File from, Instructions preprocess, Map<String, String> extra) throws Exception { if (doNotCopy(from)) return; logger.debug("copy d={} s={} path={}", jar, from, path); if (from.isDirectory()) { File files[] = from.listFiles(); for (int i = 0; i < files.length; i++) { copy(jar, appendPath(path, files[i].getName()), files[i], preprocess, extra); } } else { if (from.exists()) { Resource resource = new FileResource(from); if (preprocess != null && preprocess.matches(path)) { resource = new PreprocessResource(this, resource); } String x = extra.get("extra"); if (x != null) resource.setExtra(x); if (path.endsWith("/")) path = path + from.getName(); copy(jar, path, resource, extra); } else if (from.getName() .equals(Constants.EMPTY_HEADER)) { jar.putResource(path, new EmbeddedResource(new byte[0], 0L)); } else { error("Input file does not exist: %s", from).header(INCLUDERESOURCE + "|" + INCLUDE_RESOURCE); } } }
private void copy(Jar jar, String path, File from, boolean preprocess, Map<String,String> extra) throws Exception { if (doNotCopy(from.getName())) return; if (from.isDirectory()) { File files[] = from.listFiles(); for (int i = 0; i < files.length; i++) { copy(jar, appendPath(path, files[i].getName()), files[i], preprocess, extra); } } else { if (from.exists()) { Resource resource = new FileResource(from); if (preprocess) { resource = new PreprocessResource(this, resource); } String x = extra.get("extra"); if (x != null) resource.setExtra(x); if (path.endsWith("/")) path = path + from.getName(); jar.putResource(path, resource); if (isTrue(extra.get(LIB_DIRECTIVE))) { setProperty(BUNDLE_CLASSPATH, append(getProperty(BUNDLE_CLASSPATH), path)); } } else if (from.getName().equals(Constants.EMPTY_HEADER)) { jar.putResource(path, new EmbeddedResource(new byte[0], 0)); } else { error("Input file does not exist: " + from); } } }
jar.putResource(path, new EmbeddedResource(new byte[0], 0)); } else { error("Input file does not exist: " + from);
jar.putResource(path, new EmbeddedResource(new byte[0], 0)); } else { error("Input file does not exist: " + from);
o.flush(); byte newManifestBytes[] = o.toByteArray(); jar.putResource("META-INF/MANIFEST.MF", new EmbeddedResource(newManifestBytes, 0L)); jar.putResource("META-INF/BND.SF", new EmbeddedResource(signatureFileBytes, 0L)); jar.putResource("META-INF/BND.RSA", new EmbeddedResource(tmpStream.toByteArray(), 0L));