| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2017 Code 9 and others. |
| 3 |
* |
| 4 |
* This |
| 5 |
* program and the accompanying materials are made available under the terms of |
| 6 |
* the Eclipse Public License 2.0 which accompanies this distribution, and is |
| 7 |
* available at |
| 8 |
* https://www.eclipse.org/legal/epl-2.0/ |
| 9 |
* |
| 10 |
* SPDX-License-Identifier: EPL-2.0 |
| 11 |
* |
| 12 |
* Contributors: |
| 13 |
* Code 9 - initial API and implementation |
| 14 |
******************************************************************************/ |
| 15 |
package org.eclipse.equinox.p2.publisher; |
| 16 |
|
| 17 |
import org.eclipse.equinox.p2.metadata.Version; |
| 18 |
import org.eclipse.equinox.p2.metadata.VersionRange; |
| 19 |
|
| 20 |
public class AbstractAdvice implements IPublisherAdvice { |
| 21 |
|
| 22 |
@Override |
| 23 |
public boolean isApplicable(String configSpec, boolean includeDefault, String id, Version version) { |
| 24 |
return matchConfig(configSpec, includeDefault) && matchId(id) && matchVersion(version); |
| 25 |
} |
| 26 |
|
| 27 |
protected boolean matchVersion(Version version) { |
| 28 |
if (version == null) |
| 29 |
return true; |
| 30 |
Version adviceVersion = getVersion(); |
| 31 |
if (adviceVersion != null) |
| 32 |
return version.equals(adviceVersion); |
| 33 |
VersionRange range = getVersionRange(); |
| 34 |
if (range != null) |
| 35 |
return range.isIncluded(version); |
| 36 |
return true; |
| 37 |
} |
| 38 |
|
| 39 |
protected Version getVersion() { |
| 40 |
return null; |
| 41 |
} |
| 42 |
|
| 43 |
protected VersionRange getVersionRange() { |
| 44 |
return null; |
| 45 |
} |
| 46 |
|
| 47 |
protected boolean matchId(String id) { |
| 48 |
if (id == null) |
| 49 |
return true; |
| 50 |
String adviceId = getId(); |
| 51 |
return adviceId == null ? true : adviceId.equals(id); |
| 52 |
} |
| 53 |
|
| 54 |
protected String getId() { |
| 55 |
return null; |
| 56 |
} |
| 57 |
|
| 58 |
protected boolean matchConfig(String configSpec, boolean includeDefault) { |
| 59 |
String adviceConfigSpec = getConfigSpec(); |
| 60 |
if (adviceConfigSpec == null) |
| 61 |
return includeDefault; |
| 62 |
String[] full = AbstractPublisherAction.parseConfigSpec(configSpec); |
| 63 |
String[] partial = AbstractPublisherAction.parseConfigSpec(adviceConfigSpec); |
| 64 |
for (int i = 0; i < partial.length; i++) { |
| 65 |
String string = partial[i]; |
| 66 |
if (string != null && !string.equals(full[i])) |
| 67 |
return false; |
| 68 |
} |
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
protected String getConfigSpec() { |
| 73 |
return null; |
| 74 |
} |
| 75 |
|
| 76 |
} |