Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around problems with flattened pom #95

Merged
merged 6 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ public void run() throws Exception {
if (asciidocOutputDir ==null && jsonFile==null && pluginsDir ==null)
throw new IllegalStateException("Nothing to do. Either -adoc, -json, or -pipeline is needed");

discover(addModule(new Module.CoreModule(updateCenterJson.getJSONObject("core").getString("version"))));
Module.CoreModule coreModule = new Module.CoreModule(updateCenterJson.getJSONObject("core").getString("version"));
discover(addModule(coreModule), coreModule);

processPlugins(updateCenterJson.getJSONObject("plugins").values());
processPlugins(updateCenterJson.getJSONObject("plugins").values(), coreModule);

if (jsonFile!=null) {
JSONObject all = new JSONObject();
Expand Down Expand Up @@ -247,10 +248,10 @@ public void run() throws Exception {
}

/**
* Walks over the plugins, record {@link #modules} and call {@link #discover(Module)}.
* Walks over the plugins, record {@link #modules} and call {@link #discover(Module, Module.CoreModule)}.
* @param plugins
*/
private void processPlugins(Collection<JSONObject> plugins) throws Exception {
private void processPlugins(Collection<JSONObject> plugins, Module.CoreModule core) throws Exception {
int availableProcessors = Runtime.getRuntime().availableProcessors();
int nThreads = availableProcessors * 3;
System.out.printf("Running with %d threads%n", nThreads);
Expand All @@ -269,7 +270,8 @@ public void run() {
try {
System.out.println(artifactId);
if (asciidocOutputDir !=null || jsonFile!=null) {
discover(addModule(new Module.PluginModule(plugin.getString("gav"), plugin.getString("url"), plugin.getString("title"), plugin.optString("scm"))));
Module pluginModule = addModule(new Module.PluginModule(plugin.getString("gav"), plugin.getString("url"), plugin.getString("title"), plugin.optString("scm")));
discover(pluginModule, core);
}
if (pluginsDir!=null) {
FileUtils.copyURLToFile(
Expand Down Expand Up @@ -331,9 +333,9 @@ private void generateAsciidocReport() throws IOException {
}
}

private void discover(Module m) throws IOException, InterruptedException {
private void discover(Module m, Module.CoreModule core) throws IOException, InterruptedException {
if (asciidocOutputDir !=null || jsonFile!=null) {
for (ClassOfInterest e : extractor.extract(m)) {
for (ClassOfInterest e : extractor.extract(m, core)) {
synchronized (families) {
System.out.println("Found "+e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
* @author Kohsuke Kawaguchi
*/
public class ExtensionPointsExtractor {
public List<ClassOfInterest> extract(Module module) throws IOException, InterruptedException {
return extract(module,SourceAndLibs.create(module));
public List<ClassOfInterest> extract(Module module, Module.CoreModule core) throws IOException, InterruptedException {
return extract(module,SourceAndLibs.create(module, core));
}

public List<ClassOfInterest> extract(final Module module, final SourceAndLibs sal) throws IOException {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/jenkinsci/extension_indexer/SourceAndLibs.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static URLConnection getURLConnection(URL url) throws MalformedURLExcept
return conn;
}

public static SourceAndLibs create(Module module) throws IOException, InterruptedException {
public static SourceAndLibs create(Module module, Module.CoreModule core) throws IOException, InterruptedException {
final File tempDir = Files.createTempDirectory("jenkins-extPoint").toFile();
File srcdir = new File(tempDir,"src");
File libdir = new File(tempDir,"lib");
Expand All @@ -163,7 +163,7 @@ public static SourceAndLibs create(Module module) throws IOException, Interrupte
}

System.out.println("Downloading Dependencies");
downloadDependencies(srcdir, libdir);
downloadDependencies(srcdir, libdir, core);

return new SourceAndLibs(srcdir, libdir) {
@Override
Expand All @@ -174,7 +174,7 @@ public void close() throws IOException {
}

@SuppressFBWarnings(value = "COMMAND_INJECTION", justification = "Command injection is not a viable risk here")
private static void downloadDependencies(File pomDir, File destDir) throws IOException, InterruptedException {
private static void downloadDependencies(File pomDir, File destDir, Module.CoreModule core) throws IOException, InterruptedException {
Files.createDirectories(destDir.toPath());
String process = "mvn";
if (System.getenv("M2_HOME") != null) {
Expand All @@ -183,9 +183,12 @@ private static void downloadDependencies(File pomDir, File destDir) throws IOExc
List<String> command = new ArrayList<>();
command.add(process);
command.addAll(Arrays.asList("--settings", (System.getenv("MAVEN_SETTINGS") != null) ? System.getenv("MAVEN_SETTINGS") : new File("maven-settings.xml").getAbsolutePath()));

command.addAll(Arrays.asList("--update-snapshots",
"--batch-mode",
"dependency:copy-dependencies",
"org.apache.maven.plugins:maven-dependency-plugin:3.8.0:copy-dependencies",
"org.apache.maven.plugins:maven-dependency-plugin:3.8.0:copy",
"-Dartifact=" + core.gav,
"-DincludeScope=compile",
"-DoutputDirectory=" + destDir.getAbsolutePath()));

Expand Down