aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1667047 - in /aries/trunk: ./ esa-ant-task/ esa-ant-task/src/ esa-ant-task/src/main/ esa-ant-task/src/main/java/ esa-ant-task/src/main/java/org/ esa-ant-task/src/main/java/org/apache/ esa-ant-task/src/main/java/org/apache/aries/ esa-ant-ta...
Date Mon, 16 Mar 2015 15:49:15 GMT
Author: davidb
Date: Mon Mar 16 15:49:14 2015
New Revision: 1667047

URL: http://svn.apache.org/r1667047
Log:
[ARIES-1305] Ant ESA TaskDef

Committing on behalf of Kamesh Sampath with many thanks!


Added:
    aries/trunk/esa-ant-task/
    aries/trunk/esa-ant-task/pom.xml   (with props)
    aries/trunk/esa-ant-task/readme.txt   (with props)
    aries/trunk/esa-ant-task/src/
    aries/trunk/esa-ant-task/src/main/
    aries/trunk/esa-ant-task/src/main/java/
    aries/trunk/esa-ant-task/src/main/java/org/
    aries/trunk/esa-ant-task/src/main/java/org/apache/
    aries/trunk/esa-ant-task/src/main/java/org/apache/aries/
    aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/
    aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/
    aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/BundleSelector.java
  (with props)
    aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/Constants.java  
(with props)
    aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/EsaTask.java   (with
props)
    aries/trunk/esa-ant-task/src/test/
    aries/trunk/esa-ant-task/src/test/java/
    aries/trunk/esa-ant-task/src/test/java/org/
    aries/trunk/esa-ant-task/src/test/java/org/apache/
    aries/trunk/esa-ant-task/src/test/java/org/apache/aries/
    aries/trunk/esa-ant-task/src/test/java/org/apache/aries/ant/
    aries/trunk/esa-ant-task/src/test/java/org/apache/aries/ant/taskdefs/
    aries/trunk/esa-ant-task/src/test/java/org/apache/aries/ant/taskdefs/EsaTaskTest.java
  (with props)
    aries/trunk/esa-ant-task/src/test/resources/
    aries/trunk/esa-ant-task/src/test/resources/SUBSYSTEM.MF   (with props)
    aries/trunk/esa-ant-task/src/test/resources/bundle1.jar   (with props)
    aries/trunk/esa-ant-task/src/test/resources/bundle2.jar   (with props)
Modified:
    aries/trunk/pom.xml

Added: aries/trunk/esa-ant-task/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/esa-ant-task/pom.xml?rev=1667047&view=auto
==============================================================================
--- aries/trunk/esa-ant-task/pom.xml (added)
+++ aries/trunk/esa-ant-task/pom.xml Mon Mar 16 15:49:14 2015
@@ -0,0 +1,47 @@
+<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">
+	<modelVersion>4.0.0</modelVersion>
+	
+	<parent>
+        <groupId>org.apache.aries</groupId>
+        <artifactId>parent</artifactId>
+        <version>2.0.0</version>
+        <relativePath>../parent/pom.xml</relativePath>
+    </parent>
+    
+	<artifactId>esa-ant-task</artifactId>
+	<version>1.0.0-SNAPSHOT</version>
+	<name>Aries ESA Ant Task</name>
+	<description>Builds an esa (Enterprise Subsystem Archive) from the project for deployment
to an aries server.</description>
+	<properties>
+		<ant.version>1.8.0</ant.version>
+		<bnd.version>2.4.0</bnd.version>
+	</properties>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.ant</groupId>
+			<artifactId>ant</artifactId>
+			<version>${ant.version}</version>
+		</dependency>
+		<!-- Test dependencies -->
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.1</version>
+				<configuration>
+					<!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
+					<source>1.7</source>
+					<target>1.7</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

Propchange: aries/trunk/esa-ant-task/pom.xml
------------------------------------------------------------------------------
    svn:executable = *

