Author: jboynes
Date: Thu Sep 7 11:24:11 2006
New Revision: 441168
URL: http://svn.apache.org/viewvc?view=rev&rev=441168
Log:
apply patches from Meeraj for TUSCANY-688
Modified:
incubator/tuscany/java/samples/sca/webapp/pom.xml
incubator/tuscany/java/sca/kernel/spi/pom.xml
incubator/tuscany/java/sca/plugins/plugin.war/pom.xml
incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
Modified: incubator/tuscany/java/samples/sca/webapp/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sca/webapp/pom.xml?view=diff&rev=441168&r1=441167&r2=441168
==============================================================================
--- incubator/tuscany/java/samples/sca/webapp/pom.xml (original)
+++ incubator/tuscany/java/samples/sca/webapp/pom.xml Thu Sep 7 11:24:11 2006
@@ -57,49 +57,6 @@
</goals>
</execution>
</executions>
- <configuration>
- <bootLibs>
- <!-- these should be the default (assuming transitive
dependencies get included) -->
- <dependency>
- <groupId>org.apache.tuscany.runtime</groupId>
- <artifactId>webapp-host</artifactId>
- <version>${tuscanyVersion}</version>
- </dependency>
- <!-- the rest should be included through transitive
closure rather than be needed here -->
- <dependency>
- <groupId>org.apache.tuscany</groupId>
- <artifactId>core</artifactId>
- <version>${tuscanyVersion}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tuscany.sca.kernel</groupId>
- <artifactId>tuscany-spi</artifactId>
- <version>${tuscanyVersion}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tuscany</groupId>
- <artifactId>commonj-api_1.1</artifactId>
- <version>${tuscanyVersion}</version>
- </dependency>
- <dependency>
- <groupId>stax</groupId>
- <artifactId>stax-api</artifactId>
- <version>1.0.1</version>
- </dependency>
- <dependency>
- <groupId>woodstox</groupId>
- <artifactId>wstx-asl</artifactId>
- <version>2.9.3</version>
- </dependency>
- </bootLibs>
- <extensions>
- <dependency>
- <groupId>org.apache.tuscany.idl</groupId>
- <artifactId>wsdl</artifactId>
- <version>${tuscanyVersion}</version>
- </dependency>
- </extensions>
- </configuration>
</plugin>
</plugins>
</build>
Modified: incubator/tuscany/java/sca/kernel/spi/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/pom.xml?view=diff&rev=441168&r1=441167&r2=441168
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/pom.xml (original)
+++ incubator/tuscany/java/sca/kernel/spi/pom.xml Thu Sep 7 11:24:11 2006
@@ -57,4 +57,16 @@
<artifactId>easymock</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-clover-plugin</artifactId>
+ <configuration>
+ <jdk>1.5</jdk>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: incubator/tuscany/java/sca/plugins/plugin.war/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.war/pom.xml?view=diff&rev=441168&r1=441167&r2=441168
==============================================================================
--- incubator/tuscany/java/sca/plugins/plugin.war/pom.xml (original)
+++ incubator/tuscany/java/sca/plugins/plugin.war/pom.xml Thu Sep 7 11:24:11
2006
@@ -6,7 +6,7 @@
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>Tuscany War Plugin</name>
-
+
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
@@ -37,5 +37,5 @@
</plugin>
</plugins>
</build>
-
+
</project>
Modified:
incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java?view=diff&rev=441168&r1=441167&r2=441168
==============================================================================
---
incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
(original)
+++
incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
Thu Sep 7 11:24:11 2006
@@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
*/
package org.apache.tuscany.plugin.war;
@@ -22,41 +22,89 @@
import org.apache.maven.artifact.factory.ArtifactFactory;
/**
- * Represents a configured tuscany dependency for boot and extension
- * libraries.
- *
+ * Represents a configured tuscany dependency for boot and extension libraries.
+ *
* @version
*/
public class Dependency {
-
+
/**
* JAR type artifact.
*/
private static final String TYPE_JAR = "jar";
-
- /**
+
+ /**
+ * Default boot libraries.
+ * TODO Decide on whether to get snapshot version rather than hardcoded
version..
+ */
+ private static final Dependency[] DEFAULT_BOOT_LIBS = new Dependency[] {
new WebappHostDependency() };
+
+ /**
* Group Id that is injected in from configuration.
*/
private String groupId;
-
- /**
+
+ /**
* Artifact Id that is injected in from configuration.
*/
private String artifactId;
-
- /**
+
+ /**
* Version that is injected in from configuration.
*/
private String version;
-
+
+ /**
+ * Default constructor.
+ *
+ */
+ public Dependency() {
+ }
+
+ /**
+ * Initializes the field.
+ *
+ * @param groupId
+ * Group id.
+ * @param artifactId
+ * Artifact id.
+ * @param version
+ * Artifact version.
+ */
+ public Dependency(String groupId, String artifactId, String version) {
+ super();
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ }
+
/**
* Gets the artifact using the specified artifact factory.
- *
- * @param artifactFactory Artifact factory to use.
+ *
+ * @param artifactFactory
+ * Artifact factory to use.
* @return Artifact identified by the dependency.
*/
public Artifact getArtifact(ArtifactFactory artifactFactory) {
return artifactFactory.createArtifact(groupId, artifactId, version,
Artifact.SCOPE_RUNTIME, TYPE_JAR);
+ }
+
+ /**
+ * Returns the default boot libraries.
+ * @return Default boot libraries.
+ */
+ public static Dependency[] getDefaultBootLibs() {
+ return DEFAULT_BOOT_LIBS;
+ }
+
+ /**
+ * Webapp host depndency.
+ */
+ private static class WebappHostDependency extends Dependency {
+ // TODO Decide on whether to get snapshot version rather than
hardcoded version
+ private WebappHostDependency() {
+ super("org.apache.tuscany.runtime", "webapp-host", "1.0-SNAPSHOT");
+ }
}
}
Modified:
incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java?view=diff&rev=441168&r1=441167&r2=441168
==============================================================================
---
incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
(original)
+++
incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
Thu Sep 7 11:24:11 2006
@@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
*/
package org.apache.tuscany.plugin.war;
@@ -25,6 +25,7 @@
import java.io.InputStream;
import java.util.Enumeration;
import java.util.List;
+import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
@@ -32,16 +33,20 @@
import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
/**
* Goal which touches a timestamp file.
- *
+ *
* @goal tuscany-war
* @phase package
* @version
@@ -59,7 +64,15 @@
private static final String EXTENSION_PATH = "WEB-INF/tuscany/extensions/";
/**
+ * Artifact metadata source.
+ *
+ * @component
+ */
+ private ArtifactMetadataSource metadataSource;
+
+ /**
* Used to look up Artifacts in the remote repository.
+ *
* @parameter
expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
* @required
* @readonly
@@ -68,6 +81,7 @@
/**
* Used to look up Artifacts in the remote repository.
+ *
* @parameter
expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
* @required
* @readonly
@@ -76,6 +90,7 @@
/**
* Location of the local repository.
+ *
* @parameter expression="${localRepository}"
* @readonly
* @required
@@ -84,6 +99,7 @@
/**
* List of Remote Repositories used by the resolver
+ *
* @parameter expression="${project.remoteArtifactRepositories}"
* @readonly
* @required
@@ -92,7 +108,7 @@
/**
* The directory for the generated WAR.
- *
+ *
* @parameter expression="${project.build.directory}"
* @required
*/
@@ -100,23 +116,21 @@
/**
* The directory for the generated WAR.
- *
+ *
* @parameter
- * @required
*/
- private Dependency[] bootLibs;
+ private Dependency[] bootLibs = Dependency.getDefaultBootLibs();
/**
* The directory for the generated WAR.
- *
+ *
* @parameter
- * @required
*/
private Dependency[] extensions;
/**
* The name of the generated WAR.
- *
+ *
* @parameter expression="${project.build.finalName}"
* @required
*/
@@ -124,9 +138,9 @@
/**
* Executes the task.
- *
+ *
* The plugin executes the following tasks.
- *
+ *
* <ul>
* <li>Adds the specified boot libraries to WEB-INF/tuscany/boot
directory</li>
* <li>Adds the specified extension artifacts to
WEB-INF/tuscany/extensions</li>
@@ -140,9 +154,9 @@
JarOutputStream newWar = null;
File originalWarFile = null;
File newWarFile = null;
-
+
boolean success = false;
-
+
try {
originalWarFile = new File(outputDirectory, warName + ".war");
@@ -156,23 +170,27 @@
for (Dependency dependency : bootLibs) {
addTuscanyDependency(newWar, dependency, BOOT_PATH);
}
- for (Dependency dependency : extensions) {
- addTuscanyDependency(newWar, dependency, EXTENSION_PATH);
+
+ if(extensions != null) {
+ for (Dependency dependency : extensions) {
+ addTuscanyDependency(newWar, dependency, EXTENSION_PATH);
+ }
}
success = true;
} catch (Exception ex) {
+ ex.printStackTrace();
throw new MojoExecutionException(ex.getMessage(), ex);
} finally {
IOUtils.closeQuietly(newWar);
}
-
- if(success) {
- if(!originalWarFile.delete()) {
+
+ if (success) {
+ if (!originalWarFile.delete()) {
throw new MojoExecutionException("Unable to rename war file");
}
- if(!newWarFile.renameTo(originalWarFile)) {
+ if (!newWarFile.renameTo(originalWarFile)) {
throw new MojoExecutionException("Unable to rename war file");
}
}
@@ -181,66 +199,120 @@
/**
* Adds the tuscany dependency.
- *
- * @param newWar New WAR file.
- * @param dependency Dependency to be added.
- * @param path Path to the dependency.
- * @throws ArtifactNotFoundException
- * @throws ArtifactResolutionException
- * @throws ArtifactResolutionException If artifact is not resolved.
- * @throws ArtifactNotFoundException If artifact is not found.
- * @throws IOException
- * @throws IOException In case of an IO error.
+ *
+ * @param newWar
+ * New WAR file.
+ * @param dependency
+ * Dependency to be added.
+ * @param path
+ * Path to the dependency.
+ * @throws ArtifactResolutionException
+ * If artifact is not resolved.
+ * @throws ArtifactNotFoundException
+ * If artifact is not found.
+ * @throws IOException
+ * In case of an IO error.
+ * @throws ArtifactMetadataRetrievalException
*/
private void addTuscanyDependency(JarOutputStream newWar, Dependency
dependency, String path) throws ArtifactResolutionException,
- ArtifactNotFoundException, IOException {
+ ArtifactNotFoundException, IOException,
ArtifactMetadataRetrievalException {
+
+ Artifact artifact = dependency.getArtifact(artifactFactory);
+
+ // Resolve the artifact
+ resolver.resolve(artifact, remoteRepositories, localRepository);
+
+ // Transitively resolve all the dependencies
+ ResolutionGroup resolutionGroup = metadataSource.retrieve(artifact,
localRepository, remoteRepositories);
+ ArtifactResolutionResult result =
resolver.resolveTransitively(resolutionGroup.getArtifacts(), artifact,
remoteRepositories, localRepository,
+ metadataSource);
+
+ // Add the artifacts to the deployment unit
+ for (Artifact depArtifact : (Set<Artifact>) result.getArtifacts()) {
+ addArtifact(newWar, path, depArtifact);
+ }
+
+ addArtifact(newWar, path, artifact);
+
+ }
+
+ /**
+ * Adds the artifact to the deployment unit.
+ *
+ * @param newWar
+ * WAR to which the artifact is added.
+ * @param path
+ * Path wothin the WAR file.
+ * @param artifact
+ * ARtifact that is being added.
+ * @throws IOException
+ * In case of an IO error.
+ * @throws ArtifactResolutionException
+ * If the artifact cannot be resolved.
+ * @throws ArtifactNotFoundException
+ * If the artifact is not found.
+ */
+ private void addArtifact(JarOutputStream newWar, String path, Artifact
artifact) throws IOException, ArtifactResolutionException,
+ ArtifactNotFoundException {
FileInputStream artifactStream = null;
+ FileOutputStream fileOutputStream = null;
try {
- Artifact artifact = dependency.getArtifact(artifactFactory);
- resolver.resolve(artifact, remoteRepositories, localRepository);
-
File artifactFile = artifact.getFile();
artifactStream = new FileInputStream(artifactFile);
newWar.putNextEntry(new JarEntry(path + artifactFile.getName()));
+
+ File file = new File(outputDirectory, "webapp");
+ file = new File(file, path);
+ file.mkdirs();
+
+ file = new File(file, artifactFile.getName());
+ fileOutputStream = new FileOutputStream(file);
+
+ IOUtils.copy(artifactStream, fileOutputStream);
IOUtils.copy(artifactStream, newWar);
getLog().info("Processed " + path + artifactFile.getName());
} finally {
IOUtils.closeQuietly(artifactStream);
+ IOUtils.closeQuietly(fileOutputStream);
}
+
}
/**
* Copy the contents of the original WAR to a temporary WAR.
- *
- * @param originalWar Original WAR file.
- * @param newWar New war file.
- * @throws IOException Thrown in case of an IO error.
+ *
+ * @param originalWar
+ * Original WAR file.
+ * @param newWar
+ * New war file.
+ * @throws IOException
+ * Thrown in case of an IO error.
*/
private void copyOriginal(JarFile originalWar, JarOutputStream newWar)
throws IOException {
Enumeration entries = originalWar.entries();
-
+
while (entries.hasMoreElements()) {
-
+
JarEntry entry = (JarEntry) entries.nextElement();
InputStream jarEntryStream = null;
-
- try {
- jarEntryStream = originalWar.getInputStream(entry);
+
+ try {
+ jarEntryStream = originalWar.getInputStream(entry);
newWar.putNextEntry(entry);
- IOUtils.copy(jarEntryStream, newWar);
+ IOUtils.copy(jarEntryStream, newWar);
} finally {
IOUtils.closeQuietly(jarEntryStream);
}
-
+
}
-
+
originalWar.close();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]