ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r539245 [2/2] - in /ant/sandbox/antlibs/debian: ./ 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/
Date Fri, 18 May 2007 03:37:16 GMT
Added: ant/sandbox/antlibs/debian/src/main/org/apache/ant/debian/ControlFileTask.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/debian/src/main/org/apache/ant/debian/ControlFileTask.java?view=auto&rev=539245
==============================================================================
--- ant/sandbox/antlibs/debian/src/main/org/apache/ant/debian/ControlFileTask.java (added)
+++ ant/sandbox/antlibs/debian/src/main/org/apache/ant/debian/ControlFileTask.java Thu May
17 20:37:15 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/debian/src/main/org/apache/ant/debian/antlib.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/debian/src/main/org/apache/ant/debian/antlib.xml?view=auto&rev=539245
==============================================================================
--- ant/sandbox/antlibs/debian/src/main/org/apache/ant/debian/antlib.xml (added)
+++ ant/sandbox/antlibs/debian/src/main/org/apache/ant/debian/antlib.xml Thu May 17 20:37:15
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/debian/src/tests/antunit/controlfile-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/debian/src/tests/antunit/controlfile-test.xml?view=auto&rev=539245
==============================================================================
--- ant/sandbox/antlibs/debian/src/tests/antunit/controlfile-test.xml (added)
+++ ant/sandbox/antlibs/debian/src/tests/antunit/controlfile-test.xml Thu May 17 20:37:15
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


Mime
View raw message