org.eclipse.aether.resolution.ArtifactRequest Java Examples

The following examples show how to use org.eclipse.aether.resolution.ArtifactRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractVertxMojo.java    From vertx-maven-plugin with Apache License 2.0 7 votes vote down vote up
/**
 * this method resolves maven artifact from all configured repositories using the maven coordinates
 *
 * @param artifact - the maven coordinates of the artifact
 * @return {@link Optional} {@link File} pointing to the resolved artifact in local repository
 */
protected Optional<File> resolveArtifact(String artifact) {
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(new org.eclipse.aether.artifact.DefaultArtifact(artifact));
    try {
        ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, artifactRequest);
        if (artifactResult.isResolved()) {
            getLog().debug("Resolved :" + artifactResult.getArtifact().getArtifactId());
            return Optional.of(artifactResult.getArtifact().getFile());
        } else {
            getLog().error("Unable to resolve:" + artifact);
        }
    } catch (ArtifactResolutionException e) {
        getLog().error("Unable to resolve:" + artifact);
    }

    return Optional.empty();
}
 
Example #2
Source File: AbstractLibertySupport.java    From ci.maven with Apache License 2.0 6 votes vote down vote up
private File resolveArtifactFile(org.eclipse.aether.artifact.Artifact aetherArtifact) throws MojoExecutionException {
    ArtifactRequest req = new ArtifactRequest().setRepositories(this.repositories).setArtifact(aetherArtifact);
    ArtifactResult resolutionResult = null;
    
    try {
        resolutionResult = this.repositorySystem.resolveArtifact(this.repoSession, req);
        if (!resolutionResult.isResolved()) {
            throw new MojoExecutionException("Unable to resolve artifact: " + aetherArtifact.getGroupId() + ":"
                    + aetherArtifact.getArtifactId() + ":" + aetherArtifact.getVersion());
        }
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Unable to resolve artifact: " + aetherArtifact.getGroupId() + ":"
                + aetherArtifact.getArtifactId() + ":" + aetherArtifact.getVersion(), e);
    }
    
    File artifactFile = resolutionResult.getArtifact().getFile();
    
    return artifactFile;
}
 
Example #3
Source File: SimpleModelResolver.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
        throws UnresolvableModelException {
    Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version);

    try {
        ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null);
        pomArtifact = system.resolveArtifact(session, request).getArtifact();
    } catch (org.eclipse.aether.resolution.ArtifactResolutionException ex) {
        throw new UnresolvableModelException(ex.getMessage(), groupId, artifactId, version, ex);
    } 

    File pomFile = pomArtifact.getFile();

    return new FileModelSource(pomFile);
}
 
Example #4
Source File: BuildDependencyGraphVisitor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void visitLeave(DependencyNode node) {
    final Dependency dep = node.getDependency();
    if (dep == null) {
        return;
    }
    final Artifact artifact = dep.getArtifact();
    if (artifact.getFile() == null) {
        requests.add(new ArtifactRequest(node));
    }
    if (deploymentNode != null) {
        if (runtimeNode == null && !appDeps.contains(new AppArtifactKey(artifact.getGroupId(),
                artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension()))) {
            //we never want optional deps on the deployment CP
            if (!node.getDependency().isOptional()) {
                deploymentDepNodes.add(node);
            }
        } else if (runtimeNode == node) {
            runtimeNode = null;
            runtimeArtifact = null;
        }
        if (deploymentNode == node) {
            deploymentNode = null;
        }
    }
}
 
Example #5
Source File: CommonBehaviorMojo.java    From botsing with Apache License 2.0 6 votes vote down vote up
private File getArtifactFile(DefaultArtifact aetherArtifact) throws MojoExecutionException {

		ArtifactRequest req = new ArtifactRequest().setRepositories(this.repositories).setArtifact(aetherArtifact);
		ArtifactResult resolutionResult;
		try {
			resolutionResult = this.repoSystem.resolveArtifact(this.repoSession, req);

		} catch (ArtifactResolutionException e) {
			throw new MojoExecutionException("Artifact " + aetherArtifact.getArtifactId() + " could not be resolved.",
					e);
		}

		// The file should exists, but we never know.
		File file = resolutionResult.getArtifact().getFile();
		if (file == null || !file.exists()) {
			getLog().warn("Artifact " + aetherArtifact.getArtifactId()
					+ " has no attached file. Its content will not be copied in the target model directory.");
		}

		return file;
	}
 
