Search in sources :

Example 1 with AppModelResolverException

use of io.quarkus.bootstrap.resolver.AppModelResolverException in project quarkus by quarkusio.

the class BootstrapUtils method deserializeQuarkusModel.

public static ApplicationModel deserializeQuarkusModel(Path modelPath) throws AppModelResolverException {
    if (Files.exists(modelPath)) {
        try (InputStream existing = Files.newInputStream(modelPath);
            ObjectInputStream object = new ObjectInputStream(existing)) {
            ApplicationModel model = (ApplicationModel) object.readObject();
            IoUtils.recursiveDelete(modelPath);
            return model;
        } catch (IOException | ClassNotFoundException e) {
            throw new AppModelResolverException("Failed to deserialize quarkus model", e);
        }
    }
    throw new AppModelResolverException("Unable to locate quarkus model");
}
Also used : ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) AppModelResolverException(io.quarkus.bootstrap.resolver.AppModelResolverException) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with AppModelResolverException

use of io.quarkus.bootstrap.resolver.AppModelResolverException in project quarkus by quarkusio.

the class IDEDevModeMain method accept.

@Override
public void accept(CuratedApplication curatedApplication, Map<String, Object> stringObjectMap) {
    Path appClasses = (Path) stringObjectMap.get("app-classes");
    DevModeContext devModeContext = new DevModeContext();
    devModeContext.setArgs((String[]) stringObjectMap.get("args"));
    ApplicationModel appModel = null;
    try {
        if (BuildToolHelper.isMavenProject(appClasses)) {
            appModel = curatedApplication.getApplicationModel();
        } else {
            appModel = BootstrapUtils.deserializeQuarkusModel((Path) stringObjectMap.get(BootstrapConstants.SERIALIZED_APP_MODEL));
        }
        if (appModel != null) {
            for (ResolvedDependency project : DependenciesFilter.getReloadableModules(appModel)) {
                final ModuleInfo module = toModule(project);
                if (project.getKey().equals(appModel.getAppArtifact().getKey()) && project.getVersion().equals(appModel.getAppArtifact().getVersion())) {
                    devModeContext.setApplicationRoot(module);
                } else {
                    devModeContext.getAdditionalModules().add(module);
                    devModeContext.getLocalArtifacts().add(project.getKey());
                }
            }
        }
    } catch (AppModelResolverException e) {
        log.error("Failed to load workspace, hot reload will not be available", e);
    }
    terminateIfRunning();
    delegate = new IsolatedDevModeMain();
    Map<String, Object> params = new HashMap<>();
    params.put(DevModeContext.class.getName(), devModeContext);
    params.put(DevModeType.class.getName(), DevModeType.LOCAL);
    delegate.accept(curatedApplication, params);
}
Also used : Path(java.nio.file.Path) ModuleInfo(io.quarkus.deployment.dev.DevModeContext.ModuleInfo) HashMap(java.util.HashMap) AppModelResolverException(io.quarkus.bootstrap.resolver.AppModelResolverException) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) DevModeType(io.quarkus.dev.spi.DevModeType)

Example 3 with AppModelResolverException

use of io.quarkus.bootstrap.resolver.AppModelResolverException in project quarkus by quarkusio.

the class AppModelGradleResolver method resolveArtifact.

