source: other-projects/trunk/anttasks/src/org/greenstone/anttasks/WindowsSevenZipWrapper.java@ 20038

Last change on this file since 20038 was 20038, checked in by oranfry, 15 years ago

added a task to wrap the windows 7za.exe executable, to give it the same interface an unix sevenzip task

File size: 2.3 KB
Line 
1/*
2 * WindowsSevenZipWrapper.java
3 * A task to find a free folder to put something in
4 *
5 * Copyright (C) 2008 New Zealand Digital Library, http://www.nzdl.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21package org.greenstone.anttasks;
22
23import org.apache.tools.ant.*;
24import org.apache.tools.ant.taskdefs.*;
25import java.io.File;
26import java.io.IOException;
27
28/**
29 * Returns a path, based on the given path, which does not exist on the filesystem
30 * If the given path doesn't exist on the system, just returns the path
31 * If the given path does exist, return the path appended with "(n)" where
32 * where n is the lowest possible integer greater than 1 which would result in a
33 * path that does not exist on the file system.
34 */
35public class WindowsSevenZipWrapper extends Task {
36
37 private String task = null;
38 private File input = null;
39 private File output = null;
40
41 public void execute() {
42
43 //check both attributes set
44 if ( task != null && task != "decode" ) {
45 throw new BuildException( "Error - Only task supported is 'decode' !!" );
46 }
47
48 if ( input == null ) {
49 throw new BuildException( "Error - No input specified !!" );
50 }
51
52 if ( output == null ) {
53 throw new BuildException( "Error - No output specified !!" );
54 }
55
56 try {
57 String[] command = new String[] { "7za.exe", "x", input.getPath() };
58 Process child = Runtime.getRuntime().exec(command);
59 } catch (IOException e) {
60 throw new BuildException( "Error - Problem running 7za.exe !!" );
61 }
62
63 }
64
65 public void setOutput( File output ) {
66 this.output = output;
67 }
68
69 public void setInput( File input ) {
70 this.input = input;
71 }
72
73 public void setTask( String task ) {
74 this.task = task;
75 }
76
77}
Note: See TracBrowser for help on using the repository browser.