You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2008/04/03 03:44:14 UTC
svn commit: r644133 - in /portals/jetspeed-2/portal/trunk:
applications/jetspeed-demo/pom.xml
maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java
Author: ate
Date: Wed Apr 2 18:44:13 2008
New Revision: 644133
URL: http://svn.apache.org/viewvc?rev=644133&view=rev
Log:
Much improved and refactored deploy plugin and example usage for the jetspeed-demo application.
After proper database initialization and seeding, which still must be done using Jetspeed 2.1.3, the demo portal runs quite well,
even while still needing to deploy j2-admin from 2.1.3 (warning: import/export portlet is broken for the moment).
Modified:
portals/jetspeed-2/portal/trunk/applications/jetspeed-demo/pom.xml
portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java
Modified: portals/jetspeed-2/portal/trunk/applications/jetspeed-demo/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed-demo/pom.xml?rev=644133&r1=644132&r2=644133&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/applications/jetspeed-demo/pom.xml (original)
+++ portals/jetspeed-2/portal/trunk/applications/jetspeed-demo/pom.xml Wed Apr 2 18:44:13 2008
@@ -43,9 +43,108 @@
<scope>runtime</scope>
</dependency>
</dependencies>
-
+
+ <properties>
+ <org.apache.jetspeed.server.home>${project.build.directory}/demo-deploy</org.apache.jetspeed.server.home>
+ </properties>
+
<build>
<finalName>jetspeed</finalName>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>jetspeed-deploy-maven-plugin</artifactId>
+ <version>${pom.version}</version>
+ <dependencies>
+ <!-- shared/lib deps -->
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>${pom.artifactId}</artifactId>
+ <version>${pom.version}</version>
+ <type>war</type>
+ </dependency>
+ <dependency>
+ <groupId>portlet-api</groupId>
+ <artifactId>portlet-api</artifactId>
+ <version>${portlet-api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>jetspeed-api</artifactId>
+ <version>${pom.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>jetspeed-commons</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.pluto</groupId>
+ <artifactId>pluto</artifactId>
+ <version>${org.apache.pluto.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.portals.bridges</groupId>
+ <artifactId>portals-bridges-common</artifactId>
+ <version>${org.apache.portals.bridges.common.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${org.apache.jetspeed.test.jdbc.driver.groupId}</groupId>
+ <artifactId>${org.apache.jetspeed.test.jdbc.driver.artifactId}</artifactId>
+ <version>${org.apache.jetspeed.test.jdbc.driver.version}</version>
+ </dependency>
+ <!-- j2-admin -->
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>j2-admin</artifactId>
+ <version>2.1.3</version>
+ <type>war</type>
+ </dependency>
+ <!-- demo pa's -->
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>rss</artifactId>
+ <version>2.1.3</version>
+ <type>war</type>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>demo</artifactId>
+ <version>2.1.3</version>
+ <type>war</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.portals.bridges</groupId>
+ <artifactId>jsf-demo</artifactId>
+ <version>1.0.4</version>
+ <type>war</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.portals.bridges</groupId>
+ <artifactId>jpetstore</artifactId>
+ <version>1.0.4</version>
+ <type>war</type>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>jetspeed-layouts</artifactId>
+ <version>2.1.3</version>
+ <type>war</type>
+ </dependency>
+
+ <!-- plugin own dependencies -->
+ <dependency>
+ <groupId>org.apache.portals.jetspeed-2</groupId>
+ <artifactId>jetspeed-deploy-tools</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
<plugins>
<plugin>
<groupId>${pom.groupId}</groupId>
@@ -74,6 +173,32 @@
</executions>
</plugin>
<plugin>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>jetspeed-deploy-maven-plugin</artifactId>
+ <version>${pom.version}</version>
+ <executions>
+ <execution>
+ <id>deploy-jetspeed-layouts</id>
+ <goals>
+ <goal>deploy</goal>
+ </goals>
+ <phase>process-resources</phase>
+ <configuration>
+ <targetBaseDir>${project.build.directory}/${project.build.finalName}</targetBaseDir>
+ <destinations>
+ <local>WEB-INF/deploy/local</local>
+ </destinations>
+ <deployments>
+ <deployment>
+ <artifact>${pom.groupId}:jetspeed-layouts:war</artifact>
+ <destination>local</destination>
+ </deployment>
+ </deployments>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
@@ -91,7 +216,7 @@
<profiles>
<profile>
- <id>test-portal-deploy</id>
+ <id>demo</id>
<build>
<plugins>
<plugin>
@@ -99,31 +224,65 @@
<artifactId>jetspeed-deploy-maven-plugin</artifactId>
<version>${pom.version}</version>
<configuration>
- <targetDeployDirectory>${project.build.directory}/deploy</targetDeployDirectory>
+ <targetBaseDir>${org.apache.jetspeed.server.home}</targetBaseDir>
+ <portalName>ROOT</portalName>
<deployments>
+ <!-- shared/lib -->
+ <deployment>
+ <artifact>portlet-api:portlet-api:jar</artifact>
+ </deployment>
+ <deployment>
+ <artifact>${pom.groupId}:jetspeed-api:jar</artifact>
+ </deployment>
+ <deployment>
+ <artifact>${pom.groupId}:jetspeed-commons:jar</artifact>
+ </deployment>
+ <deployment>
+ <artifact>org.apache.pluto:pluto:jar</artifact>
+ </deployment>
+ <deployment>
+ <artifact>org.apache.portals.bridges:portals-bridges-common:jar</artifact>
+ </deployment>
+ <deployment>
+ <artifact>
+ ${org.apache.jetspeed.test.jdbc.driver.groupId}:${org.apache.jetspeed.test.jdbc.driver.artifactId}:jar
+ </artifact>
+ <destination>system</destination>
+ </deployment>
+ <!-- jetspeed portal expanded -->
+ <deployment>
+ <artifact>${pom.groupId}:${pom.artifactId}:war</artifact>
+ <expand>true</expand>
+ <targetName>ROOT</targetName>
+ <delete>./ROOT</delete>
+ </deployment>
+ <!-- admin pa -->
+ <deployment>
+ <artifact>${pom.groupId}:j2-admin:war</artifact>
+ <delete>./j2-admin</delete>
+ </deployment>
+ <!-- demo pa's -->
+ <deployment>
+ <artifact>${pom.groupId}:demo:war</artifact>
+ <delete>./demo</delete>
+ </deployment>
+ <deployment>
+ <artifact>${pom.groupId}:rss:war</artifact>
+ <delete>./rss</delete>
+ </deployment>
+ <deployment>
+ <artifact>org.apache.portals.bridges:jpetstore:war</artifact>
+ <infuse>true</infuse>
+ <delete>./jpetstore</delete>
+ </deployment>
<deployment>
<artifact>org.apache.portals.bridges:jsf-demo:war</artifact>
- <type>war</type>
<infuse>true</infuse>
- <expand>false</expand>
- <target>jsf-demo.war</target>
+ <expand>true</expand>
<delete>./jsf-demo</delete>
</deployment>
</deployments>
</configuration>
- <dependencies>
- <dependency>
- <groupId>org.apache.portals.bridges</groupId>
- <artifactId>jsf-demo</artifactId>
- <type>war</type>
- <version>1.0.4</version>
- </dependency>
- <dependency>
- <groupId>org.apache.portals.jetspeed-2</groupId>
- <artifactId>jetspeed-deploy-tools</artifactId>
- <version>${pom.version}</version>
- </dependency>
- </dependencies>
</plugin>
</plugins>
</build>
Modified: portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java?rev=644133&r1=644132&r2=644133&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java (original)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java Wed Apr 2 18:44:13 2008
@@ -32,12 +32,14 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.StringTokenizer;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.apache.jetspeed.maven.utils.Artifacts;
import org.apache.jetspeed.tools.deploy.DeployFactory;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -57,45 +59,48 @@
{
private String artifact;
private String file;
- private String type;
- private String target;
+ private String destination;
+ private String targetName;
+ private Boolean stripVersionId;
private String delete;
- private boolean expand;
- private boolean infuse;
- private Boolean stripLoggers;
- private String forcedVersion;
+ private Boolean expand;
+ private boolean expandKeepExt;
+ private Boolean infuse;
+ private Boolean infusionStripLoggers;
+ private String infusionForcedVersion;
}
private static class DeploymentObject
{
- Deployment deployment;
- String name;
- File fileHandle;
- Artifact artifact;
+ private String type;
+ private Deployment deployment;
+ private File src;
+ private File targetDir;
+ private Artifact artifact;
}
/**
- * The target deploy directory.
+ * The target base directory.
* @parameter
* @required
*/
- private String targetDeployDirectory;
+ private String targetBaseDir;
/**
- * @parameter expression="false";
+ * The name of the portal web application
+ * @parameter expression="jetspeed"
*/
- private boolean infusionStripLoggers;
+ private String portalName;
/**
- * @parameter expression="2.3";
+ * @parameter expression="false";
*/
- private String infusionForcedVersion;
+ private Boolean infusionStripLoggers;
/**
- * When true, INFO log copied/skipped resources
- * @parameter default-value="false"
+ * @parameter expression="2.3"
*/
- private boolean verbose;
+ private String infusionForcedVersion;
/**
* @parameter
@@ -103,8 +108,6 @@
*/
private Deployment[] deployments;
- private List objects = new ArrayList();
-
/** The Maven project.
* @parameter expression="${project}"
* @required
@@ -113,12 +116,20 @@
private MavenProject project;
/**
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ protected ArtifactRepository localRepository;
+
+ /**
* @parameter
*/
- private Map paths;
+ private Map destinations;
/** @parameter expression="${plugin.introducedDependencyArtifacts}" */
private Set pluginDependencyArtifacts;
+
private Artifacts artifacts;
/* (non-Javadoc)
@@ -126,31 +137,47 @@
*/
public void execute() throws MojoExecutionException, MojoFailureException
{
- File targetBaseDir = new File(targetDeployDirectory);
- if (targetBaseDir.exists() && targetBaseDir.isFile())
+ HashMap destMap = new HashMap();
+ if (destinations != null)
+ {
+ destMap.putAll(destinations);
+ }
+ // init default for tomcat5.5
+ if (!destMap.containsKey("system"))
{
- throw new MojoExecutionException("targetBaseDirectory "+targetDeployDirectory+" points to a file, not a directory");
+ destMap.put("system","common/endorsed");
}
- else if (!targetBaseDir.exists())
+ if (!destMap.containsKey("lib"))
{
- targetBaseDir.mkdirs();
+ destMap.put("lib","shared/lib");
+ }
+ if (!destMap.containsKey("war"))
+ {
+ destMap.put("war", "webapps");
+ }
+ if (!destMap.containsKey("deploy"))
+ {
+ destMap.put("deploy", ((String)destMap.get("war"))+"/"+portalName+"/WEB-INF/deploy");
+ }
+ if (!destMap.containsKey("local"))
+ {
+ destMap.put("local", ((String)destMap.get("deploy"))+"/local");
}
- artifacts = new Artifacts(pluginDependencyArtifacts);
-
- HashMap pathsMap = new HashMap();
- // init default for tomcat5.5
- pathsMap.put("lib","shared/lib");
- pathsMap.put("war", "webapps");
- pathsMap.put("portal", "jetspeed");
- pathsMap.put("deploy", "WEB-INF/deploy");
- pathsMap.put("local", "WEB-INF/deploy/local");
- if (paths != null)
+ File targetBaseDir = new File(this.targetBaseDir);
+ if (targetBaseDir.exists() && targetBaseDir.isFile())
{
- pathsMap.putAll(paths);
+ throw new MojoExecutionException("targetBaseDir "+this.targetBaseDir+" points to a file, not a directory");
}
+ File portalDeployDir = new File(targetBaseDir,(String)destMap.get("deploy"));
+ File localPortalDeployDir = new File(targetBaseDir, (String)destMap.get("local"));
+
+ artifacts = new Artifacts(pluginDependencyArtifacts);
boolean infusion = false;
+
+ List objects = new ArrayList();
+
for (int i = 0; i < deployments.length; i++)
{
DeploymentObject dobj = new DeploymentObject();
@@ -162,32 +189,112 @@
{
throw new MojoExecutionException("Artifact "+dobj.deployment.artifact+" dependency not defined");
}
- dobj.fileHandle = dobj.artifact.getFile();
- dobj.name = dobj.deployment.artifact;
+ dobj.src = dobj.artifact.getFile();
+ if (dobj.src == null)
+ {
+ String location = localRepository.pathOf(dobj.artifact);
+ if (location == null)
+ {
+ throw new MojoExecutionException("Artifact "+dobj.deployment.artifact+" could not be found in local repository");
+ }
+ dobj.src = new File(localRepository.getBasedir(), location);
+ }
+ dobj.type = dobj.artifact.getType();
}
else if (dobj.deployment.file != null)
{
- dobj.fileHandle = new File(dobj.deployment.file);
- if (!dobj.fileHandle.exists() || !dobj.fileHandle.isFile())
+ dobj.src = new File(dobj.deployment.file);
+ if (!dobj.src.exists() || !dobj.src.isFile())
{
throw new MojoExecutionException("Deployment file "+dobj.deployment.file+" not found");
}
- dobj.name = dobj.deployment.file;
+ int index = dobj.deployment.file.lastIndexOf(".");
+ if (index > -1 && index < dobj.deployment.file.length()-1)
+ {
+ dobj.type = dobj.deployment.file.substring(index+1);
+ }
+ }
+ else
+ {
+ throw new MojoExecutionException("A deployment requires an artifact of file specification");
+ }
+
+ if ("war".equals(dobj.type))
+ {
+ dobj.deployment.destination = getValue(dobj.deployment.destination,"war");
+ if ("war".equals(dobj.deployment.destination))
+ {
+ dobj.deployment.expand = getValue(dobj.deployment.expand, Boolean.FALSE);
+ dobj.deployment.infuse = getValue(dobj.deployment.infuse, Boolean.FALSE);
+ dobj.deployment.infusionStripLoggers = getValue(dobj.deployment.infusionStripLoggers, infusionStripLoggers);
+ dobj.deployment.infusionForcedVersion = getValue(dobj.deployment.infusionForcedVersion, infusionForcedVersion);
+ }
+ else
+ {
+ dobj.deployment.expand = Boolean.FALSE;
+ dobj.deployment.infuse = Boolean.FALSE;
+ }
+ }
+ else
+ {
+ dobj.deployment.destination = getValue(dobj.deployment.destination, "jar".equals(dobj.type) ? "lib" : null);
+ dobj.deployment.expand = Boolean.FALSE;
+ dobj.deployment.infuse = Boolean.FALSE;
}
- if (pathsMap.get(dobj.deployment.type) == null)
+ if (destMap.get(dobj.deployment.destination) == null)
{
- throw new MojoExecutionException("Deployment "+dobj.name+" has unknown type "+dobj.deployment.type);
+ throw new MojoExecutionException("Unknown or unspecified deployment destination: \""+dobj.deployment.destination+"\"");
}
- if ("war".equals(dobj.deployment.type))
+
+ if (dobj.deployment.infuse.booleanValue())
{
- if (dobj.deployment.infuse)
+ infusion = true;
+ }
+ boolean portalDeploy = "deploy".equals(dobj.deployment.destination);
+ boolean localPortalDeploy = "local".equals(dobj.deployment.destination);
+
+ if (dobj.deployment.targetName == null)
+ {
+ if (dobj.artifact != null)
+ {
+ Boolean defaultStripVersionId = "war".equals(dobj.type) || "war".equals(dobj.deployment.destination) || portalDeploy || localPortalDeploy ? Boolean.TRUE : Boolean.FALSE;
+ if (getValue(dobj.deployment.stripVersionId, defaultStripVersionId).booleanValue())
+ {
+ dobj.deployment.targetName = dobj.artifact.getArtifactId() + "." + dobj.artifact.getType();
+ }
+ else
+ {
+ dobj.deployment.targetName = dobj.artifact.getArtifactId() + "-"+ dobj.artifact.getVersion() + "." + dobj.artifact.getType();
+ }
+ }
+ else
{
- infusion = true;
- dobj.deployment.stripLoggers = getValue(dobj.deployment.stripLoggers,infusionStripLoggers);
- dobj.deployment.forcedVersion = getValue(dobj.deployment.forcedVersion,infusionForcedVersion);
+ dobj.deployment.targetName = dobj.src.getName();
}
+ if (dobj.deployment.expand.booleanValue() && !dobj.deployment.expandKeepExt)
+ {
+ int index = dobj.deployment.targetName.lastIndexOf(".");
+ if (index > -1)
+ {
+ dobj.deployment.targetName = dobj.deployment.targetName.substring(0, index);
+ }
+ }
+ }
+ if (portalDeploy)
+ {
+ dobj.targetDir = portalDeployDir;
+ }
+ else if (localPortalDeploy)
+ {
+ dobj.targetDir = localPortalDeployDir;
+ }
+ else
+ {
+ dobj.targetDir = new File(targetBaseDir, (String)destMap.get(dobj.deployment.destination));
}
+
objects.add(dobj);
+
}
DeployFactory deployFactory = null;
@@ -207,176 +314,148 @@
}
}
- for (Iterator iter = objects.iterator(); iter.hasNext(); )
+ String deploySelection = System.getProperty("deploy");
+ if (deploySelection != null)
{
- DeploymentObject dobj = (DeploymentObject)iter.next();
- File targetDir;
- if ("deploy".equals(dobj.deployment.type)||"local".equals(dobj.deployment.type))
- {
- targetDir = new File(new File(new File(targetBaseDir,(String)pathsMap.get("war")), (String)pathsMap.get("portal")), (String)pathsMap.get(dobj.deployment.type));
- }
- else
- {
- targetDir = new File(targetBaseDir,(String)pathsMap.get(dobj.deployment.type));
- }
- if (targetDir.exists() && targetBaseDir.isFile())
- {
- throw new MojoExecutionException("targetDirectory "+targetDir.getAbsolutePath()+" points to a file, not a directory");
- }
- else if (!targetDir.exists())
+ List selection = new ArrayList();
+ StringTokenizer st = new StringTokenizer(deploySelection,",;");
+ while (st.hasMoreTokens())
{
- targetDir.mkdirs();
- }
- File target = null;
- if ("war".equals(dobj.deployment.type))
- {
- if (!dobj.deployment.expand)
+ String destination = st.nextToken();
+ String name = null;
+ int split = destination.indexOf(":");
+ if (split > 0)
{
- if (dobj.deployment.target == null)
- {
- if (dobj.artifact != null)
- {
- target = new File(targetDir, dobj.artifact.getArtifactId() + "." + dobj.artifact.getType());
- }
- else
- {
- target = new File(targetDir, dobj.fileHandle.getName());
- }
- }
- else
- {
- target = new File(targetDir, dobj.deployment.target);
- }
- if (target.isDirectory())
- {
- throw new MojoExecutionException("Resolved target file "+ target.getAbsolutePath()+" points to a directory");
- }
+ name = destination.substring(split+1);
+ destination = destination.substring(0, split);
}
- else
+ for (Iterator iter = objects.iterator(); iter.hasNext(); )
{
- if (dobj.deployment.target != null)
- {
- target = new File(targetDir, dobj.deployment.target);
- }
- else
+ DeploymentObject dobj = (DeploymentObject)iter.next();
+ if (dobj.deployment.destination.equals(destination))
{
- String name = dobj.fileHandle.getName();
- int index = name.lastIndexOf(".");
- if (index > -1)
+ if (name == null || name.equals(dobj.deployment.targetName) && !(selection.contains(dobj)))
{
- name = name.substring(0, index);
+ selection.add(dobj);
}
- target = new File(targetDir, name);
- }
- if (target.isFile())
- {
- throw new MojoExecutionException("Resolved target directory "+ target.getAbsolutePath()+" points to a file");
- }
- if (target.exists() && !rmdir(target))
- {
- throw new MojoExecutionException("Failed to remove target directory "+ target.getAbsolutePath());
}
}
- if (dobj.deployment.delete != null)
+ }
+ objects = selection;
+ }
+
+ if (objects.size() > 0)
+ {
+ getLog().info("Deploying to targetBaseDir "+targetBaseDir.getAbsolutePath());
+ }
+
+ for (Iterator iter = objects.iterator(); iter.hasNext(); )
+ {
+ DeploymentObject dobj = (DeploymentObject)iter.next();
+
+ String infoPostFix = "";
+ if (dobj.deployment.infuse.booleanValue())
+ {
+ infoPostFix += " (infused";
+ if (dobj.deployment.expand.booleanValue())
+ {
+ infoPostFix += ", expanded";
+ }
+ infoPostFix += ")";
+ }
+ else if (dobj.deployment.expand.booleanValue())
+ {
+ infoPostFix += " (expanded)";
+ }
+
+ getLog().info(" deploying to "+dobj.deployment.destination+": "+dobj.deployment.targetName + infoPostFix);
+
+ checkMkdirs(dobj.targetDir);
+
+ if (dobj.deployment.delete != null)
+ {
+ File delete = new File(dobj.targetDir, dobj.deployment.delete);
+
+ if (delete.exists())
{
- File delete = null;
- if (dobj.deployment.expand)
+ if (delete.isDirectory())
{
- delete = new File(target, dobj.deployment.delete);
+ if (!rmdir(delete))
+ {
+ throw new MojoExecutionException("Failed to delete directory "+ delete.getAbsolutePath());
+ }
}
else
{
- delete = new File(target.getParentFile(), dobj.deployment.delete);
- }
- if (delete.exists())
- {
- if (delete.isDirectory())
- {
- if (!rmdir(delete))
- {
- throw new MojoExecutionException("Failed to delete directory "+ delete.getAbsolutePath());
- }
- }
- else
+ if (!delete.delete())
{
- if (!delete.delete())
- {
- throw new MojoExecutionException("Failed to delete file "+ target.getAbsolutePath());
- }
+ throw new MojoExecutionException("Failed to delete file "+ delete.getAbsolutePath());
}
}
}
}
- else
+
+ File target = new File(dobj.targetDir, dobj.deployment.targetName);
+
+ if (target.exists())
{
- if (dobj.deployment.target != null)
+ if (dobj.deployment.expand.booleanValue() && !target.isDirectory())
{
- target = new File(targetDir, dobj.deployment.target);
+ throw new MojoExecutionException("Resolved target directory "+ target.getAbsolutePath()+" points to a file");
}
- else
+ else if (!dobj.deployment.expand.booleanValue() && target.isDirectory())
{
- target = new File(targetDir, dobj.fileHandle.getName());
- }
-
- if ("lib".equals(dobj.deployment.type) && dobj.artifact != null)
- {
- deleteMatchingFiles(targetDir, dobj.artifact.getArtifactId(), dobj.artifact.getType());
+ throw new MojoExecutionException("Resolved target file "+ target.getAbsolutePath()+" points to a directory");
}
}
- if (dobj.deployment.infuse)
+
+ if ("lib".equals(dobj.deployment.destination) && dobj.artifact != null)
+ {
+ deleteMatchingFiles(dobj.targetDir, dobj.artifact.getArtifactId(), dobj.artifact.getType());
+ }
+
+ if (dobj.deployment.infuse.booleanValue())
{
File tmpTarget = null;
- String targetPath;
- if (dobj.deployment.expand)
+ try
{
- try
- {
- tmpTarget = File.createTempFile(target.getName(), "");
- targetPath = tmpTarget.getAbsolutePath();
- }
- catch (IOException e)
- {
- throw new MojoExecutionException("Failed to create temporary file",e);
- }
+ tmpTarget = File.createTempFile(dobj.src.getName()+".infused-", "");
+ tmpTarget.deleteOnExit();
}
- else
+ catch (IOException e)
{
- targetPath = target.getAbsolutePath();
+ throw new MojoExecutionException("Failed to create temporary file",e);
}
try
{
- deployFactory.getInstance(dobj.fileHandle.getAbsolutePath(), targetPath, dobj.deployment.stripLoggers.booleanValue(), dobj.deployment.forcedVersion);
+ deployFactory.getInstance(dobj.src.getAbsolutePath(), tmpTarget.getAbsolutePath(), dobj.deployment.infusionStripLoggers.booleanValue(), dobj.deployment.infusionForcedVersion);
+ dobj.src = tmpTarget;
}
catch (Exception e)
{
- throw new MojoExecutionException("Failed to infuse "+dobj.fileHandle.getAbsolutePath(),e);
+ throw new MojoExecutionException("Failed to infuse "+dobj.src.getAbsolutePath(),e);
}
- if (tmpTarget != null)
+ }
+ if (dobj.deployment.expand.booleanValue())
+ {
+ try
{
- try
- {
- expandWar(tmpTarget, target);
- }
- catch (IOException e)
- {
- throw new MojoExecutionException("Failed to expand infused war",e);
- }
- finally
- {
- tmpTarget.delete();
- }
+ expandWar(dobj.src, target);
+ }
+ catch (IOException e)
+ {
+ throw new MojoExecutionException("Failed to expand infused war",e);
}
}
else
{
try
{
- copyFile(dobj.fileHandle, target);
+ copyFile(dobj.src, target);
}
catch (Exception e)
{
- e.printStackTrace();
- throw new MojoExecutionException("Failed to copy "+dobj.fileHandle.getAbsolutePath() +" to "+target.getAbsolutePath(),e);
+ throw new MojoExecutionException("Failed to copy "+dobj.src.getAbsolutePath() +" to "+target.getAbsolutePath(),e);
}
}
}
@@ -387,9 +466,24 @@
return value != null ? value : defaultValue;
}
- private static Boolean getValue(Boolean value, boolean defaultValue)
+ private static Boolean getValue(Boolean value, Boolean defaultValue)
{
- return value != null ? value : new Boolean(defaultValue);
+ return value != null ? value : defaultValue;
+ }
+
+ private static void checkMkdirs(File dir) throws MojoExecutionException
+ {
+ if (dir.exists())
+ {
+ if (dir.isFile())
+ {
+ throw new MojoExecutionException("Target "+dir.getAbsolutePath()+" points to a file, not a directory");
+ }
+ }
+ else
+ {
+ dir.mkdirs();
+ }
}
private static final void deleteMatchingFiles(File dir, final String namePrefix, final String ext)
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org