Search in sources :

Example 21 with DataFile

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

the class SetBackSettingsManagerTest method generateSettings.

private List<String> generateSettings(final StoreKey key) throws Exception {
    final ArtifactStore store = storeManager.getArtifactStore(key);
    final DataFile settings = manager.generateStoreSettings(store);
    assertThat("settings.xml returned from generateStoreSettings(..) for: " + key + " does not exist!", settings.exists(), equalTo(true));
    final List<String> lines = readSettings(key, true);
    final String localRepoLine = String.format("<localRepository>%s</localRepository>", normalize(USER_HOME, ".m2/repository-" + key.getType().singularEndpointName() + "-" + key.getName()));
    assertThat("Local repository for: " + key + " not configured", lines.contains(localRepoLine), equalTo(true));
    return lines;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore)

Example 22 with DataFile

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

the class SetBackSettingsResource method get.

@ApiOperation("Return settings.xml that approximates the behavior of the specified Indy group/repository (CAUTION: Indy-hosted content will be unavailable!)")
@ApiResponses({ @ApiResponse(code = 400, message = "Requested repository is hosted on Indy and cannot be simulated via settings.xml"), @ApiResponse(code = 404, message = "No such repository or group, or the settings.xml has not been generated."), @ApiResponse(code = 200, message = "Maven settings.xml content") })
@Path("/{type: (remote|group)}/{name}")
@GET
@Produces(ApplicationContent.application_xml)
public Response get(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String t, @PathParam("name") final String n) {
    final StoreType type = StoreType.get(t);
    if (StoreType.hosted == type) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Response response;
    final StoreKey key = new StoreKey(type, n);
    DataFile settingsXml = null;
    try {
        settingsXml = controller.getSetBackSettings(key);
    } catch (final IndyWorkflowException e) {
        response = ResponseUtils.formatResponse(e);
    }
    if (settingsXml != null && settingsXml.exists()) {
        response = Response.ok(settingsXml).type(ApplicationContent.application_xml).build();
    } else {
        response = Response.status(Status.NOT_FOUND).build();
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) DataFile(org.commonjava.indy.subsys.datafile.DataFile) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 23 with DataFile

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

the class RevisionsManagerTest method commitTwoDifferentFilesAndRetrieveChangelogForOneOfThem_LimitToOldestEvent.

@Test
public void commitTwoDifferentFilesAndRetrieveChangelogForOneOfThem_LimitToOldestEvent() 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");
    final String testSummary = "test for second file.";
    f2.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", testSummary));
    f2.writeString("this is another test", "UTF-8", new ChangeSummary("test-user", "test (2) for second file."));
    listener.waitForEvents(3);
    final List<ChangeSummary> changeLog = revManager.getDataChangeLog(f2.getPath(), 1, 1);
    assertThat(changeLog, notNullValue());
    assertThat(changeLog.size(), equalTo(1));
    final ChangeSummary summary = changeLog.get(0);
    assertThat(summary.getSummary().startsWith(testSummary), equalTo(true));
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Test(org.junit.Test)

Example 24 with DataFile

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

the class RevisionsManagerTest method commitOneFileTwice_NoChangeSecondTime_RetrieveOneChangelog.

@Test
public void commitOneFileTwice_NoChangeSecondTime_RetrieveOneChangelog() throws Exception {
    lcEvents.fireStarted();
    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 a 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  "));
    final List<ChangeSummary> changeLog = revManager.getDataChangeLog(f1.getPath(), 0, -1);
    assertThat(changeLog, notNullValue());
    assertThat(changeLog.size(), equalTo(1));
    assertThat(changeLog.get(0).getSummary().contains("test for first write of file."), equalTo(true));
}
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)

Example 25 with DataFile

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

the class IndyUserLifecycleManager method getUserLifecycleActions.

@Override
public <T extends IndyLifecycleAction> Collection<T> getUserLifecycleActions(String lifecycleName, Class<T> type) {
    DataFile lifecycleDir = dataFileManager.getDataFile(LIFECYCLE_DIR, lifecycleName);
    Collection<T> set = new HashSet<T>();
    if (lifecycleDir.exists()) {
        final DataFile[] scripts = lifecycleDir.listFiles((pathname) -> {
            logger.info("Checking for user lifecycle action script in: {}", pathname);
            return pathname.getName().endsWith(".groovy");
        });
        for (final DataFile script : scripts) {
            logger.info("Reading user lifecycle action script from: {}", script);
            try {
                String s = script.readString();
                Object obj = scriptEngine.parseScriptInstance(s, type, true);
                T action = type.cast(obj);
                set.add(action);
                logger.debug("Parsed: {}", obj.getClass().getName());
            } catch (final Exception e) {
                logger.error(String.format("Cannot load user lifecycle action script from: %s. Reason: %s", script, e.getMessage()), e);
            }
        }
    }
    return set;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) HashSet(java.util.HashSet)

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