Java Code Examples for org.eclipse.aether.artifact.Artifact#getArtifactId()

The following examples show how to use org.eclipse.aether.artifact.Artifact#getArtifactId() . 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: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private String ScopeConflict( DependencyNode node )
{
    Artifact artifact = node.getArtifact();
    List<String> scopes = Arrays.asList( "compile", "provided", "runtime", "test", "system" );

    for( String scope:scopes )
    {
        String coordinate = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
                artifact.getExtension() + ":" + artifact.getVersion() + ":" + scope;
        if( coordinateStrings.contains( coordinate ) )
        {
            return scope;
        }
    }
    // check for scopeless, this probably can't happen
    return null;
}
 
Example 2
Source File: ArtifactRetriever.java    From maven-repository-tools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Iterate through the provided artifact coordinates to retrieve and pull additional artifact such as
 * jar for bundle packaging, jar for aar packaging and so on as required. And get them even if not specified.
 * @param artifactCoordinates
 */
private void getAdditionalArtifactsForRequest( List<String> artifactCoordinates )
{
  List<Artifact> artifacts = new ArrayList<Artifact>();
  for ( String artifactCoordinate : artifactCoordinates )
  {
      artifacts.add( new DefaultArtifact( artifactCoordinate ) );
  }
  for ( Artifact artifact : artifacts )
  {
    String extension = artifact.getExtension();
    if ( MavenConstants.packagingUsesJar( extension ) )
    {
      Gav gav = new Gav( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
          artifact.getExtension() );
      getJar( gav );
    }
  }
}
 
Example 3
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static AppArtifact toAppArtifact(Artifact artifact) {
    final AppArtifact appArtifact = new AppArtifact(artifact.getGroupId(), artifact.getArtifactId(),
            artifact.getClassifier(), artifact.getExtension(), artifact.getVersion());
    final File file = artifact.getFile();
    if (file != null) {
        appArtifact.setPaths(PathsCollection.of(file.toPath()));
    }
    return appArtifact;
}
 
Example 4
Source File: AetherImporter.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private static DefaultArtifact makeOtherClassifier ( final Artifact main, final String classifier )
{
    if ( main.getClassifier () != null && !main.getClassifier ().isEmpty () )
    {
        // we only change main artifacts
        return null;
    }

    return new DefaultArtifact ( main.getGroupId (), main.getArtifactId (), classifier, main.getExtension (), main.getVersion () );
}
 
Example 5
Source File: ExtraArtifactsHandler.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private DependencyNode createNode(DependencyNode n, Optional<String> extension, Optional<String> classifier) {
    Artifact original = n.getArtifact();
    Artifact withExtension =
            new DefaultArtifact(original.getGroupId(),
                    original.getArtifactId(),
                    classifier.orElse(original.getClassifier()),
                    extension.orElse(original.getExtension()),
                    original.getVersion(),
                    original.getProperties(),
                    (File) null);

    DefaultDependencyNode nodeWithClassifier = new DefaultDependencyNode(new Dependency(withExtension, "system"));

    return nodeWithClassifier;
}
 
Example 6
Source File: ComponentDependenciesBase.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
protected Artifact resolve(final Artifact dep, final String classifier, final String type) {
    final LocalRepositoryManager lrm = repositorySystemSession.getLocalRepositoryManager();
    final Artifact artifact =
            new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(), classifier, type, getVersion(dep));
    final File location = new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact));
    if (!location.exists()) {
        return resolve(artifact);
    }
    return artifact.setFile(location);
}
 
Example 7
Source File: AutoDiscoverDeployService.java    From vertx-deploy-tools with Apache License 2.0 5 votes vote down vote up
private Artifact checkWithModel(Model model, Artifact artifact, Map<String, String> properties) {
    Optional<org.apache.maven.model.Dependency> result = model.getDependencies().stream()
            .filter(d -> d.getGroupId().equals(artifact.getGroupId()))
            .filter(d -> d.getArtifactId().equals(artifact.getArtifactId()))
            .filter(d -> d.getClassifier() != null && properties.containsKey(d.getClassifier().substring(2, d.getClassifier().length() - 1)))
            .findFirst();
    return result.isPresent() ?
            new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), properties.get(result.get().getClassifier().substring(2, result.get().getClassifier().length() - 1)), artifact.getExtension(), artifact.getVersion(), artifact.getProperties(), artifact.getFile())
            : artifact;
}
 