Added: aries/trunk/esa-ant-task/readme.txt
URL: http://svn.apache.org/viewvc/aries/trunk/esa-ant-task/readme.txt?rev=1667047&view=auto
==============================================================================
--- aries/trunk/esa-ant-task/readme.txt (added)
+++ aries/trunk/esa-ant-task/readme.txt Mon Mar 16 15:49:14 2015
@@ -0,0 +1,45 @@
+# esa-ant
+This ant taskdef will help you to generate the OSGI Enterprise Archive (*.esa) bundles. This
could be used in traditional ant taskdef way in to your build scripts
+
+# Getting started
+Clone the project and then run `mvn clean install`, grab the jar and drop it your ant classpath
typically ~/.ant/lib , or $ANT_HOME/lib etc.,
+
+# Sample build file
+
+```xml
+
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ====================================================================== 
+                                                    
+
+     An ant example for esa-ant    
+     A simple build file to demonstrate the use of esa-ant task
+                   
+     kameshs                                                                
+     ====================================================================== -->
+<project name="An ant example for esa-ant" default="default">
+	<description>
+            A simple build file to demonstrate the use of esa-ant task
+    </description>
+
+	<taskdef name="esa" classname="org.apache.aries.ant.taskdefs.EsaTask" />
+
+	<target name="default" description="builds esa with supplied SUBSYSTEM.MF">
+		<esa destfile="demo.esa" symbolicname="test-esa" manifest="${basedir}/SUBSYSTEM.MF">
+			<fileset dir="/tmp/esa-ant-demo">
+				<include name="*.jar" />
+			</fileset>
+		</esa>
+	</target>
+
+	<target name="default2" description="generates the SUSBYSTEM.MF based on esa contents">
+		<esa destfile="demo2.esa" symbolicname="test-esa" generatemanifest="true">
+			<fileset dir="/tmp/esa-ant-demo">
+				<include name="*.jar" />
+			</fileset>
+		</esa>
+	</target>
+
+
+</project>
+```
\ No newline at end of file

Propchange: aries/trunk/esa-ant-task/readme.txt
------------------------------------------------------------------------------
    svn:executable = *

Added: aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/BundleSelector.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/BundleSelector.java?rev=1667047&view=auto
==============================================================================
--- aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/BundleSelector.java
(added)
+++ aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/BundleSelector.java
Mon Mar 16 15:49:14 2015
@@ -0,0 +1,81 @@
+/**
+ * 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.aries.ant.taskdefs;
+
+import java.io.File;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.selectors.FileSelector;
+
+/**
+ * A simple Ant {@link FileSelector} that can be used to filter out valid OSGi
+ * bundles
+ * 
+ * @version $Id: $
+ */
+public class BundleSelector implements FileSelector {
+
+	@Override
+	public boolean isSelected(File basedir, String filename, File file)
+		throws BuildException {
+
+		boolean isValid = false;
+
+		if (file.isFile()) {
+
+			isValid =
+				(filename.toLowerCase().endsWith(".esa") || filename.toLowerCase().endsWith(".jar") );
+
+			JarFile osgiBundle = null;
+
+			try {
+
+				osgiBundle = new JarFile(new File(basedir, filename));
+
+				if(osgiBundle!=null){
+					Manifest manifest = osgiBundle.getManifest();
+					isValid = isValid && manifest != null;
+				}
+				
+
+			}
+			catch (Exception e) {
+				// nothing to do
+				isValid = isValid && false;
+			}
+			finally {
+				try {
+					
+					if(osgiBundle!=null){
+						osgiBundle.close();
+					}
+				}
+				catch (Exception e) {
+					// nothing to do
+				}
+			}
+		}
+
+		return isValid;
+	}
+
+}

Propchange: aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/BundleSelector.java
------------------------------------------------------------------------------
    svn:executable = *

