Search in sources :

Example 6 with Archetype

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();
}
Also used : FabricRequirements(io.fabric8.api.FabricRequirements) File(java.io.File) Test(org.junit.Test)

Example 7 with Archetype

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;
}
Also used : Archetype(io.fabric8.tooling.archetype.catalog.Archetype) ArrayList(java.util.ArrayList)

Example 8 with Archetype

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;
}
Also used : Archetype(io.fabric8.tooling.archetype.catalog.Archetype) ArrayList(java.util.ArrayList)

Example 9 with Archetype

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();
}
Also used : File(java.io.File) ArchetypeUtils(io.fabric8.tooling.archetype.ArchetypeUtils) Before(org.junit.Before)

Example 10 with Archetype

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);
    }
}
Also used : StreamProvider(io.fabric8.agent.download.StreamProvider) DownloadCallback(io.fabric8.agent.download.DownloadCallback) Downloader(io.fabric8.agent.download.Downloader) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) DownloadManager(io.fabric8.agent.download.DownloadManager) IOException(java.io.IOException) MavenResolver(io.fabric8.maven.MavenResolver) File(java.io.File)

Aggregations

Archetype (io.fabric8.tooling.archetype.catalog.Archetype)7 File (java.io.File)6 MavenResolver (io.fabric8.maven.MavenResolver)2 Archetypes (io.fabric8.tooling.archetype.catalog.Archetypes)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 DownloadCallback (io.fabric8.agent.download.DownloadCallback)1 DownloadManager (io.fabric8.agent.download.DownloadManager)1 Downloader (io.fabric8.agent.download.Downloader)1 StreamProvider (io.fabric8.agent.download.StreamProvider)1 FabricRequirements (io.fabric8.api.FabricRequirements)1 AetherResult (io.fabric8.insight.maven.aether.AetherResult)1 WebDriverFacade (io.fabric8.selenium.WebDriverFacade)1 ArchetypeUtils (io.fabric8.tooling.archetype.ArchetypeUtils)1 ArchetypeHelper (io.fabric8.tooling.archetype.generator.ArchetypeHelper)1 TablePrinter (io.fabric8.utils.TablePrinter)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1