Search in sources :

Example 51 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class SetBackSettingsManager method updateSettings.

private DataFile updateSettings(final ArtifactStore store, final List<ArtifactStore> allStores, final List<RemoteRepository> remotes) throws SetBackDataException {
    if (!config.isEnabled()) {
        throw new SetBackDataException("SetBack is disabled!");
    }
    final StoreKey key = store.getKey();
    final DataFile settingsXml = getSettingsXml(key);
    final Map<String, Object> params = new HashMap<String, Object>();
    params.put("key", key);
    params.put("store", store);
    params.put("remotes", remotes);
    params.put("allStores", allStores);
    String rendered;
    try {
        rendered = templates.render(ApplicationContent.application_xml, TEMPLATE, params);
    } catch (final IndyGroovyException e) {
        throw new SetBackDataException("Failed to render template: %s for store: %s. Reason: %s", e, TEMPLATE, key, e.getMessage());
    }
    try {
        settingsXml.getParent().mkdirs();
        settingsXml.writeString(rendered, "UTF-8", new ChangeSummary(ChangeSummary.SYSTEM_USER, "SETBACK: Updating generated SetBack settings.xml for: " + key));
    } catch (final IOException e) {
        throw new SetBackDataException("Failed to write SetBack settings.xml for: %s\n  to: %s\n  Reason: %s", e, key, settingsXml, e.getMessage());
    }
    return settingsXml;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) HashMap(java.util.HashMap) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyGroovyException(org.commonjava.indy.subsys.template.IndyGroovyException)

Example 52 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class SetBackSettingsManagerTest method settingsForGroup_SingleMemberRemote.

@Test
public void settingsForGroup_SingleMemberRemote() throws Exception {
    final RemoteRepository remote = new RemoteRepository(MAVEN_PKG_KEY, "test", "http://foo.bar/");
    remote.setDescription("Test Repository");
    store(remote);
    final StoreKey remoteKey = remote.getKey();
    final Group group = new Group(MAVEN_PKG_KEY, "test-group", remoteKey);
    store(group);
    assertThat(readSettings(group.getKey(), false), equalTo(null));
    final List<String> lines = generateSettings(group.getKey());
    assertThat("No repository with id: " + remote.getName() + " found in settings.xml for remote!", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 53 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class SetBackSettingsManagerTest method settingsForSingleRemoteRepository_NoGroups.

@Test
public void settingsForSingleRemoteRepository_NoGroups() throws Exception {
    final RemoteRepository remote = new RemoteRepository(MAVEN_PKG_KEY, "test", "http://foo.bar/");
    remote.setDescription("Test Repository");
    store(remote);
    final StoreKey key = remote.getKey();
    final List<String> lines = generateSettings(key);
    assertThat("No repository with id: " + remote.getName() + " found in settings.xml", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 54 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class SetBackSettingsManagerTest method settingsForSingleRemoteRepository_GenerateDeleteAndProveNonExistent.

@Test
public void settingsForSingleRemoteRepository_GenerateDeleteAndProveNonExistent() throws Exception {
    final RemoteRepository remote = new RemoteRepository(MAVEN_PKG_KEY, "test", "http://foo.bar/");
    remote.setDescription("Test Repository");
    store(remote);
    final StoreKey key = remote.getKey();
    final List<String> lines = generateSettings(key);
    assertThat("No repository with id: " + remote.getName() + " found in settings.xml", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
    final ArtifactStore store = storeManager.getArtifactStore(key);
    manager.deleteStoreSettings(store);
    assertThat("Settings.xml for: " + key + " should have been deleted!", manager.getSetBackSettings(key), nullValue());
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 55 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class SetBackSettingsManagerTest method settingsForSingleRemoteRepository_GenerateSpawnsGroupGeneration.

@Test
public void settingsForSingleRemoteRepository_GenerateSpawnsGroupGeneration() throws Exception {
    final RemoteRepository remote = new RemoteRepository(MAVEN_PKG_KEY, "test", "http://foo.bar/");
    remote.setDescription("Test Repository");
    store(remote);
    final StoreKey key = remote.getKey();
    final Group group = new Group(MAVEN_PKG_KEY, "test-group", key);
    store(group);
    assertThat(readSettings(group.getKey(), false), equalTo(null));
    List<String> lines = generateSettings(key);
    assertThat("No repository with id: " + remote.getName() + " found in settings.xml for remote!", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
    lines = readSettings(group.getKey(), true);
    assertThat("No repository with id: " + remote.getName() + " found in settings.xml for group!", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Aggregations

StoreKey (org.commonjava.indy.model.core.StoreKey)186 Test (org.junit.Test)92 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)40 StoreType (org.commonjava.indy.model.core.StoreType)39 InputStream (java.io.InputStream)33 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)32 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)31 IndyDataException (org.commonjava.indy.data.IndyDataException)30 Group (org.commonjava.indy.model.core.Group)29 Transfer (org.commonjava.maven.galley.model.Transfer)27 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)24 Response (javax.ws.rs.core.Response)23 IOException (java.io.IOException)22 Logger (org.slf4j.Logger)21 ApiOperation (io.swagger.annotations.ApiOperation)20 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)20 ArrayList (java.util.ArrayList)19 Path (javax.ws.rs.Path)19 ApiResponse (io.swagger.annotations.ApiResponse)18 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)18