| 1974 |
jgill |
1 |
package com.erggroup.mass.ant;
|
|
|
2 |
|
|
|
3 |
import java.io.File;
|
|
|
4 |
import java.util.ArrayList;
|
|
|
5 |
import java.util.Collections;
|
|
|
6 |
import net.sourceforge.clearcase.api.IClearcase;
|
|
|
7 |
import org.apache.tools.ant.BuildException;
|
|
|
8 |
import org.apache.tools.ant.Project;
|
|
|
9 |
|
|
|
10 |
/**
|
|
|
11 |
*
|
|
|
12 |
*/
|
|
|
13 |
public class Utils
|
|
|
14 |
{
|
|
|
15 |
public static PackageVersion getHighestVersion( File packageDirectory )
|
|
|
16 |
{
|
|
|
17 |
return Utils.getHighestVersion(packageDirectory,"mas");
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
public static PackageVersion getHighestVersion( File packageDirectory, String scope)
|
|
|
21 |
{
|
|
|
22 |
File[] existing = packageDirectory.listFiles();
|
|
|
23 |
|
|
|
24 |
ArrayList versions = new ArrayList(existing.length);
|
|
|
25 |
for ( int i=0; i<existing.length; i++ )
|
|
|
26 |
{
|
|
|
27 |
try
|
|
|
28 |
{
|
|
|
29 |
PackageVersion version = new PackageVersion(existing[i].getName());
|
|
|
30 |
if ( version.getScope().equals(scope) )
|
|
|
31 |
{
|
|
|
32 |
versions.add( version );
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
catch ( NumberFormatException x )
|
|
|
36 |
{
|
|
|
37 |
// Ignore
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
if ( versions.size() > 0 )
|
|
|
42 |
{
|
|
|
43 |
return (PackageVersion)Collections.max(versions);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
return null;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Set the working directory for the current project to the VOB root
|
|
|
51 |
*
|
|
|
52 |
* @param project the project whose working directory will be set.
|
|
|
53 |
*/
|
|
|
54 |
public static void setWorkingDirectory( IClearcase clearcase, Project project )
|
|
|
55 |
{
|
|
|
56 |
File baseDirectory = project.getBaseDir().getParentFile();
|
|
|
57 |
while ( baseDirectory != null && baseDirectory.getParentFile() != null && baseDirectory.getParentFile().getParentFile() != null )
|
|
|
58 |
{
|
|
|
59 |
baseDirectory = baseDirectory.getParentFile();
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
IClearcase.Status chdir = clearcase.cleartool( "cd " + baseDirectory.getAbsolutePath() );
|
|
|
63 |
if ( !chdir.status )
|
|
|
64 |
{
|
|
|
65 |
project.log(chdir.message,Project.MSG_ERR);
|
|
|
66 |
throw new BuildException("Could not change to VOB root directory \'" + baseDirectory.getAbsolutePath() + "\'.");
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
}
|