Search in sources :

Example 6 with DataFile

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

the class DataFileStoreDataManager method delete.

private void delete(final ArtifactStore store, final ChangeSummary summary) throws IndyDataException {
    logger.trace("Attempting to delete data file for store: {}", store.getKey());
    final DataFile f = manager.getDataFile(INDY_STORE, store.getPackageType(), store.getType().singularEndpointName(), store.getName() + ".json");
    try {
        logger.trace("Deleting file: {}", f);
        f.delete(summary);
    } catch (final IOException e) {
        throw new IndyDataException("Cannot delete store definition: {} in file: {}. Reason: {}", e, store.getKey(), f, e.getMessage());
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IndyDataException(org.commonjava.indy.data.IndyDataException) IOException(java.io.IOException)

Example 7 with DataFile

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

the class DataFileStoreDataManager method store.

private void store(final boolean skipIfExists, final ChangeSummary summary, final ArtifactStore... stores) throws IndyDataException {
    for (final ArtifactStore store : stores) {
        final DataFile f = manager.getDataFile(INDY_STORE, store.getPackageType(), store.getType().singularEndpointName(), store.getName() + ".json");
        if (skipIfExists && f.exists()) {
            continue;
        }
        final DataFile d = f.getParent();
        if (!d.mkdirs()) {
            throw new IndyDataException("Cannot create storage directory: {} for definition: {}", d, store);
        }
        try {
            final String json = serializer.writeValueAsString(store);
            f.writeString(json, "UTF-8", summary);
            logger.debug("Persisted {} to disk at: {}\n{}", store, f, json);
        } catch (final IOException e) {
            throw new IndyDataException("Cannot write definition: {} to: {}. Reason: {}", e, store, f, e.getMessage());
        }
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IOException(java.io.IOException)

Example 8 with DataFile

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

the class PromoteValidationsManager method storeRule.

public synchronized ValidationRuleMapping storeRule(final String name, final String spec, final ChangeSummary changelog) throws PromotionValidationException {
    final ValidationRuleMapping mapping = ruleParser.parseRule(spec, name);
    ruleMappings.put(mapping.getName(), mapping);
    final DataFile dataDir = ffManager.getDataFile(config.getBasedir(), RULES_DIR);
    if (!dataDir.exists()) {
        dataDir.mkdirs();
    }
    final DataFile scriptFile = dataDir.getChild(name);
    try {
        scriptFile.writeString(spec, changelog);
    } catch (final IOException e) {
        throw new PromotionValidationException("Failed to write rule: %s to: %s. Reason: %s", e, name, scriptFile, e.getMessage());
    }
    return mapping;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) ValidationRuleMapping(org.commonjava.indy.promote.validate.model.ValidationRuleMapping) IOException(java.io.IOException)

Example 9 with DataFile

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

the class PromoteValidationsManager method removeRuleNamed.

public synchronized ValidationRuleMapping removeRuleNamed(final String name, final ChangeSummary changelog) throws PromotionValidationException {
    ValidationRuleMapping mapping = ruleMappings.remove(name);
    if (mapping == null) {
        return null;
    }
    final DataFile dataDir = ffManager.getDataFile(config.getBasedir(), RULES_DIR);
    if (!dataDir.exists()) {
        // this would be a very strange error...implying addition of a rule without writing it to disk.
        return null;
    }
    final DataFile scriptFile = dataDir.getChild(name);
    if (scriptFile.exists()) {
        try {
            scriptFile.delete(changelog);
            return mapping;
        } catch (final IOException e) {
            throw new PromotionValidationException("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) ValidationRuleMapping(org.commonjava.indy.promote.validate.model.ValidationRuleMapping) IOException(java.io.IOException)

Example 10 with DataFile

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

the class RevisionsManagerTest method commitTwoDifferentFilesAndRetrieveChangelogForOneOfThem.

@Test
public void commitTwoDifferentFilesAndRetrieveChangelogForOneOfThem() throws Exception {
    lcEvents.fireStarted();
    final DataFile f1 = dfManager.getDataFile("test/foo.txt");
    f1.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", "test for first file."));
    final DataFile f2 = dfManager.getDataFile("test/bar.txt");
    f2.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", "test for second file."));
    f2.writeString("this is another test", "UTF-8", new ChangeSummary("test-user", "test (2) for second file."));
    final List<DataFileEvent> events = listener.waitForEvents(3);
    System.out.println("Got events:\n  " + join(events, "\n  "));
    final List<ChangeSummary> changeLog = revManager.getDataChangeLog(f2.getPath(), 0, -1);
    assertThat(changeLog, notNullValue());
    assertThat(changeLog.size(), equalTo(2));
}
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)

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