Skip to content

Commit a184667

Browse files
committed
Simple support for Ant projects
1 parent e04eefd commit a184667

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package io.github.david0x03.project;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.util.Collections;
7+
import java.util.List;
8+
9+
10+
/**
11+
* Represents a Gradle-based Java project, providing methods to identify the Gradle
12+
* configuration, extract Java source version, build the project, and manage dependencies.
13+
*/
14+
public class AntProject extends JavaProject {
15+
16+
/**
17+
* Initializes a Ant project instance.
18+
*
19+
* @param projectPath The path to the project directory.
20+
*/
21+
public AntProject(Path projectPath) {
22+
super(projectPath);
23+
this.getSources().add(new JavaSource(this, projectPath));
24+
}
25+
26+
/**
27+
* Verifies whether the specified path contains a valid Gradle project.
28+
*
29+
* @param projectPath The path to the project directory.
30+
* @return True if the project is a Ant project, otherwise false.
31+
*/
32+
public static boolean isValidProject(Path projectPath) {
33+
return Files.exists(projectPath.resolve("build.xml"));
34+
}
35+
36+
/**
37+
* Retrieves the Java source version used by the project by executing Gradle commands.
38+
*
39+
* @return The Java source version as a string, or null if it cannot be determined.
40+
*/
41+
@Override
42+
public String getJavaSourceVersion() {
43+
return javaSourceVersion;
44+
}
45+
46+
/**
47+
* Mocks building the project by executing Ant commands.
48+
*
49+
* @return True if the build is successful, otherwise false.
50+
*/
51+
@Override
52+
public boolean buildProject() {
53+
return true;
54+
}
55+
56+
/**
57+
* Retrieves the external dependencies of the project.
58+
*
59+
* @param source The Java source file whose dependencies are to be retrieved.
60+
* @return A list of paths to dependency files.
61+
*/
62+
@Override
63+
protected List<Path> getDependencies(JavaSource source) {
64+
return Collections.emptyList();
65+
}
66+
67+
/**
68+
* Retrieves the files generated by Ant during the build process.
69+
*
70+
* @param source The Java source file to check for generated files.
71+
* @return A list of paths to generated files.
72+
*/
73+
@Override
74+
protected List<String> getGeneratedFiles(JavaSource source) {
75+
return Collections.emptyList();
76+
}
77+
}

SecurityFeatureMiningStudy/security-feature-localization/src/main/java/io/github/david0x03/project/JavaProject.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public static JavaProject load(Path projectPath) throws Exception {
4646
if (GradleProject.isValidProject(projectPath))
4747
return new GradleProject(projectPath);
4848

49+
if (AntProject.isValidProject(projectPath))
50+
return new AntProject(projectPath);
51+
4952
throw new Exception("project must include a pom.xml or build.gradle file");
5053
}
5154

0 commit comments

Comments
 (0)