Search in sources :

Example 1 with AppArtifact

use of io.quarkus.bootstrap.model.AppArtifact in project quarkus-test-framework by quarkus-qe.

the class QuarkusApplicationManagedResourceBuilder method initForcedDependencies.

public void initForcedDependencies(Dependency[] forcedDependencies) {
    if (forcedDependencies != null && forcedDependencies.length > 0) {
        requiresCustomBuild = true;
        this.forcedDependencies = Stream.of(forcedDependencies).map(d -> {
            String groupId = StringUtils.defaultIfEmpty(resolveProperty(d.groupId()), QUARKUS_GROUP_ID_DEFAULT);
            String version = StringUtils.defaultIfEmpty(resolveProperty(d.version()), Version.getVersion());
            AppArtifact artifact = new AppArtifact(groupId, d.artifactId(), version);
            // https://github.com/quarkusio/quarkus/commit/0c85b27c4046c894c181ffea367fca503d1c682c
            if (isQuarkusVersion2Dot3OrAbove()) {
                return ReflectionUtils.createInstance(AppDependency.class, artifact, DEPENDENCY_SCOPE_DEFAULT, new int[] { DEPENDENCY_DIRECT_FLAG });
            }
            return new AppDependency(artifact, DEPENDENCY_SCOPE_DEFAULT);
        }).collect(Collectors.toList());
    }
}
Also used : AppDependency(io.quarkus.bootstrap.model.AppDependency) AppArtifact(io.quarkus.bootstrap.model.AppArtifact)

Example 2 with AppArtifact

use of io.quarkus.bootstrap.model.AppArtifact in project quarkus by quarkusio.

the class BootstrapUtils method convert.

public static AppModel convert(ApplicationModel appModel) {
    if (appModel instanceof AppModel) {
        return (AppModel) appModel;
    }
    final AppModel.Builder builder = new AppModel.Builder();
    final ResolvedDependency resolvedArtifact = appModel.getAppArtifact();
    final AppArtifact appArtifact = new AppArtifact(resolvedArtifact.getGroupId(), resolvedArtifact.getArtifactId(), resolvedArtifact.getClassifier(), resolvedArtifact.getType(), resolvedArtifact.getVersion(), appModel.getApplicationModule(), resolvedArtifact.getScope(), resolvedArtifact.getFlags());
    if (appModel.getAppArtifact().isResolved()) {
        appArtifact.setPaths(PathsCollection.from(appModel.getAppArtifact().getResolvedPaths()));
    }
    builder.setAppArtifact(appArtifact);
    builder.setCapabilitiesContracts(appModel.getExtensionCapabilities().stream().map(c -> new CapabilityContract(c.getExtension(), new ArrayList<>(c.getProvidesCapabilities()), new ArrayList<>(c.getRequiresCapabilities()))).collect(Collectors.toMap(CapabilityContract::getExtension, Function.identity())));
    builder.setPlatformImports(appModel.getPlatforms());
    appModel.getDependencies().forEach(d -> {
        final AppArtifact a = new AppArtifact(d.getGroupId(), d.getArtifactId(), d.getClassifier(), d.getType(), d.getVersion(), d.getWorkspaceModule(), d.getScope(), d.getFlags());
        a.setPaths(d.getResolvedPaths() == null ? PathsCollection.of() : PathsCollection.from(d.getResolvedPaths()));
        builder.addDependency(new AppDependency(a, d.getScope(), d.getFlags()));
    });
    appModel.getLowerPriorityArtifacts().forEach(k -> builder.addLesserPriorityArtifact(new AppArtifactKey(k.getGroupId(), k.getArtifactId(), k.getClassifier(), k.getType())));
    appModel.getParentFirst().forEach(k -> builder.addParentFirstArtifact(new AppArtifactKey(k.getGroupId(), k.getArtifactId(), k.getClassifier(), k.getType())));
    appModel.getRunnerParentFirst().forEach(k -> builder.addRunnerParentFirstArtifact(new AppArtifactKey(k.getGroupId(), k.getArtifactId(), k.getClassifier(), k.getType())));
    appModel.getReloadableWorkspaceDependencies().forEach(k -> builder.addLocalProjectArtifact(new AppArtifactKey(k.getGroupId(), k.getArtifactId(), k.getClassifier(), k.getType())));
    return builder.build();
}
Also used : AppArtifactKey(io.quarkus.bootstrap.model.AppArtifactKey) AppDependency(io.quarkus.bootstrap.model.AppDependency) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) CapabilityContract(io.quarkus.bootstrap.model.CapabilityContract) ArrayList(java.util.ArrayList) AppArtifact(io.quarkus.bootstrap.model.AppArtifact) AppModel(io.quarkus.bootstrap.model.AppModel)

