use of org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO 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.maven.repository.xmlio.ArtifactsIO 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.maven.repository.xmlio.ArtifactsIO in project tycho by eclipse.
the class ModuleArtifactRepository method internalStoreWithException.
private void internalStoreWithException() throws IOException {
ArtifactsIO io = new ArtifactsIO();
io.writeXML(descriptors, p2DataFile);
}
use of org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO in project tycho by eclipse.
the class P2GeneratorImpl method persistMetadata.
@Override
public void persistMetadata(Map<String, IP2Artifact> metadata, File unitsXml, File artifactsXml) throws IOException {
Set<IInstallableUnit> units = new LinkedHashSet<>();
Set<IArtifactDescriptor> artifactDescriptors = new LinkedHashSet<>();
for (IP2Artifact artifact : metadata.values()) {
for (Object unit : artifact.getInstallableUnits()) {
units.add((IInstallableUnit) unit);
}
artifactDescriptors.add((IArtifactDescriptor) artifact.getArtifactDescriptor());
}
new MetadataIO().writeXML(units, unitsXml);
new ArtifactsIO().writeXML(artifactDescriptors, artifactsXml);
}
use of org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO in project tycho by eclipse.
the class ModuleArtifactRepository method load.
private void load() throws ProvisionException {
try {
FileInputStream p2DataFileStream = new FileInputStream(p2DataFile);
try {
Set<IArtifactDescriptor> descriptors = new ArtifactsIO().readXML(p2DataFileStream);
for (IArtifactDescriptor descriptor : descriptors) {
ModuleArtifactDescriptor internalDescriptor = getInternalDescriptorFromLoadedDescriptor(descriptor, p2DataFile);
// TODO check that GAV properties match module GAV
internalAddInternalDescriptor(internalDescriptor);
}
} finally {
p2DataFileStream.close();
}
} catch (IOException e) {
throw failedReadException(p2DataFile, null, e);
}
}
Aggregations