Refine search
private List<File> loadFromMvn(String artifact, Collection<String> excludes) throws RepositoryException { Collection<String> allExclusions = new LinkedList<>(); allExclusions.addAll(excludes); allExclusions.addAll(Arrays.asList(exclusions)); List<ArtifactResult> listOfArtifact; listOfArtifact = getArtifactsWithDep(artifact, allExclusions); Iterator<ArtifactResult> it = listOfArtifact.iterator(); while (it.hasNext()) { Artifact a = it.next().getArtifact(); String gav = a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion(); for (String exclude : allExclusions) { if (gav.startsWith(exclude)) { it.remove(); break; } } } List<File> files = new LinkedList<>(); for (ArtifactResult artifactResult : listOfArtifact) { files.add(artifactResult.getArtifact().getFile()); logger.debug("load {}", artifactResult.getArtifact().getFile().getAbsolutePath()); } return files; }
public static Set<String> discoverPlugins(Artifact artifact, ClassLoader classLoader) throws IOException { if (!artifact.getExtension().equals("presto-plugin")) { throw new RuntimeException("Unexpected extension for main artifact: " + artifact); } File file = artifact.getFile(); if (!file.getPath().endsWith("/target/classes")) { throw new RuntimeException("Unexpected file for main artifact: " + file); } if (!file.isDirectory()) { throw new RuntimeException("Main artifact file is not a directory: " + file); } if (new File(file, SERVICES_FILE).exists()) { return ImmutableSet.of(); } return listClasses(file.toPath()).stream() .filter(name -> classInterfaces(name, classLoader).contains(Plugin.class.getName())) .collect(toImmutableSet()); }
@Override public String toString() { return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getClassifier() + ':' + artifact.getExtension(); }
private Artifact getDependencyArtifact( Dependency dep ) { org.sonatype.aether.artifact.Artifact artifact = dep.getArtifact(); return factory.createDependencyArtifact( artifact.getGroupId(), artifact.getArtifactId(), VersionRange.createFromVersion( artifact.getVersion() ), artifact.getProperty( "type", artifact.getExtension() ), artifact.getClassifier(), dep.getScope(), dep.isOptional() ); }
static Dependency convertToDependency(ResourceFactory factory, DependencyNode node) { org.sonatype.aether.graph.Dependency artifactDependency = node.getDependency(); Artifact artifact = artifactDependency.getArtifact(); File file = artifact.getFile(); @SuppressWarnings("unchecked") FileResource<?> artifactResource = factory.create(FileResource.class, file); Dependency d = DependencyBuilder.create().setArtifactId(artifact.getArtifactId()) .setGroupId(artifact.getGroupId()).setVersion(artifact.getBaseVersion()) .setPackaging(artifact.getExtension()).setArtifact(artifactResource) .setOptional(artifactDependency.isOptional()) .setClassifier(artifact.getClassifier()) .setScopeType(artifactDependency.getScope()); return d; }
private static ArtifactRef createArtifact(final DependencyNode node) { final Artifact artifact = node.getDependency().getArtifact(); final ArtifactId.Builder builder = new ArtifactId.Builder(); final String classifier = normalize(artifact); builder.withGroupId(artifact.getGroupId()) .withName(artifact.getArtifactId()).withVersion(artifact.getVersion()) .withArchiveType(artifact.getExtension()).withClassifier(classifier); final ArtifactId id = builder.build(); final File file = artifact.getFile(); final URL url = toUrl(file); final ArtifactRef ref = new ArtifactRef(id, url); return ref; }
public static String gaOf(Dependency d) { return d.getArtifact().getGroupId() + ":" + d.getArtifact().getArtifactId(); }
private URLClassLoader createClassLoader(List<Artifact> artifacts, String name) throws IOException { log.debug("Classpath for %s:", name); List<URL> urls = new ArrayList<>(); for (Artifact artifact : sortedArtifacts(artifacts)) { if (artifact.getFile() == null) { throw new RuntimeException("Could not resolve artifact: " + artifact); } File file = artifact.getFile().getCanonicalFile(); log.debug(" %s", file); urls.add(file.toURI().toURL()); } return createClassLoader(urls); }
private DefaultArtifact getSideArtifact(final org.sonatype.aether.artifact.Artifact mainArtifact, final String classifier, String type) { return new DefaultArtifact(mainArtifact.getGroupId(), mainArtifact.getArtifactId(), classifier, type, mainArtifact.getVersion()); } }
public static String gavOf(Dependency d) { return d.getArtifact().getGroupId() + ":" + d.getArtifact().getArtifactId() + ":" + d.getArtifact().getVersion(); }
/** * {@inheritDoc} * * @see org.apache.maven.mae.project.session.ProjectToolsSession#getReactorProject(org.sonatype.aether.artifact.Artifact) */ @Override public MavenProject getReactorProject( final Artifact artifact ) { final String id = key( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion() ); return reactorProjects.get( id ); }
String localPath = artifact.getProperty( ArtifactProperties.LOCAL_PATH, null ); if ( localPath != null ) artifact = artifact.setFile( file ); result.setArtifact( artifact ); artifactResolved( session, trace, artifact, null, result.getExceptions() ); artifact = artifact.setVersion( versionResult.getVersion() ); artifact = artifact.setFile( file ); result.setArtifact( artifact ); result.setRepository( workspace.getRepository() ); artifact = artifact.setFile( getFile( session, artifact, local.getFile() ) ); result.setArtifact( artifact ); artifactResolved( session, trace, artifact, result.getRepository(), null ); if ( !repo.getPolicy( artifact.isSnapshot() ).isEnabled() ) boolean snapshot = artifact.isSnapshot(); RepositoryPolicy policy = remoteRepositoryManager.getPolicy( session, group.repository, !snapshot, snapshot ); artifact = artifact.setFile( getFile( session, artifact, download.getFile() ) ); item.result.setArtifact( artifact ); if ( artifact == null || artifact.getFile() == null )
public DependencyTree(DependencyId dependencyId, Dependency dependency, List<DependencyTree> children) { this(dependencyId, dependency.getArtifact().getBaseVersion(), children); this.scope = dependency.getScope(); this.optional = dependency.isOptional(); init(children); }
protected File getFile(DependencyNode node) throws ArtifactResolutionException { if (node != null) { Dependency dependency = node.getDependency(); if (dependency != null) { Artifact artifact = dependency.getArtifact(); if (artifact != null) { File file = artifact.getFile(); if (file == null) { return mavenResolver.resolveFile(artifact); } return file; } } } return null; }
@Override public Collection<Advice> getAdvices( final DependencyNode root ) { final PreorderNodeListGenerator collector = new PreorderNodeListGenerator(); root.accept( collector ); final Collection<Advice> advices = new ArrayList<Advice>(); for ( final Artifact artifact : collector.getArtifacts( false ) ) { if ( "advice".equals( artifact.getExtension() ) ) { advices.addAll( extractAdvices( artifact.getFile(), Utils.fullArtifactId( root.getDependency().getArtifact() ) ) ); } } return advices; }
static String versionlessNameOf( final Artifact artifact ) { final StringBuilder path = new StringBuilder( 128 ); path.append( artifact.getArtifactId() ); if ( artifact.getClassifier().length() > 0 ) { path.append( '-' ).append( artifact.getClassifier() ); } path.append( '.' ).append( artifact.getExtension() ); return path.toString(); }
Artifact artifact = managedDependency.getArtifact(); Object key = getKey( artifact ); String version = artifact.getVersion(); if ( version.length() > 0 && !managedVersions.containsKey( key ) ) String scope = managedDependency.getScope(); if ( scope.length() > 0 && !managedScopes.containsKey( key ) ) String localPath = managedDependency.getArtifact().getProperty( ArtifactProperties.LOCAL_PATH, null ); if ( localPath != null && !managedLocalPaths.containsKey( key ) )
public DependencyTree(DependencyId dependencyId, Dependency dependency, List<DependencyTree> children) { this(dependencyId, dependency.getArtifact().getVersion(), children); this.scope = dependency.getScope(); this.optional = dependency.isOptional(); }
@Override public boolean selectDependency(Dependency dependency) { boolean result = false; if (!isExcluded(dependency)) { boolean optional = dependency.isOptional(); if (depth < 1) return !optional; String scope = dependency.getScope(); String classifier = dependency.getArtifact().getClassifier(); if ("test".equals(scope)) return false; result = (FORGE_ADDON.equals(classifier) && depth == 1) || (!FORGE_ADDON.equals(classifier) && !"provided".equals(scope) && !optional); } return result; }
@Override public boolean visitEnter( DependencyNode dependencyNode ) { TreeEntry entry = new TreeEntry( getModelMapper().map( dependencyNode.getDependency().getArtifact(), Artifact.class ) ); entry.getArtifact().setFileExtension( dependencyNode.getDependency().getArtifact().getExtension() ); entry.getArtifact().setScope( dependencyNode.getDependency().getScope() ); entry.setParent( currentEntry ); currentEntry = entry; if ( firstDependencyNode == null ) { firstDependencyNode = dependencyNode; treeEntries.add( currentEntry ); } else { currentEntry.getParent().getChilds().add( currentEntry ); } return true; }