use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method unzipFabric8Distro.
/**
* Unzips <code>bin</code> and <code>etc</code> everything we need from org.apache.karaf.admin.core.
* @param rootDir
* @param artifact
* @param version
* @param fork
* @return branch name where the distro should be tracked, or <code>null</code> if it's already tracked
* @throws IOException
*/
private String unzipFabric8Distro(String rootDir, File artifact, String version, Git fork) throws IOException, GitAPIException {
ZipFile zf = new ZipFile(artifact);
try {
// first pass - what's this distro?
boolean officialFabric8 = true;
for (Enumeration<ZipArchiveEntry> e = zf.getEntries(); e.hasMoreElements(); ) {
ZipArchiveEntry entry = e.nextElement();
String name = entry.getName();
if (name.startsWith(rootDir + "/")) {
name = name.substring(rootDir.length() + 1);
}
if ("etc/startup.properties".equals(name)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copyLarge(zf.getInputStream(entry), baos);
Properties props = new Properties();
props.load(new ByteArrayInputStream(baos.toByteArray()));
for (String p : props.stringPropertyNames()) {
if (p.startsWith("org/jboss/fuse/shared-commands/")) {
// we have Fuse!
officialFabric8 = false;
break;
}
}
}
}
// checkout correct branch
if (officialFabric8) {
if (gitPatchRepository.containsTag(fork, String.format("baseline-ssh-fabric8-%s", version))) {
return null;
}
gitPatchRepository.checkout(fork).setName(gitPatchRepository.getFabric8SSHContainerPatchBranchName()).call();
} else {
if (gitPatchRepository.containsTag(fork, String.format("baseline-ssh-fuse-%s", version))) {
return null;
}
gitPatchRepository.checkout(fork).setName(gitPatchRepository.getFuseSSHContainerPatchBranchName()).call();
}
for (String managedDirectory : MANAGED_DIRECTORIES) {
FileUtils.deleteDirectory(new File(fork.getRepository().getWorkTree(), managedDirectory));
}
// second pass - unzip what we need
for (Enumeration<ZipArchiveEntry> e = zf.getEntries(); e.hasMoreElements(); ) {
ZipArchiveEntry entry = e.nextElement();
String name = entry.getName();
if (name.startsWith(rootDir + "/")) {
name = name.substring(rootDir.length() + 1);
}
if (!(name.startsWith("bin") || name.startsWith("etc") || name.startsWith("fabric") || name.startsWith("lib") || name.startsWith("licenses") || name.startsWith("metatype"))) {
continue;
}
if (!entry.isDirectory() && !entry.isUnixSymlink()) {
File file = new File(fork.getRepository().getWorkTree(), name);
file.getParentFile().mkdirs();
FileOutputStream output = new EOLFixingFileOutputStream(fork.getRepository().getWorkTree(), file);
IOUtils.copyLarge(zf.getInputStream(entry), output);
IOUtils.closeQuietly(output);
if (Files.getFileAttributeView(file.toPath(), PosixFileAttributeView.class) != null) {
if (name.startsWith("bin/") && !name.endsWith(".bat")) {
Files.setPosixFilePermissions(file.toPath(), getPermissionsFromUnixMode(file, 0775));
}
}
}
}
return officialFabric8 ? gitPatchRepository.getFabric8SSHContainerPatchBranchName() : gitPatchRepository.getFuseSSHContainerPatchBranchName();
} finally {
if (zf != null) {
zf.close();
}
}
}
use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.
the class ServiceImplTest method bundle.
/**
* Helper method for {@link #bundleUpdatesInPatch()} test
* @param location
* @return
*/
private Bundle bundle(String location) {
BundleStartLevel bsl = createMock(BundleStartLevel.class);
expect(bsl.getStartLevel()).andReturn(42);
replay(bsl);
Bundle b = createMock(Bundle.class);
Artifact a = Utils.mvnurlToArtifact(location, false);
expect(b.getSymbolicName()).andReturn(a.getArtifactId()).anyTimes();
expect(b.getVersion()).andReturn(new Version(a.getVersion())).anyTimes();
expect(b.getLocation()).andReturn(location).anyTimes();
expect(b.adapt(BundleStartLevel.class)).andReturn(bsl);
expect(b.getState()).andReturn(Bundle.ACTIVE);
replay(b);
return b;
}
use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.
the class ArchetypeInfoAction method doExecute.
@Override
protected Object doExecute() throws Exception {
// try artifact first
Archetype archetype = archetypeService.getArchetypeByArtifact(archetypeGAV);
if (archetype == null) {
// then by coordinate
archetypeService.getArchetype(archetypeGAV);
}
if (archetype != null) {
System.out.println(String.format(FORMAT, "GroupId:", archetype.groupId));
System.out.println(String.format(FORMAT, "ArtifactId:", archetype.artifactId));
System.out.println(String.format(FORMAT, "Version:", archetype.version));
System.out.println(String.format(FORMAT, "Coordinate:", toMavenCoordinate(archetype)));
System.out.println(String.format(FORMAT, "Description:", emptyIfNull(archetype.description)));
System.out.println(String.format(FORMAT, "Repository:", emptyIfNull(archetype.repository)));
} else {
System.err.println("No archetype found for: " + archetypeGAV);
}
return null;
}
use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.
the class AgentUtils method downloadRepositories.
public static Callable<Map<String, Repository>> downloadRepositories(DownloadManager manager, Set<String> uris) throws MultiException, InterruptedException, MalformedURLException {
final Map<String, Repository> repositories = new HashMap<>();
final Downloader downloader = manager.createDownloader();
final File targetLocation = getDefaultKarafRepository();
for (String uri : uris) {
downloader.download(uri, new DownloadCallback() {
@Override
public void downloaded(StreamProvider provider) throws Exception {
String uri = provider.getUrl();
Repository repository = new Repository(URI.create(uri));
repository.load(new FileInputStream(provider.getFile()), true);
synchronized (repositories) {
repositories.put(uri, repository);
}
for (URI repo : repository.getRepositories()) {
downloader.download(repo.toASCIIString(), this);
}
Artifact artifact = Utils.mvnurlToArtifact(uri, true);
if (artifact == null || artifact.getVersion() == null || !artifact.getVersion().endsWith("-SNAPSHOT")) {
// we need a feature repository to be available in ${karaf.home}/${karaf.default.repository}
// it makes patching much easier
// ENTESB-6931: don't store SNAPSHOT feature repositories in ${karaf.home}/${karaf.default.repository}
storeInDefaultKarafRepository(targetLocation, provider.getFile(), uri);
}
}
});
}
return new Callable<Map<String, Repository>>() {
@Override
public Map<String, Repository> call() throws Exception {
downloader.await();
return repositories;
}
};
}
use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.
the class AgentUtils method getProfileArtifacts.
/**
* Returns the location and parser map (i.e. the location and the parsed maven coordinates and artifact locations) of each bundle and feature
*/
public static Map<String, Parser> getProfileArtifacts(FabricService fabricService, Profile profile, Iterable<String> bundles, Iterable<Feature> features, Callback<String> nonMavenLocationCallback) {
Set<String> locations = new HashSet<>();
for (Feature feature : features) {
List<BundleInfo> bundleList = feature.getBundles();
if (bundleList == null) {
LOGGER.warn("No bundles for feature " + feature);
} else {
for (BundleInfo bundle : bundleList) {
locations.add(bundle.getLocation());
}
}
}
for (String bundle : bundles) {
locations.add(bundle);
}
Map<String, Parser> artifacts = new HashMap<>();
for (String location : locations) {
try {
if (location.contains("$")) {
ProfileService profileService = fabricService.adapt(ProfileService.class);
Profile overlay = profileService.getOverlayProfile(profile);
location = VersionPropertyPointerResolver.replaceVersions(fabricService, overlay.getConfigurations(), location);
}
if (location.startsWith("mvn:") || location.contains(":mvn:")) {
Parser parser = Parser.parsePathWithSchemePrefix(location);
artifacts.put(location, parser);
} else {
if (nonMavenLocationCallback != null) {
nonMavenLocationCallback.call(location);
}
}
} catch (MalformedURLException e) {
LOGGER.error("Failed to parse bundle URL: " + location + ". " + e, e);
}
}
return artifacts;
}
Aggregations