Search in sources :

Example 6 with Project

use of org.sonar.api.resources.Project in project sonarqube by SonarSource.

the class DefaultIndexTest method createIndex.

@Before
public void createIndex() throws IOException {
    ruleFinder = mock(RuleFinder.class);
    componentStore = mock(InputComponentStore.class);
    componentTree = mock(InputComponentTree.class);
    index = new DefaultIndex(componentStore, componentTree, mock(MeasureCache.class), mock(MetricFinder.class));
    baseDir = temp.newFolder();
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("project").setBaseDir(baseDir);
    ProjectDefinition moduleADef = ProjectDefinition.create().setKey("moduleA").setBaseDir(new java.io.File(baseDir, "moduleA"));
    ProjectDefinition moduleBDef = ProjectDefinition.create().setKey("moduleB").setBaseDir(new java.io.File(baseDir, "moduleB"));
    ProjectDefinition moduleB1Def = ProjectDefinition.create().setKey("moduleB1").setBaseDir(new java.io.File(baseDir, "moduleB/moduleB1"));
    rootDef.addSubProject(moduleADef);
    rootDef.addSubProject(moduleBDef);
    moduleBDef.addSubProject(moduleB1Def);
    project = new Project(rootDef);
    moduleA = new Project(moduleADef);
    moduleB = new Project(moduleBDef);
    moduleB1 = new Project(moduleB1Def);
    RulesProfile rulesProfile = RulesProfile.create();
    rule = Rule.create("repoKey", "ruleKey", "Rule");
    rule.setId(1);
    rulesProfile.activateRule(rule, null);
    index.setCurrentStorage(mock(DefaultSensorStorage.class));
}
Also used : Project(org.sonar.api.resources.Project) RulesProfile(org.sonar.api.profiles.RulesProfile) InputComponentTree(org.sonar.api.batch.fs.internal.InputComponentTree) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) DefaultSensorStorage(org.sonar.scanner.sensor.DefaultSensorStorage) RuleFinder(org.sonar.api.rules.RuleFinder) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Before(org.junit.Before)

Example 7 with Project

use of org.sonar.api.resources.Project in project sonarlint-core by SonarSource.

the class ScannerExtensionDictionnaryTest method checkProject.

@Test
public void checkProject() {
    BatchExtension ok = new CheckProjectOK();
    BatchExtension ko = new CheckProjectKO();
    ScannerExtensionDictionnary selector = newSelector(ok, ko);
    List<BatchExtension> extensions = Lists.newArrayList(selector.select(BatchExtension.class, new Project(ProjectDefinition.create().setKey("key")), true));
    assertThat(extensions).hasSize(1);
    assertThat(extensions.get(0)).isInstanceOf(CheckProjectOK.class);
}
Also used : CheckProject(org.sonar.api.batch.CheckProject) Project(org.sonar.api.resources.Project) BatchExtension(org.sonar.api.BatchExtension) Test(org.junit.Test)

Example 8 with Project

use of org.sonar.api.resources.Project in project sonarqube by SonarSource.

the class PhasesSumUpTimeProfiler method onProjectAnalysis.

@Override
public void onProjectAnalysis(ProjectAnalysisEvent event) {
    Project module = event.getProject();
    if (event.isStart()) {
        currentModuleProfiling = new ModuleProfiling(module, system);
    } else {
        currentModuleProfiling.stop();
        modulesProfilings.put(module, currentModuleProfiling);
        long moduleTotalTime = currentModuleProfiling.totalTime();
        println("");
        println(" -------- Profiling of module " + module.getName() + ": " + TimeUtils.formatDuration(moduleTotalTime) + " --------");
        println("");
        Properties props = new Properties();
        currentModuleProfiling.dump(props);
        println("");
        println(" -------- End of profiling of module " + module.getName() + " --------");
        println("");
        String fileName = module.getKey() + "-profiler.properties";
        dumpToFile(props, ScannerUtils.cleanKeyForFilename(fileName));
        totalProfiling.merge(currentModuleProfiling);
        if (module.getParent() == null && !module.getModules().isEmpty()) {
            dumpTotalExecutionSummary();
        }
    }
}
Also used : Project(org.sonar.api.resources.Project) GlobalProperties(org.sonar.scanner.bootstrap.GlobalProperties) Properties(java.util.Properties) CoreProperties(org.sonar.api.CoreProperties)

