本文整理汇总了Java中org.sonatype.aether.artifact.Artifact.getFile方法的典型用法代码示例。如果您正苦于以下问题:Java Artifact.getFile方法的具体用法?Java Artifact.getFile怎么用?Java Artifact.getFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sonatype.aether.artifact.Artifact
的用法示例。
在下文中一共展示了Artifact.getFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: discoverPlugins
import org.sonatype.aether.artifact.Artifact; //导入方法依赖的package包/类
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());
}
示例2: resolveModel
import org.sonatype.aether.artifact.Artifact; //导入方法依赖的package包/类
public ModelSource resolveModel( String groupId, String artifactId, String version )
throws UnresolvableModelException
{
Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version );
try
{
ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context );
request.setTrace( trace );
pomArtifact = resolver.resolveArtifact( session, request ).getArtifact();
}
catch ( ArtifactResolutionException e )
{
throw new UnresolvableModelException( e.getMessage(), groupId, artifactId, version, e );
}
File pomFile = pomArtifact.getFile();
return new FileModelSource( pomFile );
}
示例3: CacheKey
import org.sonatype.aether.artifact.Artifact; //导入方法依赖的package包/类
public CacheKey( List<? extends Artifact> extensionArtifacts )
{
this.files = new ArrayList<File>( extensionArtifacts.size() );
this.timestamps = new ArrayList<Long>( extensionArtifacts.size() );
this.sizes = new ArrayList<Long>( extensionArtifacts.size() );
this.ids = new ArrayList<String>( extensionArtifacts.size() );
for ( Artifact artifact : extensionArtifacts )
{
File file = artifact.getFile();
files.add( file );
timestamps.add( ( file != null ) ? Long.valueOf( file.lastModified() ) : Long.valueOf( 0 ) );
sizes.add( ( file != null ) ? Long.valueOf( file.length() ) : Long.valueOf( 0 ) );
ids.add( artifact.getVersion() );
}
this.hashCode =
31 * files.hashCode() + 31 * ids.hashCode() + 31 * timestamps.hashCode() + 31 * sizes.hashCode();
}
示例4: createClassLoader
import org.sonatype.aether.artifact.Artifact; //导入方法依赖的package包/类
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);
}
示例5: resolveModel
import org.sonatype.aether.artifact.Artifact; //导入方法依赖的package包/类
public ModelSource resolveModel( String groupId, String artifactId, String version )
throws UnresolvableModelException
{
File pomFile = null;
if ( modelPool != null )
{
pomFile = modelPool.get( groupId, artifactId, version );
}
if ( pomFile == null )
{
Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version );
try
{
ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context );
request.setTrace( trace );
pomArtifact = resolver.resolveArtifact( session, request ).getArtifact();
}
catch ( ArtifactResolutionException e )
{
throw new UnresolvableModelException( e.getMessage(), groupId, artifactId, version, e );
}
pomFile = pomArtifact.getFile();
}
return new FileModelSource( pomFile );
}
示例6: getSymbolicName
import org.sonatype.aether.artifact.Artifact; //导入方法依赖的package包/类
@Override
public String getSymbolicName(Artifact artifact)
{
if(artifact.getGroupId().indexOf('.') == -1)
{
// Find the first package with classes in it
try(JarFile jar = new JarFile(artifact.getFile())) // commons-logging:commons-logging -> org.apache.commons.logging
{
List<String> contents = new ArrayList<>();
Enumeration<JarEntry> entries = jar.entries();
while(entries.hasMoreElements())
{
JarEntry entry = entries.nextElement();
contents.add(entry.getName());
}
// sort by number of slashes
Collections.sort(contents, PATH_COMPONENTS);
for(String path : contents)
{
if(path.endsWith(".class"))
{
path = path.substring(0, path.lastIndexOf('/')).replace('/', '.');
if(path.startsWith("/"))
{
path = path.substring(1);
}
return path;
}
}
}
catch (IOException e)
{
return null;
}
}
else if(Iterables.getLast(Splitter.on('.').split(artifact.getGroupId())).equals(artifact.getArtifactId()))
{
return artifact.getGroupId(); // org.apache.maven:maven -> org.apache.maven
}
else
{
String gidEnd = Iterables.getLast(Splitter.on('.').split(artifact.getGroupId()));
if(Iterables.getFirst(Splitter.on('.').split(artifact.getArtifactId()), null).equals(gidEnd))
{
// org.apache.maven:maven-core -> org.apache.maven.core
return artifact.getGroupId() + "." + PUNCTUATION.trimFrom(artifact.getArtifactId().substring(gidEnd.length()));
}
else
{
return artifact.getGroupId() + "." + artifact.getArtifactId(); // groupId + "." + artifactId
}
}
return null;
}
示例7: createRealm
import org.sonatype.aether.artifact.Artifact; //导入方法依赖的package包/类
/**
* Creates a new class realm with the specified parent and imports.
*
* @param baseRealmId The base id to use for the new realm, must not be {@code null}.
* @param type The type of the class realm, must not be {@code null}.
* @param parent The parent realm for the new realm, may be {@code null}.
* @param parentImports The packages/types to import from the parent realm, may be {@code null}.
* @param foreignImports The packages/types to import from foreign realms, may be {@code null}.
* @param artifacts The artifacts to add to the realm, may be {@code null}. Unresolved artifacts (i.e. with a
* missing file) will automatically be excluded from the realm.
* @return The created class realm, never {@code null}.
*/
private ClassRealm createRealm( String baseRealmId, RealmType type, ClassLoader parent, List<String> parentImports,
Map<String, ClassLoader> foreignImports, List<Artifact> artifacts )
{
Set<String> artifactIds = new LinkedHashSet<String>();
List<ClassRealmConstituent> constituents = new ArrayList<ClassRealmConstituent>();
if ( artifacts != null )
{
for ( Artifact artifact : artifacts )
{
artifactIds.add( getId( artifact ) );
if ( artifact.getFile() != null )
{
constituents.add( new ArtifactClassRealmConstituent( artifact ) );
}
}
}
if ( parentImports != null )
{
parentImports = new ArrayList<String>( parentImports );
}
else
{
parentImports = new ArrayList<String>();
}
if ( foreignImports != null )
{
foreignImports = new TreeMap<String, ClassLoader>( foreignImports );
}
else
{
foreignImports = new TreeMap<String, ClassLoader>();
}
ClassRealm classRealm = newRealm( baseRealmId );
if ( parent != null )
{
classRealm.setParentClassLoader( parent );
}
callDelegates( classRealm, type, parent, parentImports, foreignImports, constituents );
wireRealm( classRealm, parentImports, foreignImports );
Set<String> includedIds = populateRealm( classRealm, constituents );
if ( logger.isDebugEnabled() )
{
artifactIds.removeAll( includedIds );
for ( String id : artifactIds )
{
logger.debug( " Excluded: " + id );
}
}
return classRealm;
}