| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2010 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.equinox.internal.p2.update; |
| 15 |
|
| 16 |
import java.util.*; |
| 17 |
|
| 18 |
/* |
| 19 |
* Represents a site in a platform.xml file. |
| 20 |
*/ |
| 21 |
public class Site { |
| 22 |
|
| 23 |
public final static String POLICY_MANAGED_ONLY = "MANAGED-ONLY"; //$NON-NLS-1$ |
| 24 |
public final static String POLICY_USER_EXCLUDE = "USER-EXCLUDE"; //$NON-NLS-1$ |
| 25 |
public final static String POLICY_USER_INCLUDE = "USER-INCLUDE"; //$NON-NLS-1$ |
| 26 |
public final static String PROP_LINK_FILE = "org.eclipse.update.site.linkFile"; //$NON-NLS-1$ |
| 27 |
|
| 28 |
private String policy; |
| 29 |
private boolean enabled = true; |
| 30 |
private boolean updateable = true; |
| 31 |
private String url; |
| 32 |
private String linkFile; |
| 33 |
private Collection<Feature> features = new HashSet<>(); |
| 34 |
private List<String> list = new ArrayList<>(); |
| 35 |
|
| 36 |
public void addFeature(Feature feature) { |
| 37 |
this.features.add(feature); |
| 38 |
} |
| 39 |
|
| 40 |
public void addPlugin(String plugin) { |
| 41 |
this.list.add(plugin); |
| 42 |
} |
| 43 |
|
| 44 |
public boolean removePlugin(String plugin) { |
| 45 |
return this.list.remove(plugin); |
| 46 |
} |
| 47 |
|
| 48 |
public void setPluginList(List<String> plugins) { |
| 49 |
if (plugins == null) |
| 50 |
this.list = new ArrayList<>(); |
| 51 |
else |
| 52 |
this.list = plugins; |
| 53 |
} |
| 54 |
|
| 55 |
public Feature[] getFeatures() { |
| 56 |
return features.toArray(new Feature[features.size()]); |
| 57 |
} |
| 58 |
|
| 59 |
/* |
| 60 |
* Return the feature object with the specific id and version. Return null if |
| 61 |
* there is no match or the id is null. If the version is null then return the |
| 62 |
* first feature with a matching id. |
| 63 |
*/ |
| 64 |
public Feature getFeature(String id, String version) { |
| 65 |
if (id == null) |
| 66 |
return null; |
| 67 |
for (Feature feature : features) { |
| 68 |
if (id.equals(feature.getId())) { |
| 69 |
if (version == null || version.equals(feature.getVersion())) |
| 70 |
return feature; |
| 71 |
} |
| 72 |
} |
| 73 |
return null; |
| 74 |
} |
| 75 |
|
| 76 |
public Feature removeFeature(String featureURL) { |
| 77 |
for (Feature feature : features) { |
| 78 |
String nextURL = feature.getUrl(); |
| 79 |
if (nextURL != null && nextURL.equals(featureURL)) |
| 80 |
return features.remove(feature) ? feature : null; |
| 81 |
} |
| 82 |
return null; |
| 83 |
} |
| 84 |
|
| 85 |
public String getLinkFile() { |
| 86 |
return linkFile; |
| 87 |
} |
| 88 |
|
| 89 |
public String[] getList() { |
| 90 |
return list.toArray(new String[list.size()]); |
| 91 |
} |
| 92 |
|
| 93 |
public String getPolicy() { |
| 94 |
return policy; |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Note the string that we are returning is an <em>ENCODED</em> URI string. |
| 99 |
*/ |
| 100 |
public String getUrl() { |
| 101 |
return url; |
| 102 |
} |
| 103 |
|
| 104 |
public boolean isEnabled() { |
| 105 |
return enabled; |
| 106 |
} |
| 107 |
|
| 108 |
public boolean isUpdateable() { |
| 109 |
return updateable; |
| 110 |
} |
| 111 |
|
| 112 |
public void setEnabled(boolean enabled) { |
| 113 |
this.enabled = enabled; |
| 114 |
} |
| 115 |
|
| 116 |
public void setLinkFile(String linkFile) { |
| 117 |
this.linkFile = linkFile; |
| 118 |
} |
| 119 |
|
| 120 |
public void setPolicy(String policy) { |
| 121 |
this.policy = policy; |
| 122 |
} |
| 123 |
|
| 124 |
public void setUpdateable(boolean updateable) { |
| 125 |
this.updateable = updateable; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Note that the string should be an <em>ENCODED</em> URI string. |
| 130 |
*/ |
| 131 |
public void setUrl(String url) { |
| 132 |
this.url = url; |
| 133 |
} |
| 134 |
|
| 135 |
@Override |
| 136 |
public int hashCode() { |
| 137 |
return getUrl().hashCode(); |
| 138 |
} |
| 139 |
|
| 140 |
@Override |
| 141 |
public boolean equals(Object obj) { |
| 142 |
if (!(obj instanceof Site)) |
| 143 |
return false; |
| 144 |
Site other = (Site) obj; |
| 145 |
if (isEnabled() != other.isEnabled()) |
| 146 |
return false; |
| 147 |
if (isUpdateable() != other.isUpdateable()) |
| 148 |
return false; |
| 149 |
if (!getUrl().equals(other.getUrl())) |
| 150 |
return false; |
| 151 |
if (!Site.equals(getLinkFile(), other.getLinkFile())) |
| 152 |
return false; |
| 153 |
if (!Site.equals(getPolicy(), other.getPolicy())) |
| 154 |
return false; |
| 155 |
if (!Site.equals(getList(), other.getList())) |
| 156 |
return false; |
| 157 |
if (!Site.equals(getFeatures(), other.getFeatures())) |
| 158 |
return false; |
| 159 |
return true; |
| 160 |
} |
| 161 |
|
| 162 |
/* |
| 163 |
* Return a boolean value indicating whether or not the given objects are |
| 164 |
* considered equal. |
| 165 |
*/ |
| 166 |
public static boolean equals(Object one, Object two) { |
| 167 |
return one == null ? two == null : one.equals(two); |
| 168 |
} |
| 169 |
|
| 170 |
/* |
| 171 |
* Return a boolean value indicating whether or not the given lists are |
| 172 |
* considered equal. |
| 173 |
*/ |
| 174 |
public static boolean equals(Object[] one, Object[] two) { |
| 175 |
if (one == null && two == null) |
| 176 |
return true; |
| 177 |
if (one == null || two == null) |
| 178 |
return false; |
| 179 |
if (one.length != two.length) |
| 180 |
return false; |
| 181 |
for (Object one1 : one) { |
| 182 |
boolean found = false; |
| 183 |
for (int j = 0; !found && j < two.length; j++) { |
| 184 |
found = one1.equals(two[j]); |
| 185 |
} |
| 186 |
if (!found) |
| 187 |
return false; |
| 188 |
} |
| 189 |
return true; |
| 190 |
} |
| 191 |
} |