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

The following examples show how to use org.eclipse.aether.artifact.Artifact#getGroupId() . 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: ArtifactIdUtils.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public static String artifactToString(Artifact artifact) {
    StringBuilder result = new StringBuilder();

    String groupId = artifact.getGroupId();
    result.append(groupId).append(ARTIFACT_DELIMITER);

    String artifactId = artifact.getArtifactId();
    result.append(artifactId).append(ARTIFACT_DELIMITER);

    String version = artifact.getVersion();
    result.append(version);

    if (StringUtils.hasText(artifact.getClassifier())) {
        String classifier = artifact.getClassifier();
        result.append(ARTIFACT_DELIMITER).append(classifier);
    }


    return result.toString();
}
 
Example 2
Source File: PomXmlUtils.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Read group, artifact, version from nodes:
 * <groupId></groupId>, <artifactId></artifactId>, <version></version>
 * If presents parent node group and artifact takes from parent node
 * @param pomXml pom.xml for read
 * @return {@link Artifact} with group, artifact, version
 */
Artifact readGroupArtifactVersionInPomXml(Path pomXml) {
    String groupExpression    = String.format("/%s/%s", PROJECT, GROUP);
    String artifactExpression = String.format("/%s/%s", PROJECT, ARTIFACT);
    String versionExpression  = String.format("/%s/%s", PROJECT, VERSION);
    Document doc = readDocumentFromFile(pomXml);
    NodeList group = executeExpression(groupExpression, doc);
    NodeList artifact = executeExpression(artifactExpression, doc);
    NodeList version = executeExpression(versionExpression, doc);

    Artifact parent = readParentGAVInPomXml(pomXml);
    String groupId = (group != null && group.getLength() > 0) ? group.item(0).getTextContent() : (parent != null ? parent.getGroupId() : null);
    String artifactId = (artifact != null && artifact.getLength() > 0) ? artifact.item(0).getTextContent() : null;
    String versionId = (version != null && version.getLength() > 0) ? version.item(0).getTextContent() : (parent != null ? parent.getVersion() : null);

    
    return (groupId != null && artifactId != null && versionId != null) 
        ? (Artifact) new DefaultArtifact(getGAV(groupId, artifactId, versionId))
        : null;
}
 
Example 3
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 4
Source File: Resolver.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Construct a key to identify the artifact, less its version */
private String buildKey(Artifact artifact) {
  return artifact.getGroupId()
      + ':'
      + artifact.getArtifactId()
      + ':'
      + artifact.getExtension()
      + ':'
      + artifact.getClassifier();
}
 
Example 5
Source File: OArtifactReference.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public static OArtifactReference valueOf(Artifact artifact) {
    if (artifact == null) return null;
    String groupId = artifact.getGroupId();
    String artifactId = artifact.getArtifactId();
    String version = artifact.getVersion();
    File file = artifact.getFile();
    return new OArtifactReference(groupId, artifactId, version, file);
}
 
Example 6
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 7
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 8
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 9
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 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: PluginSettings.java    From gyro with Apache License 2.0 5 votes vote down vote up
public void putArtifactIfNewer(Artifact artifact) throws MalformedURLException {
    String id = artifact.getGroupId() + "/" + artifact.getArtifactId();
    VersionUrl versionUrl = new VersionUrl(artifact.getVersion(), artifact.getFile().toURI().toURL());

    if (!VERSIONED_URLS.containsKey(id) || versionUrl.compareTo(VERSIONED_URLS.get(id)) > 0) {
        VERSIONED_URLS.put(id, versionUrl);
    }
}
 
Example 12
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 13
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private AppArtifactKey getKey(final Artifact artifact) {
    return new AppArtifactKey(artifact.getGroupId(), artifact.getArtifactId(),
            artifact.getClassifier(), 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: 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 16
Source File: MavenUtils.java    From syndesis with Apache License 2.0 4 votes vote down vote up
static String versionlessKey(final Artifact artifact) {
    return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
        + Optional.ofNullable(artifact.getExtension()).orElse("jar") + ":"
        + Optional.ofNullable(artifact.getClassifier()).orElse("");
}
 
Example 17
Source File: RepackageExtensionMojo.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private static ArtifactsFilter newExcludeFilter(final Dependency dependency) {
    final Artifact artifact = dependency.getArtifact();

    return new ExcludeFilter(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: 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 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();
}