Added: aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/Constants.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/Constants.java?rev=1667047&view=auto
==============================================================================
--- aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/Constants.java (added)
+++ aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/Constants.java Mon
Mar 16 15:49:14 2015
@@ -0,0 +1,57 @@
+/**
+ * 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.aries.ant.taskdefs;
+
+/**
+ * 
+ * @version $Id: $
+ */
+
+public interface Constants {
+	
+	public static final String BUNDLE_VERSION = "Bundle-Version";
+    public static final String BUNDLE_SYMBOLICNAME = "Bundle-SymbolicName";
+    public static final String FRAGMENT_HOST = "Fragment-Host";
+    
+    public static final String BUNDLE_TYPE = "osgi.bundle";
+    public static final String FRAGMENT_TYPE = "osgi.fragment";
+    
+    /*
+     * Subsystem types
+     */
+    public static final String APPLICATION_TYPE = "osgi.subsystem.application";
+    public static final String COMPOSITE_TYPE = "osgi.subsystem.composite";
+    public static final String FEATURE_TYPE = "osgi.subsystem.feature";
+
+    /*
+     * Subsystem manifest headers
+     */
+    public static final String SUBSYSTEM_MANIFESTVERSION = "Subsystem-ManifestVersion";
+    public static final String SUBSYSTEM_SYMBOLICNAME = "Subsystem-SymbolicName";
+    public static final String SUBSYSTEM_VERSION = "Subsystem-Version";
+    public static final String SUBSYSTEM_NAME = "Subsystem-Name";
+    public static final String SUBSYSTEM_DESCRIPTION = "Subsystem-Description";
+    public static final String SUBSYSTEM_CONTENT = "Subsystem-Content";
+    public static final String SUBSYSTEM_USEBUNDLE = "Use-Bundle";
+    public static final String SUBSYSTEM_TYPE = "Subsystem-Type";
+    
+    public static final String OSGI_INF_PATH = "OSGI-INF/";
+    public static final String SUBSYSTEM_MANIFEST_NAME = "OSGI-INF/SUBSYSTEM.MF";
+    public static final String SUBSYSTEM_MANIFEST_VERSION_VALUE = "1";
+}

Propchange: aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/Constants.java
------------------------------------------------------------------------------
    svn:executable = *

