org.eclipse.aether.resolution.ArtifactResolutionException Java Examples

The following examples show how to use org.eclipse.aether.resolution.ArtifactResolutionException. 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: 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 #3
Source File: LinkageMonitorTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildModelWithSnapshotBom_noSnapshotUpdate()
    throws ModelBuildingException, ArtifactResolutionException {
  Model model =
      LinkageMonitor.buildModelWithSnapshotBom(
          system, session, "com.google.cloud:libraries-bom:2.2.1", ImmutableMap.of());
  List<Dependency> dependencies = model.getDependencyManagement().getDependencies();

  assertEquals(
      "There should not be a duplicate",
      dependencies.stream().distinct().count(),
      dependencies.size());

  // This number is different from the number appearing in BOM dashboard because model from
  // buildModelWithSnapshotBom still contains unnecessary artifacts that would be filtered by
  // RepositoryUtility.shouldSkipBomMember
  assertEquals(214, dependencies.size());
}
 
Example #4
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 #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: ClassPathEntryTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetClassNames_innerClasses()
    throws IOException, ArtifactResolutionException, URISyntaxException {

  ClassPathEntry entry = TestHelper.classPathEntryOfResource(
      "testdata/conscrypt-openjdk-uber-1.4.2.jar");
  ImmutableSet<String> classFileNames = entry.getFileNames();
  Truth.assertThat(classFileNames).containsAtLeast(
      "org.conscrypt.OpenSSLSignature$1",
      "org.conscrypt.OpenSSLContextImpl$TLSv1",
      "org.conscrypt.TrustManagerImpl$1",
      "org.conscrypt.PeerInfoProvider",
      "org.conscrypt.PeerInfoProvider$1",
      "org.conscrypt.ExternalSession$Provider",
      "org.conscrypt.OpenSSLMac");
}
 
Example #7
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 #8
Source File: ClassPathEntryTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetClassNames() throws IOException, ArtifactResolutionException {
  // copy into the local repository so we can read the jar file
  Artifact artifact = resolveArtifact("com.google.truth.extensions:truth-java8-extension:1.0.1");
  
  ClassPathEntry entry = new ClassPathEntry(artifact);
  ImmutableSet<String> classFileNames = entry.getFileNames();
  
  Truth.assertThat(classFileNames).containsExactly(
      "com.google.common.truth.IntStreamSubject",
      "com.google.common.truth.LongStreamSubject",
      "com.google.common.truth.OptionalDoubleSubject",
      "com.google.common.truth.OptionalSubject",
      "com.google.common.truth.OptionalIntSubject",
      "com.google.common.truth.OptionalLongSubject",
      "com.google.common.truth.PathSubject",
      "com.google.common.truth.Truth8",
      "com.google.common.truth.StreamSubject");
}
 
Example #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
Source File: DependencyResolverTest.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Test
public void resolveArtifactsAndDependencies() throws DependencyResolutionException, ArtifactResolutionException {
    DependencyResolverFactory factory = new DependencyResolverFactory();
    DependencyResolver resolver = factory.get();

    Map<String, List<Artifact>> sets = resolver.resolveDependencySets("org.eclipse.aether:aether-util:[0,)", "org.eclipse.aether:aether-spi");

    int i = 0;
    for (Map.Entry<String, List<Artifact>> set : sets.entrySet()) {
        logger.debug("{}", i++);
        List<File> results = resolver.resolveArtifactsAndDependencies(set.getValue());

        logger.debug(set.getKey());

        for (File result : results) {
            logger.debug("{}", result);
        }
    }
}
 
Example #19
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 #20
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 #21
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 #22
Source File: PinpointPluginTestSuite.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
private List<PinpointPluginTestInstance> createCasesWithDependencies(PinpointPluginTestContext context) throws ArtifactResolutionException, DependencyResolutionException {
    List<PinpointPluginTestInstance> cases = new ArrayList<PinpointPluginTestInstance>();

    DependencyResolver resolver = getDependencyResolver(repositories);
    Map<String, List<Artifact>> dependencyCases = resolver.resolveDependencySets(dependencies);

    for (Map.Entry<String, List<Artifact>> dependencyCase : dependencyCases.entrySet()) {
        List<String> libs = new ArrayList<String>();

        for (File lib : resolver.resolveArtifactsAndDependencies(dependencyCase.getValue())) {
            libs.add(lib.getAbsolutePath());
        }

        if (testOnSystemClassLoader) {
            cases.add(new NormalPluginTestCase(context, dependencyCase.getKey(), libs, true));
        }

        if (testOnChildClassLoader) {
            cases.add(new NormalPluginTestCase(context, dependencyCase.getKey(), libs, false));
        }
    }

    return cases;
}
 
