Skip to content

Commit

Permalink
Merged from master
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Jul 21, 2011
2 parents d097c8d + c37a15d commit d14ba0d
Show file tree
Hide file tree
Showing 24 changed files with 1,211 additions and 355 deletions.
Expand Up @@ -21,8 +21,7 @@
*/
package org.jboss.forge.dev;

import java.io.File;
import java.io.IOException;
import java.io.*;
import java.util.Map;

import javax.enterprise.context.ApplicationScoped;
Expand All @@ -33,18 +32,15 @@
import org.jboss.forge.project.services.ResourceFactory;
import org.jboss.forge.resources.DirectoryResource;
import org.jboss.forge.resources.FileResource;
import org.jboss.forge.resources.Resource;
import org.jboss.forge.shell.Shell;
import org.jboss.forge.shell.ShellMessages;
import org.jboss.forge.shell.ShellPrompt;
import org.jboss.forge.shell.plugins.Alias;
import org.jboss.forge.shell.plugins.Command;
import org.jboss.forge.shell.plugins.PipeOut;
import org.jboss.forge.shell.plugins.Plugin;
import org.jboss.forge.shell.plugins.*;
import org.jboss.forge.shell.util.OSUtils;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
@Alias("as7")
@ApplicationScoped
Expand Down Expand Up @@ -80,30 +76,95 @@ public void deploy(final PipeOut out)
FileResource<?> deployedArtifact = getDeployedArtifact();

if (!deployedArtifact.exists()
|| prompt.promptBoolean("Overwrite existing deployment? [" + deployedArtifact.getFullyQualifiedName()
+ "]"))
|| prompt.promptBoolean("Overwrite existing deployment? [" + deployedArtifact.getFullyQualifiedName()
+ "]"))
{
deployedArtifact.setContents(finalArtifact.getResourceInputStream());
shell.execute("rm -rf " + deployedArtifact.getFullyQualifiedName() + ".*");
ShellMessages.success(out, "Deployed [" + finalArtifact + "] to ["
+ getDeploymentDirectory().getFullyQualifiedName() + "]");
+ getDeploymentDirectory().getFullyQualifiedName() + "]");
}
}

@Command
public void deployExploded(@Option(name = "triggerDeploy", flagOnly = true) boolean triggerDeploy,
@Option(name = "build", flagOnly = true) boolean build,
final PipeOut out) throws Exception
{
if(build) {
shell.execute("mvn compile war:exploded");
}

FileResource<?> finalArtifact = getExploded();

String artifactName = finalArtifact.getName() + ".war";
DirectoryResource deployDir = getDeploymentDirectory().getOrCreateChildDirectory(artifactName);
copyDirectory(finalArtifact.getUnderlyingResourceObject(), deployDir.getUnderlyingResourceObject());

if(triggerDeploy) {

FileResource<?> deployFile = (FileResource<?>)getDeploymentDirectory().getChild(artifactName + ".dodeploy");

deployFile.createNewFile();
}

if(triggerDeploy) {
String deployMessage = "[" + finalArtifact + "] to ["
+ getDeploymentDirectory().getFullyQualifiedName() + "]";
ShellMessages.success(out, "Deployed " + deployMessage);
} else {
ShellMessages.success(out, "Copied [" + finalArtifact + "] to ["
+ getDeploymentDirectory().getFullyQualifiedName() + ".war]. Use --triggerDeploy to redeploy the application");
}
}

private void copyDirectory(File sourceLocation, File targetLocation) throws IOException
{
if (sourceLocation.isDirectory())
{
if (!targetLocation.exists())
{
targetLocation.mkdir();
}

String[] children = sourceLocation.list();
for (int i = 0; i < children.length; i++)
{
copyDirectory(new File(sourceLocation, children[i]),
new File(targetLocation, children[i]));
}
} else
{

InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocation);

byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
in.close();
out.close();
}
}


@Command
public void undeploy(final PipeOut out)
{
FileResource<?> finalArtifact = getFinalArtifact();
FileResource<?> deployedArtifact = getDeployedArtifact();

if (deployedArtifact.exists()
&& prompt.promptBoolean("Really undeploy [" + deployedArtifact.getFullyQualifiedName()
+ "]?"))
&& prompt.promptBoolean("Really undeploy [" + deployedArtifact.getFullyQualifiedName()
+ "]?"))
{
deployedArtifact.setContents(finalArtifact.getResourceInputStream());
shell.execute("rm -rf " + deployedArtifact.getFullyQualifiedName() + "*");
ShellMessages.success(out, "Removed deployment [" + finalArtifact + "] from ["
+ getDeploymentDirectory().getFullyQualifiedName() + "]");
+ getDeploymentDirectory().getFullyQualifiedName() + "]");
}
}

