Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolved requirement: Require-Bundle on AUT's startup #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.eclipse.rcptt.internal.launching.ext.Q7UpdateSiteExtensions.Q7RuntimeInfo.SWT_PLATFORM;

import java.net.URI;
import java.util.ArrayList;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -28,11 +28,9 @@
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.rcptt.internal.launching.ext.Q7UpdateSiteExtensions.Q7RuntimeInfo;
import org.eclipse.rcptt.launching.ext.AUTInformation;
Expand All @@ -47,10 +45,6 @@
import com.google.common.collect.ImmutableList.Builder;

public class Q7TargetPlatformInitializer {

private static final String GMF = "gmf";
private static final String DRAW2D = "draw2d";
private static final String GEF = "gef";
private static final String EMF_FEATURE_GROUP = "org.eclipse.emf.feature.group";
private static final String EQUINOX_EXECUTABLE_FEATURE_GROUP = "org.eclipse.equinox.executable.feature.group";
private static final String EMF_VALIDATION_FEATURE_GROUP = "org.eclipse.emf.validation.feature.group";
Expand Down Expand Up @@ -106,7 +100,7 @@ public static IStatus initialize(ITargetPlatformHelper target,
try {
// Check for dependencies
IMetadataRepository repository = PDEHelper.safeLoadRepository(
q7Info.q7, new SubProgressMonitor(monitor, 20));
q7Info.q7, SubMonitor.convert(monitor, 20));
if (repository == null) {
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
Expand All @@ -118,7 +112,7 @@ public static IStatus initialize(ITargetPlatformHelper target,
MultiStatus rv = new MultiStatus(PLUGIN_ID, 0, "Runtime injection failed for target platform " + target,
null);
if (injectionConfiguration != null) {
rv.add(target.applyInjection(injectionConfiguration, new SubProgressMonitor(
rv.add(target.applyInjection(injectionConfiguration, SubMonitor.convert(
monitor, 60)));
if (rv.matches(IStatus.CANCEL))
return rv;
Expand All @@ -129,12 +123,12 @@ public static IStatus initialize(ITargetPlatformHelper target,
} catch (CoreException e) {
return e.getStatus();
}

}

public static InjectionConfiguration createInjectionConfiguration(
IProgressMonitor monitor, Q7Info q7Info, Map<String, Version> map) {
boolean hasEMF = map.containsKey(AUTInformation.EMF);
boolean hasEMFWorkspace = map.containsKey(AUTInformation.EMF_WORKSPACE);
boolean hasEMFTransaction = map
.containsKey(AUTInformation.EMF_TRANSACTION);
boolean hasEMFValidation = map
Expand Down Expand Up @@ -212,42 +206,6 @@ public static InjectionConfiguration createInjectionConfiguration(
return injectionConfiguration;
}

@SuppressWarnings("unused")
private static List<String> collectQ7InstallIDs(IProgressMonitor monitor,
boolean hasGEF, boolean hasGMF, IMetadataRepository repository) {
IQueryResult<IInstallableUnit> result = repository.query(
QueryUtil.ALL_UNITS, monitor);
List<String> q7Units = new ArrayList<String>();
for (IInstallableUnit unit : result.toSet()) {
if (hasProperty(unit, P2_GROUP_FEATURE, "true")) {
continue;
}
if (hasProperty(unit, P2_CATEGORY_FEATURE, "true")) {
continue;
}

// Skip gef/ gmf if not pressent
String unitId = unit.getId();
if (!hasGEF) {
if (unitId.contains(GEF)) {
continue;
}
if (unitId.contains(DRAW2D)) {
continue;
}
if (unitId.contains(GMF)) {
continue;
}
}
if (!hasGMF) {
if (unitId.contains(GMF)) {
continue;
}
}
q7Units.add(unitId);
}
return q7Units;
}

public static void logError(TargetPlatformHelper info) {
Q7ExtLaunchingPlugin.log(new MultiStatus(PLUGIN_ID, 0, new IStatus[] { info.getStatus() },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*******************************************************************************
* Copyright (c) 2019 Xored Software Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Xored Software Inc - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.rcptt.launching.ext;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.osgi.service.resolver.BundleSpecification;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.osgi.framework.Version;

public final class DependencyResolver {

private final Map<String, IPluginModelBase> dependecies;
private final Map<IPluginModelBase, Boolean> visit = new HashMap<>();

public DependencyResolver(Map<String, IPluginModelBase> dependecies) {
Objects.requireNonNull(dependecies);
this.dependecies = dependecies;
}

public Collection<IPluginModelBase> checkPlugins(Collection<IPluginModelBase> toCheckDeps) {
Objects.requireNonNull(toCheckDeps);
visit.clear();
List<IPluginModelBase> toRemove = new ArrayList<>();

toCheckDeps.forEach(dep -> {
if (!checkPlugin(dep)) {
toRemove.add(dep);
}
});
return Collections.unmodifiableList(toRemove);
}

private boolean checkPlugin(IPluginModelBase plugin) {
if (plugin == null) {
return false;
}
if (visit.containsKey(plugin)) {
return visit.get(plugin);
}

for (BundleSpecification dep : plugin.getBundleDescription().getRequiredBundles()) {
if (dep.isOptional()) {
continue;
}
if (!dependecies.containsKey(dep.getName())) {
visit.put(plugin, false);
return false;
}
if (!dep.getVersionRange()
.isIncluded(new Version(dependecies.get(dep.getName()).getPluginBase().getVersion()))) {
visit.put(plugin, false);
return false;
}
visit.put(plugin, true);
if (!checkPlugin(dependecies.get(dep.getName()))) {
visit.put(plugin, false);
return false;
}
}

visit.put(plugin, true);
return true;
}
private class Node {
public final String bundleId;
public final List<String> dependencies;

public Node(IPluginModelBase plugin) {
dependencies = Stream.of(plugin.getBundleDescription().getRequiredBundles()).map(dep -> dep.getName())
.collect(Collectors.toList());
this.bundleId = plugin.getBundleDescription().getName();
}
}

private List<IPluginModelBase> TarjanAlgorithm(Collection<IPluginModelBase> toCheckDeps) {
Map<String, Node> allNodes = new HashMap<>();
Map<Node, IPluginModelBase> nodeToPluginMap = new HashMap<>();
LinkedHashSet<Node> visited = new LinkedHashSet<>();
Set<Node> grays = new HashSet<>();
dependecies.values().forEach(plugin -> {
Node node = new Node(plugin);
allNodes.put(node.bundleId, node);
});

toCheckDeps.forEach(plugin -> {
if (allNodes.containsKey(plugin.getBundleDescription().getName())) {
nodeToPluginMap.put(allNodes.get(plugin.getBundleDescription().getName()), plugin);
} else{
Node node = new Node(plugin);
nodeToPluginMap.put(node, plugin);
}
});

for (Node node : nodeToPluginMap.keySet()) {
TarjanDepthSearch(node, allNodes, grays, visited);
}

List<IPluginModelBase> result = visited.stream().map(nodeToPluginMap::get).collect(Collectors.toList());
Collections.reverse(result);
return result;

}

public boolean TarjanDepthSearch(Node node, Map<String, Node> allNodes, Set<Node> grays, Set<Node> result) {
if (grays.contains(node)) {
return false;
}
if (result.contains(node)) {
return true;
}
grays.add(node);

for (String dep : node.dependencies) {
Node depNode = allNodes.get(dep);
if (depNode == null) {
return false;
}
if (!TarjanDepthSearch(depNode, allNodes, grays, result)) {
return false;
}
}

grays.remove(node);

result.add(node);
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
Expand All @@ -50,7 +51,6 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
Expand Down Expand Up @@ -181,7 +181,7 @@ public boolean preLaunchCheck(ILaunchConfiguration configuration,
monitor.beginTask("", 4);
if (!isHeadless(configuration)
&& !super.preLaunchCheck(configuration, mode,
new SubProgressMonitor(monitor, 1))) {
SubMonitor.convert(monitor, 1))) {
monitor.done();
return false;
}
Expand Down Expand Up @@ -328,7 +328,7 @@ private void waitForClearBundlePool(IProgressMonitor monitor) {
try {
Job.getJobManager().join(
IBundlePoolConstansts.CLEAN_BUNDLE_POOL_JOB,
new SubProgressMonitor(monitor, 1));
SubMonitor.convert(monitor, 1));
} catch (Exception e1) {
Q7ExtLaunchingPlugin.getDefault().log(
"Failed to wait for bundle pool clear job", e1);
Expand Down Expand Up @@ -608,35 +608,44 @@ protected void preLaunchCheck(final ILaunchConfiguration configuration,
ITargetPlatformHelper target = (ITargetPlatformHelper) info.target;

BundlesToLaunch bundlesToLaunch = collectBundlesCheck(target.getQ7Target(), target.getTarget(), subm.newChild(50), configuration);

setBundlesToLaunch(info, bundlesToLaunch);

removeDuplicatedModels(bundlesToLaunch.fModels, target.getQ7Target());

removeDuplicatedModels(bundlesToLaunch.fModels, target.getQ7Target(), bundlesToLaunch.fAllBundles);
checkBundles(bundlesToLaunch);
setDelegateFields(this, bundlesToLaunch.fModels, bundlesToLaunch.fAllBundles);

// Copy all additional configuration area folders into PDE new
// configuration location.
copyConfiguratonFiles(configuration, info);
monitor.done();
}

private void checkBundles(BundlesToLaunch launch) {
DependencyResolver resolver = new DependencyResolver(launch.fAllBundles);
Collection<IPluginModelBase> toDelete = resolver.checkPlugins(launch.fModels.keySet());
toDelete.forEach(plugin->{
launch.fAllBundles.remove(plugin.getBundleDescription().getName());
});

public static void removeDuplicatedModels(Map<IPluginModelBase, String> fModels, Q7Target target) {
}

private void removeDuplicatedModels(Map<IPluginModelBase, String> fModels, Q7Target target, Map<String, IPluginModelBase> deps) {
String path = target.getInstallLocation().getAbsolutePath();
List<IPluginModelBase> keysForRemove = new ArrayList<IPluginModelBase>();
Map<UniquePluginModel, IPluginModelBase> cache = new HashMap<UniquePluginModel, IPluginModelBase>();

for (Entry<IPluginModelBase, String> entry : fModels.entrySet()) {
IPluginModelBase model = entry.getKey();
UniquePluginModel uniqueModel = new UniquePluginModel(model);
IPluginModelBase secondModel = cache.get(uniqueModel);
if (secondModel != null) {
if (secondModel.getInstallLocation().contains(path)) {
keysForRemove.add(secondModel);
continue;
} else {
keysForRemove.add(model);
continue;
}

} else {
cache.put(uniqueModel, model);
}
Expand All @@ -645,7 +654,7 @@ public static void removeDuplicatedModels(Map<IPluginModelBase, String> fModels,
fModels.remove(key);
}
}

public static class BundlesToLaunchCollector {
private void addInstallationBundle(TargetBundle bundle,
BundleStart hint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map.Entry;

Expand Down Expand Up @@ -45,8 +46,10 @@
import org.eclipse.rcptt.launching.IQ7Launch;
import org.eclipse.rcptt.launching.events.AutEventManager;
import org.eclipse.rcptt.launching.ext.BundleStart;
import org.eclipse.rcptt.launching.ext.DependencyResolver;
import org.eclipse.rcptt.launching.ext.OriginalOrderProperties;
import org.eclipse.rcptt.launching.ext.Q7ExternalLaunchDelegate;
import org.eclipse.rcptt.launching.ext.Q7ExternalLaunchDelegate.BundlesToLaunch;
import org.eclipse.rcptt.launching.ext.Q7LaunchDelegateUtils;
import org.eclipse.rcptt.launching.internal.target.TargetPlatformHelper;
import org.eclipse.rcptt.launching.target.ITargetPlatformHelper;
Expand Down Expand Up @@ -150,6 +153,7 @@ public boolean preLaunchCheck(ILaunchConfiguration configuration,
IStatus rv = Q7TargetPlatformInitializer.initialize(helper, monitor);
if (!rv.isOK())
Activator.getDefault().getLog().log(rv);

helper.save();
Q7TargetPlatformManager.setHelper(targetName, helper);
}
Expand Down