Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.bnd.make; |
| 2 | |
| 3 | import java.io.*; |
| 4 | import java.net.*; |
| 5 | import java.util.*; |
| 6 | |
| 7 | import aQute.bnd.service.*; |
| 8 | import aQute.lib.osgi.*; |
| 9 | |
| 10 | public class MakeCopy implements MakePlugin { |
| 11 | |
| 12 | public Resource make(Builder builder, String destination, |
| 13 | Map<String, String> argumentsOnMake) throws Exception { |
| 14 | String type = argumentsOnMake.get("type"); |
| 15 | if (!type.equals("copy")) |
| 16 | return null; |
| 17 | |
| 18 | String from = argumentsOnMake.get("from"); |
| 19 | if (from == null) { |
| 20 | String content = argumentsOnMake.get("content"); |
| 21 | if (content == null) |
| 22 | throw new IllegalArgumentException( |
| 23 | "No 'from' or 'content' field in copy " |
| 24 | + argumentsOnMake); |
| 25 | return new EmbeddedResource(content.getBytes("UTF-8"),0); |
| 26 | } else { |
| 27 | |
| 28 | File f = builder.getFile(from); |
| 29 | if (f.isFile()) |
| 30 | return new FileResource(f); |
| 31 | else { |
| 32 | try { |
| 33 | URL url = new URL(from); |
| 34 | return new URLResource(url); |
| 35 | } catch(MalformedURLException mfue) { |
| 36 | // We ignore this |
| 37 | } |
| 38 | throw new IllegalArgumentException( |
| 39 | "Copy source does not exist " + from |
| 40 | + " for destination " + destination); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | } |