Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deactivate logging of each resource get in build log #106

Merged
merged 1 commit into from
Aug 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@
public class GetFilesToWorkFolderCommand extends AbstractCallableCommand implements Callable<Void, Exception>, GetListener {

private static final String GettingTemplate = "Getting version '%s' to '%s'...";
private static final String GotTemplate = "Finished getting version '%s'.";
private static final String GotTemplate = "Finished getting version '%s'. Retrieved %d resources.";

private final String workFolder;
private final String versionSpec;
private final boolean shouldLogEachGet;
private PrintStream logger;
private int getCount = 0;

public GetFilesToWorkFolderCommand(final ServerConfigurationProvider server, final String workFolder, final String versionSpec) {
this(server, workFolder, versionSpec, false);
// using shouldLogEachGet false as default, could be controlled by a config option at a later stage if desired, just adds noise to log though
}

public GetFilesToWorkFolderCommand(final ServerConfigurationProvider server, final String workFolder, final String versionSpec,
final boolean shouldLogEachGet) {
super(server);
this.workFolder = workFolder;
this.versionSpec = versionSpec;
this.shouldLogEachGet = shouldLogEachGet;
}

@Override
Expand Down Expand Up @@ -58,18 +67,19 @@ public Void call() throws Exception {
final VersionControlEventEngine eventEngine = vcc.getEventEngine();
eventEngine.addGetListener(this);
workspace.get(getVersionSpec, GetOptions.NONE);
// TODO: (PR #34) throw an exception if not all files could be fetched, there were conflicts, etc.
eventEngine.removeGetListener(this);

final String gotMessage = String.format(GotTemplate, versionSpecString);
final String gotMessage = String.format(GotTemplate, versionSpecString, getCount);
logger.println(gotMessage);

return null;
}

public void onGet(final GetEvent getEvent) {
// TODO: The CLC used to emit folder paths as headings, then files within; should we do that?
logger.println(getEvent.getTargetLocalItem());
getCount++;
if (shouldLogEachGet) {
logger.println(getEvent.getTargetLocalItem());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class GetFilesToWorkFolderCommandTest extends AbstractCallableCommandTest
final GetEvent getEvent = mock(GetEvent.class);
final String pathToFile = "C:\\.jenkins\\jobs\\typical\\workspace\\TODO.txt";
when(getEvent.getTargetLocalItem()).thenReturn(pathToFile);
final GetFilesToWorkFolderCommand cut = new GetFilesToWorkFolderCommand(server, null, null);
final GetFilesToWorkFolderCommand cut = new GetFilesToWorkFolderCommand(server, null, null, true);
cut.setLogger(new PrintStream(this.outputStream));

cut.onGet(getEvent);
Expand Down