use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.
the class MavenModelProcessorTest method resolvePluginVersionFromPropertyInProfile.
@Test
public void resolvePluginVersionFromPropertyInProfile() throws Exception {
final URI src = new URI("http://nowhere.com/path/to/repo");
final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-pom", "1.0");
final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
lineage.put(childRef, "test-pom-1.0.pom.xml");
final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true, false);
final String base = PROJ_BASE + "version-expression-in-a-profile/";
for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
final ProjectVersionRef ref = entry.getKey();
final String filename = entry.getValue();
final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
}
final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
final List<PluginView> buildPlugins = pomView.getAllBuildPlugins();
assertThat(buildPlugins, notNullValue());
assertThat(buildPlugins.size(), equalTo(1));
final PluginView pv = buildPlugins.get(0);
assertThat(pv, notNullValue());
assertThat(pv.getVersion(), equalTo("2.0"));
final ModelProcessorConfig discoveryConfig = new ModelProcessorConfig();
discoveryConfig.setIncludeManagedDependencies(true);
discoveryConfig.setIncludeBuildSection(true);
discoveryConfig.setIncludeManagedPlugins(false);
EProjectDirectRelationships result = fixture.getModelProcessor().readRelationships(pomView, src, discoveryConfig);
final Set<ProjectRelationship<?, ?>> rels = result.getExactAllRelationships();
logger.info("Found {} relationships:\n\n {}", rels.size(), new JoinString("\n ", rels));
boolean seen = false;
for (final ProjectRelationship<?, ?> rel : rels) {
if (rel.getType() == RelationshipType.PLUGIN && !rel.isManaged()) {
if (seen) {
fail("Multiple plugins found!");
}
seen = true;
assertThat(rel.getTarget().getVersionString(), equalTo("2.0"));
}
}
if (!seen) {
fail("Plugin relationship not found!");
}
}
use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.
the class MavenModelProcessorTest method resolveRepositoriesExpressionFromPropertyInProfile.
@Test
public void resolveRepositoriesExpressionFromPropertyInProfile() throws Exception {
final URI src = new URI("http://nowhere.com/path/to/repo");
final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-pom", "1.0");
final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
lineage.put(childRef, "test-pom-1.0.pom.xml");
final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true, false);
final String base = PROJ_BASE + "resolve-expression-in-a-profile/";
for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
final ProjectVersionRef ref = entry.getKey();
final String filename = entry.getValue();
final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
}
final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
final List<RepositoryView> rvs = pomView.getAllRepositories();
assertThat(rvs, notNullValue());
assertThat(rvs.size(), equalTo(3));
assertThat(rvs.get(0).getName(), equalTo("repo.one"));
assertThat(rvs.get(0).getUrl(), equalTo("http://repo.one.repository"));
assertThat(rvs.get(1).getName(), equalTo("test.oracle.repo"));
assertThat(rvs.get(1).getUrl(), equalTo("http://test.oracle.repository"));
assertThat(rvs.get(2).getName(), equalTo("test.second.oracle.repo"));
assertThat(rvs.get(2).getUrl(), equalTo("http://another.test.two.oracle.repository"));
}
use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.
the class DownloadHandlerConcurrencyTest method concurrentDownloadWaitsThenUsesFirstResult_SmallFile.
@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "DownloadHandler", targetMethod = "<init>", targetLocation = "ENTRY", action = "debug(\"Creating rendezvous\"); createRendezvous(\"tsync\", 4);"), @BMRule(name = "rendezvous threads", targetClass = "DownloadHandler", targetMethod = "joinOrStart", targetLocation = "ENTRY", action = "debug(\"waiting for rendezvous\"); rendezvous(\"tsync\"); debug(\"proceeding\");") })
@Test
public void concurrentDownloadWaitsThenUsesFirstResult_SmallFile() throws Exception {
final NotFoundCache nfc = new MemoryNotFoundCache();
final TransportManagerConfig mgrConfig = new TransportManagerConfig();
handler = new DownloadHandler(nfc, mgrConfig, executor);
// NOTE: Coordinate with "init" @BMRule above!
final int threads = 4;
final int timeoutSeconds = 10;
final String content = "this is a test " + System.currentTimeMillis();
final String base = "repo";
final String path = "this/is/the/path.txt";
final String baseurl = server.formatUrl(base);
// Serve the content EXACTLY ONCE. It should be cached / cache should be used after that.
server.expect("GET", server.formatUrl(base, path), new ExpectationHandler() {
private boolean sent = false;
@Override
public void handle(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
if (!sent) {
resp.setStatus(HttpServletResponse.SC_OK);
resp.getWriter().write(content);
sent = true;
} else {
throw new ServletException("Cannot write content more than once.");
}
}
});
final ConcreteResource resource = new ConcreteResource(new SimpleLocation(base, baseurl), path);
final Transfer target = cacheProvider.getTransfer(resource);
final CountDownLatch latch = new CountDownLatch(threads);
final AtomicInteger successes = new AtomicInteger(0);
final Logger logger = LoggerFactory.getLogger(getClass());
// start threads, then wait for each to complete, and
for (int i = 0; i < threads; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
String oldName = Thread.currentThread().getName();
try {
Thread.currentThread().setName("Download - " + oldName);
Transfer result = handler.download(resource, target, timeoutSeconds, transport, false, new EventMetadata());
try (InputStream in = result.openInputStream()) {
String resultContent = IOUtils.toString(in);
if (resultContent.equals(content)) {
successes.incrementAndGet();
} else {
logger.error("Expected content: '{}'\nActual content: '{}'", content, resultContent);
}
} catch (IOException e) {
logger.error("Failed to read transfer: " + e.getMessage(), e);
}
} catch (TransferException e) {
logger.error("Failed to retrieve: " + e.getMessage(), e);
} finally {
latch.countDown();
Thread.currentThread().setName(oldName);
}
}
});
}
}
use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.
the class MavenPomReader method getDocRef.
private DocRef<ProjectVersionRef> getDocRef(final ProjectVersionRef ref, final List<? extends Location> locations, final boolean cache, final EventMetadata eventMetadata) throws TransferException, GalleyMavenException {
DocRef<ProjectVersionRef> dr = getFirstCached(ref, locations);
if (dr == null) {
final Transfer transfer = artifacts.retrieveFirst(locations, ref.asPomArtifact(), eventMetadata);
if (transfer == null) {
return null;
}
final Document doc = xml.parse(transfer, new EventMetadata());
dr = new DocRef<>(ref, transfer.getLocation().toString(), doc);
if (cache) {
cache(dr);
}
}
return dr;
}
use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.
the class TransferManagerImpl method retrieveFirst.
@Override
public Transfer retrieveFirst(final VirtualResource virt, final EventMetadata eventMetadata) throws TransferException {
Transfer target;
TransferException lastError = null;
int tries = 0;
for (final ConcreteResource res : virt) {
tries++;
if (res == null) {
continue;
}
try {
target = retrieve(res, true, eventMetadata);
lastError = null;
if (target != null && target.exists()) {
return target;
}
} catch (final TransferException e) {
logger.warn("Failed to retrieve: {}. {} more tries. (Reason: {})", res, (virt.toConcreteResources().size() - tries), e.getMessage());
lastError = e;
}
}
if (lastError != null) {
throw lastError;
}
fileEventManager.fire(new FileNotFoundEvent(virt, eventMetadata));
return null;
}
Aggregations