本文整理汇总了Java中org.apache.maven.index.ArtifactInfo类的典型用法代码示例。如果您正苦于以下问题:Java ArtifactInfo类的具体用法?Java ArtifactInfo怎么用?Java ArtifactInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArtifactInfo类属于org.apache.maven.index包,在下文中一共展示了ArtifactInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: populateArtifactInfo
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
@Override public void populateArtifactInfo(ArtifactContext context) throws IOException {
ArtifactInfo ai = context.getArtifactInfo();
if (ai.getClassifier() != null) {
return;
}
try {
MavenProject mp = load(ai);
if (mp != null) {
List<Dependency> dependencies = mp.getDependencies();
LOG.log(Level.FINER, "Successfully loaded project model from repository for {0} with {1} dependencies", new Object[] {ai, dependencies.size()});
dependenciesByArtifact.put(ai, dependencies);
}
} catch (InvalidArtifactRTException ex) {
ex.printStackTrace();
}
}
示例2: load
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
private MavenProject load(ArtifactInfo ai) {
try {
Artifact projectArtifact = embedder.createArtifact(ai.getGroupId(), ai.getArtifactId(), ai.getVersion(), ai.getPackaging() != null ? ai.getPackaging() : "jar");
ProjectBuildingRequest dpbr = embedder.createMavenExecutionRequest().getProjectBuildingRequest();
//mkleint: remote repositories don't matter we use project embedder.
dpbr.setRemoteRepositories(remoteRepos);
dpbr.setProcessPlugins(false);
dpbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
ProjectBuildingResult res = embedder.buildProject(projectArtifact, dpbr);
if (res.getProject() != null) {
return res.getProject();
} else {
LOG.log(Level.FINER, "No project model from repository for {0}: {1}", new Object[] {ai, res.getProblems()});
}
} catch (ProjectBuildingException ex) {
LOG.log(Level.FINER, "Failed to load project model from repository for {0}: {1}", new Object[] {ai, ex});
} catch (Exception exception) {
LOG.log(Level.FINER, "Failed to load project model from repository for " + ai, exception);
}
return null;
}
示例3: applyArtifactInfoFilters
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
private boolean applyArtifactInfoFilters( ArtifactInfo artifactInfo,
List<? extends ArtifactInfoFilter> artifactInfoFilters,
Map<String, SearchResultHit> currentResult )
{
if ( artifactInfoFilters == null || artifactInfoFilters.isEmpty() )
{
return true;
}
for ( ArtifactInfoFilter filter : artifactInfoFilters )
{
if ( !filter.addArtifactInResult( artifactInfo, currentResult ) )
{
return false;
}
}
return true;
}
示例4: checkMavenPlugin
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
private void checkMavenPlugin(ArtifactInfo ai, JavaIOFileAdapter artifact) {
ZipInputStream zis = null;
InputStream is = null;
try {
is = artifact.getStream();
zis = new ZipInputStream(is);
ZipEntry currentEntry;
while ((currentEntry = zis.getNextEntry()) != null) {
if (currentEntry.getName().equals("META-INF/maven/plugin.xml")) {
parsePluginDetails(ai, zis);
break;
}
}
} catch (Exception e) {
log.info("Failed to parsing Maven plugin " + artifact.getAbsolutePath(), e.getMessage());
log.debug("Failed to parsing Maven plugin " + artifact.getAbsolutePath(), e);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(zis);
}
}
示例5: populateArtifactInfo
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
@Override
public void populateArtifactInfo(ArtifactContext ac) {
JavaIOFileAdapter artifact = (JavaIOFileAdapter) ac.getArtifact();
ArtifactInfo ai = ac.getArtifactInfo();
// we need the file to perform these checks, and those may be only JARs
if (artifact != null && !MAVEN_ARCHETYPE_PACKAGING.equals(ai.packaging)
&& artifact.getName().endsWith(".jar")) {
// TODO: recheck, is the following true? "Maven plugins and Maven Archetypes can be only JARs?"
// check for maven archetype, since Archetypes seems to not have consistent packaging,
// and depending on the contents of the JAR, this call will override the packaging to "maven-archetype"!
checkMavenArchetype(ai, artifact);
}
}
示例6: checkMavenArchetype
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
/**
* Archetypes that are added will have their packaging types set correctly (to maven-archetype)
*
* @param ai
* @param artifact
*/
private void checkMavenArchetype(ArtifactInfo ai, JavaIOFileAdapter artifact) {
try {
ArchiveEntriesService entriesService = ContextHelper.get().beanForType(ArchiveEntriesService.class);
Set<ZipEntryInfo> archiveEntries = entriesService.getArchiveEntries(artifact.getFileInfo().getSha1());
for (ZipEntryInfo archiveEntry : archiveEntries) {
for (String location : ARCHETYPE_XML_LOCATIONS) {
if (location.equals(archiveEntry.getName())) {
ai.packaging = MAVEN_ARCHETYPE_PACKAGING;
return;
}
}
}
} catch (Exception e) {
log.info("Failed to parse Maven artifact " + artifact.getAbsolutePath(), e.getMessage());
log.debug("Failed to parse Maven artifact " + artifact.getAbsolutePath(), e);
}
}
示例7: applyArtifactInfoFilters
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
private boolean applyArtifactInfoFilters( ArtifactInfo artifactInfo,
List<? extends ArtifactInfoFilter> artifactInfoFilters,
Map<String, SearchResultHit> currentResult )
{
if ( artifactInfoFilters == null || artifactInfoFilters.isEmpty() )
{
return true;
}
ArchivaArtifactModel artifact = new ArchivaArtifactModel();
artifact.setArtifactId( artifactInfo.getArtifactId() );
artifact.setClassifier( artifactInfo.getClassifier() );
artifact.setGroupId( artifactInfo.getGroupId() );
artifact.setRepositoryId( artifactInfo.getRepository() );
artifact.setVersion( artifactInfo.getVersion() );
artifact.setChecksumMD5( artifactInfo.getMd5() );
artifact.setChecksumSHA1( artifactInfo.getSha1() );
for ( ArtifactInfoFilter filter : artifactInfoFilters )
{
if ( !filter.addArtifactInResult( artifact, currentResult ) )
{
return false;
}
}
return true;
}
示例8: populateArtifactInfo
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
@Override public void populateArtifactInfo(ArtifactContext context) throws IOException {
classDeps = null;
ArtifactInfo ai = context.getArtifactInfo();
if (ai.getClassifier() != null) {
return;
}
if ("pom".equals(ai.getPackaging()) || ai.getFileExtension().endsWith(".lastUpdated")) {
return;
}
File jar = context.getArtifact();
if (jar == null || !jar.isFile()) {
LOG.log(Level.FINER, "no artifact for {0}", ai); // not a big deal, maybe just *.pom (or *.pom + *.nbm) here
return;
}
String packaging = ai.getPackaging();
if (packaging == null || (!packaging.equals("jar") && !isArchiveFile(jar))) {
LOG.log(Level.FINE, "skipping artifact {0} with unrecognized packaging based on {1}", new Object[] {ai, jar});
return;
}
LOG.log(Level.FINER, "reading {0}", jar);
Map<String, byte[]> classfiles = read(jar);
classDeps = new HashMap<String, Set<String>>();
Set<String> classes = classfiles.keySet();
for (Map.Entry<String, byte[]> entry : classfiles.entrySet()) {
addDependenciesToMap(entry.getKey(), entry.getValue(), classDeps, classes, jar);
}
}
示例9: updateDocument
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
@Override public void updateDocument(ArtifactInfo ai, Document doc) {
if (classDeps == null || classDeps.isEmpty()) {
return;
}
if (ai.getClassNames() == null) {
// Might be *.hpi, *.war, etc. - so JarFileContentsIndexCreator ignores it (and our results would anyway be wrong due to WEB-INF/classes/ prefix)
LOG.log(Level.FINE, "no class names in index for {0}; therefore cannot store class usages", ai);
return;
}
StringBuilder b = new StringBuilder();
String[] classNamesSplit = ai.getClassNames().split("\n");
for (String referrerTopLevel : classNamesSplit) {
Set<String> referees = classDeps.remove(referrerTopLevel.substring(1));
if (referees != null) {
for (String referee : referees) {
b.append(crc32base64(referee));
b.append(' ');
}
}
b.append(' ');
}
if (!classDeps.isEmpty()) {
// E.g. findbugs-1.2.0.jar has TigerSubstitutes.class, TigerSubstitutesTest$Foo.class, etc., but no TigerSubstitutesTest.class (?)
// Or guice-3.0-rc2.jar has e.g. $Transformer.class with no source equivalent.
LOG.log(Level.FINE, "found dependencies for {0} from classes {1} not among {2}", new Object[] {ai, classDeps.keySet(), Arrays.asList(classNamesSplit)});
}
LOG.log(Level.FINER, "Class dependencies index field: {0}", b);
// XXX is it possible to _store_ something more compact (binary) using a custom tokenizer?
// seems like DefaultIndexingContext hardcodes NexusAnalyzer
doc.add(FLD_NB_DEPENDENCY_CLASS.toField(b.toString()));
}
示例10: search
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
static void search(String className, Indexer indexer, Collection<IndexingContext> contexts, List<? super ClassUsage> results) throws IOException {
String searchString = crc32base64(className.replace('.', '/'));
Query refClassQuery = indexer.constructQuery(ClassDependencyIndexCreator.FLD_NB_DEPENDENCY_CLASS.getOntology(), new StringSearchExpression(searchString));
TopScoreDocCollector collector = TopScoreDocCollector.create(NexusRepositoryIndexerImpl.MAX_RESULT_COUNT, null);
for (IndexingContext context : contexts) {
IndexSearcher searcher = context.acquireIndexSearcher();
try {
searcher.search(refClassQuery, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
LOG.log(Level.FINER, "for {0} ~ {1} found {2} hits", new Object[] {className, searchString, hits.length});
for (ScoreDoc hit : hits) {
int docId = hit.doc;
Document d = searcher.doc(docId);
String fldValue = d.get(ClassDependencyIndexCreator.NB_DEPENDENCY_CLASSES);
LOG.log(Level.FINER, "{0} uses: {1}", new Object[] {className, fldValue});
Set<String> refClasses = parseField(searchString, fldValue, d.get(ArtifactInfo.NAMES));
if (!refClasses.isEmpty()) {
ArtifactInfo ai = IndexUtils.constructArtifactInfo(d, context);
if (ai != null) {
ai.setRepository(context.getRepositoryId());
List<NBVersionInfo> version = NexusRepositoryIndexerImpl.convertToNBVersionInfo(Collections.singleton(ai));
if (!version.isEmpty()) {
results.add(new ClassUsage(version.get(0), refClasses));
}
}
}
}
} finally {
context.releaseIndexSearcher(searcher);
}
}
}
示例11: getArtifactContext
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
@Override public ArtifactContext getArtifactContext(IndexingContext context, File file) {
ArtifactContext ac = super.getArtifactContext(context, file);
if (ac != null) {
final ArtifactInfo ai = ac.getArtifactInfo();
String fext = ai.getFileExtension();
if (fext != null) {
if (fext.endsWith(".lastUpdated")) {
// #197670: why is this even considered?
return null;
}
// Workaround for anomalous classifier behavior of nbm-maven-plugin:
if (fext.equals("nbm")) {
return new ArtifactContext(ac.getPom(), ac.getArtifact(), ac.getMetadata(), new ArtifactInfo(ai.getRepository(), ai.getGroupId(), ai.getArtifactId(), ai.getVersion(), ai.getClassifier(), fext) {
private String uinfo = null;
@Override public String getUinfo() {
if (uinfo == null) {
uinfo = new StringBuilder().
append(ai.getGroupId()).append(ArtifactInfoRecord.FS).
append(ai.getArtifactId()).append(ArtifactInfoRecord.FS).
append(ai.getVersion()).append(ArtifactInfoRecord.FS).
append(ArtifactInfoRecord.NA).append(ArtifactInfoRecord.FS).
append(ai.getPackaging()).toString();
}
return uinfo;
}
}, ac.getGav());
}
}
}
return ac;
}
示例12: updateDocument
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
@Override public void updateDocument(ArtifactInfo ai, Document doc) {
List<Dependency> dependencies = dependenciesByArtifact.get(ai);
if (dependencies != null) {
for (Dependency d : dependencies) {
doc.add(FLD_NB_DEPENDENCY_GROUP.toField(d.getGroupId()));
doc.add(FLD_NB_DEPENDENCY_ARTIFACT.toField(d.getArtifactId()));
doc.add(FLD_NB_DEPENDENCY_VERSION.toField(d.getVersion()));
}
}
}
示例13: testFind
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
public void testFind() throws Exception {
installPOM("test", "plugin", "0", "maven-plugin");
install(TestFileUtils.writeZipFile(new File(getWorkDir(), "plugin.jar"), "META-INF/maven/plugin.xml:<plugin><goalPrefix>stuff</goalPrefix></plugin>"), "test", "plugin", "0", "maven-plugin");
nrii.indexRepo(info);
QueryField qf = new QueryField();
qf.setField(ArtifactInfo.PLUGIN_PREFIX);
qf.setValue("stuff");
qf.setOccur(QueryField.OCCUR_MUST);
qf.setMatch(QueryField.MATCH_EXACT);
assertEquals("[test:plugin:0:test]", nrii.find(Collections.singletonList(qf), Collections.singletonList(info)).getResults().toString());
}
示例14: populateArtifactInfo
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
@Override
public void populateArtifactInfo(ArtifactContext artifactContext) throws IOException {
ArtifactInfo ai = artifactContext.getArtifactInfo();
JavaIOFileAdapter artifactFile = (JavaIOFileAdapter) artifactContext.getArtifact();
if (artifactFile != null && artifactFile.getName().endsWith(".jar")) {
updateArtifactInfo(ai, artifactFile);
}
}
示例15: updateArtifactInfo
import org.apache.maven.index.ArtifactInfo; //导入依赖的package包/类
private void updateArtifactInfo(ArtifactInfo ai, JavaIOFileAdapter file)
throws IOException {
ArchiveEntriesService entriesService = ContextHelper.get().beanForType(ArchiveEntriesService.class);
Set<ZipEntryInfo> archiveEntries = entriesService.getArchiveEntries(file.getFileInfo().getSha1());
StringBuilder sb = new StringBuilder();
for (ZipEntryInfo e : archiveEntries) {
String name = e.getName();
if (name.endsWith(".class")) {
// TODO verify if class is public or protected
// TODO skip all inner classes for now
int i = name.indexOf('$');
if (i == -1) {
if (name.charAt(0) != '/') {
sb.append('/');
}
// class name without ".class"
sb.append(name.substring(0, name.length() - 6)).append('\n');
}
}
}
if (sb.toString().trim().length() != 0) {
ai.classNames = sb.toString();
} else {
ai.classNames = null;
}
}