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