Added: aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/EsaTask.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/EsaTask.java?rev=1667047&view=auto
==============================================================================
--- aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/EsaTask.java (added)
+++ aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/EsaTask.java Mon
Mar 16 15:49:14 2015
@@ -0,0 +1,297 @@
+/**
+ * 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.aries.ant.taskdefs;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Jar;
+import org.apache.tools.ant.taskdefs.Zip;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ZipFileSet;
+import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.zip.ZipOutputStream;
+
+/**
+ * The Ant task that will build the Enterprise Subsystem Archive, this task is
+ * modeled based on the Ant {@link Jar} task
+ * 
+ * @version $Id: $
+ */
+public class EsaTask extends Zip {
+
+	/* name of the subsystem */
+	private String symbolicName;
+
+	/* name of the subsystem */
+	private String name;
+
+	/* subsystem description */
+	private String description;
+
+	/* version of the subsystem */
+	private String version;
+
+	/* subsystem type */
+	private String type = Constants.FEATURE_TYPE;
+
+	/* the file holder of the esa manifest */
+	private File manifestFile;
+
+	/* Flag to indicate whether to generate manifest */
+	protected boolean generateManifest;
+
+	/* Used for dry runs */
+	protected boolean skipWriting = false;
+
+	/* Used build the subsystem content header */
+	private StringBuilder subsystemContent = new StringBuilder(
+		Constants.SUBSYSTEM_CONTENT + ":");
+
+	public EsaTask() {
+
+		super();
+		archiveType = "esa";
+		setEncoding("UTF8");
+	}
+
+	/**
+	 * @param symbolicName
+	 *            the symbolicName to set
+	 */
+	public void setSymbolicName(String symbolicName) {
+
+		this.symbolicName = symbolicName;
+	}
+
+	/**
+	 * @param name
+	 *            the name to set
+	 */
+	public void setName(String name) {
+
+		this.name = name;
+	}
+
+	/**
+	 * @param version
+	 *            the version to set
+	 */
+	public void setVersion(String subsystemVersion) {
+
+		this.version = subsystemVersion;
+	}
+
+	/**
+	 * @param type
+	 *            the type to set
+	 */
+	public void setType(String subsystemType) {
+
+		this.type = subsystemType;
+	}
+
+	/**
+	 * @param manifest
+	 *            file to use the manifest to set
+	 */
+	public void setManifest(File manifestFile) {
+
+		if (!manifestFile.exists()) {
+			throw new BuildException("Manifest:" + manifestFile +
+				" does not exist", getLocation());
+		}
+
+		this.manifestFile = manifestFile;
+	}
+
+	/**
+	 * @param generateManifest
+	 *            the generateManifest to set
+	 */
+	public void setGenerateManifest(boolean generateManifest) {
+
+		this.generateManifest = generateManifest;
+	}
+
+	/**
+	 * @param skipWriting
+	 *            the skipWriting to set
+	 */
+	public void setSkipWriting(boolean skipWriting) {
+
+		this.skipWriting = skipWriting;
+	}
+
+	@Override
+	protected void zipFile(
+		File file, ZipOutputStream zOut, String vPath, int mode)
+		throws IOException {
+
+		super.zipFile(file, zOut, vPath, mode);
+
+		/*
+		 * this handling is only for OSGi bundles and we need to exclude other
+		 * entries
+		 */
+		if (file.isFile() &&
+			!Constants.SUBSYSTEM_MANIFEST_NAME.equalsIgnoreCase(vPath)) {
+
+			JarFile bundleFile = new JarFile(file);
+
+			Manifest jarManifest = bundleFile.getManifest();
+
+			if (jarManifest != null) {
+
+				Attributes mainAttributes = jarManifest.getMainAttributes();
+
+				String bundleSymbolicName =
+					mainAttributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
+
+				String bundleVersion =
+					mainAttributes.getValue(Constants.BUNDLE_VERSION);
+
+				bundleFile.close();
+
+				String strSubsystemContentEntry =
+					bundleSymbolicName + ";version=" + bundleVersion;
+
+				subsystemContent.append(strSubsystemContentEntry);
+				subsystemContent.append(",");
+			}
+		}
+	}
+
+	@Override
+	protected void initZipOutputStream(ZipOutputStream zOut)
+		throws IOException, BuildException {
+
+		if (manifestFile != null && !generateManifest) {
+
+			zipDir(
+				(Resource) null, zOut, Constants.OSGI_INF_PATH,
+				ZipFileSet.DEFAULT_DIR_MODE, null);
+
+			zipFile(
+				manifestFile, zOut, Constants.SUBSYSTEM_MANIFEST_NAME,
+				ZipFileSet.DEFAULT_FILE_MODE);
+		}
+	}
+
+	@Override
+	protected void finalizeZipOutputStream(ZipOutputStream zOut)
+		throws IOException, BuildException {
+
+		if (!skipWriting) {
+			if (generateManifest) {
+				addNewManifest(zOut);
+			}
+		}
+	}
+
+	/**
+	 * This method will add the SUBSYSTEM.MF to the esa archieve
+	 * 
+	 * @param zOut
+	 *            -the zip output stream
+	 */
+	private void addNewManifest(ZipOutputStream zOut) {
+
+		try {
+
+			log("Generating SUBSYSTEM.MF", Project.MSG_VERBOSE);
+
+			zipDir(
+				(Resource) null, zOut, Constants.OSGI_INF_PATH,
+				ZipFileSet.DEFAULT_DIR_MODE, null);
+
+			ByteArrayOutputStream bout = new ByteArrayOutputStream();
+
+			OutputStreamWriter osWriter = new OutputStreamWriter(bout, "UTF-8");
+
+			PrintWriter printWriter = new PrintWriter(osWriter);
+
+			// Start writing manifest content
+			printWriter.write(Constants.SUBSYSTEM_MANIFESTVERSION + ": " +
+				Constants.SUBSYSTEM_MANIFEST_VERSION_VALUE + "\n");
+
+			printWriter.write(Constants.SUBSYSTEM_SYMBOLICNAME + ": " +
+				symbolicName + "\n");
+
+			if (version == null) {
+				version = "1.0.0";
+			}
+
+			printWriter.write(Constants.SUBSYSTEM_VERSION + ": " + version +
+				"\n");
+
+			if (name == null) {
+				name = symbolicName;
+			}
+
+			printWriter.write(Constants.SUBSYSTEM_NAME + ": " + name + "\n");
+
+			printWriter.write(Constants.SUBSYSTEM_TYPE + ": " + type + "\n");
+
+			if (description != null) {
+				printWriter.write(Constants.SUBSYSTEM_DESCRIPTION + ": " +
+					description + "\n");
+			}
+
+			// Subsystem-content header
+
+			String subsystemContentHeader = subsystemContent.toString();
+			// strip the last ,
+			subsystemContentHeader =
+				subsystemContentHeader.substring(
+					0, (subsystemContentHeader.length() - 1)) +
+					"\n";
+
+			printWriter.write(subsystemContentHeader);
+
+			printWriter.close();
+
+			ByteArrayInputStream bais =
+				new ByteArrayInputStream(bout.toByteArray());
+			try {
+				super.zipFile(
+					bais, zOut, Constants.SUBSYSTEM_MANIFEST_NAME,
+					System.currentTimeMillis(), null,
+					ZipFileSet.DEFAULT_FILE_MODE);
+			}
+			finally {
+				// not really required
+				FileUtils.close(bais);
+			}
+		}
+		catch (IOException e) {
+			log("Error generating manifest", Project.MSG_ERR);
+		}
+	}
+}

