588
|
1 |
/*
|
|
2 |
* Copyright (c) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.core.ant.taskdefs;
|
|
19 |
|
|
20 |
import java.io.File;
|
|
21 |
import java.util.ArrayList;
|
|
22 |
import java.util.Arrays;
|
|
23 |
import java.util.List;
|
|
24 |
|
628
|
25 |
import org.apache.tools.ant.BuildException;
|
|
26 |
import org.apache.tools.ant.Task;
|
|
27 |
import org.apache.tools.ant.taskdefs.condition.Os;
|
|
28 |
|
588
|
29 |
/**
|
|
30 |
* Returns Next Free Drive available to use
|
|
31 |
*
|
|
32 |
* <pre>
|
|
33 |
* Usage: <hlm:getfreedrive property="build.drive"/>
|
|
34 |
* </pre>
|
|
35 |
* @ant.task name="getfreedrive" category="Core"
|
|
36 |
*/
|
|
37 |
public class GetFreeDriveTask extends Task {
|
|
38 |
// property to set with the available drive
|
|
39 |
private String property;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* To find the free drives available to use
|
|
43 |
*
|
|
44 |
* @return First free drive available
|
|
45 |
*/
|
|
46 |
private String getNextFreeDrive() {
|
|
47 |
List<File> drives = new ArrayList<File>(Arrays.asList(File.listRoots()));
|
|
48 |
for (char i = 'Z'; i >= 'A'; i--) {
|
|
49 |
File file = new File(i + ":" + File.separator);
|
|
50 |
if (!drives.contains(file)) {
|
|
51 |
return i + ":";
|
|
52 |
}
|
|
53 |
}
|
|
54 |
return null;
|
|
55 |
}
|
|
56 |
|
|
57 |
/**
|
|
58 |
* Name of the property to be set.
|
|
59 |
*
|
|
60 |
* @param property
|
|
61 |
* the property name
|
|
62 |
* @ant.required
|
|
63 |
*/
|
|
64 |
public void setProperty(String property) {
|
|
65 |
this.property = property;
|
|
66 |
}
|
|
67 |
|
|
68 |
@Override
|
|
69 |
public void execute() {
|
|
70 |
if (property == null) {
|
|
71 |
throw new BuildException("'property' attribute is not defined");
|
|
72 |
}
|
|
73 |
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
74 |
throw new BuildException("Task getfreedrive is supported only on windows");
|
|
75 |
}
|
|
76 |
String returnValue = getNextFreeDrive();
|
|
77 |
if (returnValue != null) {
|
|
78 |
getProject().setNewProperty(property, returnValue);
|
|
79 |
}
|
|
80 |
else {
|
|
81 |
throw new BuildException("No free drive available");
|
|
82 |
}
|
|
83 |
|
|
84 |
|
|
85 |
}
|
|
86 |
}
|