Skip to content

Commit

Permalink
Merge pull request #308 from rogergl/master
Browse files Browse the repository at this point in the history
Added set-name to MavenPlugin
  • Loading branch information
lincolnthree committed Apr 18, 2013
2 parents 65ab194 + 1d79436 commit ef4def0
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
16 changes: 16 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 @@ -106,6 +106,22 @@ public void setVersion(final PipeOut out,
out.println("Set version [ " + version + " ]");
}


@Command("set-name")
public void setName(final PipeOut out,
@Option(description = "the new name; for example: \"UI-Layer\"") final String name)
{
Assert.notNull(name, "Name must not be empty");

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

Model pom = mvn.getPOM();
pom.setName(name);
mvn.setPOM(pom);

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

@Command("set-parent")
public void setParent(
@Option(name = "parentId",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.jboss.forge.dev.mvn;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

import org.apache.maven.model.Model;
import org.jboss.forge.maven.MavenCoreFacet;
import org.jboss.forge.test.AbstractShellTest;
import org.junit.Before;
import org.junit.Test;

public class SetCommandsMavenPluginTest extends AbstractShellTest
{
@Before
public void copyFileForIDE() throws Exception
{
copyFile("maven-update/pom.xml");
getShell().execute("cd target/test-classes/maven-update");
}

@SuppressWarnings("resource")
private void copyFile(String fileName) throws IOException, FileNotFoundException
{
File source = new File("src/test/resources/", fileName);
File target = new File("target/test-classes/", fileName);

if (!target.exists())
{
target.getParentFile().mkdirs();
target.createNewFile();
}

FileChannel input = new FileInputStream(source).getChannel();
FileChannel output = new FileOutputStream(target).getChannel();

output.transferFrom(input, 0, input.size());

input.close();
output.close();
}

@Test
public void testShouldSetGroupId() throws Exception
{
getShell().execute("maven set-groupid \"groupId\"");

String pom = getOutput();
assertTrue(pom.contains("Set groupId [ groupId ]"));
assertTrue(getModel().getGroupId().equals("groupId"));
}

@Test
public void testShouldSetArtifactId() throws Exception
{
getShell().execute("maven set-artifactid \"artifactId\"");

String pom = getOutput();
assertTrue(pom.contains("Set artifactId [ artifactId ]"));
assertTrue(getModel().getArtifactId().equals("artifactId"));
}

@Test
public void testShouldSetVersion() throws Exception
{
getShell().execute("maven set-version \"1.0.0.Final\"");

String pom = getOutput();
assertTrue(pom.contains("Set version [ 1.0.0.Final ]"));
assertTrue(getModel().getVersion().equals("1.0.0.Final"));
}

@Test
public void testShouldSetName() throws Exception
{
getShell().execute("maven set-name \"BIZ-Layer\"");

String pom = getOutput();
assertTrue(pom.contains("Set name [ BIZ-Layer ]"));
assertTrue(getModel().getName().equals("BIZ-Layer"));
}

private Model getModel()
{
MavenCoreFacet mvn = getProject().getFacet(MavenCoreFacet.class);
return mvn.getPOM();
}

}

0 comments on commit ef4def0

Please sign in to comment.