blob: 74d29216ce2bb008a0d2dd0d03d6a7472e7e29e5 [file] [log] [blame]
Stuart McCullochf3173222012-06-07 21:57:32 +00001package aQute.bnd.make;
2
3import java.io.*;
4import java.net.*;
5import java.util.*;
6
7import aQute.bnd.service.*;
8import aQute.lib.osgi.*;
9
10public class MakeCopy implements MakePlugin {
11
Stuart McCulloch4482c702012-06-15 13:27:53 +000012 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 McCullochf3173222012-06-07 21:57:32 +000016
Stuart McCulloch4482c702012-06-15 13:27:53 +000017 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 McCullochf3173222012-06-07 21:57:32 +000024
Stuart McCulloch4482c702012-06-15 13:27:53 +000025 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 McCullochf3173222012-06-07 21:57:32 +000041
42}