Search in sources :

Example 11 with ProjectRequirements

use of io.fabric8.deployer.dto.ProjectRequirements in project fabric8 by jboss-fuse.

the class DeployToProfileMojo method uploadRequirements.

protected DeployResults uploadRequirements(J4pClient client, ProjectRequirements requirements) throws Exception {
    String json = DtoHelper.getMapper().writeValueAsString(requirements);
    ObjectName mbeanName = ProjectDeployerImpl.OBJECT_NAME;
    getLog().info("Updating " + (requirements.isAbstractProfile() ? "abstract " : "") + "profile: " + requirements.getProfileId() + " with parent profile(s): " + requirements.getParentProfiles() + (requirements.isUseResolver() ? " using OSGi resolver" : "") + (requirements.isLocked() ? " locked" : ""));
    getLog().info("About to invoke mbean " + mbeanName + " on jolokia URL: " + jolokiaUrl + " with user: " + fabricServer.getUsername());
    getLog().debug("JSON: " + json);
    try {
        // Append bundles to existing profile bundles if we're not running the plugin at project root
        Boolean appendBundles = !mavenSession.getExecutionRootDirectory().equalsIgnoreCase(project.getBasedir().toString());
        J4pExecRequest request = new J4pExecRequest(mbeanName, "deployProjectJsonMergeOption(java.lang.String,boolean)", json, appendBundles);
        J4pResponse<J4pExecRequest> response = client.execute(request, "POST");
        Object value = response.getValue();
        if (value == null) {
            return null;
        } else {
            DeployResults answer = DtoHelper.getMapper().reader(DeployResults.class).readValue(value.toString());
            if (answer != null) {
                String profileUrl = answer.getProfileUrl();
                if (profileUrl != null) {
                    getLog().info("");
                    getLog().info("Profile page: " + profileUrl);
                    getLog().info("");
                } else {
                    getLog().info("Result: " + answer);
                }
            } else {
                getLog().info("Result: " + value);
            }
            return answer;
        }
    } catch (J4pRemoteException e) {
        if (e.getMessage().contains(".InstanceNotFoundException")) {
            throw new MojoExecutionException("Could not find the mbean " + mbeanName + " in the JVM for " + jolokiaUrl + ". Are you sure this JVM is running the Fabric8 console?");
        } else {
            getLog().error("Failed to invoke mbean " + mbeanName + " on jolokia URL: " + jolokiaUrl + " with user: " + fabricServer.getUsername() + ". Error: " + e.getErrorType());
            getLog().error("Stack: " + e.getRemoteStackTrace());
            throw e;
        }
    }
}
Also used : J4pRemoteException(org.jolokia.client.exception.J4pRemoteException) DeployResults(io.fabric8.deployer.dto.DeployResults) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) J4pExecRequest(org.jolokia.client.request.J4pExecRequest) ObjectName(javax.management.ObjectName)

Example 12 with ProjectRequirements

use of io.fabric8.deployer.dto.ProjectRequirements in project fabric8 by jboss-fuse.

the class AbstractProfileMojo method addProjectArtifactBundle.

protected void addProjectArtifactBundle(ProjectRequirements requirements) throws MojoFailureException {
    DependencyDTO rootDependency = requirements.getRootDependency();
    if (rootDependency != null) {
        // we need url with type, so when we deploy war files the mvn url is correct
        StringBuilder urlBuffer = new StringBuilder(rootDependency.toBundleUrl());
        String apparentType = rootDependency.getType();
        String apparentClassifier = rootDependency.getClassifier();
        for (String omit : OMITTED_BUNDLE_TYPES) {
            if (omit.equals(apparentType)) {
                apparentType = null;
                break;
            }
        }
        handleArtifactBundleType(urlBuffer, apparentType);
        handleArtifactBundleClassifier(urlBuffer, apparentClassifier);
        String urlString = urlBuffer.toString();
        if (!requirements.getBundles().contains(urlString)) {
            requirements.getBundles().add(urlString);
        }
    }
}
Also used : DependencyDTO(io.fabric8.deployer.dto.DependencyDTO)

Example 13 with ProjectRequirements

use of io.fabric8.deployer.dto.ProjectRequirements in project fabric8 by jboss-fuse.

the class CreateProfileZipMojo method generateZip.

