Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Commit

Permalink
Add sensor logging message that SonarTS does nothing (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
vilchik-elena authored Nov 14, 2019
1 parent ea40741 commit 6bc0f09
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* SonarTS
* Copyright (C) 2017-2019 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.plugin.typescript;

import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;

public class EmptyTsSensor implements Sensor {

private static final Logger LOG = Loggers.get(EmptyTsSensor.class);

@Override
public void describe(SensorDescriptor sensorDescriptor) {
sensorDescriptor
.onlyOnLanguage("ts")
.name("SonarTS");
}

@Override
public void execute(SensorContext sensorContext) {
LOG.info("Since SonarTS v2.0, TypeScript analysis is performed by SonarJS analyzer v6.0 or later. No TypeScript analysis is performed by SonarTS.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ public class TypeScriptPlugin implements Plugin {
@Override
public void define(Context context) {
// This plugin doesn't define any extension, TypeScript analysis is migrated to SonarJS
// EmptyTsSensor is used to log message that this plugin does nothing
context.addExtension(EmptyTsSensor.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SonarTS
* Copyright (C) 2017-2019 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.plugin.typescript;

import java.io.File;
import org.junit.Test;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;

import static org.assertj.core.api.Assertions.assertThat;

public class EmptyTsSensorTest {

@org.junit.Rule
public LogTester logTester = new LogTester();

@Test
public void descriptor() {
DefaultSensorDescriptor sensorDescriptor = new DefaultSensorDescriptor();
new EmptyTsSensor().describe(sensorDescriptor);

assertThat(sensorDescriptor.languages()).containsExactly("ts");
assertThat(sensorDescriptor.name()).isEqualTo("SonarTS");
}

@Test
public void log_message() {
new EmptyTsSensor().execute(SensorContextTester.create(new File("")));
assertThat(logTester.logs(LoggerLevel.INFO))
.containsExactly("Since SonarTS v2.0, TypeScript analysis is performed by SonarJS analyzer v6.0 or later. No TypeScript analysis is performed by SonarTS.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public void count_extensions() {
Plugin.Context context = new Plugin.Context(runtime);
Plugin underTest = new TypeScriptPlugin();
underTest.define(context);
assertThat(context.getExtensions()).hasSize(0);
assertThat(context.getExtensions()).hasSize(1);
}
}

0 comments on commit 6bc0f09

Please sign in to comment.