use of org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation in project tycho by eclipse.
the class ReactorRepositoryManagerTest method testTargetPlatformComputationInIntegration.
@Test
public void testTargetPlatformComputationInIntegration() throws Exception {
subject = getService(ReactorRepositoryManagerFacade.class);
ReactorProject currentProject = new ReactorProjectStub("reactor-artifact");
TargetPlatformConfigurationStub tpConfig = new TargetPlatformConfigurationStub();
tpConfig.addP2Repository(new MavenRepositoryLocation(null, ResourceUtil.resourceFile("repositories/launchers").toURI()));
subject.computePreliminaryTargetPlatform(currentProject, tpConfig, new ExecutionEnvironmentConfigurationStub("JavaSE-1.7"), null, null);
ReactorProjectIdentities upstreamProject = new ReactorProjectIdentitiesStub(ResourceUtil.resourceFile("projectresult"));
subject.computeFinalTargetPlatform(currentProject, Arrays.asList(upstreamProject));
P2TargetPlatform finalTP = (P2TargetPlatform) currentProject.getContextValue("org.eclipse.tycho.core.TychoConstants/targetPlatform");
Collection<IInstallableUnit> units = finalTP.getInstallableUnits();
// units from the p2 repository
assertThat(units, hasItem(unitWithId("org.eclipse.equinox.launcher")));
// units from the upstream project
assertThat(units, hasItem(unitWithId("bundle")));
assertThat(units, hasItem(unitWithId("bundle.source")));
// TODO get artifact
}
use of org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation in project tycho by eclipse.
the class TargetPlatformFactoryImpl method createTargetPlatform.
/**
* Computes the target platform from the given configuration and content.
*
* <p>
* Used as entry point for tests, which can provide the execution environment configuration via
* the more low-level type {@link ExecutionEnvironmentResolutionHandler}.
* </p>
*
* @param tpConfiguration
* @param eeResolutionHandler
* Representation of the target execution environment profile. In case of a custom EE
* profile, the handler also reads the full specification from the target platform.
* @param reactorProjects
* may be <code>null</code>
* @param pomDependencies
* may be <code>null</code>
*
* @see #createTargetPlatform(TargetPlatformConfigurationStub,
* ExecutionEnvironmentConfiguration, List, PomDependencyCollector)
*/
public P2TargetPlatform createTargetPlatform(TargetPlatformConfigurationStub tpConfiguration, ExecutionEnvironmentResolutionHandler eeResolutionHandler, List<ReactorProject> reactorProjects, PomDependencyCollector pomDependencies) {
List<TargetDefinitionContent> targetFileContent = resolveTargetDefinitions(tpConfiguration, eeResolutionHandler.getResolutionHints());
PomDependencyCollectorImpl pomDependenciesContent = (PomDependencyCollectorImpl) pomDependencies;
// TODO 412416 remove when the RepositoryBlackboardKey registration is gone
if (pomDependenciesContent == null)
pomDependenciesContent = new PomDependencyCollectorImpl(mavenContext);
// TODO 372780 get rid of this special handling of pomDependency artifacts: there should be one p2 artifact repo view on the target platform
IRawArtifactFileProvider pomDependencyArtifactRepo = pomDependenciesContent.getArtifactRepoOfPublishedBundles();
RepositoryBlackboardKey blackboardKey = RepositoryBlackboardKey.forResolutionContextArtifacts(pomDependenciesContent.getProjectLocation());
ArtifactRepositoryBlackboard.putRepository(blackboardKey, new ProviderOnlyArtifactRepository(pomDependencyArtifactRepo, Activator.getProvisioningAgent(), blackboardKey.toURI()));
logger.debug("Registered artifact repository " + blackboardKey);
Set<MavenRepositoryLocation> completeRepositories = tpConfiguration.getP2Repositories();
registerRepositoryIDs(completeRepositories);
// collect & process metadata
boolean includeLocalMavenRepo = shouldIncludeLocallyInstalledUnits(tpConfiguration);
LinkedHashSet<IInstallableUnit> externalUIs = gatherExternalInstallableUnits(completeRepositories, targetFileContent, pomDependenciesContent, includeLocalMavenRepo);
Map<IInstallableUnit, ReactorProjectIdentities> reactorProjectUIs = getPreliminaryReactorProjectUIs(reactorProjects);
List<TargetPlatformFilter> iuFilters = tpConfiguration.getFilters();
TargetPlatformFilterEvaluator filter = !iuFilters.isEmpty() ? new TargetPlatformFilterEvaluator(iuFilters, logger) : null;
applyConfiguredFilter(filter, reactorProjectUIs.keySet());
applyFilters(filter, externalUIs, reactorProjectUIs.keySet(), eeResolutionHandler.getResolutionHints());
PreliminaryTargetPlatformImpl targetPlatform = new //
PreliminaryTargetPlatformImpl(//
reactorProjectUIs, //
externalUIs, //
pomDependenciesContent.getMavenInstallableUnits(), //
eeResolutionHandler.getResolutionHints(), //
filter, //
localMetadataRepository, createExternalArtifactProvider(completeRepositories, targetFileContent, pomDependencyArtifactRepo, //
tpConfiguration.getIncludePackedArtifacts()), //
localArtifactRepository, //
includeLocalMavenRepo, logger);
eeResolutionHandler.readFullSpecification(targetPlatform.getInstallableUnits());
return targetPlatform;
}
use of org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation in project tycho by eclipse.
the class P2DependencyResolver method addEntireP2RepositoryToTargetPlatform.
private void addEntireP2RepositoryToTargetPlatform(ArtifactRepository repository, TargetPlatformConfigurationStub resolutionContext) {
try {
if (repository.getLayout() instanceof P2ArtifactRepositoryLayout) {
URI url = new URL(repository.getUrl()).toURI();
resolutionContext.addP2Repository(new MavenRepositoryLocation(repository.getId(), url));
getLogger().debug("Added p2 repository " + repository.getId() + " (" + repository.getUrl() + ")");
}
} catch (MalformedURLException e) {
throw new RuntimeException("Invalid repository URL: " + repository.getUrl(), e);
} catch (URISyntaxException e) {
throw new RuntimeException("Invalid repository URL: " + repository.getUrl(), e);
}
}
use of org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation in project tycho by eclipse.
the class BaselineValidator method validateAndReplace.
public Map<String, IP2Artifact> validateAndReplace(MavenProject project, MojoExecution execution, Map<String, IP2Artifact> reactorMetadata, List<Repository> baselineRepositories, BaselineMode baselineMode, BaselineReplace baselineReplace) throws IOException, MojoExecutionException {
Map<String, IP2Artifact> result = reactorMetadata;
if (baselineMode != disable && baselineRepositories != null && !baselineRepositories.isEmpty()) {
List<MavenRepositoryLocation> _repositories = new ArrayList<>();
for (Repository repository : baselineRepositories) {
if (repository.getUrl() != null) {
_repositories.add(new MavenRepositoryLocation(repository.getId(), repository.getUrl()));
}
}
File baselineBasedir = new File(project.getBuild().getDirectory(), "baseline");
BaselineService baselineService = getService(BaselineService.class);
Map<String, IP2Artifact> baselineMetadata = baselineService.getProjectBaseline(_repositories, reactorMetadata, baselineBasedir);
if (baselineMetadata != null) {
CompoundArtifactDelta delta = getDelta(baselineService, baselineMetadata, reactorMetadata, execution);
if (delta != null) {
if (System.getProperties().containsKey("tycho.debug.artifactcomparator")) {
File logdir = new File(project.getBuild().getDirectory(), "artifactcomparison");
log.info("Artifact comparison detailed log directory " + logdir.getAbsolutePath());
for (Map.Entry<String, ArtifactDelta> classifier : delta.getMembers().entrySet()) {
if (classifier.getValue() instanceof CompoundArtifactDelta) {
((CompoundArtifactDelta) classifier.getValue()).writeDetails(new File(logdir, classifier.getKey()));
}
}
}
if (baselineMode == fail || (baselineMode == failCommon && !isMissingOnlyDelta(delta))) {
throw new MojoExecutionException(delta.getDetailedMessage());
} else {
log.warn(project.toString() + ": " + delta.getDetailedMessage());
}
}
if (baselineReplace != none) {
result = new LinkedHashMap<>();
// replace reactor artifacts with baseline
ArrayList<String> replaced = new ArrayList<>();
for (Map.Entry<String, IP2Artifact> artifact : baselineMetadata.entrySet()) {
File baseLineFile = artifact.getValue().getLocation();
String classifier = artifact.getKey();
File reactorFile = reactorMetadata.get(classifier).getLocation();
if (baseLineFile.isFile() && baseLineFile.length() == 0L) {
// workaround for possibly corrupted download - bug 484003
log.error("baseline file " + baseLineFile.getAbsolutePath() + " is empty. Will not replace " + reactorFile);
} else {
FileUtils.copyFile(baseLineFile, reactorFile);
result.put(classifier, artifact.getValue());
if (classifier != null) {
replaced.add(classifier);
}
}
}
// un-attach and delete artifacts present in reactor but not in baseline
ArrayList<String> removed = new ArrayList<>();
ArrayList<String> inconsistent = new ArrayList<>();
for (Map.Entry<String, IP2Artifact> entry : reactorMetadata.entrySet()) {
String classifier = entry.getKey();
IP2Artifact artifact = entry.getValue();
if (classifier == null || artifact == null) {
continue;
}
if (baselineReplace == all && !baselineMetadata.containsKey(classifier)) {
List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
ListIterator<Artifact> iterator = attachedArtifacts.listIterator();
while (iterator.hasNext()) {
if (classifier.equals(iterator.next().getClassifier())) {
iterator.remove();
break;
}
}
artifact.getLocation().delete();
removed.add(classifier);
} else {
inconsistent.add(classifier);
result.put(classifier, artifact);
}
}
if (log.isInfoEnabled()) {
StringBuilder msg = new StringBuilder();
msg.append(project.toString());
msg.append("\n The main artifact has been replaced with the baseline version.\n");
if (!replaced.isEmpty()) {
msg.append(" The following attached artifacts have been replaced with the baseline version: ");
msg.append(replaced.toString());
msg.append("\n");
}
if (!removed.isEmpty()) {
msg.append(" The following attached artifacts are not present in the baseline and have been removed: ");
msg.append(removed.toString());
msg.append("\n");
}
log.info(msg.toString());
}
}
} else {
log.info("No baseline version " + project);
}
}
return result;
}
use of org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation in project tycho by eclipse.
the class BaselineServiceImpl method getProjectBaseline.
@Override
public Map<String, IP2Artifact> getProjectBaseline(Collection<MavenRepositoryLocation> baselineLocations, Map<String, IP2Artifact> reactor, File target) {
// baseline repository may contain artifacts with the same id/version but different contents
// compared to what is installed (or cached) locally.
// current local repository layout does not track per-repository artifacts and does not allow
// multiple different artifacts with same id/version.
CompositeMetadataRepository baselineUnits;
CompositeArtifactRepository baselineArtifacts;
try {
IProvisioningAgent remoteAgent = remoteAgentManager.getProvisioningAgent();
IRepositoryIdManager remoteRepositoryIdManager = (IRepositoryIdManager) remoteAgent.getService(IRepositoryIdManager.SERVICE_NAME);
IMetadataRepositoryManager remoteMetadataRepositoryManager = (IMetadataRepositoryManager) remoteAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
IArtifactRepositoryManager remoteArtifactRepositoryManager = (IArtifactRepositoryManager) remoteAgent.getService(IArtifactRepositoryManager.SERVICE_NAME);
baselineUnits = CompositeMetadataRepository.createMemoryComposite(remoteAgent);
baselineArtifacts = CompositeArtifactRepository.createMemoryComposite(remoteAgent);
for (MavenRepositoryLocation location : baselineLocations) {
URI url = location.getURL();
try {
remoteRepositoryIdManager.addMapping(location.getId(), url);
// TODO offline mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=337022
// not strictly necessary, but makes sure metadata download is visible in the console/log
remoteMetadataRepositoryManager.loadRepository(url, monitor);
remoteArtifactRepositoryManager.loadRepository(url, monitor);
baselineUnits.addChild(url);
baselineArtifacts.addChild(url);
} catch (ProvisionException e) {
// baseline repository may not exist yet
mavenContext.getLogger().warn(e.getMessage(), e);
}
}
} catch (ProvisionException e) {
throw new RuntimeException(e);
}
Map<String, IP2Artifact> result = new LinkedHashMap<>();
for (Map.Entry<String, IP2Artifact> reactorArtifact : reactor.entrySet()) {
IArtifactDescriptor descriptor = (IArtifactDescriptor) reactorArtifact.getValue().getArtifactDescriptor();
IArtifactDescriptor baselineDescriptor = getBaselineDescriptor(baselineArtifacts, descriptor);
if (baselineDescriptor == null) {
continue;
}
IArtifactKey baslineKey = baselineDescriptor.getArtifactKey();
String format = baselineDescriptor.getProperty(IArtifactDescriptor.FORMAT);
File baselineArtifact = new File(target, baslineKey.getClassifier() + "/" + baslineKey.getId() + "/" + baslineKey.getVersion() + (format != null ? "." + format : ""));
try {
baselineArtifact.getParentFile().mkdirs();
OutputStream os = new BufferedOutputStream(new FileOutputStream(baselineArtifact));
try {
IStatus status = baselineArtifacts.getRawArtifact(baselineDescriptor, os, monitor);
if (status.matches(IStatus.ERROR | IStatus.CANCEL)) {
String repository = baselineDescriptor.getRepository().getLocation().toString();
String artifactId = baselineDescriptor.getArtifactKey().getId();
String artifactVersion = baselineDescriptor.getArtifactKey().getVersion().toString();
String statusMessage = StatusTool.toLogMessage(status);
throw new RuntimeException(String.format("Error trying to download %s version %s from %s:\n%s", artifactId, artifactVersion, repository, statusMessage), StatusTool.findException(status));
}
} finally {
try {
os.close();
} catch (IOException e) {
// ignored
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
List<IInstallableUnit> units = new ArrayList<>();
for (Object _unit : reactorArtifact.getValue().getInstallableUnits()) {
IInstallableUnit unit = (IInstallableUnit) _unit;
IInstallableUnit baselineUnit = getBaselineUnit(baselineUnits, unit.getId(), unit.getVersion());
if (baselineUnit != null) {
units.add(baselineUnit);
}
}
result.put(reactorArtifact.getKey(), new P2Artifact(baselineArtifact, units, descriptor));
}
return !result.isEmpty() ? result : null;
}
Aggregations