/** * Generate p2 data for an artifact, if the artifact is an OSGI bundle. * * <p>The p2 metadata produced by this method is only determined by the artifact, and the function * used for this conversion must not change (significantly) even in future versions. This is * required because the resulting metadata can be included in p2 repositories built by Tycho, and * hence may be propagated into the p2 universe. Therefore the metadata generated by this method * shall fulfil the basic assumption of p2 that ID+version uniquely identifies a unit/artifact. * Assuming that distinct bundle artifacts specify unique ID+versions in their manifest (which * should be mostly true), and the p2 BundlesAction used in the implementation doesn't change * significantly (which can also be assumed), these conditions specified above a met. * * <p>In slight deviation on the principles described in the previous paragraph, the * implementation adds GAV properties to the generated IU. This is justified by the potential * benefits of tracing the origin of artifact. * * @param mavenArtifact An artifact in local file system. * @return the p2 metadata of the artifact, or <code>null</code> if the artifact isn't a valid * OSGi bundle. */ IInstallableUnit attemptToPublishBundle(IArtifactFacade mavenArtifact) { if (!isAvailableAsLocalFile(mavenArtifact)) { // this should have been ensured by the caller throw new IllegalArgumentException("Not an artifact file: " + mavenArtifact.getLocation()); } if (isCertainlyNoBundle(mavenArtifact)) { return null; } PublisherRun publisherRun = new PublisherRun(mavenArtifact); IStatus status = publisherRun.execute(); if (!status.isOK()) { /** * If publishing of a jar fails, it is simply not added to the resolution context. The * BundlesAction already ignores non-bundle JARs silently, so an error status here indicates a * caught exception that we at least want to see. */ logger.warn(StatusTool.collectProblems(status), status.getException()); } IInstallableUnit publishedIU = publisherRun.getPublishedUnitIfExists(); if (publishedIU != null) { IArtifactDescriptor publishedArtifact = publisherRun.getPublishedArtifactDescriptor(); publishedArtifacts.addDescriptor(publishedArtifact, mavenArtifact); } return publishedIU; }
public TargetPlatformContent resolveContent(TargetDefinition definition) throws TargetDefinitionSyntaxException, TargetDefinitionResolutionException { List<URI> artifactRepositories = new ArrayList<URI>(); Set<IInstallableUnit> availableUnits = new LinkedHashSet<IInstallableUnit>(); Set<IInstallableUnit> rootIUs = new LinkedHashSet<IInstallableUnit>(); IncludeMode includeMode = null; Boolean includeAllEnvironments = null; for (Location locationDefinition : definition.getLocations()) { if (locationDefinition instanceof InstallableUnitLocation) { InstallableUnitLocation iuLocationDefinition = (InstallableUnitLocation) locationDefinition; if (includeMode != null && includeMode != iuLocationDefinition.getIncludeMode()) { throw new TargetDefinitionResolutionException( "Include mode must be the same for all locations"); } includeMode = iuLocationDefinition.getIncludeMode(); if (includeAllEnvironments != null && includeAllEnvironments.booleanValue() != iuLocationDefinition.includeAllEnvironments()) { throw new TargetDefinitionResolutionException( "The attribute 'includeAllPlatforms' must be the same for all locations"); } includeAllEnvironments = iuLocationDefinition.includeAllEnvironments(); List<IMetadataRepository> metadataRepositories = new ArrayList<IMetadataRepository>(); for (Repository repository : iuLocationDefinition.getRepositories()) { repositoryIdManager.addMapping(repository.getId(), repository.getLocation()); artifactRepositories.add(repository.getLocation()); metadataRepositories.add(loadRepository(repository)); } IQueryable<IInstallableUnit> locationUnits = new CompoundQueryable<IInstallableUnit>( metadataRepositories.toArray(new IMetadataRepository[metadataRepositories.size()])); for (Unit unit : iuLocationDefinition.getUnits()) { rootIUs.add(getUnitInstance(locationUnits, unit)); } Iterator<IInstallableUnit> iterator = locationUnits.query(QueryUtil.ALL_UNITS, monitor).iterator(); while (iterator.hasNext()) { IInstallableUnit unit = iterator.next(); if (!executionEnvironment.isNonApplicableEEUnit(unit)) { availableUnits.add(unit); } } } else { logger.warn( NLS.bind( "Target location type: {0} is not supported", locationDefinition.getTypeDescription())); } } Collection<IInstallableUnit> units; if (!availableUnits.isEmpty()) { AbstractResolutionStrategy strategy = getResolutionStrategy(includeMode, includeAllEnvironments); strategy.setRootInstallableUnits(rootIUs); strategy.setAvailableInstallableUnits(availableUnits); strategy.setEEResolutionHints(executionEnvironment); units = strategy.multiPlatformResolve(environments, monitor); } else { units = Collections.emptySet(); } if (definition.hasIncludedBundles()) { // the bundle selection list is currently not taken into account (see bug 373776) logger.warn( "De-selecting bundles in a target definition file is not supported. See http://wiki.eclipse.org/Tycho_Messages_Explained#Target_File_Include_Bundles for alternatives."); } return new TargetPlatformContent(units, artifactRepositories); }
public void showHelpForLoggedMessages() { if (hasLogged) { logger.warn("More information on the preceding warning(s) can be found here:"); logger.warn("- " + MIRROR_TOOL_MESSAGE_HELP); } }
public void log(IStatus status) { if (!status.isOK()) { logger.warn(MIRROR_TOOL_MESSAGE_PREFIX + StatusTool.collectProblems(status)); hasLogged = true; } }
public void log(IArtifactDescriptor descriptor, IStatus status) { if (!status.isOK()) { logger.debug(MIRROR_TOOL_MESSAGE_PREFIX + StatusTool.collectProblems(status)); hasLogged = true; } }