Skip to content

Commit

Permalink
FORGE-1014: Webapp folder is no longer hard-coded
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jul 15, 2013
1 parent 015c6a0 commit e3d9df1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.maven.facets;

import java.io.File;

import org.jboss.forge.maven.resources.MavenPomResource;
import org.jboss.forge.project.Project;
import org.jboss.forge.project.packaging.PackagingType;
import org.jboss.forge.resources.DirectoryResource;
import org.jboss.forge.test.AbstractShellTest;
import org.junit.Assert;
import org.junit.Test;

public class MavenWebResourceFacetTest extends AbstractShellTest
{
@Test
public void testDefaultWebappFolder() throws Exception
{
Project project = initializeProject(PackagingType.WAR);
MavenWebResourceFacet facet = project.getFacet(MavenWebResourceFacet.class);
DirectoryResource expected = project.getProjectRoot().getChildDirectory(
"src" + File.separator + "main" + File.separator + "webapp");
Assert.assertEquals(expected.getFullyQualifiedName(), facet.getWebRootDirectory().getFullyQualifiedName());
}

@Test
public void testCustomWebappFolder() throws Exception
{
Project project = initializeProject(PackagingType.WAR);

MavenPomResource pom = project.getProjectRoot().getChild("pom.xml").reify(MavenPomResource.class);

pom.setContents("<project><modelVersion>4.0.0.</modelVersion><groupId>com.test</groupId><artifactId>testme</artifactId><version>1.0</version><build><plugins><plugin><artifactId>maven-war-plugin</artifactId><version>2.4</version><configuration><warSourceDirectory>WebContent</warSourceDirectory><failOnMissingWebXml>false</failOnMissingWebXml></configuration></plugin></plugins></build></project>");

MavenWebResourceFacet facet = project.getFacet(MavenWebResourceFacet.class);
DirectoryResource expected = project.getProjectRoot().getChildDirectory(
"WebContent");
Assert.assertEquals(expected.getFullyQualifiedName(), facet.getWebRootDirectory().getFullyQualifiedName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

import org.jboss.forge.maven.MavenCoreFacet;
import org.jboss.forge.maven.MavenPluginFacet;
import org.jboss.forge.maven.plugins.Configuration;
import org.jboss.forge.maven.plugins.ConfigurationElementBuilder;
import org.jboss.forge.maven.plugins.MavenPlugin;
import org.jboss.forge.maven.plugins.MavenPluginBuilder;
import org.jboss.forge.project.Facet;
import org.jboss.forge.project.Project;
import org.jboss.forge.project.dependencies.Dependency;
import org.jboss.forge.project.dependencies.DependencyBuilder;
import org.jboss.forge.project.facets.BaseFacet;
import org.jboss.forge.project.facets.JavaSourceFacet;
Expand All @@ -45,7 +47,28 @@ public class MavenWebResourceFacet extends BaseFacet implements WebResourceFacet
@Override
public DirectoryResource getWebRootDirectory()
{
return project.getProjectRoot().getChildDirectory("src" + File.separator + "main" + File.separator + "webapp");
MavenPluginFacet mavenPluginFacet = project.getFacet(MavenPluginFacet.class);
final String webappFolderName;
Dependency mvnWarPluginDep = DependencyBuilder.create("org.apache.maven.plugins:maven-war-plugin");
if (mavenPluginFacet.hasPlugin(mvnWarPluginDep))
{
MavenPlugin warPlugin = mavenPluginFacet.getPlugin(mvnWarPluginDep);
Configuration config = warPlugin.getConfig();
if (config.hasConfigurationElement("warSourceDirectory"))
{
webappFolderName = config.getConfigurationElement("warSourceDirectory").getText();
}
else
{
webappFolderName = "src" + File.separator + "main" + File.separator + "webapp";
}
}
else
{
webappFolderName = "src" + File.separator + "main" + File.separator + "webapp";
}
DirectoryResource projectRoot = project.getProjectRoot();
return projectRoot.getChildDirectory(webappFolderName);
}

@Override
Expand Down

0 comments on commit e3d9df1

Please sign in to comment.