Example 9 with Project

use of org.sonar.api.resources.Project in project sonarqube by SonarSource.

the class InitializersExecutor method execute.

public void execute() {
    Collection<Initializer> initializers = selector.select(Initializer.class, module, true, null);
    eventBus.fireEvent(new InitializersPhaseEvent(Lists.newArrayList(initializers), true));
    if (LOG.isDebugEnabled()) {
        LOG.debug("Initializers : {}", StringUtils.join(initializers, " -> "));
    }
    Project project = new Project(module.definition());
    for (Initializer initializer : initializers) {
        eventBus.fireEvent(new InitializerExecutionEvent(initializer, true));
        Profiler profiler = Profiler.create(LOG).startInfo("Initializer " + initializer);
        initializer.execute(project);
        profiler.stopInfo();
        eventBus.fireEvent(new InitializerExecutionEvent(initializer, false));
    }
    eventBus.fireEvent(new InitializersPhaseEvent(Lists.newArrayList(initializers), false));
}
Also used : Project(org.sonar.api.resources.Project) Profiler(org.sonar.api.utils.log.Profiler) Initializer(org.sonar.api.batch.Initializer)

Example 10 with Project

use of org.sonar.api.resources.Project in project sonarqube by SonarSource.

the class ScannerExtensionDictionnaryTest method buildStatusCheckersAreExecutedAfterOtherPostJobs.

@Test
public void buildStatusCheckersAreExecutedAfterOtherPostJobs() {
    BuildBreaker checker = new BuildBreaker() {

        public void executeOn(Project project, SensorContext context) {
        }
    };
    ScannerExtensionDictionnary selector = newSelector(new FakePostJob(), checker, new FakePostJob());
    List extensions = Lists.newArrayList(selector.select(PostJob.class, null, true, null));
    assertThat(extensions).hasSize(3);
    assertThat(extensions.get(2)).isEqualTo(checker);
}
Also used : SensorContext(org.sonar.api.batch.SensorContext) DefaultSensorContext(org.sonar.scanner.sensor.DefaultSensorContext) CheckProject(org.sonar.api.batch.CheckProject) Project(org.sonar.api.resources.Project) BuildBreaker(org.sonar.api.batch.BuildBreaker) List(java.util.List) PostJob(org.sonar.api.batch.PostJob) Test(org.junit.Test)

Aggregations

Project (org.sonar.api.resources.Project)13 Test (org.junit.Test)7 CheckProject (org.sonar.api.batch.CheckProject)3 PostJob (org.sonar.api.batch.PostJob)3 List (java.util.List)2 BuildBreaker (org.sonar.api.batch.BuildBreaker)2 SensorContext (org.sonar.api.batch.SensorContext)2 Properties (java.util.Properties)1 Before (org.junit.Before)1 BatchExtension (org.sonar.api.BatchExtension)1 CoreProperties (org.sonar.api.CoreProperties)1 AnalysisMode (org.sonar.api.batch.AnalysisMode)1 Initializer (org.sonar.api.batch.Initializer)1 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)1 InputFile (org.sonar.api.batch.fs.InputFile)1 InputComponentTree (org.sonar.api.batch.fs.internal.InputComponentTree)1 RulesProfile (org.sonar.api.profiles.RulesProfile)1 Directory (org.sonar.api.resources.Directory)1 RuleFinder (org.sonar.api.rules.RuleFinder)1 Profiler (org.sonar.api.utils.log.Profiler)1