You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/08/01 08:37:03 UTC
svn commit: r681611 [1/2] - in /geronimo/gshell/trunk/gshell-wisdom/src/main:
java/org/apache/geronimo/gshell/wisdom/
java/org/apache/geronimo/gshell/wisdom/application/
java/org/apache/geronimo/gshell/wisdom/command/
java/org/apache/geronimo/gshell/wi...
Author: jdillon
Date: Thu Jul 31 23:37:02 2008
New Revision: 681611
URL: http://svn.apache.org/viewvc?rev=681611&view=rev
Log:
Adding some spring components for the gshell core, not hooked up or working yet, but mostly stripped of plexus muck
Added:
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/ShellBuilder.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/SettingsManagerImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandCompleterImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerFactoryImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandInfoImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandResolverImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineBuilderImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/HistoryImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/LayoutManagerImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellInfoImpl.java (with props)
geronimo/gshell/trunk/gshell-wisdom/src/main/resources/META-INF/spring/components.xml (with props)
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/ShellBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/ShellBuilder.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/ShellBuilder.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/ShellBuilder.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom;
+
+import org.apache.geronimo.gshell.application.ApplicationConfiguration;
+import org.apache.geronimo.gshell.application.ApplicationManager;
+import org.apache.geronimo.gshell.application.settings.SettingsConfiguration;
+import org.apache.geronimo.gshell.application.settings.SettingsManager;
+import org.apache.geronimo.gshell.artifact.ArtifactManager;
+import org.apache.geronimo.gshell.artifact.monitor.ProgressSpinnerMonitor;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.io.IO;
+import org.apache.geronimo.gshell.io.SystemOutputHijacker;
+import org.apache.geronimo.gshell.model.application.Application;
+import org.apache.geronimo.gshell.model.settings.Settings;
+import org.apache.geronimo.gshell.shell.Shell;
+import org.apache.geronimo.gshell.shell.ShellFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Builds {@link org.apache.geronimo.gshell.shell.Shell} instances.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ShellBuilder
+ implements ShellFactory
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ /*
+ private static final String DEFAULT_REALM_ID = "gshell";
+
+ private static final String DEFAULT_CONTAINER_NAME = "gshell";
+
+ private GShellPlexusContainer container;
+
+ private ClassWorld classWorld;
+ */
+
+ private SettingsManager settingsManager;
+
+ private SettingsConfiguration settingsConfig = new SettingsConfiguration();
+
+ private ApplicationManager applicationManager;
+
+ private ApplicationConfiguration applicationConfig = new ApplicationConfiguration();
+
+ private ArtifactManager artifactManager;
+
+ public ShellBuilder() {}
+
+ /*
+ private GShellPlexusContainer createContainer() throws PlexusContainerException {
+ ContainerConfiguration config = new DefaultContainerConfiguration();
+
+ config.setName(DEFAULT_CONTAINER_NAME);
+ config.setClassWorld(getClassWorld());
+
+ GShellPlexusContainer container = new GShellPlexusContainer(config);
+
+ // Install our logging muck
+ container.setLoggerManager(new Slf4jLoggingManager());
+
+ return container;
+ }
+
+ public GShellPlexusContainer getContainer() throws PlexusContainerException {
+ if (container == null) {
+ container = createContainer();
+ }
+ return container;
+ }
+
+ public void setContainer(final GShellPlexusContainer container) {
+ this.container = container;
+ }
+ */
+
+ /*
+ private ClassWorld createClassWorld() {
+ return new ClassWorld(DEFAULT_REALM_ID, Thread.currentThread().getContextClassLoader());
+ }
+
+ public ClassWorld getClassWorld() {
+ if (classWorld == null) {
+ classWorld = createClassWorld();
+ }
+ return classWorld;
+ }
+
+ public void setClassWorld(final ClassWorld classWorld) {
+ this.classWorld = classWorld;
+ }
+ */
+
+ public IO getIo() {
+ return applicationConfig.getIo();
+ }
+
+ public void setIo(final IO io) {
+ applicationConfig.setIo(io);
+ }
+
+ public Variables getVariables() {
+ return applicationConfig.getVariables();
+ }
+
+ public void setVariables(final Variables variables) {
+ applicationConfig.setVariables(variables);
+ }
+
+ public Settings getSettings() {
+ return settingsConfig.getSettings();
+ }
+
+ public void setSettings(final Settings settings) {
+ settingsConfig.setSettings(settings);
+ }
+
+ private SettingsManager createSettingsManager() /*FIXME: throws ComponentLookupException */ {
+ return null; // FIXME: container.lookupComponent(SettingsManager.class);
+ }
+
+ public SettingsManager getSettingsManager() /*FIXME: throws ComponentLookupException*/ {
+ if (settingsManager == null) {
+ settingsManager = createSettingsManager();
+ }
+ return settingsManager;
+ }
+
+ public void setSettingsManager(final SettingsManager settingsManager) {
+ this.settingsManager = settingsManager;
+ }
+
+ public Application getApplication() {
+ return applicationConfig.getApplication();
+ }
+
+ public void setApplication(final Application application) {
+ applicationConfig.setApplication(application);
+ }
+
+ private ApplicationManager createApplicationManager() /*FIXME: throws ComponentLookupException*/ {
+ return null; // FIXME: container.lookupComponent(ApplicationManager.class);
+ }
+
+ public ApplicationManager getApplicationManager() /*FIXME: throws ComponentLookupException*/ {
+ if (applicationManager == null) {
+ applicationManager = createApplicationManager();
+ }
+ return applicationManager;
+ }
+
+ public void setApplicationManager(final ApplicationManager applicationManager) {
+ this.applicationManager = applicationManager;
+ }
+
+ private ArtifactManager createArtifactManager() /*FIXME: throws PlexusContainerException, ComponentLookupException*/ {
+ return null; // FIXME: getContainer().lookupComponent(ArtifactManager.class);
+ }
+
+ public ArtifactManager getArtifactManager() /*FIXME: throws ComponentLookupException, PlexusContainerException*/ {
+ if (artifactManager == null) {
+ artifactManager = createArtifactManager();
+ }
+ return artifactManager;
+ }
+
+ public void setArtifactManager(final ArtifactManager artifactManager) {
+ this.artifactManager = artifactManager;
+ }
+
+ //
+ // ShellFactory
+ //
+
+ public Shell create() throws Exception {
+ log.debug("Building");
+
+ // Set some defaults
+ if (applicationConfig.getIo() == null) {
+ applicationConfig.setIo(new IO());
+ }
+ if (applicationConfig.getVariables() == null) {
+ applicationConfig.setVariables(new Variables());
+ }
+
+ // Hijack the system output streams
+ if (!SystemOutputHijacker.isInstalled()) {
+ SystemOutputHijacker.install();
+ }
+
+ // Register the application IO streams
+ IO io = getIo();
+ SystemOutputHijacker.register(io.outputStream, io.errorStream);
+
+ // Initialize the container
+ /*
+ FIXME:
+ getContainer();
+ log.debug("Container: {}", container);
+ */
+
+ //
+ // TODO: Allow someway to configure a non-interactive monitor
+ //
+
+ // Configure download monitor
+ getArtifactManager().setDownloadMonitor(new ProgressSpinnerMonitor(getIo()));
+
+ // Configure settings
+ getSettingsManager().configure(settingsConfig);
+
+ // Configure application
+ getApplicationManager().configure(applicationConfig);
+
+ return getApplicationManager().create();
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/ShellBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/ShellBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/ShellBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,347 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.application;
+
+import org.apache.geronimo.gshell.application.ApplicationConfiguration;
+import org.apache.geronimo.gshell.application.ApplicationContext;
+import org.apache.geronimo.gshell.application.ApplicationManager;
+import org.apache.geronimo.gshell.application.ApplicationSecurityManager;
+import org.apache.geronimo.gshell.application.settings.SettingsManager;
+import org.apache.geronimo.gshell.artifact.ArtifactManager;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.io.IO;
+import org.apache.geronimo.gshell.model.application.Application;
+import org.apache.geronimo.gshell.model.common.Dependency;
+import org.apache.geronimo.gshell.model.common.LocalRepository;
+import org.apache.geronimo.gshell.model.common.RemoteRepository;
+import org.apache.geronimo.gshell.model.interpolate.Interpolator;
+import org.apache.geronimo.gshell.model.interpolate.InterpolatorSupport;
+import org.apache.geronimo.gshell.model.settings.Settings;
+import org.apache.geronimo.gshell.shell.Shell;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.net.URL;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Default implementation of the {@link org.apache.geronimo.gshell.application.ApplicationManager} component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ApplicationManagerImpl
+ implements ApplicationManager
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private ArtifactManager artifactManager;
+
+ private SettingsManager settingsManager;
+
+ /*
+ FIXME:
+ private GShellPlexusContainer parentContainer;
+
+ private GShellPlexusContainer container;
+ */
+
+ private ApplicationContext applicationContext;
+
+ public ApplicationContext getContext() {
+ if (applicationContext == null) {
+ throw new IllegalStateException("Application has not been configured");
+ }
+
+ return applicationContext;
+ }
+
+ public void configure(final ApplicationConfiguration config) throws Exception {
+ assert config != null;
+
+ log.trace("Configuring; config: {}", config);
+
+ // Validate the configuration
+ config.validate();
+
+ // Interpolate the model
+ interpolate(config);
+
+ // Configure the application
+ configure(config.getApplication());
+
+ // Create a new context
+ applicationContext = new ApplicationContext() {
+ public IO getIo() {
+ return config.getIo();
+ }
+
+ public Variables getVariables() {
+ return config.getVariables();
+ }
+
+ public Application getApplication() {
+ return config.getApplication();
+ }
+ };
+ }
+
+ private void interpolate(final ApplicationConfiguration config) throws Exception {
+ assert config != null;
+
+ Application app = config.getApplication();
+ Interpolator<Application> interp = new InterpolatorSupport<Application>();
+
+ // Add value sources to resolve muck
+ interp.addValueSource(new PropertiesBasedValueSource(System.getProperties()));
+
+ // User settings should override the applications
+ assert settingsManager != null;
+ Settings settings = settingsManager.getSettings();
+ if (settings != null) {
+ interp.addValueSource(new PropertiesBasedValueSource(settings.getProperties()));
+ }
+
+ // Add application settings
+ interp.addValueSource(new PropertiesBasedValueSource(app.getProperties()));
+
+ app = interp.interpolate(app);
+
+ // Update the configuration with the new model
+ config.setApplication(app);
+ }
+
+ private void configure(final Application application) throws Exception {
+ assert application != null;
+
+ log.debug("Application ID: {}", application.getId());
+ log.trace("Application descriptor: {}", application);
+
+ // Apply artifact manager configuration settings for application
+ configureArtifactManager(application);
+
+ // Create the application container
+ // FIXME:
+ // container = createContainer(application);
+ }
+
+ private void configureArtifactManager(final Application application) throws Exception {
+ assert application != null;
+ assert artifactManager != null;
+
+ // Setup the local repository
+ LocalRepository localRepository = application.getLocalRepository();
+
+ if (localRepository != null) {
+ artifactManager.getRepositoryManager().setLocalRepository(localRepository.getDirectoryFile());
+ }
+
+ // Setup remote repositories
+ for (RemoteRepository repo : application.remoteRepositories()) {
+ artifactManager.getRepositoryManager().addRemoteRepository(repo.getId(), repo.getLocationUri());
+ }
+ }
+
+ /*
+ private GShellPlexusContainer createContainer(final Application application) throws Exception {
+ assert application != null;
+
+ log.debug("Creating application container");
+
+ List<URL> classPath = createClassPath(application);
+
+ ClassWorld world = new ClassWorld();
+ ClassRealm realm = world.newRealm("gshell.application[" + application.getId().replace(".", "/") + "]");
+ realm.setParentRealm(parentContainer.getContainerRealm());
+
+ for (URL url : classPath) {
+ realm.addURL(url);
+ }
+
+ ContainerConfiguration config = new DefaultContainerConfiguration();
+ config.setName(application.getId());
+ config.setClassWorld(world);
+ config.setRealm(realm);
+ config.addComponentDiscoverer(new PluginDiscoverer());
+ config.addComponentDiscoveryListener(new PluginCollector());
+
+ GShellPlexusContainer child = parentContainer.createChild(config);
+
+ log.debug("Application container: {}", child);
+
+ return child;
+ }
+ */
+
+ private List<URL> createClassPath(final Application application) throws Exception {
+ assert application != null;
+
+ ArtifactResolutionRequest request = new ArtifactResolutionRequest();
+ request.setFilter(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME));
+
+ Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
+ List<Dependency> dependencies = application.dependencies(true); // include groups
+
+ if (!dependencies.isEmpty()) {
+ ArtifactFactory factory = artifactManager.getArtifactFactory();
+
+ log.debug("Application dependencies:");
+
+ for (Dependency dep : dependencies) {
+ Artifact artifact = factory.createArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), null, dep.getType());
+ assert artifact != null;
+
+ log.debug(" + {}", artifact);
+
+ artifacts.add(artifact);
+ }
+ }
+
+ request.setArtifactDependencies(artifacts);
+
+ ArtifactResolutionResult result = artifactManager.resolve(request);
+
+ List<URL> classPath = new LinkedList<URL>();
+ Set<Artifact> resolvedArtifacts = result.getArtifacts();
+
+ //
+ // FIXME: Load this list from build-generated properties or something like that
+ //
+
+ ExclusionSetFilter filter = new ExclusionSetFilter(new String[] {
+ "aspectjrt",
+ "gshell-ansi",
+ "gshell-api",
+ "gshell-artifact",
+ "gshell-application",
+ "gshell-cli",
+ "gshell-clp",
+ "gshell-i18n",
+ "gshell-io",
+ "gshell-model",
+ "gshell-plexus",
+ "gshell-rapture-bootstrap",
+ "gshell-yarn",
+ "jcl104-over-slf4j",
+ "jline",
+ "log4j",
+ "maven-artifact",
+ "maven-model",
+ "maven-profile",
+ "maven-project",
+ "maven-workspace",
+ "plexus-component-annotations",
+ "plexus-container-default",
+ "plexus-interpolation",
+ "plexus-utils",
+ "plexus-classworlds",
+ "slf4j-api",
+ "slf4j-log4j12",
+ "wagon-file",
+ "wagon-http-lightweight",
+ "wagon-http-shared",
+ "wagon-provider-api",
+ "xbean-reflect",
+ "xpp3_min",
+ "xstream-",
+ });
+
+ if (resolvedArtifacts != null && !resolvedArtifacts.isEmpty()) {
+ log.debug("Application classpath:");
+
+ for (Artifact artifact : resolvedArtifacts) {
+ if (filter.include(artifact)) {
+ File file = artifact.getFile();
+ assert file != null;
+
+ URL url = file.toURI().toURL();
+ log.debug(" + {}", url);
+
+ classPath.add(url);
+ }
+ }
+ }
+
+ return classPath;
+ }
+
+ public Shell create() throws Exception {
+ // Make sure that we have a valid context
+ getContext();
+
+ final Shell shell = null; // FIXME: container.lookupComponent(Shell.class);
+
+ log.debug("Created shell instance: {}", shell);
+
+ InvocationHandler handler = new InvocationHandler()
+ {
+ //
+ // FIXME: Need to resolve how to handle the security manager for the application,
+ // the SM is not thread-specific, but VM specific... so not sure this is
+ // the right approache at all :-(
+ //
+
+ private final ApplicationSecurityManager securityManager = new ApplicationSecurityManager();
+
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
+ assert proxy != null;
+ assert method != null;
+ // args may be null
+
+ if (method.getDeclaringClass() == Object.class) {
+ return method.invoke(this, args);
+ }
+
+ SecurityManager previous = System.getSecurityManager();
+ System.setSecurityManager(securityManager);
+ try {
+ return method.invoke(shell, args);
+ }
+ catch (InvocationTargetException e) {
+ throw e.getTargetException();
+ }
+ finally {
+ System.setSecurityManager(previous);
+ }
+ }
+ };
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Shell proxy = (Shell) Proxy.newProxyInstance(cl, new Class[] { Shell.class }, handler);
+
+ log.debug("Create shell proxy: {}", proxy);
+
+ return proxy;
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/SettingsManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/SettingsManagerImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/SettingsManagerImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/SettingsManagerImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.application;
+
+import org.apache.geronimo.gshell.application.settings.SettingsConfiguration;
+import org.apache.geronimo.gshell.application.settings.SettingsManager;
+import org.apache.geronimo.gshell.artifact.ArtifactManager;
+import org.apache.geronimo.gshell.model.common.RemoteRepository;
+import org.apache.geronimo.gshell.model.interpolate.Interpolator;
+import org.apache.geronimo.gshell.model.interpolate.InterpolatorSupport;
+import org.apache.geronimo.gshell.model.settings.Settings;
+import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default implementation of the {@link org.apache.geronimo.gshell.application.settings.SettingsManager} component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SettingsManagerImpl
+ implements SettingsManager
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private ArtifactManager artifactManager;
+
+ private SettingsConfiguration settingsConfiguration;
+
+ public Settings getSettings() {
+ if (settingsConfiguration == null) {
+ throw new IllegalStateException("Not configured");
+ }
+
+ return settingsConfiguration.getSettings();
+ }
+
+ public void configure(final SettingsConfiguration config) throws Exception {
+ assert config != null;
+
+ log.trace("Configuring; config: {}", config);
+
+ // Validate the configuration
+ config.validate();
+
+ if (config.getSettings() != null) {
+ // Interpolate the model
+ interpolate(config);
+
+ // Configure settings
+ configure(config.getSettings());
+ }
+
+ // TODO: Merge in some default settings or something?
+
+ settingsConfiguration = config;
+ }
+
+ private void interpolate(final SettingsConfiguration config) throws Exception {
+ assert config != null;
+
+ Settings settings = config.getSettings();
+ Interpolator<Settings> interp = new InterpolatorSupport<Settings>();
+
+ // Add value sources to resolve muck
+ interp.addValueSource(new PropertiesBasedValueSource(System.getProperties()));
+ interp.addValueSource(new PropertiesBasedValueSource(settings.getProperties()));
+
+ settings = interp.interpolate(settings);
+
+ // Update the configuration with the new model
+ config.setSettings(settings);
+ }
+
+ private void configure(final Settings settings) throws Exception {
+ assert settings != null;
+
+ // TODO: Add settings interpolation here
+
+ // Setup remote repositories
+ for (RemoteRepository repo : settings.remoteRepositories()) {
+ artifactManager.getRepositoryManager().addRemoteRepository(repo.getId(), repo.getLocationUri());
+ }
+
+ // TODO: apply other artifact related settings (proxy, auth, whatever)
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/SettingsManagerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/SettingsManagerImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/application/SettingsManagerImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandCompleterImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandCompleterImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandCompleterImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandCompleterImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.command;
+
+import jline.Completor;
+import org.apache.geronimo.gshell.command.CommandCompleter;
+import org.apache.geronimo.gshell.command.CommandInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The default {@link CommandCompleter} component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandCompleterImpl
+ implements CommandCompleter
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ public Completor createCompletor(final CommandInfo info) {
+ assert info != null;
+
+ // TODO:
+
+ throw new Error();
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandCompleterImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandCompleterImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandCompleterImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerFactoryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerFactoryImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerFactoryImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerFactoryImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.command;
+
+import org.apache.geronimo.gshell.command.CommandContainer;
+import org.apache.geronimo.gshell.command.CommandContainerFactory;
+import org.apache.geronimo.gshell.plexus.GShellPlexusContainer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default implementation of a {@link CommandContainerFactory} component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandContainerFactoryImpl
+ implements CommandContainerFactory
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private GShellPlexusContainer container;
+
+ public CommandContainer create(final String id) throws Exception {
+ assert id != null;
+
+ log.debug("Locating container for ID: {}", id);
+
+ /*
+ ComponentDescriptor descriptor = container.getComponentDescriptor(CommandContainer.class, id);
+ if (descriptor == null) {
+ // TODO: Throw typed exception
+ throw new Exception("Command container not found for ID: " + id);
+ }
+
+ CommandContainer command;
+ try {
+ command = container.lookupComponent(CommandContainer.class, id);
+ }
+ catch (ComponentLookupException e) {
+ // TODO: Throw typed exception
+ throw new Exception("Failed to access command container for ID: " + id, e);
+ }
+
+ return command;
+ */
+
+ return null;
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerFactoryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerFactoryImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerFactoryImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.command;
+
+import org.apache.geronimo.gshell.clp.CommandLineProcessor;
+import org.apache.geronimo.gshell.clp.Option;
+import org.apache.geronimo.gshell.clp.ProcessingException;
+import org.apache.geronimo.gshell.command.Arguments;
+import org.apache.geronimo.gshell.command.CommandAction;
+import org.apache.geronimo.gshell.command.CommandCompleter;
+import org.apache.geronimo.gshell.command.CommandContainer;
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.command.CommandDocumenter;
+import org.apache.geronimo.gshell.command.CommandResult;
+import org.apache.geronimo.gshell.notification.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+/**
+ * The default {@link CommandContainer} component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandContainerImpl
+ implements CommandContainer
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ // private GShellPlexusContainer container;
+
+ private String commandId;
+
+ // Command
+
+ public String getId() {
+ return commandId;
+ }
+
+ private <T> T lookupComponent(final Class<T> role) {
+ /*
+ assert role != null;
+ assert container != null;
+
+ try {
+ return container.lookupComponent(role, commandId);
+ }
+ catch (ComponentLookupException e) {
+ throw new RuntimeException(e);
+ }
+ */
+
+ return null;
+ }
+
+ public CommandAction getAction() {
+ return lookupComponent(CommandAction.class);
+ }
+
+ public CommandDocumenter getDocumenter() {
+ return lookupComponent(CommandDocumenter.class);
+ }
+
+ public CommandCompleter getCompleter() {
+ return lookupComponent(CommandCompleter.class);
+ }
+
+ public CommandResult execute(final CommandContext context) {
+ assert context != null;
+
+ log.trace("Executing; context={}");
+
+ // Provide logging context for the command execution
+ MDC.put("commandId", commandId);
+
+ CommandResult result;
+
+ try {
+ CommandAction action = getAction();
+
+ // Process command line options/arguments, return if we have been asked to display --help
+ try {
+ if (processArguments(context, action, context.getArguments())) {
+ return new CommandResult(CommandAction.Result.SUCCESS);
+ }
+ }
+ catch (ProcessingException e) {
+ new CommandResult(e);
+ }
+
+ try {
+ final Object value = action.execute(context);
+ log.trace("Result: {}", value);
+
+ result = new CommandResult(value);
+ }
+ catch (final Notification n) {
+ log.trace("Notified: {}, n");
+
+ result = new CommandResult(n);
+ }
+ catch (final Throwable t) {
+ log.trace("Caught: {}", t);
+
+ result = new CommandResult(t);
+ }
+ }
+ finally {
+ MDC.remove("commandId");
+ }
+
+ return result;
+ }
+
+ /**
+ * Process command-line arguments for the action.
+ *
+ * @param context The command context.
+ * @param action The action being executed.
+ * @param args The arguments to the action.
+ * @return True if --help was detetected, else execute the action.
+ *
+ * @throws org.apache.geronimo.gshell.clp.ProcessingException A failure occured while processing the command-line.
+ */
+ private boolean processArguments(final CommandContext context, final CommandAction action, final Object[] args) throws ProcessingException {
+ assert context != null;
+ assert args != null;
+
+ CommandLineProcessor clp = new CommandLineProcessor();
+ clp.addBean(action);
+
+ // Attach some help context
+ CommandDocumenter documenter = getDocumenter();
+ HelpSupport help = new HelpSupport();
+ clp.addBean(help);
+ clp.addBean(documenter);
+
+ // Process the arguments
+ clp.process(Arguments.toStringArray(args));
+
+ // Render command-line usage
+ if (help.displayHelp) {
+ documenter.renderUsage(context.getInfo(), context.getIo().out);
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Helper to inject <tt>--help<tt> support. Package access to allow DefaultCommandDocumentor access.
+ */
+ static class HelpSupport
+ {
+ @Option(name="-h", aliases={"--help"}, description="Display this help message", requireOverride=true)
+ public boolean displayHelp;
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandContainerImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.command;
+
+import org.apache.geronimo.gshell.clp.CommandLineProcessor;
+import org.apache.geronimo.gshell.clp.Printer;
+import org.apache.geronimo.gshell.command.CommandAction;
+import org.apache.geronimo.gshell.command.CommandDocumenter;
+import org.apache.geronimo.gshell.command.CommandInfo;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.PrintWriter;
+
+/**
+ * The default {@link CommandDocumenter} component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandDocumenterImpl
+ implements CommandDocumenter
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ // private GShellPlexusContainer container;
+
+ /**
+ * Get the action instance for the given command context.
+ *
+ * @param info The command-info to previde an action for.
+ * @return The command action for the given information.
+ */
+ private CommandAction getAction(final CommandInfo info) {
+ assert info != null;
+
+ /*
+ FIXME:
+ assert container != null;
+
+ try {
+ return container.lookupComponent(CommandAction.class, info.getId());
+ }
+ catch (ComponentLookupException e) {
+ throw new RuntimeException(e);
+ }
+ */
+
+ return null;
+ }
+
+ // CommandDocumenter
+
+ public String getName(final CommandInfo info) {
+ assert info != null;
+
+ // Use the alias if we have one, else use the command name
+ String name = info.getAlias();
+ if (name == null) {
+ name = info.getName();
+ }
+
+ return name;
+ }
+
+ public String getDescription(final CommandInfo info) {
+ assert info != null;
+
+ //
+ // HACK: This needs to chagne, doing this for now to make it work
+ //
+
+ CommandAction action = getAction(info);
+ CommandComponent annotation = action.getClass().getAnnotation(CommandComponent.class);
+ if (annotation == null) {
+ throw new IllegalStateException("Command description not found");
+ }
+
+ return annotation.description();
+ }
+
+ //
+ // TODO: Add some nice ANSI muck
+ //
+
+ public void renderUsage(final CommandInfo info, final PrintWriter out) {
+ assert info != null;
+ assert out != null;
+
+ CommandLineProcessor clp = new CommandLineProcessor();
+
+ // Attach our helper to inject --help
+ CommandContainerImpl.HelpSupport help = new CommandContainerImpl.HelpSupport();
+ clp.addBean(help);
+
+ // And then the beans options
+ CommandAction action = getAction(info);
+ clp.addBean(action);
+
+ // Fetch the details
+ String name = getName(info);
+ String desc = getDescription(info);
+
+ // Render the help
+ out.println(desc);
+ out.println();
+
+ Printer printer = new Printer(clp);
+
+ printer.printUsage(out, name);
+ out.println();
+ }
+
+ public void renderManual(final CommandInfo info, final PrintWriter out) {
+ assert info != null;
+ assert out != null;
+
+ out.println(info.getName());
+ out.println();
+ out.println("TODO: Full docs");
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandInfoImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandInfoImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandInfoImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandInfoImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.command;
+
+import org.apache.geronimo.gshell.command.CommandInfo;
+import org.apache.geronimo.gshell.model.layout.AliasNode;
+import org.apache.geronimo.gshell.model.layout.CommandNode;
+import org.apache.geronimo.gshell.model.layout.Node;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The default {@link CommandInfo} implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandInfoImpl
+ implements CommandInfo
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private final Node node;
+
+ public CommandInfoImpl(final Node node) {
+ assert node != null;
+ this.node = node;
+ }
+
+ public String getId() {
+ if (node instanceof CommandNode) {
+ return ((CommandNode)node).getId();
+ }
+ else if (node instanceof AliasNode) {
+ return ((AliasNode)node).getCommand();
+ }
+
+ throw new IllegalStateException();
+ }
+
+ public String getName() {
+ if (node instanceof AliasNode) {
+ return ((AliasNode)node).getCommand();
+ }
+
+ return node.getName();
+ }
+
+ public String getAlias() {
+ if (node instanceof AliasNode) {
+ return node.getName();
+ }
+
+ return null;
+ }
+
+ public String getPath() {
+ throw new Error();
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandInfoImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandInfoImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandInfoImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandResolverImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandResolverImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandResolverImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandResolverImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.command;
+
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandContainer;
+import org.apache.geronimo.gshell.command.CommandContainerFactory;
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.command.CommandInfo;
+import org.apache.geronimo.gshell.command.CommandNotFoundException;
+import org.apache.geronimo.gshell.command.CommandResolver;
+import org.apache.geronimo.gshell.command.CommandResult;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.layout.LayoutManager;
+import org.apache.geronimo.gshell.layout.NotFoundException;
+import org.apache.geronimo.gshell.model.layout.AliasNode;
+import org.apache.geronimo.gshell.model.layout.CommandNode;
+import org.apache.geronimo.gshell.model.layout.Node;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The default {@link CommandResolver} component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandResolverImpl
+ implements CommandResolver
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private LayoutManager layoutManager;
+
+ private CommandContainerFactory containerFactory;
+
+ public CommandResolverImpl() {}
+
+ public CommandResolverImpl(final LayoutManager layoutManager, final CommandContainerFactory containerFactory) {
+ assert layoutManager != null;
+ assert containerFactory != null;
+
+ this.layoutManager = layoutManager;
+ this.containerFactory = containerFactory;
+ }
+
+ public Command resolve(final Variables variables, final String path) throws CommandNotFoundException {
+ assert variables != null;
+ assert path != null;
+
+ assert layoutManager != null;
+
+ log.debug("Resolving command for path: {}", path);
+
+ String searchPath = (String) variables.get(LayoutManager.COMMAND_PATH);
+ final Node node;
+
+ try {
+ node = layoutManager.findNode(path, searchPath);
+ }
+ catch (NotFoundException e) {
+ throw new CommandNotFoundException(e);
+ }
+
+ String id = findCommandId(node);
+
+ assert containerFactory != null;
+
+ final CommandContainer container;
+ try {
+ container = containerFactory.create(id);
+ }
+ catch (Exception e) {
+ throw new CommandNotFoundException(e);
+ }
+
+ // Return a new command-instance with details about it layout configuration
+ return new Command()
+ {
+ public CommandInfo getInfo() {
+ return new CommandInfoImpl(node);
+ }
+
+ public CommandContainer getContainer() {
+ return container;
+ }
+
+ public CommandResult execute(CommandContext context) {
+ return container.execute(context);
+ }
+ };
+ }
+
+ private String findCommandId(final Node node) throws CommandNotFoundException {
+ assert node != null;
+
+ assert layoutManager != null;
+
+ if (node instanceof AliasNode) {
+ AliasNode aliasNode = (AliasNode) node;
+ String targetPath = aliasNode.getCommand();
+
+ Node target;
+ try {
+ target = layoutManager.findNode(layoutManager.getLayout(), targetPath);
+ }
+ catch (NotFoundException e) {
+ throw new CommandNotFoundException(e);
+ }
+
+ return findCommandId(target);
+ }
+ else if (node instanceof CommandNode) {
+ CommandNode commandNode = (CommandNode) node;
+
+ return commandNode.getId();
+ }
+
+ throw new CommandNotFoundException("Unable to get command id for: " + node);
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandResolverImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandResolverImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandResolverImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineBuilderImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineBuilderImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineBuilderImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineBuilderImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.shell;
+
+import org.apache.geronimo.gshell.application.ApplicationManager;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.commandline.CommandLine;
+import org.apache.geronimo.gshell.commandline.CommandLineBuilder;
+import org.apache.geronimo.gshell.commandline.CommandLineExecutor;
+import org.apache.geronimo.gshell.notification.ErrorNotification;
+import org.apache.geronimo.gshell.parser.ASTCommandLine;
+import org.apache.geronimo.gshell.parser.CommandLineParser;
+import org.apache.geronimo.gshell.parser.ParseException;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.util.IOUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+/**
+ * Builds {@link CommandLine} instances ready for executing.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandLineBuilderImpl
+ implements CommandLineBuilder
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private PlexusContainer container;
+
+ private ApplicationManager applicationManager;
+
+ private final CommandLineParser parser = new CommandLineParser();
+
+ public CommandLineBuilderImpl() {}
+
+ public CommandLineBuilderImpl(final PlexusContainer container, final ApplicationManager applicationManager) {
+ assert container != null;
+ assert applicationManager != null;
+
+ this.container = container;
+ this.applicationManager = applicationManager;
+ }
+
+ private ASTCommandLine parse(final String input) throws ParseException {
+ assert input != null;
+
+ Reader reader = new StringReader(input);
+ ASTCommandLine cl;
+ try {
+ cl = parser.parse(reader);
+ }
+ finally {
+ IOUtil.close(reader);
+ }
+
+ // If debug is enabled, the log the parse tree
+ /*
+ FIXME:
+ if (log.isDebugEnabled()) {
+ LoggingVisitor logger = new LoggingVisitor(log);
+ cl.jjtAccept(logger, null);
+ }
+ */
+
+ return cl;
+ }
+
+ public CommandLine create(final String commandLine) throws ParseException {
+ assert commandLine != null;
+
+ if (commandLine.trim().length() == 0) {
+ throw new IllegalArgumentException("Command line is empty");
+ }
+
+ try {
+ assert container != null;
+ CommandLineExecutor executor = (CommandLineExecutor) container.lookup(CommandLineExecutor.class);
+
+ assert applicationManager != null;
+ Variables vars = applicationManager.getContext().getVariables();
+
+ /*
+ FIXME:
+
+ final ExecutingVisitor visitor = new ExecutingVisitor(executor, vars);
+ final ASTCommandLine root = parse(commandLine);
+
+ return new CommandLine() {
+ public Object execute() throws Exception {
+ return root.jjtAccept(visitor, null);
+ }
+ };
+ */
+
+ return null;
+ }
+ catch (Exception e) {
+ throw new ErrorNotification(e);
+ }
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineBuilderImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineBuilderImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineBuilderImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.shell;
+
+import org.apache.geronimo.gshell.application.ApplicationManager;
+import org.apache.geronimo.gshell.chronos.StopWatch;
+import org.apache.geronimo.gshell.command.Arguments;
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.command.CommandInfo;
+import org.apache.geronimo.gshell.command.CommandResolver;
+import org.apache.geronimo.gshell.command.CommandResult;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.commandline.CommandLine;
+import org.apache.geronimo.gshell.commandline.CommandLineBuilder;
+import org.apache.geronimo.gshell.commandline.CommandLineExecutionFailied;
+import org.apache.geronimo.gshell.commandline.CommandLineExecutor;
+import org.apache.geronimo.gshell.io.IO;
+import org.apache.geronimo.gshell.io.SystemOutputHijacker;
+import org.apache.geronimo.gshell.notification.ErrorNotification;
+import org.apache.geronimo.gshell.notification.Notification;
+import org.codehaus.plexus.util.IOUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.io.PrintStream;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * The default {@link CommandLineExecutor} component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandLineExecutorImpl
+ implements CommandLineExecutor
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private ApplicationManager applicationManager;
+
+ private CommandResolver commandResolver;
+
+ private CommandLineBuilder commandLineBuilder;
+
+ private Variables variables;
+
+ private IO io;
+
+ public CommandLineExecutorImpl() {}
+
+ public CommandLineExecutorImpl(final ApplicationManager applicationManager, final CommandLineBuilder commandLineBuilder) {
+ assert applicationManager != null;
+ assert commandLineBuilder != null;
+
+ this.applicationManager = applicationManager;
+ this.commandLineBuilder = commandLineBuilder;
+ }
+
+ /*
+ public void initialize() throws InitializationException {
+ assert applicationManager != null;
+
+ this.variables = applicationManager.getContext().getVariables();
+ this.io = applicationManager.getContext().getIo();
+ }
+ */
+
+ public Object execute(final String line) throws Exception {
+ assert line != null;
+
+ log.info("Executing (String): {}", line);
+
+ try {
+ CommandLine cl = commandLineBuilder.create(line);
+
+ return cl.execute();
+ }
+ catch (ErrorNotification n) {
+ // Decode the error notifiation
+ Throwable cause = n.getCause();
+
+ if (cause instanceof Exception) {
+ throw (Exception)cause;
+ }
+ else if (cause instanceof Error) {
+ throw (Error)cause;
+ }
+ else {
+ // Um, if we get this far, which we probably never will, then just re-toss the notifcation
+ throw n;
+ }
+ }
+ }
+
+ public Object execute(final Object... args) throws Exception {
+ assert args != null;
+ assert args.length > 1;
+
+ log.info("Executing (Object...): [{}]", Arguments.asString(args));
+
+ return execute(String.valueOf(args[0]), Arguments.shift(args), io);
+ }
+
+ public Object execute(final String path, final Object[] args) throws Exception {
+ assert path != null;
+ assert args != null;
+
+ log.info("Executing ({}): [{}]", path, Arguments.asString(args));
+
+ return execute(path, args, io);
+ }
+
+ public Object execute(final Object[][] commands) throws Exception {
+ assert commands != null;
+
+ // Prepare IOs
+ final IO[] ios = new IO[commands.length];
+ PipedOutputStream pos = null;
+
+ for (int i = 0; i < ios.length; i++) {
+ InputStream is = (i == 0) ? io.inputStream : new PipedInputStream(pos);
+ OutputStream os;
+
+ if (i == ios.length - 1) {
+ os = io.outputStream;
+ }
+ else {
+ os = pos = new PipedOutputStream();
+ }
+
+ ios[i] = new IO(is, new PrintStream(os), io.errorStream);
+ }
+
+ Thread[] threads = new Thread[commands.length];
+ final List<Throwable> errors = new CopyOnWriteArrayList<Throwable>();
+ final AtomicReference<Object> ref = new AtomicReference<Object>();
+
+ for (int i = 0; i < commands.length; i++) {
+ final int idx = i;
+
+ threads[i] = createThread(new Runnable() {
+ public void run() {
+ try {
+ Object o = execute(String.valueOf(commands[idx][0]), Arguments.shift(commands[idx]), ios[idx]);
+
+ if (idx == commands.length - 1) {
+ ref.set(o);
+ }
+ }
+ catch (Throwable t) {
+ errors.add(t);
+ }
+ finally {
+ if (idx > 0) {
+ IOUtil.close(ios[idx].inputStream);
+ }
+ if (idx < commands.length - 1) {
+ IOUtil.close(ios[idx].outputStream);
+ }
+ }
+ }
+ });
+
+ threads[i].start();
+ }
+
+ for (int i = 0; i < commands.length; i++) {
+ threads[i].join();
+ }
+
+ if (!errors.isEmpty()) {
+ Throwable t = errors.get(0);
+
+ // Always preserve the type of notication throwables, reguardless of the trace
+ if (t instanceof Notification) {
+ throw (Notification)t;
+ }
+
+ // Otherwise wrap to preserve the trace
+ throw new CommandLineExecutionFailied(t);
+ }
+
+ return ref.get();
+ }
+
+ protected Thread createThread(Runnable run) {
+ return new Thread(run);
+ }
+
+ //
+ // TODO: Let the CommandContext creation happen in the child, pass in the ShellContext here...
+ //
+
+ protected Object execute(final String path, final Object[] args, final IO io) throws Exception {
+ log.debug("Executing");
+
+ final Command command = commandResolver.resolve(variables, path);
+
+ // Setup the command context and pass it to the command instance
+ CommandContext context = new CommandContext()
+ {
+ // Command instances get their own namespace with defaults from the current
+ final Variables vars = new Variables(variables);
+
+ public Object[] getArguments() {
+ return args;
+ }
+
+ public IO getIo() {
+ return io;
+ }
+
+ public Variables getVariables() {
+ return vars;
+ }
+
+ public CommandInfo getInfo() {
+ return command.getInfo();
+ }
+ };
+
+ // Setup command timings
+ StopWatch watch = new StopWatch(true);
+
+ // Hijack the system streams in the current thread's context
+ SystemOutputHijacker.register(io.outputStream, io.errorStream);
+
+ CommandResult result;
+ try {
+ result = command.execute(context);
+
+ log.debug("Command completed with result: {}, after: {}", result, watch);
+ }
+ finally {
+ // Restore hijacked streams
+ SystemOutputHijacker.deregister();
+
+ // Make sure that the commands output has been flushed
+ try {
+ io.flush();
+ }
+ catch (Exception ignore) {}
+ }
+
+ // Decode the command result
+ if (result.hasNotified()) {
+ throw result.getNotification();
+ }
+ else if (result.hasFailed()) {
+ throw result.getFailure();
+ }
+ else {
+ return result.getValue();
+ }
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/CommandLineExecutorImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/HistoryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/HistoryImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/HistoryImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/HistoryImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.shell;
+
+import jline.History;
+
+/**
+ * Default implementation of the {@link jline.History} component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class HistoryImpl
+ // FIXME: extends FileHistory
+{
+ // Empty
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/HistoryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/HistoryImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/HistoryImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/LayoutManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/LayoutManagerImpl.java?rev=681611&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/LayoutManagerImpl.java (added)
+++ geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/LayoutManagerImpl.java Thu Jul 31 23:37:02 2008
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.wisdom.shell;
+
+import org.apache.geronimo.gshell.application.ApplicationManager;
+import org.apache.geronimo.gshell.layout.LayoutManager;
+import org.apache.geronimo.gshell.layout.NotFoundException;
+import org.apache.geronimo.gshell.model.layout.GroupNode;
+import org.apache.geronimo.gshell.model.layout.Layout;
+import org.apache.geronimo.gshell.model.layout.Node;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The default implementation of the {@link LayoutManager} component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class LayoutManagerImpl
+ implements LayoutManager
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private ApplicationManager applicationManager;
+
+ private Layout layout;
+
+ public LayoutManagerImpl() {}
+
+ public LayoutManagerImpl(final ApplicationManager applicationManager) {
+ assert applicationManager != null;
+
+ this.applicationManager = applicationManager;
+ }
+
+ private Layout lookupLayout() {
+ assert applicationManager != null;
+
+ Layout layout = applicationManager.getContext().getApplication().getLayout();
+
+ if (layout == null) {
+ throw new IllegalStateException("Layout has not been configured for application");
+ }
+
+ return layout;
+ }
+
+ public Layout getLayout() {
+ if (layout == null) {
+ layout = lookupLayout();
+
+ log.debug("Using layout: {}", layout);
+ }
+
+ return layout;
+ }
+
+ public Node findNode(final String path) throws NotFoundException {
+ return findNode(path, null);
+ }
+
+ public Node findNode(final String path, final String searchPath) throws NotFoundException {
+ assert path != null;
+
+ // Make sure we have initialized the layout
+ getLayout();
+
+ Node start;
+
+ if (path.startsWith(FILE_SEPARATOR)) {
+ start = layout;
+ return findNode(start, path);
+ }
+ else if (searchPath != null) {
+ String[] pathList = searchPath.split(SEARCH_PATH_SEPARATOR);
+ Node foundNode = null;
+
+ for (String commandPath : pathList) {
+ try {
+ Node pathNode = findNode(commandPath);
+ foundNode = findNode(pathNode, path);
+
+ if (foundNode != null) {
+ break;
+ }
+ }
+ catch (NotFoundException e) {
+ // Ignore this for now. We might still have paths to check
+ }
+ }
+
+ if (foundNode == null) {
+ foundNode = findNode(layout, path);
+ }
+
+ return foundNode;
+ }
+ else {
+ assert applicationManager != null;
+
+ start = (Node) applicationManager.getContext().getVariables().get(CURRENT_NODE);
+
+ if (start == null) {
+ start = layout;
+ }
+
+ return findNode(start, path);
+ }
+ }
+
+ public Node findNode(final Node start, final String path) throws NotFoundException {
+ assert start != null;
+ assert path != null;
+
+ Node current = start;
+
+ String[] elements = path.split(FILE_SEPARATOR);
+
+ for (String element : elements) {
+ if (current instanceof GroupNode) {
+ Node node = ((GroupNode)current).find(element);
+
+ if (node == null) {
+ throw new NotFoundException(path);
+ }
+
+ current = node;
+ }
+ else {
+ throw new NotFoundException(path);
+ }
+ }
+
+ return current;
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/LayoutManagerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/LayoutManagerImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/src/main/java/org/apache/geronimo/gshell/wisdom/shell/LayoutManagerImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain