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