Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
SEAMFORGE-201, SEAMFORGE-187, SEAMFORGE-203
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Jun 8, 2011
1 parent 877dbff commit 1b77363
Show file tree
Hide file tree
Showing 19 changed files with 388 additions and 92 deletions.
43 changes: 43 additions & 0 deletions dev-plugins/src/main/java/org/jboss/forge/dev/mvn/MavenPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,49 @@ public MavenPlugin(final Shell shell, final Project project, final ProjectFactor
this.resources = resources;
}

@Command("set-groupid")
public void setGroupId(final PipeOut out,
@Option(description = "the new groupId; for example: \"org.jboss.forge\"") final String groupId)
{
Assert.notNull(groupId, "GroupId must not be empty");

MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);

Model pom = mvn.getPOM();
pom.setGroupId(groupId);
mvn.setPOM(pom);
out.println("Set groupId [ " + groupId + " ]");
}

@Command("set-artifactid")
public void setArtifactId(final PipeOut out,
@Option(description = "the new artifactId; for example: \"forge-shell\"") final String artifactId)
{
Assert.notNull(artifactId, "GroupId must not be empty");

MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);

Model pom = mvn.getPOM();
pom.setArtifactId(artifactId);
mvn.setPOM(pom);
out.println("Set artifactId [ " + artifactId + " ]");
}

@Command("set-version")
public void setVersion(final PipeOut out,
@Option(description = "the new version; for example: \"1.0.0.Final\"") final String version)
{
Assert.notNull(version, "GroupId must not be empty");

MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);

Model pom = mvn.getPOM();
pom.setVersion(version);
mvn.setPOM(pom);

out.println("Set version [ " + version + " ]");
}

