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);
}
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);
}
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);
}
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);
}
}
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();
}
Aggregations