Propchange: aries/trunk/esa-ant-task/src/main/java/org/apache/aries/ant/taskdefs/EsaTask.java
------------------------------------------------------------------------------
    svn:executable = *

Added: aries/trunk/esa-ant-task/src/test/java/org/apache/aries/ant/taskdefs/EsaTaskTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-ant-task/src/test/java/org/apache/aries/ant/taskdefs/EsaTaskTest.java?rev=1667047&view=auto
==============================================================================
--- aries/trunk/esa-ant-task/src/test/java/org/apache/aries/ant/taskdefs/EsaTaskTest.java
(added)
+++ aries/trunk/esa-ant-task/src/test/java/org/apache/aries/ant/taskdefs/EsaTaskTest.java
Mon Mar 16 15:49:14 2015
@@ -0,0 +1,159 @@
+/**
+ * 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.aries.ant.taskdefs;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.FileSet;
+import org.junit.Test;
+
+/**
+ * @version $Id: $
+ */
+public class EsaTaskTest {
+
+	@Test
+	public void generateArchiveNoManifest() {
+
+		File srcDir = new File("../src/test/resources");
+
+		File destfile = new File("target/esa-test1.esa");
+		if (destfile.exists()) {
+			destfile.delete();
+		}
+
+		assertFalse(destfile.exists());
+		EsaTask esaTask = new EsaTask();
+		Project testProject = new Project();
+		esaTask.setProject(testProject);
+		FileSet fileSet = new FileSet();
+		fileSet.setDir(srcDir);
+		fileSet.setIncludes("*.jar");
+		esaTask.addFileset(fileSet);
+		esaTask.setDestFile(destfile);
+		esaTask.setSymbolicName("esatask-test");
+		esaTask.setVersion("1.0.0");
+		esaTask.execute();
+		assertTrue(destfile.exists());
+
+		try {
+			ZipFile esaArchive = new ZipFile(destfile);
+			assertNotNull(esaArchive);
+			ZipEntry subsystemManifest =
+				esaArchive.getEntry("OSGI-INF/SUBSYSTEM.MF");
+			assertNull(subsystemManifest);
+		}
+		catch (IOException e) {
+			fail(e.getMessage());
+		}
+	}
+
+	@Test
+	public void generateArchiveWithFileManifest() {
+
+		File srcDir = new File("../src/test/resources");
+
+		File destfile = new File("target/esa-test2.esa");
+		if (destfile.exists()) {
+			destfile.delete();
+		}
+
+		assertFalse(destfile.exists());
+		EsaTask esaTask = new EsaTask();
+		Project testProject = new Project();
+		esaTask.setProject(testProject);
+		FileSet fileSet = new FileSet();
+		fileSet.setDir(srcDir);
+		fileSet.setIncludes("*.jar");
+		esaTask.addFileset(fileSet);
+		esaTask.setDestFile(destfile);
+		esaTask.setSymbolicName("esatask-test");
+		esaTask.setVersion("1.0.0");
+		esaTask.setManifest(new File(srcDir, "SUBSYSTEM.MF"));
+		esaTask.execute();
+		assertTrue(destfile.exists());
+
+		try {
+			ZipFile esaArchive = new ZipFile(destfile);
+			assertNotNull(esaArchive);
+			ZipEntry subsystemManifest =
+				esaArchive.getEntry("OSGI-INF/SUBSYSTEM.MF");
+			assertNotNull(subsystemManifest);
+		}
+		catch (IOException e) {
+			fail(e.getMessage());
+		}
+	}
+
+	@Test
+	public void generateArchiveWithNewManifest() {
+
+		File srcDir = new File("../src/test/resources");
+		assertTrue(srcDir.exists());
+
+		File destfile = new File("target/esa-test.esa");
+
+		if (destfile.exists()) {
+			destfile.delete();
+		}
+
+		assertFalse(destfile.exists());
+
+		EsaTask esaTask = new EsaTask();
+
+		Project testProject = new Project();
+
+		esaTask.setProject(testProject);
+
+		FileSet fileSet = new FileSet();
+		fileSet.setDir(srcDir);
+		fileSet.setIncludes("*.jar");
+
+		esaTask.addFileset(fileSet);
+		esaTask.setDestFile(destfile);
+		esaTask.setSymbolicName("esatask-test");
+		esaTask.setName("ESA Test Task");
+		esaTask.setVersion("1.0.0");
+		esaTask.setGenerateManifest(true);
+		esaTask.execute();
+		assertTrue(destfile.exists());
+
+		try {
+			ZipFile esaArchive = new ZipFile(destfile);
+			assertNotNull(esaArchive);
+			ZipEntry subsystemManifest =
+				esaArchive.getEntry("OSGI-INF/SUBSYSTEM.MF");
+			assertNotNull(subsystemManifest);
+		}
+		catch (IOException e) {
+			fail(e.getMessage());
+		}
+	}
+}