@Command("set-parent")
public void setParent(
@Option(name = "parentId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ public interface MavenCoreFacet extends Facet
/**
* Execute a command using the native Maven installation. If native Maven is not available, fall back to the embedded
* Maven provider built in to Forge.
*
* @return
*/
public void executeMaven(ShellPrintWriter out, String[] parameters);
public boolean executeMaven(ShellPrintWriter out, String[] parameters);

/**
* Execute a command using the native Maven installation. If native Maven is not available, fall back to the embedded
* Maven provider built in to Forge.
*/
public boolean executeMaven(String[] selected);

}
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,21 @@ public boolean executeMavenEmbedded(final PrintStream out, final PrintStream err
}

@Override
public void executeMaven(final ShellPrintWriter out, final String[] parms)
public boolean executeMaven(final String[] selected)
{
return executeMaven(null, selected);
}

@Override
public boolean executeMaven(final ShellPrintWriter out, final String[] parms)
{
try
{
NativeSystemCall.execFromPath(getMvnCommand(), parms, out, project.getProjectRoot());
return 0 == NativeSystemCall.execFromPath(getMvnCommand(), parms, out, project.getProjectRoot());
}
catch (IOException e)
{
executeMavenEmbedded(parms);
return executeMavenEmbedded(parms);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.enterprise.event.Event;
import javax.inject.Inject;

import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.jboss.forge.ForgeEnvironment;
import org.jboss.forge.maven.MavenCoreFacet;
Expand Down Expand Up @@ -151,7 +152,7 @@ public Resource<?> executeBuild(final String... args)
selected = list.toArray(new String[list.size()]);
}

boolean success = project.getFacet(MavenCoreFacet.class).executeMavenEmbedded(selected);
boolean success = project.getFacet(MavenCoreFacet.class).executeMaven(selected);

if (success)
{
Expand All @@ -178,6 +179,12 @@ public void setFinalName(final String finalName)
{
MavenCoreFacet mavenFacet = project.getFacet(MavenCoreFacet.class);
Model pom = mavenFacet.getPOM();
Build build = pom.getBuild();
if (build == null)
{
build = new Build();
pom.setBuild(build);
}
pom.getBuild().setFinalName(finalName);
mavenFacet.setPOM(pom);
}
Expand Down
41 changes: 25 additions & 16 deletions shell-api/src/main/java/org/jboss/forge/shell/PromptType.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,41 @@

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public enum PromptType
{
ANY(".*"),
DEPENDENCY_ID("[^:]+:[^:]+:?([^:]+:?){0,3}"),
JAVA_PACKAGE("(?i)(~\\.)?((?!(" + Patterns.JAVA_KEYWORDS + "))[a-z0-9_]+\\.?)+[a-z0-9_]"),
JAVA_VARIABLE_NAME("^(?!(" + Patterns.JAVA_KEYWORDS + ")$)[A-Za-z0-9$_]+$"),
JAVA_CLASS(JAVA_PACKAGE.pattern + "\\.?[a-z0-9$_]"),
FILE_PATH(".*");
ANY(new String[] { ".*" }),
DEPENDENCY_ID(new String[] { "[^:]+:[^:]+:?([^:]+:?){0,3}" }),
JAVA_PACKAGE(
new String[] { "(?i)(~\\.)?([a-z0-9_]+\\.?)+[a-z0-9_]",
"^(?!.*\\b(" + Patterns.JAVA_KEYWORDS + ")\\b.*).*$" }),
JAVA_VARIABLE_NAME(new String[] { "^(?!(" + Patterns.JAVA_KEYWORDS + ")$)[A-Za-z0-9$_]+$" }),
JAVA_CLASS(new String[] { "(?i)(~\\.)?([a-z0-9_]+\\.?)+[a-z0-9_]",
"^(?!.*\\b(" + Patterns.JAVA_KEYWORDS + ")\\b.*).*$" }),
FILE_PATH(new String[] { ".*" });

private final String pattern;
private final String[] patterns;

private PromptType(final String pattern)
private PromptType(final String[] patterns)
{
this.pattern = pattern;
}

public String getPattern()
{
return pattern;
this.patterns = patterns;
}

public boolean matches(final String value)
{
return (value != null) && value.matches(pattern);
if (value == null)
{
return false;
}

for (int i = 0; i < patterns.length; i++)
{
if (!value.matches(patterns[i]))
{
return false;
}
}
return true;
}

}
1 change: 1 addition & 0 deletions shell-api/src/main/java/org/jboss/forge/shell/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,5 @@ public interface Shell extends ShellPrintWriter, ShellPrompt, ShellHistory
* Get the current Forge environment.
*/
ForgeEnvironment getEnvironment();

}
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ public interface ShellPrompt
<T> T prompt(String message, Class<T> clazz, T defaultIfEmpty);

/**
* Prompt for user input, first printing the given line, then returning user input with help from the given
* completer.
* Prompt for user input, first printing the given line, then returning user input with help from the given completer
* type.
*
* @param message The prompt message to display until valid input is entered
* @param completer The command completer instance to use during completion
* @param type The command completer type to instantiate and use during completion
*/
String promptCompleter(String string, CommandCompleter completer);
String promptCompleter(String string, Class<? extends CommandCompleter> type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class NativeSystemCall
* @param parms the command parameters
* @param out a print writer to which command output will be streamed
* @param path the path from which to execute the command
*
* @return 0 on successful completion, any other return code denotes failure
*/
public static int execFromPath(final String command, final String[] parms, final ShellPrintWriter out,
final DirectoryResource path) throws IOException
Expand Down Expand Up @@ -90,7 +92,12 @@ public static int execFromPath(final String command, final String[] parms, final
}
}

public static void exec(boolean wait, String command, final String... parms)
/**
* Execute the given system command
*
* @return 0 on successful completion, any other return code denotes failure
*/
public static void exec(final boolean wait, final String command, final String... parms)
throws IOException
{
String[] commandTokens = parms == null ? new String[1] : new String[parms.length + 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
public interface Patterns
{
/**
* A group of terms that are illegal to use as Java identifiers. For example:
* "(if|package|public...while)" and so on.
* A group of terms that are illegal to use as Java identifiers. For example: "(if|package|public...while)" and so
* on.
*/
public static final String JAVA_KEYWORDS = "abstract|" +
"continue|" + "for|" + "new|" + "switch|" + "assert|" + "default|" +
Expand Down
48 changes: 27 additions & 21 deletions shell-api/src/test/java/org/jboss/forge/shell/PromptTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,37 @@ public class PromptTypeTest
@Test
public void testJavaPackage() throws Exception
{
assertTrue("org".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertFalse("org.".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertTrue("org.jboss".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertFalse("org.jboss.".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertTrue("org.jboss_project".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertFalse("org.jboss_$f00".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertTrue(PromptType.JAVA_PACKAGE.matches("org"));
assertFalse(PromptType.JAVA_PACKAGE.matches("org."));
assertTrue(PromptType.JAVA_PACKAGE.matches("org.jboss.forge"));
assertFalse(PromptType.JAVA_PACKAGE.matches("org.jboss."));
assertTrue(PromptType.JAVA_PACKAGE.matches("org.jboss_project"));
assertFalse(PromptType.JAVA_PACKAGE.matches("org.jboss_$f00"));
}

@Test
public void testJavaClass() throws Exception
{
assertTrue(PromptType.JAVA_CLASS.matches("org.jboss.forge.spec.validation.MockMessageInterpolator"));
}

@Test
public void testJavaPackageCannotContainKeywords() throws Exception
{
assertFalse("org.jboss.package".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertFalse("org.jboss.private".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertFalse("org.public".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertFalse("public".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertFalse("org.synchronized.foo".matches(PromptType.JAVA_PACKAGE.getPattern()));
assertFalse(PromptType.JAVA_PACKAGE.matches("org.jboss.package"));
assertFalse(PromptType.JAVA_PACKAGE.matches("org.jboss.private"));
assertFalse(PromptType.JAVA_PACKAGE.matches("org.public"));
assertFalse(PromptType.JAVA_PACKAGE.matches("public"));
assertFalse(PromptType.JAVA_PACKAGE.matches("org.synchronized.foo"));
}

@Test
public void testJavaVariableName() throws Exception
{
assertTrue("gamesPlayed".matches(PromptType.JAVA_VARIABLE_NAME.getPattern()));
assertFalse("(*#$%".matches(PromptType.JAVA_VARIABLE_NAME.getPattern()));
assertFalse("public".matches(PromptType.JAVA_VARIABLE_NAME.getPattern()));
assertTrue("privateIpAddress".matches(PromptType.JAVA_VARIABLE_NAME.getPattern()));
assertTrue(PromptType.JAVA_VARIABLE_NAME.matches("gamesPlayed"));
assertFalse(PromptType.JAVA_VARIABLE_NAME.matches("(*#$%"));
assertFalse(PromptType.JAVA_VARIABLE_NAME.matches("public"));
assertTrue(PromptType.JAVA_VARIABLE_NAME.matches("privateIpAddress"));
}

@Test
Expand All @@ -77,12 +83,12 @@ public void testPatternsReservedWords() throws Exception
@Test
public void testDependencyId() throws Exception
{
assertFalse("group.id".matches(PromptType.DEPENDENCY_ID.getPattern()));
assertTrue("group.id:artifact.id".matches(PromptType.DEPENDENCY_ID.getPattern()));
assertTrue("group.id:artifact.id:1.0.0".matches(PromptType.DEPENDENCY_ID.getPattern()));
assertTrue("group.id:artifact.id:2.0.0-SNAPSHOT:scope".matches(PromptType.DEPENDENCY_ID.getPattern()));
assertTrue("group.id:artifact.id:3.0.Final:scope:packaging".matches(PromptType.DEPENDENCY_ID.getPattern()));
assertFalse("group.id:artifact.id:3.0.Final:scope:packaging:extra".matches(PromptType.DEPENDENCY_ID.getPattern()));
assertFalse(PromptType.DEPENDENCY_ID.matches("group.id"));
assertTrue(PromptType.DEPENDENCY_ID.matches("group.id:artifact.id"));
assertTrue(PromptType.DEPENDENCY_ID.matches("group.id:artifact.id:1.0.0"));
assertTrue(PromptType.DEPENDENCY_ID.matches("group.id:artifact.id:2.0.0-SNAPSHOT:scope"));
assertTrue(PromptType.DEPENDENCY_ID.matches("group.id:artifact.id:3.0.Final:scope:packaging"));
assertFalse(PromptType.DEPENDENCY_ID.matches("group.id:artifact.id:3.0.Final:scope:packaging:extra"));
}

}
Loading

0 comments on commit 1b77363

Please sign in to comment.