private Resource createPomFromFile(File file) throws Exception { if (!file.isFile()) return null; return new FileResource(file); }
private Resource createPomFromFile(File file) throws Exception { if (!file.isFile()) return null; return new FileResource(file); }
static void traverse(Jar jar, int rootlength, File directory, Pattern doNotCopy) { if (doNotCopy != null && doNotCopy.matcher(directory.getName()).matches()) return; jar.updateModified(directory.lastModified(), "Dir change"); File files[] = directory.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) traverse(jar, rootlength, files[i], doNotCopy); else { String path = files[i].getAbsolutePath().substring(rootlength + 1); if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/'); jar.putResource(path, new FileResource(files[i]), true); } } }
static void traverse(Jar jar, int rootlength, File directory, Pattern doNotCopy) { if (doNotCopy != null && doNotCopy.matcher(directory.getName()).matches()) return; jar.updateModified(directory.lastModified(), "Dir change " + directory); File files[] = directory.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) traverse(jar, rootlength, files[i], doNotCopy); else { String path = files[i].getAbsolutePath().substring(rootlength + 1); if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/'); jar.putResource(path, new FileResource(files[i]), true); } } }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String relativePath = IO.normalizePath(baseDir.relativize(file)); putResource(relativePath, new FileResource(file, attrs), true); return FileVisitResult.CONTINUE; } });
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String relativePath = IO.normalizePath(baseDir.relativize(file)); putResource(relativePath, new FileResource(file, attrs), true); return FileVisitResult.CONTINUE; } });
static void traverse(Jar jar, int rootlength, File directory, Pattern doNotCopy) { if (doNotCopy != null && doNotCopy.matcher(directory.getName()).matches()) return; jar.updateModified(directory.lastModified(), "Dir change " + directory); File files[] = directory.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) traverse(jar, rootlength, files[i], doNotCopy); else { String path = files[i].getAbsolutePath().substring(rootlength + 1); if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/'); jar.putResource(path, new FileResource(files[i]), true); } } }
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); }
/** * @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); }
static Resource fromURL(URL url, HttpClient client) throws IOException { if (url.getProtocol() .equalsIgnoreCase("file")) { URI uri = URI.create(url.toExternalForm()); Path path = new File(uri.getSchemeSpecificPart()).toPath() .toAbsolutePath(); return new FileResource(path); } if (url.getProtocol() .equals("jar")) { JarURLUtil util = new JarURLUtil(url); URL jarFileURL = util.getJarFileURL(); if (jarFileURL.getProtocol() .equalsIgnoreCase("file")) { URI uri = URI.create(jarFileURL.toExternalForm()); Path path = new File(uri.getSchemeSpecificPart()).toPath() .toAbsolutePath(); String entryName = util.getEntryName(); if (entryName == null) { return new FileResource(path); } return new ZipResource(path, entryName); } } return new URLResource(url, client); } }
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); }
static Resource fromURL(URL url, HttpClient client) throws IOException { if (url.getProtocol() .equalsIgnoreCase("file")) { URI uri = URI.create(url.toExternalForm()); Path path = new File(uri.getSchemeSpecificPart()).toPath() .toAbsolutePath(); return new FileResource(path); } if (url.getProtocol() .equals("jar")) { JarURLUtil util = new JarURLUtil(url); URL jarFileURL = util.getJarFileURL(); if (jarFileURL.getProtocol() .equalsIgnoreCase("file")) { URI uri = URI.create(jarFileURL.toExternalForm()); Path path = new File(uri.getSchemeSpecificPart()).toPath() .toAbsolutePath(); String entryName = util.getEntryName(); if (entryName == null) { return new FileResource(path); } return new ZipResource(path, entryName); } } return new URLResource(url, client); } }
@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); }
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); } } }
XmlUtils.writeXml(featureSpec, newXml); FileResource newRes = new FileResource(newXml); jar.putResource("feature.xml", newRes, true); jar.write(outputFile);
@Override public Entry<String, Resource> export(String type, Project project, Map<String, String> options) throws Exception { project.prepare(); Collection<Container> runbundles = project.getRunbundles(); Jar jar = new Jar(project.getName()); jar.setDoNotTouchManifest(); for (Container container : runbundles) { File source = container.getFile(); String path = nonCollidingPath(jar, source.getName()); jar.putResource(path, new FileResource(source)); } return new SimpleEntry<>(jar.getName(), new JarResource(jar, true)); }
@Override public Entry<String, Resource> export(String type, Project project, Map<String, String> options) throws Exception { project.prepare(); Collection<Container> runbundles = project.getRunbundles(); Jar jar = new Jar(project.getName()); jar.setDoNotTouchManifest(); for (Container container : runbundles) { File source = container.getFile(); String path = nonCollidingPath(jar, source.getName()); jar.putResource(path, new FileResource(source)); } return new SimpleEntry<>(jar.getName(), new JarResource(jar, true)); }