Example #6
Source File: AbstractMavenArtifactRepositoryManager.java    From galleon with Apache License 2.0 6 votes vote down vote up
@Override
public void resolve(MavenArtifact artifact) throws MavenUniverseException {
    if (artifact.isResolved()) {
        throw new MavenUniverseException("Artifact is already resolved");
    }
    final ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(),
            artifact.getExtension(), artifact.getVersion()));

    request.setRepositories(getRepositories());

    final ArtifactResult result;
    try {
        result = repoSystem.resolveArtifact(getSession(), request);
    } catch (Exception e) {
        throw new MavenUniverseException(FpMavenErrors.artifactResolution(request.getArtifact().toString()), e);
    }
    if (!result.isResolved()) {
        throw new MavenUniverseException(FpMavenErrors.artifactResolution(request.getArtifact().toString()));
    }
    if (result.isMissing()) {
        throw new MavenUniverseException(FpMavenErrors.artifactMissing(request.getArtifact().toString()));
    }
    artifact.setPath(Paths.get(result.getArtifact().getFile().toURI()));
}
 
Example #7
Source File: SingerMojo.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
private Path findMain() {
    final LocalRepositoryManager lrm = repositorySystemSession.getLocalRepositoryManager();
    final Artifact artifact = new DefaultArtifact(GAV.GROUP, "component-kitap", "fatjar", "jar", GAV.VERSION);
    final File location = new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact));
    if (!location.exists()) {
        final ArtifactRequest artifactRequest =
                new ArtifactRequest().setArtifact(artifact).setRepositories(remoteRepositories);
        try {
            final ArtifactResult result =
                    repositorySystem.resolveArtifact(repositorySystemSession, artifactRequest);
            if (result.isMissing()) {
                throw new IllegalStateException("Can't find " + artifact);
            }
            return result.getArtifact().getFile().toPath();
        } catch (final ArtifactResolutionException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
    return location.toPath();
}
 
Example #8
Source File: AbstractVertxMojo.java    From vertx-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * this method resolves maven artifact from all configured repositories using the maven coordinates
 *
 * @param artifact - the maven coordinates of the artifact
 * @return {@link Optional} {@link File} pointing to the resolved artifact in local repository
 */
protected Optional<File> resolveArtifact(String artifact) {
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(new org.eclipse.aether.artifact.DefaultArtifact(artifact));
    try {
        ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, artifactRequest);
        if (artifactResult.isResolved()) {
            getLog().debug("Resolved :" + artifactResult.getArtifact().getArtifactId());
            return Optional.of(artifactResult.getArtifact().getFile());
        } else {
            getLog().error("Unable to resolve:" + artifact);
        }
    } catch (ArtifactResolutionException e) {
        getLog().error("Unable to resolve:" + artifact);
    }

    return Optional.empty();
}
 
Example #9
Source File: ArtifactCacheLoader.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Optional<ArtifactResult> load(ArtifactCoordinates coordinates) throws Exception {
  Artifact artifact = new DefaultArtifact(coordinates.toString());

  ArtifactRequest artifactRequest = new ArtifactRequest();
  artifactRequest.setArtifact(artifact);
  artifactRequest.setRepositories(this.remoteProjectRepos);

  ArtifactResult artifactResult;
  try {
    artifactResult = this.repoSystem.resolveArtifact(this.repoSession, artifactRequest);
  } catch (ArtifactResolutionException e) {
    // must not throw the error or log as an error since this is an expected behavior
    artifactResult = null;
  }

  return Optional.fromNullable(artifactResult);
}
 
Example #10
Source File: CachingArtifactResolvingHelper.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private File resolveArtifactFile(ArtifactSpec spec) {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact(spec));

    remoteRepositories.forEach(request::addRepository);

    try {
        ArtifactResult artifactResult = repoSystem.resolveArtifact(session, request);

        return artifactResult.isResolved()
                ? artifactResult.getArtifact().getFile()
                : null;
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #11
Source File: MavenArtifactResolvingHelper.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public ArtifactSpec resolve(ArtifactSpec spec) {
    if (spec.file == null) {
        final DefaultArtifact artifact = new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(),
                typeToExtension(spec.type()), spec.version(), new DefaultArtifactType(spec.type()));

        final LocalArtifactResult localResult = this.session.getLocalRepositoryManager()
                .find(this.session, new LocalArtifactRequest(artifact, this.remoteRepositories, null));
        if (localResult.isAvailable()) {
            spec.file = localResult.getFile();
        } else {
            try {
                final ArtifactResult result = resolver.resolveArtifact(this.session,
                        new ArtifactRequest(artifact, this.remoteRepositories, null));
                if (result.isResolved()) {
                    spec.file = result.getArtifact().getFile();
                }
            } catch (ArtifactResolutionException e) {
                e.printStackTrace();
            }
        }
    }

    return spec.file != null ? spec : null;
}
 
