Skip to content

Commit

Permalink
JBIDE-14548 fix IAE while installing plugins via project examples req…
Browse files Browse the repository at this point in the history
…uirements

- Moved mylyn discovery from central to project-examples
- refactored 3 ConnectorDiscovery creation points into one DiscoveryUtil
  method

Author:    Denis Golovin <dgolovin@gmail.com>
CoAuthor:    Fred Bricon <fbricon@gmail.com>
  • Loading branch information
dgolovin authored and fbricon committed Jun 19, 2013
1 parent 3420438 commit 1021f38
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 113 deletions.
3 changes: 0 additions & 3 deletions central/plugins/org.jboss.tools.central/META-INF/MANIFEST.MF
Expand Up @@ -38,10 +38,7 @@ Export-Package: org.jboss.tools.central,
org.jboss.tools.central.editors,
org.jboss.tools.central.editors.xpl,
org.jboss.tools.central.internal;x-friends:="org.jboss.tools.central.test",
org.jboss.tools.central.internal.discovery;x-friends:="org.jboss.tools.central.test",
org.jboss.tools.central.internal.discovery.wizards;x-friends:="org.jboss.tools.central.test",
org.jboss.tools.central.internal.discovery.wizards.xpl;x-friends:="org.jboss.tools.central.test",
org.jboss.tools.central.internal.xpl,
org.jboss.tools.central.jobs,
org.jboss.tools.central.model,
org.jboss.tools.central.preferences
Expand Up @@ -100,8 +100,6 @@
import org.eclipse.ui.part.PageBook;
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.internal.ImageUtil;
import org.jboss.tools.central.internal.discovery.ExpressionBasedBundleDiscoveryStrategy;
import org.jboss.tools.central.internal.discovery.ExpressionBasedRemoteBundleDiscoveryStrategy;
import org.jboss.tools.central.internal.discovery.wizards.ProxyWizard;
import org.jboss.tools.central.internal.discovery.wizards.ProxyWizardManager;
import org.jboss.tools.central.internal.discovery.wizards.ProxyWizardManager.ProxyWizardManagerListener;
Expand All @@ -110,6 +108,7 @@
import org.jboss.tools.central.jobs.RefreshTutorialsJob;
import org.jboss.tools.central.model.FeedsEntry;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.internal.discovery.DiscoveryUtil;
import org.jboss.tools.project.examples.model.ProjectExample;
import org.jboss.tools.project.examples.model.ProjectExampleCategory;
import org.jboss.tools.project.examples.wizard.NewProjectExamplesWizard2;
Expand Down Expand Up @@ -629,18 +628,10 @@ protected void installMissingWizard(final Collection<String> connectorIds) throw
final IStatus[] results = new IStatus[1];
final ConnectorDiscovery[] connectorDiscoveries = new ConnectorDiscovery[1];

//TODO Refactor the connector installation b/w the software page & project examples
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
connectorDiscoveries[0] = new ConnectorDiscovery();
// look for descriptors from installed bundles
connectorDiscoveries[0].getDiscoveryStrategies().add(new ExpressionBasedBundleDiscoveryStrategy());
ExpressionBasedRemoteBundleDiscoveryStrategy remoteDiscoveryStrategy = new ExpressionBasedRemoteBundleDiscoveryStrategy();
remoteDiscoveryStrategy.setDirectoryUrl(ProjectExamplesActivator.getDefault().getConfigurator().getJBossDiscoveryDirectory());
connectorDiscoveries[0].getDiscoveryStrategies().add(remoteDiscoveryStrategy);