Example 8
Source File: MavenUtils.java    From syndesis with Apache License 2.0 5 votes vote down vote up
static String toGav(final Artifact artifact) {
    // <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
    return artifact.getGroupId()
        + ":" + artifact.getArtifactId()
        + (artifact.getExtension() == null ? "" : ":" + artifact.getExtension())
        + (artifact.getClassifier() == null ? "" : ":" + artifact.getClassifier())
        + ":" + artifact.getVersion();
}
 
Example 9
Source File: AetherImporter.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private static DefaultArtifact makeOtherExtension ( final Artifact main, final String extension )
{
    if ( main.getClassifier () != null && !main.getClassifier ().isEmpty () )
    {
        // we only change main artifacts
        return null;
    }

    return new DefaultArtifact ( main.getGroupId (), main.getArtifactId (), null, extension, main.getVersion () );
}
 
Example 10
Source File: LocalWorkspace.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> findVersions(Artifact artifact) {
    if (lastFindVersionsKey != null && artifact.getVersion().equals(lastFindVersions.get(0))
            && lastFindVersionsKey.getArtifactId().equals(artifact.getArtifactId())
            && lastFindVersionsKey.getGroupId().equals(artifact.getGroupId())) {
        return lastFindVersions;
    }
    lastFindVersionsKey = new AppArtifactKey(artifact.getGroupId(), artifact.getArtifactId());
    final LocalProject lp = getProject(lastFindVersionsKey);
    if (lp == null || !lp.getVersion().equals(artifact.getVersion())) {
        lastFindVersionsKey = null;
        return Collections.emptyList();
    }
    return lastFindVersions = Collections.singletonList(artifact.getVersion());
}
 
Example 11
Source File: StackResolution.java    From vertx-stack with Apache License 2.0 5 votes vote down vote up
private String getManagementKey(Artifact artifact) {
  return artifact.getGroupId()
    + ":" + artifact.getArtifactId()
    + ":" + artifact.getExtension()
    + (artifact.getClassifier() != null && artifact.getClassifier().length() > 0
    ? ":" + artifact.getClassifier() : "");
}
 
Example 12
Source File: BomTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static String buildMavenCentralUrl(Artifact artifact) {
  return "https://repo1.maven.org/maven2/"
      + artifact.getGroupId().replace('.', '/')
      + "/"
      + artifact.getArtifactId()
      + "/"
      + artifact.getVersion()
      + "/";
}
 
Example 13
Source File: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static String getVersionlessCoordinate( DependencyNode node )
{
    Artifact artifact = node.getArtifact();

    // scope not included because we check for scope conflicts separately
    return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getExtension();
}
 
Example 14
Source File: MavenArtifactResolver.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private static AppArtifactKey getId(Artifact a) {
    return new AppArtifactKey(a.getGroupId(), a.getArtifactId(), a.getClassifier(), a.getExtension());
}
 
