use of org.eclipse.tycho.p2.repository.GAV in project tycho by eclipse.
the class GAVArtifactDescriptor method getP2DerivedCoordinates.
/**
* @return fake Maven coordinates derived from the given key; never <code>null</code>
*/
private static MavenRepositoryCoordinates getP2DerivedCoordinates(IArtifactKey key, Map<String, String> properties) {
GAV gav = RepositoryLayoutHelper.getP2Gav(key.getClassifier(), key.getId(), key.getVersion().toString());
String classifier = null;
String extension = RepositoryLayoutHelper.DEFAULT_EXTERNSION;
if (properties != null && IArtifactDescriptor.FORMAT_PACKED.equals(properties.get(IArtifactDescriptor.FORMAT))) {
classifier = RepositoryLayoutHelper.PACK200_CLASSIFIER;
extension = RepositoryLayoutHelper.PACK200_EXTENSION;
}
return new MavenRepositoryCoordinates(gav, classifier, extension);
}
use of org.eclipse.tycho.p2.repository.GAV in project tycho by eclipse.
the class LocalArtifactRepository method saveMaven.
private void saveMaven() {
File location = getBasedir();
TychoRepositoryIndex index = localRepoIndices.getArtifactsIndex();
ArtifactsIO io = new ArtifactsIO();
Set<IArtifactDescriptor> changedDescriptors = new HashSet<IArtifactDescriptor>(descriptors);
changedDescriptors.removeAll(descriptorsOnLastSave);
Set<IArtifactKey> changedKeys = new HashSet<>();
for (IArtifactDescriptor changedDescriptor : changedDescriptors) {
changedKeys.add(changedDescriptor.getArtifactKey());
}
for (IArtifactKey key : changedKeys) {
Set<GAVArtifactDescriptor> keyDescriptors = descriptorsMap.get(key);
if (keyDescriptors != null && !keyDescriptors.isEmpty()) {
// all descriptors should have the same GAV
GAVArtifactDescriptor anyDescriptorOfKey = keyDescriptors.iterator().next();
GAV gav = anyDescriptorOfKey.getMavenCoordinates().getGav();
index.addGav(gav);
String relpath = getMetadataRelpath(gav);
File file = new File(location, relpath);
file.getParentFile().mkdirs();
try {
OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
try {
io.writeXML(keyDescriptors, os);
} finally {
os.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
try {
index.save();
} catch (IOException e) {
throw new RuntimeException(e);
}
descriptorsOnLastSave = new HashSet<IArtifactDescriptor>(descriptors);
}
use of org.eclipse.tycho.p2.repository.GAV in project tycho by eclipse.
the class LocalArtifactRepository method loadMaven.
private void loadMaven() {
final ArtifactsIO io = new ArtifactsIO();
TychoRepositoryIndex index = localRepoIndices.getArtifactsIndex();
for (final GAV gav : index.getProjectGAVs()) {
try {
File localArtifactFileLocation = contentLocator.getLocalArtifactLocation(gav, RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS, RepositoryLayoutHelper.EXTENSION_P2_ARTIFACTS);
if (!localArtifactFileLocation.exists()) {
// if files have been manually removed from the repository, simply remove them from the index (bug 351080)
index.removeGav(gav);
} else {
final InputStream is = new FileInputStream(contentLocator.getLocalArtifactLocation(gav, RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS, RepositoryLayoutHelper.EXTENSION_P2_ARTIFACTS));
try {
final Set<IArtifactDescriptor> gavDescriptors = io.readXML(is);
for (IArtifactDescriptor descriptor : gavDescriptors) {
internalAddDescriptor(descriptor);
}
} finally {
is.close();
}
}
} catch (IOException e) {
// TODO throw properly typed exception if repository cannot be loaded
e.printStackTrace();
}
}
descriptorsOnLastSave = new HashSet<IArtifactDescriptor>(descriptors);
}
use of org.eclipse.tycho.p2.repository.GAV in project tycho by eclipse.
the class LocalMetadataRepository method save.
public void save() {
File basedir = new File(getLocation());
MetadataIO io = new MetadataIO();
for (GAV gav : changedGAVs) {
Set<IInstallableUnit> gavUnits = unitsMap.get(gav);
if (gavUnits != null && !gavUnits.isEmpty()) {
String relpath = RepositoryLayoutHelper.getRelativePath(gav, RepositoryLayoutHelper.CLASSIFIER_P2_METADATA, RepositoryLayoutHelper.EXTENSION_P2_METADATA);
File file = new File(basedir, relpath);
file.getParentFile().mkdirs();
try {
io.writeXML(gavUnits, file);
metadataIndex.addGav(gav);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
try {
metadataIndex.save();
} catch (IOException e) {
throw new RuntimeException(e);
}
changedGAVs.clear();
}
use of org.eclipse.tycho.p2.repository.GAV in project tycho by eclipse.
the class LocalMetadataRepository method addInstallableUnits.
@Override
public void addInstallableUnits(Collection<IInstallableUnit> newUnits) {
for (IInstallableUnit unit : newUnits) {
GAV gav = RepositoryLayoutHelper.getGAV(unit.getProperties());
addInstallableUnit(unit, gav);
}
save();
}
Aggregations