org.apache.maven.index.ArtifactInfo Java Examples
The following examples show how to use
org.apache.maven.index.ArtifactInfo.
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: ArtifactDependencyIndexCreator.java From netbeans with Apache License 2.0 | 6 votes |
@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(); } }
Example #2
Source File: ArtifactDependencyIndexCreator.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: MavenRepositorySearch.java From archiva with Apache License 2.0 | 6 votes |
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; }
Example #4
Source File: ClassDependencyIndexCreator.java From netbeans with Apache License 2.0 | 5 votes |
@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())); }
Example #5
Source File: ClassDependencyIndexCreator.java From netbeans with Apache License 2.0 | 5 votes |
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); } } }
Example #6
Source File: CustomArtifactContextProducer.java From netbeans with Apache License 2.0 | 5 votes |
@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; }
Example #7
Source File: ArtifactDependencyIndexCreator.java From netbeans with Apache License 2.0 | 5 votes |
@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())); } } }
Example #8
Source File: ClassDependencyIndexCreator.java From netbeans with Apache License 2.0 | 5 votes |
@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; } if (jar.length() == 0) { LOG.log(Level.FINER, "zero length jar for {0}", ai); // Don't try to index zero length files 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); classDeps = new HashMap<>(); read(jar, (String name, InputStream stream, Set<String> classes) -> { try { addDependenciesToMap(name, stream, classDeps, classes, jar); } catch (IOException ex) { LOG.log(Level.INFO, "Exception indexing " + jar, ex); } }); }
Example #9
Source File: NexusRepositoryIndexerImplTest.java From netbeans with Apache License 2.0 | 5 votes |
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()); }
Example #10
Source File: IndexQuerier.java From sling-whiteboard with Apache License 2.0 | 5 votes |
private static ArtifactInfo extract(ArtifactInfoGroup group) { return group.getArtifactInfos() .stream() .filter(a -> a.getClassifier() == null) .findFirst() .orElse(null); }
Example #11
Source File: IndexQuerier.java From sling-whiteboard with Apache License 2.0 | 5 votes |
private void writeLine(OutputStreamWriter w, ArtifactInfo aws) { try { w.write(aws.getGroupId() + ',' + aws.getArtifactId() + ',' + aws.getVersion() + ',' + (aws.getSourcesExists() == PRESENT ? '1' : '0') + '\n'); } catch (IOException e) { throw new RuntimeException(e); } }
Example #12
Source File: NotifyingIndexCreator.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void updateDocument(ArtifactInfo artifactInfo, Document document) { listener.unpackingProgress(artifactInfo.getGroupId() + ':' + artifactInfo.getArtifactId()); }
Example #13
Source File: ArchivaIndexingTaskExecutorTest.java From archiva with Apache License 2.0 | 4 votes |
@Test public void testPackagedIndex() throws Exception { Path basePath = repo.getRoot().getFilePath(); IndexCreationFeature icf = repo.getFeature( IndexCreationFeature.class ).get(); StorageAsset packedIndexDirectory = icf.getLocalPackedIndexPath(); StorageAsset indexerDirectory = icf.getLocalIndexPath(); for (StorageAsset dir : new StorageAsset[] { packedIndexDirectory, indexerDirectory }) { if (dir.getFilePath()!=null) { Path localDirPath = dir.getFilePath(); Files.list( localDirPath ).filter( path -> path.getFileName( ).toString( ).startsWith( "nexus-maven-repository-index" ) ) .forEach( path -> { try { System.err.println( "Deleting " + path ); Files.delete( path ); } catch ( IOException e ) { e.printStackTrace( ); } } ); } } Path artifactFile = basePath.resolve( "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ); ArtifactIndexingTask task = new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.ADD, repo.getIndexingContext() ); task.setExecuteOnEntireRepo( false ); indexingExecutor.executeTask( task ); task = new ArtifactIndexingTask( repo, null, ArtifactIndexingTask.Action.FINISH, repo.getIndexingContext() ); task.setExecuteOnEntireRepo( false ); indexingExecutor.executeTask( task ); assertTrue( Files.exists(packedIndexDirectory.getFilePath()) ); assertTrue( Files.exists(indexerDirectory.getFilePath()) ); // test packed index file creation //no more zip //Assertions.assertThat(new File( indexerDirectory, "nexus-maven-repository-index.zip" )).exists(); Assertions.assertThat( Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.properties" ) )); Assertions.assertThat( Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.gz" ) )); assertFalse( Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.1.gz" ) )); // unpack .zip index //unzipIndex( indexerDirectory.getPath(), destDir.getPath() ); DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher( packedIndexDirectory.getFilePath().toFile() ); IndexUpdateRequest updateRequest = new IndexUpdateRequest( getIndexingContext(), fetcher ); //updateRequest.setLocalIndexCacheDir( indexerDirectory ); indexUpdater.fetchAndUpdateIndex( updateRequest ); BooleanQuery.Builder qb = new BooleanQuery.Builder(); qb.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ), BooleanClause.Occur.SHOULD ); qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), BooleanClause.Occur.SHOULD ); FlatSearchRequest request = new FlatSearchRequest( qb.build(), getIndexingContext() ); FlatSearchResponse response = indexer.searchFlat( request ); assertEquals( 1, response.getTotalHitsCount() ); Set<ArtifactInfo> results = response.getResults(); ArtifactInfo artifactInfo = results.iterator().next(); assertEquals( "org.apache.archiva", artifactInfo.getGroupId() ); assertEquals( "archiva-index-methods-jar-test", artifactInfo.getArtifactId() ); assertEquals( "test-repo", artifactInfo.getRepository() ); }
Example #14
Source File: ArchivaIndexingTaskExecutorTest.java From archiva with Apache License 2.0 | 4 votes |
@Test public void testAddArtifactToIndex() throws Exception { Path basePath = repo.getRoot().getFilePath(); Path artifactFile = basePath.resolve( "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ); ArtifactIndexingTask task = new ArtifactIndexingTask( repo, artifactFile, ArtifactIndexingTask.Action.ADD, repo.getIndexingContext()); indexingExecutor.executeTask( task ); task = new ArtifactIndexingTask( repo, null, ArtifactIndexingTask.Action.FINISH, repo.getIndexingContext() ); indexingExecutor.executeTask( task ); BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder( ); queryBuilder.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ), BooleanClause.Occur.SHOULD ); queryBuilder.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), BooleanClause.Occur.SHOULD ); BooleanQuery q = queryBuilder.build(); FlatSearchRequest request = new FlatSearchRequest( q , getIndexingContext()); FlatSearchResponse response = indexer.searchFlat( request ); assertTrue( Files.exists(basePath.resolve( ".indexer" )) ); assertTrue( Files.exists(basePath.resolve(".index" )) ); assertEquals( 1, response.getTotalHitsCount()); Set<ArtifactInfo> results = response.getResults(); ArtifactInfo artifactInfo = results.iterator().next(); assertEquals( "org.apache.archiva", artifactInfo.getGroupId() ); assertEquals( "archiva-index-methods-jar-test", artifactInfo.getArtifactId() ); assertEquals( "test-repo", artifactInfo.getRepository() ); }
Example #15
Source File: MavenRepositorySearch.java From archiva with Apache License 2.0 | 4 votes |
/** * calculate baseUrl without the context and base Archiva Url * * @param artifactInfo * @return */ protected String getBaseUrl( ArtifactInfo artifactInfo, List<String> selectedRepos ) { StringBuilder sb = new StringBuilder(); if ( StringUtils.startsWith( artifactInfo.getContext(), "remote-" ) ) { // it's a remote index result we search a managed which proxying this remote and on which // current user has read karma String managedRepoId = getManagedRepoId( StringUtils.substringAfter( artifactInfo.getContext(), "remote-" ), selectedRepos ); if ( managedRepoId != null ) { sb.append( '/' ).append( managedRepoId ); artifactInfo.setContext( managedRepoId ); } } else { sb.append( '/' ).append( artifactInfo.getContext() ); } sb.append( '/' ).append( StringUtils.replaceChars( artifactInfo.getGroupId(), '.', '/' ) ); sb.append( '/' ).append( artifactInfo.getArtifactId() ); sb.append( '/' ).append( artifactInfo.getVersion() ); sb.append( '/' ).append( artifactInfo.getArtifactId() ); sb.append( '-' ).append( artifactInfo.getVersion() ); if ( StringUtils.isNotBlank( artifactInfo.getClassifier() ) ) { sb.append( '-' ).append( artifactInfo.getClassifier() ); } // maven-plugin packaging is a jar if ( StringUtils.equals( "maven-plugin", artifactInfo.getPackaging() ) ) { sb.append( "jar" ); } else { sb.append( '.' ).append( artifactInfo.getPackaging() ); } return sb.toString(); }
Example #16
Source File: MavenRepositorySearch.java From archiva with Apache License 2.0 | 4 votes |
private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits, List<? extends ArtifactInfoFilter> artifactInfoFilters, List<String> selectedRepos, boolean includePoms ) { SearchResults results = new SearchResults(); Set<ArtifactInfo> artifactInfos = response.getResults(); for ( ArtifactInfo artifactInfo : artifactInfos ) { if ( StringUtils.equalsIgnoreCase( "pom", artifactInfo.getFileExtension() ) && !includePoms ) { continue; } String id = SearchUtil.getHitId( artifactInfo.getGroupId(), // artifactInfo.getArtifactId(), // artifactInfo.getClassifier(), // artifactInfo.getPackaging() ); Map<String, SearchResultHit> hitsMap = results.getHitsMap(); if ( !applyArtifactInfoFilters( artifactInfo, artifactInfoFilters, hitsMap ) ) { continue; } SearchResultHit hit = hitsMap.get( id ); if ( hit != null ) { if ( !hit.getVersions().contains( artifactInfo.getVersion() ) ) { hit.addVersion( artifactInfo.getVersion() ); } } else { hit = new SearchResultHit(); hit.setArtifactId( artifactInfo.getArtifactId() ); hit.setGroupId( artifactInfo.getGroupId() ); hit.setRepositoryId( artifactInfo.getRepository() ); hit.addVersion( artifactInfo.getVersion() ); hit.setBundleExportPackage( artifactInfo.getBundleExportPackage() ); hit.setBundleExportService( artifactInfo.getBundleExportService() ); hit.setBundleSymbolicName( artifactInfo.getBundleSymbolicName() ); hit.setBundleVersion( artifactInfo.getBundleVersion() ); hit.setBundleDescription( artifactInfo.getBundleDescription() ); hit.setBundleDocUrl( artifactInfo.getBundleDocUrl() ); hit.setBundleRequireBundle( artifactInfo.getBundleRequireBundle() ); hit.setBundleImportPackage( artifactInfo.getBundleImportPackage() ); hit.setBundleLicense( artifactInfo.getBundleLicense() ); hit.setBundleName( artifactInfo.getBundleName() ); hit.setContext( artifactInfo.getContext() ); hit.setGoals( artifactInfo.getGoals() ); hit.setPrefix( artifactInfo.getPrefix() ); hit.setPackaging( artifactInfo.getPackaging() ); hit.setClassifier( artifactInfo.getClassifier() ); hit.setFileExtension( artifactInfo.getFileExtension() ); hit.setUrl( getBaseUrl( artifactInfo, selectedRepos ) ); } results.addHit( id, hit ); } results.setTotalHits( response.getTotalHitsCount() ); results.setTotalHitsMapSize( results.getHitsMap().values().size() ); results.setReturnedHitsCount( response.getReturnedHitsCount() ); results.setLimits( limits ); if ( limits == null || limits.getSelectedPage() == SearchResultLimits.ALL_PAGES ) { return results; } else { return paginate( results ); } }
Example #17
Source File: NotifyingIndexCreator.java From netbeans with Apache License 2.0 | 4 votes |
@Override public boolean updateArtifactInfo(Document document, ArtifactInfo artifactInfo) { return false; }
Example #18
Source File: ArtifactDependencyIndexCreator.java From netbeans with Apache License 2.0 | 4 votes |
@Override public boolean updateArtifactInfo(Document doc, ArtifactInfo ai) { return false; }
Example #19
Source File: ClassDependencyIndexCreator.java From netbeans with Apache License 2.0 | 4 votes |
@Override public boolean updateArtifactInfo(Document document, ArtifactInfo artifactInfo) { return false; }