Search in sources :

Example 11 with DataFile

use of org.commonjava.indy.subsys.datafile.DataFile in project indy by Commonjava.

the class RevisionsManagerTest method commitOneFileTwice_ChangedBeforeServerStart_FirstChangelogAppearsOnServerStart.

@Test
public void commitOneFileTwice_ChangedBeforeServerStart_FirstChangelogAppearsOnServerStart() throws Exception {
    revManager.setup();
    final DataFile f1 = dfManager.getDataFile("test/foo.txt");
    f1.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", "test for first write of file."));
    List<DataFileEvent> events = listener.waitForEvents(1);
    System.out.println("Got events:\n  " + join(events, "\n  "));
    f1.writeString("this is another test", "UTF-8", new ChangeSummary("test-user", "test for second write of file."));
    events = listener.waitForEvents(1);
    System.out.println("Got events:\n  " + join(events, "\n  "));
    List<ChangeSummary> changeLog = revManager.getDataChangeLog(f1.getPath(), 0, -1);
    assertThat(changeLog, notNullValue());
    assertThat(changeLog.size(), equalTo(0));
    lcEvents.fireStarted();
    changeLog = revManager.getDataChangeLog(f1.getPath(), 0, -1);
    assertThat(changeLog, notNullValue());
    assertThat(changeLog.size(), equalTo(1));
    assertThat(changeLog.get(0).getSummary().contains(RevisionsManager.CATCHUP_CHANGELOG), equalTo(true));
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) DataFileEvent(org.commonjava.indy.subsys.datafile.change.DataFileEvent) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Test(org.junit.Test)

Example 12 with DataFile

use of org.commonjava.indy.subsys.datafile.DataFile in project indy by Commonjava.

the class SetBackSettingsManager method deleteStoreSettings.

public boolean deleteStoreSettings(final ArtifactStore store) throws SetBackDataException {
    if (!config.isEnabled()) {
        throw new SetBackDataException("SetBack is disabled!");
    }
    final StoreKey key = store.getKey();
    if (StoreType.hosted == key.getType()) {
        return false;
    }
    final DataFile settingsXml = getSettingsXml(key);
    if (settingsXml.exists()) {
        try {
            settingsXml.delete(new ChangeSummary(ChangeSummary.SYSTEM_USER, "SETBACK: Deleting generated SetBack settings.xml for: " + store));
        } catch (final IOException e) {
            throw new SetBackDataException("Failed to delete SetBack settings.xml for: %s.\n  at: %s\n  Reason: %s", e, store, settingsXml, e.getMessage());
        }
        return true;
    }
    return false;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 13 with DataFile

use of org.commonjava.indy.subsys.datafile.DataFile 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 14 with DataFile

use of org.commonjava.indy.subsys.datafile.DataFile in project indy by Commonjava.

the class SetBackSettingsManagerTest method readSettings.

private List<String> readSettings(final StoreKey key, final boolean expectExistence) throws Exception {
    final DataFile settings = manager.getSetBackSettings(key);
    if (expectExistence) {
        assertThat("Retrieved settings.xml for: " + key + " does not exist!", settings.exists(), equalTo(true));
        final List<String> rawLines = settings.readLines();
        System.out.println(join(rawLines, "\n"));
        final List<String> lines = new ArrayList<String>();
        for (final String line : rawLines) {
            lines.add(line.trim());
        }
        return lines;
    } else {
        assertThat("Retrieved settings.xml for: " + key + " already exists!", settings, nullValue());
        return null;
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) ArrayList(java.util.ArrayList)

Example 15 with DataFile

use of org.commonjava.indy.subsys.datafile.DataFile in project indy by Commonjava.

the class AutoProxCatalogManager method removeRuleNamed.

public synchronized RuleMapping removeRuleNamed(final String name, final ChangeSummary changelog) throws AutoProxRuleException {
    if (!checkEnabled()) {
        throw new AutoProxRuleException("AutoProx is disabled");
    }
    RuleMapping mapping = null;
    for (final Iterator<RuleMapping> mappingIt = ruleMappings.iterator(); mappingIt.hasNext(); ) {
        final RuleMapping m = mappingIt.next();
        if (m.getScriptName().equals(name)) {
            logger.info("Found rule {} in rule Mappings, delete it now.", name);
            mappingIt.remove();
            mapping = m;
            break;
        }
    }
    if (mapping == null) {
        return null;
    }
    final DataFile dataDir = ffManager.getDataFile(apConfig.getBasedir());
    if (!dataDir.exists()) {
        dataDir.mkdirs();
    }
    final DataFile scriptFile = dataDir.getChild(name + ".groovy");
    if (scriptFile.exists()) {
        try {
            logger.info("Found rule file {} in flat file storage, begin to delete", scriptFile);
            scriptFile.delete(changelog);
            return mapping;
        } catch (final IOException e) {
            throw new AutoProxRuleException("Failed to delete rule: %s to: %s. Reason: %s", e, name, scriptFile, e.getMessage());
        }
    }
    return null;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IOException(java.io.IOException)

Aggregations

DataFile (org.commonjava.indy.subsys.datafile.DataFile)36 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)21 IOException (java.io.IOException)16 Test (org.junit.Test)14 IndyDataException (org.commonjava.indy.data.IndyDataException)5 StoreKey (org.commonjava.indy.model.core.StoreKey)5 File (java.io.File)3 HashMap (java.util.HashMap)3 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)3 StoreType (org.commonjava.indy.model.core.StoreType)3 ValidationRuleMapping (org.commonjava.indy.promote.validate.model.ValidationRuleMapping)3 DataFileEvent (org.commonjava.indy.subsys.datafile.change.DataFileEvent)3 Logger (org.slf4j.Logger)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)2 IndyLifecycleException (org.commonjava.indy.action.IndyLifecycleException)2 ValidationRuleSet (org.commonjava.indy.promote.model.ValidationRuleSet)2 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)2 Template (groovy.text.Template)1