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 [5/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.core/src/main/java/info/evanchik/eclipse/karaf/core/equinox/BundleEntry.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/equinox/BundleEntry.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/equinox/BundleEntry.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/equinox/BundleEntry.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,238 @@
+/**
+ * Copyright (c) 2009 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.core.equinox;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class BundleEntry {
+
+ /**
+ * A builder to help facilitate the construction of {@link BundleEntry}
+ * objects
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+ public static class Builder {
+
+ private final String bundle;
+
+ private final URL bundleUrl;
+
+ private String startLevel;
+
+ private String autostart;
+
+ /**
+ * Builder for a simple {@link BundleEntry}
+ *
+ * @param bundle
+ * the string location of the bundle
+ */
+ public Builder(final String bundle) {
+ if (bundle == null) {
+ throw new NullPointerException("bundle");
+ }
+
+ this.bundle = bundle;
+ this.bundleUrl = null;
+ }
+
+ /**
+ * Builder for a absolutely qualified {@link UrlBundleEntry}
+ *
+ * @param u
+ * the URL to the bundle
+ */
+ public Builder(final URL u) {
+ if (u == null) {
+ throw new NullPointerException("u");
+ }
+
+ this.bundleUrl = u;
+ this.bundle = null;
+ }
+
+ public Builder startLevel(final String startLevel) {
+ this.startLevel = startLevel;
+ return this;
+ }
+
+ public Builder autostart(final String autostart) {
+ if (autostart == null) {
+ throw new NullPointerException("autostart");
+ }
+
+ this.autostart = autostart;
+ return this;
+ }
+
+ /**
+ * Construct the appropriate {@link BundleEntry} type
+ *
+ * @return the {@link BundleEntry}
+ */
+ public BundleEntry build() {
+ final BundleEntry entry;
+ if (bundle != null) {
+ entry = new BundleEntry(bundle);
+ } else {
+ entry = new UrlBundleEntry(bundleUrl);
+ }
+
+ entry.startLevel = startLevel;
+ entry.autostart = autostart;
+
+ return entry;
+ }
+ }
+
+ /**
+ * Parses an entry from an {@code osgi.bundles} property. The format is:<br>
+ * <br>
+ * <URL | simple bundle location>[@ [<start-level>] [":start"]] <br>
+ *
+ * @param s
+ * the candidate string
+ * @return an instance of {@code EquinoxBundleEntry}
+ */
+ public static BundleEntry fromString(final String s) {
+ if (s == null) {
+ throw new NullPointerException("s");
+ }
+
+ String candidateBundle;
+ String startComponent;
+
+ final int at = s.indexOf('@');
+ if (at != -1) {
+ candidateBundle = s.substring(0, at);
+ startComponent = s.substring(at + 1);
+ } else {
+ candidateBundle = s;
+ startComponent = "";
+ }
+
+ URL u = null;
+ try {
+ u = new URL(candidateBundle);
+ } catch (final MalformedURLException e) {
+ // Do nothing as this is acceptable for a simple bundle
+ }
+
+ final BundleEntry entry;
+ if (u == null) {
+ entry = new BundleEntry(candidateBundle);
+ } else {
+ entry = new BundleEntry.UrlBundleEntry(u);
+ }
+
+ if (startComponent.length() > 0) {
+ final int colon = startComponent.indexOf(':');
+ if (colon == -1) {
+ entry.startLevel = startComponent;
+ } else {
+ entry.startLevel = startComponent.substring(0, colon);
+ entry.autostart = startComponent.substring(colon + 1);
+ }
+ }
+
+ return entry;
+ }
+
+ /**
+ * A simple class to distinguish between simple bundle entries and URL
+ * bundle entries.
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+ private static class UrlBundleEntry extends BundleEntry {
+
+ /**
+ * Constructs an entry that is based on a fully qualified URL to the
+ * bundle.
+ *
+ * @param bundleUrl
+ * the bundle in URL form
+ */
+ public UrlBundleEntry(final URL bundleUrl) {
+ super(bundleUrl.toExternalForm());
+ }
+ };
+
+ private final String bundle;
+
+ private String startLevel;
+
+ private String autostart;
+
+ /**
+ * Construct a bundle entry using the specified string as the bundle
+ * location.
+ *
+ * @param bundle
+ * the location of the bundle
+ */
+ private BundleEntry(final String bundle) {
+ this.bundle = bundle;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj instanceof BundleEntry == false) {
+ return false;
+ }
+
+ final BundleEntry rhs = (BundleEntry) obj;
+ return toString().equals(rhs.toString());
+ }
+
+ public String getAutostart() {
+ return autostart;
+ }
+
+ public String getBundle() {
+ return bundle;
+ }
+
+ public String getStartLevel() {
+ return startLevel;
+ }
+
+ @Override
+ public int hashCode() {
+ // This should be revisited
+ return toString().hashCode();
+ }
+
+ @Override
+ public String toString() {
+ final StringBuffer sb = new StringBuffer();
+ sb.append(bundle);
+ if (startLevel != null) {
+ sb.append("@");
+ sb.append(startLevel);
+ if (autostart != null) {
+ sb.append(":");
+ sb.append(autostart);
+ }
+ }
+
+ return sb.toString();
+ }
+
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Bundle.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Bundle.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Bundle.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Bundle.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.core.features;
+
+import info.evanchik.eclipse.karaf.core.features.internal.ElementTransformer;
+
+import org.apache.commons.collections.Transformer;
+import org.jdom.Element;
+
+/**
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class Bundle implements ParentAwareObject<Object> {
+
+ private final String bundleUrl;
+
+ private final Element element;
+
+ /**
+ *
+ * @param element
+ */
+ public Bundle(final Element element) {
+ bundleUrl = element.getValue();
+ if (bundleUrl == null) {
+ throw new IllegalArgumentException("bundle element is invalid: " + element.toString());
+ }
+
+ this.element = element;
+ }
+
+ public String getBundleUrl() {
+ return bundleUrl;
+ }
+
+ @Override
+ public Object getParent() {
+ final Transformer transformer = new ElementTransformer();
+ return transformer.transform(element.getParentElement());
+ }
+
+ @Override
+ public String toString() {
+ return bundleUrl;
+ }
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Feature.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Feature.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Feature.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Feature.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,142 @@
+/**
+ * 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.core.features;
+
+import info.evanchik.eclipse.karaf.core.KarafCorePluginUtils;
+import info.evanchik.eclipse.karaf.core.features.internal.ElementTransformer;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.collections.list.TransformedList;
+import org.jdom.Element;
+
+/**
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class Feature implements ParentAwareObject<Object> {
+
+ private final String name;
+
+ private final String version;
+
+ private final Element element;
+
+ /**
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+ private static final class BundleOnlyPredicate implements Predicate {
+ @Override
+ public boolean evaluate(final Object element) {
+ return element instanceof Bundle;
+ }
+ }
+
+ /**
+ *
+ * @param element
+ */
+ public Feature(final Element element) {
+ if (element.getAttribute("name") != null) {
+ name = element.getAttributeValue("name");
+ } else {
+ name = element.getValue();
+ }
+
+ version = element.getAttributeValue("version");
+
+ this.element = element;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (name == null ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (!(obj instanceof Feature)) {
+ return false;
+ }
+
+ final Feature other = (Feature) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Object getParent() {
+ final Transformer transformer = new ElementTransformer();
+ return transformer.transform(element.getParentElement());
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuffer sb = new StringBuffer("");
+
+ if (name != null) {
+ sb.append(name);
+ }
+
+ return sb.toString();
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Bundle> getBundles() {
+ final List<Bundle> rawList = new ArrayList<Bundle>();
+ final List<Bundle> transformedList = TransformedList.decorate(rawList, new ElementTransformer());
+ transformedList.addAll(element.getChildren());
+
+ return Collections.unmodifiableList(KarafCorePluginUtils.filterList(transformedList, new BundleOnlyPredicate()));
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Feature> getFeatures() {
+ final List<Feature> rawList = new ArrayList<Feature>();
+ final List<Feature> transformedList = TransformedList.decorate(rawList, new ElementTransformer());
+ transformedList.addAll(element.getChildren());
+
+ return Collections.unmodifiableList(KarafCorePluginUtils.filterList(transformedList, new FeatureOnlyPredicate()));
+ }
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeatureOnlyPredicate.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeatureOnlyPredicate.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeatureOnlyPredicate.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeatureOnlyPredicate.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,29 @@
+/**
+ * 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.core.features;
+
+
+import org.apache.commons.collections.Predicate;
+
+/**
+ * A {@link Predicate} implementation that evaluates to {@code true} if the
+ * supplied input is a {@link Feature}
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+final class FeatureOnlyPredicate implements Predicate {
+
+ @Override
+ public boolean evaluate(final Object element) {
+ return element instanceof Feature;
+ }
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeatureResolverImpl.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeatureResolverImpl.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeatureResolverImpl.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeatureResolverImpl.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,63 @@
+/**
+ * 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.core.features;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class FeatureResolverImpl {
+
+ private final List<FeaturesRepository> featuresRepositories = new ArrayList<FeaturesRepository>();
+
+ /**
+ *
+ * @param repositories
+ */
+ public FeatureResolverImpl(final Collection<FeaturesRepository> repositories) {
+ featuresRepositories.addAll(repositories);
+ }
+
+ /**
+ *
+ * @param featureName
+ * @return
+ */
+ public Feature findFeature(final String featureName) {
+ final Object[] path = getFeaturePath(featureName);
+
+ if (path.length > 0) {
+ return (Feature) path[path.length - 1];
+ } else {
+ return null;
+ }
+ }
+
+ public Object[] getFeaturePath(final String featureName) {
+ final List<Object> path = new ArrayList<Object>();
+
+ for (final FeaturesRepository r : featuresRepositories) {
+ for (final Feature f : r.getFeatures().getFeatures()) {
+ if (f.getName().equals(featureName)) {
+ path.addAll(Arrays.asList(r, r.getFeatures(), f));
+ return path.toArray();
+ }
+ }
+ }
+
+ return path.toArray();
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Features.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Features.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Features.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Features.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,112 @@
+/**
+ * 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.core.features;
+
+import info.evanchik.eclipse.karaf.core.KarafCorePluginUtils;
+import info.evanchik.eclipse.karaf.core.features.internal.ElementTransformer;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.collections.list.TransformedList;
+import org.jdom.Element;
+
+/**
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class Features implements ParentAwareObject<FeaturesRepository> {
+
+ private final Element element;
+
+ private final FeaturesRepository featuresRepository;
+
+ private final String name;
+
+ /**
+ *
+ * @param element
+ * @param featuresRepository
+ */
+ public Features(final Element element, final FeaturesRepository featuresRepository) {
+ this.name = element.getAttributeValue("name");
+ this.element = element;
+ this.featuresRepository = featuresRepository;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (!(obj instanceof Features)) {
+ return false;
+ }
+
+ final Features other = (Features) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Feature> getFeatures() {
+ final List<Feature> rawList = new ArrayList<Feature>();
+ final List<Feature> transformedList = TransformedList.decorate(rawList, new ElementTransformer());
+ transformedList.addAll(element.getChildren());
+
+ return Collections.unmodifiableList(KarafCorePluginUtils.filterList(transformedList, new FeatureOnlyPredicate()));
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public FeaturesRepository getParent() {
+ return featuresRepository;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Repository> getRepositories() {
+ final List<Repository> rawList = new ArrayList<Repository>();
+ final List<Repository> transformedList = TransformedList.decorate(rawList, new ElementTransformer());
+ transformedList.addAll(element.getChildren());
+
+ return Collections.unmodifiableList(KarafCorePluginUtils.filterList(transformedList, new RepositoryOnlyPredicate()));
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (name == null ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return element.toString();
+ }
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeaturesRepository.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeaturesRepository.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeaturesRepository.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/FeaturesRepository.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,59 @@
+/**
+ * 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.core.features;
+
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public interface FeaturesRepository {
+
+ /**
+ * Returns the {@link Feature}s found in this {@code FeaturesRepository}
+ *
+ * @return the {@code Feature}s found in this repository
+ */
+ public Features getFeatures();
+
+ /**
+ * Returns the name of the {@code FeaturesRepository}; this can be null
+ *
+ * @return the name of the {@code FeaturesRepository} or null if this is not
+ * available
+ */
+ public String getName();
+
+ /**
+ * Returns the list of referenced {@link Repository}s by this
+ * {@code FeaturesRespository}
+ *
+ * @return the list of referenced {@code Repository}s; this list could be
+ * empty
+ */
+ public List<Repository> getRepositories();
+
+ /**
+ * Writes the contents of the {@code FeaturesRepository} to the specified
+ * {@link OutputStream}
+ *
+ * @param out
+ * the {@code OutputStream}
+ * @throws IOException
+ * if there is a problem writing the contents of the
+ * {@code FeaturesRepository}
+ */
+ public void write(OutputStream out) throws IOException;
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/ParentAwareObject.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/ParentAwareObject.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/ParentAwareObject.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/ParentAwareObject.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,25 @@
+/**
+ * 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.core.features;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public interface ParentAwareObject<T> {
+
+ /**
+ * Retuns the parent of this object
+ *
+ * @return the parent of this object
+ */
+ public T getParent();
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Repository.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Repository.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Repository.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/Repository.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,62 @@
+/**
+ * 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.core.features;
+
+import info.evanchik.eclipse.karaf.core.features.internal.ElementTransformer;
+
+import java.net.URI;
+
+import org.apache.commons.collections.Transformer;
+import org.jdom.Element;
+
+/**
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class Repository implements ParentAwareObject<Object> {
+
+ private final Element element;
+
+ private final String repositoryUrl;
+
+ public Repository(final Element element) {
+ repositoryUrl = element.getValue();
+ if (repositoryUrl == null) {
+ throw new IllegalArgumentException("repository element is invalid: " + element.toString());
+ }
+
+ this.element = element;
+ }
+
+ @Override
+ public Object getParent() {
+ final Transformer transformer = new ElementTransformer();
+ return transformer.transform(element.getParentElement());
+ }
+
+ public String getRepositoryUrl() {
+ return repositoryUrl;
+ }
+
+ @Override
+ public String toString() {
+ return repositoryUrl;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public URI toURI() {
+ return URI.create(repositoryUrl);
+ }
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/RepositoryOnlyPredicate.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/RepositoryOnlyPredicate.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/RepositoryOnlyPredicate.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/RepositoryOnlyPredicate.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,28 @@
+/**
+ * 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.core.features;
+
+
+import org.apache.commons.collections.Predicate;
+
+/**
+ * A {@link Predicate} implementation that returns {@code true} if the supplied
+ * input is a {@link Repository}
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+final class RepositoryOnlyPredicate implements Predicate {
+ @Override
+ public boolean evaluate(final Object element) {
+ return element instanceof Repository;
+ }
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/XmlFeaturesRepository.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/XmlFeaturesRepository.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/XmlFeaturesRepository.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/XmlFeaturesRepository.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,138 @@
+/**
+ * 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.core.features;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.List;
+
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class XmlFeaturesRepository implements FeaturesRepository {
+
+ private final Document document;
+
+ private final Features features;
+
+ private final String repositoryName;
+
+ /**
+ *
+ * @param repositoryName
+ * @param inputStream
+ * @throws IOException
+ * @throws NullPointerException
+ * if any argument is null
+ */
+ public XmlFeaturesRepository(final String repositoryName, final InputStream inputStream) throws IOException {
+ if (repositoryName == null) {
+ throw new NullPointerException("repositoryName");
+ }
+
+ if (inputStream == null) {
+ throw new NullPointerException("inputStream");
+ }
+
+ try {
+ document = new SAXBuilder().build(inputStream);
+
+ final Element rootElement = document.getRootElement();
+ if (rootElement == null) {
+ // This is bad!
+ }
+
+ this.features = new Features(rootElement, this);
+ this.repositoryName = repositoryName;
+ } catch (final JDOMException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (!(obj instanceof XmlFeaturesRepository)) {
+ return false;
+ }
+
+ final XmlFeaturesRepository other = (XmlFeaturesRepository) obj;
+ if (features == null) {
+ if (other.features != null) {
+ return false;
+ }
+ } else if (!features.equals(other.features)) {
+ return false;
+ }
+
+ if (repositoryName == null) {
+ if (other.repositoryName != null) {
+ return false;
+ }
+ } else if (!repositoryName.equals(other.repositoryName)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public Features getFeatures() {
+ return features;
+ }
+
+ @Override
+ public String getName() {
+ return repositoryName;
+ }
+
+ @Override
+ public List<Repository> getRepositories() {
+ return Collections.unmodifiableList(features.getRepositories());
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (features == null ? 0 : features.hashCode());
+ result = prime * result + (repositoryName == null ? 0 : repositoryName.hashCode());
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return repositoryName;
+ }
+
+ @Override
+ public void write(final OutputStream out) throws IOException {
+ final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
+ xmlOutputter.output(document, out);
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/internal/ElementTransformer.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/internal/ElementTransformer.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/internal/ElementTransformer.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/features/internal/ElementTransformer.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,47 @@
+/**
+ * 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.core.features.internal;
+
+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.Repository;
+
+import org.apache.commons.collections.Transformer;
+import org.jdom.Element;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class ElementTransformer implements Transformer {
+
+ @Override
+ public Object transform(final Object object) {
+ if (!(object instanceof Element)) {
+ return null;
+ }
+
+ final Element element = (Element) object;
+
+ if (element.getName().equalsIgnoreCase("repository")) {
+ return new Repository(element);
+ } else if (element.getName().equalsIgnoreCase("feature")) {
+ return new Feature(element);
+ } else if (element.getName().equalsIgnoreCase("bundle")) {
+ return new Bundle(element);
+ } else if (element.getName().equalsIgnoreCase("features")) {
+ return new Features(element, null);
+ } else {
+ return object;
+ }
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/GenericKarafPlatformModelFactory.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/GenericKarafPlatformModelFactory.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/GenericKarafPlatformModelFactory.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/GenericKarafPlatformModelFactory.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,42 @@
+/**
+ * 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.core.internal;
+
+import info.evanchik.eclipse.karaf.core.KarafPlatformModel;
+import info.evanchik.eclipse.karaf.core.KarafPlatformModelFactory;
+import info.evanchik.eclipse.karaf.core.KarafPlatformValidator;
+import info.evanchik.eclipse.karaf.core.model.GenericKarafPlatformModel;
+
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class GenericKarafPlatformModelFactory implements KarafPlatformModelFactory {
+
+ private static final GenericKarafPlatformValidator platformValidator =
+ new GenericKarafPlatformValidator();
+
+ @Override
+ public KarafPlatformModel getPlatformModel(final IPath rootDirectory) {
+ if (!platformValidator.isValid(rootDirectory)) {
+
+ }
+
+ return new GenericKarafPlatformModel(rootDirectory);
+ }
+
+ @Override
+ public KarafPlatformValidator getPlatformValidator() {
+ return platformValidator;
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/GenericKarafPlatformValidator.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/GenericKarafPlatformValidator.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/GenericKarafPlatformValidator.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/GenericKarafPlatformValidator.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2009 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.core.internal;
+
+import info.evanchik.eclipse.karaf.core.KarafPlatformValidator;
+
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class GenericKarafPlatformValidator implements KarafPlatformValidator {
+
+ public boolean isValid(IPath rootPath) {
+ final IPath karafJar = rootPath.append("/lib/karaf.jar");
+
+ final IPath systemDir = rootPath.append("/system");
+ final IPath confDir = rootPath.append("/etc");
+
+ // First level is the Karaf JARs in the lib directory
+ if (karafJar.toFile().exists()) {
+ return true;
+ }
+
+ /*
+ * Second level is the directory structure with the features system
+ * configuration files.
+ */
+ if(systemDir.toFile().isDirectory() && confDir.toFile().isDirectory()) {
+ final IPath karafFeatures = confDir.append("/org.apache.felix.karaf.features.cfg");
+
+ if(karafFeatures.toFile().exists()) {
+ return true;
+ }
+ }
+
+
+ return false;
+ }
+
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/KarafCorePluginActivator.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/KarafCorePluginActivator.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/KarafCorePluginActivator.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/KarafCorePluginActivator.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) 2009 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.core.internal;
+
+import info.evanchik.eclipse.karaf.core.LogWrapper;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class KarafCorePluginActivator extends Plugin {
+
+ public static final String PLUGIN_ID = "info.evanchik.eclipse.karaf.core"; //$NON-NLS-1$
+
+ private static KarafCorePluginActivator plugin = null;
+
+ /**
+ * Returns the shared instance of this plugin.
+ *
+ * @return the shared instance
+ */
+ public static KarafCorePluginActivator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Getter for the {@link LogWrapper} object that makes logging much easier
+ * on the caller.
+ *
+ * @return the {@link LogWrapper} instance
+ */
+ public static LogWrapper getLogger() {
+ return new LogWrapper(getDefault().getLog(), PLUGIN_ID);
+ }
+
+ @Override
+ public void start(final BundleContext context) throws Exception {
+ super.start(context);
+ KarafCorePluginActivator.plugin = this;
+ }
+
+ @Override
+ public void stop(final BundleContext context) throws Exception {
+ super.stop(context);
+ KarafCorePluginActivator.plugin = null;
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/PluginLocVariableResolver.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/PluginLocVariableResolver.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/PluginLocVariableResolver.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/internal/PluginLocVariableResolver.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,78 @@
+/**
+ * Copyright (c) 2009 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.core.internal;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.variables.IDynamicVariable;
+import org.eclipse.core.variables.IDynamicVariableResolver;
+import org.osgi.framework.Bundle;
+
+/**
+ *
+ * Resolver for ${plugin_loc:<bundle symbolic name>}. The argument is mandatory
+ * and should be the plugins's symbolic name.<br>
+ * <br>
+ * The variable resolves to the absolute path of the plugin specified in the
+ * argument.
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class PluginLocVariableResolver implements IDynamicVariableResolver {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.variables.IDynamicVariableResolver#resolveValue(org.
+ * eclipse.core.variables.IDynamicVariable, java.lang.String)
+ */
+ public String resolveValue(IDynamicVariable variable, String argument) throws CoreException {
+ if (argument == null) {
+ final String message = "The plugin_loc variable requires the symbolic name of a bundle as an argument";
+
+ throw new CoreException(new Status(IStatus.ERROR, KarafCorePluginActivator.PLUGIN_ID, IStatus.OK,
+ message, null));
+
+ }
+
+ final Bundle b = Platform.getBundle(argument);
+
+ if (b == null) {
+ // This does not throw an exception because it is expected that
+ // people will put the wrong symbolic name in to the variable's
+ // arguments.
+ return null;
+ }
+
+ // At this point we have a valid bundle so resolve it the absolute file
+ // system path
+ try {
+ final File bundleFile = FileLocator.getBundleFile(b);
+
+ return bundleFile.getAbsolutePath();
+ } catch (IOException e) {
+ final String message = "Unable to resolve bundle to absolute filesystem path: "
+ + argument;
+
+ throw new CoreException(new Status(IStatus.ERROR,
+ KarafCorePluginActivator.PLUGIN_ID, IStatus.OK, message,
+ null));
+ }
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/AbstractKarafPlatformModel.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/AbstractKarafPlatformModel.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/AbstractKarafPlatformModel.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/AbstractKarafPlatformModel.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,88 @@
+/**
+ * Copyright (c) 2009 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.core.model;
+
+import info.evanchik.eclipse.karaf.core.KarafPlatformModel;
+import info.evanchik.eclipse.karaf.core.SystemBundleNames;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.osgi.service.resolver.BundleDescription;
+import org.eclipse.osgi.service.resolver.State;
+import org.eclipse.pde.core.plugin.IPluginModelBase;
+import org.eclipse.pde.internal.core.PDEState;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+@SuppressWarnings("restriction")
+abstract public class AbstractKarafPlatformModel implements KarafPlatformModel {
+
+ /**
+ * The detailed OSGi metadata regarding the state of this model
+ */
+ private PDEState pdeState;
+
+ /**
+ * The list of bundles that are contained withing this platform
+ */
+ private final List<URL> bundleList = new ArrayList<URL>();
+
+ private final Object monitor = new Object();
+
+ public boolean containsPlugin(IPluginModelBase plugin) {
+ final String symbolicName = plugin.getBundleDescription().getSymbolicName();
+
+ final BundleDescription desc = getState().getBundle(symbolicName, null);
+
+ return desc != null;
+ }
+
+ public IPath getConfigurationDirectory() {
+ return getRootDirectory().append("etc"); //$NON-NLS-1$
+ }
+
+ public IPath getUserDeployedDirectory() {
+ return getRootDirectory().append("deploy"); //$NON-NLS-1$
+ }
+
+ public State getState() {
+ synchronized (monitor) {
+ if (pdeState == null) {
+ bundleList.addAll(getPlatformBundles());
+
+ pdeState = new PDEState(bundleList.toArray(new URL[0]), false, new NullProgressMonitor());
+ }
+ }
+
+ return pdeState.getState();
+ }
+
+ public boolean isFrameworkPlugin(IPluginModelBase model) {
+ final String symbolicName = model.getBundleDescription().getSymbolicName();
+
+ return SystemBundleNames.EQUINOX.toString().equals(symbolicName) || SystemBundleNames.FELIX.toString().equals(symbolicName);
+ }
+
+ /**
+ * Returns the {@code List} of {@link Bundle} {@code URL}S that are found in
+ * this Karaf platform implementation
+ *
+ * @return TODO
+ */
+ protected abstract List<URL> getPlatformBundles();
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/GenericKarafPlatformDetails.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/GenericKarafPlatformDetails.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/GenericKarafPlatformDetails.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/GenericKarafPlatformDetails.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,106 @@
+/**
+ * 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.core.model;
+
+import info.evanchik.eclipse.karaf.core.KarafPlatformDetails;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.osgi.framework.Constants;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class GenericKarafPlatformDetails implements KarafPlatformDetails {
+
+ private static final String UNKNOWN_VERSION = "Unknown version";
+
+ private static final String UNKNOWN_PLATFORM = "Unknown platform";
+
+ private final JarFile platformDetailsBundle;
+
+ /**
+ *
+ * @param file
+ */
+ public GenericKarafPlatformDetails(final File file) throws IOException {
+ this.platformDetailsBundle = new JarFile(file);
+ }
+
+ @Override
+ public String getDescription() {
+ final String description;
+ try {
+ final Manifest manifest = platformDetailsBundle.getManifest();
+ if (manifest == null) {
+ description = "";
+ } else {
+ final String bundleDescription = manifest.getMainAttributes().getValue(Constants.BUNDLE_DESCRIPTION);
+ if (bundleDescription == null) {
+ description = "";
+ } else {
+ description = bundleDescription;
+ }
+ }
+ } catch (final IOException e) {
+ return "";
+ }
+
+ return description;
+ }
+
+ @Override
+ public String getName() {
+ final String name;
+ try {
+ final Manifest manifest = platformDetailsBundle.getManifest();
+ if (manifest == null) {
+ name = UNKNOWN_PLATFORM;
+ } else {
+ final String bundleName = manifest.getMainAttributes().getValue(Constants.BUNDLE_NAME);
+ if (bundleName == null) {
+ name = UNKNOWN_PLATFORM;
+ } else {
+ name = bundleName;
+ }
+ }
+ } catch (final IOException e) {
+ return UNKNOWN_PLATFORM;
+ }
+
+ return name;
+ }
+
+ @Override
+ public String getVersion() {
+ final String version;
+ try {
+ final Manifest manifest = platformDetailsBundle.getManifest();
+ if (manifest == null) {
+ version = UNKNOWN_VERSION;
+ } else {
+ final String bundleVersion = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
+ if (bundleVersion == null) {
+ version = UNKNOWN_VERSION;
+ } else {
+ version = bundleVersion;
+ }
+ }
+ } catch (final IOException e) {
+ return UNKNOWN_VERSION;
+ }
+ return version;
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/GenericKarafPlatformModel.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/GenericKarafPlatformModel.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/GenericKarafPlatformModel.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/GenericKarafPlatformModel.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,219 @@
+/**
+ * Copyright (c) 2009 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.core.model;
+
+import info.evanchik.eclipse.karaf.core.IKarafConstants;
+import info.evanchik.eclipse.karaf.core.KarafCorePluginUtils;
+import info.evanchik.eclipse.karaf.core.KarafPlatformDetails;
+import info.evanchik.eclipse.karaf.core.configuration.FeaturesSection;
+import info.evanchik.eclipse.karaf.core.configuration.GeneralSection;
+import info.evanchik.eclipse.karaf.core.configuration.ManagementSection;
+import info.evanchik.eclipse.karaf.core.configuration.ShellSection;
+import info.evanchik.eclipse.karaf.core.configuration.StartupSection;
+import info.evanchik.eclipse.karaf.core.configuration.SystemSection;
+import info.evanchik.eclipse.karaf.core.configuration.internal.FeaturesSectionImpl;
+import info.evanchik.eclipse.karaf.core.configuration.internal.GeneralSectionImpl;
+import info.evanchik.eclipse.karaf.core.configuration.internal.ManagementSectionImpl;
+import info.evanchik.eclipse.karaf.core.configuration.internal.ShellSectionImpl;
+import info.evanchik.eclipse.karaf.core.configuration.internal.StartupSectionImpl;
+import info.evanchik.eclipse.karaf.core.configuration.internal.SystemSectionImpl;
+import info.evanchik.eclipse.karaf.core.internal.KarafCorePluginActivator;
+import info.evanchik.eclipse.karaf.core.shell.KarafSshConnectionUrl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class GenericKarafPlatformModel extends AbstractKarafPlatformModel implements IAdaptable {
+
+ /**
+ * The maximum depth to search for JARs in this model
+ */
+ public static int MAX_SEARCH_DEPTH = 50;
+
+ /**
+ * The root of the Karaf platform installation
+ */
+ private final IPath rootPlatformPath;
+
+ /**
+ *
+ * @param platformPath
+ */
+ public GenericKarafPlatformModel(final IPath platformPath) {
+ this.rootPlatformPath = platformPath;
+ }
+
+ @Override
+ public Object getAdapter(@SuppressWarnings("rawtypes") final Class adapterType) {
+ final Object adaptedObject;
+ if (adapterType == FeaturesSection.class) {
+ adaptedObject = new FeaturesSectionImpl(this);
+ } else if (adapterType == ShellSection.class) {
+ adaptedObject = new ShellSectionImpl(this);
+ }else if (adapterType == GeneralSection.class) {
+ adaptedObject = new GeneralSectionImpl(this);
+ } else if (adapterType == ManagementSection.class) {
+ adaptedObject = adaptManagementSection();
+ } else if (adapterType == StartupSection.class) {
+ adaptedObject = new StartupSectionImpl(this);
+ } else if (adapterType == SystemSection.class) {
+ return new SystemSectionImpl(this);
+ } else if (adapterType == KarafPlatformDetails.class) {
+ adaptedObject = adaptKarafPlatformDetails();
+ } else if (adapterType == KarafSshConnectionUrl.class) {
+ adaptedObject = adaptKarafSshConnectionUrl();
+ } else {
+ adaptedObject = Platform.getAdapterManager().getAdapter(this, adapterType);
+ }
+
+ return adaptedObject;
+ }
+
+ @Override
+ public List<String> getBootClasspath() {
+ final List<File> jarFiles = new ArrayList<File>();
+ KarafCorePluginUtils.getJarFileList(rootPlatformPath.append("lib").toFile(), jarFiles, 0); //$NON-NLS-1$
+
+ final List<String> bootClasspath = new ArrayList<String>();
+ for(final File f : jarFiles) {
+ bootClasspath.add(f.getAbsolutePath());
+ }
+
+ return bootClasspath;
+ }
+ @Override
+ public IPath getConfigurationDirectory() {
+ return rootPlatformPath.append("etc"); //$NON-NLS-1$
+ }
+
+ @Override
+ public IPath getConfigurationFile(final String key) {
+ return getConfigurationDirectory().append(key);
+ }
+
+ @Override
+ public IPath getPluginRootDirectory() {
+ return rootPlatformPath.append("system"); //$NON-NLS-1$
+ }
+
+ @Override
+ public IPath getRootDirectory() {
+ return rootPlatformPath;
+ }
+
+ /**
+ * Directory based Karaf platform model's typically exist outside of an
+ * Eclipse platform on a file system and support customization of their
+ * configuration.
+ *
+ * @return false, always
+ */
+ @Override
+ public boolean isReadOnly() {
+ return false;
+ }
+
+ /**
+ * Convert a {@link List} of {@link File} to a {@code List} of {@link URL}
+ *
+ * @param files
+ * the {@code List} of {@code File}S
+ * @return a {@code List} of {@code URL}S, one for each {@code File}
+ */
+ protected final List<URL> filesToUrls(final List<File> files) {
+ final List<URL> urls = new ArrayList<URL>();
+
+ for (final File f : files) {
+ try {
+ final URL u = f.toURI().toURL();
+ urls.add(u);
+ } catch (final MalformedURLException e) {
+ KarafCorePluginActivator.getLogger().error(
+ "Unable to convert file to URL: " + f.getAbsolutePath(), e);
+ }
+ }
+
+ return urls;
+ }
+
+ @Override
+ protected List<URL> getPlatformBundles() {
+
+ final List<File> jarFiles = new ArrayList<File>();
+ KarafCorePluginUtils.getJarFileList(getPluginRootDirectory().toFile(), jarFiles,
+ MAX_SEARCH_DEPTH);
+
+ return filesToUrls(jarFiles);
+ }
+
+ /**
+ *
+ * @return
+ */
+ private Object adaptKarafSshConnectionUrl() {
+ final ShellSection shellSection = (ShellSection) getAdapter(ShellSection.class);
+ shellSection.load();
+
+ return new KarafSshConnectionUrl(shellSection.getSshHost(), shellSection.getSshPort());
+ }
+
+ /**
+ * @return
+ */
+ private Object adaptKarafPlatformDetails() {
+ final Object adaptedObject;
+ try {
+ if(KarafCorePluginUtils.isServiceMix(this)) {
+ final File file = getRootDirectory().append("lib").append("servicemix.jar").toFile();
+ adaptedObject = new GenericKarafPlatformDetails(file); // $NON-NLS-2$
+ } else if (KarafCorePluginUtils.isFelixKaraf(this) || KarafCorePluginUtils.isKaraf(this)) {
+ final File file = getRootDirectory().append("lib").append("karaf.jar").toFile();
+ adaptedObject = new GenericKarafPlatformDetails(file); // $NON-NLS-2$
+ } else {
+ adaptedObject = null;
+ }
+ } catch (final IOException e) {
+ return null;
+ }
+ return adaptedObject;
+ }
+
+ /**
+ * @param karafModel
+ * @return
+ */
+ private Object adaptManagementSection() {
+ final Object adaptedObject;
+ if(KarafCorePluginUtils.isServiceMix(this)) {
+ adaptedObject = new ManagementSectionImpl(this, IKarafConstants.ORG_APACHE_SERVICEMIX_MANAGEMENT_CFG_FILENAME);
+ } else if (KarafCorePluginUtils.isFelixKaraf(this)) {
+ adaptedObject = new ManagementSectionImpl(this, IKarafConstants.ORG_APACHE_FELIX_KARAF_MANAGEMENT_CFG_FILENAME);
+ } else if (KarafCorePluginUtils.isKaraf(this)) {
+ adaptedObject = new ManagementSectionImpl(this, IKarafConstants.ORG_APACHE_KARAF_MANAGEMENT_CFG_FILENAME);
+ } else {
+ adaptedObject = null;
+ }
+
+ return adaptedObject;
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/WorkingKarafPlatformModel.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/WorkingKarafPlatformModel.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/WorkingKarafPlatformModel.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/model/WorkingKarafPlatformModel.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,129 @@
+/**
+ * Copyright (c) 2009 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.core.model;
+
+import info.evanchik.eclipse.karaf.core.KarafPlatformModel;
+import info.evanchik.eclipse.karaf.core.KarafWorkingPlatformModel;
+
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.osgi.service.resolver.State;
+import org.eclipse.pde.core.plugin.IPluginModelBase;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class WorkingKarafPlatformModel extends AbstractKarafPlatformModel implements KarafWorkingPlatformModel {
+
+ private final IPath location;
+
+ private final KarafPlatformModel parentKarafModel;
+
+ /**
+ * Constructs a {@link KarafPlatformModel} that delegates all information
+ * about the underlying plugins that comprise this model while handling all
+ * configuration methods.
+ *
+ * @param thisModelLocation
+ * the {@link IPath} to the working copy of the {@code
+ * KarafPlatformModel}
+ * @param source
+ * the source of all non-configuration information for this Karaf
+ * platform.
+ */
+ public WorkingKarafPlatformModel(final IPath thisModelLocation, final KarafPlatformModel source) {
+ this.location = thisModelLocation;
+ this.parentKarafModel = source;
+ }
+
+ @Override
+ public boolean containsPlugin(final IPluginModelBase plugin) {
+ return parentKarafModel.containsPlugin(plugin);
+ }
+
+ @Override
+ public Object getAdapter(@SuppressWarnings("rawtypes") final Class adapter) {
+ final KarafPlatformModel parentModel = getParentKarafModel();
+ final Object adaptedObject = parentModel.getAdapter(adapter);
+ return adaptedObject;
+ }
+
+ @Override
+ public List<String> getBootClasspath() {
+ return parentKarafModel.getBootClasspath();
+ }
+
+ @Override
+ public IPath getConfigurationFile(final String key) {
+ final IPath origFile = parentKarafModel.getConfigurationFile(key);
+ final int matchingSegments = origFile.matchingFirstSegments(parentKarafModel
+ .getConfigurationDirectory());
+
+ final IPath configFile = origFile.removeFirstSegments(matchingSegments - 1);
+
+ return location.append(configFile);
+ }
+
+ @Override
+ public KarafPlatformModel getParentKarafModel() {
+ return parentKarafModel;
+ }
+
+ @Override
+ public IPath getPluginRootDirectory() {
+ return parentKarafModel.getPluginRootDirectory();
+ }
+
+ @Override
+ public IPath getRootDirectory() {
+ return location;
+ }
+
+ @Override
+ public State getState() {
+ return parentKarafModel.getState();
+ }
+
+ @Override
+ public boolean isFrameworkPlugin(final IPluginModelBase model) {
+ return parentKarafModel.isFrameworkPlugin(model);
+ }
+
+ /**
+ * While the source {@link KarafPlatformModel} may be read-only this working
+ * copy is not.
+ *
+ * @return true in all cases
+ */
+ @Override
+ public boolean isReadOnly() {
+ return false;
+ }
+
+ /**
+ * This working copy is always valid (unless something outside of Eclipse
+ * mutates it).
+ *
+ * @return true in all cases
+ */
+ public boolean isValid() {
+ return true;
+ }
+
+ @Override
+ protected List<URL> getPlatformBundles() {
+ return Collections.emptyList();
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafRemoteShellConnection.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafRemoteShellConnection.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafRemoteShellConnection.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafRemoteShellConnection.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,41 @@
+/**
+ * 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.core.shell;
+
+import java.io.IOException;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public interface KarafRemoteShellConnection {
+
+ /**
+ * Connects to the remote shell of a Karaf instance.
+ * <p>
+ * This method will block until the connection has been established.
+ */
+ public void connect() throws IOException;
+
+ /**
+ * Disconnects from the remote shell of a Karaf instance
+ * <p>
+ * This method will block until the connection has been severed
+ */
+ public void disconnect() throws IOException;
+
+ /**
+ * Determines whether or not there is a connection to the Karaf remote shell
+ *
+ * @return true if a connection exists, false otherwise
+ */
+ public boolean isConnected();
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafSshConnectionUrl.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafSshConnectionUrl.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafSshConnectionUrl.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafSshConnectionUrl.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,94 @@
+/**
+ * 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.core.shell;
+
+/**
+ * This object represents the necessary information for a Karaf
+ * SSH connection
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public final class KarafSshConnectionUrl {
+
+ private final String host;
+
+ private final int port;
+
+ /**
+ * This object represents the necessary information for a Karaf
+ * SSH connection
+ *
+ * @param host
+ * the remote host
+ * @param port
+ * the port of the remote host
+ */
+ public KarafSshConnectionUrl(final String host, final int port) {
+ this.host = host;
+ this.port = port;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (!(obj instanceof KarafSshConnectionUrl)) {
+ return false;
+ }
+
+ final KarafSshConnectionUrl other = (KarafSshConnectionUrl) obj;
+ if (host == null) {
+ if (other.host != null) {
+ return false;
+ }
+ } else if (!host.equals(other.host)) {
+ return false;
+ }
+
+ if (port != other.port) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Getter for the remote host
+ *
+ * @return the remote host
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * Getter for the SSH server's port
+ *
+ * @return the SSH server's port
+ */
+ public int getPort() {
+ return port;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (host == null ? 0 : host.hashCode());
+ result = prime * result + port;
+ return result;
+ }
+
+
+}
\ No newline at end of file
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafSshShellConnection.java
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafSshShellConnection.java?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafSshShellConnection.java (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.core/src/main/java/info/evanchik/eclipse/karaf/core/shell/KarafSshShellConnection.java Wed Jan 4 13:22:10 2012
@@ -0,0 +1,244 @@
+/**
+ * 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.core.shell;
+
+import info.evanchik.eclipse.karaf.core.internal.KarafCorePluginActivator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.sshd.ClientChannel;
+import org.apache.sshd.ClientSession;
+import org.apache.sshd.SshClient;
+import org.apache.sshd.client.future.AuthFuture;
+import org.apache.sshd.client.future.ConnectFuture;
+import org.apache.sshd.common.util.NoCloseInputStream;
+import org.apache.sshd.common.util.NoCloseOutputStream;
+import org.fusesource.jansi.AnsiConsole;
+
+/**
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+public class KarafSshShellConnection implements KarafRemoteShellConnection {
+
+ /**
+ *
+ * @author Stephen Evanchik (evanchsa@gmail.com)
+ *
+ */
+ public static final class Credentials {
+
+ private final String password;
+
+ private final String username;
+
+ /**
+ *
+ * @param username
+ * @param password
+ */
+ public Credentials(final String username, final String password) {
+ this.username = username;
+ this.password = password;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (!(obj instanceof Credentials)) {
+ return false;
+ }
+
+ final Credentials other = (Credentials) obj;
+ if (password == null) {
+ if (other.password != null) {
+ return false;
+ }
+ } else if (!password.equals(other.password)) {
+ return false;
+ }
+
+ if (username == null) {
+ if (other.username != null) {
+ return false;
+ }
+ } else if (!username.equals(other.username)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (password == null ? 0 : password.hashCode());
+ result = prime * result + (username == null ? 0 : username.hashCode());
+ return result;
+ }
+ }
+
+ private ClientChannel clientChannel;
+
+ private ClientSession clientSession;
+
+ private final AtomicBoolean connected = new AtomicBoolean();
+
+ private int connectionStatus;
+
+ private final KarafSshConnectionUrl connectionUrl;
+
+ private final Credentials credentials;
+
+ private final OutputStream errorStream;
+
+ private volatile Throwable exception;
+
+ private final InputStream inputStream;
+
+ private final OutputStream outputStream;
+
+ private SshClient sshClient;
+
+ /**
+ * Creates a remote shell connection to a Karaf instance using the SSH
+ * protocol
+ *
+ * @param connectionUrl
+ * the coordinates used to establish the connection
+ * @param credentials
+ * the username and password used to authenticate when connection
+ * @param inputStream
+ * the {@link InputStream} used to interact with the remote
+ * system
+ * @param outputStream
+ * the {@link OutputStream} used to receive data from
+ * {@code stdout} of the remote system
+ * @param errorStream
+ * the {@link OutputStream} used to receive data from
+ * {@code stderr} of the remote system
+ */
+ public KarafSshShellConnection(
+ final KarafSshConnectionUrl connectionUrl,
+ final Credentials credentials,
+ final InputStream inputStream,
+ final OutputStream outputStream,
+ final OutputStream errorStream)
+ {
+
+ this.connectionUrl = connectionUrl;
+ this.credentials = credentials;
+
+ this.inputStream = inputStream;
+ this.outputStream = outputStream;
+ this.errorStream = errorStream;
+
+ this.exception = null;
+
+ this.sshClient = SshClient.setUpDefaultClient();
+ }
+
+ @Override
+ public void connect() throws IOException {
+ sshClient.start();
+
+ try {
+ final ConnectFuture connectFuture = sshClient.connect(connectionUrl.getHost(), connectionUrl.getPort());
+ connectFuture.await(15 * 1000);
+
+ clientSession = connectFuture.getSession();
+
+ final AuthFuture authFuture = clientSession.authPassword(credentials.getUsername(), credentials.getPassword());
+ authFuture.await(15 * 1000);
+
+ if (!authFuture.isSuccess()) {
+ exception = authFuture.getException();
+
+ try {
+ disconnect();
+ } catch (final IOException e) {
+ KarafCorePluginActivator.getLogger().warn("Error while disconnecting after authenticate failure", e);
+ }
+
+ throw new IOException(exception);
+ }
+
+ clientChannel = clientSession.createChannel(ClientChannel.CHANNEL_SHELL);
+
+ clientChannel.setIn(new NoCloseInputStream(inputStream));
+ clientChannel.setOut(AnsiConsole.wrapOutputStream(new NoCloseOutputStream(outputStream)));
+ clientChannel.setErr(AnsiConsole.wrapOutputStream(new NoCloseOutputStream(errorStream)));
+
+ connected.set(true);
+
+ clientChannel.open();
+ connectionStatus = clientChannel.waitFor(ClientChannel.CLOSED, 15 * 1000);
+ } catch (final Exception e) {
+ throw new IOException(e);
+ }
+ }
+
+ @Override
+ public void disconnect() throws IOException {
+ try {
+ if (clientChannel != null) {
+ clientChannel.close(true).await();
+ }
+
+ if (clientSession != null) {
+ clientSession.close(true).await();
+ }
+ } catch (final Exception e) {
+ throw new IOException(e);
+ } finally {
+ clientChannel = null;
+ clientSession = null;
+
+ connected.set(false);
+ }
+ }
+
+ public int getConnectionStatus() {
+ return connectionStatus;
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ @Override
+ public boolean isConnected() {
+ return connected.get();
+ }
+
+ public void setSshClient(final SshClient sshClient) {
+ this.sshClient = sshClient;
+ }
+}
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/.classpath
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/.classpath?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/.classpath (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/.classpath Wed Jan 4 13:22:10 2012
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/.project
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/.project?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/.project (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/.project Wed Jan 4 13:22:10 2012
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>info.evanchik.eclipse.karaf.hooks</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/META-INF/MANIFEST.MF?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/META-INF/MANIFEST.MF (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/META-INF/MANIFEST.MF Wed Jan 4 13:22:10 2012
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Framework Extensions for Eclipse Integration for Apache Felix Karaf
+Bundle-SymbolicName: info.evanchik.eclipse.karaf.hooks;singleton:=true
+Bundle-Version: 0.5.0.qualifier
+Fragment-Host: org.eclipse.osgi;bundle-version="3.4.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-Vendor: evanchik.info
Added: karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/build.properties
URL: http://svn.apache.org/viewvc/karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/build.properties?rev=1227144&view=auto
==============================================================================
--- karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/build.properties (added)
+++ karaf/eik/trunk/plugins/info.evanchik.eclipse.karaf.hooks/build.properties Wed Jan 4 13:22:10 2012
@@ -0,0 +1,10 @@
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ .,\
+ hookconfigurators.properties,\
+ epl-v10.html
+src.includes = src/,\
+ hookconfigurators.properties,\
+ epl-v10.html,\
+ pom.xml