Skip to content

Commit

Permalink
Merge pull request fabric8io#254 from davsclaus/252
Browse files Browse the repository at this point in the history
Jube maven plugin should be able to autodownload the jube image
  • Loading branch information
davsclaus committed Mar 17, 2015
2 parents fc8cece + 5de46fd commit 38f0d89
Showing 1 changed file with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@
*/
package io.fabric8.jube.maven;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import io.fabric8.jube.util.ImageMavenCoords;
import io.fabric8.jube.util.InstallHelper;
import io.fabric8.utils.Objects;
import io.fabric8.utils.Zips;

import org.apache.commons.io.FileUtils;
import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
Expand All @@ -45,19 +53,12 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.shared.filtering.MavenFileFilter;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static io.fabric8.utils.PropertiesHelper.findPropertiesWithPrefix;

/**
Expand Down Expand Up @@ -146,7 +147,7 @@ public class BuildMojo extends AbstractMojo {
private ArtifactResolver artifactResolver;

@Component
private ArtifactFactory artifactFactory;
private RepositorySystem repositorySystem;

@Component
private ArtifactRepositoryFactory artifactRepositoryFactory;
Expand Down Expand Up @@ -316,14 +317,23 @@ protected void unpackBaseImage(File buildDir, boolean useDefaultPrefix) throws E

ImageMavenCoords baseImageCoords = ImageMavenCoords.parse(imageName, useDefaultPrefix);
String coords = baseImageCoords.getAetherCoords();
getLog().info("Looking up Jube: " + coords);
Artifact artifact = artifactFactory.createArtifactWithClassifier(baseImageCoords.getGroupId(),

Artifact artifact = repositorySystem.createArtifactWithClassifier(baseImageCoords.getGroupId(),
baseImageCoords.getArtifactId(), baseImageCoords.getVersion(), baseImageCoords.getType(),
baseImageCoords.getClassifier());
getLog().info("Resolving Jube image: " + artifact);

artifactResolver.resolve(artifact, pomRemoteRepositories, localRepository);
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setLocalRepository(localRepository);
request.setRemoteRepositories(pomRemoteRepositories);

ArtifactResolutionResult result = artifactResolver.resolve(request);
if (!result.isSuccess()) {
throw new ArtifactNotFoundException("Cannot download Jube image", artifact);
}

System.out.println(artifact.getFile());
getLog().info("Resolved Jube image: " + artifact);

if (artifact.getFile() != null) {
File file = artifact.getFile();
Expand Down

0 comments on commit 38f0d89

Please sign in to comment.