This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-4.8.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.8.x by this push: new 1bdc51783c5 Fix NPE in MavenDownloader reported in IDEA tooling (https://github.com/camel-tooling/camel-idea-plugin/issues/1085) 1bdc51783c5 is described below commit 1bdc51783c5523783bc4a21eb6611046f09ab7c6 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Dec 12 15:48:45 2024 +0100 Fix NPE in MavenDownloader reported in IDEA tooling (https://github.com/camel-tooling/camel-idea-plugin/issues/1085) --- .../camel/tooling/maven/MavenDownloaderImpl.java | 80 ++++++++++++---------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java index a0c8cde9ffc..a01277fd32a 100644 --- a/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java +++ b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java @@ -1220,48 +1220,52 @@ public class MavenDownloaderImpl extends ServiceSupport implements MavenDownload // then process the repositories from active profiles from external Maven settings for (String profile : settings.getActiveProfiles()) { - for (Repository r : settings.getProfilesAsMap().get(profile).getRepositories()) { - try { - URL url = new URL(r.getUrl()); - if (repositoryURLs.add(r.getUrl())) { - if (mavenApacheSnapshotEnabled && url.getHost().equals("repository.apache.org") - && url.getPath().startsWith("/snapshots")) { - // record that Apache Snapshots repository is included in default (always used) - // repositories and used preconfigured instance of o.e.aether.repository.RemoteRepository - apacheSnapshotsIncluded = true; - repositories.add(apacheSnapshotsRepository); - } else { - RemoteRepository.Builder rb = new RemoteRepository.Builder(r.getId(), r.getLayout(), r.getUrl()); - if (r.getReleases() == null) { - // default (enabled) policy for releases - rb.setPolicy(defaultPolicy); - } else { - String updatePolicy = r.getReleases().getUpdatePolicy() == null - ? RepositoryPolicy.UPDATE_POLICY_DAILY : r.getReleases().getUpdatePolicy(); - String checksumPolicy = r.getReleases().getChecksumPolicy() == null - ? RepositoryPolicy.CHECKSUM_POLICY_WARN : r.getReleases().getChecksumPolicy(); - rb.setPolicy(new RepositoryPolicy( - r.getReleases().isEnabled(), - updatePolicy, checksumPolicy)); - } - // if someone defines Apache snapshots repository, (s)he has to specify proper policy, sorry. - if (r.getSnapshots() == null) { - // default (disabled) policy for releases - rb.setSnapshotPolicy(POLICY_DISABLED); + Profile p = settings.getProfilesAsMap().get(profile); + if (p != null) { + for (Repository r : p.getRepositories()) { + try { + URL url = new URL(r.getUrl()); + if (repositoryURLs.add(r.getUrl())) { + if (mavenApacheSnapshotEnabled && url.getHost().equals("repository.apache.org") + && url.getPath().startsWith("/snapshots")) { + // record that Apache Snapshots repository is included in default (always used) + // repositories and used preconfigured instance of o.e.aether.repository.RemoteRepository + apacheSnapshotsIncluded = true; + repositories.add(apacheSnapshotsRepository); } else { - String updatePolicy = r.getSnapshots().getUpdatePolicy() == null - ? RepositoryPolicy.UPDATE_POLICY_DAILY : r.getSnapshots().getUpdatePolicy(); - String checksumPolicy = r.getSnapshots().getChecksumPolicy() == null - ? RepositoryPolicy.CHECKSUM_POLICY_WARN : r.getSnapshots().getChecksumPolicy(); - rb.setSnapshotPolicy(new RepositoryPolicy( - r.getSnapshots().isEnabled(), - updatePolicy, checksumPolicy)); + RemoteRepository.Builder rb + = new RemoteRepository.Builder(r.getId(), r.getLayout(), r.getUrl()); + if (r.getReleases() == null) { + // default (enabled) policy for releases + rb.setPolicy(defaultPolicy); + } else { + String updatePolicy = r.getReleases().getUpdatePolicy() == null + ? RepositoryPolicy.UPDATE_POLICY_DAILY : r.getReleases().getUpdatePolicy(); + String checksumPolicy = r.getReleases().getChecksumPolicy() == null + ? RepositoryPolicy.CHECKSUM_POLICY_WARN : r.getReleases().getChecksumPolicy(); + rb.setPolicy(new RepositoryPolicy( + r.getReleases().isEnabled(), + updatePolicy, checksumPolicy)); + } + // if someone defines Apache snapshots repository, (s)he has to specify proper policy, sorry. + if (r.getSnapshots() == null) { + // default (disabled) policy for releases + rb.setSnapshotPolicy(POLICY_DISABLED); + } else { + String updatePolicy = r.getSnapshots().getUpdatePolicy() == null + ? RepositoryPolicy.UPDATE_POLICY_DAILY : r.getSnapshots().getUpdatePolicy(); + String checksumPolicy = r.getSnapshots().getChecksumPolicy() == null + ? RepositoryPolicy.CHECKSUM_POLICY_WARN : r.getSnapshots().getChecksumPolicy(); + rb.setSnapshotPolicy(new RepositoryPolicy( + r.getSnapshots().isEnabled(), + updatePolicy, checksumPolicy)); + } + repositories.add(rb.build()); } - repositories.add(rb.build()); } + } catch (MalformedURLException e) { + LOG.warn("Cannot use {} URL from Maven settings: {}. Skipping.", r.getUrl(), e.getMessage(), e); } - } catch (MalformedURLException e) { - LOG.warn("Cannot use {} URL from Maven settings: {}. Skipping.", r.getUrl(), e.getMessage(), e); } } }