Example #12
Source File: Aether.java    From pro with GNU General Public License v3.0 6 votes vote down vote up
public List<ArtifactDescriptor> download(List<ArtifactInfo> unresolvedArtifacts) throws IOException {
  var repositories = this.remoteRepositories;
  var artifactRequests = unresolvedArtifacts.stream()
      .map(dependency -> {
        ArtifactRequest artifactRequest = new ArtifactRequest();
        artifactRequest.setArtifact(dependency.artifact);
        artifactRequest.setRepositories(repositories);
        return artifactRequest;
      })
      .collect(Collectors.toUnmodifiableList());

  List<ArtifactResult> artifactResults;
  try {
    artifactResults = system.resolveArtifacts(session, artifactRequests);
  } catch (ArtifactResolutionException e) {
    throw new IOException(e);
  }
  
  return artifactResults.stream()
    .map(result -> new ArtifactDescriptor(result.getArtifact()))
    .collect(Collectors.toUnmodifiableList());
}
 
Example #13
Source File: MeecrowaveBundleMojo.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
private File resolve(final String group, final String artifact, final String version, final String classifier) {
    final DefaultArtifact art = new DefaultArtifact(group, artifact, classifier, "jar", version);
    final ArtifactRequest artifactRequest = new ArtifactRequest().setArtifact(art).setRepositories(remoteRepositories);

    final LocalRepositoryManager lrm = session.getLocalRepositoryManager();
    art.setFile(new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifactRequest.getArtifact())));

    try {
        final ArtifactResult result = repositorySystem.resolveArtifact(session, artifactRequest);
        if (result.isMissing()) {
            throw new IllegalStateException("Can't find commons-cli, please add it to the pom.");
        }
        return result.getArtifact().getFile();
    } catch (final ArtifactResolutionException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example #14
Source File: ExternalBomResolver.java    From sundrio with Apache License 2.0 6 votes vote down vote up
private Map<Artifact, Dependency> resolveDependencies(BomImport bom) throws Exception {
    org.eclipse.aether.artifact.Artifact artifact = new org.eclipse.aether.artifact.DefaultArtifact(bom.getGroupId(), bom.getArtifactId(), "pom", bom.getVersion());

    List<RemoteRepository> repositories = remoteRepositories;
    if (bom.getRepository() != null) {
        // Include the additional repository into the copy
        repositories = new LinkedList<RemoteRepository>(repositories);
        RemoteRepository repo = new RemoteRepository.Builder(bom.getArtifactId() + "-repository", "default", bom.getRepository()).build();
        repositories.add(0, repo);
    }

    ArtifactRequest artifactRequest = new ArtifactRequest(artifact, repositories, null);
    system.resolveArtifact(session, artifactRequest); // To get an error when the artifact does not exist

    ArtifactDescriptorRequest req = new ArtifactDescriptorRequest(artifact, repositories, null);
    ArtifactDescriptorResult res = system.readArtifactDescriptor(session, req);

    Map<Artifact, Dependency> mavenDependencies = new LinkedHashMap<Artifact, Dependency>();
    if (res.getManagedDependencies() != null) {
        for (org.eclipse.aether.graph.Dependency dep : res.getManagedDependencies()) {
            mavenDependencies.put(toMavenArtifact(dep), toMavenDependency(dep));
        }
    }

    return mavenDependencies;
}
 
Example #15
Source File: AetherImporter.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Prepare a plain import process
 * <p>
 * Prepare a simple import request with a specific list of coordinates
 * </p>
 */
public static AetherResult preparePlain ( final Path tmpDir, final ImportConfiguration cfg ) throws ArtifactResolutionException
{
    Objects.requireNonNull ( tmpDir );
    Objects.requireNonNull ( cfg );

    final RepositoryContext ctx = new RepositoryContext ( tmpDir, cfg.getRepositoryUrl (), cfg.isAllOptional () );

    // extend

    final List<ArtifactRequest> requests = extendRequests ( cfg.getCoordinates ().stream ().map ( c -> {
        final DefaultArtifact artifact = new DefaultArtifact ( c.toString () );
        return makeRequest ( ctx.getRepositories (), artifact );
    } ), ctx, cfg );

    // process

    return asResult ( resolve ( ctx, requests ), cfg, empty () );
}
 
Example #16
Source File: OpenSourceLicenseCheckMojo.java    From license-check with MIT License 6 votes vote down vote up
/**
 * Uses Aether to retrieve an artifact from the repository.
 *
 * @param coordinates as in groupId:artifactId:version
 * @return the located artifact
 */
Artifact retrieveArtifact(final String coordinates)
{

  final ArtifactRequest request = new ArtifactRequest();
  request.setArtifact(new DefaultArtifact(coordinates));
  request.setRepositories(remoteRepos);

  ArtifactResult result = null;
  try {
    result = repoSystem.resolveArtifact(repoSession, request);
  } catch (final ArtifactResolutionException e) {
    getLog().error("Could not resolve parent artifact (" + coordinates + "): " + e.getMessage());
  }

  if (result != null) {
    return RepositoryUtils.toArtifact(result.getArtifact());
  }
  return null;
}
 
Example #17
Source File: EclipseAetherArtifactResolver.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Path resolve(final RepositorySystemSession session, final List<RemoteRepository> repositories, final ArtifactName name) {
    final ArtifactResult result;
    try {
        final ArtifactRequest request = new ArtifactRequest();
        final Artifact defaultArtifact = new DefaultArtifact(name.getGroupId(), name.getArtifactId(), name.getClassifier(), name.getPackaging(), name.getVersion());
        request.setArtifact(defaultArtifact);
        request.setRepositories(repositories);
        result = repoSystem.resolveArtifact(session, request);
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    if (!result.isResolved()) {
        throw new RuntimeException("Failed to resolve artifact " + name);
    }
    final Artifact artifact = result.getArtifact();
    final File artifactFile;
    if (artifact == null || (artifactFile = artifact.getFile()) == null) {
        throw new RuntimeException("Failed to resolve artifact " + name);
    }
    return artifactFile.toPath();
}
 
Example #18
Source File: DependencyFinder.java    From wisdom with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves the specified artifact (using the : separated syntax).
 *
 * @param mojo   the mojo
 * @param coords the coordinates ot the artifact to resolve using the : separated syntax -
 *               {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}, must not be {@code null}
 * @return the artifact's file if it can be revolved. The file is located in the local maven repository.
 * @throws MojoExecutionException if the artifact cannot be resolved
 */
public static File resolve(AbstractWisdomMojo mojo, String coords) throws MojoExecutionException {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(
            new DefaultArtifact(coords));
    request.setRepositories(mojo.remoteRepos);

    mojo.getLog().info("Resolving artifact " + coords +
            " from " + mojo.remoteRepos);

    ArtifactResult result;
    try {
        result = mojo.repoSystem.resolveArtifact(mojo.repoSession, request);
    } catch (ArtifactResolutionException e) {
        mojo.getLog().error("Cannot resolve " + coords);
        throw new MojoExecutionException(e.getMessage(), e);
    }

    mojo.getLog().info("Resolved artifact " + coords + " to " +
            result.getArtifact().getFile() + " from "
            + result.getRepository());

    return result.getArtifact().getFile();
}
 
Example #19
Source File: DependencyFinder.java    From wisdom with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves the specified artifact (using its GAV, classifier and packaging).
 *
 * @param mojo       the mojo
 * @param groupId    the groupId of the artifact to resolve
 * @param artifactId the artifactId of the artifact to resolve
 * @param version    the version
 * @param type       the type
 * @param classifier the classifier
 * @return the artifact's file if it can be revolved. The file is located in the local maven repository.
 * @throws MojoExecutionException if the artifact cannot be resolved
 */
public static File resolve(AbstractWisdomMojo mojo, String groupId, String artifactId, String version,
                           String type, String classifier) throws MojoExecutionException {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(
            new DefaultArtifact(groupId, artifactId, classifier, type, version));
    request.setRepositories(mojo.remoteRepos);

    mojo.getLog().info("Resolving artifact " + artifactId +
            " from " + mojo.remoteRepos);

    ArtifactResult result;
    try {
        result = mojo.repoSystem.resolveArtifact(mojo.repoSession, request);
    } catch (ArtifactResolutionException e) {
        mojo.getLog().error("Cannot resolve " + groupId + ":" + artifactId + ":" + version + ":" + type);
        throw new MojoExecutionException(e.getMessage(), e);
    }

    mojo.getLog().info("Resolved artifact " + artifactId + " to " +
            result.getArtifact().getFile() + " from "
            + result.getRepository());

    return result.getArtifact().getFile();
}
 
Example #20
Source File: MavenModelResolver.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
         throws UnresolvableModelException
{
   Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version);
   try
   {
      final ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null);
      pomArtifact = system.resolveArtifact(session, request).getArtifact();

   }
   catch (ArtifactResolutionException e)
   {
      throw new UnresolvableModelException("Failed to resolve POM for " + groupId + ":" + artifactId + ":"
               + version + " due to " + e.getMessage(), groupId, artifactId, version, e);
   }

   final File pomFile = pomArtifact.getFile();

   return new FileModelSource(pomFile);

}
 
