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());
}
}
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());
}
}
}
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;
}
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;
}
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));
}
Aggregations