use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Location in project tycho by eclipse.
the class LocalMetadataRepositoryTest method createRepository.
private LocalMetadataRepository createRepository(File location) throws ProvisionException {
location.mkdirs();
File metadataFile = new File(location, FileBasedTychoRepositoryIndex.METADATA_INDEX_RELPATH);
metadataFile.delete();
metadataFile.getParentFile().mkdirs();
TychoRepositoryIndex metadataIndex = createMetadataIndex(location);
return new LocalMetadataRepository(location.toURI(), metadataIndex);
}
use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Location in project tycho by eclipse.
the class LocalMetadataRepositoryTest method testOutdatedIndex.
@Test
public void testOutdatedIndex() throws CoreException {
// create and fill repo
File location = new File("target/indexmetadataRepo");
LocalMetadataRepository repository = createRepository(location);
InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
iud.setId("test");
iud.setVersion(Version.parseVersion("1.0.0"));
iud.setProperty(RepositoryLayoutHelper.PROP_GROUP_ID, "group");
iud.setProperty(RepositoryLayoutHelper.PROP_ARTIFACT_ID, "artifact");
iud.setProperty(RepositoryLayoutHelper.PROP_VERSION, "version");
IInstallableUnit iu = MetadataFactory.createInstallableUnit(iud);
repository.addInstallableUnits(Arrays.asList(iu));
repository = (LocalMetadataRepository) loadRepository(location);
// check: the artifact is in the index
TychoRepositoryIndex metaIndex = createMetadataIndex(location);
Assert.assertFalse(metaIndex.getProjectGAVs().isEmpty());
// delete artifact from file system
deleteDir(new File(location, "group"));
// create a new repo and check that the reference was gracefully removed from the index
repository = (LocalMetadataRepository) loadRepository(location);
repository.save();
metaIndex = createMetadataIndex(location);
Assert.assertTrue(metaIndex.getProjectGAVs().isEmpty());
}
use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Location 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.target.facade.TargetDefinition.Location in project tycho by eclipse.
the class P2GeneratorImplTest method testOptionalImportPackage_REQUIRE.
@Test
public void testOptionalImportPackage_REQUIRE() throws Exception {
DefaultDependencyMetadataGenerator generator = createDependencyMetadataGenerator();
File location = new File("resources/generator/optional-import-package").getCanonicalFile();
ArtifactMock artifactMock = new ArtifactMock(location, "optional-import-package", "optional-import-package", "0.0.1", "eclipse-plugin");
Set<Object> units = generator.generateMetadata(artifactMock, getEnvironments(), OptionalResolutionAction.REQUIRE).getMetadata();
assertEquals(1, units.size());
IInstallableUnit iu = getUnit("optional-import-package", units);
assertNotNull(iu);
List<IRequirement> requirements = new ArrayList<>(iu.getRequirements());
assertEquals(1, requirements.size());
IRequiredCapability requirement = (IRequiredCapability) requirements.get(0);
assertTrue(requirement.isGreedy());
assertEquals(1, requirement.getMin());
assertEquals(1, requirement.getMax());
assertEquals(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE, requirement.getNamespace());
assertEquals("org.osgi.framework", requirement.getName());
}
use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Location in project tycho by eclipse.
the class StandaloneDirectorRuntimeFactory method installStandaloneDirector.
private void installStandaloneDirector(File installLocation, ArtifactRepository localMavenRepository) throws MojoExecutionException {
// using the internal director...
DirectorRuntime bootstrapDirector = osgiServices.getService(DirectorRuntime.class);
try {
// ... install from a zipped p2 repository obtained via Maven ...
URI directorRuntimeRepo = URI.create("jar:" + getDirectorRepositoryZip(localMavenRepository).toURI() + "!/");
DirectorRuntime.Command command = bootstrapDirector.newInstallCommand();
command.addMetadataSources(Arrays.asList(directorRuntimeRepo));
command.addArtifactSources(Arrays.asList(directorRuntimeRepo));
// ... a product that includes the p2 director application ...
command.addUnitToInstall("tycho-standalone-p2-director");
command.setProfileName("director");
// ... to a location in the target folder
command.setDestination(installLocation);
// there is only this environment in the p2 repository zip
// TODO use a "no environment-specific units" setting
command.setEnvironment(new TargetEnvironment("linux", "gtk", "x86_64"));
logger.info("Installing a standalone p2 Director...");
command.execute();
} catch (DirectorCommandException e) {
throw new MojoExecutionException("Could not install the standalone director", e);
}
}
Aggregations