blob: 9a6897e79c2239b515df76e70618a64c72e7bc5f [file] [log] [blame]
Stuart McCullochbb014372012-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 McCulloch2286f232012-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 McCullochbb014372012-06-07 21:57:32 +000016
Stuart McCulloch2286f232012-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);
Stuart McCulloch2286f232012-06-15 13:27:53 +000023 }
Stuart McCullochd4826102012-06-26 16:34:24 +000024 File f = builder.getFile(from);
25 if (f.isFile())
26 return new FileResource(f);
27 try {
28 URL url = new URL(from);
29 return new URLResource(url);
30 }
31 catch (MalformedURLException mfue) {
32 // We ignore this
33 }
34 throw new IllegalArgumentException("Copy source does not exist " + from + " for destination "
35 + destination);
Stuart McCulloch2286f232012-06-15 13:27:53 +000036 }
Stuart McCullochbb014372012-06-07 21:57:32 +000037
38}