Search in sources :

Example 1 with Location

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);
}
Also used : TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) FileBasedTychoRepositoryIndex(org.eclipse.tycho.repository.local.index.FileBasedTychoRepositoryIndex) File(java.io.File)

Example 2 with Location

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());
}
Also used : InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) FileBasedTychoRepositoryIndex(org.eclipse.tycho.repository.local.index.FileBasedTychoRepositoryIndex) File(java.io.File) Test(org.junit.Test)

Example 3 with Location

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);
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) ArtifactsIO(org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO) TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) IOException(java.io.IOException) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) FileOutputStream(java.io.FileOutputStream) File(java.io.File) GAV(org.eclipse.tycho.p2.repository.GAV) BufferedOutputStream(java.io.BufferedOutputStream) HashSet(java.util.HashSet)

Example 4 with Location

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());
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) ArrayList(java.util.ArrayList) IRequiredCapability(org.eclipse.equinox.internal.p2.metadata.IRequiredCapability) ArtifactMock(org.eclipse.tycho.p2.impl.test.ArtifactMock) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File) DefaultDependencyMetadataGenerator(org.eclipse.tycho.p2.impl.publisher.DefaultDependencyMetadataGenerator) Test(org.junit.Test)

Example 5 with Location

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DirectorCommandException(org.eclipse.tycho.p2.tools.director.shared.DirectorCommandException) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) URI(java.net.URI) DirectorRuntime(org.eclipse.tycho.p2.tools.director.shared.DirectorRuntime)

Aggregations

Test (org.junit.Test)16 File (java.io.File)14 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)11 ArrayList (java.util.ArrayList)10 DefaultDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.DefaultDependencyMetadataGenerator)8 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)8 SourcesBundleDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.SourcesBundleDependencyMetadataGenerator)7 DependencyMetadataGenerator (org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator)7 InstallableUnitLocation (org.eclipse.tycho.p2.target.facade.TargetDefinition.InstallableUnitLocation)7 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)6 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)4 TargetDefinition (org.eclipse.tycho.p2.target.facade.TargetDefinition)4 IOException (java.io.IOException)3 URI (java.net.URI)3 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)3 TychoRepositoryIndex (org.eclipse.tycho.p2.repository.TychoRepositoryIndex)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)2