blob: 3d5e4c84498a343153983586d9e8a7ac1399ff8c [file] [log] [blame]
Stuart McCullochd00f9712009-07-13 10:06:47 +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
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}