Example #21
Source File: ArtifactTransporter.java    From jenkins-build-monitor-plugin with MIT License 6 votes vote down vote up
public Path get(@NotNull String groupName, @NotNull String artifactName, @NotNull String version, @NotNull String artifactFileExtension) {
    Artifact artifact = new DefaultArtifact(groupName, artifactName, artifactFileExtension, version);

    RepositorySystem system = newRepositorySystem();
    RepositorySystemSession session = newRepositorySystemSession(system);

    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact);
    request.setRepositories(repositories(system, session));

    try {
        ArtifactResult artifactResult = system.resolveArtifact(session, request);

        artifact = artifactResult.getArtifact();

        Log.info(artifact + " resolved to  " + artifact.getFile());

        return artifact.getFile().toPath();

    } catch (ArtifactResolutionException e) {
        throw new RuntimeException(format("Couldn't resolve a '%s' artifact for '%s:%s:%s'",
                artifactFileExtension, groupName, artifactName, version
        ), e);
    }
}
 
Example #22
Source File: ResolveMojoTest.java    From roboconf-platform with Apache License 2.0 6 votes vote down vote up
private RepositorySystem newRepositorySystem() {

		RepositorySystem repoSystem = new DefaultRepositorySystem() {
			@Override
			public ArtifactResult resolveArtifact( RepositorySystemSession session, ArtifactRequest request )
			throws ArtifactResolutionException {

				ArtifactResult res = new ArtifactResult( request );
				Artifact mavenArtifact = ResolveMojoTest.this.artifactIdToArtifact.get( request.getArtifact().getArtifactId());
				if( mavenArtifact == null )
					throw new ArtifactResolutionException( new ArrayList<ArtifactResult>( 0 ), "Error in test wrapper and settings." );

				org.eclipse.aether.artifact.DefaultArtifact art =
						new org.eclipse.aether.artifact.DefaultArtifact(
								"groupId", "artifactId", "classifier", "extension", "version",
								null, mavenArtifact.getFile());

				res.setArtifact( art );
				return res;
			}
		};

		return repoSystem;
	}
 
