use of io.fabric8.tooling.archetype.catalog.Archetype in project fabric8 by jboss-fuse.
the class ArchetypeTest method testCreateArchetype.
@Test
public void testCreateArchetype() throws Exception {
ArchetypeInfo archetype = archetypeIdToArchetypeInfoMap.get(archetypeId);
assertNotNull("No archetype found for id: " + archetypeId, archetype);
File mavenSettingsFile = getMavenSettingsFile();
assertFileExists(mavenSettingsFile);
// create a fabric
// generate and deploy archetypes
File workDir = new File(System.getProperty("basedir", "."), "target/generated-projects");
workDir.mkdirs();
String profileId = assertGenerateArchetype(archetype, workDir, mavenSettingsFile);
assertNotNull("Should have a profile ID for " + archetype, profileId);
FabricRequirements requirements = fabricController.getRequirements();
if (!addedBroker) {
addedBroker = true;
requirements.profile("mq-default").minimumInstances(1);
FabricAssertions.assertRequirementsSatisfied(fabricController, requirements);
}
// deploying each profile should have caused the requirements to be updated to add them all now
// so lets load the requirements and assert they are satisfied
requirements.profile(profileId).minimumInstances(1);
FabricAssertions.assertRequirementsSatisfied(fabricController, requirements);
System.out.println();
System.out.println("Managed to create a container for " + profileId + ". Now lets stop it");
System.out.println();
// now lets force the container to be stopped
requirements.profile(profileId).minimumInstances(0).maximumInstances(0);
FabricAssertions.assertRequirementsSatisfied(fabricController, requirements);
System.out.println();
System.out.println("Stopped a container for " + profileId + ". Now lets clear requirements");
System.out.println();
requirements.removeProfileRequirements(profileId);
FabricAssertions.assertRequirementsSatisfied(fabricController, requirements);
System.out.println();
System.out.println("Removed requirements for profile " + profileId);
System.out.println();
}
use of io.fabric8.tooling.archetype.catalog.Archetype in project fabric8 by jboss-fuse.
the class ArchetypeServiceImpl method listArchetypeGAVs.
@Override
public List<String[]> listArchetypeGAVs() {
assertValid();
List<String[]> answer = new ArrayList<String[]>(this.archetypes.size());
for (Archetype a : this.archetypes.values()) {
answer.add(new String[] { a.groupId, a.artifactId, a.version });
}
return answer;
}
use of io.fabric8.tooling.archetype.catalog.Archetype in project fabric8 by jboss-fuse.
the class ArchetypeServiceImpl method listArchetypes.
@Override
public List<Archetype> listArchetypes(String filter, boolean artifactIdOnly) {
List<Archetype> answer = new ArrayList<Archetype>();
if (Strings.isNullOrBlank(filter)) {
answer.addAll(listArchetypes());
return answer;
}
filter = filter.toLowerCase();
for (Archetype archetype : archetypes.values()) {
if (artifactIdOnly && archetype.artifactId.toLowerCase().contains(filter)) {
answer.add(archetype);
} else {
if (archetype.groupId.toLowerCase().contains(filter) || archetype.artifactId.toLowerCase().contains(filter) || archetype.version.toLowerCase().contains(filter)) {
answer.add(archetype);
}
}
}
return answer;
}
use of io.fabric8.tooling.archetype.catalog.Archetype in project fabric8 by jboss-fuse.
the class ArchetypeBuilderTest method init.
@Before
public void init() throws IOException {
if (basedir == null) {
basedir = ".";
}
catalogFile = new File(basedir, "target/test-archetypes/archetype-catalog.xml").getCanonicalFile();
builder = new ArchetypeBuilder(catalogFile);
builder.setIndentSize(4);
archetypeUtils = new ArchetypeUtils();
}
use of io.fabric8.tooling.archetype.catalog.Archetype in project fabric8 by jboss-fuse.
the class ArchetypeGenerateAction method fetchArchetype.
/**
* Fetches archetype from the configured repositories
* TODO: make this code available to hawt.io/JMX too
*/
private File fetchArchetype(Archetype archetype) throws IOException {
MavenResolver resolver = MavenResolvers.createMavenResolver(new Hashtable<String, String>(), "org.ops4j.pax.url.mvn");
DownloadManager dm = DownloadManagers.createDownloadManager(resolver, Executors.newSingleThreadScheduledExecutor());
final AtomicReference<File> file = new AtomicReference<>();
String url = String.format("mvn:%s/%s/%s", archetype.groupId, archetype.artifactId, archetype.version);
Downloader downloader = dm.createDownloader();
downloader.download(url, new DownloadCallback() {
@Override
public void downloaded(StreamProvider provider) throws Exception {
file.set(provider.getFile());
}
});
// wait for download
try {
boolean init = false;
for (int i = 0; i < 2 * 60 && file.get() == null; i++) {
// dont do anything in the first 3 seconds as we likely can download it faster
if (i > 3) {
if (!init) {
System.out.print("Downloading archetype in progress: ");
init = true;
}
System.out.print(".");
}
// only sleep 0.5 sec so we can react faster
Thread.sleep(500);
}
} catch (InterruptedException e) {
System.err.println("\nFailed to download " + archetype);
throw new IOException(e.getMessage(), e);
}
try {
downloader.await();
return file.get();
} catch (Exception e) {
System.err.println("\nFailed to download archetype within 60 seconds: " + archetype);
throw new IOException("Failed to download archetype within 60 seconds: " + archetype);
}
}
Aggregations