File: make.md

package info (click to toggle)
bnd 5.0.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 44,128 kB
  • sloc: java: 249,039; xml: 90,728; sh: 655; perl: 153; makefile: 96; python: 47; javascript: 9
file content (104 lines) | stat: -rw-r--r-- 2,899 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
layout: default
class: Project
title: -make   
summary:  If a resource is not found, specify a recipe to make it.
---

		package aQute.bnd.make;
		
		import java.util.*;
		import java.util.Map.Entry;
		import java.util.regex.*;
		
		import aQute.bnd.header.*;
		import aQute.bnd.osgi.*;
		import aQute.bnd.service.*;
		
		public class Make {
			Builder								builder;
			Map<Instruction,Map<String,String>>	make;
		
			public Make(Builder builder) {
				this.builder = builder;
			}
		
			public Resource process(String source) {
				Map<Instruction,Map<String,String>> make = getMakeHeader();
				builder.trace("make " + source);
		
				for (Map.Entry<Instruction,Map<String,String>> entry : make.entrySet()) {
					Instruction instr = entry.getKey();
					Matcher m = instr.getMatcher(source);
					if (m.matches() || instr.isNegated()) {
						Map<String,String> arguments = replace(m, entry.getValue());
						List<MakePlugin> plugins = builder.getPlugins(MakePlugin.class);
						for (MakePlugin plugin : plugins) {
							try {
								Resource resource = plugin.make(builder, source, arguments);
								if (resource != null) {
									builder.trace("Made " + source + " from args " + arguments + " with " + plugin);
									return resource;
								}
							}
							catch (Exception e) {
								builder.error("Plugin " + plugin + " generates error when use in making " + source
										+ " with args " + arguments, e);
							}
						}
					}
				}
				return null;
			}
		
			private Map<String,String> replace(Matcher m, Map<String,String> value) {
				Map<String,String> newArgs = Processor.newMap();
				for (Map.Entry<String,String> entry : value.entrySet()) {
					String s = entry.getValue();
					s = replace(m, s);
					newArgs.put(entry.getKey(), s);
				}
				return newArgs;
			}
		
			String replace(Matcher m, CharSequence s) {
				StringBuilder sb = new StringBuilder();
				int max = '0' + m.groupCount() + 1;
				for (int i = 0; i < s.length(); i++) {
					char c = s.charAt(i);
					if (c == '$' && i < s.length() - 1) {
						c = s.charAt(++i);
						if (c >= '0' && c <= max) {
							int index = c - '0';
							String replacement = m.group(index);
							if (replacement != null)
								sb.append(replacement);
						} else {
							if (c == '$')
								i++;
							sb.append(c);
						}
					} else
						sb.append(c);
				}
				return sb.toString();
			}
		
			Map<Instruction,Map<String,String>> getMakeHeader() {
				if (make != null)
					return make;
				make = Processor.newMap();
		
				String s = builder.getProperty(Builder.MAKE);
				Parameters make = builder.parseHeader(s);
		
				for (Entry<String,Attrs> entry : make.entrySet()) {
					String pattern = Processor.removeDuplicateMarker(entry.getKey());
		
					Instruction instr = new Instruction(pattern);
					this.make.put(instr, entry.getValue());
				}
		
				return this.make;
			}
		}