Search in sources :

Example 81 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class RepoListCommand method doExecute.

protected void doExecute(FeaturesService featuresService) throws Exception {
    if (reload) {
        reloadAllRepos(featuresService);
    }
    ShellTable table = new ShellTable();
    table.column("Repository");
    table.column("URL");
    if (showBlacklisted) {
        table.column("Blacklisted");
    }
    table.emptyTableText("No repositories available");
    Repository[] repos = featuresService.listRepositories();
    for (Repository repo : repos) {
        if (repo != null) {
            if (showBlacklisted || !repo.isBlacklisted()) {
                Row row = table.addRow();
                row.addContent(repo.getName(), repo.getURI().toString());
                if (showBlacklisted) {
                    row.addContent(repo.isBlacklisted() ? "yes" : "no");
                }
            }
        }
    }
    table.print(System.out, !noFormat);
}
Also used : Repository(org.apache.karaf.features.Repository) ShellTable(org.apache.karaf.shell.support.table.ShellTable) Row(org.apache.karaf.shell.support.table.Row)

Example 82 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class RepoRefreshCommand method doExecute.

@Override
protected void doExecute(FeaturesService featuresService) throws Exception {
    Set<URI> uris = new LinkedHashSet<>();
    if (nameOrUrl != null) {
        uris = selectRepositories(nameOrUrl, version);
        if (uris.isEmpty()) {
            System.err.println("No matching repository for " + nameOrUrl + (version != null ? " / " + version : ""));
            return;
        }
    } else {
        Repository[] repos = featuresService.listRepositories();
        for (Repository repo : repos) {
            uris.add(repo.getURI());
        }
    }
    String uriString = uris.stream().map(URI::toString).collect(Collectors.joining(", "));
    try {
        System.out.println("Refreshing feature url: " + uriString);
        featuresService.refreshRepositories(uris);
    } catch (Exception e) {
        System.err.println("Error refreshing " + uriString + ": " + e.getMessage());
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Repository(org.apache.karaf.features.Repository) URI(java.net.URI)

Example 83 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class FeaturesPlugin method writeJSON.

private void writeJSON(final PrintWriter pw) throws IOException {
    final List<Repository> repositories = this.getRepositories();
    final List<ExtendedFeature> features = this.getFeatures(repositories);
    final String statusLine = this.getStatusLine(features);
    final JSONWriter jw = new JSONWriter(pw);
    jw.object();
    jw.key("status");
    jw.value(statusLine);
    jw.key("repositories");
    jw.array();
    for (Repository r : repositories) {
        jw.object();
        jw.key("name");
        String name = "";
        if (r.getName() != null)
            name = r.getName();
        jw.value(name);
        jw.key("url");
        String uri = r.getURI().toString();
        jw.value(uri);
        jw.key("actions");
        jw.array();
        boolean enable = true;
        if (uri.startsWith("bundle")) {
            enable = false;
        }
        action(jw, enable, "refreshRepository", "Refresh", "refresh");
        action(jw, enable, "removeRepository", "Remove", "delete");
        jw.endArray();
        jw.endObject();
    }
    jw.endArray();
    jw.key("features");
    jw.array();
    for (ExtendedFeature f : features) {
        featureInfo(jw, f);
    }
    jw.endArray();
    jw.endObject();
}
Also used : JSONWriter(org.apache.felix.utils.json.JSONWriter) Repository(org.apache.karaf.features.Repository)

Example 84 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class JmxRepositoryTest method testJmxRepositoryCompositeData.

@Test
public void testJmxRepositoryCompositeData() throws Exception {
    Features features = new Features();
    features.setName("test-1.0.0");
    features.getRepository().add("mvn:org.test/test-dependency/1.0.0/xml/features");
    features.getFeature().add(new Feature("test-feature", "1.0.0"));
    URI uri = new URI("mvn:org.test/test/1.0.0/xml/features");
    Repository repository = new RepositoryImpl(uri, features, true);
    JmxRepository jmxRepository = new JmxRepository(repository);
    CompositeData compositeData = jmxRepository.asCompositeData();
    assertEquals("test-1.0.0", compositeData.get(REPOSITORY_NAME));
    assertEquals(uri.toString(), compositeData.get(REPOSITORY_URI));
    assertTrue((Boolean) compositeData.get(REPOSITORY_BLACKLISTED));
    String[] repositoryUris = (String[]) compositeData.get(REPOSITORY_REPOSITORIES);
    assertEquals(1, repositoryUris.length);
    assertEquals("mvn:org.test/test-dependency/1.0.0/xml/features", repositoryUris[0]);
    TabularData repositoryFeatures = (TabularData) compositeData.get(REPOSITORY_FEATURES);
    assertEquals(1, repositoryFeatures.size());
    assertNotNull(repositoryFeatures.get(new Object[] { "test-feature", "1.0.0" }));
}
Also used : Repository(org.apache.karaf.features.Repository) RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) CompositeData(javax.management.openmbean.CompositeData) Features(org.apache.karaf.features.internal.model.Features) Feature(org.apache.karaf.features.internal.model.Feature) REPOSITORY_URI(org.apache.karaf.features.management.FeaturesServiceMBean.REPOSITORY_URI) URI(java.net.URI) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Example 85 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class FeaturesDumpProvider method writeDump.

/**
 * {@inheritDoc}
 */
protected void writeDump(OutputStreamWriter outputStreamWriter) throws Exception {
    // creates header
    outputStreamWriter.write("Repositories:\n");
    // list repositories
    for (Repository repo : features.listRepositories()) {
        outputStreamWriter.write(repo.getURI() + " (" + repo.getName() + ")\n");
    }
    // list features
    outputStreamWriter.write("\nfeatures:\n");
    for (Feature feature : features.listFeatures()) {
        outputStreamWriter.write(feature.getName() + " " + feature.getVersion());
        outputStreamWriter.write(" installed: " + features.isInstalled(feature));
        outputStreamWriter.write("\nBundles:\n");
        for (BundleInfo bundle : feature.getBundles()) {
            outputStreamWriter.write("\t" + bundle.getLocation());
            if (bundle.getStartLevel() != 0) {
                outputStreamWriter.write(" start level " + bundle.getStartLevel());
            }
            outputStreamWriter.write("\n\n");
        }
    }
    // flush & close stream
    outputStreamWriter.close();
}
Also used : Repository(org.apache.karaf.features.Repository) BundleInfo(org.apache.karaf.features.BundleInfo) Feature(org.apache.karaf.features.Feature)

Aggregations

Repository (org.apache.karaf.features.Repository)85 Test (org.junit.Test)53 HashSet (java.util.HashSet)51 FeaturesService (org.apache.karaf.features.FeaturesService)44 Feature (org.apache.karaf.features.Feature)38 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)37 URI (java.net.URI)21 Application (org.codice.ddf.admin.application.service.Application)20 ArrayList (java.util.ArrayList)8 LinkedHashSet (java.util.LinkedHashSet)8 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)8 Logger (org.slf4j.Logger)7 Appender (ch.qos.logback.core.Appender)6 HashMap (java.util.HashMap)6 ArgumentMatcher (org.mockito.ArgumentMatcher)6 Mockito.anyString (org.mockito.Mockito.anyString)6 IOException (java.io.IOException)5 EnumSet (java.util.EnumSet)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)4