Search in sources :

Example 1 with IO.getFile

use of aQute.lib.io.IO.getFile in project bnd by bndtools.

the class FileRepoTest method testIndex.

/**
	 * Test a repo with an index
	 */
public void testIndex() throws Exception {
    //
    // Check if the index property works
    // by verifying the diff between the
    // testRepo and the indexed Repo
    //
    assertNull(testRepo.getResources());
    assertNotNull(indexedRepo.getResources());
    //
    // Check that we can actually put a resource
    //
    PutResult put = indexedRepo.put(IO.getFile("jar/osgi.jar").toURI().toURL().openStream(), null);
    assertNotNull(put);
    // Can we get it?
    ResourceDescriptor desc = indexedRepo.getDescriptor("osgi", new Version("4.0"));
    assertNotNull(desc);
    // Got the same file?
    assertTrue(Arrays.equals(put.digest, desc.id));
    //
    // Check if the description was copied
    //
    assertEquals("OSGi Service Platform Release 4 Interfaces and Classes for use in compiling bundles.", desc.description);
    //
    // We must be able to access by its sha1
    //
    ResourceDescriptor resource = indexedRepo.getResource(put.digest);
    assertTrue(Arrays.equals(resource.id, desc.id));
    //
    // Check if we now have a set of resources
    //
    SortedSet<ResourceDescriptor> resources = indexedRepo.getResources();
    assertEquals(1, resources.size());
    ResourceDescriptor rd = resources.iterator().next();
    assertTrue(Arrays.equals(rd.id, put.digest));
    //
    // Check if the bsn brings us back
    //
    File file = indexedRepo.get(desc.bsn, desc.version, null);
    assertNotNull(file);
    assertTrue(Arrays.equals(put.digest, SHA1.digest(file).digest()));
    byte[] digest = SHA256.digest(file).digest();
    assertTrue(Arrays.equals(rd.sha256, digest));
    //
    // Delete and see if it is really gone
    //
    indexedRepo.delete(desc.bsn, desc.version);
    resources = indexedRepo.getResources();
    assertEquals(0, resources.size());
    file = indexedRepo.get(desc.bsn, desc.version, null);
    assertNull(file);
    resource = indexedRepo.getResource(put.digest);
    assertNull(resource);
}
Also used : Version(aQute.bnd.version.Version) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) IO.getFile(aQute.lib.io.IO.getFile) File(java.io.File) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 2 with IO.getFile

use of aQute.lib.io.IO.getFile in project bnd by bndtools.

the class FileRepoTest method tearDown.

@Override
protected void tearDown() throws Exception {
    File nonExistentDir = IO.getFile("invalidrepo");
    delete(nonExistentDir);
    IO.delete(tmp);
}
Also used : IO.getFile(aQute.lib.io.IO.getFile) File(java.io.File)

Example 3 with IO.getFile

use of aQute.lib.io.IO.getFile in project bnd by bndtools.

the class Jar method copyResource.