Expand Down Expand Up @@ -142,6 +203,12 @@ public FileResource<?> getFinalArtifact()
return finalArtifact;
}

public DirectoryResource getExploded()
{
PackagingFacet packaging = project.getFacet(PackagingFacet.class);
return project.getProjectRoot().getChildDirectory("target").getChildDirectory(packaging.getFinalName());
}

public FileResource<?> getDeployedArtifact()
{
DirectoryResource deployDir = getDeploymentDirectory();
Expand Down
12 changes: 11 additions & 1 deletion pom.xml
Expand Up @@ -64,7 +64,7 @@
<groovy.version>1.7.5</groovy.version>
<jboss.javaee.version>1.0.0.Final</jboss.javaee.version>
<jboss.logging.version>3.0.0.Beta4</jboss.logging.version>
<jboss.modules.version>1.0.0.GA</jboss.modules.version>
<jboss.modules.version>1.0.1.GA</jboss.modules.version>
<junit.version>4.8.1</junit.version>
<log4j.version>1.2.16</log4j.version>
<shrinkwrap.version>1.0.0-alpha-11</shrinkwrap.version>
Expand Down Expand Up @@ -99,6 +99,11 @@
<type>pom</type>
</dependency>

<dependency>
<groupId>org.jboss.forge</groupId>
<artifactId>forge-distribution</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.forge</groupId>
<artifactId>forge-event-bus</artifactId>
Expand Down Expand Up @@ -185,6 +190,11 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.jboss.modules</groupId>
<artifactId>jboss-modules</artifactId>
<version>${jboss.modules.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions shell-api/src/main/java/org/jboss/forge/shell/Shell.java
Expand Up @@ -192,6 +192,15 @@ public interface Shell extends ShellPrintWriter, ShellPrompt, ShellHistory
*/
String readLine() throws IOException;

/**
* Ask the current {@link InputStream} for input, masking keystrokes in the console with the given mask.
*
* @param mask The character to use for masking input
* @return any read data as a string, or null if none available.
* @throws IOException on error
*/
String readLine(Character mask) throws IOException;

/**
* Controls the shell's usage of ANSI escape code support. This method does not guarantee ANSI will function
* properly, as the underlying Terminal must also support it.
Expand Down
Expand Up @@ -214,4 +214,10 @@ public interface ShellPrompt
* @param type The command completer type to instantiate and use during completion
*/
String promptCompleter(String string, Class<? extends CommandCompleter> type);

/**
* First print the given message, prompt the user for input (masking keystrokes for secrecy,) then return user input.
*/
String promptSecret(String message);

}
@@ -0,0 +1,124 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.forge.shell.command;

import java.lang.reflect.Method;
import java.util.List;
import java.util.Set;

import org.jboss.forge.resources.Resource;

/**
* Defines a command.
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public interface CommandMetadata
{
/**
* Get the help text for this comand.
*/
String getHelp();

/**
* Get the {@link Method} that implements this command.
*/
Method getMethod();

/**
* Get the name of this command.
*/
String getName();

/**
* Get the option defined by the given name.
*
* @throws IllegalArgumentException if no such option exists.
*/
OptionMetadata getNamedOption(String name) throws IllegalArgumentException;

/**
* Return the number of ordered (unnamed) options defined by this command.
*/
int getNumOrderedOptions();

/**
* Return the option at the given index in the plugin method signature, not the index of the option on the command
* line.
*/
OptionMetadata getOptionByAbsoluteIndex(int index);

/**
* Return a list of all options defined by this command.
*/
List<OptionMetadata> getOptions();

/**
* Return the option at the given index as required on the command line, not the index of the option in the
* implementing method signature.
*/
OptionMetadata getOrderedOptionByIndex(int index) throws IllegalArgumentException;

/**
* Return the {@link PluginMetadata} containing this command.
*/
PluginMetadata getParent();

/**
* Return the set of {@link Resource} types for which this command is in scope, or available.
*/
@SuppressWarnings("rawtypes")
Set<Class<? extends Resource>> getResourceScopes();

/**
* Return true if this command has an {@link OptionMetadata} with the given name.
*/
boolean hasOption(String name);

/**
* Return true if this command has any options.
*/
boolean hasOptions();

/**
* Return true if this command accepts ordered options.
*/
boolean hasOrderedOptions();

/**
* Return true if this command accepts options that declare a short name.
*/
boolean hasShortOption(String name);

/**
* Return true if this command is the default command for its declaring {@link PluginMetadata}
*/
boolean isDefault();

/**
* Return true if this command is usable with the given resource scope.
*/
@SuppressWarnings("rawtypes")
boolean usableWithResource(Class<? extends Resource> class1);

}

0 comments on commit d14ba0d

Please sign in to comment.