You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ke...@apache.org on 2007/05/18 05:12:32 UTC
svn commit: r539232 [2/2] - in /ant/sandbox/antlibs: ./ src/ src/etc/
src/main/ src/main/org/ src/main/org/apache/ src/main/org/apache/ant/
src/main/org/apache/ant/debian/ src/tests/ src/tests/antunit/
Added: ant/sandbox/antlibs/src/main/org/apache/ant/debian/ControlFileTask.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/src/main/org/apache/ant/debian/ControlFileTask.java?view=auto&rev=539232
==============================================================================
--- ant/sandbox/antlibs/src/main/org/apache/ant/debian/ControlFileTask.java (added)
+++ ant/sandbox/antlibs/src/main/org/apache/ant/debian/ControlFileTask.java Thu May 17 20:12:30 2007
@@ -0,0 +1,122 @@
+/*
+ * 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.ant.debian;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.util.FileUtils;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * ControlFile task
+ * Use to create a debian control file
+ */
+public class ControlFileTask extends Task {
+
+ /**
+ * The file to write the control file info to
+ */
+ private File file;
+
+ /**
+ * The file encoding
+ * defaults to utf-8
+ */
+ private String encoding = "UTF-8";
+
+ private ControlFile controlFile = new ControlFile();
+
+ /**
+ * Create the debian control file when used as a task.
+ * @throws org.apache.tools.ant.BuildException if the control file cannot be written.
+ */
+ public void execute() throws BuildException {
+ if (file == null) {
+ throw new BuildException("the file attribute is required");
+ }
+ PrintWriter w = null;
+ try {
+ FileOutputStream fos = new FileOutputStream(file);
+ OutputStreamWriter osw = new OutputStreamWriter(fos, encoding);
+ w = new PrintWriter(osw);
+ controlFile.write(w);
+ } catch (IOException e) {
+ throw new BuildException("Failed to write " + file,
+ e, getLocation());
+ } finally {
+ FileUtils.close(w);
+ }
+ }
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public void setControlFile(ControlFile controlFile) {
+ this.controlFile = controlFile;
+ }
+
+ public void setPackage(String debPackage) {
+ controlFile.setDebPackage(debPackage);
+ }
+
+ public void setSection(String debSection) {
+ controlFile.setDebSection(debSection);
+ }
+
+ public void setVersion(String debVersion) {
+ controlFile.setDebVersion(debVersion);
+ }
+
+ public void setPriority(String debPriority) {
+ controlFile.setDebPriority(debPriority);
+ }
+
+ public void setArchitecture(String debArchitecture) {
+ controlFile.setDebArchitecture(debArchitecture);
+ }
+
+ public void setEssential(String debEssential) {
+ controlFile.setDebEssential(debEssential);
+ }
+
+ public void setMaintainer(String debMaintainer) {
+ controlFile.setDebMaintainer(debMaintainer);
+ }
+
+ public void setProvides(String debProvides) {
+ controlFile.setDebProvides(debProvides);
+ }
+
+ public void addDescription(ControlFile.Description description) {
+ controlFile.addDescription(description);
+ }
+
+ public void addDependency(ControlFile.Dependency dependency) {
+ controlFile.addDependency(dependency);
+ }
+}
\ No newline at end of file
Added: ant/sandbox/antlibs/src/main/org/apache/ant/debian/antlib.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/src/main/org/apache/ant/debian/antlib.xml?view=auto&rev=539232
==============================================================================
--- ant/sandbox/antlibs/src/main/org/apache/ant/debian/antlib.xml (added)
+++ ant/sandbox/antlibs/src/main/org/apache/ant/debian/antlib.xml Thu May 17 20:12:30 2007
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<antlib>
+ <taskdef
+ name="dpkg"
+ classname="org.apache.ant.debian.BuildDpkg"
+ />
+ <taskdef
+ name="control"
+ classname="org.apache.ant.debian.ControlFileTask"
+ />
+</antlib>
\ No newline at end of file
Added: ant/sandbox/antlibs/src/tests/antunit/controlfile-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/src/tests/antunit/controlfile-test.xml?view=auto&rev=539232
==============================================================================
--- ant/sandbox/antlibs/src/tests/antunit/controlfile-test.xml (added)
+++ ant/sandbox/antlibs/src/tests/antunit/controlfile-test.xml Thu May 17 20:12:30 2007
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<project default="all" xmlns:au="antlib:org.apache.ant.antunit">
+
+ <property name="testfile" value="cf"/>
+
+ <target name="setUp">
+ <taskdef name="control"
+ classname="org.apache.ant.debian.ControlFileTask"
+ />
+ </target>
+
+ <target name="tearDown">
+ <delete file="${java.io.tmpdir}/${testfile}"/>
+ </target>
+
+ <target name="testControlFileCreated">
+ <au:assertFileDoesntExist file="${java.io.tmpdir}/${testfile}"/>
+ <control file="${java.io.tmpdir}/${testfile}" package="ant" version="1.71alpha" maintainer="kevj@apache.org">
+ <dependency name="test1"/>
+ <dependency name="test2"/>
+ </control>
+ <au:assertFileExists file="${java.io.tmpdir}/${testfile}"/>
+ </target>
+
+ <target name="all">
+ <au:antunit>
+ <fileset file="${ant.file}"/>
+ <au:plainlistener/>
+ </au:antunit>
+ </target>
+</project>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org