Example 3 with AppArtifact

use of io.quarkus.bootstrap.model.AppArtifact in project quarkus by quarkusio.

the class ModelUtils method getUpdateCandidates.

/**
 * Filters out non-platform from application POM dependencies.
 *
 * @param deps POM model application dependencies
 * @param appDeps resolved application dependencies
 * @return dependencies that can be checked for updates
 */
public static List<AppDependency> getUpdateCandidates(List<Dependency> deps, List<AppDependency> appDeps, Set<String> groupIds) {
    final Map<AppArtifactKey, AppDependency> appDepMap = new LinkedHashMap<>(appDeps.size());
    for (AppDependency appDep : appDeps) {
        final AppArtifact appArt = appDep.getArtifact();
        appDepMap.put(new AppArtifactKey(appArt.getGroupId(), appArt.getArtifactId(), appArt.getClassifier()), appDep);
    }
    final List<AppDependency> updateCandidates = new ArrayList<>(deps.size());
    // it's critical to preserve the order of the dependencies from the pom
    for (Dependency dep : deps) {
        if (!groupIds.contains(dep.getGroupId()) || "test".equals(dep.getScope())) {
            continue;
        }
        final AppDependency appDep = appDepMap.remove(new AppArtifactKey(dep.getGroupId(), dep.getArtifactId(), dep.getClassifier()));
        if (appDep == null) {
            // throw new AppCreatorException("Failed to locate dependency " + new AppArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getClassifier(), dep.getType(), dep.getVersion()) + " present in pom.xml among resolved application dependencies");
            continue;
        }
        updateCandidates.add(appDep);
    }
    for (AppDependency appDep : appDepMap.values()) {
        if (groupIds.contains(appDep.getArtifact().getGroupId())) {
            updateCandidates.add(appDep);
        }
    }
    return updateCandidates;
}
Also used : AppArtifactKey(io.quarkus.bootstrap.model.AppArtifactKey) AppDependency(io.quarkus.bootstrap.model.AppDependency) ArrayList(java.util.ArrayList) AppDependency(io.quarkus.bootstrap.model.AppDependency) Dependency(org.apache.maven.model.Dependency) AppArtifact(io.quarkus.bootstrap.model.AppArtifact) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with AppArtifact

use of io.quarkus.bootstrap.model.AppArtifact in project quarkus by quarkusio.

the class ModelUtils method resolveAppArtifact.

public static AppArtifact resolveAppArtifact(Path appJar) throws IOException {
    try (FileSystem fs = ZipUtils.newFileSystem(appJar)) {
        final Path metaInfMaven = fs.getPath("META-INF", "maven");
        if (Files.exists(metaInfMaven)) {
            try (DirectoryStream<Path> groupIds = Files.newDirectoryStream(metaInfMaven)) {
                for (Path groupIdPath : groupIds) {
                    if (!Files.isDirectory(groupIdPath)) {
                        continue;
                    }
                    try (DirectoryStream<Path> artifactIds = Files.newDirectoryStream(groupIdPath)) {
                        for (Path artifactIdPath : artifactIds) {
                            if (!Files.isDirectory(artifactIdPath)) {
                                continue;
                            }
                            final Path propsPath = artifactIdPath.resolve("pom.properties");
                            if (Files.exists(propsPath)) {
                                final Properties props = loadPomProps(appJar, artifactIdPath);
                                AppArtifact appArtifact = new AppArtifact(props.getProperty("groupId"), props.getProperty("artifactId"), props.getProperty("version"));
                                appArtifact.setPath(appJar);
                                return appArtifact;
                            }
                        }
                    }
                }
            }
        }
        AppArtifact appArtifact = new AppArtifact("unknown", "unknown", "1.0-SNAPSHOT");
        appArtifact.setPath(appJar);
        return appArtifact;
    }
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Properties(java.util.Properties) AppArtifact(io.quarkus.bootstrap.model.AppArtifact)

Aggregations

AppArtifact (io.quarkus.bootstrap.model.AppArtifact)4 AppDependency (io.quarkus.bootstrap.model.AppDependency)3 AppArtifactKey (io.quarkus.bootstrap.model.AppArtifactKey)2 ArrayList (java.util.ArrayList)2 AppModel (io.quarkus.bootstrap.model.AppModel)1 CapabilityContract (io.quarkus.bootstrap.model.CapabilityContract)1 ResolvedDependency (io.quarkus.maven.dependency.ResolvedDependency)1 FileSystem (java.nio.file.FileSystem)1 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1 Properties (java.util.Properties)1 Dependency (org.apache.maven.model.Dependency)1