本文整理汇总了Java中org.srcdeps.core.SrcVersion类的典型用法代码示例。如果您正苦于以下问题:Java SrcVersion类的具体用法?Java SrcVersion怎么用?Java SrcVersion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SrcVersion类属于org.srcdeps.core包,在下文中一共展示了SrcVersion类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openBuildDirectory
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
/**
* Goes sequentially over integers form {@code 0} to {@link #CONCURRENCY_THRESHOLD} until it finds such {@code i} of
* them which when appended to <code>"${rootDirectory}/${projectBuildHome}"</code>, makes up a new or existing
* directory <code>"${rootDirectory}/${projectBuildHome}/${i}"</code> that can be locked using {@link #pathLocker}.
* The {@link PathLock} returned contains a reference to the first
* <code>"${rootDirectory}/${projectBuildHome}/${i}"</code> that could be locked successfully.
* <p>
* The returned {@link PathLock} should be released using its {@link Closeable#close()} method.
*
* @param projectBuildHome
* the given project's build home (something like {@code Paths.get("org", "project", "component")})
* relative to {@link #rootDirectory} under which a subdirectory will be taken or created and
* subsequently locked via {@link PathLocker#tryLockDirectory(Path)}
* @param srcVersion
* @return a {@link PathLock} whose holder is guaranteed to have an exclusive access to {@link PathLock#getPath()}
* @throws BuildException
* when no such {@code i} between {@code 0} and {@link #CONCURRENCY_THRESHOLD} could be found that a
* directory <code>"${rootDirectory}/${projectBuildHome}/${i}"</code> could be locked.
* @throws IOException
*/
public PathLock openBuildDirectory(Path projectBuildHome, SrcVersion srcVersion) throws BuildException, IOException {
Path scmRepositoryDir = rootDirectory.resolve(projectBuildHome);
SrcdepsCoreUtils.ensureDirectoryExists(scmRepositoryDir);
Throwable lastException = null;
for (int i = 0; i < CONCURRENCY_THRESHOLD; i++) {
Path checkoutDirectoryPath = scmRepositoryDir.resolve(String.valueOf(i));
try {
return pathLocker.lockDirectory(checkoutDirectoryPath, srcVersion);
} catch (CannotAcquireLockException e) {
/* nevermind, another i will work */
lastException = e;
log.debug("Could not get PathLock for path {}", checkoutDirectoryPath);
}
}
throw new BuildException(String.format("Could not get PathLock for any of 0-%d subpaths of [%s]",
CONCURRENCY_THRESHOLD - 1, scmRepositoryDir), lastException);
}
示例2: execute
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
@Override
public void execute(DependencyResolveDetails dep) {
ModuleVersionSelector requested = dep.getRequested();
final String version = requested.getVersion();
if (SrcVersion.isSrcVersion(version)) {
final SrcdepsService srcdepsService = Wiring.getInjector().getInstance(SrcdepsService.class);
srcdepsService.buildIfNecessary(requested.getGroup(), requested.getName(), version);
}
}
示例3: main
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
public static void main(String[] args) {
try {
int i = 0;
new PathLockerProcess(Paths.get(args[i++]), SrcVersion.parse(args[i++]), Paths.get(args[i++]),
Paths.get(args[i++])).run();
} catch (Throwable e) {
e.printStackTrace();
log.info(pid + " PathLockerProcess exiting");
System.exit(500);
}
}
示例4: PathLockerProcess
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
public PathLockerProcess(Path lockedDirectory, SrcVersion srcVersion, Path keepRunnigFile, Path lockSuccessFile) {
super();
this.lockedDirectory = lockedDirectory;
this.keepRunnigFile = keepRunnigFile;
this.lockSuccessFile = lockSuccessFile;
this.srcVersion = srcVersion;
if (Files.notExists(keepRunnigFile)) {
throw new IllegalStateException(String
.format("The keepRunnigFile [%s] should exist when PathLockerProcess is created", keepRunnigFile));
}
if (Files.exists(lockSuccessFile)) {
throw new IllegalStateException(String.format(
"The lockSuccessFile [%s] should not exist when PathLockerProcess is created", lockSuccessFile));
}
}
示例5: lockConcurrently
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
private Future<PathLock> lockConcurrently(final PathLocker<SrcVersion> pathLocker, final Path path,
final SrcVersion srcVersion) {
final ExecutorService executor = Executors.newSingleThreadExecutor();
return executor.submit(new Callable<PathLock>() {
@Override
public PathLock call() throws Exception {
return pathLocker.lockDirectory(path, srcVersion);
}
});
}
示例6: testCheckout
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
@Test
public void testCheckout() throws IOException, ScmException, NoHeadException, GitAPIException {
Path dir = targetDir.resolve("test-repo");
SrcdepsCoreUtils.ensureDirectoryExistsAndEmpty(dir);
/* first clone */
BuildRequest cloningRequest = BuildRequest.builder() //
.srcVersion(SrcVersion.parse("0.0.1-SRC-tag-0.0.1")) //
.dependentProjectRootDirectory(dir) //
.projectRootDirectory(dir) //
.scmUrl("git:https://github.com/srcdeps/srcdeps-test-artifact.git") //
.versionsMavenPluginVersion(Maven.getDefaultVersionsMavenPluginVersion()) //
.gradleModelTransformer(CharStreamSource.defaultModelTransformer()) //
.build();
JGitScm jGitScm = new JGitScm();
jGitScm.checkout(cloningRequest);
/* ensure that the tag is there through checking that it has a known commit hash */
assertCommit(dir, "19ef91ed30fd8b1a459803ee0c279dcf8e236184");
/* try if the fetch works after we have cloned already */
BuildRequest fetchingRequest = BuildRequest.builder() //
.srcVersion(SrcVersion.parse("0.0.1-SRC-revision-0a5ab902099b24c2b13ed1dad8c5f537458bcc89")) //
.dependentProjectRootDirectory(dir) //
.projectRootDirectory(dir) //
.scmUrl("git:https://github.com/srcdeps/srcdeps-test-artifact.git") //
.versionsMavenPluginVersion(Maven.getDefaultVersionsMavenPluginVersion()) //
.gradleModelTransformer(CharStreamSource.defaultModelTransformer()) //
.build();
jGitScm.fetchAndReset(fetchingRequest);
/* ensure that the WC's HEAD has the known commit hash */
assertCommit(dir, "0a5ab902099b24c2b13ed1dad8c5f537458bcc89");
}
示例7: assertNotSrcdeps
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
private static void assertNotSrcdeps(String group, String artifact, String version, String[] violation)
throws LifecycleExecutionException {
if (SrcVersion.isSrcVersion(version)) {
throw new LifecycleExecutionException(String.format(
"This build was configured to fail if there is a source dependency [%s:%s:%s] and %s [%s]", group,
artifact, version, violation[0], violation[1]));
}
}
示例8: SrcdepsLocalRepositoryManager
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
public SrcdepsLocalRepositoryManager(LocalRepositoryManager delegate, BuildService buildService,
PathLocker<SrcVersion> pathLocker, ConfigurationProducer configurationProducer) {
super();
this.delegate = delegate;
this.buildService = buildService;
this.scrdepsDir = delegate.getRepository().getBasedir().toPath().getParent().resolve("srcdeps");
this.buildDirectoriesManager = new BuildDirectoriesManager(scrdepsDir, pathLocker);
this.configurationProducer = configurationProducer;
}
示例9: init
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
/**
* Performs the wiring for the given Gradle {@link Project}.
*
* @param project
*/
public static void init(final Project project) {
final Path srcdepsYamlPath = project.getRootDir().toPath().resolve("srcdeps.yaml");
Gradle gradle = project.getGradle();
if (!(gradle instanceof GradleInternal)) {
throw new RuntimeException(String.format("Expected %s, but found %s", GradleInternal.class.getName(),
gradle.getClass().getName()));
}
ServiceRegistry services = ((GradleInternal) gradle).getServices();
if (!(services instanceof DefaultServiceRegistry)) {
throw new RuntimeException(String.format("Expected %s, but found %s",
DefaultServiceRegistry.class.getName(), services.getClass().getName()));
}
ArtifactRepository repo = project.getRepositories()
.findByName(org.gradle.api.artifacts.ArtifactRepositoryContainer.DEFAULT_MAVEN_LOCAL_REPO_NAME);
if (!(repo instanceof MavenArtifactRepository)) {
throw new RuntimeException(
String.format("Expected %s, but found %s", MavenArtifactRepository.class.getName(), repo));
}
final MavenLocalRepository localRepository = new MavenLocalRepository(Paths.get(((MavenArtifactRepository) repo).getUrl()));
final Path scrdepsDir = localRepository.getRootDirectory().getParent().resolve("srcdeps");
final PathLocker<SrcVersion> pathLocker = new PathLocker<>();
final BuildDirectoriesManager buildDirectoriesManager = new BuildDirectoriesManager(scrdepsDir, pathLocker);
ClassLoader classloader = Wiring.class.getClassLoader();
final Module spaceModule = new SpaceModule(new URLClassSpace(classloader));
Module wrappedWiremodule = new Module() {
@Override
public void configure(Binder binder) {
spaceModule.configure(binder);
binder.bind(Path.class).annotatedWith(Names.named(ConfigurationService.SRCDEPS_YAML_PATH))
.toInstance(srcdepsYamlPath);
binder.bind(MavenLocalRepository.class).toInstance(localRepository);
binder.bind(new TypeLiteral<PathLocker<SrcVersion>>() {
}).toInstance(pathLocker);
binder.bind(BuildDirectoriesManager.class).toInstance(buildDirectoriesManager);
}
};
final Module wireModule = new WireModule(wrappedWiremodule);
injector = Guice.createInjector(wireModule);
}
示例10: buildIfNecessary
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
/**
* Builds the artifact given by the arguments if necessary and installs it to the Local Maven Repository.
*
* @param groupId
* @param artifactId
* @param version
*/
public void buildIfNecessary(String groupId, String artifactId, String version) {
final Configuration configuration = configurationService.getConfiguration();
if (configuration.isSkip()) {
log.info("srcdeps: Skipped");
}
Gavtc artifactGavtc = new Gavtc(groupId, artifactId, version, "jar"); // FIXME: "jar" should not be hard
// coded but Gradle does not seem to have
// a notion of type an classifier (does
// it?)
Path artfactPath = localRepository.resolve(artifactGavtc);
if (!Files.exists(artfactPath)) {
ScmRepository scmRepo = findScmRepo(configuration.getRepositories(), groupId, artifactId, version);
SrcVersion srcVersion = SrcVersion.parse(version);
try (PathLock projectBuildDir = buildDirectoriesManager.openBuildDirectory(scmRepo.getIdAsPath(),
srcVersion)) {
/* query the delegate again, because things may have changed since we requested the lock */
if (Files.exists(artfactPath)) {
log.debug("srcdeps: Found in the local repo and using it as is: {}", artfactPath);
return;
} else {
/* no change in the local repo, let's build */
BuilderIo builderIo = scmRepo.getBuilderIo();
IoRedirects ioRedirects = IoRedirects.builder() //
.stdin(IoRedirects.parseUri(builderIo.getStdin())) //
.stdout(IoRedirects.parseUri(builderIo.getStdout())) //
.stderr(IoRedirects.parseUri(builderIo.getStderr())) //
.build();
List<String> buildArgs = enhanceBuildArguments(scmRepo.getBuildArguments(),
configurationService.getConfigurationLocation(),
localRepository.getRootDirectory().toString());
BuildRequest buildRequest = BuildRequest.builder() //
.dependentProjectRootDirectory(configurationService.getMultimoduleProjectRootDirectory())
.projectRootDirectory(projectBuildDir.getPath()) //
.scmUrls(scmRepo.getUrls()) //
.srcVersion(srcVersion) //
.buildArguments(buildArgs) //
.timeoutMs(scmRepo.getBuildTimeout().toMilliseconds()) //
.skipTests(scmRepo.isSkipTests()) //
.forwardProperties(configuration.getForwardProperties()) //
.addDefaultBuildArguments(scmRepo.isAddDefaultBuildArguments()) //
.verbosity(scmRepo.getVerbosity()) //
.ioRedirects(ioRedirects) //
.versionsMavenPluginVersion(scmRepo.getMaven().getVersionsMavenPluginVersion())
.gradleModelTransformer(scmRepo.getGradle().getModelTransformer()).build();
buildService.build(buildRequest);
/* check once again if the delegate sees the newly built artifact */
if (!Files.exists(artfactPath)) {
log.error(
"srcdeps: Build succeeded but the artifact {}:{}:{} is still not available in the local repository",
groupId, artifactId, version);
}
}
} catch (BuildException | IOException e) {
log.error("srcdeps: Could not build {}:{}:{}" + groupId, artifactId, version, e);
}
}
}
示例11: BuildDirectoriesManager
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
public BuildDirectoriesManager(Path rootDirectory, PathLocker<SrcVersion> pathLocker) {
super();
this.rootDirectory = rootDirectory;
this.pathLocker = pathLocker;
}
示例12: cloneAndCheckout
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
void cloneAndCheckout(BuildRequest request) throws ScmException {
final Path dir = request.getProjectRootDirectory();
final SrcVersion srcVersion = request.getSrcVersion();
ScmException lastException = null;
/* Try the urls one after another and exit on the first success */
for (String url : request.getScmUrls()) {
String useUrl = stripUriPrefix(url);
log.info("srcdeps: attempting to clone version {} from SCM URL {}", request.getSrcVersion(), useUrl);
CloneCommand cmd = Git.cloneRepository().setURI(useUrl).setDirectory(dir.toFile());
switch (srcVersion.getWellKnownType()) {
case branch:
case tag:
cmd.setBranch(srcVersion.getScmVersion());
break;
case revision:
cmd.setCloneAllBranches(true);
break;
default:
throw new IllegalStateException("Unexpected " + WellKnownType.class.getName() + " value '"
+ srcVersion.getWellKnownType() + "'.");
}
try (Git git = cmd.call()) {
git.checkout().setName(srcVersion.getScmVersion()).call();
/*
* workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474093
*/
git.getRepository().close();
/* return on the first success */
return;
} catch (Exception e) {
log.warn("srcdeps: could not checkout version {} from SCM URL {}: {}: {}", request.getSrcVersion(),
useUrl, e.getClass().getName(), e.getMessage());
lastException = new ScmException(String.format("Could not checkout from URL [%s]", useUrl), e);
}
}
throw lastException;
}
示例13: anotherProcess
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
/**
* First spawns another process that locks some test directory and then makes sure that the present process'es
* {@link PathLocker} cannot lock the same directory at the same time.
*
* @throws Exception
*/
@Test
public void anotherProcess() throws Exception {
final Path keepRunnigFile = targetDirectory
.resolve("PathLockerProcess-keep-running-" + UUID.randomUUID().toString());
Files.write(keepRunnigFile, "PathLockerProcess will run till this file exists".getBytes("utf-8"));
final Path dirToLock = lockerDirectory.resolve(UUID.randomUUID().toString());
final SrcVersion srcVersion = SrcVersion.parse("1.2.3-SRC-revision-deadbeef");
final Path lockSuccessFile = dirToLock.resolve("lock-success.txt");
/* lock dirToLock from another process running on the same machine */
final String slfApiJar = getJarPath(org.slf4j.LoggerFactory.class);
final String slfSimpleJar = getJarPath(org.slf4j.impl.StaticLoggerBinder.class);
final String classPath = targetDirectory.resolve("classes").toString() + File.pathSeparator
+ targetDirectory.resolve("test-classes").toString() + File.pathSeparator + slfApiJar
+ File.pathSeparator + slfSimpleJar;
final ShellCommand command = ShellCommand.builder().executable(SrcdepsCoreUtils.getCurrentJavaExecutable())
.arguments("-cp", classPath, PathLockerProcess.class.getName(), dirToLock.toString(),
srcVersion.toString(), keepRunnigFile.toString(), lockSuccessFile.toString())
.workingDirectory(lockerDirectory).build();
final ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> future = executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
Shell.execute(command).assertSuccess();
return true;
}
});
/* with some delay, the dirToLock eventually gets locked by PathLockerProcess */
final PathLocker<SrcVersion> pathLocker = new PathLocker<>();
final long timeoutSeconds = 5;
final long lockDeadline = System.currentTimeMillis() + (timeoutSeconds * 1000);
while (Files.notExists(lockSuccessFile) && System.currentTimeMillis() <= lockDeadline) {
log.debug(pid + " Lock success file not there yet {}", lockSuccessFile);
Thread.sleep(10);
}
Assert.assertTrue(
String.format("PathLockerProcess has not locked [%s] within [%d] seconds", dirToLock, timeoutSeconds),
Files.exists(lockSuccessFile));
log.debug(pid + " Lock success file exists {}", lockSuccessFile);
try (PathLock lock1 = pathLocker.lockDirectory(dirToLock, srcVersion)) {
/* locked for the current thread */
Assert.fail(String.format("The current thread and process should not be able to lock [%s]", dirToLock));
} catch (CannotAcquireLockException e) {
/* expected */
} finally {
/* Signal to PathLockerProcess that it should exit */
Files.deleteIfExists(keepRunnigFile);
/* Ensure the PathLockerProcess exited cleanly */
future.get(5, TimeUnit.SECONDS);
}
/*
* PathLockerProcess must have unlocked at this point and we must succeed in locking from here now
*/
try (PathLock lock1 = pathLocker.lockDirectory(dirToLock, srcVersion)) {
Assert.assertTrue(lock1 != null);
}
}
示例14: find
import org.srcdeps.core.SrcVersion; //导入依赖的package包/类
/**
* In case the {@link #delegate} does not find the given artifact and the given artifact's version string is a
* srcdeps version string, then the version is built from source and returned.
*
* @see org.eclipse.aether.repository.LocalRepositoryManager#find(org.eclipse.aether.RepositorySystemSession,
* org.eclipse.aether.repository.LocalArtifactRequest)
*/
@Override
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
log.debug("Srcdeps looking up locally {}", request.getArtifact());
final LocalArtifactResult result = delegate.find(session, request);
Artifact artifact = request.getArtifact();
String version = artifact.getVersion();
if (!result.isAvailable() && SrcVersion.isSrcVersion(version)) {
final Configuration configuration = configurationProducer.getConfiguration();
if (!configuration.isSkip()) {
final ScmRepository scmRepo = findScmRepo(configuration.getRepositories(), artifact.getGroupId(), artifact.getArtifactId(),
version);
SrcVersion srcVersion = SrcVersion.parse(version);
try (PathLock projectBuildDir = buildDirectoriesManager.openBuildDirectory(scmRepo.getIdAsPath(),
srcVersion)) {
/* query the delegate again, because things may have changed since we requested the lock */
final LocalArtifactResult result2 = delegate.find(session, request);
if (result2.isAvailable()) {
return result2;
} else {
/* no change in the local repo, let's build */
BuilderIo builderIo = scmRepo.getBuilderIo();
IoRedirects ioRedirects = IoRedirects.builder() //
.stdin(IoRedirects.parseUri(builderIo.getStdin())) //
.stdout(IoRedirects.parseUri(builderIo.getStdout())) //
.stderr(IoRedirects.parseUri(builderIo.getStderr())) //
.build();
List<String> buildArgs = enhanceBuildArguments(scmRepo.getBuildArguments(),
configurationProducer.getConfigurationLocation(),
delegate.getRepository().getBasedir().getAbsolutePath());
BuildRequest buildRequest = BuildRequest.builder() //
.dependentProjectRootDirectory(configurationProducer.getMultimoduleProjectRootDirectory()) //
.projectRootDirectory(projectBuildDir.getPath()) //
.scmUrls(scmRepo.getUrls()) //
.srcVersion(srcVersion) //
.buildArguments(buildArgs) //
.timeoutMs(scmRepo.getBuildTimeout().toMilliseconds()) //
.skipTests(scmRepo.isSkipTests()) //
.forwardProperties(configuration.getForwardProperties()) //
.addDefaultBuildArguments(scmRepo.isAddDefaultBuildArguments()) //
.verbosity(scmRepo.getVerbosity()) //
.ioRedirects(ioRedirects) //
.versionsMavenPluginVersion(scmRepo.getMaven().getVersionsMavenPluginVersion())
.gradleModelTransformer(scmRepo.getGradle().getModelTransformer()).build();
buildService.build(buildRequest);
/* check once again if the delegate sees the newly built artifact */
final LocalArtifactResult newResult = delegate.find(session, request);
if (!newResult.isAvailable()) {
log.error(
"Srcdeps build succeeded but the artifact {} is still not available in the local repository",
artifact);
}
return newResult;
}
} catch (BuildException | IOException e) {
log.error("Srcdeps could not build " + request, e);
}
}
}
return result;
}