Search in sources :

Example 1 with MavenCoordinates

use of io.fabric8.api.gravia.MavenCoordinates in project fabric8 by jboss-fuse.

the class AbstractManagedContainer method create.

@Override
public final synchronized void create(T configuration) throws LifecycleException {
    if (state != null)
        throw new IllegalStateException("Cannot create container in state: " + state);
    this.configuration = configuration;
    // [TODO] [FABRIC-929] No connector available to access repository jboss-public-repository-group
    // Remove this hack. It shouldbe possible to use the shrinkwrap maven resolver
    boolean useShrinkwrap = System.getProperty("shrinkwrap.resolver") != null;
    for (MavenCoordinates artefact : configuration.getMavenCoordinates()) {
        File zipfile = useShrinkwrap ? shrinkwrapResolve(artefact) : localResolve(artefact);
        GenericArchive archive = ShrinkWrap.createFromZipFile(GenericArchive.class, zipfile);
        ExplodedExporter exporter = archive.as(ExplodedExporter.class);
        File targetdir = configuration.getTargetDirectory();
        if (!targetdir.isDirectory() && !targetdir.mkdirs())
            throw new IllegalStateException("Cannot create target dir: " + targetdir);
        if (containerHome == null) {
            exporter.exportExploded(targetdir, "");
            File[] childDirs = targetdir.listFiles();
            if (childDirs.length != 1)
                throw new IllegalStateException("Expected one child directory, but was: " + Arrays.asList(childDirs));
            containerHome = childDirs[0];
        } else {
            exporter.exportExploded(containerHome, "");
        }
    }
    state = State.CREATED;
    try {
        doConfigure(configuration);
    } catch (Exception ex) {
        throw new LifecycleException("Cannot configure container", ex);
    }
}
Also used : MavenCoordinates(io.fabric8.api.gravia.MavenCoordinates) LifecycleException(io.fabric8.runtime.container.LifecycleException) GenericArchive(org.jboss.shrinkwrap.api.GenericArchive) ExplodedExporter(org.jboss.shrinkwrap.api.exporter.ExplodedExporter) File(java.io.File) LifecycleException(io.fabric8.runtime.container.LifecycleException) IOException(java.io.IOException)

Aggregations

MavenCoordinates (io.fabric8.api.gravia.MavenCoordinates)1 LifecycleException (io.fabric8.runtime.container.LifecycleException)1 File (java.io.File)1 IOException (java.io.IOException)1 GenericArchive (org.jboss.shrinkwrap.api.GenericArchive)1 ExplodedExporter (org.jboss.shrinkwrap.api.exporter.ExplodedExporter)1