Propchange: aries/trunk/esa-ant-task/src/test/java/org/apache/aries/ant/taskdefs/EsaTaskTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: aries/trunk/esa-ant-task/src/test/resources/SUBSYSTEM.MF
URL: http://svn.apache.org/viewvc/aries/trunk/esa-ant-task/src/test/resources/SUBSYSTEM.MF?rev=1667047&view=auto
==============================================================================
--- aries/trunk/esa-ant-task/src/test/resources/SUBSYSTEM.MF (added)
+++ aries/trunk/esa-ant-task/src/test/resources/SUBSYSTEM.MF Mon Mar 16 15:49:14 2015
@@ -0,0 +1,3 @@
+Subsystem-SymbolicName: esa-task-test2
+Subsystem-Version: 1.0.0
+Subsystem-Type: osgi.subsystem.feature

Propchange: aries/trunk/esa-ant-task/src/test/resources/SUBSYSTEM.MF
------------------------------------------------------------------------------
    svn:executable = *

Added: aries/trunk/esa-ant-task/src/test/resources/bundle1.jar
URL: http://svn.apache.org/viewvc/aries/trunk/esa-ant-task/src/test/resources/bundle1.jar?rev=1667047&view=auto
==============================================================================
Binary file - no diff available.

Propchange: aries/trunk/esa-ant-task/src/test/resources/bundle1.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: aries/trunk/esa-ant-task/src/test/resources/bundle1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: aries/trunk/esa-ant-task/src/test/resources/bundle2.jar
URL: http://svn.apache.org/viewvc/aries/trunk/esa-ant-task/src/test/resources/bundle2.jar?rev=1667047&view=auto
==============================================================================
Binary file - no diff available.

Propchange: aries/trunk/esa-ant-task/src/test/resources/bundle2.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: aries/trunk/esa-ant-task/src/test/resources/bundle2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: aries/trunk/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/pom.xml?rev=1667047&r1=1667046&r2=1667047&view=diff
==============================================================================
--- aries/trunk/pom.xml (original)
+++ aries/trunk/pom.xml Mon Mar 16 15:49:14 2015
@@ -55,6 +55,7 @@
         <module>jpa</module>
         <module>spi-fly</module>
         <module>samples</module>
+        <module>esa-ant-task</module>
         <module>esa-maven-plugin</module>
     </modules>
 



Mime
View raw message