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

JBIDE-14413 #127

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.jboss.tools.stacks.core;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.jboss.tools.foundation.plugin.BaseCorePlugin;
import org.jboss.tools.foundation.plugin.log.IPluginLog;
import org.jboss.tools.foundation.plugin.log.StatusFactory;
import org.osgi.framework.BundleContext;

public class StacksCoreActivator extends Plugin {
public class StacksCoreActivator extends BaseCorePlugin {

public static final String PLUGIN_ID = "org.jboss.tools.stacks.core";
private static BundleContext context;
Expand Down Expand Up @@ -35,20 +35,25 @@ public void start(BundleContext bundleContext) throws Exception {
public void stop(BundleContext bundleContext) throws Exception {
StacksCoreActivator.context = null;
}
public static void log(Throwable e) {
IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e
.getLocalizedMessage(), e);
getDefault().getLog().log(status);
}

public static void log(Throwable e, String message) {
IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message, e);
getDefault().getLog().log(status);
}

public static void log(String message) {
IStatus status = new Status(IStatus.INFO, PLUGIN_ID, message);
getDefault().getLog().log(status);

/**
* Get the IPluginLog for this plugin. This method
* helps to make logging easier, for example:
*
* FoundationCorePlugin.pluginLog().logError(etc)
*
* @return IPluginLog object
*/
public static IPluginLog pluginLog() {
return getDefault().pluginLogInternal();
}

/**
* Get a status factory for this plugin
* @return status factory
*/
public static StatusFactory statusFactory() {
return getDefault().statusFactoryInternal();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.jboss.jdf.stacks.client.StacksClient;
import org.jboss.jdf.stacks.client.StacksClientConfiguration;
import org.jboss.jdf.stacks.model.Stacks;
Expand All @@ -32,23 +34,58 @@ public class StacksManager {
*/
private static final String STACKS_URL_PROPERTY = "org.jboss.examples.stacks.url";
private static final String STACKS_URL;


// TODO move into client jar also?
private static final String PRESTACKS_URL = "https://raw.github.com/jboss-jdf/jdf-stack/1.0.0.Final/pre-stacks.yaml";

// Declare the types of stacks available for fetch
public enum StacksType {
STACKS_TYPE, PRESTACKS_TYPE
}

// Load the default stacks url from a sysprop or jar
static {
String defaultUrl = getStacksUrlFromJar(); //$NON-NLS-1$
STACKS_URL = System.getProperty(
STACKS_URL_PROPERTY, defaultUrl); //$NON-NLS-1$
}

public Stacks getStacks(IProgressMonitor monitor) {
return getStacks(STACKS_URL, "stacks", "yaml", monitor);
return getStacks(STACKS_URL, "stacks.yaml", monitor);
}

// Added for easier testing

public Stacks[] getStacks(String jobName, IProgressMonitor monitor, StacksType... types) {
if( types == null )
return new Stacks[0];

ArrayList<Stacks> ret = new ArrayList<Stacks>(types.length);
monitor.beginTask(jobName, types.length * 100);
for( int i = 0; i < types.length; i++ ) {
switch(types[i] ) {
case STACKS_TYPE:
ret.add(getStacks(STACKS_URL, jobName, new SubProgressMonitor(monitor, 100)));
break;
case PRESTACKS_TYPE:
ret.add(getStacks(PRESTACKS_URL, jobName, new SubProgressMonitor(monitor, 100)));
break;
default:
break;
}
}
monitor.done();
return (Stacks[]) ret.toArray(new Stacks[ret.size()]);
}

// Added for easier testing Please use other signatures.
@Deprecated
protected Stacks getStacks(String url, String prefix, String suffix, IProgressMonitor monitor) {
String jobName = prefix + "." + suffix;
return getStacks(url, jobName, monitor);
}

protected Stacks getStacks(String url, String jobName, IProgressMonitor monitor) {
Stacks stacks = null;
try {
String jobName = prefix + "." + suffix;
File f = getCachedFileForURL(url, jobName, monitor);
if (f != null && f.exists()) {
FileInputStream fis = null;
Expand All @@ -61,10 +98,10 @@ protected Stacks getStacks(String url, String prefix, String suffix, IProgressMo
}
}
} catch (Exception e) {
StacksCoreActivator.log(e, "Can't access or parse " + STACKS_URL ); //$NON-NLS-1$
StacksCoreActivator.pluginLog().logError("Can't access or parse " + url, e ); //$NON-NLS-1$
}
if (stacks == null) {
StacksCoreActivator.log("Stacks from "+STACKS_URL +" can not be read, falling back on default Stacks Client values");
StacksCoreActivator.pluginLog().logWarning("Stacks from "+ url +" can not be read, falling back on default Stacks Client values");
StacksClient client = new StacksClient();
stacks = client.getStacks();
}
Expand Down Expand Up @@ -93,8 +130,7 @@ private static String getStacksUrlFromJar() {
p.load(is);
return p.getProperty(StacksClientConfiguration.REPO_PROPERTY);
} catch (Exception e) {
System.err.println("Can't read stacks url from the stacks-client.jar"); //$NON-NLS-1$
e.printStackTrace();
StacksCoreActivator.pluginLog().logWarning("Can't read stacks url from the stacks-client.jar", e); //$NON-NLS-1$
} finally {
close(is);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public StacksCoreTestActivator() {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
this.context = context;
StacksCoreTestActivator.context = context;
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jboss.tools.stacks.core.test;

import java.net.URL;
import java.util.Iterator;
import java.util.List;

import junit.framework.TestCase;
Expand Down Expand Up @@ -34,7 +33,7 @@ private StacksManager2 getProtectedManager() {

private static class StacksManager2 extends StacksManager {
public Stacks getStacks2(String url, String prefix, String suffix, IProgressMonitor monitor) {
return super.getStacks(url, prefix, suffix, monitor);
return super.getStacks(url, prefix + "." + suffix, monitor);
}
}
}