private ResolvedDependency resolveArtifact(ArtifactCoords appArtifact) throws AppModelResolverException {
    if (ResolvedDependency.class.isAssignableFrom(appArtifact.getClass())) {
        final ResolvedDependency resolved = (ResolvedDependency) appArtifact;
        if (resolved.isResolved()) {
            return resolved;
        }
    }
    final DefaultDependencyArtifact dep = new DefaultDependencyArtifact();
    dep.setExtension(appArtifact.getType());
    dep.setType(appArtifact.getType());
    dep.setName(appArtifact.getArtifactId());
    if (appArtifact.getClassifier() != null) {
        dep.setClassifier(appArtifact.getClassifier());
    }
    final DefaultExternalModuleDependency gradleDep = new DefaultExternalModuleDependency(appArtifact.getGroupId(), appArtifact.getArtifactId(), appArtifact.getVersion(), null);
    gradleDep.addArtifact(dep);
    final Configuration detachedConfig = project.getConfigurations().detachedConfiguration(gradleDep);
    final ResolvedConfiguration rc = detachedConfig.getResolvedConfiguration();
    Set<ResolvedArtifact> resolvedArtifacts;
    try {
        resolvedArtifacts = rc.getResolvedArtifacts();
    } catch (ResolveException e) {
        throw new AppModelResolverException("Failed to resolve " + appArtifact, e);
    }
    for (ResolvedArtifact a : resolvedArtifacts) {
        if (appArtifact.getArtifactId().equals(a.getName()) && appArtifact.getType().equals(a.getType()) && (a.getClassifier() == null ? appArtifact.getClassifier() == null : a.getClassifier().equals(appArtifact.getClassifier())) && appArtifact.getGroupId().equals(a.getModuleVersion().getId().getGroup())) {
            final String version = appArtifact.getVersion().equals(a.getModuleVersion().getId().getVersion()) ? appArtifact.getVersion() : a.getModuleVersion().getId().getVersion();
            return new ResolvedArtifactDependency(appArtifact.getGroupId(), appArtifact.getArtifactId(), appArtifact.getClassifier(), appArtifact.getType(), version, a.getFile().toPath());
        }
    }
    throw new AppModelResolverException("Failed to resolve " + appArtifact);
}
Also used : ResolveException(org.gradle.api.artifacts.ResolveException) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) DefaultDependencyArtifact(org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Configuration(org.gradle.api.artifacts.Configuration) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) AppModelResolverException(io.quarkus.bootstrap.resolver.AppModelResolverException) ResolvedArtifactDependency(io.quarkus.maven.dependency.ResolvedArtifactDependency) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency)

Example 4 with AppModelResolverException

use of io.quarkus.bootstrap.resolver.AppModelResolverException in project quarkus by quarkusio.

the class QuarkusBuild method buildQuarkus.

@TaskAction
public void buildQuarkus() {
    final ApplicationModel appModel;
    try {
        appModel = extension().getAppModelResolver().resolveModel(new GACTV(getProject().getGroup().toString(), getProject().getName(), getProject().getVersion().toString()));
    } catch (AppModelResolverException e) {
        throw new GradleException("Failed to resolve Quarkus application model for " + getProject().getPath(), e);
    }
    final Properties effectiveProperties = getBuildSystemProperties(appModel.getAppArtifact());
    if (ignoredEntries != null && ignoredEntries.size() > 0) {
        String joinedEntries = String.join(",", ignoredEntries);
        effectiveProperties.setProperty("quarkus.package.user-configured-ignored-entries", joinedEntries);
    }
    exportCustomManifestProperties(effectiveProperties);
    try (CuratedApplication appCreationContext = QuarkusBootstrap.builder().setBaseClassLoader(getClass().getClassLoader()).setExistingModel(appModel).setTargetDirectory(getProject().getBuildDir().toPath()).setBaseName(extension().finalName()).setBuildSystemProperties(effectiveProperties).setAppArtifact(appModel.getAppArtifact()).setLocalProjectDiscovery(false).setIsolateDeployment(true).build().bootstrap()) {
        // Processes launched from within the build task of Gradle (daemon) lose content
        // generated on STDOUT/STDERR by the process (see https://github.com/gradle/gradle/issues/13522).
        // We overcome this by letting build steps know that the STDOUT/STDERR should be explicitly
        // streamed, if they need to make available that generated data.
        // The io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabled$Factory
        // does the necessary work to generate such a build item which the build step(s) can rely on
        appCreationContext.createAugmentor("io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabled$Factory", Collections.emptyMap()).createProductionApplication();
    } catch (BootstrapException e) {
        throw new GradleException("Failed to build a runnable JAR", e);
    }
}
Also used : CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) AppModelResolverException(io.quarkus.bootstrap.resolver.AppModelResolverException) GradleException(org.gradle.api.GradleException) BootstrapException(io.quarkus.bootstrap.BootstrapException) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) GACTV(io.quarkus.maven.dependency.GACTV) Properties(java.util.Properties) TaskAction(org.gradle.api.tasks.TaskAction)

