use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class AutoProxDataManagerDecorator method getRemoteRepository.
private RemoteRepository getRemoteRepository(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
logger.debug("DECORATED (getRemoteRepository: {})", key);
RemoteRepository repo = (RemoteRepository) dataManager.getArtifactStore(key);
if (!catalog.isEnabled()) {
logger.debug("AutoProx decorator disabled; returning: {}", repo);
return repo;
}
logger.debug("AutoProx decorator active");
if (repo == null) {
logger.info("AutoProx: creating repository for: {}", key);
try {
repo = catalog.createRemoteRepository(key);
if (repo != null) {
if (!checkValidity(key)) {
return null;
}
final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? repo.getKey() : impliedBy);
dataManager.storeArtifactStore(repo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating remote repository for: '" + key + "'"), false, true, eventMetadata);
}
} catch (final AutoProxRuleException e) {
throw new IndyDataException("[AUTOPROX] Failed to create new remote repository from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
}
}
return repo;
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class AutoProxDataManagerDecorator method getGroup.
private Group getGroup(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
logger.debug("DECORATED (getGroup: {})", key);
Group g = (Group) dataManager.getArtifactStore(key);
if (!catalog.isEnabled()) {
logger.debug("AutoProx decorator disabled; returning: {}", g);
return g;
}
logger.debug("AutoProx decorator active");
if (g == null) {
logger.debug("AutoProx: creating repository for: {}", key);
if (!checkValidity(key)) {
return null;
}
try {
g = catalog.createGroup(key);
} catch (final AutoProxRuleException e) {
throw new IndyDataException("[AUTOPROX] Failed to create new group from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
}
if (g != null) {
logger.info("Validating group: {}", g);
for (final StoreKey memberKey : new ArrayList<>(g.getConstituents())) {
final ArtifactStore store = getArtifactStore(memberKey, impliedBy == null ? g.getKey() : impliedBy);
if (store == null) {
g.removeConstituent(memberKey);
}
}
if (g.getConstituents().isEmpty()) {
return null;
}
final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? g.getKey() : impliedBy);
dataManager.storeArtifactStore(g, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating group for: '" + key + "'"), false, true, eventMetadata);
}
}
return g;
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class AutoProxAproxMigrationAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
final DataFile dataDir = ffManager.getDataFile(config.getBasedir());
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Scanning {} for autoprox rules...", dataDir);
int changed = 0;
if (dataDir.exists()) {
final DataFile[] scripts = dataDir.listFiles((pathname) -> {
logger.trace("Checking for autoprox rule in: {}", pathname);
return pathname.getName().endsWith(".groovy");
});
logger.info("Migrating autoprox rules.");
for (final DataFile script : scripts) {
try {
String scriptContent = script.readString();
String migrated = scriptContent.replaceAll("A[Pp]rox", "Indy").replaceAll("aprox", "indy");
if (!migrated.equals(scriptContent)) {
logger.info("Migrating autoprox rule in: {}", script.getPath());
script.writeString(migrated, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Migrating to Indy packages / naming"));
changed++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
return changed != 0;
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class GitManager method toChangeSummary.
// private void printFiles( final RevCommit commit )
// throws IOException
// {
// final RevWalk tree = new RevWalk( repo );
// final RevCommit parent = commit.getParentCount() > 0 ? tree.parseCommit( commit.getParent( 0 )
// .getId() ) : null;
//
// final DiffFormatter df = new DiffFormatter( DisabledOutputStream.INSTANCE );
// df.setRepository( repo );
// df.setDiffComparator( RawTextComparator.DEFAULT );
// df.setDetectRenames( true );
//
// final List<DiffEntry> diffs;
// if ( parent == null )
// {
// diffs =
// df.scan( new EmptyTreeIterator(),
// new CanonicalTreeParser( null, tree.getObjectReader(), commit.getTree() ) );
// }
// else
// {
// diffs = df.scan( parent.getTree(), commit.getTree() );
// }
//
// for ( final DiffEntry diff : diffs )
// {
// logger.info( "({} {} {}", diff.getChangeType()
// .name(), diff.getNewMode()
// .getBits(), diff.getNewPath() );
// }
// }
private ChangeSummary toChangeSummary(final RevCommit commit) {
final PersonIdent who = commit.getAuthorIdent();
final Date when = new Date(TimeUnit.MILLISECONDS.convert(commit.getCommitTime(), TimeUnit.SECONDS));
return new ChangeSummary(who.getName(), commit.getFullMessage(), when, commit.getId().name());
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class GitManagerConcurrentTest method concurrentAddToRepo.
@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "GitManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "addAndCommitPaths call", targetClass = "GitManager", targetMethod = "addAndCommitPaths(ChangeSummary,Collection)", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": thread proceeding.\")") })
@Test
public void concurrentAddToRepo() throws Exception {
final int threshold = 2;
final Executor pool = Executors.newFixedThreadPool(threshold);
CountDownLatch latch = new CountDownLatch(threshold);
for (int i = 0; i < threshold; i++) {
final int j = i;
pool.execute(() -> {
try {
final File f = new File(cloneDir, String.format("test%s.txt", j));
FileUtils.write(f, String.format("This is a test %s", j));
final String user = "test" + j;
final String log = "test commit " + j;
git.addAndCommitFiles(new ChangeSummary(user, log), f);
} catch (Exception e) {
e.printStackTrace();
failed = true;
} finally {
latch.countDown();
}
});
}
latch.await();
if (failed) {
fail();
}
}
Aggregations