Example #23
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 #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: AbstractPinpointPluginTestSuite.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public AbstractPinpointPluginTestSuite(Class<?> testClass) throws InitializationError, ArtifactResolutionException, DependencyResolutionException {
    super(testClass, Collections.<Runner> emptyList());

    PinpointAgent agent = testClass.getAnnotation(PinpointAgent.class);
    this.agentJar = resolveAgentPath(agent);

    PinpointConfig config = testClass.getAnnotation(PinpointConfig.class);
    this.configFile = config == null ? null : resolveConfigFileLocation(config.value());

    PinpointProfile profile = testClass.getAnnotation(PinpointProfile.class);
    this.profile = resolveProfile(profile);

    JvmArgument jvmArgument = testClass.getAnnotation(JvmArgument.class);
    this.jvmArguments = getJvmArguments(jvmArgument);

    JvmVersion jvmVersion = testClass.getAnnotation(JvmVersion.class);
    this.jvmVersions = jvmVersion == null ? new int[] { NO_JVM_VERSION } : jvmVersion.value();

    ImportPlugin importPlugin = testClass.getAnnotation(ImportPlugin.class);
    this.importPluginIds = getImportPlugin(importPlugin);

    this.requiredLibraries = getClassPathList(REQUIRED_CLASS_PATHS);
    this.mavenDependencyLibraries = getClassPathList(MAVEN_DEPENDENCY_CLASS_PATHS);
    this.testClassLocation = resolveTestClassLocation(testClass);
    this.debug = isDebugMode();
}
 
Example #26
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 #27
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 #28
Source File: PinpointPluginTestSuite.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public PinpointPluginTestSuite(Class<?> testClass, boolean sharedProcess) throws InitializationError, ArtifactResolutionException, DependencyResolutionException {
    super(testClass);

    OnClassLoader onClassLoader = testClass.getAnnotation(OnClassLoader.class);
    this.testOnChildClassLoader = onClassLoader == null ? true : onClassLoader.child();
    this.testOnSystemClassLoader = onClassLoader == null ? false : onClassLoader.system();

    Dependency deps = testClass.getAnnotation(Dependency.class);
    this.dependencies = deps == null ? null : deps.value();

    TestRoot lib = testClass.getAnnotation(TestRoot.class);

    if (lib == null) {
        this.libraryPath = null;
        this.librarySubDirs = null;
    } else {
        String path = lib.value();

        if (path.isEmpty()) {
            path = lib.path();
        }

        this.libraryPath = path;
        this.librarySubDirs = lib.libraryDir();
    }

    if (deps != null && lib != null) {
        throw new IllegalArgumentException("@Dependency and @TestRoot can not annotate a class at the same time");
    }

    Repository repos = testClass.getAnnotation(Repository.class);
    this.repositories = repos == null ? new String[0] : repos.value();
    this.sharedProcess = sharedProcess;
}
 
Example #29
Source File: MavenArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 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(),
                spec.type(), spec.version());

        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) {
                System.err.println("ERR " + e);
                e.printStackTrace();
            }
        }
    }

    return spec.file != null ? spec : null;

}
 
Example #30
Source File: Resolver.java    From buck with Apache License 2.0 5 votes vote down vote up
private void downloadSources(Artifact artifact, Path project, Prebuilt library)
    throws IOException {
  Artifact srcs = new SubArtifact(artifact, "sources", "jar");
  try {
    Path relativePath = resolveArtifact(srcs, project);
    library.setSourceJar(relativePath);
  } catch (ArtifactResolutionException e) {
    System.err.println("Skipping sources for: " + srcs);
  }
}