protected void generateZip() throws DependencyTreeBuilderException, MojoExecutionException, IOException, MojoFailureException {
    ProjectRequirements requirements = new ProjectRequirements();
    DependencyDTO rootDependency = null;
    if (isIncludeArtifact()) {
        rootDependency = loadRootDependency();
        requirements.setRootDependency(rootDependency);
    }
    configureRequirements(requirements);
    if (isIncludeArtifact()) {
        addProjectArtifactBundle(requirements);
    }
    File profileBuildDir = createProfileBuildDir(requirements.getProfileId());
    boolean hasConfigDir = profileConfigDir.isDirectory();
    if (hasConfigDir) {
        copyProfileConfigFiles(profileBuildDir, profileConfigDir);
    } else {
        getLog().info("The profile configuration files directory " + profileConfigDir + " doesn't exist, so not copying any additional project documentation or configuration files");
    }
    // to avoid generating dummy profiles for parent poms
    if (hasConfigDir || rootDependency != null || notEmpty(requirements.getBundles()) || notEmpty(requirements.getFeatures()) || notEmpty(requirements.getFeatureRepositories())) {
        if (includeReadMe) {
            copyReadMe(project.getFile().getParentFile(), profileBuildDir);
        }
        if (generateSummaryFile) {
            String description = project.getDescription();
            if (Strings.isNotBlank(description)) {
                File summaryMd = new File(profileBuildDir, "Summary.md");
                summaryMd.getParentFile().mkdirs();
                if (!summaryMd.exists()) {
                    byte[] bytes = description.getBytes();
                    Files.copy(new ByteArrayInputStream(bytes), new FileOutputStream(summaryMd));
                }
            }
        }
        if (isIncludeArtifact()) {
            writeProfileRequirements(requirements, profileBuildDir);
        }
        generateFabricAgentProperties(requirements, new File(profileBuildDir, "io.fabric8.agent.properties"));
        // only generate if its a WAR project
        if ("war".equals(project.getPackaging())) {
            generateFabricContextPathProperties(requirements, new File(profileBuildDir, Constants.WEB_CONTEXT_PATHS_PID + ".properties"));
        }
        Zips.createZipFile(getLog(), buildDir, outputFile);
        projectHelper.attachArtifact(project, artifactType, artifactClassifier, outputFile);
        getLog().info("Created profile zip file: " + outputFile);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) File(java.io.File)

Example 14 with ProjectRequirements

use of io.fabric8.deployer.dto.ProjectRequirements in project fabric8 by jboss-fuse.

the class CreateScriptMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        DependencyDTO rootDependency = loadRootDependency();
        ProjectRequirements requirements = new ProjectRequirements();
        requirements.setRootDependency(rootDependency);
        configureRequirements(requirements);
        addProjectArtifactBundle(requirements);
        generateScript(requirements, outputFile);
        projectHelper.attachArtifact(project, artifactType, artifactClassifier, outputFile);
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("Error executing", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 15 with ProjectRequirements

use of io.fabric8.deployer.dto.ProjectRequirements in project fabric8 by jboss-fuse.

the class MavenProxyServletSupport method toProjectRequirements.

protected ProjectRequirements toProjectRequirements(UploadContext context) {
    ProjectRequirements requirements = new ProjectRequirements();
    requirements.setParentProfiles(Collections.<String>emptyList());
    String url = String.format("mvn:%s/%s/%s", context.getGroupId(), context.getArtifactId(), context.getVersion());
    if (!"jar".equals(context.getType())) {
        url += "/" + context.getType();
    }
    requirements.setBundles(Collections.singletonList(url));
    return requirements;
}
Also used : ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements)

Aggregations

ProjectRequirements (io.fabric8.deployer.dto.ProjectRequirements)11 DependencyDTO (io.fabric8.deployer.dto.DependencyDTO)6 Profile (io.fabric8.api.Profile)4 DeployResults (io.fabric8.deployer.dto.DeployResults)4 ProfileBuilder (io.fabric8.api.ProfileBuilder)3 ProfileService (io.fabric8.api.ProfileService)3 File (java.io.File)3 IOException (java.io.IOException)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 Version (io.fabric8.api.Version)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 J4pRemoteException (org.jolokia.client.exception.J4pRemoteException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DownloadManager (io.fabric8.agent.download.DownloadManager)1 Feature (io.fabric8.agent.model.Feature)1 FabricRequirements (io.fabric8.api.FabricRequirements)1 ProfileRegistry (io.fabric8.api.ProfileRegistry)1 ProfileRequirements (io.fabric8.api.ProfileRequirements)1 RuntimeProperties (io.fabric8.api.RuntimeProperties)1 AbstractRuntimeProperties (io.fabric8.api.scr.AbstractRuntimeProperties)1