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

Maven Archetype 3.3.1 compatibility #1076

Merged
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
1 change: 1 addition & 0 deletions maven-plugins/helidon-archetype-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
</dependency>
<!--suppress VulnerableLibrariesLocal -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.apache.maven.project.ProjectBuildingRequest;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;

import static java.util.Collections.emptyMap;

Expand Down Expand Up @@ -66,21 +67,32 @@ public static void generate(ArchetypeGenerationRequest request, List<String> dep
checkMavenVersion();
checkJavaVersion();

Aether aether = EngineFacade.<RepositorySystemSession>invoke(request, "getRepositorySession")
// archetype-common >= 3.3.0
.map(repoSession -> new Aether(repoSession, request.getRemoteArtifactRepositories()))
// archetype-common < 3.3.0
.orElseGet(() -> {
ProjectBuildingRequest pbr = EngineFacade.<ProjectBuildingRequest>invoke(request, "getProjectBuildingRequest")
.orElseThrow(() -> new IllegalStateException("Unable to get project building request"));
RepositorySystemSession repoSession = EngineFacade.<RepositorySystemSession>invoke(pbr,
"getRepositorySession")
.orElseThrow(() -> new IllegalStateException("Unable to get repository system session"));
List<ArtifactRepository> artifactRepos = EngineFacade.<List<ArtifactRepository>>invoke(request,
"getRemoteArtifactRepositories")
.orElseThrow(() -> new IllegalStateException("Unable to get artifact repositories"));
return new Aether(repoSession, artifactRepos, true);
});
// getRepositorySession only exists in archetype-common >= 3.3.0
RepositorySystemSession repoSession = EngineFacade.<RepositorySystemSession>invoke(request, "getRepositorySession")
// getProjectBuildingRequest was removed in archetype-common == 3.3.0
.or(() -> EngineFacade.<ProjectBuildingRequest>invoke(request, "getProjectBuildingRequest")
.map(ProjectBuildingRequest::getRepositorySession))
.orElseThrow(() -> new IllegalStateException("Unable to get repository system session"));

// getRemoteRepositories only exists in archetype-common >= 3.3.1
Aether aether = EngineFacade.<List<RemoteRepository>>invoke(request, "getRemoteRepositories")
.map(remoteRepos -> new Aether(repoSession, remoteRepos))
.or(() -> EngineFacade.<List<?>>invoke(request, "getRemoteArtifactRepositories")
.map(repos -> {
Object repo = repos.isEmpty() ? null : repos.get(0);
if (repo instanceof ArtifactRepository) {
// getRemoteArtifactRepositories returns List<ArtifactRepository> in archetype-common != 3.3.0
return new Aether(repoSession, asListOf(repos, ArtifactRepository.class), true);
} else if (repo instanceof RemoteRepository) {
// getRemoteArtifactRepositories returns List<RemoteRepository> in archetype-common == 3.3.0
return new Aether(repoSession, asListOf(repos, RemoteRepository.class));
} else {
// empty repository, or unsupported repository type
return new Aether(repoSession, List.of());
}
}))
.orElseThrow(() -> new IllegalStateException("Unable to initialize aether"));

File localRepo = aether.repoSession().getLocalRepository().getBasedir();

// enable mvn:// URL support
Expand Down Expand Up @@ -167,4 +179,9 @@ private static <T> Optional<T> invoke(Object object, String methodName) {
throw new RuntimeException(ex);
}
}

@SuppressWarnings("unchecked")
private static <T> List<T> asListOf(List<?> list, Class<T> type) {
return (List<T>) list;
}
}
Loading