Example 15
Source File: PluginBundleManager.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
private void loadDependencies(String pluginBundleVersion, boolean strictDependencyChecking, Model model,
			DelegatingClassLoader delegatingClassLoader)
			throws DependencyCollectionException, InvalidVersionSpecificationException, Exception {
		if (model.getRepositories() != null) {
			for (Repository repository : model.getRepositories()) {
				mavenPluginRepository.addRepository(repository.getId(), "default", repository.getUrl());
			}
		}

		List<Dependency> dependenciesToResolve = new ArrayList<>();
		for (org.apache.maven.model.Dependency dependency2 : model.getDependencies()) {
			String scope = dependency2.getScope();
			if (scope != null && (scope.contentEquals("test"))) {
				// Skip
				continue;
			}
			Dependency d = new Dependency(new DefaultArtifact(dependency2.getGroupId(), dependency2.getArtifactId(), dependency2.getType(), dependency2.getVersion()), dependency2.getScope());
			Set<Exclusion> exclusions = new HashSet<>();
			d.setExclusions(exclusions);
			exclusions.add(new Exclusion("org.opensourcebim", "pluginbase", null, "jar"));
			exclusions.add(new Exclusion("org.opensourcebim", "shared", null, "jar"));
			exclusions.add(new Exclusion("org.opensourcebim", "ifcplugins", null, "jar"));
			dependenciesToResolve.add(d);
		}
		CollectRequest collectRequest = new CollectRequest(dependenciesToResolve, null, null);
		collectRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
		CollectResult collectDependencies = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest);
		PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
		DependencyNode rootDep = collectDependencies.getRoot();
		rootDep.accept(nlg);
		
		for (Dependency dependency : nlg.getDependencies(true)) {
			if (dependency.getScope().contentEquals("test")) {
				continue;
			}
//			LOGGER.info(dependency.getArtifact().getGroupId() + "." + dependency.getArtifact().getArtifactId());
			Artifact dependencyArtifact = dependency.getArtifact();
			PluginBundleIdentifier pluginBundleIdentifier = new PluginBundleIdentifier(dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId());
			if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleIdentifier)) {
				if (strictDependencyChecking) {
					String version = dependencyArtifact.getVersion();
					if (!version.contains("[") && !version.contains("(")) {
						version = "[" + version + "]";
					}
					VersionRange versionRange = VersionRange.createFromVersionSpec(version);
					// String version =
					// pluginBundleIdentifierToPluginBundle.get(pluginBundleIdentifier).getPluginBundleVersion().getVersion();
					ArtifactVersion artifactVersion = new DefaultArtifactVersion(pluginBundleVersion);
					if (versionRange.containsVersion(artifactVersion)) {
						// OK
					} else {
						throw new Exception(
								"Required dependency " + pluginBundleIdentifier + " is installed, but it's version (" + pluginBundleVersion + ") does not comply to the required version (" + dependencyArtifact.getVersion() + ")");
					}
				} else {
					LOGGER.info("Skipping strict dependency checking for dependency " + dependencyArtifact.getArtifactId());
				}
			} else {
				try {
					if (dependencyArtifact.getGroupId().contentEquals("com.sun.xml.ws")) {
						continue;
					}
					MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId());
					if (dependencyArtifact.getExtension().contentEquals("jar")) {
						Path depJarFile = mavenPluginLocation.getVersionJar(dependencyArtifact.getVersion());
						
						FileJarClassLoader jarClassLoader = new FileJarClassLoader(pluginManager, delegatingClassLoader, depJarFile);
						jarClassLoaders.add(jarClassLoader);
						delegatingClassLoader.add(jarClassLoader);
					}
				} catch (Exception e) {
					e.printStackTrace();
					throw new Exception("Required dependency " + pluginBundleIdentifier + " is not installed");
				}
			}
		}
	}
 
Example 16
Source File: IDEWorkspaceReader2.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public File findArtifact(Artifact artifact) {
    return super.findArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getExtension(), artifact.getClassifier());
}
 
Example 17
Source File: IDEWorkspaceReader2.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public List<String> findVersions(Artifact artifact) {
    return super.findVersions(artifact.getGroupId(), artifact.getArtifactId());
}
 
Example 18
Source File: Artifacts.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
public static String makeKey(Artifact artifact) {
  return artifact.getGroupId() + ":" + artifact.getArtifactId();
}
 
Example 19
Source File: Pom.java    From buck with Apache License 2.0 4 votes vote down vote up
public DepKey(Artifact artifact) {
  groupId = artifact.getGroupId();
  artifactId = artifact.getArtifactId();
  validate();
}
 
Example 20
Source File: Artifacts.java    From cloud-opensource-java with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the artifact's Maven coordinates in the form groupId:artifactId:version. Repo and
 * packaging are not included.
 */
public static String toCoordinates(Artifact artifact) {
  return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
}