Example #23
Source File: DevServerMojo.java    From yawp with MIT License 6 votes vote down vote up
public String resolveDevServerJar() {
    String version = getYawpVersion();
    List<RemoteRepository> allRepos = ImmutableList.copyOf(Iterables.concat(getProjectRepos()));

    ArtifactRequest request = new ArtifactRequest(new DefaultArtifact(YAWP_GROUP_ID, YAWP_DEVSERVER_ARTIFACT_ID, "jar", version), allRepos,
            null);

    ArtifactResult result;
    try {
        result = repoSystem.resolveArtifact(repoSession, request);
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException("Could not resolve DevServer artifact in Maven.");
    }

    return result.getArtifact().getFile().getPath();
}
 
Example #24
Source File: JAXRSAnalyzerMojo.java    From jaxrs-analyzer-maven-plugin with Apache License 2.0 6 votes vote down vote up
private Path fetchDependency(final String artifactIdentifier) throws MojoExecutionException {
    ArtifactRequest request = new ArtifactRequest();
    final DefaultArtifact artifact = new DefaultArtifact(artifactIdentifier);
    request.setArtifact(artifact);
    request.setRepositories(remoteRepos);

    LogProvider.debug("Resolving artifact " + artifact + " from " + remoteRepos);

    ArtifactResult result;
    try {
        result = repoSystem.resolveArtifact(repoSession, request);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

    LogProvider.debug("Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
    return result.getArtifact().getFile().toPath();
}
 
Example #25
Source File: AetherImporter.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Process the actual import request
 * <p>
 * This method takes the import configuration as is and simply tries to
 * import it. Not manipulating the list of coordinates any more
 * </p>
 */
public static Collection<ArtifactResult> processImport ( final Path tmpDir, final ImportConfiguration cfg ) throws ArtifactResolutionException
{
    Objects.requireNonNull ( tmpDir );
    Objects.requireNonNull ( cfg );

    final RepositoryContext ctx = new RepositoryContext ( tmpDir, cfg.getRepositoryUrl () );

    final Collection<ArtifactRequest> requests = new LinkedList<> ();

    for ( final MavenCoordinates coords : cfg.getCoordinates () )
    {
        // main artifact

        final DefaultArtifact main = new DefaultArtifact ( coords.toString () );
        requests.add ( makeRequest ( ctx.getRepositories (), main ) );
    }

    // process

    return ctx.getSystem ().resolveArtifacts ( ctx.getSession (), requests );
}
 
Example #26
Source File: MavenPluginLocation.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public GregorianCalendar getVersionDate(String version) throws ArtifactResolutionException, ParseException, IOException {
//		byte[] jarContent = getJarContent(version, "plugin/version.properties");
//		if (jarContent != null) {
//			Properties properties = new Properties();
//			properties.load(new ByteArrayInputStream(jarContent));
//			String buildDate = properties.getProperty("build.date");
//			DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
//			try {
//				Date parse = dateFormat.parse(buildDate);
//				GregorianCalendar gregorianCalendar = new GregorianCalendar();
//				gregorianCalendar.setTimeInMillis(parse.getTime());
//				return gregorianCalendar;
//			} catch (ParseException e) {
//				return null;
//			}
//		}
//		return null;

		Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "version", "properties", version.toString());
		
		ArtifactRequest request = new ArtifactRequest();
		request.setArtifact(versionArtifact);
		request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
		ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
		
		byte[] bytes = FileUtils.readFileToByteArray(resolveArtifact.getArtifact().getFile());
		
		Properties properties = new Properties();
		properties.load(new ByteArrayInputStream(bytes));
		String buildDate = properties.getProperty("build.date");
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
		try {
			Date parse = dateFormat.parse(buildDate);
			GregorianCalendar gregorianCalendar = new GregorianCalendar();
			gregorianCalendar.setTimeInMillis(parse.getTime());
			return gregorianCalendar;
		} catch (ParseException e) {
			return null;
		}
	}
 
Example #27
Source File: MavenPluginLocation.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public Path getVersionJar(String version) throws ArtifactResolutionException {
	Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "jar", version.toString());
	
	ArtifactRequest request = new ArtifactRequest();
	request.setArtifact(versionArtifact);
	request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
	ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
	
	return resolveArtifact.getArtifact().getFile().toPath();
}
 
