Search in sources :

Example 1 with DataFile

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);
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException)

Example 2 with DataFile

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);
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) PostConstruct(javax.annotation.PostConstruct)

Example 3 with DataFile

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());
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IndyDataException(org.commonjava.indy.data.IndyDataException) IOException(java.io.IOException)

Example 4 with DataFile

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));
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Test(org.junit.Test)

Example 5 with DataFile

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));
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) 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