Debian Codegraph @

bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/pde/internal/build/publisher/FeatureRootAdvice.java

raw
1 /*******************************************************************************
2 * Copyright (c) 2008, 2017 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.pde.internal.build.publisher;
15
16 import java.util.*;
17 import org.eclipse.equinox.internal.p2.core.helpers.FileUtils.IPathComputer;
18 import org.eclipse.equinox.internal.p2.publisher.FileSetDescriptor;
19 import org.eclipse.equinox.p2.metadata.Version;
20 import org.eclipse.equinox.p2.publisher.AbstractAdvice;
21 import org.eclipse.equinox.p2.publisher.actions.IFeatureRootAdvice;
22
23 public class FeatureRootAdvice extends AbstractAdvice implements IFeatureRootAdvice {
24 private static final int IDX_COMPUTER = 0;
25 private static final int IDX_DESCRIPTOR = 1;
26
27 // String config -> Object[] { GatheringComputer, Map: permission -> Set, String }
28 private final Map<String, Object[]> advice = new HashMap<>();
29 private String featureId;
30 private Version featureVersion;
31
32 @Override
33 public boolean isApplicable(String configSpec, boolean includeDefault, String id, Version version) {
34 if (featureId != null && !featureId.equals(id))
35 return false;
36 if (featureVersion != null && !featureVersion.equals(version))
37 return false;
38
39 if (configSpec != null && !advice.containsKey(configSpec))
40 return false;
41
42 return true;
43 }
44
45 /**
46 * Return the configs for which we have advice
47 * @return String[]
48 */
49 public String[] getConfigs() {
50 return advice.keySet().toArray(new String[advice.size()]);
51 }
52
53 /**
54 * Return the GatheringComputer containing the set of rootfiles to include for the given config
55 * Returns null if we have no advice for the given config.
56 * @param config
57 * @return GatheringComputer
58 */
59 @Override
60 public IPathComputer getRootFileComputer(String config) {
61 if (advice.containsKey(config))
62 return (GatheringComputer) advice.get(config)[IDX_COMPUTER];
63 return null;
64 }
65
66 public void addRootfiles(String config, GatheringComputer computer) {
67 Object[] configAdvice = getConfigAdvice(config);
68
69 if (configAdvice[IDX_COMPUTER] == null)
70 configAdvice[IDX_COMPUTER] = computer;
71 else {
72 GatheringComputer existing = (GatheringComputer) configAdvice[IDX_COMPUTER];
73 existing.addAll(computer);
74 }
75 FileSetDescriptor descriptor = getDescriptor(config);
76 descriptor.addFiles(computer.getFiles());
77 }
78
79 public void addPermissions(String config, String permissions, String[] files) {
80 FileSetDescriptor descriptor = getDescriptor(config);
81 for (String file : files) {
82 descriptor.addPermissions(new String[]{permissions, file});
83 }
84 }
85
86 public void addLinks(String config, String links) {
87 FileSetDescriptor descriptor = getDescriptor(config);
88 descriptor.setLinks(links);
89 }
90
91 private Object[] getConfigAdvice(String config) {
92 Object[] configAdvice = advice.get(config);
93 if (configAdvice == null) {
94 configAdvice = new Object[3];
95 advice.put(config, configAdvice);
96 }
97 return configAdvice;
98 }
99
100 @Override
101 public FileSetDescriptor getDescriptor(String config) {
102 Object[] configAdvice = getConfigAdvice(config);
103 FileSetDescriptor descriptor = null;
104
105 if (configAdvice[IDX_DESCRIPTOR] != null)
106 descriptor = (FileSetDescriptor) configAdvice[IDX_DESCRIPTOR];
107 else {
108 String key = "root"; //$NON-NLS-1$
109 if (config.length() > 0)
110 key += "." + config; //$NON-NLS-1$
111 descriptor = new FileSetDescriptor(key, config);
112 configAdvice[IDX_DESCRIPTOR] = descriptor;
113 }
114 return descriptor;
115 }
116
117 public void setFeatureId(String featureId) {
118 this.featureId = featureId;
119 }
120
121 public void setFeatureVersion(Version featureVersion) {
122 this.featureVersion = featureVersion;
123 }
124
125 @Override
126 public String[] getConfigurations() {
127 Set<String> keys = advice.keySet();
128 return keys.toArray(new String[keys.size()]);
129 }
130
131 }