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 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 12 | public Resource make(Builder builder, String destination, Map<String,String> argumentsOnMake) throws Exception { |
| 13 | String type = argumentsOnMake.get("type"); |
| 14 | if (!type.equals("copy")) |
| 15 | return null; |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 16 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 17 | String from = argumentsOnMake.get("from"); |
| 18 | if (from == null) { |
| 19 | String content = argumentsOnMake.get("content"); |
| 20 | if (content == null) |
| 21 | throw new IllegalArgumentException("No 'from' or 'content' field in copy " + argumentsOnMake); |
| 22 | return new EmbeddedResource(content.getBytes("UTF-8"), 0); |
| 23 | } else { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 24 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 25 | File f = builder.getFile(from); |
| 26 | if (f.isFile()) |
| 27 | return new FileResource(f); |
| 28 | else { |
| 29 | try { |
| 30 | URL url = new URL(from); |
| 31 | return new URLResource(url); |
| 32 | } |
| 33 | catch (MalformedURLException mfue) { |
| 34 | // We ignore this |
| 35 | } |
| 36 | throw new IllegalArgumentException("Copy source does not exist " + from + " for destination " |
| 37 | + destination); |
| 38 | } |
| 39 | } |
| 40 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 41 | |
| 42 | } |