You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/01/04 14:22:42 UTC
svn commit: r1227144 [8/18] - in /karaf/eik/trunk: ./ features/
features/info.evanchik.eclipse.karaf.feature/
features/info.evanchik.eclipse.karaf.jmx.feature/
features/info.evanchik.eclipse.karaf.update/
features/info.evanchik.eclipse.karaf.update/fea...
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/console/KarafRemoteConsole.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/console/KarafRemoteConsole.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/console/KarafRemoteConsole.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/console/KarafRemoteConsole.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,280 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.console;
+
+import info.evanchik.eclipse.karaf.core.shell.KarafRemoteShellConnection;
+import info.evanchik.eclipse.karaf.core.shell.KarafSshConnectionUrl;
+import info.evanchik.eclipse.karaf.core.shell.KarafSshShellConnection;
+import info.evanchik.eclipse.karaf.ui.KarafLaunchConfigurationConstants;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+import info.evanchik.eclipse.karaf.ui.internal.KarafRemoteShellConnectJob;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IDebugEventSetListener;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.debug.ui.console.IConsoleColorProvider;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.ui.console.IOConsole;
+import org.eclipse.ui.console.IOConsoleInputStream;
+import org.eclipse.ui.console.IOConsoleOutputStream;
+import org.eclipse.ui.progress.UIJob;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class KarafRemoteConsole extends IOConsole implements IDebugEventSetListener {
+
+ public static final String KARAF_REMOTE_CONSOLE_TYPE = "info.evanchik.eclipse.karaf.console.remote";
+
+ private final IConsoleColorProvider colorProvider;
+
+ private final IOConsoleInputStream inputStream;
+
+ private final IProcess process;
+
+ private KarafRemoteShellConnection shellConnection;
+
+ /**
+ *
+ * @param process
+ * @param connectionUrl
+ * @param credentials
+ * @param colorProvider
+ * @param name
+ * @param encoding
+ */
+ public KarafRemoteConsole(
+ final IProcess process,
+ final KarafSshConnectionUrl connectionUrl,
+ final KarafSshShellConnection.Credentials credentials,
+ final IConsoleColorProvider colorProvider,
+ final String name,
+ final String encoding)
+ {
+ super(
+ name,
+ KARAF_REMOTE_CONSOLE_TYPE,
+ KarafUIPluginActivator.getDefault().getImageRegistry().getDescriptor(KarafUIPluginActivator.LOGO_16X16_IMG),
+ encoding,
+ true);
+
+ this.process = process;
+ this.inputStream = getInputStream();
+ this.colorProvider = colorProvider;
+
+ final Color color = this.colorProvider.getColor(IDebugUIConstants.ID_STANDARD_INPUT_STREAM);
+ this.inputStream.setColor(color);
+
+ final InputStream noAvailableInputStream = new FilterInputStream(inputStream) {
+ @Override
+ public int available() throws IOException {
+ return 0;
+ }
+ };
+
+ setName(computeName());
+ final IOConsoleOutputStream outputStream = newOutputStream();
+
+ boolean remoteShellEnabled = false;
+ try {
+ final ILaunchConfiguration configuration = process.getLaunch().getLaunchConfiguration();
+ remoteShellEnabled =
+ configuration.getAttribute(
+ KarafLaunchConfigurationConstants.KARAF_LAUNCH_START_REMOTE_CONSOLE,
+ false);
+ } catch (final CoreException e) {
+ return;
+ }
+
+ if (remoteShellEnabled) {
+ shellConnection =
+ new KarafSshShellConnection(
+ connectionUrl,
+ credentials,
+ noAvailableInputStream,
+ outputStream,
+ outputStream);
+
+ final KarafRemoteShellConnectJob job = new KarafRemoteShellConnectJob(name, shellConnection);
+ job.addJobChangeListener(new JobChangeAdapter() {
+ @Override
+ public void done(final IJobChangeEvent event) {
+ if (!event.getResult().isOK()) {
+ final Throwable t = event.getResult().getException();
+ writeTo(outputStream, "Unable to connect to SSH server: " + (t != null ? t.getLocalizedMessage() : "Unknown error"));
+ }
+ }
+ });
+
+ DebugPlugin.getDefault().addDebugEventListener(new IDebugEventSetListener() {
+
+ @Override
+ public void handleDebugEvents(final DebugEvent[] events) {
+
+ for (final DebugEvent event : events) {
+ if ( process != null
+ && process.equals(event.getSource())
+ && event.getKind() == DebugEvent.TERMINATE)
+ {
+ job.cancel();
+ }
+ }
+ }
+ });
+
+ job.schedule(15 * 1000);
+ } else {
+ writeTo(outputStream, "The Karaf remote shell is disabled. Enable it in the launch configuration dialog");
+ }
+ }
+
+ /**
+ * @param outputStream
+ * @param message
+ */
+ private void writeTo(final IOConsoleOutputStream outputStream, final String message) {
+ try {
+ outputStream.write(message);
+ outputStream.flush();
+ } catch (final IOException e) {
+ // Do nothing
+ }
+ }
+
+ /**
+ * Returns the {@link IProcess} for this console
+ *
+ * @return the {@code IProcess} for this console
+ */
+ public IProcess getProcess() {
+ return process;
+ }
+
+ @Override
+ public void handleDebugEvents(final DebugEvent[] events) {
+ for (final DebugEvent event : events) {
+ if (event.getSource().equals(process)) {
+ if (event.getKind() == DebugEvent.TERMINATE) {
+ if (shellConnection != null) {
+ try {
+ shellConnection.disconnect();
+ } catch (final IOException e) {
+ KarafUIPluginActivator.getLogger().error("Unable to disconnect from SSH server", e);
+ }
+ }
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+
+ resetName();
+ }
+ }
+ }
+ }
+
+ /**
+ * Computes and returns the current name of this console.
+ *
+ * @return a name for this console
+ */
+ protected String computeName() {
+ String label = null;
+ final IProcess process = getProcess();
+ final ILaunchConfiguration config = process.getLaunch().getLaunchConfiguration();
+
+ label = process.getAttribute(IProcess.ATTR_PROCESS_LABEL);
+ if (label == null) {
+ if (config == null) {
+ label = process.getLabel();
+ } else {
+ // check if PRIVATE config
+ if (DebugUITools.isPrivate(config)) {
+ label = process.getLabel();
+ } else {
+ String type = null;
+ try {
+ type = config.getType().getName();
+ } catch (final CoreException e) {
+ }
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append("Remote shell connection to: ");
+ buffer.append(config.getName());
+ if (type != null) {
+ buffer.append(" ["); //$NON-NLS-1$
+ buffer.append(type);
+ buffer.append("] "); //$NON-NLS-1$
+ }
+ buffer.append(process.getLabel());
+ label = buffer.toString();
+ }
+ }
+ }
+
+ if (process.isTerminated()) {
+ return MessageFormat.format("<disconnected> {0}", (Object[]) new String[] { label });
+ }
+ return label;
+ }
+
+ @Override
+ protected void dispose() {
+ super.dispose();
+
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+
+ if (process.isTerminated()) {
+ if (shellConnection != null) {
+ try {
+ shellConnection.disconnect();
+ } catch (final IOException e) {
+ KarafUIPluginActivator.getLogger().error("Unable to disconnect from SSH server", e);
+ }
+ }
+ } else {
+ DebugPlugin.getDefault().addDebugEventListener(this);
+ }
+ }
+
+ private void resetName() {
+ final String newName = computeName();
+ final String name = getName();
+ if (!name.equals(newName)) {
+ final UIJob job = new UIJob("Update console title") { //$NON-NLS-1$
+ @Override
+ public IStatus runInUIThread(final IProgressMonitor monitor) {
+ KarafRemoteConsole.this.setName(newName);
+ return Status.OK_STATUS;
+ }
+ };
+ job.setSystem(true);
+ job.schedule();
+ }
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesContentProvider.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesContentProvider.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesContentProvider.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesContentProvider.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,116 @@
+package info.evanchik.eclipse.karaf.ui.features;
+
+import info.evanchik.eclipse.karaf.core.features.Bundle;
+import info.evanchik.eclipse.karaf.core.features.Feature;
+import info.evanchik.eclipse.karaf.core.features.Features;
+import info.evanchik.eclipse.karaf.core.features.FeaturesRepository;
+import info.evanchik.eclipse.karaf.ui.IKarafProject;
+import info.evanchik.eclipse.karaf.ui.model.AbstractContentModel;
+import info.evanchik.eclipse.karaf.ui.model.ContentModel;
+import info.evanchik.eclipse.karaf.ui.model.FeatureRepositoryContentModel;
+import info.evanchik.eclipse.karaf.ui.project.KarafProject;
+
+import java.util.List;
+
+import org.apache.commons.collections.ListUtils;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * A {@link ITreeContentProvider} suitable for displaying Apache Karaf Features
+ * Repositories.
+ *
+ * @see FeaturesResolverJob
+ * @see FeaturesRepository
+ * @see Features
+ * @see Feature
+ * @see Bundle
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ */
+public final class FeaturesContentProvider implements ITreeContentProvider {
+
+ private List<FeaturesRepository> featuresRepositories;
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object[] getChildren(final Object parentElement) {
+ if (parentElement instanceof IProject && KarafProject.isKarafProject((IProject) parentElement)) {
+ final IProject project = (IProject) parentElement;
+ final IKarafProject karafProject = (IKarafProject) project.getAdapter(IKarafProject.class);
+
+ return new Object[] { new FeatureRepositoryContentModel(karafProject) };
+ } else if (parentElement instanceof ContentModel) {
+ final ContentModel contentModel = (ContentModel) parentElement;
+ return contentModel.getElements();
+ } else if (parentElement == featuresRepositories && parentElement != null) {
+ return featuresRepositories.toArray();
+ } else if (parentElement instanceof FeaturesRepository) {
+ final FeaturesRepository featuresRepository = (FeaturesRepository) parentElement;
+ return featuresRepository.getFeatures().getFeatures().toArray();
+ } else if (parentElement instanceof Features) {
+ final Features features = (Features) parentElement;
+ return features.getFeatures().toArray();
+ } else if (parentElement instanceof Feature) {
+ final Feature feature = (Feature) parentElement;
+ return ListUtils.union(feature.getFeatures(), feature.getBundles()).toArray();
+ } else {
+ return new Object[0];
+ }
+ }
+
+ @Override
+ public Object[] getElements(final Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ @Override
+ public Object getParent(final Object element) {
+ if (element instanceof AbstractContentModel) {
+ return ((AbstractContentModel) element).getParent();
+ } else if (element instanceof FeaturesRepository) {
+ return featuresRepositories;
+ } else if (element instanceof Features) {
+ final Features features = (Features) element;
+ return features.getParent();
+ } else if (element instanceof Feature) {
+ return ((Feature)element).getParent();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean hasChildren(final Object element) {
+ if (element instanceof AbstractContentModel) {
+ return ((AbstractContentModel) element).getElements().length > 0;
+ } else if (element == featuresRepositories && element != null) {
+ return featuresRepositories.size() > 0;
+ } else if (element instanceof FeaturesRepository) {
+ final FeaturesRepository featuresRepository = (FeaturesRepository) element;
+ return featuresRepository.getFeatures().getFeatures().size() > 0;
+ } else if (element instanceof Features) {
+ final Features features = (Features) element;
+ return features.getFeatures().size() > 0;
+ } else if (element instanceof Feature) {
+ final Feature feature = (Feature) element;
+ return feature.getBundles().size() > 0 || feature.getFeatures().size() > 0;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
+ if (newInput != null) {
+ if (newInput instanceof List) {
+ featuresRepositories = (List<FeaturesRepository>) newInput;
+ }
+ }
+ }
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesLabelProvider.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesLabelProvider.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesLabelProvider.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesLabelProvider.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,119 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.features;
+
+import info.evanchik.eclipse.karaf.core.features.Bundle;
+import info.evanchik.eclipse.karaf.core.features.Feature;
+import info.evanchik.eclipse.karaf.core.features.Features;
+import info.evanchik.eclipse.karaf.core.features.FeaturesRepository;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+import info.evanchik.eclipse.karaf.ui.model.ContentModel;
+
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * A {@link LabelProvider} and {@link ITableLabelProvider} suitable for
+ * displaying Apache Karaf Features Repositories.
+ *
+ * @see FeaturesResolverJob
+ * @see FeaturesRepository
+ * @see Features
+ * @see Feature
+ * @see Bundle
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ */
+public final class FeaturesLabelProvider extends LabelProvider implements ITableLabelProvider {
+
+ public static final String MVN_URL_PREFIX = "mvn:"; //$NON-NLS-1$
+
+ @Override
+ public Image getColumnImage(final Object element, final int columnIndex) {
+ switch (columnIndex) {
+ case 0:
+ return getImage(element);
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public String getColumnText(final Object element, final int columnIndex) {
+
+ switch (columnIndex) {
+ case 0:
+ return getText(element);
+ case 1:
+ if (element instanceof Feature) {
+ final Feature feature = (Feature) element;
+ return feature.getVersion();
+ } else {
+ return null;
+ }
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public Image getImage(final Object element) {
+ if (element instanceof ContentModel) {
+ return ((ContentModel) element).getImage();
+ } else if (element instanceof FeaturesRepository) {
+ return KarafUIPluginActivator.getDefault().getImageRegistry().get(KarafUIPluginActivator.LOGO_16X16_IMG);
+ } else if (element instanceof Feature) {
+ return KarafUIPluginActivator.getDefault().getImageRegistry().get(KarafUIPluginActivator.FEATURE_OBJ_IBM);
+ } else if (element instanceof Bundle) {
+ return KarafUIPluginActivator.getDefault().getImageRegistry().get(KarafUIPluginActivator.BUNDLE_OBJ_IMG);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String getText(final Object element) {
+ if (element instanceof FeaturesRepository) {
+ final FeaturesRepository featuresRepository = (FeaturesRepository) element;
+ if (featuresRepository.getFeatures().getName() != null) {
+ return featuresRepository.getFeatures().getName();
+ } else {
+ return featuresRepository.getName();
+ }
+ } else if (element instanceof Features) {
+ final Features features = (Features) element;
+ if (features.getName() != null) {
+ return features.getName();
+ } else if (features.getParent() != null) {
+ return features.getParent().getName();
+ } else {
+ return null;
+ }
+ } else if (element instanceof Feature) {
+ final Feature feature = (Feature) element;
+ return feature.getName();
+ } else if (element instanceof Bundle) {
+ final Bundle bundle = (Bundle) element;
+ final String label;
+ if (bundle.getBundleUrl().startsWith(MVN_URL_PREFIX)) {
+ final String[] bundleComponents = bundle.getBundleUrl().split("/"); //$NON-NLS-1$
+ label = bundleComponents[1];
+ } else {
+ label = element.toString();
+ }
+
+ return label;
+ } else {
+ return element.toString();
+ }
+ }
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesResolverJob.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesResolverJob.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesResolverJob.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/features/FeaturesResolverJob.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,155 @@
+package info.evanchik.eclipse.karaf.ui.features;
+
+import info.evanchik.eclipse.karaf.core.KarafCorePluginUtils;
+import info.evanchik.eclipse.karaf.core.KarafPlatformModel;
+import info.evanchik.eclipse.karaf.core.PropertyUtils;
+import info.evanchik.eclipse.karaf.core.configuration.FeaturesSection;
+import info.evanchik.eclipse.karaf.core.features.FeaturesRepository;
+import info.evanchik.eclipse.karaf.core.features.XmlFeaturesRepository;
+import info.evanchik.eclipse.karaf.ui.IKarafProject;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.ops4j.pax.url.mvn.MvnURLConnectionFactory;
+
+/**
+ * A {@link Job} that loads an Apache Karaf features configuration file
+ * {@code org.apache.karaf.features.cfg} and examines all of the referenced
+ * Features Repositories. It then attempts to resolve each of the repositories
+ * in order to produce a {@link List} of {@link FeaturesRepository}
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class FeaturesResolverJob extends Job {
+
+ private static final String ORG_OPS4J_PAX_URL_MVN_CFG = "org.ops4j.pax.url.mvn.cfg";
+
+ private final List<FeaturesRepository> featuresRepositories =
+ Collections.synchronizedList(new ArrayList<FeaturesRepository>());
+
+ private final FeaturesSection featuresSection;
+
+ private final KarafPlatformModel karafPlatformModel;
+
+ public FeaturesResolverJob(final String name, final KarafPlatformModel karafPlatformModel, final FeaturesSection featuresSection) {
+ super("Resolving Features for " + name);
+
+ this.featuresSection = featuresSection;
+ this.karafPlatformModel = karafPlatformModel;
+ }
+
+ /**
+ * Getter for the {@link List} of {@link FeaturesRepository} objects. This
+ * {@code List} is read-only and is a synchronized list via
+ * {@link Collections#synchronizedList(List)}.
+ *
+ * @return the {@link List} of {@link FeaturesRepository} objects.
+ */
+ public List<FeaturesRepository> getFeaturesRepositories() {
+ return Collections.unmodifiableList(featuresRepositories);
+ }
+
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+ featuresSection.load();
+ featuresRepositories.clear();
+
+ return resolveFeatures(monitor);
+ }
+
+ /**
+ * Helper method that resolves Karaf Features.
+ *
+ * @param monitor
+ * the {@link IProgressMonitor} instance
+ * @return the {@link Status#OK_STATUS} if the Features are successfully
+ * resolved
+ */
+ private IStatus resolveFeatures(final IProgressMonitor monitor) {
+ monitor.beginTask("Loading Karaf Features", featuresSection.getRepositoryList().size());
+ try {
+
+ for (final String repository : featuresSection.getRepositoryList()) {
+
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+
+ try {
+ // Begin: Refactor this out in to an OPS4j mvn URL configuration
+ final Properties mvnConfiguration =
+ KarafCorePluginUtils.loadProperties(karafPlatformModel.getConfigurationDirectory().toFile(), ORG_OPS4J_PAX_URL_MVN_CFG);
+
+ final IKarafProject karafProject = (IKarafProject) karafPlatformModel.getAdapter(IKarafProject.class);
+ final Properties runtimeProperties = karafProject.getRuntimeProperties();
+
+ PropertyUtils.interpolateVariables(mvnConfiguration, runtimeProperties);
+
+ final String defaultRepos = (String) mvnConfiguration.get("org.ops4j.pax.url.mvn.defaultRepositories");
+ final String repos = (String) mvnConfiguration.get("org.ops4j.pax.url.mvn.repositories");
+
+ final String combinedRepos = KarafCorePluginUtils.join(Arrays.asList(new String[] { defaultRepos, repos }), ",");
+ mvnConfiguration.put("org.ops4j.pax.url.mvn.repositories", combinedRepos);
+ // End: Refactor
+
+ final String repositoryName;
+ final InputStream stream;
+ if (repository.startsWith(FeaturesLabelProvider.MVN_URL_PREFIX)) {
+ final MvnURLConnectionFactory urlConnectionFactory = new MvnURLConnectionFactory(mvnConfiguration);
+ stream = urlConnectionFactory.create(new URL(repository)).getInputStream();
+
+ final String[] repositoryComponents = repository.split("/"); //$NON-NLS-1$
+ repositoryName = repositoryComponents[1] + "-" + repositoryComponents[2]; //$NON-NLS-1$
+ } else {
+ stream = new URL(repository).openStream();
+
+ repositoryName = repository;
+ }
+
+ final FeaturesRepository newRepo = new XmlFeaturesRepository(repositoryName, stream);
+ featuresRepositories.add(newRepo);
+
+ monitor.worked(1);
+
+ } catch (final MalformedURLException e) {
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ } else {
+ return new Status(IStatus.WARNING, KarafUIPluginActivator.PLUGIN_ID, "Unable determine location for Features repository: " + repository, e);
+ }
+ } catch (final IOException e) {
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ } else {
+ return new Status(IStatus.WARNING, KarafUIPluginActivator.PLUGIN_ID, "Unable load Features repository: " + repository, e);
+ }
+ } catch (final CoreException e) {
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ } else {
+ return new Status(IStatus.ERROR, KarafUIPluginActivator.PLUGIN_ID, "Unable load Features repository: " + repository, e);
+ }
+ }
+ }
+
+ return Status.OK_STATUS;
+ } finally {
+ monitor.done();
+ }
+ }
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/JavaFilePropertyTester.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/JavaFilePropertyTester.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/JavaFilePropertyTester.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/JavaFilePropertyTester.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.internal;
+
+import java.io.File;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * A {@link PropertyTester} implemenation that us suitable for evaluating
+ * several {@link File} properties (file name, directory and, extension).
+ * <p>
+ * Consult the constants declared in {@link Property} for a description in how
+ * the test is performed.
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class JavaFilePropertyTester extends PropertyTester {
+
+ public static enum Property {
+ /**
+ * Matches the name of the file as returned by {@link File#getName()}
+ */
+ name,
+
+ /**
+ * Matches the directory of the file as returned by
+ * {@link File#getParent()}. The test does not attempt to match the
+ * directory exactly. Instead it considers a match if the file's
+ * directory ends with the supplied value.
+ */
+ directory,
+
+ /**
+ * Matches the extension of the file as returned by
+ * {@link IPath#getFileExtension()}. The {@code File} is converted to an
+ * {@link IPath} using the {@link File#getAbsolutePath()}
+ */
+ extension
+ }
+
+ @Override
+ public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
+ if (receiver instanceof File) {
+ final File f = (File) receiver;
+ if (property.equals(Property.name.toString())) {
+ return f.getName().equals(expectedValue);
+ } else if (property.equals(Property.directory.toString())) {
+ return f.getParent().endsWith((String) expectedValue);
+ } else if (property.equals(Property.extension.toString())) {
+ return new Path(f.getAbsolutePath()).getFileExtension().equals(expectedValue);
+ } else {
+ return false;
+ }
+ }
+
+ return false;
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafLaunchConfigurationAdapterFactory.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafLaunchConfigurationAdapterFactory.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafLaunchConfigurationAdapterFactory.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafLaunchConfigurationAdapterFactory.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,89 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.internal;
+
+import info.evanchik.eclipse.karaf.core.KarafPlatformModel;
+import info.evanchik.eclipse.karaf.core.KarafPlatformModelRegistry;
+import info.evanchik.eclipse.karaf.ui.IKarafProject;
+import info.evanchik.eclipse.karaf.ui.KarafLaunchConfigurationConstants;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+import info.evanchik.eclipse.karaf.ui.project.KarafProject;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class KarafLaunchConfigurationAdapterFactory implements IAdapterFactory {
+
+ @Override
+ public Object getAdapter(final Object adaptableObject, @SuppressWarnings("rawtypes") final Class adapterType) {
+
+ // TODO: This entire method is ugly and needs to be cleaned up
+
+ final Object adapted;
+ if ( KarafPlatformModel.class.equals(adapterType)
+ && adaptableObject instanceof ILaunchConfiguration)
+ {
+ final ILaunchConfiguration configuration = (ILaunchConfiguration) adaptableObject;
+ try {
+ if (configuration.getAttributes().containsKey(KarafLaunchConfigurationConstants.KARAF_LAUNCH_SOURCE_RUNTIME)) {
+ final String platformPath = (String) configuration.getAttributes().get(KarafLaunchConfigurationConstants.KARAF_LAUNCH_SOURCE_RUNTIME);
+ adapted = KarafPlatformModelRegistry.findPlatformModel(new Path(platformPath));
+ } else {
+ adapted = null;
+ }
+ } catch (final CoreException e) {
+ KarafUIPluginActivator.getLogger().error("Unable to find Karaf Platform model", e);
+ return null;
+ }
+ } else if ( IKarafProject.class.equals(adapterType)
+ && adaptableObject instanceof KarafPlatformModel)
+ {
+ IKarafProject karafProject = null;
+ final KarafPlatformModel karafPlatformModel = (KarafPlatformModel) adaptableObject;
+ for (final IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
+ if (KarafProject.isKarafProject(project)) {
+ karafProject = new KarafProject(project);
+ if (karafPlatformModel.getRootDirectory().equals(karafProject.getPlatformRootDirectory())) {
+ break;
+ }
+ }
+ }
+
+ adapted = karafProject;
+ } else if ( IKarafProject.class.equals(adapterType)
+ && adaptableObject instanceof IProject)
+ {
+ if (KarafProject.isKarafProject((IProject) adaptableObject)) {
+ adapted = new KarafProject((IProject) adaptableObject);
+ } else {
+ return null;
+ }
+ } else {
+ adapted = null;
+ }
+
+ return adapted;
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Class[] getAdapterList() {
+ return new Class[] { KarafPlatformModel.class, IKarafProject.class };
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafLaunchUtils.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafLaunchUtils.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafLaunchUtils.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafLaunchUtils.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,84 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.internal;
+
+import info.evanchik.eclipse.karaf.core.KarafCorePluginUtils;
+import info.evanchik.eclipse.karaf.core.KarafPlatformModel;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.pde.internal.core.target.DirectoryBundleContainer;
+import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class KarafLaunchUtils {
+
+ private static final int MAX_DIRECTORY_RECURSE_DEPTH = 50;
+
+ @SuppressWarnings("restriction")
+ public static List<IBundleContainer> getBundleContainers(final KarafPlatformModel karafPlatformModel) {
+ final Collection<File> directories = KarafLaunchUtils.getJarDirectories(karafPlatformModel);
+
+ final List<IBundleContainer> bundleContainers = new ArrayList<IBundleContainer>();
+ for (final File dir : directories) {
+ bundleContainers.add(new DirectoryBundleContainer(dir.getAbsolutePath()));
+ }
+
+ return bundleContainers;
+ }
+
+ /**
+ * Constructs an array of directories that contain plugins in the Karaf
+ * platform. This array includes the {@code lib} directory as well as all
+ * directories that contain JARs under {@code system} and {@code deploy}.
+ *
+ * @param karafPlatformModel
+ * the Karaf Platform
+ * @return the directories that contain JARs in the Karaf platform
+ */
+ public static Collection<File> getJarDirectories(final KarafPlatformModel karafPlatformModel) {
+ final List<File> jarFiles = new ArrayList<File>();
+ KarafCorePluginUtils.getJarFileList(
+ karafPlatformModel.getPluginRootDirectory().toFile(),
+ jarFiles,
+ MAX_DIRECTORY_RECURSE_DEPTH);
+
+ KarafCorePluginUtils.getJarFileList(
+ karafPlatformModel.getUserDeployedDirectory().toFile(),
+ jarFiles,
+ MAX_DIRECTORY_RECURSE_DEPTH);
+
+ // Add each JAR file's directory to the list of directories that contain
+ // plugins
+ final Set<File> directories = new HashSet<File>();
+ for (final File f : jarFiles) {
+ directories.add(f.getParentFile());
+ }
+
+ // Add the lib directory for completeness, if the developer is pulling a
+ // target platform they better know what the are doing
+ directories.add(karafPlatformModel.getRootDirectory().append("lib").toFile()); // $NON-NLS-1$
+
+ return directories;
+ }
+
+ private KarafLaunchUtils() {
+ throw new AssertionError("Do not instantiate");
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafRemoteShellConnectJob.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafRemoteShellConnectJob.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafRemoteShellConnectJob.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/KarafRemoteShellConnectJob.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,79 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.internal;
+
+import info.evanchik.eclipse.karaf.core.shell.KarafRemoteShellConnection;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+
+/**
+ * A s{@link Job} that will connect to a Karaf SSH server using the specified
+ * {@link KarafRemoteShellConnection}
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class KarafRemoteShellConnectJob extends Job {
+
+ private final KarafRemoteShellConnection karafRemoteShellConnection;
+
+ /**
+ * Creates a {@link Job} that will connect to a Karaf SSH server using the
+ * specified {@link KarafRemoteShellConnection}
+ *
+ * @param name
+ * the name of the {@code Job}
+ * @param karafRemoteShellConnection
+ * the {@code KarafRemoteShellConnection} to use
+ */
+ public KarafRemoteShellConnectJob(final String name, final KarafRemoteShellConnection karafRemoteShellConnection) {
+ super(name);
+
+ this.karafRemoteShellConnection = karafRemoteShellConnection;
+ }
+
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+
+ monitor.beginTask("Connecting to Karaf remote shell: " + getName(), 1);
+
+ try {
+
+ karafRemoteShellConnection.connect();
+
+ monitor.worked(1);
+
+ if (monitor.isCanceled()) {
+ karafRemoteShellConnection.disconnect();
+
+ return Status.CANCEL_STATUS;
+ }
+ } catch (final Exception e) {
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ } else {
+ return new Status(Status.ERROR, KarafUIPluginActivator.PLUGIN_ID, "Unable to connect to Karaf remote shell", e);
+ }
+ } finally {
+ monitor.done();
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ public boolean isConnected() {
+ return karafRemoteShellConnection.isConnected();
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/PopulateObrFileJob.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/PopulateObrFileJob.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/PopulateObrFileJob.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/PopulateObrFileJob.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,134 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.internal;
+
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.eclipse.ant.core.AntRunner;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class PopulateObrFileJob extends Job {
+
+ private static final String ANT_BUILD_OBR_FILE = "ant/build.xml";
+
+ private final File obrFile;
+
+ private volatile boolean obrComplete;
+
+ /**
+ * Creates a {@link Job} that will populate a {@link File} with OBR data
+ *
+ * @param name
+ * the name of the {@code Job}
+ * @param obrFile
+ * the {@code File} where this {@code Job} will write the OBR
+ * data
+ */
+ public PopulateObrFileJob(final String name, final File obrFile) {
+ super(name);
+
+ this.obrFile = obrFile;
+ }
+
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+ if (AntRunner.isBuildRunning()) {
+ schedule(15 * 1000);
+ return Status.OK_STATUS;
+ }
+
+ obrComplete = false;
+
+ File buildFile;
+ final AntRunner runner = new AntRunner();
+
+ try {
+ buildFile = getAntBuildFile();
+
+ runner.setBuildFileLocation(buildFile.getAbsolutePath());
+ runner.setArguments("-Dobr.filename=" + obrFile.getAbsolutePath());
+ runner.run(monitor);
+ } catch (final CoreException e) {
+ monitor.setCanceled(true);
+
+ return Status.CANCEL_STATUS;
+ } catch (final IOException e) {
+ monitor.setCanceled(true);
+
+ return Status.CANCEL_STATUS;
+ } finally {
+ monitor.done();
+ }
+
+ obrComplete = true;
+
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * Getter for the {@link File} that contains the OBR data
+ *
+ * @return the {@code File} that contains the OBR data
+ */
+ public File getObrFile() {
+ return obrFile;
+ }
+
+ /**
+ * Determines whether or the OBR file population has complated
+ *
+ * @return true if the OBR file is complete, false otherwise
+ */
+ public boolean isObrPopulationComplete() {
+ return obrComplete;
+ }
+
+ /**
+ * Getter for the {@code build.xml} file used to execute the
+ * {@link AntRunner}
+ *
+ * @return the {@link File} that the {@code AntRunner} will execute
+ * @throws IOException
+ * thrown if the {@code File} cannot be created
+ */
+ private File getAntBuildFile() throws IOException {
+ final Bundle thisBundle = KarafUIPluginActivator.getDefault().getBundle();
+ final URL[] urls = FileLocator.findEntries(thisBundle, new Path(ANT_BUILD_OBR_FILE));
+
+ if (urls.length > 1 || urls.length == 0) {
+ throw new AssertionError("Error locating Bundle URL for " + ANT_BUILD_OBR_FILE);
+ }
+
+ final URL fileUrl = FileLocator.toFileURL(urls[0]);
+
+ try {
+ return new File(fileUrl.toURI());
+ } catch (final URISyntaxException e) {
+ throw new IOException("Unable to convert URI to File", e);
+ }
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/WorkbenchServiceExtensions.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/WorkbenchServiceExtensions.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/WorkbenchServiceExtensions.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/internal/WorkbenchServiceExtensions.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2010 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.internal;
+
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+import info.evanchik.eclipse.karaf.ui.workbench.KarafWorkbenchServiceFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.Platform;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class WorkbenchServiceExtensions {
+
+ private static final String ATT_CLASS = "class";
+
+ private static final String TAG_LAUNCHCUSTOMIZER_ITEMTYPE = "launchCustomizer";
+
+ /**
+ * Gets all {@link KarafWorkbenchServiceFactory} objects that are a
+ * "launchCustomizer"
+ *
+ * @return a {@link List<KarafWorkbenchServiceFactory>} of 0 or more {@code
+ * KarafWorkbenchServiceFactory}
+ * @throws CoreException
+ * if there is a problem fetching information from the extension
+ * registry
+ */
+ public static List<KarafWorkbenchServiceFactory> getLaunchCustomizerFactories() throws CoreException {
+ final List<KarafWorkbenchServiceFactory> factories =
+ new ArrayList<KarafWorkbenchServiceFactory>();
+
+ final IExtension[] extensions = Platform.getExtensionRegistry()
+ .getExtensionPoint(KarafUIPluginActivator.PLUGIN_ID, "service")
+ .getExtensions();
+
+ for (final IExtension e : extensions) {
+ for (final IConfigurationElement c : e.getConfigurationElements()) {
+
+ if (!c.getName().equals(TAG_LAUNCHCUSTOMIZER_ITEMTYPE)) {
+ continue;
+ }
+
+ final KarafWorkbenchServiceFactory f =
+ (KarafWorkbenchServiceFactory)c.createExecutableExtension(ATT_CLASS);
+
+
+
+ factories.add(f);
+ }
+ }
+
+ return factories;
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/AbstractContentModel.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/AbstractContentModel.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/AbstractContentModel.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/AbstractContentModel.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.model;
+
+import info.evanchik.eclipse.karaf.core.KarafPlatformModel;
+import info.evanchik.eclipse.karaf.ui.IKarafProject;
+
+import org.eclipse.core.runtime.PlatformObject;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public abstract class AbstractContentModel extends PlatformObject implements ContentModel {
+
+ protected final KarafPlatformModel karafPlatformModel;
+
+ protected final IKarafProject project;
+
+ /**
+ *
+ * @param project
+ */
+ public AbstractContentModel(final IKarafProject project) {
+ this.project = project;
+ this.karafPlatformModel = (KarafPlatformModel) project.getAdapter(KarafPlatformModel.class);
+ }
+
+ @Override
+ public Object getAdapter(@SuppressWarnings("rawtypes") final Class adapter) {
+ if (KarafPlatformModel.class.equals(adapter)) {
+ return karafPlatformModel;
+ } else {
+ return super.getAdapter(adapter);
+ }
+ }
+
+ @Override
+ public Object getParent() {
+ return project.getProjectHandle();
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/BootClasspath.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/BootClasspath.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/BootClasspath.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/BootClasspath.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.model;
+
+import info.evanchik.eclipse.karaf.ui.IKarafProject;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+
+import java.io.File;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class BootClasspath extends AbstractContentModel {
+
+ /**
+ *
+ * @param project
+ */
+ public BootClasspath(final IKarafProject project) {
+ super(project);
+ }
+
+ /**
+ *
+ * @return
+ */
+ @Override
+ public Object[] getElements() {
+ final List<String> bootClasspath = karafPlatformModel.getBootClasspath();
+
+ final File[] files = new File[bootClasspath.size()];
+ for (int i = 0; i < files.length; i++) {
+ files[i] = new File(bootClasspath.get(i));
+ }
+
+ return files;
+ }
+
+ @Override
+ public Image getImage() {
+ return KarafUIPluginActivator.getDefault().getImageRegistry().get("runtime_obj");
+ }
+
+ @Override
+ public String toString() {
+ return "Boot classpath";
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/ConfigurationFiles.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/ConfigurationFiles.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/ConfigurationFiles.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/ConfigurationFiles.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.model;
+
+import info.evanchik.eclipse.karaf.ui.IKarafProject;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class ConfigurationFiles extends AbstractContentModel {
+
+ /**
+ *
+ * @param project
+ */
+ public ConfigurationFiles(final IKarafProject project) {
+ super(project);
+ }
+
+ @Override
+ public Object[] getElements() {
+ final List<Object> elements = new ArrayList<Object>();
+ return elements.toArray();
+ }
+
+ @Override
+ public Image getImage() {
+ return KarafUIPluginActivator.getDefault().getImageRegistry().get("details_view");
+ }
+
+ @Override
+ public String toString() {
+ return "Configuration Files";
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/ContentModel.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/ContentModel.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/ContentModel.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/ContentModel.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.model;
+
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public interface ContentModel {
+
+ /**
+ *
+ * @return
+ */
+ public Object[] getElements();
+
+ /**
+ *
+ * @return
+ */
+ public Image getImage();
+
+ /**
+ *
+ * @return
+ */
+ public Object getParent();
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/FeatureRepositoryContentModel.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/FeatureRepositoryContentModel.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/FeatureRepositoryContentModel.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/FeatureRepositoryContentModel.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,81 @@
+package info.evanchik.eclipse.karaf.ui.model;
+
+import info.evanchik.eclipse.karaf.core.features.FeaturesRepository;
+import info.evanchik.eclipse.karaf.core.features.XmlFeaturesRepository;
+import info.evanchik.eclipse.karaf.ui.IKarafProject;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class FeatureRepositoryContentModel extends AbstractContentModel {
+
+ private final Set<FeaturesRepository> featuresRepository = new HashSet<FeaturesRepository>();
+
+ /**
+ *
+ * @param project
+ */
+ public FeatureRepositoryContentModel(final IKarafProject project) {
+ super(project);
+ }
+
+ @Override
+ public Object[] getElements() {
+ FileInputStream fin = null;
+ try {
+ final IFolder featuresFolder = project.getFolder("features");
+ if (!featuresFolder.exists()) {
+ return new Object[0];
+ }
+
+ final IResource[] resources = featuresFolder.members();
+
+ for (final IResource featureFileResource : resources) {
+ if (featureFileResource.getFullPath().getFileExtension().equals("xml")) {
+ fin = new FileInputStream(featureFileResource.getRawLocation().toFile());
+ featuresRepository.add(new XmlFeaturesRepository(featureFileResource.getName(), fin));
+ fin.close();
+ } else {
+ // TODO: What to do here?
+ }
+ }
+ } catch (final IOException e) {
+ e.printStackTrace();
+ } catch (final CoreException e) {
+ e.printStackTrace();
+ } finally {
+ if (fin != null) {
+ try {
+ fin.close();
+ } catch (final IOException e) {
+ // This is intentionally left blank
+ }
+ }
+ }
+
+ return featuresRepository.toArray();
+ }
+
+ @Override
+ public Image getImage() {
+ return KarafUIPluginActivator.getDefault().getImageRegistry().get(KarafUIPluginActivator.FEATURE_OBJ_IBM);
+ }
+
+ @Override
+ public String toString() {
+ return "Feature Repositories";
+ }
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/SystemBundles.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/SystemBundles.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/SystemBundles.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/SystemBundles.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.model;
+
+import info.evanchik.eclipse.karaf.core.KarafCorePluginUtils;
+import info.evanchik.eclipse.karaf.ui.IKarafProject;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class SystemBundles extends AbstractContentModel {
+
+ /**
+ *
+ * @param project
+ */
+ public SystemBundles(final IKarafProject project) {
+ super(project);
+ }
+
+ @Override
+ public Object[] getElements() {
+ final List<File> files = new ArrayList<File>();
+
+ KarafCorePluginUtils.getFileList(karafPlatformModel.getPluginRootDirectory().toFile(), ".jar", files, 50);
+ KarafCorePluginUtils.getFileList(karafPlatformModel.getPluginRootDirectory().toFile(), ".war", files, 50);
+
+ return files.toArray(new Object[0]);
+ }
+
+ @Override
+ public Image getImage() {
+ return KarafUIPluginActivator.getDefault().getImageRegistry().get(KarafUIPluginActivator.BUNDLE_OBJ_IMG);
+ }
+
+ @Override
+ public String toString() {
+ return "System Bundles";
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/UserBundles.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/UserBundles.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/UserBundles.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/model/UserBundles.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.model;
+
+import info.evanchik.eclipse.karaf.core.KarafCorePluginUtils;
+import info.evanchik.eclipse.karaf.ui.IKarafProject;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class UserBundles extends AbstractContentModel {
+
+ /**
+ *
+ * @param project
+ */
+ public UserBundles(final IKarafProject project) {
+ super(project);
+ }
+
+ @Override
+ public Object[] getElements() {
+ final List<File> files = new ArrayList<File>();
+
+ KarafCorePluginUtils.getFileList(karafPlatformModel.getUserDeployedDirectory().toFile(), ".jar", files, 50);
+ KarafCorePluginUtils.getFileList(karafPlatformModel.getUserDeployedDirectory().toFile(), ".war", files, 50);
+
+ return files.toArray(new Object[0]);
+ }
+
+ @Override
+ public Image getImage() {
+ return KarafUIPluginActivator.getDefault().getImageRegistry().get(KarafUIPluginActivator.BUNDLE_OBJ_IMG);
+ }
+
+ @Override
+ public String toString() {
+ return "User Bundles";
+ }
+
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/navigator/KarafPlatformModelContentProvider.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/navigator/KarafPlatformModelContentProvider.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/navigator/KarafPlatformModelContentProvider.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/navigator/KarafPlatformModelContentProvider.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.navigator;
+
+import info.evanchik.eclipse.karaf.ui.model.AbstractContentModel;
+import info.evanchik.eclipse.karaf.ui.model.ContentModel;
+import info.evanchik.eclipse.karaf.ui.project.KarafProject;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class KarafPlatformModelContentProvider implements ITreeContentProvider {
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object[] getChildren(final Object parentElement) {
+ if (parentElement instanceof IProject && KarafProject.isKarafProject((IProject) parentElement)) {
+ return new Object[0];
+ } else if (parentElement instanceof ContentModel) {
+ final ContentModel model = (ContentModel) parentElement;
+ return model.getElements();
+ } else {
+ return new Object[0];
+ }
+ }
+
+ @Override
+ public Object[] getElements(final Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ @Override
+ public Object getParent(final Object element) {
+ if (element instanceof AbstractContentModel) {
+ final AbstractContentModel model = (AbstractContentModel) element;
+ return model.getParent();
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren(final Object element) {
+ if (element instanceof AbstractContentModel) {
+ final AbstractContentModel model = (AbstractContentModel) element;
+ return model.getElements() != null && model.getElements().length > 0;
+ }
+
+ return false;
+ }
+
+ @Override
+ public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/navigator/KarafPlatformModelLabelProvider.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/navigator/KarafPlatformModelLabelProvider.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/navigator/KarafPlatformModelLabelProvider.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/navigator/KarafPlatformModelLabelProvider.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,42 @@
+package info.evanchik.eclipse.karaf.ui.navigator;
+import info.evanchik.eclipse.karaf.ui.model.ContentModel;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class KarafPlatformModelLabelProvider extends LabelProvider implements ILabelProvider {
+
+ public KarafPlatformModelLabelProvider() {
+ super();
+ }
+
+ @Override
+ public Image getImage(final Object element) {
+ if (element instanceof ContentModel) {
+ return ((ContentModel) element).getImage();
+ }
+
+ return super.getImage(element);
+ }
+
+ @Override
+ public String getText(final Object element) {
+ return super.getText(element);
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/project/KarafBuildUnit.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/project/KarafBuildUnit.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/project/KarafBuildUnit.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/project/KarafBuildUnit.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.project;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public interface KarafBuildUnit {
+
+ /**
+ *
+ * @param kind
+ * @param args
+ * @param monitor
+ * @throws CoreException
+ */
+ public void build(final int kind, @SuppressWarnings("rawtypes") final Map args, final IProgressMonitor monitor) throws CoreException;
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/project/KarafProject.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/project/KarafProject.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/project/KarafProject.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.ui/src/main/java/info/evanchik/eclipse/karaf/ui/project/KarafProject.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,136 @@
+/**
+ * Copyright (c) 2011 Stephen Evanchik
+ * 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:
+ * Stephen Evanchik - initial implementation
+ */
+package info.evanchik.eclipse.karaf.ui.project;
+
+import info.evanchik.eclipse.karaf.core.KarafCorePluginUtils;
+import info.evanchik.eclipse.karaf.core.KarafPlatformModel;
+import info.evanchik.eclipse.karaf.core.KarafPlatformModelRegistry;
+import info.evanchik.eclipse.karaf.ui.IKarafProject;
+import info.evanchik.eclipse.karaf.ui.KarafUIPluginActivator;
+
+import java.util.Properties;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.QualifiedName;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class KarafProject extends PlatformObject implements IKarafProject {
+
+ private static final IPath ROOT_PATH = new Path(".bin");
+
+ public static final IPath ROOT_PLATFORM_PATH = ROOT_PATH.append("platform");
+
+ /**
+ * Determines if the {@link IProject} is actually an {@link IKarafProject}
+ *
+ * @param project
+ * the {@code IProject} to test
+ * @return true if the specified {@code IProject} is a {@code IKarafProject}
+ * ; false otherwise
+ */
+ public static boolean isKarafProject(final IProject project) {
+ try {
+ final String karafProject = project.getPersistentProperty(
+ new QualifiedName(KarafUIPluginActivator.PLUGIN_ID, "karafProject"));
+
+ return karafProject != null;
+ } catch (final CoreException e) {
+ KarafUIPluginActivator.getLogger().warn("Unable to determine if " + project.getName() + " is a Karaf Project", e);
+ }
+
+ return false;
+ }
+
+ private final IProject project;
+
+ /**
+ *
+ * @param project
+ */
+ public KarafProject(final IProject project) {
+ this.project = project;
+ }
+
+ @Override
+ public Object getAdapter(@SuppressWarnings("rawtypes") final Class adapter) {
+ if (KarafPlatformModel.class.equals(adapter)) {
+ try {
+ return KarafPlatformModelRegistry.findPlatformModel(getPlatformRootDirectory());
+ } catch (final CoreException e) {
+ KarafUIPluginActivator.getLogger().error("Unable to find Karaf Platform at the root directory: " + getPlatformRootDirectory().toOSString(), e);
+ return null;
+ }
+ } else if(IProject.class.equals(adapter)) {
+ return project;
+ } else {
+ return super.getAdapter(adapter);
+ }
+ }
+
+ @Override
+ public IFile getFile(final String name) {
+ return project.getFile(ROOT_PATH.append(name));
+ }
+
+ @Override
+ public IFolder getFolder(final String name) {
+ return project.getFolder(ROOT_PATH.append(name));
+ }
+
+ @Override
+ public IPath getLocation() {
+ return project.getLocation();
+ }
+
+ @Override
+ public String getName() {
+ return project.getName();
+ }
+
+ @Override
+ public IPath getPlatformRootDirectory() {
+ try {
+ final String karafModelPath = project.getPersistentProperty(
+ new QualifiedName(KarafUIPluginActivator.PLUGIN_ID, "karafModel"));
+
+ return new Path(karafModelPath);
+ } catch (final CoreException e) {
+ KarafUIPluginActivator.getLogger().error("Unable to determine platform root directory for project: " + project.getName(), e);
+ }
+
+ return null;
+ }
+
+ @Override
+ public IProject getProjectHandle() {
+ return project;
+ }
+
+ @Override
+ public Properties getRuntimeProperties() {
+ try {
+ return KarafCorePluginUtils.loadProperties(
+ project.getFolder("runtime").getRawLocation().toFile(),
+ "runtime.properties");
+ } catch (final CoreException e) {
+ return new Properties();
+ }
+ }
+}