Example #28
Source File: MavenPluginLocation.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public byte[] getVersionIcon(String version) throws ArtifactResolutionException, IOException {
	Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "icon", "png", version.toString());
	
	ArtifactRequest request = new ArtifactRequest();
	request.setArtifact(versionArtifact);
	request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
	ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
	
	return FileUtils.readFileToByteArray(resolveArtifact.getArtifact().getFile());
}
 
Example #29
Source File: MavenPluginLocation.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public String getLatestVersionString() {
	Artifact lastArt = new DefaultArtifact(groupId, artifactId, "jar", "LATEST");

	ArtifactRequest request = new ArtifactRequest();
	request.setArtifact(lastArt);
	request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
	
	try {
		ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
		return resolveArtifact.getArtifact().getVersion();
	} catch (ArtifactResolutionException e1) {
		e1.printStackTrace();
	}
	return null;
}
 
Example #30
Source File: MavenPluginLocation.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public byte[] getVersionPluginXml(String version) throws ArtifactResolutionException, IOException {
//		return getJarContent(version, "plugin/plugin.xml");

		Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "plugin", "xml", version.toString());
		
		ArtifactRequest request = new ArtifactRequest();
		request.setArtifact(versionArtifact);
		request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
		ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
		
		byte[] bytes = FileUtils.readFileToByteArray(resolveArtifact.getArtifact().getFile());
		return bytes;
	}