private URLClassLoader buildClassLoaderFromCoordinates(String coordinates) throws Exception { Artifact rootArtifact = new DefaultArtifact(coordinates); List<Artifact> artifacts = resolver.resolveArtifacts(rootArtifact); return createClassLoader(artifacts, rootArtifact.toString()); }
private URLClassLoader buildClassLoaderFromPom(File pomFile) throws Exception { List<Artifact> artifacts = resolver.resolvePom(pomFile); URLClassLoader classLoader = createClassLoader(artifacts, pomFile.getPath()); Artifact artifact = artifacts.get(0); Set<String> plugins = discoverPlugins(artifact, classLoader); if (!plugins.isEmpty()) { writePluginServices(plugins, artifact.getFile()); } return classLoader; }
this.plugins = ImmutableList.copyOf(config.getPlugins()); this.resolver = new ArtifactResolver(config.getMavenLocalRepository(), config.getMavenRemoteRepository());
@Test public void testResolvePom() throws DependencyResolutionException { File pomFile = new File("src/test/poms/maven-core-3.0.4.pom"); Assert.assertTrue(pomFile.canRead()); ArtifactResolver artifactResolver = new ArtifactResolver(USER_LOCAL_REPO, MAVEN_CENTRAL_URI); List<Artifact> artifacts = artifactResolver.resolvePom(pomFile); Assert.assertNotNull(artifacts, "artifacts is null"); for (Artifact artifact : artifacts) { Assert.assertNotNull(artifact.getFile(), "Artifact " + artifact + " is not resolved"); } } }
@Test public void testResolveArtifacts() throws Exception { ArtifactResolver artifactResolver = new ArtifactResolver(USER_LOCAL_REPO, MAVEN_CENTRAL_URI); List<Artifact> artifacts = artifactResolver.resolveArtifacts(ImmutableList.of(new DefaultArtifact("org.apache.maven:maven-core:3.0.4"))); Assert.assertNotNull(artifacts, "artifacts is null"); for (Artifact artifact : artifacts) { Assert.assertNotNull(artifact.getFile(), "Artifact " + artifact + " is not resolved"); } }
public List<Artifact> resolveArtifacts(Artifact... sourceArtifacts) { return resolveArtifacts(Arrays.asList(sourceArtifacts)); }
@Override public Artifact setFile(File file) { if ((this.file == null) ? file == null : this.file.equals(file)) { return this; } return new DefaultArtifact(groupId, artifactId, classifier, extension, version, file, properties); }
@Override public String getBaseVersion() { if (baseVersion == null) { baseVersion = toBaseVersion(getVersion()); } return baseVersion; }
Map<String, String> properties, ArtifactType type) this.groupId = emptify(groupId); this.artifactId = emptify(artifactId); if (classifier != null || type == null) { this.classifier = emptify(classifier); this.classifier = emptify(type.getClassifier()); this.extension = emptify(extension); this.extension = emptify(type.getExtension()); this.version = emptify(version); this.file = null; this.properties = merge(properties, (type != null) ? type.getProperties() : null);
DefaultArtifact(String groupId, String artifactId, String classifier, String extension, String version, File file, Map<String, String> properties) { // NOTE: This constructor assumes immutability of the provided properties, for internal use only this.groupId = emptify(groupId); this.artifactId = emptify(artifactId); this.classifier = emptify(classifier); this.extension = emptify(extension); this.version = emptify(version); this.file = file; this.properties = properties; }
private URLClassLoader buildClassLoaderFromCoordinates(String coordinates) throws Exception { Artifact rootArtifact = new DefaultArtifact(coordinates); List<Artifact> artifacts = resolver.resolveArtifacts(rootArtifact); return createClassLoader(artifacts, rootArtifact.toString()); }
private URLClassLoader buildClassLoaderFromPom(File pomFile) throws Exception { List<Artifact> artifacts = resolver.resolvePom(pomFile); URLClassLoader classLoader = createClassLoader(artifacts, pomFile.getPath()); Artifact artifact = artifacts.get(0); Set<String> plugins = discoverPlugins(artifact, classLoader); if (!plugins.isEmpty()) { writePluginServices(plugins, artifact.getFile()); } return classLoader; }
public List<Artifact> resolveArtifacts(Iterable<? extends Artifact> sourceArtifacts) { CollectRequest collectRequest = new CollectRequest(); for (Artifact sourceArtifact : sourceArtifacts) { collectRequest.addDependency(new Dependency(sourceArtifact, JavaScopes.RUNTIME)); } for (RemoteRepository repository : repositories) { collectRequest.addRepository(repository); } DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME)); return resolveArtifacts(dependencyRequest); }
@Override public Artifact setVersion(String version) { if (this.version.equals(version) || (version == null && this.version.length() <= 0)) { return this; } return new DefaultArtifact(groupId, artifactId, classifier, extension, version, file, properties); }
/** * Creates a new artifact with the specified coordinates, properties and file. Passing {@code null} for any of the * coordinates is equivalent to specifying an empty string. * * @param groupId The group identifier of the artifact, may be {@code null}. * @param artifactId The artifact identifier of the artifact, may be {@code null}. * @param classifier The classifier of the artifact, may be {@code null}. * @param extension The file extension of the artifact, may be {@code null}. * @param version The version of the artifact, may be {@code null}. * @param properties The properties of the artifact, may be {@code null} if none. * @param file The resolved file of the artifact, may be {@code null}. */ public DefaultArtifact(String groupId, String artifactId, String classifier, String extension, String version, Map<String, String> properties, File file) { this.groupId = emptify(groupId); this.artifactId = emptify(artifactId); this.classifier = emptify(classifier); this.extension = emptify(extension); this.version = emptify(version); this.file = file; this.properties = Collections.unmodifiableMap(new LinkedHashMap<>(properties)); }
private URLClassLoader buildClassLoaderFromCoordinates(String coordinates) throws Exception { Artifact rootArtifact = new DefaultArtifact(coordinates); List<Artifact> artifacts = resolver.resolveArtifacts(rootArtifact); return createClassLoader(artifacts, rootArtifact.toString()); }
private URLClassLoader buildClassLoaderFromPom(File pomFile) throws Exception { List<Artifact> artifacts = resolver.resolvePom(pomFile); URLClassLoader classLoader = createClassLoader(artifacts, pomFile.getPath()); Artifact artifact = artifacts.get(0); Set<String> plugins = discoverPlugins(artifact, classLoader); if (!plugins.isEmpty()) { writePluginServices(plugins, artifact.getFile()); } return classLoader; }
@Override public Artifact setProperties(Map<String, String> properties) { if (this.properties.equals(properties) || (properties == null && this.properties.isEmpty())) { return this; } return new DefaultArtifact(groupId, artifactId, classifier, extension, version, file, Collections.unmodifiableMap(new LinkedHashMap<>(properties))); }
private URLClassLoader buildClassLoaderFromCoordinates(String coordinates) throws Exception { Artifact rootArtifact = new DefaultArtifact(coordinates); List<Artifact> artifacts = resolver.resolveArtifacts(rootArtifact); return createClassLoader(artifacts, rootArtifact.toString()); }
private URLClassLoader buildClassLoaderFromPom(File pomFile) throws Exception { List<Artifact> artifacts = resolver.resolvePom(pomFile); URLClassLoader classLoader = createClassLoader(artifacts, pomFile.getPath()); Artifact artifact = artifacts.get(0); Set<String> plugins = discoverPlugins(artifact, classLoader); if (!plugins.isEmpty()) { writePluginServices(plugins, artifact.getFile()); } return classLoader; }