connectorDiscoveries[0].setEnvironment(ProjectExamplesActivator.getEnvironment());
connectorDiscoveries[0].setVerifyUpdateSiteAvailability(true);
connectorDiscoveries[0] = DiscoveryUtil.createConnectorDiscovery();
connectorDiscoveries[0].setEnvironment(JBossCentralActivator.getEnvironment());
results[0] = connectorDiscoveries[0].performDiscovery(monitor);
if (monitor.isCanceled()) {
results[0] = Status.CANCEL_STATUS;
Expand Down
Expand Up @@ -122,10 +122,12 @@
import org.eclipse.ui.progress.WorkbenchJob;
import org.eclipse.ui.statushandlers.StatusManager;
import org.eclipse.ui.themes.IThemeManager;
import org.jboss.tools.central.internal.discovery.ChainedDiscoveryStrategy;
import org.jboss.tools.central.internal.discovery.ChainedDiscoveryStrategy.DataCollector;
import org.jboss.tools.central.internal.discovery.ExpressionBasedBundleDiscoveryStrategy;
import org.jboss.tools.central.internal.discovery.ExpressionBasedRemoteBundleDiscoveryStrategy;
import org.jboss.tools.project.examples.internal.discovery.ChainedDiscoveryStrategy;
import org.jboss.tools.project.examples.internal.discovery.ChainedDiscoveryStrategy.DataCollector;
import org.jboss.tools.project.examples.internal.discovery.ChainedDiscoveryStrategy.DiscoveryConnectorCollector;
import org.jboss.tools.project.examples.internal.discovery.DiscoveryUtil;
import org.jboss.tools.project.examples.internal.discovery.ExpressionBasedBundleDiscoveryStrategy;
import org.jboss.tools.project.examples.internal.discovery.ExpressionBasedRemoteBundleDiscoveryStrategy;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;

Expand All @@ -137,8 +139,6 @@
*/
public class DiscoveryViewer {

private static boolean ALLOW_DUPLICATE_DISCOVERY_CONNECTORS = Boolean.getBoolean("org.jboss.tools.central.allow.duplicate.connectors");

public class ConnectorBorderPaintListener implements PaintListener {
public void paintControl(PaintEvent e) {
Composite composite = (Composite) e.widget;
Expand Down Expand Up @@ -1493,24 +1493,7 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
if (DiscoveryViewer.this.installedFeatures == null) {
DiscoveryViewer.this.installedFeatures = getInstalledFeatures(monitor);
}

ConnectorDiscovery connectorDiscovery = new ConnectorDiscovery();
ChainedDiscoveryStrategy chainedDiscoveryStrategy = new ChainedDiscoveryStrategy(new DiscoveryConnectorCollector(ALLOW_DUPLICATE_DISCOVERY_CONNECTORS));

// look for remote descriptor first
if (directoryUrl != null) {
ExpressionBasedRemoteBundleDiscoveryStrategy remoteDiscoveryStrategy = new ExpressionBasedRemoteBundleDiscoveryStrategy();
remoteDiscoveryStrategy.setDirectoryUrl(directoryUrl);
chainedDiscoveryStrategy.addStrategy(remoteDiscoveryStrategy);
}

//Fall back on bundle discovery strategy
chainedDiscoveryStrategy.addStrategy(new ExpressionBasedBundleDiscoveryStrategy());

// look for descriptors from installed bundles
connectorDiscovery.getDiscoveryStrategies().add(chainedDiscoveryStrategy);


ConnectorDiscovery connectorDiscovery = DiscoveryUtil.createConnectorDiscovery(directoryUrl);
connectorDiscovery.setEnvironment(environment);
connectorDiscovery.setVerifyUpdateSiteAvailability(false);
try {
Expand Down Expand Up @@ -1602,26 +1585,4 @@ protected Set<String> getInstalledFeatures(IProgressMonitor monitor) throws Inte
return DiscoveryUi.createInstallJob().getInstalledFeatures(monitor);
}

private final class DiscoveryConnectorCollector implements DataCollector {

private boolean isComplete;

private boolean allowDuplicates;

public DiscoveryConnectorCollector(boolean allowDuplicates) {
this.allowDuplicates = allowDuplicates;
}

@Override
public boolean isComplete() {
return isComplete && !allowDuplicates;
}

@Override
public void collectData(AbstractDiscoveryStrategy ds) {
List<DiscoveryConnector> collected = ds.getConnectors();
isComplete = (collected != null && !collected.isEmpty());
}
}

}
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.internal.discovery.core.model.AbstractDiscoverySource;
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.internal.discovery.wizards.xpl.ExternalBundleDiscoveryStrategy;
import org.jboss.tools.project.examples.internal.discovery.xpl.ExternalBundleDiscoveryStrategy;

/**
* @author Fred Bricon
Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.internal.discovery.core.model.AbstractDiscoverySource;
import org.jboss.tools.central.internal.discovery.wizards.xpl.BundleDiscoveryStrategy;
import org.jboss.tools.project.examples.internal.discovery.xpl.BundleDiscoveryStrategy;

/**
* @author Fred Bricon
Expand Down
Expand Up @@ -14,7 +14,7 @@
import java.util.List;

import org.eclipse.mylyn.internal.discovery.core.model.AbstractDiscoveryStrategy;
import org.jboss.tools.central.internal.discovery.ChainedDiscoveryStrategy.DataCollector;
import org.jboss.tools.project.examples.internal.discovery.ChainedDiscoveryStrategy.DataCollector;

/**
* Collects {@link ProxyWizard}s discovered by {@link ProxyWizardDiscoveryStrategy}s
Expand Down
Expand Up @@ -25,8 +25,8 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.internal.discovery.core.model.ConnectorDiscovery;
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.internal.discovery.ChainedDiscoveryStrategy;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.internal.discovery.ChainedDiscoveryStrategy;


/**
Expand Down
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.internal.discovery.core.model.AbstractDiscoverySource;
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.internal.discovery.wizards.xpl.RemoteExternalBundleDiscoveryStrategy;
import org.jboss.tools.project.examples.internal.discovery.xpl.RemoteExternalBundleDiscoveryStrategy;

/**
*
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.internal.discovery.core.model.AbstractDiscoveryStrategy;
import org.jboss.tools.central.internal.discovery.ChainedDiscoveryStrategy;
import org.jboss.tools.project.examples.internal.discovery.ChainedDiscoveryStrategy;
import org.junit.Test;

public class ChainedDiscoveryStrategyTest {
Expand Down
Expand Up @@ -26,7 +26,8 @@
import org.jboss.tools.central.editors.JBossCentralEditor;
import org.jboss.tools.central.editors.SoftwarePage;
import org.jboss.tools.central.editors.xpl.DiscoveryViewer;
import org.jboss.tools.central.internal.discovery.ExpressionBasedDiscoveryConnector;
import org.jboss.tools.project.examples.internal.discovery.ChainedDiscoveryStrategy.DiscoveryConnectorCollector;
import org.jboss.tools.project.examples.internal.discovery.ExpressionBasedDiscoveryConnector;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -46,7 +47,7 @@ public class DiscoveryTest {
public static void init() throws Exception {
System.setProperty("central.URL", TEST_URL);
//Need to allow bundle discovery AND remote discovery hence :
System.setProperty("org.jboss.tools.central.allow.duplicate.connectors", Boolean.TRUE.toString());
System.setProperty(DiscoveryConnectorCollector.ALLOW_DUPLICATE_DISCOVERY_CONNECTORS_KEY, Boolean.TRUE.toString());
final WorkbenchWindow window = (WorkbenchWindow) PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
final IWorkbenchPage page = window.getActivePage();
Expand All @@ -64,7 +65,7 @@ public static void init() throws Exception {

@AfterClass
public static void shutDown() {
System.clearProperty("org.jboss.tools.central.allow.duplicate.connectors");
System.clearProperty(DiscoveryConnectorCollector.ALLOW_DUPLICATE_DISCOVERY_CONNECTORS_KEY);
System.clearProperty("central.URL");
}

Expand Down
Expand Up @@ -8,8 +8,8 @@

import junit.framework.Assert;

import org.jboss.tools.central.internal.xpl.ExpressionResolutionException;
import org.jboss.tools.central.internal.xpl.ExpressionResolver;
import org.jboss.tools.project.examples.internal.xpl.ExpressionResolutionException;
import org.jboss.tools.project.examples.internal.xpl.ExpressionResolver;
import org.junit.Test;

public class ExpressionResolverTest {
Expand Down
Expand Up @@ -51,6 +51,9 @@ Export-Package: org.jboss.tools.project.examples,
org.jboss.tools.project.examples.dialog,
org.jboss.tools.project.examples.dialog.xpl,
org.jboss.tools.project.examples.fixes,
org.jboss.tools.project.examples.internal.discovery;x-friends:="org.jboss.tools.central",
org.jboss.tools.project.examples.internal.discovery.xpl;x-internal:=true,
org.jboss.tools.project.examples.internal.xpl;x-internal:=true,
org.jboss.tools.project.examples.model,
org.jboss.tools.project.examples.preferences,
org.jboss.tools.project.examples.runtimes,
Expand Down
Expand Up @@ -1230,21 +1230,6 @@ private void logIgnoredExtensionPoint(IExtension extension) {
log(builder.toString());
}

public static Dictionary<Object, Object> getEnvironment() {
Dictionary<Object, Object> environment = new Hashtable<Object, Object>(
System.getProperties());
Bundle bundle = Platform.getBundle("org.jboss.tools.central"); //$NON-NLS-1$
Version version = bundle.getVersion();
environment.put("org.jboss.tools.central.version", version.toString()); //$NON-NLS-1$
environment.put(
"org.jboss.tools.central.version.major", version.getMajor()); //$NON-NLS-1$
environment.put(
"org.jboss.tools.central.version.minor", version.getMinor()); //$NON-NLS-1$
environment.put(
"org.jboss.tools.central.version.micro", version.getMicro()); //$NON-NLS-1$
return environment;
}

public static String getShortDescription(String description) {
if (description.length() <= DESCRIPTION_LENGTH) {
return description;
Expand Down
Expand Up @@ -8,7 +8,7 @@
* Contributors:
* JBoss by Red Hat - Initial implementation.
************************************************************************************/
package org.jboss.tools.central.internal.discovery;
package org.jboss.tools.project.examples.internal.discovery;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -25,7 +25,8 @@
import org.eclipse.mylyn.internal.discovery.core.model.DiscoveryCertification;
import org.eclipse.mylyn.internal.discovery.core.model.DiscoveryConnector;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.project.examples.ProjectExamplesActivator;


/**
*
Expand Down Expand Up @@ -53,7 +54,7 @@ public void performDiscovery(IProgressMonitor monitor) throws CoreException {
throw new IllegalStateException("At least one AbstractDiscoveryStrategy must be added");
}

MultiStatus status = new MultiStatus(JBossCentralActivator.PLUGIN_ID, 0,
MultiStatus status = new MultiStatus(ProjectExamplesActivator.PLUGIN_ID, 0,
"All attempts to discover connectors have failed", null);

for (AbstractDiscoveryStrategy ds : strategies) {
Expand Down Expand Up @@ -115,4 +116,41 @@ public interface DataCollector {

}

public final static class DiscoveryConnectorCollector implements DataCollector {

/**
* Use for testing purposes only
*/
public static String ALLOW_DUPLICATE_DISCOVERY_CONNECTORS_KEY = "org.jboss.tools.discovery.allow.duplicate.connectors";//$NON-NLS-1$

private boolean isComplete;

private boolean allowDuplicates;

/**
* Creates a new DiscoveryConnectorCollector instance which allows duplicate connectors if the <code>org.jboss.tools.discovery.allow.duplicate.connectors</code> system property exists and is set to true
*/
public DiscoveryConnectorCollector() {
this(Boolean.getBoolean(ALLOW_DUPLICATE_DISCOVERY_CONNECTORS_KEY));
}

/**
* Creates a new DiscoveryConnectorCollector instance. If <code>allowDuplicates</code> is true, duplicate connectors can be collected.
*/
public DiscoveryConnectorCollector(boolean allowDuplicates) {
this.allowDuplicates = allowDuplicates;
}

@Override
public boolean isComplete() {
return isComplete && !allowDuplicates;
}

@Override
public void collectData(AbstractDiscoveryStrategy ds) {
List<DiscoveryConnector> collected = ds.getConnectors();
isComplete = (collected != null && !collected.isEmpty());
}
}

}
@@ -0,0 +1,68 @@
/*************************************************************************************
* Copyright (c) 2008-2013 Red Hat, 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:
* JBoss by Red Hat - Initial implementation.
************************************************************************************/
package org.jboss.tools.project.examples.internal.discovery;

import java.util.Dictionary;
import java.util.Hashtable;

import org.eclipse.mylyn.internal.discovery.core.model.ConnectorDiscovery;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.internal.discovery.ChainedDiscoveryStrategy.DiscoveryConnectorCollector;

/**
* Discovery utility class.
*
* @author Fred Bricon
*
*/
public class DiscoveryUtil {

private DiscoveryUtil() {
}

/**
* Creates a new {@link ConnectorDiscovery} which looks for remote discovery sites first and falls back on locally defined connectors.
*/
public static ConnectorDiscovery createConnectorDiscovery() {
String directoryUrl = ProjectExamplesActivator.getDefault().getConfigurator().getJBossDiscoveryDirectory();
return createConnectorDiscovery(directoryUrl);
}

/**
* Creates a new {@link ConnectorDiscovery} which looks for a remote discovery site first and falls back on locally defined connectors.
*/
public static ConnectorDiscovery createConnectorDiscovery(String directoryUrl) {
ConnectorDiscovery connectorDiscovery = new ConnectorDiscovery();
ChainedDiscoveryStrategy chainedDiscoveryStrategy = new ChainedDiscoveryStrategy(new DiscoveryConnectorCollector());

// look for remote descriptor first
if (directoryUrl != null) {
ExpressionBasedRemoteBundleDiscoveryStrategy remoteDiscoveryStrategy = new ExpressionBasedRemoteBundleDiscoveryStrategy();
remoteDiscoveryStrategy.setDirectoryUrl(directoryUrl);
chainedDiscoveryStrategy.addStrategy(remoteDiscoveryStrategy);
}

// look for descriptors from installed bundles
chainedDiscoveryStrategy.addStrategy(new ExpressionBasedBundleDiscoveryStrategy());

connectorDiscovery.getDiscoveryStrategies().add(chainedDiscoveryStrategy);
connectorDiscovery.setVerifyUpdateSiteAvailability(true);
connectorDiscovery.setEnvironment(getEnvironment());
return connectorDiscovery;
}

private static Dictionary<Object, Object> getEnvironment() {
Dictionary<Object, Object> environment = new Hashtable<Object, Object>(
System.getProperties());
return environment;
}

}

0 comments on commit 1021f38

Please sign in to comment.