Author: marrs
Date: Wed Aug 3 08:10:32 2011
New Revision: 1153383
URL: http://svn.apache.org/viewvc?rev=1153383&view=rev
Log:
ACE-163 Initial version of Ant task.
Added:
incubator/ace/trunk/ace-ant-tasks/
incubator/ace/trunk/ace-ant-tasks/build.xml
incubator/ace/trunk/ace-ant-tasks/pom.xml
incubator/ace/trunk/ace-ant-tasks/src/
incubator/ace/trunk/ace-ant-tasks/src/main/
incubator/ace/trunk/ace-ant-tasks/src/main/java/
incubator/ace/trunk/ace-ant-tasks/src/main/java/org/
incubator/ace/trunk/ace-ant-tasks/src/main/java/org/apache/
incubator/ace/trunk/ace-ant-tasks/src/main/java/org/apache/ace/
incubator/ace/trunk/ace-ant-tasks/src/main/java/org/apache/ace/ant/
incubator/ace/trunk/ace-ant-tasks/src/main/java/org/apache/ace/ant/deploymentpackage/
incubator/ace/trunk/ace-ant-tasks/src/main/java/org/apache/ace/ant/deploymentpackage/DeploymentPackageTask.java
incubator/ace/trunk/ace-ant-tasks/src/test/
incubator/ace/trunk/ace-ant-tasks/src/test/java/
Added: incubator/ace/trunk/ace-ant-tasks/build.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-ant-tasks/build.xml?rev=1153383&view=auto
==============================================================================
--- incubator/ace/trunk/ace-ant-tasks/build.xml (added)
+++ incubator/ace/trunk/ace-ant-tasks/build.xml Wed Aug 3 08:10:32 2011
@@ -0,0 +1,11 @@
+<project name="test" default="build">
+ <taskdef name="dp" classname="org.apache.ace.ant.deploymentpackage.DeploymentPackageTask"
classpath="target/org.apache.ace.ant.tasks-0.8.1-incubator-SNAPSHOT.jar" />
+ <target name="build">
+ <echo message="Start..." />
+ <dp name="marrs" version="1.0.0" dir="/Users/marcel/Desktop/demo" destination="cool-dp.jar">
+ <include name="servicebased.host-1.0.0.jar" />
+ <include name="servicebased.triangle-1.0.0.jar" />
+ </dp>
+ <echo message="Stop..." />
+ </target>
+</project>
Added: incubator/ace/trunk/ace-ant-tasks/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-ant-tasks/pom.xml?rev=1153383&view=auto
==============================================================================
--- incubator/ace/trunk/ace-ant-tasks/pom.xml (added)
+++ incubator/ace/trunk/ace-ant-tasks/pom.xml Wed Aug 3 08:10:32 2011
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-pom</artifactId>
+ <version>0.8.1-incubator-SNAPSHOT</version>
+ <relativePath>../pom/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.ace.ant.tasks</artifactId>
+
+ <version>0.8.1-incubator-SNAPSHOT</version>
+ <name>Apache ACE :: Ant Tasks</name>
+ <description>Collection of Ant tasks for integrating Apache ACE into your development
environment.</description>
+ <packaging>jar</packaging>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/ace/trunk/ace-ant-tasks</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/ace/trunk/ace-ant-tasks</developerConnection>
+ <url>http://svn.apache.org/repos/asf/incubator/ace/trunk/ace-ant-tasks</url>
+ </scm>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.8.2</version>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/ace/trunk/ace-ant-tasks/src/main/java/org/apache/ace/ant/deploymentpackage/DeploymentPackageTask.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-ant-tasks/src/main/java/org/apache/ace/ant/deploymentpackage/DeploymentPackageTask.java?rev=1153383&view=auto
==============================================================================
--- incubator/ace/trunk/ace-ant-tasks/src/main/java/org/apache/ace/ant/deploymentpackage/DeploymentPackageTask.java
(added)
+++ incubator/ace/trunk/ace-ant-tasks/src/main/java/org/apache/ace/ant/deploymentpackage/DeploymentPackageTask.java
Wed Aug 3 08:10:32 2011
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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.
+ */
+package org.apache.ace.ant.deploymentpackage;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.jar.Attributes;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.MatchingTask;
+
+public class DeploymentPackageTask extends MatchingTask {
+ private File m_destination;
+ private String m_name;
+ private String m_version;
+ private File m_dir;
+
+ public void setDir (File dir) {
+ m_dir = dir;
+ }
+
+ public void setName(String name) {
+ m_name = name;
+ }
+
+ public void setVersion(String version) {
+ m_version = version;
+ }
+
+ public void setDestination(File destination) {
+ m_destination = destination;
+ }
+
+ public void execute() throws BuildException {
+ if (m_dir == null) {
+ throw new BuildException("dir must be specified");
+ }
+ if (m_name == null) {
+ throw new BuildException("name must be specified");
+ }
+ if (m_version == null) {
+ throw new BuildException("version must be specified");
+ }
+ if (m_destination == null) {
+ throw new BuildException("destination must be specified");
+ }
+ log("dir = " + m_dir, Project.MSG_DEBUG);
+
+ DirectoryScanner ds = getDirectoryScanner(m_dir);
+ String[] files = ds.getIncludedFiles();
+ for (int i = 0; i < files.length; i++) {
+ log("file: " + files[i]);
+ }
+
+ Manifest manifest = new Manifest();
+ Attributes main = manifest.getMainAttributes();
+ main.putValue("Manifest-Version", "1.0");
+ main.putValue("DeploymentPackage-SymbolicName", m_name);
+ main.putValue("DeploymentPackage-Version", m_version);
+
+ for (String file : files) {
+ try {
+ JarInputStream jis = new JarInputStream(new FileInputStream(new File(m_dir,
file)));
+ Manifest bundleManifest = jis.getManifest();
+ String bsn = bundleManifest.getMainAttributes().getValue("Bundle-SymbolicName");
+ String version = bundleManifest.getMainAttributes().getValue("Bundle-Version");
+ jis.close();
+ Attributes a = new Attributes();
+ a.putValue("Bundle-SymbolicName", bsn);
+ a.putValue("Bundle-Version", version);
+ manifest.getEntries().put(file, a);
+ }
+ catch (IOException e) {
+ throw new BuildException("Could not read bundle " + file + ".", e);
+ }
+ }
+
+ JarOutputStream output = null;
+ try {
+ output = new JarOutputStream(new FileOutputStream(m_destination), manifest);
+ byte[] buffer = new byte[4096];
+ for (String file : files) {
+ output.putNextEntry(new ZipEntry(file));
+ FileInputStream fis = new FileInputStream(new File(m_dir, file));
+ int bytes = fis.read(buffer);
+ while (bytes != -1) {
+ output.write(buffer, 0, bytes);
+ bytes = fis.read(buffer);
+ }
+ output.closeEntry();
+ }
+ }
+ catch (Exception e) {
+ throw new BuildException("Could not create deployment package " + m_destination
+ ".", e);
+ }
+ finally {
+ if (output != null) {
+ try {
+ output.close();
+ }
+ catch (IOException e) {
+ throw new BuildException("Could not close deployment package " + m_destination
+ ".", e);
+ }
+ }
+ }
+ }
+}
+
|