use of org.commonjava.indy.subsys.datafile.DataFile in project indy by Commonjava.
the class FoloLifecycleParticipant method start.
@Override
public void start() throws IndyLifecycleException {
try {
final DataFile dataFile = dataFileManager.getDataFile(".gitignore");
final List<String> lines = dataFile.exists() ? dataFile.readLines() : new ArrayList<String>();
if (!lines.contains(FOLO_DIRECTORY_IGNORE)) {
lines.add(FOLO_DIRECTORY_IGNORE);
dataFile.writeLines(lines, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding artimon to ignored list."));
}
} catch (final IOException e) {
throw new IndyLifecycleException("Failed while attempting to access .gitignore for data directory (trying to add artimon dir to ignores list).", e);
}
}
use of org.commonjava.indy.subsys.datafile.DataFile in project indy by Commonjava.
the class DataFileStoreDataManager method readDefinitions.
@PostConstruct
public void readDefinitions() {
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Reading definitions from disk, culling invalid definition files.");
try {
DataFile[] packageDirs = manager.getDataFile(INDY_STORE).listFiles((f) -> true);
for (DataFile pkgDir : packageDirs) {
for (StoreType type : StoreType.values()) {
DataFile[] files = pkgDir.getChild(type.singularEndpointName()).listFiles(f -> true);
if (files != null) {
for (final DataFile f : files) {
try {
final String json = f.readString();
final ArtifactStore store = serializer.readValue(json, type.getStoreClass());
if (store == null) {
f.delete(summary);
} else {
storeArtifactStore(store, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, LOAD_FROM_DISK));
}
} catch (final IOException e) {
logger.error(String.format("Failed to load %s store: %s. Reason: %s", type, f, e.getMessage()), e);
}
}
}
}
}
started = true;
} catch (final IndyDataException e) {
throw new IllegalStateException("Failed to start store data manager: " + e.getMessage(), e);
}
}
use of org.commonjava.indy.subsys.datafile.DataFile in project indy by Commonjava.
the class DataFileStoreDataManager method clear.
@Override
public void clear(final ChangeSummary summary) throws IndyDataException {
super.clear(summary);
final DataFile basedir = manager.getDataFile(INDY_STORE);
try {
basedir.delete(summary);
} catch (final IOException e) {
throw new IndyDataException("Failed to delete Indy storage files: {}", e, e.getMessage());
}
}
use of org.commonjava.indy.subsys.datafile.DataFile in project indy by Commonjava.
the class LegacyDataMigrationActionTest method migrateHostedRepoJSONWithMissingTypeAttribute.
@Test
public void migrateHostedRepoJSONWithMissingTypeAttribute() throws Exception {
final DataFile dir = dfm.getDataFile(INDY_STORE, hosted.singularEndpointName());
dir.mkdirs();
final DataFile file = dir.getChild("test.json");
file.writeString("{\"name\": \"test\", \"packageType\": \"maven\", \"key\": \"maven:hosted:test\"}", new ChangeSummary(ChangeSummary.SYSTEM_USER, "test repo creation"));
final boolean result = action.migrate();
assertThat(result, equalTo(true));
DataFile out = dfm.getDataFile(INDY_STORE, MAVEN_PKG_KEY, hosted.singularEndpointName(), "test.json");
final String json = out.readString();
assertThat(json.contains("\"type\" : \"hosted\""), equalTo(true));
assertThat(json.contains("\"packageType\" : \"maven\""), equalTo(true));
assertThat(json.contains("\"key\" : \"maven:hosted:test\""), equalTo(true));
}
use of org.commonjava.indy.subsys.datafile.DataFile in project indy by Commonjava.
the class LegacyDataMigrationActionTest method migrateRemoteRepoJSONWithMissingPackageTypeInKey.
@Test
public void migrateRemoteRepoJSONWithMissingPackageTypeInKey() throws Exception {
final DataFile dir = dfm.getDataFile(INDY_STORE, remote.singularEndpointName());
dir.mkdirs();
final DataFile file = dir.getChild("test.json");
file.writeString("{\"name\": \"test\", \"type\": \"remote\", \"key\": \"remote:test\", \"url\": \"http://www.google.com\"}", new ChangeSummary(ChangeSummary.SYSTEM_USER, "test repo creation"));
final boolean result = action.migrate();
assertThat(result, equalTo(true));
DataFile out = dfm.getDataFile(INDY_STORE, MAVEN_PKG_KEY, remote.singularEndpointName(), "test.json");
final String json = out.readString();
assertThat(json.contains("\"type\" : \"remote\""), equalTo(true));
assertThat(json.contains("\"packageType\" : \"maven\""), equalTo(true));
assertThat(json.contains("\"key\" : \"maven:remote:test\""), equalTo(true));
}
Aggregations