Example 5 with AppModelResolverException

use of io.quarkus.bootstrap.resolver.AppModelResolverException in project quarkus by quarkusio.

the class GradleApplicationModelBuilder method resolvePlatformImports.

private PlatformImports resolvePlatformImports(Project project, List<org.gradle.api.artifacts.Dependency> deploymentDeps) {
    final Configuration boms = project.getConfigurations().detachedConfiguration(deploymentDeps.toArray(new org.gradle.api.artifacts.Dependency[0]));
    final PlatformImportsImpl platformImports = new PlatformImportsImpl();
    boms.getResolutionStrategy().eachDependency(d -> {
        final String group = d.getTarget().getGroup();
        final String name = d.getTarget().getName();
        if (name.endsWith(BootstrapConstants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX)) {
            platformImports.addPlatformDescriptor(group, name, d.getTarget().getVersion(), "json", d.getTarget().getVersion());
        } else if (name.endsWith(BootstrapConstants.PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX)) {
            final DefaultDependencyArtifact dep = new DefaultDependencyArtifact();
            dep.setExtension("properties");
            dep.setType("properties");
            dep.setName(name);
            final DefaultExternalModuleDependency gradleDep = new DefaultExternalModuleDependency(group, name, d.getTarget().getVersion(), null);
            gradleDep.addArtifact(dep);
            for (ResolvedArtifact a : project.getConfigurations().detachedConfiguration(gradleDep).getResolvedConfiguration().getResolvedArtifacts()) {
                if (a.getName().equals(name)) {
                    try {
                        platformImports.addPlatformProperties(group, name, null, "properties", d.getTarget().getVersion(), a.getFile().toPath());
                    } catch (AppModelResolverException e) {
                        throw new GradleException("Failed to import platform properties " + a.getFile(), e);
                    }
                    break;
                }
            }
        }
    });
    boms.getResolvedConfiguration();
    return platformImports;
}
Also used : DefaultDependencyArtifact(org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Configuration(org.gradle.api.artifacts.Configuration) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) AppModelResolverException(io.quarkus.bootstrap.resolver.AppModelResolverException) GradleException(org.gradle.api.GradleException) PlatformImportsImpl(io.quarkus.bootstrap.model.PlatformImportsImpl) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) Dependency(io.quarkus.maven.dependency.Dependency) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency)

Aggregations

AppModelResolverException (io.quarkus.bootstrap.resolver.AppModelResolverException)7 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)4 ResolvedDependency (io.quarkus.maven.dependency.ResolvedDependency)4 IOException (java.io.IOException)3 GACTV (io.quarkus.maven.dependency.GACTV)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 GradleException (org.gradle.api.GradleException)2 Configuration (org.gradle.api.artifacts.Configuration)2 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)2 ResolvedConfiguration (org.gradle.api.artifacts.ResolvedConfiguration)2 DefaultDependencyArtifact (org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact)2 DefaultExternalModuleDependency (org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency)2 BootstrapConstants (io.quarkus.bootstrap.BootstrapConstants)1 BootstrapException (io.quarkus.bootstrap.BootstrapException)1 CuratedApplication (io.quarkus.bootstrap.app.CuratedApplication)1 CurationResult (io.quarkus.bootstrap.app.CurationResult)1 PlatformImportsImpl (io.quarkus.bootstrap.model.PlatformImportsImpl)1