private void addConfiguration(final Project project, final SonarRunnerRootExtension rootExtension) { final Configuration configuration = project.getConfigurations().create(SonarRunnerExtension.SONAR_RUNNER_CONFIGURATION_NAME); configuration .setVisible(false) .setTransitive(false) .setDescription("The SonarRunner configuration to use to run analysis") .getIncoming() .beforeResolve(new Action<ResolvableDependencies>() { public void execute(ResolvableDependencies resolvableDependencies) { DependencySet dependencies = resolvableDependencies.getDependencies(); if (dependencies.isEmpty()) { String toolVersion = rootExtension.getToolVersion(); DependencyHandler dependencyHandler = project.getDependencies(); Dependency dependency = dependencyHandler.create("org.codehaus.sonar.runner:sonar-runner-dist:" + toolVersion); configuration.getDependencies().add(dependency); } } }); }
private void resolveGraphIfRequired(final InternalState requestedState) { if (resolvedState == ARTIFACTS_RESOLVED) { if (dependenciesModified) { throw new InvalidUserDataException(String.format("Attempted to resolve %s that has been resolved previously.", getDisplayName())); } return; } if (resolvedState == GRAPH_RESOLVED) { if (!dependenciesModified) { return; } throw new InvalidUserDataException(String.format("Resolved %s again after modification", getDisplayName())); } if (resolvedState != UNRESOLVED) { throw new IllegalStateException("Graph resolution already performed"); } buildOperationExecutor.run("Resolve dependencies " + identityPath, new Action<BuildOperationContext>() { @Override public void execute(BuildOperationContext buildOperationContext) { ResolvableDependencies incoming = getIncoming(); performPreResolveActions(incoming); cachedResolverResults = new DefaultResolverResults(); resolver.resolveGraph(DefaultConfiguration.this, cachedResolverResults); dependenciesModified = false; resolvedState = GRAPH_RESOLVED; // Mark all affected configurations as observed markParentsObserved(requestedState); markReferencedProjectConfigurationsObserved(requestedState); dependencyResolutionListeners.getSource().afterResolve(incoming); // Discard listeners dependencyResolutionListeners.removeAll(); } }); }
private void performPreResolveActions(ResolvableDependencies incoming) { DependencyResolutionListener dependencyResolutionListener = dependencyResolutionListeners.getSource(); insideBeforeResolve = true; try { dependencyResolutionListener.beforeResolve(incoming); } finally { insideBeforeResolve = false; } triggerWhenEmptyActionsIfNecessary(); }
public void beforeResolve(ResolvableDependencies dependencies) { LinkedList<ProgressLogger> loggers = progressLoggers.get(); progressLoggers.set(loggers); ProgressLogger logger = loggerFactory.newOperation(DependencyResolutionLogger.class); logger.start("Resolve " + dependencies, "Resolving " + dependencies); loggers.add(logger); }
public void afterResolve(ResolvableDependencies dependencies) { LinkedList<ProgressLogger> loggers = progressLoggers.get(); if (loggers.isEmpty()) { throw new IllegalStateException("Logging operation was not started or it has already completed."); } ProgressLogger logger = loggers.removeLast(); logger.completed(); if (loggers.isEmpty()) { progressLoggers.remove(); } }
public void beforeResolve(ResolvableDependencies dependencies) { LinkedList<ProgressLogger> loggers = progressLoggers.get(); progressLoggers.set(loggers); ProgressLogger logger = loggerFactory.newOperation(DependencyResolutionLogger.class); logger.start(String.format("Resolve %s", dependencies), String.format("Resolving %s", dependencies)); loggers.add(logger); }
public ResolvableDependencies getIncoming() { return resolvableDependencies; }
public void beforeResolve(Action<? super ResolvableDependencies> action) { dependencyResolutionListeners.add("beforeResolve", action); }
public void afterResolve(Action<? super ResolvableDependencies> action) { dependencyResolutionListeners.add("afterResolve", action); }
public void beforeResolve(ResolvableDependencies dependencies) { long now = timeProvider.getCurrentTime(); buildProfile.getDependencySetProfile(dependencies.getPath()).setStart(now); }
public void afterResolve(ResolvableDependencies dependencies) { long now = timeProvider.getCurrentTime(); buildProfile.getDependencySetProfile(dependencies.getPath()).setFinish(now); }