private void copyResource(File dir, String path, Resource resource) throws IOException, Exception {
    File to = IO.getFile(dir, path);
    IO.mkdirs(to.getParentFile());
    IO.copy(resource.openInputStream(), to);
}
Also used : IO.getFile(aQute.lib.io.IO.getFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 4 with IO.getFile

use of aQute.lib.io.IO.getFile in project bnd by bndtools.

the class Jar method writeFolder.

public void writeFolder(File dir) throws Exception {
    IO.mkdirs(dir);
    if (!dir.exists())
        throw new IllegalArgumentException("The directory " + dir + " to write the JAR " + this + " could not be created");
    if (!dir.isDirectory())
        throw new IllegalArgumentException("The directory " + dir + " to write the JAR " + this + " to is not a directory");
    check();
    Set<String> done = new HashSet<String>();
    Set<String> directories = new HashSet<String>();
    if (doNotTouchManifest) {
        Resource r = getResource(manifestName);
        if (r != null) {
            copyResource(dir, manifestName, r);
            done.add(manifestName);
        }
    } else {
        File file = IO.getFile(dir, manifestName);
        IO.mkdirs(file.getParentFile());
        try (OutputStream fout = IO.outputStream(file)) {
            writeManifest(fout);
            done.add(manifestName);
        }
    }
    for (Map.Entry<String, Resource> entry : getResources().entrySet()) {
        String path = entry.getKey();
        if (done.contains(path))
            continue;
        Resource resource = entry.getValue();
        copyResource(dir, path, resource);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) DigestOutputStream(java.security.DigestOutputStream) IO.getFile(aQute.lib.io.IO.getFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) Map(java.util.Map) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Example 5 with IO.getFile

use of aQute.lib.io.IO.getFile in project bnd by bndtools.

the class BndMavenPlugin method loadProjectProperties.

private File loadProjectProperties(Builder builder, MavenProject project) throws Exception {
    // Load parent project properties first
    MavenProject parentProject = project.getParent();
    if (parentProject != null) {
        loadProjectProperties(builder, parentProject);
    }
    // Merge in current project properties
    Xpp3Dom configuration = project.getGoalConfiguration("biz.aQute.bnd", "bnd-maven-plugin", mojoExecution.getExecutionId(), mojoExecution.getGoal());
    File baseDir = project.getBasedir();
    if (baseDir != null) {
        // file system based pom
        File pomFile = project.getFile();
        builder.updateModified(pomFile.lastModified(), "POM: " + pomFile);
        // check for bnd file
        String bndFileName = Project.BNDFILE;
        if (configuration != null) {
            Xpp3Dom bndfileElement = configuration.getChild("bndfile");
            if (bndfileElement != null) {
                bndFileName = bndfileElement.getValue();
            }
        }
        File bndFile = IO.getFile(baseDir, bndFileName);
        if (bndFile.isFile()) {
            logger.debug("loading bnd properties from file: {}", bndFile);
            // we use setProperties to handle -include
            builder.setProperties(bndFile.getParentFile(), builder.loadProperties(bndFile));
            return bndFile;
        }
    // no bnd file found, so we fall through
    }
    // check for bnd-in-pom configuration
    if (configuration != null) {
        Xpp3Dom bndElement = configuration.getChild("bnd");
        if (bndElement != null) {
            logger.debug("loading bnd properties from bnd element in pom: {}", project);
            UTF8Properties properties = new UTF8Properties();
            properties.load(bndElement.getValue(), project.getFile(), builder);
            if (baseDir != null) {
                String here = baseDir.toURI().getPath();
                here = Matcher.quoteReplacement(here.substring(0, here.length() - 1));
                properties = properties.replaceAll("\\$\\{\\.\\}", here);
            }
            // we use setProperties to handle -include
            builder.setProperties(baseDir, properties);
        }
    }
    return project.getFile();
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenProject(org.apache.maven.project.MavenProject) IO.getFile(aQute.lib.io.IO.getFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Aggregations

IO.getFile (aQute.lib.io.IO.getFile)8 File (java.io.File)8 PutResult (aQute.bnd.service.RepositoryPlugin.PutResult)3 ZipFile (java.util.zip.ZipFile)3 Version (aQute.bnd.version.Version)2 DownloadListener (aQute.bnd.service.RepositoryPlugin.DownloadListener)1 PutOptions (aQute.bnd.service.RepositoryPlugin.PutOptions)1 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)1 FileRepo (aQute.lib.deployer.FileRepo)1 UTF8Properties (aQute.lib.utf8properties.UTF8Properties)1 SHA1 (aQute.libg.cryptography.SHA1)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 OutputStream (java.io.OutputStream)1 DigestOutputStream (java.security.DigestOutputStream)1 MessageDigest (java.security.MessageDigest)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 JarOutputStream (java.util.jar.JarOutputStream)1