use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.
the class GitManager method commitModifiedFiles.
public GitManager commitModifiedFiles(final ChangeSummary changeSummary) throws GitSubsystemException {
lockAnd((me) -> {
Status status;
try {
status = git.status().call();
} catch (NoWorkTreeException | GitAPIException e) {
throw new GitSubsystemException("Failed to retrieve status of: %s. Reason: %s", e, rootDir, e.getMessage());
}
final Map<String, StageState> css = status.getConflictingStageState();
if (!css.isEmpty()) {
throw new GitSubsystemException("%s contains conflicts. Cannot auto-commit.\n %s", rootDir, new JoinString("\n ", css.entrySet()));
}
final Set<String> toAdd = new HashSet<>();
final Set<String> modified = status.getModified();
if (modified != null && !modified.isEmpty()) {
toAdd.addAll(modified);
}
final Set<String> untracked = status.getUntracked();
if (untracked != null && !untracked.isEmpty()) {
toAdd.addAll(untracked);
}
final Set<String> untrackedFolders = status.getUntrackedFolders();
if (untrackedFolders != null && !untrackedFolders.isEmpty()) {
toAdd.addAll(untrackedFolders);
// for ( String folderPath : untrackedFolders )
// {
// File dir = new File( rootDir, folderPath );
// Files.walkFileTree( null, null )
// }
}
if (!toAdd.isEmpty()) {
addAndCommitPaths(changeSummary, toAdd);
}
return me;
});
return this;
}
use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.
the class ImpliedRepoMaintainer method processImpliedRepos.
private boolean processImpliedRepos(final ImpliedRepoMaintJob job) {
final Set<StoreKey> processed = new HashSet<>();
// implications. Reachable means they could be in nested groups.
for (final ArtifactStore member : job.reachableMembers) {
processed.add(member.getKey());
}
logger.debug("Preset processed-implications to reachable members:\n {}", new JoinString("\n ", processed));
int lastLen = 0;
boolean changed = false;
job.added = new ArrayList<>();
// As soon as we go an iteration without adding a new member, we've captured everything.
do {
lastLen = job.members.size();
for (final ArtifactStore member : new ArrayList<>(job.members)) {
logger.debug("Processing member: {} for implied repos within group: {}", member.getKey(), job.group.getKey());
processed.add(member.getKey());
List<StoreKey> implied;
try {
implied = metadataManager.getStoresImpliedBy(member);
} catch (final ImpliedReposException e) {
logger.error("Failed to retrieve implied-store metadata for: " + member.getKey(), e);
continue;
}
if (implied == null || implied.isEmpty()) {
continue;
}
implied.removeAll(processed);
for (final StoreKey key : implied) {
logger.debug("Found implied store: {} not already in group: {}", key, job.group.getKey());
ArtifactStore impliedStore;
try {
impliedStore = storeManager.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error("Failed to retrieve store: " + key + " implied by: " + member.getKey(), e);
continue;
}
logger.info("Adding: {} to group: {} (implied by POMs in: {})", key, job.group.getKey(), member.getKey());
processed.add(key);
job.added.add(key);
job.group.addConstituent(key);
job.members.add(impliedStore);
changed = true;
}
}
} while (job.members.size() > lastLen);
return changed;
}
use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.
the class ImpliedRepositoryDetector method addImpliedRepositories.
private void addImpliedRepositories(final ImplicationsJob job) {
job.implied = new ArrayList<>();
logger.debug("Retrieving repository/pluginRepository declarations from:\n {}", new JoinString("\n ", job.pomView.getDocRefStack()));
final List<List<RepositoryView>> repoLists = Arrays.asList(job.pomView.getNonProfileRepositories(), job.pomView.getAllPluginRepositories());
final ImpliedRepositoryCreator creator = createRepoCreator();
if (creator == null) {
logger.error("Cannot proceed without a valid ImpliedRepositoryCreator instance. Aborting detection.");
return;
}
for (final List<RepositoryView> repos : repoLists) {
if (repos == null || repos.isEmpty()) {
continue;
}
for (final RepositoryView repo : repos) {
final ProjectVersionRef gav = job.pathInfo.getProjectId();
try {
if (config.isBlacklisted(repo.getUrl())) {
logger.debug("Discarding blacklisted repository: {}", repo);
continue;
} else if (!config.isIncludeSnapshotRepos() && !repo.isReleasesEnabled()) {
logger.debug("Discarding snapshot repository: {}", repo);
continue;
}
} catch (final MalformedURLException e) {
logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to check if repository is blacklisted.", repo.getUrl(), gav, job.transfer), e);
}
logger.debug("Detected POM-declared repository: {}", repo);
RemoteRepository rr = null;
try {
rr = storeManager.query().packageType(MAVEN_PKG_KEY).getRemoteRepositoryByUrl(repo.getUrl());
} catch (IndyDataException e) {
logger.error(String.format("Cannot lookup remote repositories by URL: %s. Reason: %s", e.getMessage()), e);
}
if (rr == null) {
logger.debug("Creating new RemoteRepository for: {}", repo);
rr = creator.createFrom(gav, repo, LoggerFactory.getLogger(creator.getClass()));
if (rr == null) {
logger.warn("ImpliedRepositoryCreator didn't create anything for repo: {}, specified in: {}. Skipping.", repo.getId(), gav);
continue;
}
rr.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
if (!remoteValidator.isValid(rr)) {
logger.warn("Implied repository to: {} is invalid! Repository created was: {}", repo.getUrl(), rr);
continue;
}
final String changelog = String.format("Adding remote repository: %s (url: %s, name: %s), which is implied by the POM: %s (at: %s/%s)", repo.getId(), repo.getUrl(), repo.getName(), gav, job.transfer.getLocation().getUri(), job.transfer.getPath());
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, changelog);
try {
final boolean result = storeManager.storeArtifactStore(rr, summary, true, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_BY_POM_TRANSFER, job.transfer));
logger.debug("Stored new RemoteRepository: {}. (successful? {})", rr, result);
job.implied.add(rr);
} catch (final IndyDataException e) {
logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to store new remote repository.", repo.getUrl(), gav, job.transfer), e);
}
} else {
logger.debug("Found existing RemoteRepository: {}", rr);
}
}
}
}
use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.
the class ImpliedRepositoryDetector method addImpliedMetadata.
private boolean addImpliedMetadata(final ImplicationsJob job) {
try {
logger.debug("Adding implied-repo metadata to: {} and {}", job.store, new JoinString(", ", job.implied));
metadataManager.addImpliedMetadata(job.store, job.implied);
return true;
} catch (final ImpliedReposException e) {
logger.error("Failed to store list of implied stores in: " + job.store.getKey(), e);
}
return false;
}
use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.
the class StoreAdminHandler method getAll.
@ApiOperation("Retrieve the definitions of all artifact stores of a given type on the system")
@ApiResponses({ @ApiResponse(code = 200, response = StoreListingDTO.class, message = "The store definitions") })
@GET
@Produces(ApplicationContent.application_json)
public Response getAll(@ApiParam("Filter only stores that support the package type (eg. maven, npm). NOTE: '_all' returns all.") @PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type) {
final StoreType st = StoreType.get(type);
Response response;
try {
final List<ArtifactStore> stores = adminController.getAllOfType(packageType, st);
logger.info("Returning listing containing stores:\n\t{}", new JoinString("\n\t", stores));
final StoreListingDTO<ArtifactStore> dto = new StoreListingDTO<>(stores);
response = formatOkResponseWithJsonEntity(dto, objectMapper);
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e);
}
return response;
}
Aggregations